Override video mode list in Team Arena UI

Override the video mode list in the Team Arena data files with detected
modes from SDL like in ioquake3's Q3 UI. Add the aspect ratio to the
end of the video resolution (i.e., "640x480 (4:3)"). Add the current
(custom) video mode to the list.

Before when using a custom resolution in the menu you could not change
the video mode using the mouse because the resolution text was blank.
Now custom video resolution is displayed and can be clicked.
This commit is contained in:
Zack Middleton 2019-04-15 22:40:09 -05:00
parent c61417b8e2
commit 9fcb2bb336
3 changed files with 168 additions and 0 deletions

View file

@ -3086,6 +3086,7 @@ static void UI_Update(const char *name) {
trap_Cvar_SetValue( "r_stencilbits", 8 ); trap_Cvar_SetValue( "r_stencilbits", 8 );
trap_Cvar_SetValue( "r_picmip", 0 ); trap_Cvar_SetValue( "r_picmip", 0 );
trap_Cvar_SetValue( "r_mode", 4 ); trap_Cvar_SetValue( "r_mode", 4 );
trap_Cvar_Set( "ui_videomode", "800x600" );
trap_Cvar_SetValue( "r_texturebits", 32 ); trap_Cvar_SetValue( "r_texturebits", 32 );
trap_Cvar_SetValue( "r_fastSky", 0 ); trap_Cvar_SetValue( "r_fastSky", 0 );
trap_Cvar_SetValue( "r_inGameVideo", 1 ); trap_Cvar_SetValue( "r_inGameVideo", 1 );
@ -3103,6 +3104,7 @@ static void UI_Update(const char *name) {
trap_Cvar_Reset( "r_stencilbits" ); trap_Cvar_Reset( "r_stencilbits" );
trap_Cvar_SetValue( "r_picmip", 1 ); trap_Cvar_SetValue( "r_picmip", 1 );
trap_Cvar_SetValue( "r_mode", 3 ); trap_Cvar_SetValue( "r_mode", 3 );
trap_Cvar_Set( "ui_videomode", "640x480" );
trap_Cvar_SetValue( "r_texturebits", 0 ); trap_Cvar_SetValue( "r_texturebits", 0 );
trap_Cvar_SetValue( "r_fastSky", 0 ); trap_Cvar_SetValue( "r_fastSky", 0 );
trap_Cvar_SetValue( "r_inGameVideo", 1 ); trap_Cvar_SetValue( "r_inGameVideo", 1 );
@ -3120,6 +3122,7 @@ static void UI_Update(const char *name) {
trap_Cvar_Reset( "r_stencilbits" ); trap_Cvar_Reset( "r_stencilbits" );
trap_Cvar_SetValue( "r_picmip", 1 ); trap_Cvar_SetValue( "r_picmip", 1 );
trap_Cvar_SetValue( "r_mode", 3 ); trap_Cvar_SetValue( "r_mode", 3 );
trap_Cvar_Set( "ui_videomode", "640x480" );
trap_Cvar_SetValue( "r_texturebits", 0 ); trap_Cvar_SetValue( "r_texturebits", 0 );
trap_Cvar_SetValue( "cg_shadows", 0 ); trap_Cvar_SetValue( "cg_shadows", 0 );
trap_Cvar_SetValue( "r_fastSky", 1 ); trap_Cvar_SetValue( "r_fastSky", 1 );
@ -3136,6 +3139,7 @@ static void UI_Update(const char *name) {
trap_Cvar_SetValue( "r_depthbits", 16 ); trap_Cvar_SetValue( "r_depthbits", 16 );
trap_Cvar_SetValue( "r_stencilbits", 0 ); trap_Cvar_SetValue( "r_stencilbits", 0 );
trap_Cvar_SetValue( "r_mode", 3 ); trap_Cvar_SetValue( "r_mode", 3 );
trap_Cvar_Set( "ui_videomode", "640x480" );
trap_Cvar_SetValue( "r_picmip", 2 ); trap_Cvar_SetValue( "r_picmip", 2 );
trap_Cvar_SetValue( "r_texturebits", 16 ); trap_Cvar_SetValue( "r_texturebits", 16 );
trap_Cvar_SetValue( "cg_shadows", 0 ); trap_Cvar_SetValue( "cg_shadows", 0 );
@ -5079,6 +5083,8 @@ void _UI_Init( qboolean inGameLoad ) {
// cache redundant calulations // cache redundant calulations
trap_GetGlconfig( &uiInfo.uiDC.glconfig ); trap_GetGlconfig( &uiInfo.uiDC.glconfig );
trap_Cvar_Set("ui_videomode", va( "%dx%d", uiInfo.uiDC.glconfig.vidWidth, uiInfo.uiDC.glconfig.vidHeight ) );
// for 640x480 virtualized screen // for 640x480 virtualized screen
uiInfo.uiDC.yscale = uiInfo.uiDC.glconfig.vidHeight * (1.0/480.0); uiInfo.uiDC.yscale = uiInfo.uiDC.glconfig.vidHeight * (1.0/480.0);
uiInfo.uiDC.xscale = uiInfo.uiDC.glconfig.vidWidth * (1.0/640.0); uiInfo.uiDC.xscale = uiInfo.uiDC.glconfig.vidWidth * (1.0/640.0);
@ -5871,6 +5877,7 @@ static cvarTable_t cvarTable[] = {
{ &ui_realCaptureLimit, "capturelimit", "8", CVAR_SERVERINFO | CVAR_ARCHIVE | CVAR_NORESTART}, { &ui_realCaptureLimit, "capturelimit", "8", CVAR_SERVERINFO | CVAR_ARCHIVE | CVAR_NORESTART},
{ &ui_serverStatusTimeOut, "ui_serverStatusTimeOut", "7000", CVAR_ARCHIVE}, { &ui_serverStatusTimeOut, "ui_serverStatusTimeOut", "7000", CVAR_ARCHIVE},
{ NULL, "ui_videomode", "", CVAR_ROM },
{ NULL, "g_localTeamPref", "", 0 }, { NULL, "g_localTeamPref", "", 0 },
}; };

View file

@ -2055,6 +2055,26 @@ qboolean Item_Multi_HandleKey(itemDef_t *item, int key) {
} else if ( current >= max ) { } else if ( current >= max ) {
current = 0; current = 0;
} }
if (multiPtr->videoMode) {
if (multiPtr->cvarValue[current] != -1) {
DC->setCVar("r_mode", va("%i", (int) multiPtr->cvarValue[current] ));
} else {
int w, h;
char *x;
char str[8];
x = strchr( multiPtr->cvarStr[current], 'x' ) + 1;
Q_strncpyz( str, multiPtr->cvarStr[current], MIN( x-multiPtr->cvarStr[current], sizeof( str ) ) );
w = atoi( str );
h = atoi( x );
DC->setCVar("r_mode", "-1");
DC->setCVar("r_customwidth", va("%i", w));
DC->setCVar("r_customheight", va("%i", h));
}
}
if (multiPtr->strDef) { if (multiPtr->strDef) {
DC->setCVar(item->cvar, multiPtr->cvarStr[current]); DC->setCVar(item->cvar, multiPtr->cvarStr[current]);
} else { } else {
@ -5003,6 +5023,7 @@ qboolean ItemParse_cvarStrList( itemDef_t *item, int handle ) {
multiPtr = (multiDef_t*)item->typeData; multiPtr = (multiDef_t*)item->typeData;
multiPtr->count = 0; multiPtr->count = 0;
multiPtr->strDef = qtrue; multiPtr->strDef = qtrue;
multiPtr->videoMode = qfalse;
if (!trap_PC_ReadToken(handle, &token)) if (!trap_PC_ReadToken(handle, &token))
return qfalse; return qfalse;
@ -5051,6 +5072,7 @@ qboolean ItemParse_cvarFloatList( itemDef_t *item, int handle ) {
multiPtr = (multiDef_t*)item->typeData; multiPtr = (multiDef_t*)item->typeData;
multiPtr->count = 0; multiPtr->count = 0;
multiPtr->strDef = qfalse; multiPtr->strDef = qfalse;
multiPtr->videoMode = qfalse;
if (!trap_PC_ReadToken(handle, &token)) if (!trap_PC_ReadToken(handle, &token))
return qfalse; return qfalse;
@ -5227,6 +5249,61 @@ void Item_SetupKeywordHash(void) {
} }
} }
static const char *builtinResolutions[ ] =
{
"320x240",
"400x300",
"512x384",
"640x480",
"800x600",
"960x720",
"1024x768",
"1152x864",
"1280x1024",
"1600x1200",
"2048x1536",
"856x480",
NULL
};
static const char *knownRatios[ ][2] =
{
{ "1.25:1", "5:4" },
{ "1.33:1", "4:3" },
{ "1.50:1", "3:2" },
{ "1.56:1", "14:9" },
{ "1.60:1", "16:10" },
{ "1.67:1", "5:3" },
{ "1.78:1", "16:9" },
{ NULL , NULL }
};
/*
===============
UI_ResolutionToAspect
===============
*/
static void UI_ResolutionToAspect( const char *resolution, char *aspect, size_t aspectLength ) {
int i, w, h;
char *x;
char str[8];
// calculate resolution's aspect ratio
x = strchr( resolution, 'x' ) + 1;
Q_strncpyz( str, resolution, MIN( x-resolution, sizeof( str ) ) );
w = atoi( str );
h = atoi( x );
Com_sprintf( aspect, aspectLength, "%.2f:1", (float)w / (float)h );
// rename common ratios ("1.33:1" -> "4:3")
for( i = 0; knownRatios[i][0]; i++ ) {
if( !Q_stricmp( aspect, knownRatios[i][0] ) ) {
Q_strncpyz( aspect, knownRatios[i][1], aspectLength );
break;
}
}
}
/* /*
=============== ===============
Item_ApplyHacks Item_ApplyHacks
@ -5261,6 +5338,89 @@ static void Item_ApplyHacks( itemDef_t *item ) {
} }
} }
// Replace mode list and use a temporary ui_videomode cvar for handling custom modes
if ( item->type == ITEM_TYPE_MULTI && item->cvar && !Q_stricmp( item->cvar, "r_mode" ) ) {
multiDef_t *multiPtr = (multiDef_t*)item->typeData;
int i, oldCount;
char resbuf[MAX_STRING_CHARS];
char modeName[32], aspect[8];
item->cvar = "ui_videomode";
multiPtr->strDef = qtrue;
multiPtr->videoMode = qtrue;
oldCount = multiPtr->count;
multiPtr->count = 0;
DC->getCVarString( "r_availableModes", resbuf, sizeof( resbuf ) );
if ( *resbuf ) {
char *s = resbuf, *mode;
while ( s && multiPtr->count < MAX_MULTI_CVARS ) {
mode = s;
s = strchr(s, ' ');
if( s )
*s++ = '\0';
UI_ResolutionToAspect( mode, aspect, sizeof( aspect ) );
Com_sprintf( modeName, sizeof( modeName ), "%s (%s)", mode, aspect );
multiPtr->cvarList[multiPtr->count] = String_Alloc( modeName );
for ( i = 0; builtinResolutions[i]; i++ ) {
if( !Q_stricmp( builtinResolutions[i], mode ) ) {
multiPtr->cvarStr[multiPtr->count] = builtinResolutions[i];
multiPtr->cvarValue[multiPtr->count] = i;
break;
}
}
if ( builtinResolutions[i] == NULL ) {
multiPtr->cvarStr[multiPtr->count] = String_Alloc( mode );
multiPtr->cvarValue[multiPtr->count] = -1;
}
multiPtr->count++;
}
} else {
for ( i = 0; builtinResolutions[i] && multiPtr->count < MAX_MULTI_CVARS; i++ ) {
UI_ResolutionToAspect( builtinResolutions[i], aspect, sizeof( aspect ) );
Com_sprintf( modeName, sizeof( modeName ), "%s (%s)", builtinResolutions[i], aspect );
multiPtr->cvarList[multiPtr->count] = String_Alloc( modeName );
multiPtr->cvarStr[multiPtr->count] = builtinResolutions[i];
multiPtr->cvarValue[multiPtr->count] = i;
multiPtr->count++;
}
}
// Add custom resolution if not in mode list
if ( multiPtr->count < MAX_MULTI_CVARS ) {
char currentResolution[20];
Com_sprintf( currentResolution, sizeof ( currentResolution ), "%dx%d", DC->glconfig.vidWidth, DC->glconfig.vidHeight );
for ( i = 0; i < multiPtr->count; i++ ) {
if ( !Q_stricmp( multiPtr->cvarStr[i], currentResolution ) ) {
break;
}
}
if ( i == multiPtr->count ) {
UI_ResolutionToAspect( currentResolution, aspect, sizeof( aspect ) );
Com_sprintf( modeName, sizeof( modeName ), "%s (%s)", currentResolution, aspect );
multiPtr->cvarList[multiPtr->count] = String_Alloc( modeName );
multiPtr->cvarStr[multiPtr->count] = String_Alloc( currentResolution );
multiPtr->cvarValue[multiPtr->count] = -1;
multiPtr->count++;
}
}
Com_Printf( "Found video mode list with %d modes, replaced list with %d modes\n", oldCount, multiPtr->count );
}
} }
/* /*

View file

@ -203,6 +203,7 @@ typedef struct multiDef_s {
float cvarValue[MAX_MULTI_CVARS]; float cvarValue[MAX_MULTI_CVARS];
int count; int count;
qboolean strDef; qboolean strDef;
qboolean videoMode;
} multiDef_t; } multiDef_t;
typedef struct modelDef_s { typedef struct modelDef_s {