-
Notifications
You must be signed in to change notification settings - Fork 889
feat(scoreboard): Scoreboard rewrite. #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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' | ||
| 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' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Meh. Is this compliant to any newer versions' stuff? |
||
| 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'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remote dependencies are a no. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| html | ||
| node_modules | ||
| .yarn.installed | ||
| yarn.lock | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't ignore yarn.lock. |
||
| 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") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = {} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
| 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' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' | ||
| 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" | ||
| } | ||
| } |
There was a problem hiding this comment.
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.