From 35dfd937798d105238db23ea86f90f21be46694b Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Sun, 7 Nov 2021 03:53:07 +0000 Subject: code cleanup, xp, postgame and some small changes --- .../scripts/vscripts/ui/menu_ns_serverbrowser.nut | 63 ++++-- .../mod/scripts/vscripts/ui/openinvites.nut | 242 +++++++++++++++++++++ .../mod/scripts/vscripts/ui/panel_mainmenu.nut | 12 +- 3 files changed, 299 insertions(+), 18 deletions(-) create mode 100644 Northstar.Client/mod/scripts/vscripts/ui/openinvites.nut (limited to 'Northstar.Client/mod') 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 29c1f81a2..c288b3a83 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut @@ -175,16 +175,17 @@ void function OnServerSelected( var button ) if ( NSIsRequestingServerList() || !NSMasterServerConnectionSuccessful() ) return - int server = int( Hud_GetScriptID( button ) ) + int serverIndex = file.page * BUTTONS_PER_PAGE + int ( Hud_GetScriptID( button ) ) + file.lastSelectedServer = serverIndex // check mods - for ( int i = 0; i < NSGetServerRequiredModsCount( server ); i++ ) + for ( int i = 0; i < NSGetServerRequiredModsCount( serverIndex ); i++ ) { - if ( !NSGetModNames().contains( NSGetServerRequiredModName( server, i ) ) ) + if ( !NSGetModNames().contains( NSGetServerRequiredModName( serverIndex, i ) ) ) { DialogData dialogData dialogData.header = "#ERROR" - dialogData.message = "Missing mod \"" + NSGetServerRequiredModName( server, i ) + "\" v" + NSGetServerRequiredModVersion( server, i ) + dialogData.message = "Missing mod \"" + NSGetServerRequiredModName( serverIndex, i ) + "\" v" + NSGetServerRequiredModVersion( serverIndex, i ) dialogData.image = $"ui/menu/common/dialog_error" #if PC_PROG @@ -200,16 +201,43 @@ void function OnServerSelected( var button ) } else { - string modVersion = NSGetServerRequiredModVersion( server, i ) - // check this is sorta valid semver, d + // this uses semver https://semver.org + array serverModVersion = split( NSGetServerRequiredModVersion( serverIndex, i ), "." ) + array clientModVersion = split( NSGetModVersionByModName( NSGetServerRequiredModName( serverIndex, i ) ), "." ) + + bool semverFail = false + // if server has invalid semver don't bother checking + if ( serverModVersion.len() == 3 ) + { + // bad client semver + if ( clientModVersion.len() != serverModVersion.len() ) + semverFail = true + // major version, don't think we should need to check other versions + else if ( clientModVersion[ 0 ] != serverModVersion[ 0 ] ) + semverFail = true + } + + if ( semverFail ) + { + DialogData dialogData + dialogData.header = "#ERROR" + dialogData.message = "Server has mod \"" + NSGetServerRequiredModName( serverIndex, i ) + "\" v" + NSGetServerRequiredModVersion( serverIndex, i ) + " while we have v" + NSGetModVersionByModName( NSGetServerRequiredModName( serverIndex, i ) ) + dialogData.image = $"ui/menu/common/dialog_error" + + #if PC_PROG + AddDialogButton( dialogData, "#DISMISS" ) + + AddDialogFooter( dialogData, "#A_BUTTON_SELECT" ) + #endif // PC_PROG + AddDialogFooter( dialogData, "#B_BUTTON_DISMISS_RUI" ) + + OpenDialog( dialogData ) + + return + } } } - var menu = GetMenu( "ServerBrowserMenu" ) - int serverIndex = file.page * BUTTONS_PER_PAGE + int ( Hud_GetScriptID( button ) ) - - file.lastSelectedServer = serverIndex - if ( NSServerRequiresPassword( serverIndex ) ) AdvanceMenu( GetMenu( "ConnectWithPasswordMenu" ) ) else @@ -229,16 +257,25 @@ void function ThreadedAuthAndConnectToServer( string password = "" ) if ( NSWasAuthSuccessful() ) { + bool modsChanged + array requiredMods for ( int i = 0; i < NSGetServerRequiredModsCount( file.lastSelectedServer ); i++ ) requiredMods.append( NSGetServerRequiredModName( file.lastSelectedServer, i ) ) // unload mods we don't need, load necessary ones and reload mods before connecting foreach ( string mod in NSGetModNames() ) + { if ( NSIsModRequiredOnClient( mod ) ) + { + modsChanged = modsChanged || NSIsModEnabled( mod ) != requiredMods.contains( mod ) NSSetModEnabled( mod, requiredMods.contains( mod ) ) - - ReloadMods() + } + } + + // only actually reload if we need to since the uiscript reset on reload lags hard + if ( modsChanged ) + ReloadMods() NSConnectToAuthedServer() } diff --git a/Northstar.Client/mod/scripts/vscripts/ui/openinvites.nut b/Northstar.Client/mod/scripts/vscripts/ui/openinvites.nut new file mode 100644 index 000000000..4b3d0f55e --- /dev/null +++ b/Northstar.Client/mod/scripts/vscripts/ui/openinvites.nut @@ -0,0 +1,242 @@ +global function InitOpenInvitesMenu +global function UICodeCallback_OpenInviteUpdated +global function InPendingOpenInvite +global function LeaveOpenInvite +global function JoinOpenInvite +global function JoinOpenInvite_OnClick +global function CanJoinOpenInvite +global function CanLeaveOpenInvite +global function CanDestroyOpenInvite +global function LeaveOpenInviteButton +global function IsOpenInviteVisible + +struct +{ + bool openInviteJoinable + bool openInviteVisible +} file + +bool function InPendingOpenInvite() +{ + if ( !file.openInviteVisible ) + return false + OpenInvite openInvite = GetOpenInvite() + return openInvite.amIInThis +} + +void function LeaveOpenInviteButton( var button ) +{ + LeaveOpenInvite() +} + +void function LeaveOpenInvite() +{ + EmitUISound( "UI_Networks_Invitation_Canceled" ) + ClientCommand( "leaveopeninvite" ) + + // sort of HACK: revert lobby to non-FD mode when you cancel out of open invite + Lobby_SetFDMode( false ) + Lobby_RefreshButtons() +} + +void function JoinOpenInvite( var button ) +{ + if ( CanJoinOpenInvite() ) + { + EmitUISound( "UI_Networks_Invitation_Accepted" ) + ClientCommand( "joinopeninvite" ) + } + else if ( CanLeaveOpenInvite() ) + { + LeaveOpenInvite() + } +} + +void function JoinOpenInvite_OnClick( var button ) +{ + // haaaack. Either join it or leave it here, depending on context + OpenInvite openInvite = GetOpenInvite() + if ( openInvite.amIInThis ) + LeaveOpenInvite() + else + JoinOpenInvite( button ) +} + +bool function IsOpenInviteVisible() +{ + return file.openInviteVisible +} + +bool function CanDestroyOpenInvite() +{ + OpenInvite openInvite = GetOpenInvite() + return file.openInviteVisible && openInvite.amILeader +} + +bool function CanJoinOpenInvite() +{ + OpenInvite openInvite = GetOpenInvite() + int currentPartySize = GetPartySize() + return currentPartySize <= 1 && file.openInviteVisible && file.openInviteJoinable && !openInvite.amIInThis +} + +bool function CanLeaveOpenInvite() +{ + OpenInvite openInvite = GetOpenInvite() + return file.openInviteVisible && file.openInviteJoinable && !openInvite.amILeader && openInvite.amIInThis +} + +void function UpdateOpenInvite() +{ + OpenInvite openInvite = GetOpenInvite() + + if ( openInvite.timeLeft <= -1 || openInvite.numFreeSlots == 0 ) + { + HideOpenInvite() + if ( openInvite.amILeader ) + ClientCommand( "openinvitelaunch" ) + if ( openInvite.amIInThis ) + { + CloseAllToTargetMenu( GetMenu( "LobbyMenu" ) ) + AdvanceMenu( GetMenu( "SearchMenu" ) ) + } + else + { + Lobby_SetFDMode( false ) + Lobby_RefreshButtons() + } + file.openInviteVisible = false + file.openInviteJoinable = false + UpdateFooterOptions() + return + } + + array playlists = split( openInvite.playlistName, "," ) + + string message = "" + string param1 = "" + string ornull param2 = null + switch( openInvite.inviteType ) + { + case "party": + if ( openInvite.amILeader ) + message = "#OPENINVITE_SENDER_PARTY"; + else + message = "#OPENINVITE_PARTY"; + param1 = openInvite.originatorName + break; + case "playlist": + if ( playlists.len() > 1 ) + { + if ( openInvite.amILeader ) + message = "#OPENINVITE_SENDER_PLAYLIST_MANY" + else + message = "#OPENINVITE_PLAYLIST_MANY" + param1 = openInvite.originatorName + param2 = GetPlaylistDisplayName( openInvite.playlistName ) + } + else + { + if ( openInvite.amILeader ) + message = "#OPENINVITE_SENDER_PLAYLIST" + else + message = "#OPENINVITE_PLAYLIST" + param1 = openInvite.originatorName + param2 = GetPlaylistDisplayName( openInvite.playlistName ) + } + break; + case "private_match": + if ( openInvite.amILeader ) + message = "#OPENINVITE_SENDER_PRIVATEMATCH" + else + message = "#OPENINVITE_PRIVATEMATCH" + param1 = openInvite.originatorName + break; + default: + HideOpenInvite() + file.openInviteVisible = false + file.openInviteJoinable = false + UpdateFooterOptions() + return; + } + int timeLeft = int( openInvite.timeLeft ) + 1 + if ( openInvite.timeLeft <= 0 || openInvite.numFreeSlots == 0 ) + { + if ( file.openInviteJoinable ) + { + file.openInviteJoinable = false + UpdateFooterOptions() + } + timeLeft = 0 + } + else + { + if ( !file.openInviteJoinable ) + { + file.openInviteJoinable = true + UpdateFooterOptions() + printt( "openinvite is joinable" ) + } + } + + UpdateOpenInvites( openInvite, message, param1, param2, timeLeft ) +} + +void function UpdateOpenInvite_Thread() +{ + while ( file.openInviteVisible ) + { + if ( !IsConnected() || !IsLobby() ) + { + HideOpenInvite() + file.openInviteVisible = false + file.openInviteJoinable = false + UpdateFooterOptions() + return + } + + UpdateOpenInvite() + WaitFrame() + } +} + +void function UICodeCallback_OpenInviteUpdated() +{ + if ( file.openInviteVisible || IsNorthstarServer() ) + return + + int currentPartySize = GetPartySize() + if ( currentPartySize > 1 ) + { + HideOpenInvite() + file.openInviteVisible = false + return + } + + if ( !IsConnected() ) + { + HideOpenInvite() + file.openInviteVisible = false + return + } + + entity player = GetUIPlayer() + if ( IsValid( player ) && Player_NextAvailableMatchmakingTime( player ) > 0 ) + { + HideOpenInvite() + file.openInviteVisible = false + return + } + + OpenInvite openInvite = GetOpenInvite() + ShowOpenInvite() + file.openInviteVisible = true + UpdateOpenInvite() + thread UpdateOpenInvite_Thread() +} + +void function InitOpenInvitesMenu() +{ + file.openInviteVisible = false + file.openInviteJoinable = false +} diff --git a/Northstar.Client/mod/scripts/vscripts/ui/panel_mainmenu.nut b/Northstar.Client/mod/scripts/vscripts/ui/panel_mainmenu.nut index 2eafa373a..7528495f1 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/panel_mainmenu.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/panel_mainmenu.nut @@ -274,15 +274,15 @@ void function UpdatePlayButton( var button ) message = "#CONTACTING_RESPAWN_SERVERS" file.mpButtonActivateFunc = null } - else if ( !isFullyInstalled ) + + bool hasNonVanillaMods = false + if ( hasNonVanillaMods ) { - //message = "#INSTALL_IN_PROGRESS" - file.mpButtonActivateFunc = LaunchMP + // todo: make this disable non-vanilla mods } else - { file.mpButtonActivateFunc = LaunchMP - } + isLocked = file.mpButtonActivateFunc == null ? true : false Hud_SetLocked( button, isLocked ) @@ -507,6 +507,7 @@ void function OnPlayFDButton_Activate( var button ) // repurposed for launching //ClientCommand( "setplaylist tdm" ) //ClientCommand( "map mp_lobby" ) + SetConVarBool( "ns_is_modded_server", true ) NSTryAuthWithLocalServer() thread TryAuthWithLocalServer() @@ -537,6 +538,7 @@ void function OnPlayMPButton_Activate( var button ) { Lobby_SetAutoFDOpen( false ) // Lobby_SetFDMode( false ) + SetConVarBool( "ns_is_modded_server", false ) thread file.mpButtonActivateFunc() } } -- cgit v1.2.3