Skip to content

Commit

Permalink
client: add ID, weapons state to UI
Browse files Browse the repository at this point in the history
  • Loading branch information
xxshady committed Aug 11, 2022
1 parent 1eacd26 commit 5196d66
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 10 deletions.
Binary file added freeroam-extended/client/html/Inter-Bold.ttf
Binary file not shown.
24 changes: 23 additions & 1 deletion freeroam-extended/client/html/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,33 @@ function addString(text) {
}

function updatePlayersOnline (number) {
document.querySelector(".players-online").textContent = `${number} players online`;
document.querySelector(".players-online-number").textContent = `${number}`;
}

function setPlayerId (id) {
document.querySelector(".player-id-number").textContent = `${id}`;
}

function setWeaponsDisabled (disabled) {
const el = document.querySelector(".weapons-enabled").children[0];
const [, styleClass] = el.classList;

if (disabled) {
el.classList.remove("weapons-enabled-on");
el.classList.add("weapons-enabled-off");
el.textContent = "OFF";
}
else {
el.classList.remove("weapons-enabled-off");
el.classList.add("weapons-enabled-on");
el.textContent = "ON";
}
}

alt.on("addString", (text) => addString(colorify(text)));
alt.on("addMessage", (name, text) => addString("<b>" + name + ": </b>" + colorify(text)));
alt.on("openChat", openChat);
alt.on("closeChat", closeChat);
alt.on("updatePlayersOnline", updatePlayersOnline);
alt.on("setPlayerId", setPlayerId);
alt.on("setWeaponsDisabled", setWeaponsDisabled);
13 changes: 10 additions & 3 deletions freeroam-extended/client/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@
<div class="stress-test-label">
Public Stress Test - xx.xx.2022
</div>
<div class="players-online">
x players online
<div class="info">
<div class="players-online">
<div class="info-number players-online-number">xxxx</div> players online
</div>
<div class="player-id">
<div class="info-number player-id-number">xxxx</div> your ID
</div>
<div class="weapons-enabled">
<div class="info-number weapons-enabled-on">ON</div> weapons
</div>
</div>
<div class="help-keys">
<ol>
Expand All @@ -32,7 +40,6 @@
</ol>
</div>
<div class="content">
<!-- <div class="shblock"></div> -->
<div class="chatbox">
<div class="msglist">
<div class="messages"></div>
Expand Down
62 changes: 57 additions & 5 deletions freeroam-extended/client/html/style.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
@font-face {
font-family: "Inter";
src: url("./Inter-Medium.ttf"),
src: url("./Inter-Medium.ttf");
}

@font-face {
font-family: "Inter";
font-weight: bold;
src: url("./Inter-Bold.ttf");
}

* {
Expand All @@ -11,7 +17,7 @@
-webkit-font-smoothing: antialiased;
-webkit-user-drag: none;
font-family: Inter, "Segoe UI", "Segoe UI Symbol", Arial, sans-serif;
text-shadow: 0px 0px 5px rgba(0, 0, 0, 0.793);
text-shadow: 0px 0px 0.1em rgba(0, 0, 0, 0.6);
}

*:focus {
Expand All @@ -28,7 +34,7 @@ body {

.help-keys {
position: absolute;
top: 3.0em;
top: 7em;
right: 1.5em;
text-align: right;
}
Expand Down Expand Up @@ -210,13 +216,43 @@ body {
}
}

.players-online {
.info {
font-size: .9em;
color: rgb(60, 255, 180);
position: absolute;
top: 1.5em;
right: 1.5em;
text-align: right;
color: white;
display: flex;
flex-direction: column;
align-items: flex-end;
font-weight: bold;
}

.info > div {
justify-self: right;
margin-bottom: 0.2em;
border-radius: 1.5em;
padding: 0.2em 0.5em;
width: fit-content;
flex-grow: 20%;
}

.info > div > .info-number {
background:rgb(255, 255, 255);
box-shadow: 0 0 0.5em rgba(255, 255, 255, 0.69);
border-radius: 0.5em;
color: black;
display: inline;
padding: 0.2em 0.5em;
text-shadow: none;
}

.players-online-number {
/* background: rgb(0,0, 0, 0.3);
padding: 0.1em;
border-radius: 0.5em; */
display: inline;
}

.stress-test-label {
Expand All @@ -229,3 +265,19 @@ body {
position: absolute;
color: rgba(255, 255, 255, 0.628);
}

.weapons-enabled > * {
color: rgb(255, 255, 255) !important;
}

.weapons-enabled-on {
--bg-color: rgb(98, 218, 114);
background: var(--bg-color) !important;
box-shadow: 0 0 0.5em var(--bg-color) !important;
}

.weapons-enabled-off {
--bg-color: rgb(235, 91, 86);
background: var(--bg-color) !important;
box-shadow: 0 0 0.5em var(--bg-color) !important;
}
6 changes: 6 additions & 0 deletions freeroam-extended/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ alt.setConfigFlag(ConfigFlag.DisableIdleCamera, true)
alt.setStat(StatName.Stamina, 100)
alt.setWatermarkPosition(WatermarkPosition.TopCenter)

view.emit("setPlayerId", LOCAL_PLAYER.id)

setInterval(() => {
if (!playerData.areNametagsVisible) return
view.emit("updatePlayersOnline", alt.Player.all.length)
Expand All @@ -24,6 +26,10 @@ playerData.onAreNametagsVisibleChange = (value) => {
playerNametags.enable(value)
}

playerData.onAreWeaponsDisabledChange = (value) => {
view.emit("setWeaponsDisabled", value)
}

alt.everyTick(() => {
if (playerData.areWeaponsDisabled) {
native.setCanPedEquipAllWeapons(LOCAL_PLAYER, false)
Expand Down
2 changes: 2 additions & 0 deletions freeroam-extended/client/src/playerdata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class PlayerData {
public onAreNametagsVisibleChange: ((value: boolean) => void) | null = null
public onAreWeaponsDisabledChange: ((value: boolean) => void) | null = null

private _areNametagsVisible = true
private _areWeaponsDisabled = true
Expand All @@ -23,6 +24,7 @@ class PlayerData {

public set areWeaponsDisabled(value: boolean) {
this._areWeaponsDisabled = value
this.onAreWeaponsDisabledChange?.(value)
}

public get lastCommandTimestamp(): number {
Expand Down
4 changes: 3 additions & 1 deletion freeroam-extended/client/src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ type EventNames =
"openChat" |
"closeChat" |
"addString" |
"addMessage"
"addMessage" |
"setPlayerId" |
"setWeaponsDisabled"

class View extends alt.WebView {
public override emit(eventName: EventNames, ...args: unknown[]) {
Expand Down

0 comments on commit 5196d66

Please sign in to comment.