diff options
author | F1F7Y <64418963+F1F7Y@users.noreply.github.com> | 2022-04-19 22:33:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-19 22:33:45 +0200 |
commit | 2da71a5730b65d13049fbbd2635d1fac189f6662 (patch) | |
tree | fba87e1dcb459045edbc91f836126249947261a6 /Northstar.Client/mod/scripts/vscripts/ui | |
parent | 6fdbd80dd796c9334f205606fdab8c141b922de0 (diff) | |
download | NorthstarMods-2da71a5730b65d13049fbbd2635d1fac189f6662.tar.gz NorthstarMods-2da71a5730b65d13049fbbd2635d1fac189f6662.zip |
Server browser fix + formatting (#315)
* Fixes #314
* Updates formatting to project style
Diffstat (limited to 'Northstar.Client/mod/scripts/vscripts/ui')
-rw-r--r-- | Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut | 331 |
1 files changed, 174 insertions, 157 deletions
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 6bffe8bb..c77000e9 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut @@ -7,15 +7,16 @@ global function ThreadedAuthAndConnectToServer // Stop peeking -const int BUTTONS_PER_PAGE = 15 -const float DOUBLE_CLICK_TIME_MS = 0.4 // unsure what the ideal value is - +const int BUTTONS_PER_PAGE = 15 // Number of servers we show +const float DOUBLE_CLICK_TIME_MS = 0.4 // Max time between clicks for double click registering +// Stores mouse delta used for scroll bar struct { int deltaX = 0 int deltaY = 0 } mouseDeltaBuffer +// Filters struct { bool hideFull = false bool hideEmpty = false @@ -39,6 +40,7 @@ enum sortingBy LATENCY } +// Column sort direction, only one of these can be aplied at once struct { // true = alphabeticaly false = reverse bool serverName = true @@ -62,6 +64,7 @@ struct serverStruct { } struct { + // UI state vars var menu int lastSelectedServer = 999 int focusedServerIndex = 0 @@ -72,9 +75,11 @@ struct { int serverButtonFocusedID = 0 bool shouldFocus = true bool cancelConnection = false - + + // filtered array of servers array<serverStruct> serversArrayFiltered - + + // UI references array<var> serverButtons array<var> serversName array<var> playerCountLabels @@ -86,9 +91,10 @@ struct { -bool function floatCompareInRange(float arg1, float arg2, float tolerance) +bool function FloatsEqual( float arg1, float arg2, float epsilon ) { - if ( arg1 > arg2 - tolerance && arg1 < arg2 + tolerance) return true + if ( fabs( arg1 - arg2 ) < epsilon ) return true + return false } @@ -159,7 +165,7 @@ void function InitServerBrowserMenu() AddMenuFooterOption( file.menu, BUTTON_Y, PrependControllerPrompts( BUTTON_Y, "#REFRESH_SERVERS" ), "#REFRESH_SERVERS", RefreshServers ) // Setup server buttons - var width = 1120.0 * (GetScreenSize()[1] / 1080.0) + var width = 1120.0 * ( GetScreenSize()[1] / 1080.0 ) foreach ( var button in GetElementsByClassname( file.menu, "ServerButton" ) ) { AddButtonEventHandler( button, UIE_CLICK, OnServerButtonClicked ) @@ -206,20 +212,20 @@ void function InitServerBrowserMenu() // Hidden cause no need, if server descriptions become too long use this - Hud_SetEnabled( Hud_GetChild( file.menu, "BtnServerDescription"), false) - Hud_SetEnabled( Hud_GetChild( file.menu, "BtnServerMods"), false) - Hud_SetText( Hud_GetChild( file.menu, "BtnServerDescription"), "") - Hud_SetText( Hud_GetChild( file.menu, "BtnServerMods"), "") + Hud_SetEnabled( Hud_GetChild( file.menu, "BtnServerDescription"), false ) + Hud_SetEnabled( Hud_GetChild( file.menu, "BtnServerMods"), false ) + Hud_SetText( Hud_GetChild( file.menu, "BtnServerDescription"), "" ) + Hud_SetText( Hud_GetChild( file.menu, "BtnServerMods"), "" ) // Unfinished features Hud_SetLocked( Hud_GetChild( file.menu, "BtnServerLatencyTab" ), true ) // Rui is a pain - RuiSetString( Hud_GetRui( Hud_GetChild( file.menu, "SwtBtnHideFull")), "buttonText", "") - RuiSetString( Hud_GetRui( Hud_GetChild( file.menu, "SwtBtnHideEmpty")), "buttonText", "") - RuiSetString( Hud_GetRui( Hud_GetChild( file.menu, "SwtBtnHideProtected")), "buttonText", "") - RuiSetString( Hud_GetRui( Hud_GetChild( file.menu, "SwtBtnSelectMap")), "buttonText", "") - RuiSetString( Hud_GetRui( Hud_GetChild( file.menu, "SwtBtnSelectGamemode")), "buttonText", "") + RuiSetString( Hud_GetRui( Hud_GetChild( file.menu, "SwtBtnHideFull") ), "buttonText", "" ) + RuiSetString( Hud_GetRui( Hud_GetChild( file.menu, "SwtBtnHideEmpty") ), "buttonText", "" ) + RuiSetString( Hud_GetRui( Hud_GetChild( file.menu, "SwtBtnHideProtected") ), "buttonText", "" ) + RuiSetString( Hud_GetRui( Hud_GetChild( file.menu, "SwtBtnSelectMap") ), "buttonText", "" ) + RuiSetString( Hud_GetRui( Hud_GetChild( file.menu, "SwtBtnSelectGamemode") ), "buttonText", "" ) ToggleConnectingHUD(false) @@ -231,7 +237,7 @@ void function InitServerBrowserMenu() //////////////////////////// // Slider //////////////////////////// -void function UpdateMouseDeltaBuffer(int x, int y) +void function UpdateMouseDeltaBuffer( int x, int y ) { mouseDeltaBuffer.deltaX += x mouseDeltaBuffer.deltaY += y @@ -248,7 +254,7 @@ void function FlushMouseDeltaBuffer() void function SliderBarUpdate() { - if ( file.serversArrayFiltered.len() <= 15 ) + if ( file.serversArrayFiltered.len() <= BUTTONS_PER_PAGE ) { FlushMouseDeltaBuffer() return @@ -258,17 +264,17 @@ void function SliderBarUpdate() var sliderPanel = Hud_GetChild( file.menu , "BtnServerListSliderPanel" ) var movementCapture = Hud_GetChild( file.menu , "MouseMovementCapture" ) - Hud_SetFocused(sliderButton) + Hud_SetFocused( sliderButton ) - float minYPos = -40.0 * (GetScreenSize()[1] / 1080.0) - float maxHeight = 562.0 * (GetScreenSize()[1] / 1080.0) - float maxYPos = minYPos - (maxHeight - Hud_GetHeight( sliderPanel )) - float useableSpace = (maxHeight - Hud_GetHeight( sliderPanel )) + float minYPos = -40.0 * ( GetScreenSize()[1] / 1080.0 ) + float maxHeight = 562.0 * ( GetScreenSize()[1] / 1080.0 ) + float maxYPos = minYPos - ( maxHeight - Hud_GetHeight( sliderPanel ) ) + float useableSpace = ( maxHeight - Hud_GetHeight( sliderPanel ) ) - float jump = minYPos - (useableSpace / ( float( file.serversArrayFiltered.len()))) + float jump = minYPos - ( useableSpace / ( float( file.serversArrayFiltered.len() ) ) ) // got local from official respaw scripts, without untyped throws an error - local pos = Hud_GetPos(sliderButton)[1] + local pos = Hud_GetPos( sliderButton )[1] local newPos = pos - mouseDeltaBuffer.deltaY FlushMouseDeltaBuffer() @@ -279,7 +285,7 @@ void function SliderBarUpdate() Hud_SetPos( sliderPanel , 2, newPos ) Hud_SetPos( movementCapture , 2, newPos ) - file.scrollOffset = -int( ( (newPos - minYPos) / useableSpace ) * (file.serversArrayFiltered.len() - 15) ) + file.scrollOffset = -int( ( ( newPos - minYPos ) / useableSpace ) * ( file.serversArrayFiltered.len() - BUTTONS_PER_PAGE ) ) UpdateShownPage() } @@ -289,10 +295,10 @@ void function UpdateListSliderHeight( float servers ) var sliderPanel = Hud_GetChild( file.menu , "BtnServerListSliderPanel" ) var movementCapture = Hud_GetChild( file.menu , "MouseMovementCapture" ) - float maxHeight = 562.0 * (GetScreenSize()[1] / 1080.0) - float minHeight = 80.0 * (GetScreenSize()[1] / 1080.0) + float maxHeight = 562.0 * ( GetScreenSize()[1] / 1080.0 ) + float minHeight = 80.0 * ( GetScreenSize()[1] / 1080.0 ) - float height = maxHeight * (15.0 / servers ) + float height = maxHeight * ( BUTTONS_PER_PAGE / servers ) if ( height > maxHeight ) height = maxHeight if ( height < minHeight ) height = minHeight @@ -309,12 +315,10 @@ void function UpdateListSliderPosition( int servers ) var sliderPanel = Hud_GetChild( file.menu , "BtnServerListSliderPanel" ) var movementCapture = Hud_GetChild( file.menu , "MouseMovementCapture" ) - float minYPos = -40.0 * (GetScreenSize()[1] / 1080.0) - float useableSpace = (562.0 * (GetScreenSize()[1] / 1080.0) - Hud_GetHeight( sliderPanel )) + float minYPos = -40.0 * ( GetScreenSize()[1] / 1080.0 ) + float useableSpace = (562.0 * ( GetScreenSize()[1] / 1080.0 ) - Hud_GetHeight( sliderPanel ) ) - float jump = minYPos - (useableSpace / ( float( servers ) - 15.0 ) * file.scrollOffset) - - //jump = jump * (GetScreenSize()[1] / 1080.0) + float jump = minYPos - ( useableSpace / ( float( servers ) - BUTTONS_PER_PAGE ) * file.scrollOffset ) if ( jump > minYPos ) jump = minYPos @@ -325,7 +329,7 @@ void function UpdateListSliderPosition( int servers ) void function OnScrollDown( var button ) { - if (file.serversArrayFiltered.len() <= 15) return + if (file.serversArrayFiltered.len() <= BUTTONS_PER_PAGE) return file.scrollOffset += 5 if (file.scrollOffset + BUTTONS_PER_PAGE > file.serversArrayFiltered.len()) { file.scrollOffset = file.serversArrayFiltered.len() - BUTTONS_PER_PAGE @@ -337,7 +341,7 @@ void function OnScrollDown( var button ) void function OnScrollUp( var button ) { file.scrollOffset -= 5 - if (file.scrollOffset < 0) { + if ( file.scrollOffset < 0 ) { file.scrollOffset = 0 } UpdateShownPage() @@ -349,7 +353,7 @@ void function OnScrollUp( var button ) //////////////////////////// void function ToggleConnectingHUD( bool vis ) { - foreach (e in GetElementsByClassname(file.menu, "connectingHUD")) { + foreach (e in GetElementsByClassname( file.menu, "connectingHUD" ) ) { Hud_SetEnabled( e, vis ) Hud_SetVisible( e, vis ) } @@ -369,7 +373,7 @@ void function ConnectingButton_Activate( var button ) // This doesn't werk on some obscure resolutions, mostly really small 4:3 void function UpdateServerInfoBasedOnRes() { - if (floatCompareInRange(float(GetScreenSize()[0]) / float(GetScreenSize()[1]) , 1.6, 0.07)) // 16/10 + if ( FloatsEqual( float(GetScreenSize()[0] ) / float( GetScreenSize()[1] ) , 1.6, 0.07 ) ) // 16/10 { Hud_SetWidth( Hud_GetChild(file.menu, "ServerName"), 392) Hud_SetWidth( Hud_GetChild(file.menu, "NextMapImage"), 400) @@ -378,7 +382,7 @@ void function UpdateServerInfoBasedOnRes() Hud_SetWidth( Hud_GetChild(file.menu, "LabelDescription"), 360) Hud_SetWidth( Hud_GetChild(file.menu, "ServerDetailsPanel"), 400) } - if(floatCompareInRange(float(GetScreenSize()[0]) / float(GetScreenSize()[1]) , 1.3, 0.055)) // 4/3 + if( FloatsEqual( float( GetScreenSize()[0] ) / float( GetScreenSize()[1] ) , 1.3, 0.055 ) ) // 4/3 { Hud_SetWidth( Hud_GetChild(file.menu, "ServerName"), 292) Hud_SetWidth( Hud_GetChild(file.menu, "NextMapImage"), 300) @@ -396,19 +400,19 @@ void function OnCloseServerBrowserMenu() { try { - DeregisterButtonPressedCallback(MOUSE_WHEEL_UP , OnScrollUp) - DeregisterButtonPressedCallback(MOUSE_WHEEL_DOWN , OnScrollDown) - DeregisterButtonPressedCallback(KEY_TAB , OnKeyTabPressed) - DeregisterButtonPressedCallback(KEY_ENTER, OnEnterPressed) - DeregisterButtonPressedCallback(KEY_R, OnKeyRPressed) + DeregisterButtonPressedCallback( MOUSE_WHEEL_UP , OnScrollUp ) + DeregisterButtonPressedCallback( MOUSE_WHEEL_DOWN , OnScrollDown ) + DeregisterButtonPressedCallback( KEY_TAB , OnKeyTabPressed ) + DeregisterButtonPressedCallback( KEY_ENTER, OnEnterPressed ) + DeregisterButtonPressedCallback( KEY_R, OnKeyRPressed ) } catch ( ex ) {} } void function OnServerBrowserMenuOpened() { - Hud_SetText( Hud_GetChild( file.menu, "InGamePlayerLabel" ), Localize("#INGAME_PLAYERS", "0") ) - Hud_SetText( Hud_GetChild( file.menu, "TotalServerLabel" ), Localize("#TOTAL_SERVERS", "0") ) + Hud_SetText( Hud_GetChild( file.menu, "InGamePlayerLabel" ), Localize( "#INGAME_PLAYERS", "0" ) ) + Hud_SetText( Hud_GetChild( file.menu, "TotalServerLabel" ), Localize( "#TOTAL_SERVERS", "0" ) ) UpdatePrivateMatchModesAndMaps() Hud_SetText( Hud_GetChild( file.menu, "Title" ), "#MENU_TITLE_SERVER_BROWSER" ) UI_SetPresentationType( ePresentationType.KNOWLEDGEBASE_MAIN ) @@ -424,22 +428,23 @@ void function OnServerBrowserMenuOpened() thread WaitForServerListRequest() - RegisterButtonPressedCallback(MOUSE_WHEEL_UP , OnScrollUp) - RegisterButtonPressedCallback(MOUSE_WHEEL_DOWN , OnScrollDown) - RegisterButtonPressedCallback(KEY_TAB , OnKeyTabPressed) - RegisterButtonPressedCallback(KEY_ENTER, OnEnterPressed) - RegisterButtonPressedCallback(KEY_R, OnKeyRPressed) + RegisterButtonPressedCallback( MOUSE_WHEEL_UP , OnScrollUp ) + RegisterButtonPressedCallback( MOUSE_WHEEL_DOWN , OnScrollDown ) + RegisterButtonPressedCallback( KEY_TAB , OnKeyTabPressed ) + RegisterButtonPressedCallback( KEY_ENTER, OnEnterPressed ) + RegisterButtonPressedCallback( KEY_R, OnKeyRPressed ) } //////////////////////////// // Arrow navigation fuckery //////////////////////////// -bool function IsFilterPanelElementFocused() { +bool function IsFilterPanelElementFocused() +{ // get name of focused element - var focusedElement = GetFocus(); - var name = Hud_GetHudName(focusedElement); + var focusedElement = GetFocus() - foreach (element in GetElementsByClassname( file.menu, "FilterPanelChild")) { + foreach ( element in GetElementsByClassname( file.menu, "FilterPanelChild" ) ) + { if ( element == focusedElement ) return true } @@ -447,65 +452,78 @@ bool function IsFilterPanelElementFocused() { return false; } -void function OnKeyTabPressed(var button) { +void function OnKeyTabPressed( var button ) +{ try { // toggle focus between server list and filter panel - if (IsFilterPanelElementFocused()) { - Hud_SetFocused(Hud_GetChild(file.menu, "BtnServer1")) + if ( IsFilterPanelElementFocused() ) + { + Hud_SetFocused( Hud_GetChild( file.menu, "BtnServer1" ) ) } - else { - Hud_SetFocused(Hud_GetChild(file.menu, "BtnServerSearch")) + else + { + Hud_SetFocused( Hud_GetChild( file.menu, "BtnServerSearch" ) ) HideServerInfo() } } catch ( ex ) {} } -void function OnHitDummyTop(var button) { +void function OnHitDummyTop( var button ) +{ file.scrollOffset -= 1 - if (file.scrollOffset < 0) { + if ( file.scrollOffset < 0 ) + { // was at top already file.scrollOffset = 0 Hud_SetFocused(Hud_GetChild(file.menu, "BtnServerNameTab")) - } else { + } + else + { // only update if list position changed UpdateShownPage() UpdateListSliderPosition( file.serversArrayFiltered.len() ) - DisplayFocusedServerInfo(file.serverButtonFocusedID) - Hud_SetFocused(Hud_GetChild(file.menu, "BtnServer1")) + DisplayFocusedServerInfo( file.serverButtonFocusedID ) + Hud_SetFocused( Hud_GetChild( file.menu, "BtnServer1" ) ) } } -void function OnHitDummyBottom(var button) { +void function OnHitDummyBottom( var button ) +{ file.scrollOffset += 1 - if (file.scrollOffset + BUTTONS_PER_PAGE > file.serversArrayFiltered.len()) + if ( file.scrollOffset + BUTTONS_PER_PAGE > file.serversArrayFiltered.len() ) { // was at bottom already file.scrollOffset = file.serversArrayFiltered.len() - BUTTONS_PER_PAGE - Hud_SetFocused(Hud_GetChild(file.menu, "BtnServerSearch")) + Hud_SetFocused( Hud_GetChild( file.menu, "BtnServerSearch" ) ) HideServerInfo() - } else { + } + else + { // only update if list position changed UpdateShownPage() UpdateListSliderPosition( file.serversArrayFiltered.len() ) - DisplayFocusedServerInfo(file.serverButtonFocusedID) - Hud_SetFocused(Hud_GetChild(file.menu, "BtnServer15")) + DisplayFocusedServerInfo( file.serverButtonFocusedID ) + Hud_SetFocused( Hud_GetChild( file.menu, "BtnServer15" ) ) } } -void function OnHitDummyAfterFilterClear(var button) { - Hud_SetFocused(Hud_GetChild(file.menu, "BtnServerNameTab")) +void function OnHitDummyAfterFilterClear( var button ) +{ + Hud_SetFocused( Hud_GetChild( file.menu, "BtnServerNameTab" ) ) } void function OnDownArrowSelected( var button ) { - if (file.serversArrayFiltered.len() <= 15) return + if ( file.serversArrayFiltered.len() <= BUTTONS_PER_PAGE ) return file.scrollOffset += 1 - if (file.scrollOffset + BUTTONS_PER_PAGE > file.serversArrayFiltered.len()) { + if ( file.scrollOffset + BUTTONS_PER_PAGE > file.serversArrayFiltered.len() ) + { file.scrollOffset = file.serversArrayFiltered.len() - BUTTONS_PER_PAGE } + UpdateShownPage() UpdateListSliderPosition( file.serversArrayFiltered.len() ) } @@ -514,9 +532,11 @@ void function OnDownArrowSelected( var button ) void function OnUpArrowSelected( var button ) { file.scrollOffset -= 1 - if (file.scrollOffset < 0) { + if ( file.scrollOffset < 0 ) + { file.scrollOffset = 0 } + UpdateShownPage() UpdateListSliderPosition( file.serversArrayFiltered.len() ) } @@ -524,18 +544,18 @@ void function OnUpArrowSelected( var button ) //////////////////////// // Key Callbacks //////////////////////// -void function OnEnterPressed(arg) +void function OnEnterPressed( arg ) { // only trigger if a server is focused - if (IsServerButtonFocused()) + if ( IsServerButtonFocused() ) { OnServerSelected(0) } } -void function OnKeyRPressed(arg) +void function OnKeyRPressed( arg ) { - if (!IsSearchBarFocused()) + if ( !IsSearchBarFocused() ) { RefreshServers(0); } @@ -543,22 +563,24 @@ void function OnKeyRPressed(arg) bool function IsServerButtonFocused() { - var focusedElement = GetFocus(); - var name = Hud_GetHudName(focusedElement); + var focusedElement = GetFocus() + if ( focusedElement == null ) + return false + + var name = Hud_GetHudName( focusedElement ) - foreach (element in GetElementsByClassname( file.menu, "ServerButton")) + foreach ( element in GetElementsByClassname( file.menu, "ServerButton" ) ) { if ( element == focusedElement ) return true } - - return false; + return false } bool function IsSearchBarFocused() { - return Hud_GetChild( file.menu, "BtnServerSearch") == GetFocus() + return Hud_GetChild( file.menu, "BtnServerSearch" ) == GetFocus() } @@ -567,31 +589,32 @@ bool function IsSearchBarFocused() //////////////////////////// void function ShowServerDescription( var button ) { - Hud_SetVisible( Hud_GetChild( file.menu, "LabelDescription"), true) - Hud_SetVisible( Hud_GetChild( file.menu, "LabelMods"), false) + Hud_SetVisible( Hud_GetChild( file.menu, "LabelDescription" ), true ) + Hud_SetVisible( Hud_GetChild( file.menu, "LabelMods" ), false ) } void function ShowServerMods( var button ) { - Hud_SetVisible( Hud_GetChild( file.menu, "LabelDescription"), false) - Hud_SetVisible( Hud_GetChild( file.menu, "LabelMods"), true) + Hud_SetVisible( Hud_GetChild( file.menu, "LabelDescription" ), false ) + Hud_SetVisible( Hud_GetChild( file.menu, "LabelMods" ), true ) } //////////////////////////// // Server list; filter,update,... //////////////////////////// -void function HideServerInfo() { - Hud_SetVisible(Hud_GetChild(file.menu, "BtnServerDescription"), false) - Hud_SetVisible(Hud_GetChild(file.menu, "BtnServerMods"), false) - Hud_SetVisible(Hud_GetChild(file.menu, "BtnServerJoin"), false) - Hud_SetVisible(Hud_GetChild(file.menu, "LabelDescription"), false) - Hud_SetVisible(Hud_GetChild(file.menu, "LabelMods"), false) - Hud_SetVisible(Hud_GetChild(file.menu, "NextMapImage"), false) - Hud_SetVisible(Hud_GetChild(file.menu, "NextMapBack"), false) - Hud_SetVisible(Hud_GetChild(file.menu, "NextMapName"), false) - Hud_SetVisible(Hud_GetChild(file.menu, "ServerName"), false) - Hud_SetVisible(Hud_GetChild(file.menu, "NextModeIcon"), false) - Hud_SetVisible(Hud_GetChild(file.menu, "NextGameModeName"), false) +void function HideServerInfo() +{ + Hud_SetVisible( Hud_GetChild( file.menu, "BtnServerDescription" ), false ) + Hud_SetVisible( Hud_GetChild( file.menu, "BtnServerMods" ), false ) + Hud_SetVisible( Hud_GetChild( file.menu, "BtnServerJoin" ), false ) + Hud_SetVisible( Hud_GetChild( file.menu, "LabelDescription" ), false ) + Hud_SetVisible( Hud_GetChild( file.menu, "LabelMods" ), false ) + Hud_SetVisible( Hud_GetChild( file.menu, "NextMapImage" ), false ) + Hud_SetVisible( Hud_GetChild( file.menu, "NextMapBack" ), false ) + Hud_SetVisible( Hud_GetChild( file.menu, "NextMapName" ), false ) + Hud_SetVisible( Hud_GetChild( file.menu, "ServerName" ), false ) + Hud_SetVisible( Hud_GetChild( file.menu, "NextModeIcon" ), false ) + Hud_SetVisible( Hud_GetChild( file.menu, "NextGameModeName" ), false ) } void function OnBtnFiltersClear_Activate( var button ) @@ -677,8 +700,7 @@ void function RefreshServers( var button ) void function WaitForServerListRequest() { - - for ( int i = 0; i < 15; i++) + for ( int i = 0; i < BUTTONS_PER_PAGE; i++) { Hud_SetVisible( file.serversProtected[ i ], false ) Hud_SetVisible( file.serverButtons[ i ], false ) @@ -689,12 +711,9 @@ void function WaitForServerListRequest() Hud_SetText( file.serversLatency[ i ], "" ) } - HideServerInfo() - Hud_SetVisible( file.serversName[ 0 ], true ) - Hud_SetText( file.serversName[ 0 ], "#NS_SERVERBROWSER_WAITINGFORSERVERS" ) // wait for request to complete @@ -709,7 +728,7 @@ void function WaitForServerListRequest() else { FilterAndUpdateList(0) - Hud_SetFocused(Hud_GetChild(file.menu, "BtnServer1")) + Hud_SetFocused( Hud_GetChild(file.menu, "BtnServer1" ) ) } } @@ -735,21 +754,21 @@ void function FilterServerList() // Branchless programming ;) - if (!(filterArguments.hideEmpty && tempServer.serverPlayers == 0) && !(filterArguments.hideFull && tempServer.serverPlayers == tempServer.serverPlayersMax) && !(filterArguments.hideProtected && tempServer.serverProtected)) + if ( !( filterArguments.hideEmpty && tempServer.serverPlayers == 0 ) && !( filterArguments.hideFull && tempServer.serverPlayers == tempServer.serverPlayersMax ) && !( filterArguments.hideProtected && tempServer.serverProtected ) ) { if ( filterArguments.useSearch ) { - string sName = tempServer.serverName.tolower() + " " + Localize(GetMapDisplayName(tempServer.serverMap)).tolower() + " " + tempServer.serverMap.tolower() + " " + tempServer.serverGamemode.tolower() + " " + Localize(tempServer.serverGamemode).tolower() + string sName = tempServer.serverName.tolower() + " " + Localize( GetMapDisplayName( tempServer.serverMap ) ).tolower() + " " + tempServer.serverMap.tolower() + " " + tempServer.serverGamemode.tolower() + " " + Localize( tempServer.serverGamemode ).tolower() string sTerm = filterArguments.searchTerm.tolower() - if ( sName.find(sTerm) != null) + if ( sName.find( sTerm ) != null) { - if (filterArguments.filterMap != "SWITCH_ANY" && filterArguments.filterMap == tempServer.serverMap) + if ( filterArguments.filterMap != "SWITCH_ANY" && filterArguments.filterMap == tempServer.serverMap ) { CheckGamemode( tempServer ) } - else if (filterArguments.filterMap == "SWITCH_ANY") + else if ( filterArguments.filterMap == "SWITCH_ANY" ) { CheckGamemode( tempServer ) } @@ -757,28 +776,28 @@ void function FilterServerList() } else { - if (filterArguments.filterMap != "SWITCH_ANY" && filterArguments.filterMap == tempServer.serverMap) + if ( filterArguments.filterMap != "SWITCH_ANY" && filterArguments.filterMap == tempServer.serverMap ) { CheckGamemode( tempServer ) } - else if (filterArguments.filterMap == "SWITCH_ANY") + else if ( filterArguments.filterMap == "SWITCH_ANY" ) { CheckGamemode( tempServer ) } } } - Hud_SetText( Hud_GetChild( file.menu, "InGamePlayerLabel" ), Localize("#INGAME_PLAYERS", string(totalPlayers)) ) - Hud_SetText( Hud_GetChild( file.menu, "TotalServerLabel" ), Localize("#TOTAL_SERVERS", string( NSGetServerCount()) ) ) + Hud_SetText( Hud_GetChild( file.menu, "InGamePlayerLabel" ), Localize("#INGAME_PLAYERS", string( totalPlayers ) ) ) + Hud_SetText( Hud_GetChild( file.menu, "TotalServerLabel" ), Localize("#TOTAL_SERVERS", string( NSGetServerCount() ) ) ) } } void function CheckGamemode( serverStruct t ) { - if (filterArguments.filterGamemode != "SWITCH_ANY" && filterArguments.filterGamemode == t.serverGamemode) + if ( filterArguments.filterGamemode != "SWITCH_ANY" && filterArguments.filterGamemode == t.serverGamemode ) { file.serversArrayFiltered.append( t ) } - else if (filterArguments.filterGamemode == "SWITCH_ANY") + else if ( filterArguments.filterGamemode == "SWITCH_ANY" ) { file.serversArrayFiltered.append( t ) } @@ -788,7 +807,7 @@ void function CheckGamemode( serverStruct t ) void function UpdateShownPage() { - for ( int i = 0; i < 15; i++) + for ( int i = 0; i < BUTTONS_PER_PAGE; i++ ) { Hud_SetVisible( file.serversProtected[ i ], false ) Hud_SetVisible( file.serverButtons[ i ], false ) @@ -799,7 +818,7 @@ void function UpdateShownPage() Hud_SetText( file.serversLatency[ i ], "" ) } - int j = file.serversArrayFiltered.len() > 15 ? 15 : file.serversArrayFiltered.len() + int j = file.serversArrayFiltered.len() > BUTTONS_PER_PAGE ? BUTTONS_PER_PAGE : file.serversArrayFiltered.len() for ( int i = 0; i < j; i++ ) { @@ -829,26 +848,26 @@ void function UpdateShownPage() void function OnServerButtonFocused( var button ) { - if (file.scrollOffset < 0) + if ( file.scrollOffset < 0 ) file.scrollOffset = 0 - int scriptID = int (Hud_GetScriptID(button)) + int scriptID = int ( Hud_GetScriptID( button ) ) file.serverButtonFocusedID = scriptID if ( file.serversArrayFiltered.len() > 0 ) file.focusedServerIndex = file.serversArrayFiltered[ file.scrollOffset + scriptID ].serverIndex - DisplayFocusedServerInfo(scriptID); + DisplayFocusedServerInfo( scriptID ) } void function OnServerButtonClicked(var button) { - int scriptID = int (Hud_GetScriptID(button)) + int scriptID = int ( Hud_GetScriptID( button ) ) - DisplayFocusedServerInfo(scriptID) - CheckDoubleClick(scriptID, true) + DisplayFocusedServerInfo( scriptID ) + CheckDoubleClick( scriptID, true ) } -void function CheckDoubleClick(int scriptID, bool wasClickNav) +void function CheckDoubleClick( int scriptID, bool wasClickNav ) { if ( NSGetServerCount() == 0 ) return @@ -856,34 +875,31 @@ void function CheckDoubleClick(int scriptID, bool wasClickNav) int serverIndex = file.scrollOffset + scriptID bool sameServer = false - if (file.lastSelectedServer == serverIndex) sameServer = true + if ( file.lastSelectedServer == serverIndex ) sameServer = true file.serverSelectedTimeLast = file.serverSelectedTime file.serverSelectedTime = Time() - printt(file.serverSelectedTime - file.serverSelectedTimeLast, file.lastSelectedServer, serverIndex) - file.lastSelectedServer = serverIndex - - if (wasClickNav && (file.serverSelectedTime - file.serverSelectedTimeLast < DOUBLE_CLICK_TIME_MS) && sameServer) + if ( wasClickNav && ( file.serverSelectedTime - file.serverSelectedTimeLast < DOUBLE_CLICK_TIME_MS ) && sameServer ) { OnServerSelected(0) } } -void function DisplayFocusedServerInfo( int scriptID) +void function DisplayFocusedServerInfo( int scriptID ) { - if (scriptID == 999 || scriptID == -1 || scriptID == 16) return + if ( scriptID == 999 || scriptID == -1 || scriptID == 16 ) return - if ( NSIsRequestingServerList() || NSGetServerCount() == 0 || file.serverListRequestFailed || file.serversArrayFiltered.len() == 0) + if ( NSIsRequestingServerList() || NSGetServerCount() == 0 || file.serverListRequestFailed || file.serversArrayFiltered.len() == 0 ) return var menu = GetMenu( "ServerBrowserMenu" ) int serverIndex = file.scrollOffset + scriptID - if (serverIndex < 0) serverIndex = 0 + if ( serverIndex < 0 ) serverIndex = 0 Hud_SetVisible( Hud_GetChild( menu, "BtnServerDescription" ), true ) @@ -892,7 +908,7 @@ void function DisplayFocusedServerInfo( int scriptID) // text panels Hud_SetVisible( Hud_GetChild( menu, "LabelDescription" ), true ) Hud_SetVisible( Hud_GetChild( menu, "LabelMods" ), false ) - Hud_SetText( Hud_GetChild( menu, "LabelDescription" ), NSGetServerDescription( file.serversArrayFiltered[ serverIndex ].serverIndex ) + "\n\nRequired Mods:\n" + FillInServerModsLabel( file.serversArrayFiltered[ serverIndex ].serverIndex )) + Hud_SetText( Hud_GetChild( menu, "LabelDescription" ), NSGetServerDescription( file.serversArrayFiltered[ serverIndex ].serverIndex ) + "\n\nRequired Mods:\n" + FillInServerModsLabel( file.serversArrayFiltered[ serverIndex ].serverIndex ) ) // map name/image/server name string map = file.serversArrayFiltered[ serverIndex ].serverMap @@ -1019,33 +1035,33 @@ void function ThreadedAuthAndConnectToServer( string password = "" ) ToggleConnectingHUD( true ) - while ( NSIsAuthenticatingWithServer() && !file.cancelConnection) + while ( NSIsAuthenticatingWithServer() && !file.cancelConnection ) { WaitFrame() } ToggleConnectingHUD( false ) - if (file.cancelConnection) + if ( file.cancelConnection ) { file.cancelConnection = false // re-focus server list - Hud_SetFocused( Hud_GetChild( file.menu, "BtnServer" + (file.serverButtonFocusedID + 1)) ) + Hud_SetFocused( Hud_GetChild( file.menu, "BtnServer" + ( file.serverButtonFocusedID + 1 ) ) ) return } file.cancelConnection = false - NSSetLoading(true) + NSSetLoading( true ) NSUpdateServerInfo( - NSGetServerID(file.lastSelectedServer), - NSGetServerName(file.lastSelectedServer), + 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))) + NSGetServerPlayerCount( file.lastSelectedServer ), + NSGetServerMaxPlayerCount( file.lastSelectedServer ), + NSGetServerMap( file.lastSelectedServer ), + Localize( GetMapDisplayName( NSGetServerMap( file.lastSelectedServer ) ) ), + NSGetServerPlaylist( file.lastSelectedServer ), + Localize( GetPlaylistDisplayName( NSGetServerPlaylist( file.lastSelectedServer ) ) ) ) if ( NSWasAuthSuccessful() ) @@ -1093,7 +1109,7 @@ void function ThreadedAuthAndConnectToServer( string password = "" ) ////////////////////////////////////// // Shadow realm ////////////////////////////////////// -int function ServerSortLogic ( serverStruct a, serverStruct b) +int function ServerSortLogic ( serverStruct a, serverStruct b ) { var aTemp var bTemp @@ -1101,7 +1117,8 @@ int function ServerSortLogic ( serverStruct a, serverStruct b) bool direction // We can hard code this cause adding entire columns isn't as easy - switch ( filterDirection.sortingBy ) { + switch ( filterDirection.sortingBy ) + { case sortingBy.NAME: aTemp = a.serverName.tolower() bTemp = b.serverName.tolower() @@ -1113,13 +1130,13 @@ int function ServerSortLogic ( serverStruct a, serverStruct b) direction = filterDirection.serverPlayers break; case sortingBy.MAP: - aTemp = Localize(a.serverMap).tolower() - bTemp = Localize(b.serverMap).tolower() + aTemp = Localize( a.serverMap ).tolower() + bTemp = Localize( b.serverMap ).tolower() direction = filterDirection.serverMap break; case sortingBy.GAMEMODE: - aTemp = Localize(a.serverGamemode).tolower() - bTemp = Localize(b.serverGamemode).tolower() + aTemp = Localize( a.serverGamemode ).tolower() + bTemp = Localize( b.serverGamemode ).tolower() direction = filterDirection.serverGamemode break; case sortingBy.LATENCY: |