aboutsummaryrefslogtreecommitdiff
path: root/Northstar.Client
diff options
context:
space:
mode:
authorEmma Miler <emma.pi@protonmail.com>2023-04-11 20:49:35 +0200
committerGitHub <noreply@github.com>2023-04-11 20:49:35 +0200
commitdb2434b524c284913c91556c75ff1ebd4226c96e (patch)
tree878b21866830ae4c6cc78963d7e93689ae16028c /Northstar.Client
parent7ec5413c0e71300814350164c69e6452136bd4cd (diff)
downloadNorthstarMods-db2434b524c284913c91556c75ff1ebd4226c96e.tar.gz
NorthstarMods-db2434b524c284913c91556c75ff1ebd4226c96e.zip
New presence code for plugins v2 (#532)
* test * Update cl_presence.nut * Update Northstar.Client/mod/scripts/vscripts/presence/ui_presence.nut * Apply suggestions from code review * New scripts * fix playlist and add native funcs to build * remove snake cases from GameStateStruct * I forgor --------- Co-authored-by: cat_or_not <41955154+catornot@users.noreply.github.com>
Diffstat (limited to 'Northstar.Client')
-rw-r--r--Northstar.Client/mod.json1
-rw-r--r--Northstar.Client/mod/scripts/vscripts/cl_northstar_client_init.nut22
-rw-r--r--Northstar.Client/mod/scripts/vscripts/presence/cl_presence.nut95
-rw-r--r--Northstar.Client/mod/scripts/vscripts/presence/ui_presence.nut42
-rw-r--r--Northstar.Client/mod/scripts/vscripts/ui/_menus.nut2
-rw-r--r--Northstar.Client/mod/scripts/vscripts/ui/menu_lobby.nut2
-rw-r--r--Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut12
7 files changed, 73 insertions, 103 deletions
diff --git a/Northstar.Client/mod.json b/Northstar.Client/mod.json
index d52f95fc..f0f45e67 100644
--- a/Northstar.Client/mod.json
+++ b/Northstar.Client/mod.json
@@ -3,6 +3,7 @@
"Description": "Various ui and client changes to fix bugs and add better support for mods",
"Version": "1.12.0",
"LoadPriority": 0,
+ "InitScript": "cl_northstar_client_init.nut",
"ConVars": [
{
"Name": "filter_hide_empty",
diff --git a/Northstar.Client/mod/scripts/vscripts/cl_northstar_client_init.nut b/Northstar.Client/mod/scripts/vscripts/cl_northstar_client_init.nut
new file mode 100644
index 00000000..212568d0
--- /dev/null
+++ b/Northstar.Client/mod/scripts/vscripts/cl_northstar_client_init.nut
@@ -0,0 +1,22 @@
+global struct GameStateStruct {
+
+ string map
+ string mapDisplayname
+
+ string playlist
+ string playlistDisplayname
+
+ int currentPlayers
+ int maxPlayers
+ int ownScore
+ int otherHighestScore
+ int maxScore
+ float timeEnd
+}
+
+global struct UIPresenceStruct {
+ bool isLoading
+ bool isLobby
+ string loadingLevel
+ string loadedLevel
+} \ No newline at end of file
diff --git a/Northstar.Client/mod/scripts/vscripts/presence/cl_presence.nut b/Northstar.Client/mod/scripts/vscripts/presence/cl_presence.nut
index 755396e3..c8a8274a 100644
--- a/Northstar.Client/mod/scripts/vscripts/presence/cl_presence.nut
+++ b/Northstar.Client/mod/scripts/vscripts/presence/cl_presence.nut
@@ -1,60 +1,45 @@
untyped
globalize_all_functions
-struct {
- int highestScore = 0
- int secondHighestScore = 0
-} file
-
-void function OnPrematchStart()
-{
- if ( GetServerVar( "roundBased" ) )
- NSUpdateTimeInfo( level.nv.roundEndTime - Time() )
- else
- NSUpdateTimeInfo( level.nv.gameEndTime - Time() )
-}
-
-void function NSUpdateGameStateClientStart()
-{
- #if MP
- AddCallback_GameStateEnter( eGameState.Prematch, OnPrematchStart )
- #endif
-
- thread NSUpdateGameStateLoopClient()
- OnPrematchStart()
-}
-
-void function NSUpdateGameStateLoopClient()
-{
- while ( true )
+void function NorthstarCodeCallback_GenerateGameState() {
+
+ GameStateStruct gs
+
+ int highestScore = 0
+ int secondHighest = 0
+
+ foreach ( player in GetPlayerArray() )
{
- if ( IsSingleplayer() )
- {
- NSUpdateGameStateClient( GetPlayerArray().len(), GetCurrentPlaylistVarInt( "max_players", 65535 ), 1, 1, 1, GetServerVar( "roundBased" ), 1 )
- wait 1.0
- }
- else
- {
- foreach ( player in GetPlayerArray() )
- {
- if ( GameRules_GetTeamScore( player.GetTeam() ) >= file.highestScore )
- {
- file.highestScore = GameRules_GetTeamScore( player.GetTeam() )
- }
- else if ( GameRules_GetTeamScore( player.GetTeam() ) > file.secondHighestScore )
- {
- file.secondHighestScore = GameRules_GetTeamScore( player.GetTeam() )
- }
- }
-
- int ourScore = 0
- if ( IsValid( GetLocalClientPlayer() ) )
- ourScore = GameRules_GetTeamScore( GetLocalClientPlayer().GetTeam() )
-
- int limit = IsRoundBased() ? GetCurrentPlaylistVarInt( "roundscorelimit", 0 ) : GetCurrentPlaylistVarInt( "scorelimit", 0 )
- NSUpdateGameStateClient( GetPlayerArray().len(), GetCurrentPlaylistVarInt( "max_players", 65535 ), ourScore, file.secondHighestScore, file.highestScore, GetServerVar( "roundBased" ), limit )
- OnPrematchStart()
- wait 1.0
- }
+ if ( GameRules_GetTeamScore( player.GetTeam() ) >= highestScore )
+ {
+ highestScore = GameRules_GetTeamScore( player.GetTeam() )
+ }
+ else if ( GameRules_GetTeamScore( player.GetTeam() ) > secondHighest )
+ {
+ secondHighest = GameRules_GetTeamScore( player.GetTeam() )
+ }
}
-}
+
+ gs.map = GetMapName()
+ gs.mapDisplayname = Localize(GetMapDisplayName(GetMapName()))
+
+ gs.playlist = GetCurrentPlaylistName()
+ gs.playlistDisplayname = Localize(GetCurrentPlaylistVarString("name", GetCurrentPlaylistName()))
+
+ gs.currentPlayers = GetPlayerArray().len()
+ gs.maxPlayers = GetCurrentPlaylistVarInt( "maxPlayers", -1 )
+
+ if ( IsValid( GetLocalClientPlayer() ) )
+ gs.ownScore = GameRules_GetTeamScore( GetLocalClientPlayer().GetTeam() )
+
+ gs.otherHighestScore = gs.ownScore == highestScore ? secondHighest : highestScore
+
+ gs.maxScore = IsRoundBased() ? GetCurrentPlaylistVarInt( "roundscorelimit", 0 ) : GetCurrentPlaylistVarInt( "scorelimit", 0 )
+
+ if ( GetServerVar( "roundBased" ) )
+ gs.timeEnd = expect float(level.nv.roundEndTime - Time())
+ else
+ gs.timeEnd = expect float(level.nv.gameEndTime - Time())
+
+ NSPushGameStateData(gs)
+} \ No newline at end of file
diff --git a/Northstar.Client/mod/scripts/vscripts/presence/ui_presence.nut b/Northstar.Client/mod/scripts/vscripts/presence/ui_presence.nut
index 1e381989..cdf1c981 100644
--- a/Northstar.Client/mod/scripts/vscripts/presence/ui_presence.nut
+++ b/Northstar.Client/mod/scripts/vscripts/presence/ui_presence.nut
@@ -1,38 +1,12 @@
untyped
globalize_all_functions
-void function NSUpdateGameStateUIStart()
-{
- thread NSUpdateGameStateLoopUI()
-}
+void function NorthstarCodeCallback_GenerateUIPresence() {
+ UIPresenceStruct uis
-void function NSUpdateGameStateLoopUI()
-{
- while ( true )
- {
- wait 1.0
-
- if ( uiGlobal.loadedLevel == "" )
- {
- if ( uiGlobal.isLoading )
- NSSetLoading( true )
- else
- {
- NSSetLoading( false )
- NSUpdateGameStateUI( "", "", "", "", true, false )
- }
-
- continue
- }
-
- NSSetLoading( false )
- if( GetConVarString( "mp_gamemode" ) == "solo" )
- {
- NSUpdateGameStateUI( GetActiveLevel(), Localize( GetMapDisplayName( GetActiveLevel() + "_CAMPAIGN_NAME" ) ), "Campaign", "Campaign", IsFullyConnected(), false )
- }
- else
- {
- NSUpdateGameStateUI( GetActiveLevel(), Localize( GetMapDisplayName( GetActiveLevel() ) ), GetConVarString( "mp_gamemode" ), Localize( GetPlaylistDisplayName( GetConVarString( "mp_gamemode" ) ) ), IsFullyConnected(), false )
- }
- }
-}
+ uis.isLoading = uiGlobal.isLoading
+ uis.isLobby = IsLobby()
+ uis.loadingLevel = uiGlobal.loadingLevel
+ uis.loadedLevel = uiGlobal.loadedLevel
+ NSPushUIPresence(uis)
+} \ No newline at end of file
diff --git a/Northstar.Client/mod/scripts/vscripts/ui/_menus.nut b/Northstar.Client/mod/scripts/vscripts/ui/_menus.nut
index 90a535ee..c83381fd 100644
--- a/Northstar.Client/mod/scripts/vscripts/ui/_menus.nut
+++ b/Northstar.Client/mod/scripts/vscripts/ui/_menus.nut
@@ -187,6 +187,7 @@ bool function UICodeCallback_LevelLoadingStarted( string levelname )
CloseAllDialogs()
uiGlobal.loadingLevel = levelname
+ uiGlobal.isLoading = true
StopMusic()
@@ -235,6 +236,7 @@ void function UICodeCallback_LevelLoadingFinished( bool error )
}
uiGlobal.loadingLevel = ""
+ uiGlobal.isLoading = false
Signal( uiGlobal.signalDummy, "LevelFinishedLoading" )
}
diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_lobby.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_lobby.nut
index 938e0d3f..3c868aab 100644
--- a/Northstar.Client/mod/scripts/vscripts/ui/menu_lobby.nut
+++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_lobby.nut
@@ -372,8 +372,6 @@ void function StartPrivateMatch( var button )
return
ClientCommand( "StartPrivateMatchSearch" )
- NSSetLoading(true)
- NSUpdateListenServer()
}
void function DoRoomInviteIfAllowed( var button )
diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut
index 03028255..b2e2a8b6 100644
--- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut
+++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut
@@ -1058,18 +1058,6 @@ void function ThreadedAuthAndConnectToServer( string password = "" )
}
file.cancelConnection = false
- NSSetLoading( true )
- NSUpdateServerInfo(
- NSGetServerID( file.lastSelectedServer ),
- NSGetServerName( file.lastSelectedServer ),
- password,
- NSGetServerPlayerCount( file.lastSelectedServer ),
- NSGetServerMaxPlayerCount( file.lastSelectedServer ),
- NSGetServerMap( file.lastSelectedServer ),
- Localize( GetMapDisplayName( NSGetServerMap( file.lastSelectedServer ) ) ),
- NSGetServerPlaylist( file.lastSelectedServer ),
- Localize( GetPlaylistDisplayName( NSGetServerPlaylist( file.lastSelectedServer ) ) )
- )
if ( NSWasAuthSuccessful() )
{