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:
parent
c61417b8e2
commit
9fcb2bb336
3 changed files with 168 additions and 0 deletions
|
@ -2055,6 +2055,26 @@ qboolean Item_Multi_HandleKey(itemDef_t *item, int key) {
|
|||
} else if ( current >= max ) {
|
||||
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) {
|
||||
DC->setCVar(item->cvar, multiPtr->cvarStr[current]);
|
||||
} else {
|
||||
|
@ -5003,6 +5023,7 @@ qboolean ItemParse_cvarStrList( itemDef_t *item, int handle ) {
|
|||
multiPtr = (multiDef_t*)item->typeData;
|
||||
multiPtr->count = 0;
|
||||
multiPtr->strDef = qtrue;
|
||||
multiPtr->videoMode = qfalse;
|
||||
|
||||
if (!trap_PC_ReadToken(handle, &token))
|
||||
return qfalse;
|
||||
|
@ -5051,6 +5072,7 @@ qboolean ItemParse_cvarFloatList( itemDef_t *item, int handle ) {
|
|||
multiPtr = (multiDef_t*)item->typeData;
|
||||
multiPtr->count = 0;
|
||||
multiPtr->strDef = qfalse;
|
||||
multiPtr->videoMode = qfalse;
|
||||
|
||||
if (!trap_PC_ReadToken(handle, &token))
|
||||
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
|
||||
|
@ -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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue