-
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
Open
The-Neco
wants to merge
4
commits into
citizenfx:master
Choose a base branch
from
The-Neco:feat-scoreboard
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
|
|
||
| fx_version 'cerulean' | ||
| game 'gta5' | ||
|
|
||
| version '1.0.0' | ||
| author 'Cfx.re <root@cfx.re>' | ||
| 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', | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| .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; | ||
| 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; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| html | ||
| node_modules | ||
| .yarn.installed |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| local isShowing = false | ||
| local players = {} | ||
| local lastUpdate = 0 | ||
|
|
||
| RegisterKeyMapping("+scoreboard", "Open the scoreboard.", "keyboard", "z") | ||
| RegisterCommand("+scoreboard", function(source, args, rawcommand) | ||
| if not isShowing then | ||
| if GetGameTimer() >= lastUpdate + 3000 then | ||
| lastUpdate = GetGameTimer() | ||
| TriggerServerEvent("scoreboard:getPlayers") | ||
| end | ||
| sortedColumns = sortColumns(GlobalState.columns) | ||
| SendNUIMessage({ | ||
| app = 'CfxScoreboard', | ||
| method = 'setColumns', | ||
| data = sortedColumns | ||
| }) | ||
| 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) -- INPUT_LOOK_LR - Prevent moving camera when moving mouse. | ||
| DisableControlAction(0, 2, true) -- INPUT_LOOK_UD - Prevent moving camera when moving mouse. | ||
| DisableControlAction(0, 16, true) -- INPUT_SELECT_NEXT_WEAPON - Prevent switching weapon when scrolling through list. | ||
| DisableControlAction(0, 17, true) -- INPUT_SELECT_PREV_WEAPON - Prevent switching weapon when scrolling through list. | ||
|
The-Neco marked this conversation as resolved.
|
||
| if GetGameTimer() >= lastUpdate + 3000 then | ||
| TriggerServerEvent("scoreboard:getPlayers") | ||
| lastUpdate = GetGameTimer() | ||
| end | ||
| 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) | ||
|
|
||
| RegisterNetEvent("scoreboard:receivePlayers") | ||
| AddEventHandler("scoreboard:receivePlayers", function(_players) | ||
| players = _players | ||
| local nuiData = {} | ||
| local sortedColumns = sortColumns(GlobalState.columns) | ||
| SendNUIMessage({ | ||
| app = 'CfxScoreboard', | ||
| method = 'setColumns', | ||
| data = sortedColumns | ||
| }) | ||
| for playerId, playerData in pairs(players) do | ||
| local nextId = #nuiData+1 | ||
| nuiData[nextId] = {} | ||
| for id, columnData in pairs(sortedColumns) do | ||
| nuiData[nextId][id] = playerData[columnData.identifier] | ||
| end | ||
| end | ||
| -- send to NUI to populate players | ||
| SendNUIMessage({ | ||
| app = 'CfxScoreboard', | ||
| method = 'setPlayers', | ||
| data = nuiData | ||
| }) | ||
| end) | ||
|
|
||
| TriggerServerEvent("scoreboard:initialize") | ||
|
|
||
| function sortColumns(unsortedTable) | ||
| table.sort(unsortedTable, function(a, b) | ||
| if not a or not b then return end | ||
| return a["position"] < b["position"] | ||
| end) | ||
| return unsortedTable | ||
| 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) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| -- This resource is part of the default Cfx.re asset pack (cfx-server-data) | ||
| -- Altering or recreating for local use only is strongly discouraged. | ||
|
|
||
| fx_version 'cerulean' | ||
| game 'gta5' | ||
|
|
||
| version '1.0.0' | ||
| author 'Cfx.re <root@cfx.re>' | ||
| 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', | ||
| 'assets/*.ttf' | ||
| } | ||
|
|
||
| client_script 'client.lua' | ||
|
|
||
| server_script 'server.lua' | ||
|
|
||
| dependencies { | ||
| 'yarn', | ||
| 'webpack' | ||
| } | ||
|
|
||
| webpack_config 'webpack.config.js' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why are these both the exact same?