diff options
Diffstat (limited to 'Northstar.Client/mod/scripts/vscripts/ui')
-rw-r--r-- | Northstar.Client/mod/scripts/vscripts/ui/menu_ns_connect_password.nut | 42 | ||||
-rw-r--r-- | Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut | 257 |
2 files changed, 154 insertions, 145 deletions
diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_connect_password.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_connect_password.nut index e1ed8991..56db0ccc 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_connect_password.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_connect_password.nut @@ -1,5 +1,13 @@ global function AddNorthstarConnectWithPasswordMenu +struct +{ + var menu + var enterPasswordBox + var enterPasswordDummy + var connectButton +} file + void function AddNorthstarConnectWithPasswordMenu() { AddMenu( "ConnectWithPasswordMenu", $"resource/ui/menus/connect_password.menu", InitConnectWithPasswordMenu, "#MENU_CONNECT" ) @@ -7,24 +15,42 @@ void function AddNorthstarConnectWithPasswordMenu() void function InitConnectWithPasswordMenu() { - AddMenuEventHandler( GetMenu( "ConnectWithPasswordMenu" ), eUIEvent.MENU_OPEN, OnConnectWithPasswordMenuOpened ) - AddMenuFooterOption( GetMenu( "ConnectWithPasswordMenu" ), BUTTON_B, "#B_BUTTON_BACK", "#BACK" ) + file.menu = GetMenu( "ConnectWithPasswordMenu" ) + + file.enterPasswordBox = Hud_GetChild( file.menu, "EnterPasswordBox") + file.enterPasswordDummy = Hud_GetChild( file.menu, "EnterPasswordBoxDummy") + file.connectButton = Hud_GetChild( file.menu, "ConnectButton") + + AddMenuEventHandler( file.menu, eUIEvent.MENU_OPEN, OnConnectWithPasswordMenuOpened ) + AddMenuFooterOption( file.menu, BUTTON_B, "#B_BUTTON_BACK", "#BACK" ) + + AddButtonEventHandler( file.connectButton, UIE_CLICK, ConnectWithPassword ) + + AddButtonEventHandler( file.enterPasswordBox, UIE_CHANGE, UpdatePasswordLabel ) - AddButtonEventHandler( Hud_GetChild( GetMenu( "ConnectWithPasswordMenu" ), "ConnectButton" ), UIE_CLICK, ConnectWithPassword ) RegisterButtonPressedCallback( KEY_ENTER, ConnectWithPassword ) } +void function UpdatePasswordLabel( var n ) +{ + string hiddenPSWD + for ( int i = 0; i < Hud_GetUTF8Text( file.enterPasswordBox ).len(); i++) + hiddenPSWD += "*" + Hud_SetText( file.enterPasswordDummy, hiddenPSWD ) +} + void function OnConnectWithPasswordMenuOpened() { UI_SetPresentationType( ePresentationType.KNOWLEDGEBASE_SUB ) - Hud_SetText( Hud_GetChild( GetMenu( "ConnectWithPasswordMenu" ), "Title" ), "#MENU_TITLE_CONNECT_PASSWORD" ) - Hud_SetText( Hud_GetChild( GetMenu( "ConnectWithPasswordMenu" ), "ConnectButton" ), "#MENU_CONNECT_MENU_CONNECT" ) - Hud_SetText( Hud_GetChild( GetMenu( "ConnectWithPasswordMenu" ), "EnterPasswordBox" ), "" ) + Hud_SetText( Hud_GetChild( file.menu, "Title" ), "#MENU_TITLE_CONNECT_PASSWORD" ) + Hud_SetText( file.connectButton, "#MENU_CONNECT_MENU_CONNECT" ) + Hud_SetText( file.enterPasswordBox, "" ) + Hud_SetText( file.enterPasswordDummy, "" ) } void function ConnectWithPassword( var button ) { - if ( GetTopNonDialogMenu() == GetMenu( "ConnectWithPasswordMenu" ) ) - thread ThreadedAuthAndConnectToServer( Hud_GetUTF8Text( Hud_GetChild( GetMenu( "ConnectWithPasswordMenu" ), "EnterPasswordBox" ) ) ) + if ( GetTopNonDialogMenu() == file.menu ) + thread ThreadedAuthAndConnectToServer( Hud_GetUTF8Text( Hud_GetChild( file.menu, "EnterPasswordBox" ) ) ) }
\ No newline at end of file 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 7c3e2fae..437a8cf2 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut @@ -4,12 +4,11 @@ untyped global function AddNorthstarServerBrowserMenu global function ThreadedAuthAndConnectToServer -global function UpdateMouseDeltaBuffer // Stop peeking const int BUTTONS_PER_PAGE = 15 -const float DOUBLE_CLICK_TIME_MS = 0.2 // unsure what the ideal value is +const float DOUBLE_CLICK_TIME_MS = 0.3 // unsure what the ideal value is struct { @@ -29,6 +28,17 @@ struct { string filterGamemode } filterArguments + +enum sortingBy +{ + NONE, + NAME, + PLAYERS, + MAP, + GAMEMODE, + LATENCY +} + struct { // true = alphabeticaly false = reverse bool serverName = true @@ -100,22 +110,22 @@ void function UpdatePrivateMatchModesAndMaps() { if ( filterArguments.filterMaps.find( map ) != -1 ) continue - + filterArguments.filterMaps.append( map ) - + string localized = GetMapDisplayName( map ) Hud_DialogList_AddListItem( Hud_GetChild( file.menu, "SwtBtnSelectMap" ) , localized, string( enum_ + 1 ) ) - } - + } + array<string> realModes = [ "private_match" ] realModes.extend( GetPrivateMatchModes() ) - + foreach( int enum_, string mode in realModes ) { string localized = GetGameModeDisplayName( mode ) if ( filterArguments.filterGamemodes.find( localized ) != -1 ) continue - + filterArguments.filterGamemodes.append( localized ) Hud_DialogList_AddListItem( Hud_GetChild( file.menu, "SwtBtnSelectGamemode" ) , localized, string( enum_ + 1 ) ) } @@ -125,6 +135,8 @@ void function InitServerBrowserMenu() { file.menu = GetMenu( "ServerBrowserMenu" ) + AddMouseMovementCaptureHandler( file.menu, UpdateMouseDeltaBuffer ) + // Get menu stuff file.serverButtons = GetElementsByClassname( file.menu, "ServerButton" ) file.serversName = GetElementsByClassname( file.menu, "ServerName" ) @@ -136,7 +148,7 @@ void function InitServerBrowserMenu() filterArguments.filterMaps = [ "SWITCH_ANY" ] Hud_DialogList_AddListItem( Hud_GetChild( file.menu, "SwtBtnSelectMap" ), "SWITCH_ANY", "0" ) - + filterArguments.filterGamemodes = [ "SWITCH_ANY" ] Hud_DialogList_AddListItem( Hud_GetChild( file.menu, "SwtBtnSelectGamemode" ), "SWITCH_ANY", "0" ) @@ -171,11 +183,11 @@ void function InitServerBrowserMenu() AddButtonEventHandler( Hud_GetChild( file.menu, "BtnFiltersClear"), UIE_CLICK, OnBtnFiltersClear_Activate ) - AddButtonEventHandler( Hud_GetChild( file.menu, "BtnServerNameTab"), UIE_CLICK, SortServerListByName ) - AddButtonEventHandler( Hud_GetChild( file.menu, "BtnServerPlayersTab"), UIE_CLICK, SortServerListByPlayers ) - AddButtonEventHandler( Hud_GetChild( file.menu, "BtnServerMapTab"), UIE_CLICK, SortServerListByMap ) - AddButtonEventHandler( Hud_GetChild( file.menu, "BtnServerGamemodeTab"), UIE_CLICK, SortServerListByGamemode ) - AddButtonEventHandler( Hud_GetChild( file.menu, "BtnServerLatencyTab"), UIE_CLICK, SortServerListByLatency ) + AddButtonEventHandler( Hud_GetChild( file.menu, "BtnServerNameTab"), UIE_CLICK, SortServerListByName_Activate ) + AddButtonEventHandler( Hud_GetChild( file.menu, "BtnServerPlayersTab"), UIE_CLICK, SortServerListByPlayers_Activate ) + AddButtonEventHandler( Hud_GetChild( file.menu, "BtnServerMapTab"), UIE_CLICK, SortServerListByMap_Activate ) + AddButtonEventHandler( Hud_GetChild( file.menu, "BtnServerGamemodeTab"), UIE_CLICK, SortServerListByGamemode_Activate ) + AddButtonEventHandler( Hud_GetChild( file.menu, "BtnServerLatencyTab"), UIE_CLICK, SortServerListByLatency_Activate ) AddButtonEventHandler( Hud_GetChild( file.menu, "SwtBtnSelectMap"), UIE_CHANGE, FilterAndUpdateList ) @@ -278,10 +290,12 @@ void function UpdateListSliderHeight( float servers ) var movementCapture = Hud_GetChild( file.menu , "MouseMovementCapture" ) float maxHeight = 562.0 * (GetScreenSize()[1] / 1080.0) + float minHeight = 80.0 * (GetScreenSize()[1] / 1080.0) float height = maxHeight * (15.0 / servers ) if ( height > maxHeight ) height = maxHeight + if ( height < minHeight ) height = minHeight Hud_SetHeight( sliderButton , height ) Hud_SetHeight( sliderPanel , height ) @@ -419,36 +433,29 @@ bool function IsFilterPanelElementFocused() { var focusedElement = GetFocus(); var name = Hud_GetHudName(focusedElement); - print(name) - - // kinda sucks but just check if any of the filter elements - // has focus. would be nice to have tags or sth here - bool match = (name == "FilterPanel") || - (name == "BtnSearchLabel") || - (name == "BtnServerSearch") || - (name == "SwtBtnSelectMap") || - (name == "SwtBtnSelectGamemode") || - (name == "SwtBtnHideFull") || - (name == "SwtBtnHideEmpty") || - (name == "SwtBtnHideProtected") || - (name == "BtnFiltersClear") || - (name == "BtnDummyAfterFilterClear"); + foreach (element in GetElementsByClassname( file.menu, "FilterPanelChild")) { + if ( element == focusedElement ) return true + } - return match; + return false; } void function OnKeyTabPressed(var button) { - // toggle focus between server list and filter panel - if (IsFilterPanelElementFocused()) { - // print("Switching focus from filter panel to server list") - Hud_SetFocused(Hud_GetChild(file.menu, "BtnServer1")) - } - else { - // print("Switching focus from server list to filter panel") - Hud_SetFocused(Hud_GetChild(file.menu, "BtnServerSearch")) - HideServerInfo() + try + { + // toggle focus between server list and filter panel + if (IsFilterPanelElementFocused()) { + // print("Switching focus from filter panel to server list") + Hud_SetFocused(Hud_GetChild(file.menu, "BtnServer1")) + } + else { + // print("Switching focus from server list to filter panel") + Hud_SetFocused(Hud_GetChild(file.menu, "BtnServerSearch")) + HideServerInfo() + } } + catch ( ex ) {} } void function OnHitDummyTop(var button) { @@ -570,30 +577,31 @@ void function FilterAndUpdateList( var n ) FilterServerList() + switch ( filterDirection.sortingBy ) { - case 0: + case sortingBy.NONE: UpdateShownPage() break - case 1: + case sortingBy.NAME: filterDirection.serverName = !filterDirection.serverName - SortServerListByName(0) + SortServerListByName_Activate(0) break - case 2: + case sortingBy.PLAYERS: filterDirection.serverPlayers = !filterDirection.serverPlayers - SortServerListByPlayers(0) + SortServerListByPlayers_Activate(0) break - case 3: + case sortingBy.MAP: filterDirection.serverMap = !filterDirection.serverMap - SortServerListByMap(0) + SortServerListByMap_Activate(0) break - case 5: // 4 skipped cause it doesn't work respawn pls fix + case sortingBy.GAMEMODE: filterDirection.serverGamemode = !filterDirection.serverGamemode - SortServerListByGamemode(0) + SortServerListByGamemode_Activate(0) break - case 6: + case sortingBy.LATENCY: filterDirection.serverLatency = !filterDirection.serverLatency - SortServerListByLatency(0) + SortServerListByLatency_Activate(0) break default: printt( "How the f did you get here" ) @@ -1021,130 +1029,105 @@ void function ThreadedAuthAndConnectToServer( string password = "" ) ////////////////////////////////////// // Shadow realm ////////////////////////////////////// -void function SortServerListByName( var button ) +int function ServerSortLogic ( serverStruct a, serverStruct b) { - filterDirection.sortingBy = 1 + var aTemp + var bTemp + + bool direction + + // We can hard code this cause adding entire columns isn't as easy + switch ( filterDirection.sortingBy ) { + case sortingBy.NAME: + aTemp = a.serverName.tolower() + bTemp = b.serverName.tolower() + direction = filterDirection.serverName + break; + case sortingBy.PLAYERS: + aTemp = a.serverPlayers + bTemp = b.serverPlayers + direction = filterDirection.serverPlayers + break; + case sortingBy.MAP: + 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() + direction = filterDirection.serverGamemode + break; + case sortingBy.LATENCY: + aTemp = a.serverLatency + bTemp = b.serverLatency + direction = filterDirection.serverLatency + break; + default: + return 0 + } - int n = file.serversArrayFiltered.len() - 1 + int invert = direction == true ? 1 : -1 - serverStruct tempServer + if ( aTemp > bTemp ) + return 1 * invert - for ( int i = 0; i < n; i++) - { - for ( int j = 0; j < n - 1; j++) - { - if ( file.serversArrayFiltered[ j ].serverName < file.serversArrayFiltered[ j + 1 ].serverName && filterDirection.serverName || file.serversArrayFiltered[ j ].serverName > file.serversArrayFiltered[ j + 1 ].serverName && !filterDirection.serverName) - { - tempServer = file.serversArrayFiltered[ j ] - file.serversArrayFiltered[ j ] = file.serversArrayFiltered[ j + 1 ] - file.serversArrayFiltered[ j + 1 ] = tempServer - } - } - } + if ( aTemp < bTemp ) + return -1 * invert + + return 0 +} + +void function SortServerListByName_Activate ( var button ) +{ + filterDirection.sortingBy = sortingBy.NAME + + file.serversArrayFiltered.sort( ServerSortLogic ) filterDirection.serverName = !filterDirection.serverName UpdateShownPage() } -void function SortServerListByPlayers( var button ) -{ - filterDirection.sortingBy = 2 - int n = file.serversArrayFiltered.len() - 1 +void function SortServerListByPlayers_Activate( var button ) +{ + filterDirection.sortingBy = sortingBy.PLAYERS - serverStruct tempServer - - for ( int i = 0; i < n; i++) - { - for ( int j = 0; j < n - 1; j++) - { - if ( file.serversArrayFiltered[ j ].serverPlayers < file.serversArrayFiltered[ j + 1 ].serverPlayers && filterDirection.serverPlayers || file.serversArrayFiltered[ j ].serverPlayers > file.serversArrayFiltered[ j + 1 ].serverPlayers && !filterDirection.serverPlayers) - { - tempServer = file.serversArrayFiltered[ j ] - file.serversArrayFiltered[ j ] = file.serversArrayFiltered[ j + 1 ] - file.serversArrayFiltered[ j + 1 ] = tempServer - } - } - } + file.serversArrayFiltered.sort( ServerSortLogic ) filterDirection.serverPlayers = !filterDirection.serverPlayers UpdateShownPage() } -void function SortServerListByMap( var button ) +void function SortServerListByMap_Activate( var button ) { - filterDirection.sortingBy = 3 - - int n = file.serversArrayFiltered.len() - 1 + filterDirection.sortingBy = sortingBy.MAP - serverStruct tempServer - - for ( int i = 0; i < n; i++) - { - for ( int j = 0; j < n - 1; j++) - { - if ( Localize(file.serversArrayFiltered[ j ].serverMap) < Localize(file.serversArrayFiltered[ j + 1 ].serverMap) && filterDirection.serverMap || Localize(file.serversArrayFiltered[ j ].serverMap) > Localize(file.serversArrayFiltered[ j + 1 ].serverMap) && !filterDirection.serverMap) - { - tempServer = file.serversArrayFiltered[ j ] - file.serversArrayFiltered[ j ] = file.serversArrayFiltered[ j + 1 ] - file.serversArrayFiltered[ j + 1 ] = tempServer - } - } - } + file.serversArrayFiltered.sort( ServerSortLogic ) filterDirection.serverMap = !filterDirection.serverMap UpdateShownPage() } -void function SortServerListByGamemode( var button ) +void function SortServerListByGamemode_Activate( var button ) { - filterDirection.sortingBy = 5 - - int n = file.serversArrayFiltered.len() - 1 - - serverStruct tempServer + filterDirection.sortingBy = sortingBy.GAMEMODE - for ( int i = 0; i < n; i++) - { - for ( int j = 0; j < n - 1; j++) - { - if ( Localize(file.serversArrayFiltered[ j ].serverGamemode) < Localize(file.serversArrayFiltered[ j + 1 ].serverGamemode) && filterDirection.serverGamemode || Localize(file.serversArrayFiltered[ j ].serverGamemode) > Localize(file.serversArrayFiltered[ j + 1 ].serverGamemode) && !filterDirection.serverGamemode) - { - tempServer = file.serversArrayFiltered[ j ] - file.serversArrayFiltered[ j ] = file.serversArrayFiltered[ j + 1 ] - file.serversArrayFiltered[ j + 1 ] = tempServer - } - } - } + file.serversArrayFiltered.sort( ServerSortLogic ) filterDirection.serverGamemode = !filterDirection.serverGamemode UpdateShownPage() } -void function SortServerListByLatency( var button ) +void function SortServerListByLatency_Activate( var button ) { - filterDirection.sortingBy = 5 + filterDirection.sortingBy = sortingBy.LATENCY - int n = file.serversArrayFiltered.len() - 1 - - serverStruct tempServer - - for ( int i = 0; i < n; i++) - { - for ( int j = 0; j < n - 1; j++) - { - if ( file.serversArrayFiltered[ j ].serverLatency < file.serversArrayFiltered[ j + 1 ].serverLatency && filterDirection.serverLatency || file.serversArrayFiltered[ j ].serverLatency > file.serversArrayFiltered[ j + 1 ].serverLatency && !filterDirection.serverLatency) - { - tempServer = file.serversArrayFiltered[ j ] - file.serversArrayFiltered[ j ] = file.serversArrayFiltered[ j + 1 ] - file.serversArrayFiltered[ j + 1 ] = tempServer - } - } - } + file.serversArrayFiltered.sort( ServerSortLogic ) filterDirection.serverLatency = !filterDirection.serverLatency |