Skip to content

Commit

Permalink
update server browser default sorting mode
Browse files Browse the repository at this point in the history
Now sorts by player count by default, if status query support is available. Uses new cvar to store setting to avoid conflicting with mods.
  • Loading branch information
Chomenor committed Nov 12, 2021
1 parent eca6b95 commit 99dbc5a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions code/ui/ui_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,7 @@ extern vmCvar_t ui_spSelection;
extern vmCvar_t ui_browserMaster;
extern vmCvar_t ui_browserGameType;
extern vmCvar_t ui_browserSortKey;
extern vmCvar_t ui_browserSortKey2;
extern vmCvar_t ui_browserShowEmpty;
extern vmCvar_t ui_browserPlayerType;

Expand Down
2 changes: 2 additions & 0 deletions code/ui/ui_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ vmCvar_t ui_spSelection;
vmCvar_t ui_browserMaster;
vmCvar_t ui_browserGameType;
vmCvar_t ui_browserSortKey;
vmCvar_t ui_browserSortKey2;
vmCvar_t ui_browserShowEmpty;
vmCvar_t ui_browserPlayerType;

Expand Down Expand Up @@ -219,6 +220,7 @@ cvarTable_t cvarTable[] = {
{ &ui_browserMaster, "ui_browserMaster", "0", CVAR_ARCHIVE },
{ &ui_browserGameType, "ui_browserGameType", "0", CVAR_ARCHIVE },
{ &ui_browserSortKey, "ui_browserSortKey", "4", CVAR_ARCHIVE },
{ &ui_browserSortKey2, "ui_browserSortKey2", "2", CVAR_ARCHIVE },
{ &ui_browserShowEmpty, "ui_browserShowEmpty", "1", CVAR_ARCHIVE },
{ &ui_browserPlayerType, "ui_browserPlayerType", "1", CVAR_ARCHIVE },

Expand Down
8 changes: 6 additions & 2 deletions code/ui/ui_servers2.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ typedef struct {

static arenaservers_t g_arenaservers;

// Use cvar with different default if status query is enabled
#define SORT_KEY_CVAR ( g_arenaservers.statusQueryEnabled ? &ui_browserSortKey2 : &ui_browserSortKey )
#define SORT_KEY_CVAR_NAME ( g_arenaservers.statusQueryEnabled ? "ui_browserSortKey2" : "ui_browserSortKey" )

typedef struct
{
menuframework_s menu;
Expand Down Expand Up @@ -2105,7 +2109,7 @@ static void ArenaServers_Event( void* ptr, int event ) {
break;

case ID_SORTKEY:
trap_Cvar_SetValue( "ui_browserSortKey", g_arenaservers.sortkey.curvalue );
trap_Cvar_SetValue( SORT_KEY_CVAR_NAME, g_arenaservers.sortkey.curvalue );
ArenaServers_Sort( g_arenaservers.sortkey.curvalue );
ArenaServers_UpdateMenu();
break;
Expand Down Expand Up @@ -2617,7 +2621,7 @@ static void ArenaServers_MenuInit( void )
g_gametype = Com_Clamp( 0, 4, ui_browserGameType.integer );
g_arenaservers.gametype.curvalue = g_gametype;

g_sortkey = Com_Clamp( 0, 4, ui_browserSortKey.integer );
g_sortkey = Com_Clamp( 0, 4, SORT_KEY_CVAR->integer );
g_arenaservers.sortkey.curvalue = g_sortkey;

if ( g_arenaservers.statusQueryEnabled ) {
Expand Down

0 comments on commit 99dbc5a

Please sign in to comment.