From 44894dfde583f7fb3a4491b4f17893a907336d1f Mon Sep 17 00:00:00 2001 From: Emma Miler <27428383+emma-miler@users.noreply.github.com> Date: Fri, 29 Apr 2022 23:28:41 +0200 Subject: Add default sort method for server browser (#303) * Add default sort method * Do gecko's change * Fixed it * Set default sort mode when opening browser * Update Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut Co-authored-by: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> * remove trailing space <3 gecko Co-authored-by: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> --- .../scripts/vscripts/ui/menu_ns_serverbrowser.nut | 39 ++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'Northstar.Client/mod/scripts/vscripts') 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 c77000e9..5f6cda1a 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut @@ -33,6 +33,7 @@ struct { enum sortingBy { NONE, + DEFAULT, NAME, PLAYERS, MAP, @@ -48,8 +49,8 @@ struct { bool serverMap = true bool serverGamemode = true bool serverLatency = true - // 0 = none; 1 = name; 2 = players; 3 = map; 5 = gamemode; 6 = latency - int sortingBy = 0 + // 0 = none; 1 = default; 2 = name; 3 = players; 4 = map; 5 = gamemode; 6 = latency + int sortingBy = 1 } filterDirection struct serverStruct { @@ -425,6 +426,8 @@ void function OnServerBrowserMenuOpened() NSRequestServerList() } + filterDirection.sortingBy = sortingBy.DEFAULT + thread WaitForServerListRequest() @@ -652,6 +655,10 @@ void function FilterAndUpdateList( var n ) case sortingBy.NONE: UpdateShownPage() break + case sortingBy.DEFAULT: + filterDirection.serverName = !filterDirection.serverName + SortServerListByDefault_Activate(0) + break case sortingBy.NAME: filterDirection.serverName = !filterDirection.serverName SortServerListByName_Activate(0) @@ -1119,6 +1126,22 @@ int function ServerSortLogic ( serverStruct a, serverStruct b ) // We can hard code this cause adding entire columns isn't as easy switch ( filterDirection.sortingBy ) { + case sortingBy.DEFAULT: + aTemp = a.serverPlayers + bTemp = b.serverPlayers + + // `1000` is assumed to always be higher than `serverPlayersMax` + if (aTemp + 1 < a.serverPlayersMax) + aTemp = aTemp+2000 + if (bTemp + 1 < b.serverPlayersMax) + bTemp = bTemp+2000 + if (aTemp + 1 == a.serverPlayersMax) + aTemp = aTemp+1000 + if (bTemp + 1 == b.serverPlayersMax) + bTemp = bTemp+1000 + + direction = filterDirection.serverName + break; case sortingBy.NAME: aTemp = a.serverName.tolower() bTemp = b.serverName.tolower() @@ -1159,6 +1182,18 @@ int function ServerSortLogic ( serverStruct a, serverStruct b ) return 0 } +void function SortServerListByDefault_Activate ( var button ) +{ + filterDirection.sortingBy = sortingBy.DEFAULT + + file.serversArrayFiltered.sort( ServerSortLogic ) + + filterDirection.serverName = !filterDirection.serverName + + UpdateShownPage() +} + + void function SortServerListByName_Activate ( var button ) { filterDirection.sortingBy = sortingBy.NAME -- cgit v1.2.3