Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions resources/[system]/scoreboard-basic-theme/fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- This resource is part of the default Cfx.re asset pack (cfx-server-data)
-- Altering or recreating for local use only is strongly discouraged.

version '1.0.0'
author 'Chip & Neco'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bundled assets should be a generic name since we're not using the fxports system at this time.

description 'A basic theme for the scoreboard resource.'
repository 'https://github.com/citizenfx/cfx-server-data'

file 'style.css'

scoreboard_theme 'basic' {
styleSheet = 'style.css',
}

game 'gta5'
fx_version 'adamant'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meh. Is this compliant to any newer versions' stuff?

74 changes: 74 additions & 0 deletions resources/[system]/scoreboard-basic-theme/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
@import url('https://fonts.googleapis.com/css2?family=Rubik:wght@400;500;600&display=swap');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remote dependencies are a no.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you'd like me to download the font instead?


* {
font-family: 'Rubik', sans-serif;
}

.scoreboardWrapper {
display: flex;
justify-content: center;
align-items: center;
width: 100vw;
height: 100vh;
}

.scoreboard {
background-color: #414a4d;
width: 1000px;
max-width: 100%;
height: 600px;
overflow: auto;
background-image: none;
}
.content-table {
border-collapse: separate;
width: 100%;
table-layout: fixed;
border: none;
margin: 0;
border-spacing: 0;
}

.content-table thead th {
position: sticky;
top: 0;
z-index: 1000;
background: rgba(35, 35, 35, 1);
border-bottom: 2px solid #fff;
text-align: left;
color: #fff;
font-weight: bold;
}

.content-table th,
.content-table td {
padding: 12px 12px;
min-width: 50px;
overflow: hidden;
white-space: nowrap;
}

.content-table tbody tr {
color: #fff;
border-bottom: 1px solid #eeeeee;
background-color: rgba(31, 31, 31, 0.75);
}

.content-table tbody tr:nth-child(2n) {
color: #fff;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these both the exact same?

border-bottom: 1px solid #eeeeee;
background-color: rgba(31, 31, 31, 0.75);
}

.content-table tbody tr:hover {
background-color: rgba(31, 31, 31, 0.75);
}

::-webkit-scrollbar {
background: #414a4d;
width: 10px;
}

::-webkit-scrollbar-thumb {
background-color: #232323;
}
4 changes: 4 additions & 0 deletions resources/[system]/scoreboard/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
html
node_modules
.yarn.installed
yarn.lock

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't ignore yarn.lock.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
118 changes: 118 additions & 0 deletions resources/[system]/scoreboard/client.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
RegisterKeyMapping("+scoreboard", "Open the scoreboard.", "keyboard", "z")

RegisterCommand("+scoreboard", function(source, args, rawcommand)
if not isShowing then
TriggerServerEvent("scoreboard:getPlayers")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latent events and some sort of rate limiting (now you can just hit the button a lot and it'll request a lot of updates)?

SendNUIMessage({
app = 'CfxScoreboard',
method = 'setVisibility',
data = true
})
SetNuiFocus(true, true)
SetNuiFocusKeepInput(true)
SetCursorLocation(0.5, 0.5)
isShowing = true
Citizen.CreateThread(function()
while isShowing do
Citizen.Wait(0)
DisableControlAction(0, 1, true)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What're these control IDs? Magic numbers, too. 😕

Also, why even disable controls?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It disables camera movement and weapon switching via scroll wheel while the scoreboard is open, to allow for scrolling when there are many players, I will add comments to explain these.

DisableControlAction(0, 2, true)
DisableControlAction(0, 16, true)
DisableControlAction(0, 17, true)
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No re-request for users who hold it for >1 second either? :(

end)
end
end, false)

RegisterCommand("-scoreboard", function(source, args, rawcommand)
SendNUIMessage({
app = 'CfxScoreboard',
method = 'setVisibility',
data = false
})
SetNuiFocus(false, false)
SetNuiFocusKeepInput(false)
isShowing = false
end, false)

players = {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a global for any particular reason?


RegisterNetEvent("scoreboard:receivePlayers")
AddEventHandler("scoreboard:receivePlayers", function(_players)
players = _players
local nuiData = {}
for playerId, playerData in pairs(players) do
local nextId = #nuiData+1
nuiData[nextId] = {}
for id, columnData in pairs(columns) do
nuiData[nextId][id] = playerData[columnData.friendlyName]
end
end
-- send to NUI to populate players
SendNUIMessage({
app = 'CfxScoreboard',
method = 'setPlayers',
data = nuiData
})
end)

TriggerServerEvent("scoreboard:requestColumns")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if a column is added dynamically during the resource's lifetime?


RegisterNetEvent("scoreboard:receiveColumns")
AddEventHandler("scoreboard:receiveColumns", function(_columns)
table.sort(_columns, function(a, b)
if not a or not b then return end
return a["position"] < b["position"]
end)
columns = _columns
-- Send to NUI to populate columns
SendNUIMessage({
app = 'CfxScoreboard',
method = 'setColumns',
data = columns
})
end)

--[[
The following is stolen from the chat resource to allow for themes.
All credit for this goes to moscovium for writing the theme logic (03362d2).
]]
local function refreshThemes()
local themes = {}

for resIdx = 0, GetNumResources() - 1 do
local resource = GetResourceByFindIndex(resIdx)

if GetResourceState(resource) == 'started' then
local numThemes = GetNumResourceMetadata(resource, 'scoreboard_theme')

if numThemes > 0 then
local themeName = GetResourceMetadata(resource, 'scoreboard_theme')
local themeData = json.decode(GetResourceMetadata(resource, 'scoreboard_theme_extra') or 'null')

if themeName and themeData then
themeData.baseUrl = 'nui://' .. resource .. '/'
themes[themeName] = themeData
end
end
end
end

SendNUIMessage({
app = 'CfxScoreboard',
method = 'updateThemes',
data = themes
})
end

AddEventHandler('onClientResourceStart', function(resName)
Wait(500)

refreshThemes()
end)

AddEventHandler('onClientResourceStop', function(resName)
Wait(500)

refreshThemes()
end)
27 changes: 27 additions & 0 deletions resources/[system]/scoreboard/fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
fx_version 'cerulean'
game 'gta5'

version '1.0.0'
author 'Chip & Neco'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the other manifest.

description 'The scoreboard resource.'
repository 'https://github.com/citizenfx/cfx-server-data'

ui_page 'html/index.html'

files {
'html/index.html',
'html/*.js',
'html/*.css',
'assets/*.png'
}

client_script 'client.lua'

server_script 'server.lua'

dependencies {
'yarn',
'webpack'
}

webpack_config 'webpack.config.js'
54 changes: 54 additions & 0 deletions resources/[system]/scoreboard/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "ui",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/jest": "^26.0.15",
"@types/node": "^12.0.0",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.3",
"typescript": "^4.1.2",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "cross-env NODE_ENV=production webpack --color --progress",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"copy-webpack-plugin": "^5.1.1",
"cross-env": "^7.0.3",
"css-loader": "^5.1.0",
"html-loader": "^2.1.1",
"html-webpack-plugin": "4",
"style-loader": "^2.0.0",
"ts-loader": "^8.0.18",
"url-loader": "^4.1.1",
"webpack-cli": "^4.5.0"
}
}
Loading