diff options
author | Emma Miler <27428383+emma-miler@users.noreply.github.com> | 2022-04-29 23:28:41 +0200 |
---|---|---|
committer | GeckoEidechse <gecko.eidechse+git@pm.me> | 2022-04-29 23:49:08 +0200 |
commit | f49a8f8566f9586acc1912a4c021f11204d3c9f9 (patch) | |
tree | fcb581bd238febe770acf6183d52dd22645a04ed | |
parent | 07cab284b541701b98af3bd9ce393c9f695afd3b (diff) | |
download | NorthstarMods-f49a8f8566f9586acc1912a4c021f11204d3c9f9.tar.gz NorthstarMods-f49a8f8566f9586acc1912a4c021f11204d3c9f9.zip |
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>
-rw-r--r-- | Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut | 39 |
1 files changed, 37 insertions, 2 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 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 |