Skip to content
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

feat: Server-side choice RUI #831

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ce1c984
feat: add NSCreateChoiceOnPlayer server-side function
Alystrasz Aug 5, 2024
c16037f
feat: send choice parameters to client
Alystrasz Aug 5, 2024
749d200
feat: use RUI component to display choice on client
Alystrasz Aug 5, 2024
51fbb68
feat: emit sound on choice UI spawn
Alystrasz Aug 5, 2024
fd06f34
feat: RUI disappears with a smooth transition
Alystrasz Aug 5, 2024
e5454d4
fix: multiple choices can be triggered one after another
Alystrasz Aug 5, 2024
07f519e
feat: player can answer choice prompts
Alystrasz Aug 5, 2024
f50ed89
feat: add NSGetPlayerChoiceResponse method
Alystrasz Aug 5, 2024
ee9d35b
refactor: NSGetPlayerChoiceResponse returns -2 if input player is not…
Alystrasz Aug 5, 2024
6787f28
refactor: integrate key to choice API
Alystrasz Aug 5, 2024
e19cb6c
feat: add NSCreateChoiceOnAllPlayers util function
Alystrasz Aug 5, 2024
06de4be
Merge branch 'main' into feat/serverside-choice
Zanieon Aug 11, 2024
6325524
Merge branch 'main' into feat/serverside-choice
Alystrasz Aug 18, 2024
7a8b711
refactor: API takes an array of strings as input parameter
Alystrasz Aug 18, 2024
18ec783
feat: NSCreateChoiceOnPlayer throws when not getting 1 or 2 options
Alystrasz Aug 18, 2024
d4525b8
Merge branch 'main' into feat/serverside-choice
Alystrasz Aug 18, 2024
39cacda
refactor: add ePlayerChoiceStatus enum
Alystrasz Aug 19, 2024
7030714
Merge branch 'main' into feat/serverside-choice
Alystrasz Aug 26, 2024
71a79f2
style: use spaces to align enum (instead of tabs)
Alystrasz Aug 26, 2024
8141ccd
feat: support one choice only
Alystrasz Aug 26, 2024
f7909ec
Merge branch 'main' into feat/serverside-choice
Alystrasz Aug 27, 2024
a3c55f7
Merge branch 'main' into feat/serverside-choice
Alystrasz Sep 19, 2024
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
41 changes: 36 additions & 5 deletions Northstar.Custom/mod/scripts/vscripts/sh_message_utils.gnut
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ global function NSCreateStatusMessageOnPlayer
global function NSEditStatusMessageOnPlayer
global function NSDeleteStatusMessageOnPlayer

global enum ePlayerChoiceStatus
{
UNKNOWN,
NOT_FOUND, // no choice matching the key was found
NOT_FOUND_FOR_PLAYER, // choice exists, but the player was not proposed with it

ONGOING, // choice is currently proposed to the player, whom hasn't answered it yet
NOT_ANSWERED, // player did not answer the choice (RUI timed out)
CHOICE_1, // player selected first option
CHOICE_2 // player selected second option
}
GeckoEidechse marked this conversation as resolved.
Show resolved Hide resolved

struct
{
table<entity,int> playerPollResponses
Expand Down Expand Up @@ -144,9 +156,28 @@ bool function ClientCommand_ChoiceRespond( entity player, array<string> args )
if( args.len() != 2 )
return false

int responseValue = args[0].tointeger()
string key = args[1]
// todo: what if args[0] is not an integer?
int responseCode = args[0].tointeger()
int responseValue = ePlayerChoiceStatus.NOT_FOUND
switch( responseCode )
{
case 0:
responseValue = ePlayerChoiceStatus.NOT_ANSWERED
break
case 1:
responseValue = ePlayerChoiceStatus.CHOICE_1
break
case 2:
responseValue = ePlayerChoiceStatus.CHOICE_2
break
default:
// todo: test this usecase
print( format( "Player %s sent incorrect choice response value (was %s).", player.GetPlayerName(), responseCode ) )
responseValue = ePlayerChoiceStatus.UNKNOWN
break
}

string key = args[1]
if ( !( key in server.playerChoiceResponses ) || !( player in server.playerChoiceResponses[key] ) )
return false

Expand Down Expand Up @@ -230,7 +261,7 @@ string function NSCreateChoiceOnPlayer( entity player, array<string> options, fl

if( !( id in server.playerChoiceResponses ) )
server.playerChoiceResponses[id] <- {}
server.playerChoiceResponses[id][player] <- -1 // Reset choice response table entry
server.playerChoiceResponses[id][player] <- ePlayerChoiceStatus.ONGOING // Reset choice response table entry
ServerToClientStringCommand( player, "ServerHUDMessageShow " + eMessageType.CHOICE )

return id
Expand All @@ -239,10 +270,10 @@ string function NSCreateChoiceOnPlayer( entity player, array<string> options, fl
int function NSGetPlayerChoiceResponse( entity player, string key )
{
if( !( key in server.playerChoiceResponses ) )
return -3
return ePlayerChoiceStatus.NOT_FOUND

if( !( player in server.playerChoiceResponses[key] ) )
return -2
return ePlayerChoiceStatus.NOT_FOUND_FOR_PLAYER

return server.playerChoiceResponses[ key ][ player ]
}
Expand Down
Loading