Skip to content

Commit

Permalink
cgame: preselect a map in server creation window, remember it
Browse files Browse the repository at this point in the history
  • Loading branch information
illwieckz committed Dec 27, 2023
1 parent 12534d6 commit 5bf062a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/unvanquished_src.dpkdir/ui/server_create.rml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</row>

<row id="maplist">
<dataselect source="mapList.default" fields="mapName" valuefield="mapLoadName" name="map" cvar="ui_dialogCvar1"/>
<dataselect source="mapList.default" fields="mapName" valuefield="mapLoadName" name="map"/>
<h3><translate>Map</translate></h3>
</row>

Expand Down
43 changes: 39 additions & 4 deletions src/cgame/cg_rocket_datasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Maryland 20850 USA.

#include "cg_local.h"

static Cvar::Cvar<std::string> g_defaultMap("g_defaultMap", "default map to play", Cvar::ARCHIVE, "plat23");

static bool AddToServerList( const char *name, const char *label, int clients, int bots, int ping, int maxClients, char *mapName, char *addr, int netSrc )
{
server_t *node;
Expand Down Expand Up @@ -1119,16 +1121,30 @@ static void CG_Rocket_BuildMapList( const char* )
Rocket_DSClearTable( "mapList", "default" );
CG_LoadMapList();

rocketInfo.data.mapIndex = -1;

for ( size_t i = 0; i < rocketInfo.data.mapList.size(); ++i )
{
char buf[ MAX_INFO_STRING ] = { 0 };

Str::StringRef mapLoadName = rocketInfo.data.mapList[ i ].mapLoadName;

Info_SetValueForKey( buf, "num", std::to_string( i ).c_str(), false );
Info_SetValueForKey( buf, "mapName", rocketInfo.data.mapList[ i ].mapLoadName.c_str(), false );
Info_SetValueForKey( buf, "mapLoadName", rocketInfo.data.mapList[ i ].mapLoadName.c_str(), false );
Info_SetValueForKey( buf, "mapName", mapLoadName.c_str(), false );
Info_SetValueForKey( buf, "mapLoadName", mapLoadName.c_str(), false );

if ( mapLoadName == g_defaultMap.Get() )
{
rocketInfo.data.mapIndex = i;
}

Rocket_DSAddRow( "mapList", "default", buf );
}

if ( rocketInfo.data.mapIndex == -1 && !rocketInfo.data.mapList.empty() )
{
rocketInfo.data.mapIndex = 0;
}
}

static void CG_Rocket_CleanUpMapList( const char* )
Expand All @@ -1137,7 +1153,26 @@ static void CG_Rocket_CleanUpMapList( const char* )

static void CG_Rocket_SetMapListIndex( const char*, int index )
{
rocketInfo.data.mapIndex = index;
int size = int( rocketInfo.data.mapList.size() );

if ( index >= 0 && index < size )
{
rocketInfo.data.mapIndex = index;
g_defaultMap.Set( rocketInfo.data.mapList[ index ].mapLoadName );
}
else
{
Log::Warn( "Map list index %d is out of range [0, %d[", index, size );
}
}

static int CG_Rocket_GetMapListIndex( const char* )
{
if ( rocketInfo.data.mapList.size() != 0 )
{
CG_Rocket_BuildMapList( nullptr );
}
return rocketInfo.data.mapIndex;
}


Expand Down Expand Up @@ -1841,7 +1876,7 @@ static const dataSourceCmd_t dataSourceCmdList[] =
{ "humanBuildList", &CG_Rocket_BuildHumanBuildList, &nullSortFunc, &nullCleanFunc, &nullSetFunc, &nullFilterFunc, &nullExecFunc, &nullGetFunc },
{ "humanSpawnItems", &CG_Rocket_BuildHumanSpawnItems, &nullSortFunc, CG_Rocket_CleanUpHumanSpawnItems, &CG_Rocket_SetHumanSpawnItems, &nullFilterFunc, &CG_Rocket_ExecHumanSpawnItems, &nullGetFunc },
{ "languages", &CG_Rocket_BuildLanguageList, &nullSortFunc, &CG_Rocket_CleanUpLanguageList, &CG_Rocket_SetLanguageListLanguage, &nullFilterFunc, &nullExecFunc, &CG_Rocket_GetLanguageListIndex },
{ "mapList", &CG_Rocket_BuildMapList, &nullSortFunc, &CG_Rocket_CleanUpMapList, &CG_Rocket_SetMapListIndex, &nullFilterFunc, &nullExecFunc, &nullGetFunc },
{ "mapList", &CG_Rocket_BuildMapList, &nullSortFunc, &CG_Rocket_CleanUpMapList, &CG_Rocket_SetMapListIndex, &nullFilterFunc, &nullExecFunc, &CG_Rocket_GetMapListIndex },
{ "modList", &CG_Rocket_BuildModList, &nullSortFunc, &CG_Rocket_CleanUpModList, &CG_Rocket_SetModListMod, &nullFilterFunc, &nullExecFunc, &nullGetFunc },
{ "playerList", &CG_Rocket_BuildPlayerList, &CG_Rocket_SortPlayerList, &CG_Rocket_CleanUpPlayerList, &CG_Rocket_SetPlayerListPlayer, &nullFilterFunc, &nullExecFunc, &nullGetFunc },
{ "resolutions", &CG_Rocket_BuildResolutionList, &nullSortFunc, &CG_Rocket_CleanUpResolutionList, &CG_Rocket_SetResolutionListResolution, &nullFilterFunc, &nullExecFunc, &CG_Rocket_GetResolutionListIndex},
Expand Down

0 comments on commit 5bf062a

Please sign in to comment.