diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/ui_atoms.c | 107 | ||||
-rw-r--r-- | src/ui/ui_gameinfo.c | 197 | ||||
-rw-r--r-- | src/ui/ui_local.h | 99 | ||||
-rw-r--r-- | src/ui/ui_main.c | 2700 | ||||
-rw-r--r-- | src/ui/ui_public.h | 59 | ||||
-rw-r--r-- | src/ui/ui_shared.c | 5934 | ||||
-rw-r--r-- | src/ui/ui_shared.h | 266 | ||||
-rw-r--r-- | src/ui/ui_syscalls.c | 292 |
8 files changed, 5714 insertions, 3940 deletions
diff --git a/src/ui/ui_atoms.c b/src/ui/ui_atoms.c index a5c15c25..ec1e1e73 100644 --- a/src/ui/ui_atoms.c +++ b/src/ui/ui_atoms.c @@ -2,19 +2,19 @@ =========================================================================== Copyright (C) 1999-2005 Id Software, Inc. Copyright (C) 2000-2006 Tim Angus - + This file is part of Tremulous. - + Tremulous is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + Tremulous is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with Tremulous; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA @@ -23,33 +23,35 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA /********************************************************************** UI_ATOMS.C - + User interface building blocks and support functions. **********************************************************************/ #include "ui_local.h" qboolean m_entersound; // after a frame, so caching won't disrupt the sound -void QDECL Com_Error( int level, const char *error, ... ) { +void QDECL Com_Error( int level, const char *error, ... ) +{ va_list argptr; char text[1024]; - va_start (argptr, error); - vsprintf (text, error, argptr); - va_end (argptr); + va_start ( argptr, error ); + vsprintf ( text, error, argptr ); + va_end ( argptr ); - trap_Error( va("%s", text) ); + trap_Error( va( "%s", text ) ); } -void QDECL Com_Printf( const char *msg, ... ) { +void QDECL Com_Printf( const char *msg, ... ) +{ va_list argptr; char text[1024]; - va_start (argptr, msg); - vsprintf (text, msg, argptr); - va_end (argptr); + va_start ( argptr, msg ); + vsprintf ( text, msg, argptr ); + va_end ( argptr ); - trap_Print( va("%s", text) ); + trap_Print( va( "%s", text ) ); } @@ -60,8 +62,10 @@ UI_ClampCvar */ float UI_ClampCvar( float min, float max, float value ) { - if ( value < min ) return min; - if ( value > max ) return max; + if( value < min ) return min; + + if( value > max ) return max; + return value; } @@ -70,11 +74,13 @@ float UI_ClampCvar( float min, float max, float value ) UI_StartDemoLoop ================= */ -void UI_StartDemoLoop( void ) { +void UI_StartDemoLoop( void ) +{ trap_Cmd_ExecuteText( EXEC_APPEND, "d1\n" ); } -char *UI_Argv( int arg ) { +char *UI_Argv( int arg ) +{ static char buffer[MAX_STRING_CHARS]; trap_Argv( arg, buffer, sizeof( buffer ) ); @@ -83,7 +89,8 @@ char *UI_Argv( int arg ) { } -char *UI_Cvar_VariableString( const char *var_name ) { +char *UI_Cvar_VariableString( const char *var_name ) +{ static char buffer[MAX_STRING_CHARS]; trap_Cvar_VariableStringBuffer( var_name, buffer, sizeof( buffer ) ); @@ -91,20 +98,21 @@ char *UI_Cvar_VariableString( const char *var_name ) { return buffer; } -static void UI_Cache_f( void ) { +static void UI_Cache_f( void ) +{ Display_CacheAll(); } /* ================= UI_ConsoleCommand - + FIXME: lookup table ================= */ qboolean UI_ConsoleCommand( int realTime ) { - char *cmd; + char * cmd; char *arg1; uiInfo.uiDC.frameTime = realTime - uiInfo.uiDC.realTime; @@ -115,38 +123,45 @@ qboolean UI_ConsoleCommand( int realTime ) // ensure minimum menu data is available //Menu_Cache(); - if ( Q_stricmp (cmd, "ui_report") == 0 ) { + if( Q_stricmp ( cmd, "ui_report" ) == 0 ) + { UI_Report(); return qtrue; } - if ( Q_stricmp (cmd, "ui_load") == 0 ) { + if( Q_stricmp ( cmd, "ui_load" ) == 0 ) + { UI_Load(); return qtrue; } - if ( Q_stricmp (cmd, "remapShader") == 0 ) { - if (trap_Argc() == 4) { + if( Q_stricmp ( cmd, "remapShader" ) == 0 ) + { + if( trap_Argc() == 4 ) + { char shader1[MAX_QPATH]; char shader2[MAX_QPATH]; - Q_strncpyz(shader1, UI_Argv(1), sizeof(shader1)); - Q_strncpyz(shader2, UI_Argv(2), sizeof(shader2)); - trap_R_RemapShader(shader1, shader2, UI_Argv(3)); + Q_strncpyz( shader1, UI_Argv( 1 ), sizeof( shader1 ) ); + Q_strncpyz( shader2, UI_Argv( 2 ), sizeof( shader2 ) ); + trap_R_RemapShader( shader1, shader2, UI_Argv( 3 ) ); return qtrue; } } - if ( Q_stricmp (cmd, "ui_cache") == 0 ) { + if( Q_stricmp ( cmd, "ui_cache" ) == 0 ) + { UI_Cache_f(); return qtrue; } - if ( Q_stricmp (cmd, "ui_teamOrders") == 0 ) { + if( Q_stricmp ( cmd, "ui_teamOrders" ) == 0 ) + { //UI_TeamOrdersMenu_f(); return qtrue; } - if ( Q_strncmp( cmd, "messagemode", 11 ) == 0 ) { + if( Q_strncmp( cmd, "messagemode", 11 ) == 0 ) + { trap_Cvar_Set( "ui_sayBuffer", "" ); switch( cmd[ 11 ] ) @@ -197,7 +212,8 @@ qboolean UI_ConsoleCommand( int realTime ) return qfalse; } -void UI_DrawNamedPic( float x, float y, float width, float height, const char *picname ) { +void UI_DrawNamedPic( float x, float y, float width, float height, const char *picname ) +{ qhandle_t hShader; hShader = trap_R_RegisterShaderNoMip( picname ); @@ -205,28 +221,33 @@ void UI_DrawNamedPic( float x, float y, float width, float height, const char *p trap_R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, hShader ); } -void UI_DrawHandlePic( float x, float y, float w, float h, qhandle_t hShader ) { +void UI_DrawHandlePic( float x, float y, float w, float h, qhandle_t hShader ) +{ float s0; float s1; float t0; float t1; - if( w < 0 ) { // flip about vertical + if( w < 0 ) + { // flip about vertical w = -w; s0 = 1; s1 = 0; } - else { + else + { s0 = 0; s1 = 1; } - if( h < 0 ) { // flip about horizontal + if( h < 0 ) + { // flip about horizontal h = -h; t0 = 1; t1 = 0; } - else { + else + { t0 = 0; t1 = 1; } @@ -238,11 +259,12 @@ void UI_DrawHandlePic( float x, float y, float w, float h, qhandle_t hShader ) { /* ================ UI_FillRect - + Coordinates are 640*480 virtual values ================= */ -void UI_FillRect( float x, float y, float width, float height, const float *color ) { +void UI_FillRect( float x, float y, float width, float height, const float *color ) +{ trap_R_SetColor( color ); UI_AdjustFrom640( &x, &y, &width, &height ); @@ -251,6 +273,7 @@ void UI_FillRect( float x, float y, float width, float height, const float *colo trap_R_SetColor( NULL ); } -void UI_SetColor( const float *rgba ) { +void UI_SetColor( const float *rgba ) +{ trap_R_SetColor( rgba ); } diff --git a/src/ui/ui_gameinfo.c b/src/ui/ui_gameinfo.c index f6d0d4d3..4315ddfb 100644 --- a/src/ui/ui_gameinfo.c +++ b/src/ui/ui_gameinfo.c @@ -2,19 +2,19 @@ =========================================================================== Copyright (C) 1999-2005 Id Software, Inc. Copyright (C) 2000-2006 Tim Angus - + This file is part of Tremulous. - + Tremulous is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + Tremulous is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with Tremulous; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA @@ -44,54 +44,69 @@ static char *ui_arenaInfos[MAX_ARENAS]; UI_ParseInfos =============== */ -int UI_ParseInfos( char *buf, int max, char *infos[] ) { - char *token; +int UI_ParseInfos( char *buf, int max, char *infos[] ) +{ + char * token; int count; char key[MAX_TOKEN_CHARS]; char info[MAX_INFO_STRING]; count = 0; - while ( 1 ) { + while( 1 ) + { token = COM_Parse( &buf ); - if ( !token[0] ) { + + if( !token[0] ) break; - } - if ( strcmp( token, "{" ) ) { + + if( strcmp( token, "{" ) ) + { Com_Printf( "Missing { in info file\n" ); break; } - if ( count == max ) { + if( count == max ) + { Com_Printf( "Max infos exceeded\n" ); break; } info[0] = '\0'; - while ( 1 ) { + + while( 1 ) + { token = COM_ParseExt( &buf, qtrue ); - if ( !token[0] ) { + + if( !token[0] ) + { Com_Printf( "Unexpected end of info file\n" ); break; } - if ( !strcmp( token, "}" ) ) { + + if( !strcmp( token, "}" ) ) break; - } + Q_strncpyz( key, token, sizeof( key ) ); token = COM_ParseExt( &buf, qfalse ); - if ( !token[0] ) { + + if( !token[0] ) strcpy( token, "<NULL>" ); - } + Info_SetValueForKey( info, key, token ); } + //NOTE: extra space for arena number - infos[count] = UI_Alloc(strlen(info) + strlen("\\num\\") + strlen(va("%d", MAX_ARENAS)) + 1); - if (infos[count]) { - strcpy(infos[count], info); + infos[count] = UI_Alloc( strlen( info ) + strlen( "\\num\\" ) + strlen( va( "%d", MAX_ARENAS ) ) + 1 ); + + if( infos[count] ) + { + strcpy( infos[count], info ); count++; } } + return count; } @@ -100,17 +115,22 @@ int UI_ParseInfos( char *buf, int max, char *infos[] ) { UI_LoadArenasFromFile =============== */ -static void UI_LoadArenasFromFile( char *filename ) { +static void UI_LoadArenasFromFile( char *filename ) +{ int len; fileHandle_t f; char buf[MAX_ARENAS_TEXT]; len = trap_FS_FOpenFile( filename, &f, FS_READ ); - if ( !f ) { + + if( !f ) + { trap_Print( va( S_COLOR_RED "file not found: %s\n", filename ) ); return; } - if ( len >= MAX_ARENAS_TEXT ) { + + if( len >= MAX_ARENAS_TEXT ) + { trap_Print( va( S_COLOR_RED "file too large: %s is %i, max allowed is %i", filename, len, MAX_ARENAS_TEXT ) ); trap_FS_FCloseFile( f ); return; @@ -130,8 +150,8 @@ UI_MapNameCompare */ static int UI_MapNameCompare( const void *a, const void *b ) { - mapInfo *A = (mapInfo *)a; - mapInfo *B = (mapInfo *)b; + mapInfo * A = ( mapInfo * )a; + mapInfo *B = ( mapInfo * )b; return Q_stricmp( A->mapName, B->mapName ); } @@ -141,7 +161,8 @@ static int UI_MapNameCompare( const void *a, const void *b ) UI_LoadArenas =============== */ -void UI_LoadArenas( void ) { +void UI_LoadArenas( void ) +{ int numdirs; char filename[128]; char dirlist[1024]; @@ -154,32 +175,36 @@ void UI_LoadArenas( void ) { uiInfo.mapCount = 0; // get all arenas from .arena files - numdirs = trap_FS_GetFileList("scripts", ".arena", dirlist, 1024 ); + numdirs = trap_FS_GetFileList( "scripts", ".arena", dirlist, 1024 ); dirptr = dirlist; - for (i = 0; i < numdirs; i++, dirptr += dirlen+1) { - dirlen = strlen(dirptr); - strcpy(filename, "scripts/"); - strcat(filename, dirptr); - UI_LoadArenasFromFile(filename); + + for( i = 0; i < numdirs; i++, dirptr += dirlen + 1 ) + { + dirlen = strlen( dirptr ); + strcpy( filename, "scripts/" ); + strcat( filename, dirptr ); + UI_LoadArenasFromFile( filename ); } + trap_Print( va( "[skipnotify]%i arenas parsed\n", ui_numArenas ) ); - if (UI_OutOfMemory()) { - trap_Print(S_COLOR_YELLOW"WARNING: not anough memory in pool to load all arenas\n"); - } + + if( UI_OutOfMemory() ) + trap_Print( S_COLOR_YELLOW"WARNING: not anough memory in pool to load all arenas\n" ); for( n = 0; n < ui_numArenas; n++ ) { - // determine type + // determine type type = Info_ValueForKey( ui_arenaInfos[ n ], "type" ); // if no type specified, it will be treated as "ffa" uiInfo.mapList[uiInfo.mapCount].cinematic = -1; - uiInfo.mapList[uiInfo.mapCount].mapLoadName = String_Alloc(Info_ValueForKey(ui_arenaInfos[n], "map")); - uiInfo.mapList[uiInfo.mapCount].mapName = String_Alloc(Info_ValueForKey(ui_arenaInfos[n], "longname")); + uiInfo.mapList[uiInfo.mapCount].mapLoadName = String_Alloc( Info_ValueForKey( ui_arenaInfos[n], "map" ) ); + uiInfo.mapList[uiInfo.mapCount].mapName = String_Alloc( Info_ValueForKey( ui_arenaInfos[n], "longname" ) ); uiInfo.mapList[uiInfo.mapCount].levelShot = -1; - uiInfo.mapList[uiInfo.mapCount].imageName = String_Alloc(va("levelshots/%s", uiInfo.mapList[uiInfo.mapCount].mapLoadName)); + uiInfo.mapList[uiInfo.mapCount].imageName = String_Alloc( va( "levelshots/%s", uiInfo.mapList[uiInfo.mapCount].mapLoadName ) ); uiInfo.mapCount++; + if( uiInfo.mapCount >= MAX_MAPS ) break; } @@ -193,17 +218,22 @@ void UI_LoadArenas( void ) { UI_LoadBotsFromFile =============== */ -static void UI_LoadBotsFromFile( char *filename ) { +static void UI_LoadBotsFromFile( char *filename ) +{ int len; fileHandle_t f; char buf[MAX_BOTS_TEXT]; len = trap_FS_FOpenFile( filename, &f, FS_READ ); - if ( !f ) { + + if( !f ) + { trap_Print( va( S_COLOR_RED "file not found: %s\n", filename ) ); return; } - if ( len >= MAX_BOTS_TEXT ) { + + if( len >= MAX_BOTS_TEXT ) + { trap_Print( va( S_COLOR_RED "file too large: %s is %i, max allowed is %i", filename, len, MAX_BOTS_TEXT ) ); trap_FS_FCloseFile( f ); return; @@ -213,7 +243,7 @@ static void UI_LoadBotsFromFile( char *filename ) { buf[len] = 0; trap_FS_FCloseFile( f ); - COM_Compress(buf); + COM_Compress( buf ); ui_numBots += UI_ParseInfos( buf, MAX_BOTS - ui_numBots, &ui_botInfos[ui_numBots] ); } @@ -223,7 +253,8 @@ static void UI_LoadBotsFromFile( char *filename ) { UI_LoadBots =============== */ -void UI_LoadBots( void ) { +void UI_LoadBots( void ) +{ vmCvar_t botsFile; int numdirs; char filename[128]; @@ -234,23 +265,26 @@ void UI_LoadBots( void ) { ui_numBots = 0; - trap_Cvar_Register( &botsFile, "g_botsFile", "", CVAR_INIT|CVAR_ROM ); - if( *botsFile.string ) { - UI_LoadBotsFromFile(botsFile.string); - } - else { - UI_LoadBotsFromFile("scripts/bots.txt"); - } + trap_Cvar_Register( &botsFile, "g_botsFile", "", CVAR_INIT | CVAR_ROM ); + + if( *botsFile.string ) + UI_LoadBotsFromFile( botsFile.string ); + else + UI_LoadBotsFromFile( "scripts/bots.txt" ); // get all bots from .bot files - numdirs = trap_FS_GetFileList("scripts", ".bot", dirlist, 1024 ); + numdirs = trap_FS_GetFileList( "scripts", ".bot", dirlist, 1024 ); + dirptr = dirlist; - for (i = 0; i < numdirs; i++, dirptr += dirlen+1) { - dirlen = strlen(dirptr); - strcpy(filename, "scripts/"); - strcat(filename, dirptr); - UI_LoadBotsFromFile(filename); + + for( i = 0; i < numdirs; i++, dirptr += dirlen + 1 ) + { + dirlen = strlen( dirptr ); + strcpy( filename, "scripts/" ); + strcat( filename, dirptr ); + UI_LoadBotsFromFile( filename ); } + trap_Print( va( "%i bots parsed\n", ui_numBots ) ); } @@ -260,11 +294,14 @@ void UI_LoadBots( void ) { UI_GetBotInfoByNumber =============== */ -char *UI_GetBotInfoByNumber( int num ) { - if( num < 0 || num >= ui_numBots ) { +char *UI_GetBotInfoByNumber( int num ) +{ + if( num < 0 || num >= ui_numBots ) + { trap_Print( va( S_COLOR_RED "Invalid bot number: %i\n", num ) ); return NULL; } + return ui_botInfos[num]; } @@ -274,30 +311,35 @@ char *UI_GetBotInfoByNumber( int num ) { UI_GetBotInfoByName =============== */ -char *UI_GetBotInfoByName( const char *name ) { +char *UI_GetBotInfoByName( const char *name ) +{ int n; char *value; - for ( n = 0; n < ui_numBots ; n++ ) { + for( n = 0; n < ui_numBots ; n++ ) + { value = Info_ValueForKey( ui_botInfos[n], "name" ); - if ( !Q_stricmp( value, name ) ) { + + if( !Q_stricmp( value, name ) ) return ui_botInfos[n]; - } } return NULL; } -int UI_GetNumBots( void ) { +int UI_GetNumBots( void ) +{ return ui_numBots; } -char *UI_GetBotNameByNumber( int num ) { - char *info = UI_GetBotInfoByNumber(num); - if (info) { +char *UI_GetBotNameByNumber( int num ) +{ + char * info = UI_GetBotInfoByNumber( num ); + + if( info ) return Info_ValueForKey( info, "name" ); - } + return ""; } @@ -306,23 +348,24 @@ void UI_ServerInfo( void ) char info[ MAX_INFO_VALUE ]; info[0] = '\0'; + if( trap_GetConfigString( CS_SERVERINFO, info, sizeof( info ) ) ) - { + { trap_Cvar_Set( "ui_serverinfo_mapname", - Info_ValueForKey( info, "mapname" ) ); + Info_ValueForKey( info, "mapname" ) ); trap_Cvar_Set( "ui_serverinfo_timelimit", - Info_ValueForKey( info, "timelimit" ) ); + Info_ValueForKey( info, "timelimit" ) ); trap_Cvar_Set( "ui_serverinfo_sd", - Info_ValueForKey( info, "g_suddenDeathTime" ) ); + Info_ValueForKey( info, "g_suddenDeathTime" ) ); trap_Cvar_Set( "ui_serverinfo_hostname", - Info_ValueForKey( info, "sv_hostname" ) ); + Info_ValueForKey( info, "sv_hostname" ) ); trap_Cvar_Set( "ui_serverinfo_maxclients", - Info_ValueForKey( info, "sv_maxclients" ) ); + Info_ValueForKey( info, "sv_maxclients" ) ); trap_Cvar_Set( "ui_serverinfo_version", - Info_ValueForKey( info, "version" ) ); + Info_ValueForKey( info, "version" ) ); trap_Cvar_Set( "ui_serverinfo_unlagged", - Info_ValueForKey( info, "g_unlagged" ) ); + Info_ValueForKey( info, "g_unlagged" ) ); trap_Cvar_Set( "ui_serverinfo_ff", - Info_ValueForKey( info, "ff" ) ); + Info_ValueForKey( info, "ff" ) ); } } diff --git a/src/ui/ui_local.h b/src/ui/ui_local.h index 5c404227..ca3dab77 100644 --- a/src/ui/ui_local.h +++ b/src/ui/ui_local.h @@ -2,19 +2,19 @@ =========================================================================== Copyright (C) 1999-2005 Id Software, Inc. Copyright (C) 2000-2006 Tim Angus - + This file is part of Tremulous. - + Tremulous is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + Tremulous is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with Tremulous; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA @@ -36,11 +36,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // void UI_Report( void ); void UI_Load( void ); -void UI_LoadMenus(const char *menuFile, qboolean reset); -int UI_AdjustTimeByGame(int time); +void UI_LoadMenus( const char *menuFile, qboolean reset ); +int UI_AdjustTimeByGame( int time ); void UI_ClearScores( void ); -void UI_LoadArenas(void); -void UI_ServerInfo(void); +void UI_LoadArenas( void ); +void UI_ServerInfo( void ); void UI_RegisterCvars( void ); void UI_UpdateCvars( void ); @@ -58,26 +58,33 @@ void UI_DrawConnectScreen( qboolean overlay ); #define MAX_DEMOS 256 #define MAX_MOVIES 256 -typedef struct { +typedef struct +{ const char *mapName; const char *mapLoadName; const char *imageName; int cinematic; qhandle_t levelShot; -} mapInfo; +} +mapInfo; -typedef struct serverFilter_s { +typedef struct serverFilter_s +{ const char *description; const char *basedir; -} serverFilter_t; +} +serverFilter_t; -typedef struct { +typedef struct +{ char adrstr[MAX_ADDRESSLENGTH]; int start; -} pinglist_t; +} +pinglist_t; -typedef struct serverStatus_s { +typedef struct serverStatus_s +{ pinglist_t pingList[MAX_PINGREQUESTS]; int numqueriedservers; int currentping; @@ -105,34 +112,43 @@ typedef struct serverStatus_s { int motdOffset; int motdTime; char motd[MAX_STRING_CHARS]; -} serverStatus_t; +} +serverStatus_t; -typedef struct { +typedef struct +{ char adrstr[MAX_ADDRESSLENGTH]; char name[MAX_ADDRESSLENGTH]; int startTime; int serverNum; qboolean valid; -} pendingServer_t; +} +pendingServer_t; -typedef struct { +typedef struct +{ int num; pendingServer_t server[MAX_SERVERSTATUSREQUESTS]; -} pendingServerStatus_t; +} +pendingServerStatus_t; -typedef struct { +typedef struct +{ char address[MAX_ADDRESSLENGTH]; char *lines[MAX_SERVERSTATUS_LINES][4]; char text[MAX_SERVERSTATUS_TEXT]; char pings[MAX_CLIENTS * 3]; int numLines; -} serverStatusInfo_t; +} +serverStatusInfo_t; -typedef struct { +typedef struct +{ const char *modName; const char *modDescr; -} modInfo_t; +} +modInfo_t; typedef enum { @@ -156,9 +172,11 @@ typedef struct weapon_t weapon; upgrade_t upgrade; } v; -} menuItem_t; +} +menuItem_t; -typedef struct { +typedef struct +{ displayContextDef_t uiDC; int playerCount; @@ -248,7 +266,8 @@ typedef struct { qboolean chatTeam; int chatTargetClientNum; -} uiInfo_t; +} +uiInfo_t; extern uiInfo_t uiInfo; @@ -323,24 +342,24 @@ void trap_LAN_GetPing( int n, char *buf, int buflen, int *pingtime ); void trap_LAN_GetPingInfo( int n, char *buf, int buflen ); void trap_LAN_LoadCachedServers( void ); void trap_LAN_SaveCachedServers( void ); -void trap_LAN_MarkServerVisible(int source, int n, qboolean visible); -int trap_LAN_ServerIsVisible( int source, int n); +void trap_LAN_MarkServerVisible( int source, int n, qboolean visible ); +int trap_LAN_ServerIsVisible( int source, int n ); qboolean trap_LAN_UpdateVisiblePings( int source ); -int trap_LAN_AddServer(int source, const char *name, const char *addr); -void trap_LAN_RemoveServer(int source, const char *addr); -void trap_LAN_ResetPings(int n); +int trap_LAN_AddServer( int source, const char *name, const char *addr ); +void trap_LAN_RemoveServer( int source, const char *addr ); +void trap_LAN_ResetPings( int n ); int trap_LAN_ServerStatus( const char *serverAddress, char *serverStatus, int maxLen ); int trap_LAN_CompareServers( int source, int sortKey, int sortDir, int s1, int s2 ); int trap_MemoryRemaining( void ); -void trap_R_RegisterFont(const char *pFontname, int pointSize, fontInfo_t *font); +void trap_R_RegisterFont( const char *pFontname, int pointSize, fontInfo_t *font ); void trap_S_StopBackgroundTrack( void ); -void trap_S_StartBackgroundTrack( const char *intro, const char *loop); -int trap_CIN_PlayCinematic( const char *arg0, int xpos, int ypos, int width, int height, int bits); -e_status trap_CIN_StopCinematic(int handle); -e_status trap_CIN_RunCinematic (int handle); -void trap_CIN_DrawCinematic (int handle); -void trap_CIN_SetExtents (int handle, int x, int y, int w, int h); -int trap_RealTime(qtime_t *qtime); +void trap_S_StartBackgroundTrack( const char *intro, const char *loop ); +int trap_CIN_PlayCinematic( const char *arg0, int xpos, int ypos, int width, int height, int bits ); +e_status trap_CIN_StopCinematic( int handle ); +e_status trap_CIN_RunCinematic ( int handle ); +void trap_CIN_DrawCinematic ( int handle ); +void trap_CIN_SetExtents ( int handle, int x, int y, int w, int h ); +int trap_RealTime( qtime_t *qtime ); void trap_R_RemapShader( const char *oldShader, const char *newShader, const char *timeOffset ); void trap_SetPbClStatus( int status ); diff --git a/src/ui/ui_main.c b/src/ui/ui_main.c index 61ce1d91..fcc08e67 100644 --- a/src/ui/ui_main.c +++ b/src/ui/ui_main.c @@ -2,19 +2,19 @@ =========================================================================== Copyright (C) 1999-2005 Id Software, Inc. Copyright (C) 2000-2006 Tim Angus - + This file is part of Tremulous. - + Tremulous is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + Tremulous is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with Tremulous; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA @@ -23,9 +23,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA /* ======================================================================= - + USER INTERFACE MAIN - + ======================================================================= */ @@ -33,22 +33,26 @@ USER INTERFACE MAIN uiInfo_t uiInfo; -static const char *MonthAbbrev[] = { - "Jan","Feb","Mar", - "Apr","May","Jun", - "Jul","Aug","Sep", - "Oct","Nov","Dec" +static const char *MonthAbbrev[ ] = +{ + "Jan", "Feb", "Mar", + "Apr", "May", "Jun", + "Jul", "Aug", "Sep", + "Oct", "Nov", "Dec" }; -static const char *netSources[] = { +static const char *netSources[ ] = +{ "Internet", "Mplayer", "LAN", "Favorites" }; -static const int numNetSources = sizeof(netSources) / sizeof(const char*); -static char* netnames[] = { +static const int numNetSources = sizeof( netSources ) / sizeof( const char* ); + +static const char* netnames[ ] = +{ "???", "UDP", "IPX", @@ -61,12 +65,15 @@ cvars ================ */ -typedef struct { +typedef struct +{ vmCvar_t *vmCvar; char *cvarName; char *defaultString; int cvarFlags; -} cvarTable_t; +} + +cvarTable_t; vmCvar_t ui_browserShowFull; vmCvar_t ui_browserShowEmpty; @@ -91,7 +98,8 @@ vmCvar_t ui_developer; vmCvar_t ui_winner; -static cvarTable_t cvarTable[] = { +static cvarTable_t cvarTable[ ] = +{ { &ui_browserShowFull, "ui_browserShowFull", "1", CVAR_ARCHIVE }, { &ui_browserShowEmpty, "ui_browserShowEmpty", "1", CVAR_ARCHIVE }, @@ -114,12 +122,12 @@ static cvarTable_t cvarTable[] = { { &ui_developer, "ui_developer", "0", CVAR_ARCHIVE | CVAR_CHEAT }, }; -static int cvarTableSize = sizeof(cvarTable) / sizeof(cvarTable[0]); +static int cvarTableSize = sizeof( cvarTable ) / sizeof( cvarTable[0] ); /* ================ vmMain - + This is the only way control passes into the module. This must be the very first function compiled into the .qvm file ================ @@ -132,14 +140,16 @@ void UI_Refresh( int realtime ); qboolean UI_IsFullscreen( void ); void UI_SetActiveMenu( uiMenuCommand_t menu ); intptr_t vmMain( int command, int arg0, int arg1, int arg2, int arg3, - int arg4, int arg5, int arg6, int arg7, - int arg8, int arg9, int arg10, int arg11 ) { - switch ( command ) { + int arg4, int arg5, int arg6, int arg7, + int arg8, int arg9, int arg10, int arg11 ) +{ + switch( command ) + { case UI_GETAPIVERSION: return UI_API_VERSION; case UI_INIT: - UI_Init(arg0); + UI_Init( arg0 ); return 0; case UI_SHUTDOWN: @@ -166,7 +176,7 @@ intptr_t vmMain( int command, int arg0, int arg1, int arg2, int arg3, return 0; case UI_CONSOLE_COMMAND: - return UI_ConsoleCommand(arg0); + return UI_ConsoleCommand( arg0 ); case UI_DRAW_CONNECT_SCREEN: UI_DrawConnectScreen( arg0 ); @@ -178,7 +188,8 @@ intptr_t vmMain( int command, int arg0, int arg1, int arg2, int arg3, -void AssetCache( void ) { +void AssetCache( void ) +{ uiInfo.uiDC.Assets.gradientBar = trap_R_RegisterShaderNoMip( ASSET_GRADIENTBAR ); uiInfo.uiDC.Assets.scrollBar = trap_R_RegisterShaderNoMip( ASSET_SCROLLBAR ); uiInfo.uiDC.Assets.scrollBarArrowDown = trap_R_RegisterShaderNoMip( ASSET_SCROLLBAR_ARROWDOWN ); @@ -190,31 +201,35 @@ void AssetCache( void ) { uiInfo.uiDC.Assets.sliderThumb = trap_R_RegisterShaderNoMip( ASSET_SLIDER_THUMB ); } -void UI_DrawSides(float x, float y, float w, float h, float size) { +void UI_DrawSides( float x, float y, float w, float h, float size ) +{ UI_AdjustFrom640( &x, &y, &w, &h ); size *= uiInfo.uiDC.xscale; trap_R_DrawStretchPic( x, y, size, h, 0, 0, 0, 0, uiInfo.uiDC.whiteShader ); trap_R_DrawStretchPic( x + w - size, y, size, h, 0, 0, 0, 0, uiInfo.uiDC.whiteShader ); } -void UI_DrawTopBottom(float x, float y, float w, float h, float size) { +void UI_DrawTopBottom( float x, float y, float w, float h, float size ) +{ UI_AdjustFrom640( &x, &y, &w, &h ); size *= uiInfo.uiDC.yscale; trap_R_DrawStretchPic( x, y, w, size, 0, 0, 0, 0, uiInfo.uiDC.whiteShader ); trap_R_DrawStretchPic( x, y + h - size, w, size, 0, 0, 0, 0, uiInfo.uiDC.whiteShader ); } + /* ================ UI_DrawRect - + Coordinates are 640*480 virtual values ================= */ -void UI_DrawRect( float x, float y, float width, float height, float size, const float *color ) { +void UI_DrawRect( float x, float y, float width, float height, float size, const float *color ) +{ trap_R_SetColor( color ); - UI_DrawTopBottom(x, y, width, height, size); - UI_DrawSides(x, y, width, height, size); + UI_DrawTopBottom( x, y, width, height, size ); + UI_DrawSides( x, y, width, height, size ); trap_R_SetColor( NULL ); } @@ -224,17 +239,19 @@ void UI_DrawRect( float x, float y, float width, float height, float size, const UI_InsertServerIntoDisplayList ================== */ -static void UI_InsertServerIntoDisplayList(int num, int position) { +static void UI_InsertServerIntoDisplayList( int num, int position ) +{ int i; - if (position < 0 || position > uiInfo.serverStatus.numDisplayServers ) { + if( position < 0 || position > uiInfo.serverStatus.numDisplayServers ) return; - } + // uiInfo.serverStatus.numDisplayServers++; - for (i = uiInfo.serverStatus.numDisplayServers; i > position; i--) { + + for( i = uiInfo.serverStatus.numDisplayServers; i > position; i-- ) uiInfo.serverStatus.displayServers[i] = uiInfo.serverStatus.displayServers[i-1]; - } + uiInfo.serverStatus.displayServers[position] = num; } @@ -243,15 +260,19 @@ static void UI_InsertServerIntoDisplayList(int num, int position) { UI_RemoveServerFromDisplayList ================== */ -static void UI_RemoveServerFromDisplayList(int num) { +static void UI_RemoveServerFromDisplayList( int num ) +{ int i, j; - for (i = 0; i < uiInfo.serverStatus.numDisplayServers; i++) { - if (uiInfo.serverStatus.displayServers[i] == num) { + for( i = 0; i < uiInfo.serverStatus.numDisplayServers; i++ ) + { + if( uiInfo.serverStatus.displayServers[i] == num ) + { uiInfo.serverStatus.numDisplayServers--; - for (j = i; j < uiInfo.serverStatus.numDisplayServers; j++) { + + for( j = i; j < uiInfo.serverStatus.numDisplayServers; j++ ) uiInfo.serverStatus.displayServers[j] = uiInfo.serverStatus.displayServers[j+1]; - } + return; } } @@ -262,7 +283,8 @@ static void UI_RemoveServerFromDisplayList(int num) { UI_BinaryServerInsertion ================== */ -static void UI_BinaryServerInsertion(int num) { +static void UI_BinaryServerInsertion( int num ) +{ int mid, offset, res, len; // use binary search to insert server @@ -270,64 +292,78 @@ static void UI_BinaryServerInsertion(int num) { mid = len; offset = 0; res = 0; - while(mid > 0) { + + while( mid > 0 ) + { mid = len >> 1; // res = trap_LAN_CompareServers( ui_netSource.integer, uiInfo.serverStatus.sortKey, - uiInfo.serverStatus.sortDir, num, uiInfo.serverStatus.displayServers[offset+mid]); + uiInfo.serverStatus.sortDir, num, uiInfo.serverStatus.displayServers[offset+mid] ); // if equal - if (res == 0) { - UI_InsertServerIntoDisplayList(num, offset+mid); + + if( res == 0 ) + { + UI_InsertServerIntoDisplayList( num, offset + mid ); return; } + // if larger - else if (res == 1) { + else if( res == 1 ) + { offset += mid; len -= mid; } + // if smaller - else { + else len -= mid; - } } - if (res == 1) { + + if( res == 1 ) offset++; - } - UI_InsertServerIntoDisplayList(num, offset); + + UI_InsertServerIntoDisplayList( num, offset ); } typedef struct { char *name, *altName; -} serverStatusCvar_t; +} + +serverStatusCvar_t; serverStatusCvar_t serverStatusCvars[] = { - {"sv_hostname", "Name"}, - {"Address", ""}, - {"gamename", "Game name"}, - {"mapname", "Map"}, - {"version", ""}, - {"protocol", ""}, - {"timelimit", ""}, - {NULL, NULL} -}; + {"sv_hostname", "Name"}, + {"Address", ""}, + {"gamename", "Game name"}, + {"mapname", "Map"}, + {"version", ""}, + {"protocol", ""}, + {"timelimit", ""}, + {NULL, NULL} + }; /* ================== UI_SortServerStatusInfo ================== */ -static void UI_SortServerStatusInfo( serverStatusInfo_t *info ) { +static void UI_SortServerStatusInfo( serverStatusInfo_t *info ) +{ int i, j, index; char *tmp1, *tmp2; index = 0; - for (i = 0; serverStatusCvars[i].name; i++) { - for (j = 0; j < info->numLines; j++) { - if ( !info->lines[j][1] || info->lines[j][1][0] ) { + + for( i = 0; serverStatusCvars[i].name; i++ ) + { + for( j = 0; j < info->numLines; j++ ) + { + if( !info->lines[j][1] || info->lines[j][1][0] ) continue; - } - if ( !Q_stricmp(serverStatusCvars[i].name, info->lines[j][0]) ) { + + if( !Q_stricmp( serverStatusCvars[i].name, info->lines[j][0] ) ) + { // swap lines tmp1 = info->lines[index][0]; tmp2 = info->lines[index][3]; @@ -336,9 +372,10 @@ static void UI_SortServerStatusInfo( serverStatusInfo_t *info ) { info->lines[j][0] = tmp1; info->lines[j][3] = tmp2; // - if ( strlen(serverStatusCvars[i].altName) ) { + + if( strlen( serverStatusCvars[i].altName ) ) info->lines[index][0] = serverStatusCvars[i].altName; - } + index++; } } @@ -350,17 +387,22 @@ static void UI_SortServerStatusInfo( serverStatusInfo_t *info ) { UI_GetServerStatusInfo ================== */ -static int UI_GetServerStatusInfo( const char *serverAddress, serverStatusInfo_t *info ) { - char *p, *score, *ping, *name; +static int UI_GetServerStatusInfo( const char *serverAddress, serverStatusInfo_t *info ) +{ + char * p, *score, *ping, *name; int i, len; - if (!info) { - trap_LAN_ServerStatus( serverAddress, NULL, 0); + if( !info ) + { + trap_LAN_ServerStatus( serverAddress, NULL, 0 ); return qfalse; } - memset(info, 0, sizeof(*info)); - if ( trap_LAN_ServerStatus( serverAddress, info->text, sizeof(info->text)) ) { - Q_strncpyz(info->address, serverAddress, sizeof(info->address)); + + memset( info, 0, sizeof( *info ) ); + + if( trap_LAN_ServerStatus( serverAddress, info->text, sizeof( info->text ) ) ) + { + Q_strncpyz( info->address, serverAddress, sizeof( info->address ) ); p = info->text; info->numLines = 0; info->lines[info->numLines][0] = "Address"; @@ -369,26 +411,38 @@ static int UI_GetServerStatusInfo( const char *serverAddress, serverStatusInfo_t info->lines[info->numLines][3] = info->address; info->numLines++; // get the cvars - while (p && *p) { - p = strchr(p, '\\'); - if (!p) break; + + while( p && *p ) + { + p = strchr( p, '\\' ); + + if( !p ) break; + *p++ = '\0'; - if (*p == '\\') + + if( *p == '\\' ) break; + info->lines[info->numLines][0] = p; info->lines[info->numLines][1] = ""; info->lines[info->numLines][2] = ""; - p = strchr(p, '\\'); - if (!p) break; + + p = strchr( p, '\\' ); + + if( !p ) break; + *p++ = '\0'; - info->lines[info->numLines][3] = p; + info->lines[info->numLines][3] = p; info->numLines++; - if (info->numLines >= MAX_SERVERSTATUS_LINES) + + if( info->numLines >= MAX_SERVERSTATUS_LINES ) break; } + // get the player list - if (info->numLines < MAX_SERVERSTATUS_LINES-3) { + if( info->numLines < MAX_SERVERSTATUS_LINES - 3 ) + { // empty line info->lines[info->numLines][0] = ""; info->lines[info->numLines][1] = ""; @@ -404,42 +458,65 @@ static int UI_GetServerStatusInfo( const char *serverAddress, serverStatusInfo_t // parse players i = 0; len = 0; - while (p && *p) { - if (*p == '\\') - *p++ = '\0'; - if (!p) + + while( p && *p ) + { + if( *p == '\\' ) + * p++ = '\0'; + + if( !p ) break; + score = p; - p = strchr(p, ' '); - if (!p) + + p = strchr( p, ' ' ); + + if( !p ) break; + *p++ = '\0'; + ping = p; - p = strchr(p, ' '); - if (!p) + + p = strchr( p, ' ' ); + + if( !p ) break; + *p++ = '\0'; + name = p; - Com_sprintf(&info->pings[len], sizeof(info->pings)-len, "%d", i); + + Com_sprintf( &info->pings[len], sizeof( info->pings ) - len, "%d", i ); + info->lines[info->numLines][0] = &info->pings[len]; - len += strlen(&info->pings[len]) + 1; + + len += strlen( &info->pings[len] ) + 1; + info->lines[info->numLines][1] = score; info->lines[info->numLines][2] = ping; info->lines[info->numLines][3] = name; info->numLines++; - if (info->numLines >= MAX_SERVERSTATUS_LINES) + + if( info->numLines >= MAX_SERVERSTATUS_LINES ) break; - p = strchr(p, '\\'); - if (!p) + + p = strchr( p, '\\' ); + + if( !p ) break; + *p++ = '\0'; + // i++; } } + UI_SortServerStatusInfo( info ); return qtrue; } + return qfalse; } @@ -448,16 +525,20 @@ static int UI_GetServerStatusInfo( const char *serverAddress, serverStatusInfo_t stristr ================== */ -static char *stristr(char *str, char *charset) { +static char *stristr( char *str, char *charset ) +{ int i; - while(*str) { - for (i = 0; charset[i] && str[i]; i++) { - if (toupper(charset[i]) != toupper(str[i])) break; - } - if (!charset[i]) return str; + while( *str ) + { + for( i = 0; charset[i] && str[i]; i++ ) + if( toupper( charset[i] ) != toupper( str[i] ) ) break; + + if( !charset[i] ) return str; + str++; } + return NULL; } @@ -466,9 +547,10 @@ static char *stristr(char *str, char *charset) { UI_BuildFindPlayerList ================== */ -static void UI_FeederSelection(float feederID, int index); +static void UI_FeederSelection( float feederID, int index ); -static void UI_BuildFindPlayerList(qboolean force) { +static void UI_BuildFindPlayerList( qboolean force ) +{ static int numFound, numTimeOuts; int i, j, k, resend; serverStatusInfo_t info; @@ -476,137 +558,180 @@ static void UI_BuildFindPlayerList(qboolean force) { char infoString[MAX_STRING_CHARS]; qboolean duplicate; - if (!force) { - if (!uiInfo.nextFindPlayerRefresh || uiInfo.nextFindPlayerRefresh > uiInfo.uiDC.realTime) { + if( !force ) + { + if( !uiInfo.nextFindPlayerRefresh || uiInfo.nextFindPlayerRefresh > uiInfo.uiDC.realTime ) return; - } } - else { - memset(&uiInfo.pendingServerStatus, 0, sizeof(uiInfo.pendingServerStatus)); + else + { + memset( &uiInfo.pendingServerStatus, 0, sizeof( uiInfo.pendingServerStatus ) ); uiInfo.numFoundPlayerServers = 0; uiInfo.currentFoundPlayerServer = 0; - trap_Cvar_VariableStringBuffer( "ui_findPlayer", uiInfo.findPlayerName, sizeof(uiInfo.findPlayerName)); - Q_CleanStr(uiInfo.findPlayerName); + trap_Cvar_VariableStringBuffer( "ui_findPlayer", uiInfo.findPlayerName, sizeof( uiInfo.findPlayerName ) ); + Q_CleanStr( uiInfo.findPlayerName ); // should have a string of some length - if (!strlen(uiInfo.findPlayerName)) { + + if( !strlen( uiInfo.findPlayerName ) ) + { uiInfo.nextFindPlayerRefresh = 0; return; } + // set resend time resend = ui_serverStatusTimeOut.integer / 2 - 10; - if (resend < 50) { + + if( resend < 50 ) resend = 50; - } - trap_Cvar_Set("cl_serverStatusResendTime", va("%d", resend)); + + trap_Cvar_Set( "cl_serverStatusResendTime", va( "%d", resend ) ); // reset all server status requests - trap_LAN_ServerStatus( NULL, NULL, 0); + trap_LAN_ServerStatus( NULL, NULL, 0 ); // uiInfo.numFoundPlayerServers = 1; - Com_sprintf(uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1], - sizeof(uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1]), - "searching %d...", uiInfo.pendingServerStatus.num); + Com_sprintf( uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1], + sizeof( uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1] ), + "searching %d...", uiInfo.pendingServerStatus.num ); numFound = 0; numTimeOuts++; } - for (i = 0; i < MAX_SERVERSTATUSREQUESTS; i++) { + + for( i = 0; i < MAX_SERVERSTATUSREQUESTS; i++ ) + { // if this pending server is valid - if (uiInfo.pendingServerStatus.server[i].valid) { + + if( uiInfo.pendingServerStatus.server[i].valid ) + { // try to get the server status for this server - if (UI_GetServerStatusInfo( uiInfo.pendingServerStatus.server[i].adrstr, &info ) ) { + + if( UI_GetServerStatusInfo( uiInfo.pendingServerStatus.server[i].adrstr, &info ) ) + { // numFound++; // parse through the server status lines - for (j = 0; j < info.numLines; j++) { + + for( j = 0; j < info.numLines; j++ ) + { // should have ping info - if ( !info.lines[j][2] || !info.lines[j][2][0] ) { + + if( !info.lines[j][2] || !info.lines[j][2][0] ) continue; - } + // clean string first - Q_strncpyz(name, info.lines[j][3], sizeof(name)); - Q_CleanStr(name); + Q_strncpyz( name, info.lines[j][3], sizeof( name ) ); + + Q_CleanStr( name ); duplicate = qfalse; + for( k = 0; k < uiInfo.numFoundPlayerServers - 1; k++ ) { - if( Q_strncmp( uiInfo.foundPlayerServerAddresses[ k ], - uiInfo.pendingServerStatus.server[ i ].adrstr, - MAX_ADDRESSLENGTH ) == 0 ) - duplicate = qtrue; + if( Q_strncmp( uiInfo.foundPlayerServerAddresses[ k ], + uiInfo.pendingServerStatus.server[ i ].adrstr, + MAX_ADDRESSLENGTH ) == 0 ) + duplicate = qtrue; } // if the player name is a substring - if( stristr( name, uiInfo.findPlayerName ) && !duplicate ) { + if( stristr( name, uiInfo.findPlayerName ) && !duplicate ) + { // add to found server list if we have space (always leave space for a line with the number found) - if (uiInfo.numFoundPlayerServers < MAX_FOUNDPLAYER_SERVERS-1) { + + if( uiInfo.numFoundPlayerServers < MAX_FOUNDPLAYER_SERVERS - 1 ) + { // - Q_strncpyz(uiInfo.foundPlayerServerAddresses[uiInfo.numFoundPlayerServers-1], - uiInfo.pendingServerStatus.server[i].adrstr, - sizeof(uiInfo.foundPlayerServerAddresses[0])); - Q_strncpyz(uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1], - uiInfo.pendingServerStatus.server[i].name, - sizeof(uiInfo.foundPlayerServerNames[0])); + Q_strncpyz( uiInfo.foundPlayerServerAddresses[uiInfo.numFoundPlayerServers-1], + uiInfo.pendingServerStatus.server[i].adrstr, + sizeof( uiInfo.foundPlayerServerAddresses[0] ) ); + Q_strncpyz( uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1], + uiInfo.pendingServerStatus.server[i].name, + sizeof( uiInfo.foundPlayerServerNames[0] ) ); uiInfo.numFoundPlayerServers++; } - else { + else + { // can't add any more so we're done uiInfo.pendingServerStatus.num = uiInfo.serverStatus.numDisplayServers; } } } - Com_sprintf(uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1], - sizeof(uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1]), - "searching %d/%d...", numFound, uiInfo.pendingServerStatus.num ); + + Com_sprintf( uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1], + sizeof( uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1] ), + "searching %d/%d...", numFound, uiInfo.pendingServerStatus.num ); // retrieved the server status so reuse this spot uiInfo.pendingServerStatus.server[i].valid = qfalse; } } + // if empty pending slot or timed out - if (!uiInfo.pendingServerStatus.server[i].valid || - uiInfo.pendingServerStatus.server[i].startTime < uiInfo.uiDC.realTime - ui_serverStatusTimeOut.integer) { - if (uiInfo.pendingServerStatus.server[i].valid) { + if( !uiInfo.pendingServerStatus.server[i].valid || + uiInfo.pendingServerStatus.server[i].startTime < uiInfo.uiDC.realTime - ui_serverStatusTimeOut.integer ) + { + if( uiInfo.pendingServerStatus.server[i].valid ) numTimeOuts++; - } + // reset server status request for this address UI_GetServerStatusInfo( uiInfo.pendingServerStatus.server[i].adrstr, NULL ); + // reuse pending slot uiInfo.pendingServerStatus.server[i].valid = qfalse; + // if we didn't try to get the status of all servers in the main browser yet - if (uiInfo.pendingServerStatus.num < uiInfo.serverStatus.numDisplayServers) { + if( uiInfo.pendingServerStatus.num < uiInfo.serverStatus.numDisplayServers ) + { uiInfo.pendingServerStatus.server[i].startTime = uiInfo.uiDC.realTime; - trap_LAN_GetServerAddressString(ui_netSource.integer, uiInfo.serverStatus.displayServers[uiInfo.pendingServerStatus.num], - uiInfo.pendingServerStatus.server[i].adrstr, sizeof(uiInfo.pendingServerStatus.server[i].adrstr)); - trap_LAN_GetServerInfo(ui_netSource.integer, uiInfo.serverStatus.displayServers[uiInfo.pendingServerStatus.num], infoString, sizeof(infoString)); - Q_strncpyz(uiInfo.pendingServerStatus.server[i].name, Info_ValueForKey(infoString, "hostname"), sizeof(uiInfo.pendingServerStatus.server[0].name)); + trap_LAN_GetServerAddressString( ui_netSource.integer, + uiInfo.serverStatus.displayServers[uiInfo.pendingServerStatus.num], + uiInfo.pendingServerStatus.server[i].adrstr, + sizeof( uiInfo.pendingServerStatus.server[i].adrstr ) ); + + trap_LAN_GetServerInfo( ui_netSource.integer, + uiInfo.serverStatus.displayServers[uiInfo.pendingServerStatus.num], + infoString, sizeof( infoString ) ); + + Q_strncpyz( uiInfo.pendingServerStatus.server[i].name, + Info_ValueForKey( infoString, "hostname" ), + sizeof( uiInfo.pendingServerStatus.server[0].name ) ); + uiInfo.pendingServerStatus.server[i].valid = qtrue; uiInfo.pendingServerStatus.num++; - Com_sprintf(uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1], - sizeof(uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1]), - "searching %d/%d...", numFound, uiInfo.pendingServerStatus.num ); + Com_sprintf( uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1], + sizeof( uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1] ), + "searching %d/%d...", numFound, uiInfo.pendingServerStatus.num ); } } } - for (i = 0; i < MAX_SERVERSTATUSREQUESTS; i++) { - if (uiInfo.pendingServerStatus.server[i].valid) { + + for( i = 0; i < MAX_SERVERSTATUSREQUESTS; i++ ) + { + if( uiInfo.pendingServerStatus.server[i].valid ) break; - } } + // if still trying to retrieve server status info - if (i < MAX_SERVERSTATUSREQUESTS) { + if( i < MAX_SERVERSTATUSREQUESTS ) uiInfo.nextFindPlayerRefresh = uiInfo.uiDC.realTime + 25; - } - else { + else + { // add a line that shows the number of servers found - if (!uiInfo.numFoundPlayerServers) { - Com_sprintf(uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1], sizeof(uiInfo.foundPlayerServerAddresses[0]), "no servers found"); + + if( !uiInfo.numFoundPlayerServers ) + { + Com_sprintf( uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1], + sizeof( uiInfo.foundPlayerServerAddresses[0] ), "no servers found" ); } - else { - Com_sprintf(uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1], sizeof(uiInfo.foundPlayerServerAddresses[0]), - "%d server%s found with player %s", uiInfo.numFoundPlayerServers-1, - uiInfo.numFoundPlayerServers == 2 ? "":"s", uiInfo.findPlayerName); + else + { + Com_sprintf( uiInfo.foundPlayerServerNames[uiInfo.numFoundPlayerServers-1], + sizeof( uiInfo.foundPlayerServerAddresses[0] ), + "%d server%s found with player %s", uiInfo.numFoundPlayerServers - 1, + uiInfo.numFoundPlayerServers == 2 ? "" : "s", uiInfo.findPlayerName ); } + uiInfo.nextFindPlayerRefresh = 0; // show the server status info for the selected server - UI_FeederSelection(FEEDER_FINDPLAYER, uiInfo.currentFoundPlayerServer); + UI_FeederSelection( FEEDER_FINDPLAYER, uiInfo.currentFoundPlayerServer ); } } @@ -615,32 +740,36 @@ static void UI_BuildFindPlayerList(qboolean force) { UI_BuildServerStatus ================== */ -static void UI_BuildServerStatus(qboolean force) { - - if (uiInfo.nextFindPlayerRefresh) { +static void UI_BuildServerStatus( qboolean force ) +{ + if( uiInfo.nextFindPlayerRefresh ) return; - } - if (!force) { - if (!uiInfo.nextServerStatusRefresh || uiInfo.nextServerStatusRefresh > uiInfo.uiDC.realTime) { + + if( !force ) + { + if( !uiInfo.nextServerStatusRefresh || uiInfo.nextServerStatusRefresh > uiInfo.uiDC.realTime ) return; - } } - else { - Menu_SetFeederSelection(NULL, FEEDER_SERVERSTATUS, 0, NULL); + else + { + Menu_SetFeederSelection( NULL, FEEDER_SERVERSTATUS, 0, NULL ); uiInfo.serverStatusInfo.numLines = 0; // reset all server status requests - trap_LAN_ServerStatus( NULL, NULL, 0); + trap_LAN_ServerStatus( NULL, NULL, 0 ); } - if (uiInfo.serverStatus.currentServer < 0 || uiInfo.serverStatus.currentServer > uiInfo.serverStatus.numDisplayServers || uiInfo.serverStatus.numDisplayServers == 0) { + + if( uiInfo.serverStatus.currentServer < 0 || + uiInfo.serverStatus.currentServer > uiInfo.serverStatus.numDisplayServers || + uiInfo.serverStatus.numDisplayServers == 0 ) return; - } - if (UI_GetServerStatusInfo( uiInfo.serverStatusAddress, &uiInfo.serverStatusInfo ) ) { + + if( UI_GetServerStatusInfo( uiInfo.serverStatusAddress, &uiInfo.serverStatusInfo ) ) + { uiInfo.nextServerStatusRefresh = 0; UI_GetServerStatusInfo( uiInfo.serverStatusAddress, NULL ); } - else { + else uiInfo.nextServerStatusRefresh = uiInfo.uiDC.realTime + 500; - } } /* @@ -648,41 +777,47 @@ static void UI_BuildServerStatus(qboolean force) { UI_BuildServerDisplayList ================== */ -static void UI_BuildServerDisplayList(qboolean force) { +static void UI_BuildServerDisplayList( qboolean force ) +{ int i, count, clients, maxClients, ping, len, visible; char info[MAX_STRING_CHARS]; static int numinvisible; - if (!(force || uiInfo.uiDC.realTime > uiInfo.serverStatus.nextDisplayRefresh)) { + if( !( force || uiInfo.uiDC.realTime > uiInfo.serverStatus.nextDisplayRefresh ) ) return; - } + // if we shouldn't reset - if ( force == 2 ) { + if( force == 2 ) force = 0; - } // do motd updates here too - trap_Cvar_VariableStringBuffer( "cl_motdString", uiInfo.serverStatus.motd, sizeof(uiInfo.serverStatus.motd) ); - len = strlen(uiInfo.serverStatus.motd); - if (len != uiInfo.serverStatus.motdLen) { + trap_Cvar_VariableStringBuffer( "cl_motdString", uiInfo.serverStatus.motd, sizeof( uiInfo.serverStatus.motd ) ); + + len = strlen( uiInfo.serverStatus.motd ); + + if( len != uiInfo.serverStatus.motdLen ) + { uiInfo.serverStatus.motdLen = len; uiInfo.serverStatus.motdWidth = -1; } - if (force) { + if( force ) + { numinvisible = 0; // clear number of displayed servers uiInfo.serverStatus.numDisplayServers = 0; uiInfo.serverStatus.numPlayersOnServers = 0; // set list box index to zero - Menu_SetFeederSelection(NULL, FEEDER_SERVERS, 0, NULL); + Menu_SetFeederSelection( NULL, FEEDER_SERVERS, 0, NULL ); // mark all servers as visible so we store ping updates for them - trap_LAN_MarkServerVisible(ui_netSource.integer, -1, qtrue); + trap_LAN_MarkServerVisible( ui_netSource.integer, -1, qtrue ); } // get the server count (comes from the master) - count = trap_LAN_GetServerCount(ui_netSource.integer); - if (count == -1 || (ui_netSource.integer == AS_LOCAL && count == 0) ) { + count = trap_LAN_GetServerCount( ui_netSource.integer ); + + if( count == -1 || ( ui_netSource.integer == AS_LOCAL && count == 0 ) ) + { // still waiting on a response from the master uiInfo.serverStatus.numDisplayServers = 0; uiInfo.serverStatus.numPlayersOnServers = 0; @@ -691,45 +826,56 @@ static void UI_BuildServerDisplayList(qboolean force) { } visible = qfalse; - for (i = 0; i < count; i++) { + + for( i = 0; i < count; i++ ) + { // if we already got info for this server - if (!trap_LAN_ServerIsVisible(ui_netSource.integer, i)) { + + if( !trap_LAN_ServerIsVisible( ui_netSource.integer, i ) ) continue; - } + visible = qtrue; // get the ping for this server - ping = trap_LAN_GetServerPing(ui_netSource.integer, i); - if (ping > 0 || ui_netSource.integer == AS_FAVORITES) { + ping = trap_LAN_GetServerPing( ui_netSource.integer, i ); - trap_LAN_GetServerInfo(ui_netSource.integer, i, info, MAX_STRING_CHARS); + if( ping > 0 || ui_netSource.integer == AS_FAVORITES ) + { + trap_LAN_GetServerInfo( ui_netSource.integer, i, info, MAX_STRING_CHARS ); - clients = atoi(Info_ValueForKey(info, "clients")); + clients = atoi( Info_ValueForKey( info, "clients" ) ); uiInfo.serverStatus.numPlayersOnServers += clients; - if (ui_browserShowEmpty.integer == 0) { - if (clients == 0) { - trap_LAN_MarkServerVisible(ui_netSource.integer, i, qfalse); + if( ui_browserShowEmpty.integer == 0 ) + { + if( clients == 0 ) + { + trap_LAN_MarkServerVisible( ui_netSource.integer, i, qfalse ); continue; } } - if (ui_browserShowFull.integer == 0) { - maxClients = atoi(Info_ValueForKey(info, "sv_maxclients")); - if (clients == maxClients) { - trap_LAN_MarkServerVisible(ui_netSource.integer, i, qfalse); + if( ui_browserShowFull.integer == 0 ) + { + maxClients = atoi( Info_ValueForKey( info, "sv_maxclients" ) ); + + if( clients == maxClients ) + { + trap_LAN_MarkServerVisible( ui_netSource.integer, i, qfalse ); continue; } } // make sure we never add a favorite server twice - if (ui_netSource.integer == AS_FAVORITES) { - UI_RemoveServerFromDisplayList(i); - } + if( ui_netSource.integer == AS_FAVORITES ) + UI_RemoveServerFromDisplayList( i ); + // insert the server into the list - UI_BinaryServerInsertion(i); + UI_BinaryServerInsertion( i ); + // done with this server - if (ping > 0) { - trap_LAN_MarkServerVisible(ui_netSource.integer, i, qfalse); + if( ping > 0 ) + { + trap_LAN_MarkServerVisible( ui_netSource.integer, i, qfalse ); numinvisible++; } } @@ -738,7 +884,9 @@ static void UI_BuildServerDisplayList(qboolean force) { uiInfo.serverStatus.refreshtime = uiInfo.uiDC.realTime; // if there were no servers visible for ping updates - if (!visible) { + + if( !visible ) + { // UI_StopServerRefresh(); // uiInfo.serverStatus.nextDisplayRefresh = 0; } @@ -754,19 +902,23 @@ static void UI_StopServerRefresh( void ) { int count; - if (!uiInfo.serverStatus.refreshActive) { + if( !uiInfo.serverStatus.refreshActive ) + { // not currently refreshing return; } + uiInfo.serverStatus.refreshActive = qfalse; - Com_Printf("%d servers listed in browser with %d players.\n", - uiInfo.serverStatus.numDisplayServers, - uiInfo.serverStatus.numPlayersOnServers); - count = trap_LAN_GetServerCount(ui_netSource.integer); - if (count - uiInfo.serverStatus.numDisplayServers > 0) { - Com_Printf("%d servers not listed due to packet loss or pings higher than %d\n", - count - uiInfo.serverStatus.numDisplayServers, - (int) trap_Cvar_VariableValue("cl_maxPing")); + Com_Printf( "%d servers listed in browser with %d players.\n", + uiInfo.serverStatus.numDisplayServers, + uiInfo.serverStatus.numPlayersOnServers ); + count = trap_LAN_GetServerCount( ui_netSource.integer ); + + if( count - uiInfo.serverStatus.numDisplayServers > 0 ) + { + Com_Printf( "%d servers not listed due to packet loss or pings higher than %d\n", + count - uiInfo.serverStatus.numDisplayServers, + ( int ) trap_Cvar_VariableValue( "cl_maxPing" ) ); } } @@ -780,38 +932,42 @@ static void UI_DoServerRefresh( void ) { qboolean wait = qfalse; - if (!uiInfo.serverStatus.refreshActive) { + if( !uiInfo.serverStatus.refreshActive ) return; - } - if (ui_netSource.integer != AS_FAVORITES) { - if (ui_netSource.integer == AS_LOCAL) { - if (!trap_LAN_GetServerCount(ui_netSource.integer)) { + + if( ui_netSource.integer != AS_FAVORITES ) + { + if( ui_netSource.integer == AS_LOCAL ) + { + if( !trap_LAN_GetServerCount( ui_netSource.integer ) ) wait = qtrue; - } - } else { - if (trap_LAN_GetServerCount(ui_netSource.integer) < 0) { + } + else + { + if( trap_LAN_GetServerCount( ui_netSource.integer ) < 0 ) wait = qtrue; - } } } - if (uiInfo.uiDC.realTime < uiInfo.serverStatus.refreshtime) { - if (wait) { + if( uiInfo.uiDC.realTime < uiInfo.serverStatus.refreshtime ) + { + if( wait ) return; - } } // if still trying to retrieve pings - if (trap_LAN_UpdateVisiblePings(ui_netSource.integer)) { + if( trap_LAN_UpdateVisiblePings( ui_netSource.integer ) ) uiInfo.serverStatus.refreshtime = uiInfo.uiDC.realTime + 1000; - } else if (!wait) { + else if( !wait ) + { // get the last servers in the list - UI_BuildServerDisplayList(2); + UI_BuildServerDisplayList( 2 ); // stop the refresh UI_StopServerRefresh(); } + // - UI_BuildServerDisplayList(qfalse); + UI_BuildServerDisplayList( qfalse ); } /* @@ -819,8 +975,9 @@ static void UI_DoServerRefresh( void ) UI_UpdatePendingPings ================= */ -static void UI_UpdatePendingPings( void ) { - trap_LAN_ResetPings(ui_netSource.integer); +static void UI_UpdatePendingPings( void ) +{ + trap_LAN_ResetPings( ui_netSource.integer ); uiInfo.serverStatus.refreshActive = qtrue; uiInfo.serverStatus.refreshtime = uiInfo.uiDC.realTime + 1000; @@ -831,20 +988,22 @@ static void UI_UpdatePendingPings( void ) { UI_StartServerRefresh ================= */ -static void UI_StartServerRefresh(qboolean full) +static void UI_StartServerRefresh( qboolean full ) { int i; char *ptr; int time; qtime_t q; - time = trap_RealTime(&q); - trap_Cvar_Set( va("ui_lastServerRefresh_%i_time", ui_netSource.integer ), - va( "%i", time ) ); - trap_Cvar_Set( va("ui_lastServerRefresh_%i", ui_netSource.integer), - va("%s-%i, %i at %i:%02i", MonthAbbrev[q.tm_mon],q.tm_mday, 1900+q.tm_year,q.tm_hour,q.tm_min)); + time = trap_RealTime( &q ); + trap_Cvar_Set( va( "ui_lastServerRefresh_%i_time", ui_netSource.integer ), + va( "%i", time ) ); + trap_Cvar_Set( va( "ui_lastServerRefresh_%i", ui_netSource.integer ), + va( "%s-%i, %i at %i:%02i", MonthAbbrev[q.tm_mon], + q.tm_mday, 1900 + q.tm_year, q.tm_hour, q.tm_min ) ); - if (!full) { + if( !full ) + { UI_UpdatePendingPings(); return; } @@ -855,31 +1014,35 @@ static void UI_StartServerRefresh(qboolean full) uiInfo.serverStatus.numDisplayServers = 0; uiInfo.serverStatus.numPlayersOnServers = 0; // mark all servers as visible so we store ping updates for them - trap_LAN_MarkServerVisible(ui_netSource.integer, -1, qtrue); + trap_LAN_MarkServerVisible( ui_netSource.integer, -1, qtrue ); // reset all the pings - trap_LAN_ResetPings(ui_netSource.integer); + trap_LAN_ResetPings( ui_netSource.integer ); // - if( ui_netSource.integer == AS_LOCAL ) { + + if( ui_netSource.integer == AS_LOCAL ) + { trap_Cmd_ExecuteText( EXEC_NOW, "localservers\n" ); uiInfo.serverStatus.refreshtime = uiInfo.uiDC.realTime + 1000; return; } uiInfo.serverStatus.refreshtime = uiInfo.uiDC.realTime + 5000; - if( ui_netSource.integer == AS_GLOBAL || ui_netSource.integer == AS_MPLAYER ) { - if( ui_netSource.integer == AS_GLOBAL ) { + + if( ui_netSource.integer == AS_GLOBAL || ui_netSource.integer == AS_MPLAYER ) + { + if( ui_netSource.integer == AS_GLOBAL ) i = 0; - } - else { + else i = 1; - } - ptr = UI_Cvar_VariableString("debug_protocol"); - if (strlen(ptr)) { - trap_Cmd_ExecuteText( EXEC_NOW, va( "globalservers %d %s full empty\n", i, ptr)); - } - else { - trap_Cmd_ExecuteText( EXEC_NOW, va( "globalservers %d %d full empty\n", i, (int)trap_Cvar_VariableValue( "protocol" ) ) ); + ptr = UI_Cvar_VariableString( "debug_protocol" ); + + if( strlen( ptr ) ) + trap_Cmd_ExecuteText( EXEC_NOW, va( "globalservers %d %s full empty\n", i, ptr ) ); + else + { + trap_Cmd_ExecuteText( EXEC_NOW, va( "globalservers %d %d full empty\n", i, + (int)trap_Cvar_VariableValue( "protocol" ) ) ); } } } @@ -893,7 +1056,7 @@ void UI_Refresh( int realtime ) static int index; static int previousTimes[UI_FPS_FRAMES]; - //if ( !( trap_Key_GetCatcher() & KEYCATCH_UI ) ) { + //if( !( trap_Key_GetCatcher() & KEYCATCH_UI ) ) { // return; //} @@ -902,40 +1065,43 @@ void UI_Refresh( int realtime ) previousTimes[index % UI_FPS_FRAMES] = uiInfo.uiDC.frameTime; index++; - if ( index > UI_FPS_FRAMES ) { + + if( index > UI_FPS_FRAMES ) + { int i, total; // average multiple frames together to smooth changes out a bit total = 0; - for ( i = 0 ; i < UI_FPS_FRAMES ; i++ ) { + + for( i = 0 ; i < UI_FPS_FRAMES ; i++ ) total += previousTimes[i]; - } - if ( !total ) { + + if( !total ) total = 1; - } + uiInfo.uiDC.FPS = 1000 * UI_FPS_FRAMES / total; } - - UI_UpdateCvars(); - if (Menu_Count() > 0) { + if( Menu_Count() > 0 ) + { // paint all the menus Menu_PaintAll(); // refresh server browser list UI_DoServerRefresh(); // refresh server status - UI_BuildServerStatus(qfalse); + UI_BuildServerStatus( qfalse ); // refresh find player list - UI_BuildFindPlayerList(qfalse); + UI_BuildFindPlayerList( qfalse ); } // draw cursor UI_SetColor( NULL ); + if( Menu_Count( ) > 0 && !trap_Cvar_VariableValue( "ui_hideCursor" ) ) { UI_DrawHandlePic( uiInfo.uiDC.cursorx - ( 16.0f * uiInfo.uiDC.aspectScale ), uiInfo.uiDC.cursory - 16.0f, - 32.0f * uiInfo.uiDC.aspectScale, 32.0f, uiInfo.uiDC.Assets.cursor); + 32.0f * uiInfo.uiDC.aspectScale, 32.0f, uiInfo.uiDC.Assets.cursor ); } } @@ -944,238 +1110,263 @@ void UI_Refresh( int realtime ) UI_Shutdown ================= */ -void UI_Shutdown( void ) { +void UI_Shutdown( void ) +{ trap_LAN_SaveCachedServers(); } -qboolean Asset_Parse(int handle) { +qboolean Asset_Parse( int handle ) +{ pc_token_t token; const char *tempStr; - if (!trap_Parse_ReadToken(handle, &token)) + if( !trap_Parse_ReadToken( handle, &token ) ) return qfalse; - if (Q_stricmp(token.string, "{") != 0) { - return qfalse; - } - while ( 1 ) { + if( Q_stricmp( token.string, "{" ) != 0 ) + return qfalse; - memset(&token, 0, sizeof(pc_token_t)); + while( 1 ) + { + memset( &token, 0, sizeof( pc_token_t ) ); - if (!trap_Parse_ReadToken(handle, &token)) + if( !trap_Parse_ReadToken( handle, &token ) ) return qfalse; - if (Q_stricmp(token.string, "}") == 0) { + if( Q_stricmp( token.string, "}" ) == 0 ) return qtrue; - } // font - if (Q_stricmp(token.string, "font") == 0) { + if( Q_stricmp( token.string, "font" ) == 0 ) + { int pointSize; - if (!PC_String_Parse(handle, &tempStr) || !PC_Int_Parse(handle,&pointSize)) { + + if( !PC_String_Parse( handle, &tempStr ) || !PC_Int_Parse( handle, &pointSize ) ) return qfalse; - } - trap_R_RegisterFont(tempStr, pointSize, &uiInfo.uiDC.Assets.textFont); + + trap_R_RegisterFont( tempStr, pointSize, &uiInfo.uiDC.Assets.textFont ); uiInfo.uiDC.Assets.fontRegistered = qtrue; continue; } - if (Q_stricmp(token.string, "smallFont") == 0) { + if( Q_stricmp( token.string, "smallFont" ) == 0 ) + { int pointSize; - if (!PC_String_Parse(handle, &tempStr) || !PC_Int_Parse(handle,&pointSize)) { + + if( !PC_String_Parse( handle, &tempStr ) || !PC_Int_Parse( handle, &pointSize ) ) return qfalse; - } - trap_R_RegisterFont(tempStr, pointSize, &uiInfo.uiDC.Assets.smallFont); + + trap_R_RegisterFont( tempStr, pointSize, &uiInfo.uiDC.Assets.smallFont ); continue; } - if (Q_stricmp(token.string, "bigFont") == 0) { + if( Q_stricmp( token.string, "bigFont" ) == 0 ) + { int pointSize; - if (!PC_String_Parse(handle, &tempStr) || !PC_Int_Parse(handle,&pointSize)) { + + if( !PC_String_Parse( handle, &tempStr ) || !PC_Int_Parse( handle, &pointSize ) ) return qfalse; - } - trap_R_RegisterFont(tempStr, pointSize, &uiInfo.uiDC.Assets.bigFont); + + trap_R_RegisterFont( tempStr, pointSize, &uiInfo.uiDC.Assets.bigFont ); continue; } // gradientbar - if (Q_stricmp(token.string, "gradientbar") == 0) { - if (!PC_String_Parse(handle, &tempStr)) { + if( Q_stricmp( token.string, "gradientbar" ) == 0 ) + { + if( !PC_String_Parse( handle, &tempStr ) ) return qfalse; - } - uiInfo.uiDC.Assets.gradientBar = trap_R_RegisterShaderNoMip(tempStr); + + uiInfo.uiDC.Assets.gradientBar = trap_R_RegisterShaderNoMip( tempStr ); continue; } // enterMenuSound - if (Q_stricmp(token.string, "menuEnterSound") == 0) { - if (!PC_String_Parse(handle, &tempStr)) { + if( Q_stricmp( token.string, "menuEnterSound" ) == 0 ) + { + if( !PC_String_Parse( handle, &tempStr ) ) return qfalse; - } + uiInfo.uiDC.Assets.menuEnterSound = trap_S_RegisterSound( tempStr, qfalse ); continue; } // exitMenuSound - if (Q_stricmp(token.string, "menuExitSound") == 0) { - if (!PC_String_Parse(handle, &tempStr)) { + if( Q_stricmp( token.string, "menuExitSound" ) == 0 ) + { + if( !PC_String_Parse( handle, &tempStr ) ) return qfalse; - } + uiInfo.uiDC.Assets.menuExitSound = trap_S_RegisterSound( tempStr, qfalse ); continue; } // itemFocusSound - if (Q_stricmp(token.string, "itemFocusSound") == 0) { - if (!PC_String_Parse(handle, &tempStr)) { + if( Q_stricmp( token.string, "itemFocusSound" ) == 0 ) + { + if( !PC_String_Parse( handle, &tempStr ) ) return qfalse; - } + uiInfo.uiDC.Assets.itemFocusSound = trap_S_RegisterSound( tempStr, qfalse ); continue; } // menuBuzzSound - if (Q_stricmp(token.string, "menuBuzzSound") == 0) { - if (!PC_String_Parse(handle, &tempStr)) { + if( Q_stricmp( token.string, "menuBuzzSound" ) == 0 ) + { + if( !PC_String_Parse( handle, &tempStr ) ) return qfalse; - } + uiInfo.uiDC.Assets.menuBuzzSound = trap_S_RegisterSound( tempStr, qfalse ); continue; } - if (Q_stricmp(token.string, "cursor") == 0) { - if (!PC_String_Parse(handle, &uiInfo.uiDC.Assets.cursorStr)) { + if( Q_stricmp( token.string, "cursor" ) == 0 ) + { + if( !PC_String_Parse( handle, &uiInfo.uiDC.Assets.cursorStr ) ) return qfalse; - } - uiInfo.uiDC.Assets.cursor = trap_R_RegisterShaderNoMip( uiInfo.uiDC.Assets.cursorStr); + + uiInfo.uiDC.Assets.cursor = trap_R_RegisterShaderNoMip( uiInfo.uiDC.Assets.cursorStr ); continue; } - if (Q_stricmp(token.string, "fadeClamp") == 0) { - if (!PC_Float_Parse(handle, &uiInfo.uiDC.Assets.fadeClamp)) { + if( Q_stricmp( token.string, "fadeClamp" ) == 0 ) + { + if( !PC_Float_Parse( handle, &uiInfo.uiDC.Assets.fadeClamp ) ) return qfalse; - } + continue; } - if (Q_stricmp(token.string, "fadeCycle") == 0) { - if (!PC_Int_Parse(handle, &uiInfo.uiDC.Assets.fadeCycle)) { + if( Q_stricmp( token.string, "fadeCycle" ) == 0 ) + { + if( !PC_Int_Parse( handle, &uiInfo.uiDC.Assets.fadeCycle ) ) return qfalse; - } + continue; } - if (Q_stricmp(token.string, "fadeAmount") == 0) { - if (!PC_Float_Parse(handle, &uiInfo.uiDC.Assets.fadeAmount)) { + if( Q_stricmp( token.string, "fadeAmount" ) == 0 ) + { + if( !PC_Float_Parse( handle, &uiInfo.uiDC.Assets.fadeAmount ) ) return qfalse; - } + continue; } - if (Q_stricmp(token.string, "shadowX") == 0) { - if (!PC_Float_Parse(handle, &uiInfo.uiDC.Assets.shadowX)) { + if( Q_stricmp( token.string, "shadowX" ) == 0 ) + { + if( !PC_Float_Parse( handle, &uiInfo.uiDC.Assets.shadowX ) ) return qfalse; - } + continue; } - if (Q_stricmp(token.string, "shadowY") == 0) { - if (!PC_Float_Parse(handle, &uiInfo.uiDC.Assets.shadowY)) { + if( Q_stricmp( token.string, "shadowY" ) == 0 ) + { + if( !PC_Float_Parse( handle, &uiInfo.uiDC.Assets.shadowY ) ) return qfalse; - } + continue; } - if (Q_stricmp(token.string, "shadowColor") == 0) { - if (!PC_Color_Parse(handle, &uiInfo.uiDC.Assets.shadowColor)) { + if( Q_stricmp( token.string, "shadowColor" ) == 0 ) + { + if( !PC_Color_Parse( handle, &uiInfo.uiDC.Assets.shadowColor ) ) return qfalse; - } + uiInfo.uiDC.Assets.shadowFadeClamp = uiInfo.uiDC.Assets.shadowColor[3]; continue; } } + return qfalse; } -void UI_Report( void ) { +void UI_Report( void ) +{ String_Report(); } -void UI_ParseMenu(const char *menuFile) { +void UI_ParseMenu( const char *menuFile ) +{ int handle; pc_token_t token; - handle = trap_Parse_LoadSource(menuFile); - if (!handle) { + handle = trap_Parse_LoadSource( menuFile ); + + if( !handle ) return; - } - while ( 1 ) { - memset(&token, 0, sizeof(pc_token_t)); - if (!trap_Parse_ReadToken( handle, &token )) { + while( 1 ) + { + memset( &token, 0, sizeof( pc_token_t ) ); + + if( !trap_Parse_ReadToken( handle, &token ) ) break; - } - //if ( Q_stricmp( token, "{" ) ) { + //if( Q_stricmp( token, "{" ) ) { // Com_Printf( "Missing { in menu file\n" ); // break; //} - //if ( menuCount == MAX_MENUS ) { + //if( menuCount == MAX_MENUS ) { // Com_Printf( "Too many menus!\n" ); // break; //} - if ( token.string[0] == '}' ) { + if( token.string[0] == '}' ) break; - } - if (Q_stricmp(token.string, "assetGlobalDef") == 0) { - if (Asset_Parse(handle)) { + if( Q_stricmp( token.string, "assetGlobalDef" ) == 0 ) + { + if( Asset_Parse( handle ) ) continue; - } else { + else break; - } } - if (Q_stricmp(token.string, "menudef") == 0) { + if( Q_stricmp( token.string, "menudef" ) == 0 ) + { // start a new menu - Menu_New(handle); + Menu_New( handle ); } } - trap_Parse_FreeSource(handle); + + trap_Parse_FreeSource( handle ); } -qboolean Load_Menu(int handle) { +qboolean Load_Menu( int handle ) +{ pc_token_t token; - if (!trap_Parse_ReadToken(handle, &token)) - return qfalse; - if (token.string[0] != '{') { + if( !trap_Parse_ReadToken( handle, &token ) ) return qfalse; - } - while ( 1 ) { + if( token.string[0] != '{' ) + return qfalse; - if (!trap_Parse_ReadToken(handle, &token)) + while( 1 ) + { + if( !trap_Parse_ReadToken( handle, &token ) ) return qfalse; - if ( token.string[0] == 0 ) { + if( token.string[0] == 0 ) return qfalse; - } - if ( token.string[0] == '}' ) { + if( token.string[0] == '}' ) return qtrue; - } - UI_ParseMenu(token.string); + UI_ParseMenu( token.string ); } + return qfalse; } -void UI_LoadMenus(const char *menuFile, qboolean reset) { +void UI_LoadMenus( const char *menuFile, qboolean reset ) +{ pc_token_t token; int handle; int start; @@ -1183,53 +1374,53 @@ void UI_LoadMenus(const char *menuFile, qboolean reset) { start = trap_Milliseconds(); handle = trap_Parse_LoadSource( menuFile ); - if (!handle) { + + if( !handle ) trap_Error( va( S_COLOR_RED "default menu file not found: ui/menus.txt, unable to continue!\n" ) ); - } - if (reset) { + if( reset ) Menu_Reset(); - } - while ( 1 ) { - if (!trap_Parse_ReadToken(handle, &token)) + while( 1 ) + { + if( !trap_Parse_ReadToken( handle, &token ) ) break; - if( token.string[0] == 0 || token.string[0] == '}') { + + if( token.string[0] == 0 || token.string[0] == '}' ) break; - } - if ( token.string[0] == '}' ) { + if( token.string[0] == '}' ) break; - } - if (Q_stricmp(token.string, "loadmenu") == 0) { - if (Load_Menu(handle)) { + if( Q_stricmp( token.string, "loadmenu" ) == 0 ) + { + if( Load_Menu( handle ) ) continue; - } else { + else break; - } } } - Com_Printf("UI menu load time = %d milli seconds\n", trap_Milliseconds() - start); + Com_Printf( "UI menu load time = %d milli seconds\n", trap_Milliseconds() - start ); trap_Parse_FreeSource( handle ); } -void UI_Load( void ) { +void UI_Load( void ) +{ char lastName[1024]; menuDef_t *menu = Menu_GetFocused(); - if (menu && menu->window.name) { - strcpy(lastName, menu->window.name); - } + + if( menu && menu->window.name ) + strcpy( lastName, menu->window.name ); String_Init(); - UI_LoadMenus("ui/menus.txt", qtrue); - UI_LoadMenus("ui/ingame.txt", qfalse); - UI_LoadMenus("ui/tremulous.txt", qfalse); + UI_LoadMenus( "ui/menus.txt", qtrue ); + UI_LoadMenus( "ui/ingame.txt", qfalse ); + UI_LoadMenus( "ui/tremulous.txt", qfalse ); Menus_CloseAll(); - Menus_ActivateByName(lastName); + Menus_ActivateByName( lastName ); } @@ -1244,10 +1435,12 @@ static void UI_DrawInfoPane( menuItem_t *item, rectDef_t *rect, float text_x, fl int value = 0; const char *s = ""; char *string = ""; + int class, credits; char ui_currentClass[ MAX_STRING_CHARS ]; trap_Cvar_VariableStringBuffer( "ui_currentClass", ui_currentClass, MAX_STRING_CHARS ); + sscanf( ui_currentClass, "%d %d", &class, &credits ); switch( item->type ) @@ -1258,77 +1451,92 @@ static void UI_DrawInfoPane( menuItem_t *item, rectDef_t *rect, float text_x, fl case INFOTYPE_CLASS: value = BG_ClassCanEvolveFromTo( class, item->v.pclass, credits, 0 ); + if( value < 1 ) { s = va( "%s\n\n%s", - BG_FindHumanNameForClassNum( item->v.pclass ), - BG_FindInfoForClassNum( item->v.pclass ) ); + BG_FindHumanNameForClassNum( item->v.pclass ), + BG_FindInfoForClassNum( item->v.pclass ) ); } else { s = va( "%s\n\n%s\n\nKills: %d", - BG_FindHumanNameForClassNum( item->v.pclass ), - BG_FindInfoForClassNum( item->v.pclass ), - value ); + BG_FindHumanNameForClassNum( item->v.pclass ), + BG_FindInfoForClassNum( item->v.pclass ), + value ); } + break; case INFOTYPE_WEAPON: value = BG_FindPriceForWeapon( item->v.weapon ); + if( value == 0 ) { s = va( "%s\n\n%s\n\nCredits: Free", - BG_FindHumanNameForWeapon( item->v.weapon ), - BG_FindInfoForWeapon( item->v.weapon ) ); + BG_FindHumanNameForWeapon( item->v.weapon ), + BG_FindInfoForWeapon( item->v.weapon ) ); } else { s = va( "%s\n\n%s\n\nCredits: %d", - BG_FindHumanNameForWeapon( item->v.weapon ), - BG_FindInfoForWeapon( item->v.weapon ), - value ); + BG_FindHumanNameForWeapon( item->v.weapon ), + BG_FindInfoForWeapon( item->v.weapon ), + value ); } + break; case INFOTYPE_UPGRADE: value = BG_FindPriceForUpgrade( item->v.upgrade ); + if( value == 0 ) { s = va( "%s\n\n%s\n\nCredits: Free", - BG_FindHumanNameForUpgrade( item->v.upgrade ), - BG_FindInfoForUpgrade( item->v.upgrade ) ); + BG_FindHumanNameForUpgrade( item->v.upgrade ), + BG_FindInfoForUpgrade( item->v.upgrade ) ); } else { s = va( "%s\n\n%s\n\nCredits: %d", - BG_FindHumanNameForUpgrade( item->v.upgrade ), - BG_FindInfoForUpgrade( item->v.upgrade ), - value ); + BG_FindHumanNameForUpgrade( item->v.upgrade ), + BG_FindInfoForUpgrade( item->v.upgrade ), + value ); } + break; case INFOTYPE_BUILDABLE: value = BG_FindBuildPointsForBuildable( item->v.buildable ); + switch( BG_FindTeamForBuildable( item->v.buildable ) ) { - case BIT_ALIENS: string = "Sentience"; break; - case BIT_HUMANS: string = "Power"; break; - default: break; + case BIT_ALIENS: + string = "Sentience"; + break; + + case BIT_HUMANS: + string = "Power"; + break; + + default: + break; } if( value == 0 ) { s = va( "%s\n\n%s", - BG_FindHumanNameForBuildable( item->v.buildable ), - BG_FindInfoForBuildable( item->v.buildable ) ); + BG_FindHumanNameForBuildable( item->v.buildable ), + BG_FindInfoForBuildable( item->v.buildable ) ); } else { s = va( "%s\n\n%s\n\n%s: %d", - BG_FindHumanNameForBuildable( item->v.buildable ), - BG_FindInfoForBuildable( item->v.buildable ), - string, value ); + BG_FindHumanNameForBuildable( item->v.buildable ), + BG_FindInfoForBuildable( item->v.buildable ), + string, value ); } + break; } @@ -1337,80 +1545,90 @@ static void UI_DrawInfoPane( menuItem_t *item, rectDef_t *rect, float text_x, fl } -static void UI_DrawServerMapPreview(rectDef_t *rect, float scale, vec4_t color) { - if (uiInfo.serverStatus.currentServerCinematic >= 0) { - trap_CIN_RunCinematic(uiInfo.serverStatus.currentServerCinematic); - trap_CIN_SetExtents(uiInfo.serverStatus.currentServerCinematic, rect->x, rect->y, rect->w, rect->h); - trap_CIN_DrawCinematic(uiInfo.serverStatus.currentServerCinematic); - } else if (uiInfo.serverStatus.currentServerPreview > 0) { - UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, uiInfo.serverStatus.currentServerPreview); - } else { - UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, trap_R_RegisterShaderNoMip("gfx/2d/load_screen")); +static void UI_DrawServerMapPreview( rectDef_t *rect, float scale, vec4_t color ) +{ + if( uiInfo.serverStatus.currentServerCinematic >= 0 ) + { + trap_CIN_RunCinematic( uiInfo.serverStatus.currentServerCinematic ); + trap_CIN_SetExtents( uiInfo.serverStatus.currentServerCinematic, rect->x, rect->y, rect->w, rect->h ); + trap_CIN_DrawCinematic( uiInfo.serverStatus.currentServerCinematic ); } + else if( uiInfo.serverStatus.currentServerPreview > 0 ) + UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, uiInfo.serverStatus.currentServerPreview ); + else + UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, trap_R_RegisterShaderNoMip( "gfx/2d/load_screen" ) ); } -static void UI_DrawSelectedMapPreview(rectDef_t *rect, float scale, vec4_t color) { +static void UI_DrawSelectedMapPreview( rectDef_t *rect, float scale, vec4_t color ) +{ int map = ui_selectedMap.integer; - if (map < 0 || map > uiInfo.mapCount) { + if( map < 0 || map > uiInfo.mapCount ) + { ui_selectedMap.integer = 0; - trap_Cvar_Set("ui_selectedMap", "0"); + trap_Cvar_Set( "ui_selectedMap", "0" ); map = 0; } - if (uiInfo.mapList[map].cinematic >= -1) { - if (uiInfo.mapList[map].cinematic == -1) { - uiInfo.mapList[map].cinematic = trap_CIN_PlayCinematic(va("%s.roq", uiInfo.mapList[map].mapLoadName), 0, 0, 0, 0, (CIN_loop | CIN_silent) ); + if( uiInfo.mapList[map].cinematic >= -1 ) + { + if( uiInfo.mapList[map].cinematic == -1 ) + uiInfo.mapList[map].cinematic = trap_CIN_PlayCinematic( va( "%s.roq", uiInfo.mapList[map].mapLoadName ), + 0, 0, 0, 0, ( CIN_loop | CIN_silent ) ); + + if( uiInfo.mapList[map].cinematic >= 0 ) + { + trap_CIN_RunCinematic( uiInfo.mapList[map].cinematic ); + trap_CIN_SetExtents( uiInfo.mapList[map].cinematic, rect->x, rect->y, rect->w, rect->h ); + trap_CIN_DrawCinematic( uiInfo.mapList[map].cinematic ); } - if (uiInfo.mapList[map].cinematic >= 0) { - trap_CIN_RunCinematic(uiInfo.mapList[map].cinematic); - trap_CIN_SetExtents(uiInfo.mapList[map].cinematic, rect->x, rect->y, rect->w, rect->h); - trap_CIN_DrawCinematic(uiInfo.mapList[map].cinematic); - } else { + else uiInfo.mapList[map].cinematic = -2; - } - } else { - if (uiInfo.mapList[map].levelShot == -1) { - uiInfo.mapList[map].levelShot = trap_R_RegisterShaderNoMip(uiInfo.mapList[map].imageName); - } + } + else + { + if( uiInfo.mapList[map].levelShot == -1 ) + uiInfo.mapList[map].levelShot = trap_R_RegisterShaderNoMip( uiInfo.mapList[map].imageName ); - if (uiInfo.mapList[map].levelShot > 0) { - UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, uiInfo.mapList[map].levelShot); - } else { - UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, trap_R_RegisterShaderNoMip("gfx/2d/load_screen")); - } + if( uiInfo.mapList[map].levelShot > 0 ) + UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, uiInfo.mapList[map].levelShot ); + else + UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, trap_R_RegisterShaderNoMip( "gfx/2d/load_screen" ) ); } } -static void UI_DrawSelectedMapName(rectDef_t *rect, float scale, vec4_t color, int textStyle) { +static void UI_DrawSelectedMapName( rectDef_t *rect, float scale, vec4_t color, int textStyle ) +{ int map = ui_selectedMap.integer; - if (map >= 0 && map < uiInfo.mapCount) { - UI_Text_Paint(rect->x, rect->y, scale, color, uiInfo.mapList[map].mapName, 0, 0, textStyle); - } + + if( map >= 0 && map < uiInfo.mapCount ) + UI_Text_Paint( rect->x, rect->y, scale, color, uiInfo.mapList[map].mapName, 0, 0, textStyle ); } -static const char *UI_OwnerDrawText(int ownerDraw) { - const char *s = NULL; +static const char *UI_OwnerDrawText( int ownerDraw ) +{ + const char * s = NULL; switch( ownerDraw ) { case UI_NETSOURCE: - if (ui_netSource.integer < 0 || ui_netSource.integer >= numNetSources) { + if( ui_netSource.integer < 0 || ui_netSource.integer >= numNetSources ) ui_netSource.integer = 0; - } + s = netSources[ui_netSource.integer]; break; case UI_KEYBINDSTATUS: - if (Display_KeyBindPending()) { + if( Display_KeyBindPending() ) s = "Waiting for new key... Press ESCAPE to cancel"; - } else { + else s = "Press ENTER or CLICK to change, Press BACKSPACE to clear"; - } + break; case UI_SERVERREFRESHDATE: - if (uiInfo.serverStatus.refreshActive) { + if( uiInfo.serverStatus.refreshActive ) + { #define MAX_DOTS 5 int numServers = trap_LAN_GetServerCount( ui_netSource.integer ); int numDots = ( uiInfo.uiDC.realTime / 500 ) % ( MAX_DOTS + 1 ); @@ -1423,10 +1641,11 @@ static const char *UI_OwnerDrawText(int ownerDraw) { dots[ i ] = '\0'; s = numServers < 0 ? va( "Waiting for response%s", dots ) : - va("Getting info for %d servers (ESC to cancel)%s", numServers, dots ); - } else { - s = va("Refresh Time: %s", UI_Cvar_VariableString(va("ui_lastServerRefresh_%i", ui_netSource.integer))); + va( "Getting info for %d servers (ESC to cancel)%s", numServers, dots ); } + else + s = va( "Refresh Time: %s", UI_Cvar_VariableString( va( "ui_lastServerRefresh_%i", ui_netSource.integer ) ) ); + break; case UI_SERVERMOTD: @@ -1440,8 +1659,9 @@ static const char *UI_OwnerDrawText(int ownerDraw) { return s; } -static int UI_OwnerDrawWidth(int ownerDraw, float scale) { - const char *s = NULL; +static int UI_OwnerDrawWidth( int ownerDraw, float scale ) +{ + const char * s = NULL; switch( ownerDraw ) { @@ -1456,9 +1676,9 @@ static int UI_OwnerDrawWidth(int ownerDraw, float scale) { break; } - if (s) { - return UI_Text_Width(s, scale, 0); - } + if( s ) + return UI_Text_Width( s, scale, 0 ); + return 0; } @@ -1467,7 +1687,8 @@ static int UI_OwnerDrawWidth(int ownerDraw, float scale) { UI_BuildPlayerList =============== */ -static void UI_BuildPlayerList( void ) { +static void UI_BuildPlayerList( void ) +{ uiClientState_t cs; int n, count, team, team2, playerTeamNumber; char info[MAX_INFO_STRING]; @@ -1475,39 +1696,48 @@ static void UI_BuildPlayerList( void ) { trap_GetClientState( &cs ); trap_GetConfigString( CS_PLAYERS + cs.clientNum, info, MAX_INFO_STRING ); uiInfo.playerNumber = cs.clientNum; - team = atoi(Info_ValueForKey(info, "t")); - trap_GetConfigString( CS_SERVERINFO, info, sizeof(info) ); + team = atoi( Info_ValueForKey( info, "t" ) ); + trap_GetConfigString( CS_SERVERINFO, info, sizeof( info ) ); count = atoi( Info_ValueForKey( info, "sv_maxclients" ) ); uiInfo.playerCount = 0; uiInfo.myTeamCount = 0; uiInfo.myPlayerIndex = 0; playerTeamNumber = 0; - for( n = 0; n < count; n++ ) { + + for( n = 0; n < count; n++ ) + { trap_GetConfigString( CS_PLAYERS + n, info, MAX_INFO_STRING ); - if (info[0]) { + if( info[0] ) + { BG_ClientListParse( &uiInfo.ignoreList[ uiInfo.playerCount ], - Info_ValueForKey( info, "ig" ) ); + Info_ValueForKey( info, "ig" ) ); Q_strncpyz( uiInfo.rawPlayerNames[uiInfo.playerCount], - Info_ValueForKey( info, "n" ), MAX_NAME_LENGTH ); + Info_ValueForKey( info, "n" ), MAX_NAME_LENGTH ); Q_strncpyz( uiInfo.playerNames[uiInfo.playerCount], - Info_ValueForKey( info, "n" ), MAX_NAME_LENGTH ); + Info_ValueForKey( info, "n" ), MAX_NAME_LENGTH ); Q_CleanStr( uiInfo.playerNames[uiInfo.playerCount] ); uiInfo.clientNums[uiInfo.playerCount] = n; + if( n == uiInfo.playerNumber ) uiInfo.myPlayerIndex = uiInfo.playerCount; + uiInfo.playerCount++; - team2 = atoi(Info_ValueForKey(info, "t")); - if (team2 == team) { + + team2 = atoi( Info_ValueForKey( info, "t" ) ); + + if( team2 == team ) + { Q_strncpyz( uiInfo.rawTeamNames[uiInfo.myTeamCount], - Info_ValueForKey( info, "n" ), MAX_NAME_LENGTH ); + Info_ValueForKey( info, "n" ), MAX_NAME_LENGTH ); Q_strncpyz( uiInfo.teamNames[uiInfo.myTeamCount], - Info_ValueForKey( info, "n" ), MAX_NAME_LENGTH ); + Info_ValueForKey( info, "n" ), MAX_NAME_LENGTH ); Q_CleanStr( uiInfo.teamNames[uiInfo.myTeamCount] ); uiInfo.teamClientNums[uiInfo.myTeamCount] = n; - if (uiInfo.playerNumber == n) { + + if( uiInfo.playerNumber == n ) playerTeamNumber = uiInfo.myTeamCount; - } + uiInfo.myTeamCount++; } } @@ -1515,14 +1745,15 @@ static void UI_BuildPlayerList( void ) { } static void UI_DrawGLInfo( rectDef_t *rect, float scale, int textalign, int textvalign, - vec4_t color, int textStyle, float text_x, float text_y) { + vec4_t color, int textStyle, float text_x, float text_y ) +{ char buffer[ 4096 ]; Com_sprintf( buffer, sizeof( buffer ), "VENDOR: %s\nVERSION: %s\n" - "PIXELFORMAT: color(%d-bits) Z(%d-bits) stencil(%d-bits)\n%s", - uiInfo.uiDC.glconfig.vendor_string, uiInfo.uiDC.glconfig.renderer_string, - uiInfo.uiDC.glconfig.colorBits, uiInfo.uiDC.glconfig.depthBits, - uiInfo.uiDC.glconfig.stencilBits, uiInfo.uiDC.glconfig.extensions_string ); + "PIXELFORMAT: color(%d-bits) Z(%d-bits) stencil(%d-bits)\n%s", + uiInfo.uiDC.glconfig.vendor_string, uiInfo.uiDC.glconfig.renderer_string, + uiInfo.uiDC.glconfig.colorBits, uiInfo.uiDC.glconfig.depthBits, + uiInfo.uiDC.glconfig.stencilBits, uiInfo.uiDC.glconfig.extensions_string ); UI_DrawTextBlock( rect, text_x, text_y, color, scale, textalign, textvalign, textStyle, buffer ); @@ -1547,66 +1778,68 @@ static void UI_OwnerDraw( float x, float y, float w, float h, { case UI_TEAMINFOPANE: UI_DrawInfoPane( &uiInfo.teamList[ uiInfo.teamIndex ], - &rect, text_x, text_y, scale, textalign, textvalign, color, textStyle ); + &rect, text_x, text_y, scale, textalign, textvalign, color, textStyle ); break; case UI_ACLASSINFOPANE: UI_DrawInfoPane( &uiInfo.alienClassList[ uiInfo.alienClassIndex ], - &rect, text_x, text_y, scale, textalign, textvalign, color, textStyle ); + &rect, text_x, text_y, scale, textalign, textvalign, color, textStyle ); break; case UI_AUPGRADEINFOPANE: UI_DrawInfoPane( &uiInfo.alienUpgradeList[ uiInfo.alienUpgradeIndex ], - &rect, text_x, text_y, scale, textalign, textvalign, color, textStyle ); + &rect, text_x, text_y, scale, textalign, textvalign, color, textStyle ); break; case UI_HITEMINFOPANE: UI_DrawInfoPane( &uiInfo.humanItemList[ uiInfo.humanItemIndex ], - &rect, text_x, text_y, scale, textalign, textvalign, color, textStyle ); + &rect, text_x, text_y, scale, textalign, textvalign, color, textStyle ); break; case UI_HBUYINFOPANE: UI_DrawInfoPane( &uiInfo.humanArmouryBuyList[ uiInfo.humanArmouryBuyIndex ], - &rect, text_x, text_y, scale, textalign, textvalign, color, textStyle ); + &rect, text_x, text_y, scale, textalign, textvalign, color, textStyle ); break; case UI_HSELLINFOPANE: UI_DrawInfoPane( &uiInfo.humanArmourySellList[ uiInfo.humanArmourySellIndex ], - &rect, text_x, text_y, scale, textalign, textvalign, color, textStyle ); + &rect, text_x, text_y, scale, textalign, textvalign, color, textStyle ); break; case UI_ABUILDINFOPANE: UI_DrawInfoPane( &uiInfo.alienBuildList[ uiInfo.alienBuildIndex ], - &rect, text_x, text_y, scale, textalign, textvalign, color, textStyle ); + &rect, text_x, text_y, scale, textalign, textvalign, color, textStyle ); break; case UI_HBUILDINFOPANE: UI_DrawInfoPane( &uiInfo.humanBuildList[ uiInfo.humanBuildIndex ], - &rect, text_x, text_y, scale, textalign, textvalign, color, textStyle ); + &rect, text_x, text_y, scale, textalign, textvalign, color, textStyle ); break; case UI_NETMAPPREVIEW: - UI_DrawServerMapPreview(&rect, scale, color); + UI_DrawServerMapPreview( &rect, scale, color ); break; case UI_SELECTEDMAPPREVIEW: - UI_DrawSelectedMapPreview(&rect, scale, color); + UI_DrawSelectedMapPreview( &rect, scale, color ); break; case UI_SELECTEDMAPNAME: - UI_DrawSelectedMapName(&rect, scale, color, textStyle); + UI_DrawSelectedMapName( &rect, scale, color, textStyle ); break; case UI_GLINFO: - UI_DrawGLInfo(&rect, scale, textalign, textvalign, color, textStyle, text_x, text_y); + UI_DrawGLInfo( &rect, scale, textalign, textvalign, color, textStyle, text_x, text_y ); break; + default: break; } } -static qboolean UI_OwnerDrawVisible(int flags) { +static qboolean UI_OwnerDrawVisible( int flags ) +{ qboolean vis = qtrue; uiClientState_t cs; pTeam_t team; @@ -1617,8 +1850,8 @@ static qboolean UI_OwnerDrawVisible(int flags) { team = atoi( Info_ValueForKey( info, "t" ) ); - while (flags) { - + while( flags ) + { if( flags & UI_SHOW_NOTSPECTATING ) { if( team == PTE_NONE ) @@ -1675,60 +1908,74 @@ static qboolean UI_OwnerDrawVisible(int flags) { flags &= ~UI_SHOW_CANTEAMVOTE; } - if (flags & UI_SHOW_FAVORITESERVERS) { + if( flags & UI_SHOW_FAVORITESERVERS ) + { // this assumes you only put this type of display flag on something showing in the proper context - if (ui_netSource.integer != AS_FAVORITES) { + + if( ui_netSource.integer != AS_FAVORITES ) vis = qfalse; - } + flags &= ~UI_SHOW_FAVORITESERVERS; } - if (flags & UI_SHOW_NOTFAVORITESERVERS) { + if( flags & UI_SHOW_NOTFAVORITESERVERS ) + { // this assumes you only put this type of display flag on something showing in the proper context - if (ui_netSource.integer == AS_FAVORITES) { + + if( ui_netSource.integer == AS_FAVORITES ) vis = qfalse; - } + flags &= ~UI_SHOW_NOTFAVORITESERVERS; - } else { - flags = 0; } + else + flags = 0; } + return vis; } -static qboolean UI_NetSource_HandleKey(int flags, float *special, int key) { - if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER) { - - if (key == K_MOUSE2) { +static qboolean UI_NetSource_HandleKey( int flags, float *special, int key ) +{ + if( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) + { + if( key == K_MOUSE2 ) + { ui_netSource.integer--; - if (ui_netSource.integer == AS_MPLAYER) + + if( ui_netSource.integer == AS_MPLAYER ) ui_netSource.integer--; - } else { + } + else + { ui_netSource.integer++; - if (ui_netSource.integer == AS_MPLAYER) + + if( ui_netSource.integer == AS_MPLAYER ) ui_netSource.integer++; } - if (ui_netSource.integer >= numNetSources) { + if( ui_netSource.integer >= numNetSources ) ui_netSource.integer = 0; - } else if (ui_netSource.integer < 0) { + else if( ui_netSource.integer < 0 ) ui_netSource.integer = numNetSources - 1; - } - UI_BuildServerDisplayList(qtrue); - if (ui_netSource.integer != AS_GLOBAL) { - UI_StartServerRefresh(qtrue); - } - trap_Cvar_Set( "ui_netSource", va("%d", ui_netSource.integer)); + UI_BuildServerDisplayList( qtrue ); + + if( ui_netSource.integer != AS_GLOBAL ) + UI_StartServerRefresh( qtrue ); + + trap_Cvar_Set( "ui_netSource", va( "%d", ui_netSource.integer ) ); return qtrue; } + return qfalse; } -static qboolean UI_OwnerDrawHandleKey(int ownerDraw, int flags, float *special, int key) { - switch (ownerDraw) { +static qboolean UI_OwnerDrawHandleKey( int ownerDraw, int flags, float *special, int key ) +{ + switch( ownerDraw ) + { case UI_NETSOURCE: - UI_NetSource_HandleKey(flags, special, key); + UI_NetSource_HandleKey( flags, special, key ); break; default: @@ -1744,8 +1991,10 @@ static qboolean UI_OwnerDrawHandleKey(int ownerDraw, int flags, float *special, UI_ServersQsortCompare ================= */ -static int QDECL UI_ServersQsortCompare( const void *arg1, const void *arg2 ) { - return trap_LAN_CompareServers( ui_netSource.integer, uiInfo.serverStatus.sortKey, uiInfo.serverStatus.sortDir, *(int*)arg1, *(int*)arg2); +static int QDECL UI_ServersQsortCompare( const void *arg1, const void *arg2 ) +{ + return trap_LAN_CompareServers( ui_netSource.integer, uiInfo.serverStatus.sortKey, + uiInfo.serverStatus.sortDir, *( int* )arg1, *( int* )arg2 ); } @@ -1754,16 +2003,17 @@ static int QDECL UI_ServersQsortCompare( const void *arg1, const void *arg2 ) { UI_ServersSort ================= */ -void UI_ServersSort(int column, qboolean force) { - - if ( !force ) { - if ( uiInfo.serverStatus.sortKey == column ) { +void UI_ServersSort( int column, qboolean force ) +{ + if( !force ) + { + if( uiInfo.serverStatus.sortKey == column ) return; - } } uiInfo.serverStatus.sortKey = column; - qsort( &uiInfo.serverStatus.displayServers[0], uiInfo.serverStatus.numDisplayServers, sizeof(int), UI_ServersQsortCompare); + qsort( &uiInfo.serverStatus.displayServers[0], uiInfo.serverStatus.numDisplayServers, + sizeof( int ), UI_ServersQsortCompare ); } @@ -1778,7 +2028,7 @@ static stage_t UI_GetCurrentAlienStage( void ) stage_t stage, dummy; trap_Cvar_VariableStringBuffer( "ui_stages", buffer, sizeof( buffer ) ); - sscanf( buffer, "%d %d", (int *)&stage , (int *)&dummy ); + sscanf( buffer, "%d %d", ( int * ) & stage , ( int * ) & dummy ); return stage; } @@ -1794,7 +2044,7 @@ static stage_t UI_GetCurrentHumanStage( void ) stage_t stage, dummy; trap_Cvar_VariableStringBuffer( "ui_stages", buffer, sizeof( buffer ) ); - sscanf( buffer, "%d %d", (int *)&dummy, (int *)&stage ); + sscanf( buffer, "%d %d", ( int * ) & dummy, ( int * ) & stage ); return stage; } @@ -1822,12 +2072,12 @@ static void UI_LoadTeams( void ) uiInfo.teamList[ 1 ].cmd = String_Alloc( "cmd team humans\n" ); uiInfo.teamList[ 1 ].type = INFOTYPE_TEXT; uiInfo.teamList[ 1 ].v.text = - "The Human Team\n\n" - "The humans are the masters of technology. Although their " - "bases take long to construct, their automated defense " - "ensures they stay built. A wide range of upgrades and " - "weapons are available to the humans, each contributing " - "to eradicate the alien threat."; + "The Human Team\n\n" + "The humans are the masters of technology. Although their " + "bases take long to construct, their automated defense " + "ensures they stay built. A wide range of upgrades and " + "weapons are available to the humans, each contributing " + "to eradicate the alien threat."; uiInfo.teamList[ 2 ].text = String_Alloc( "Spectate" ); uiInfo.teamList[ 2 ].cmd = String_Alloc( "cmd team spectate\n" ); @@ -1845,13 +2095,17 @@ static void UI_LoadTeams( void ) UI_AddClass =============== */ + static void UI_AddClass( pClass_t class ) { uiInfo.alienClassList[ uiInfo.alienClassCount ].text = + String_Alloc( BG_FindHumanNameForClassNum( class ) ); uiInfo.alienClassList[ uiInfo.alienClassCount ].cmd = + String_Alloc( va( "cmd class %s\n", BG_FindNameForClassNum( class ) ) ); uiInfo.alienClassList[ uiInfo.alienClassCount ].type = INFOTYPE_CLASS; + uiInfo.alienClassList[ uiInfo.alienClassCount ].v.pclass = class; uiInfo.alienClassCount++; @@ -1932,6 +2186,7 @@ static void UI_ParseCarriageList( void ) uiInfo.upgrades = 0; //simple parser to give rise to weapon/upgrade list + while( iterator && iterator[ 0 ] != '$' ) { bufPointer = buffer; @@ -1941,7 +2196,7 @@ static void UI_ParseCarriageList( void ) iterator++; while( iterator[ 0 ] != ' ' ) - *bufPointer++ = *iterator++; + * bufPointer++ = *iterator++; *bufPointer++ = '\n'; @@ -1954,7 +2209,7 @@ static void UI_ParseCarriageList( void ) iterator++; while( iterator[ 0 ] != ' ' ) - *bufPointer++ = *iterator++; + * bufPointer++ = *iterator++; *bufPointer++ = '\n'; @@ -2112,11 +2367,13 @@ UI_LoadAlienUpgrades static void UI_LoadAlienUpgrades( void ) { int i, j = 0; + int class, credits; char ui_currentClass[ MAX_STRING_CHARS ]; stage_t stage = UI_GetCurrentAlienStage( ); trap_Cvar_VariableStringBuffer( "ui_currentClass", ui_currentClass, MAX_STRING_CHARS ); + sscanf( ui_currentClass, "%d %d", &class, &credits ); uiInfo.alienUpgradeCount = 0; @@ -2217,7 +2474,8 @@ static void UI_LoadHumanBuilds( void ) UI_LoadMods =============== */ -static void UI_LoadMods( void ) { +static void UI_LoadMods( void ) +{ int numdirs; char dirlist[2048]; char *dirptr; @@ -2226,18 +2484,20 @@ static void UI_LoadMods( void ) { int dirlen; uiInfo.modCount = 0; - numdirs = trap_FS_GetFileList( "$modlist", "", dirlist, sizeof(dirlist) ); + numdirs = trap_FS_GetFileList( "$modlist", "", dirlist, sizeof( dirlist ) ); dirptr = dirlist; - for( i = 0; i < numdirs; i++ ) { + + for( i = 0; i < numdirs; i++ ) + { dirlen = strlen( dirptr ) + 1; descptr = dirptr + dirlen; - uiInfo.modList[uiInfo.modCount].modName = String_Alloc(dirptr); - uiInfo.modList[uiInfo.modCount].modDescr = String_Alloc(descptr); - dirptr += dirlen + strlen(descptr) + 1; + uiInfo.modList[uiInfo.modCount].modName = String_Alloc( dirptr ); + uiInfo.modList[uiInfo.modCount].modDescr = String_Alloc( descptr ); + dirptr += dirlen + strlen( descptr ) + 1; uiInfo.modCount++; - if (uiInfo.modCount >= MAX_MODS) { + + if( uiInfo.modCount >= MAX_MODS ) break; - } } } @@ -2248,25 +2508,30 @@ static void UI_LoadMods( void ) { UI_LoadMovies =============== */ -static void UI_LoadMovies( void ) { +static void UI_LoadMovies( void ) +{ char movielist[4096]; char *moviename; int i, len; uiInfo.movieCount = trap_FS_GetFileList( "video", "roq", movielist, 4096 ); - if (uiInfo.movieCount) { - if (uiInfo.movieCount > MAX_MOVIES) { + if( uiInfo.movieCount ) + { + if( uiInfo.movieCount > MAX_MOVIES ) uiInfo.movieCount = MAX_MOVIES; - } + moviename = movielist; - for ( i = 0; i < uiInfo.movieCount; i++ ) { + + for( i = 0; i < uiInfo.movieCount; i++ ) + { len = strlen( moviename ); - if (!Q_stricmp(moviename + len - 4,".roq")) { + + if( !Q_stricmp( moviename + len - 4, ".roq" ) ) moviename[len-4] = '\0'; - } - Q_strupr(moviename); - uiInfo.movieList[i] = String_Alloc(moviename); + + Q_strupr( moviename ); + uiInfo.movieList[i] = String_Alloc( moviename ); moviename += len + 1; } } @@ -2280,83 +2545,109 @@ static void UI_LoadMovies( void ) { UI_LoadDemos =============== */ -static void UI_LoadDemos( void ) { +static void UI_LoadDemos( void ) +{ char demolist[4096]; char demoExt[32]; char *demoname; int i, len; - Com_sprintf(demoExt, sizeof(demoExt), "dm_%d", (int)trap_Cvar_VariableValue("protocol")); + Com_sprintf( demoExt, sizeof( demoExt ), "dm_%d", ( int )trap_Cvar_VariableValue( "protocol" ) ); uiInfo.demoCount = trap_FS_GetFileList( "demos", demoExt, demolist, 4096 ); - Com_sprintf(demoExt, sizeof(demoExt), ".dm_%d", (int)trap_Cvar_VariableValue("protocol")); + Com_sprintf( demoExt, sizeof( demoExt ), ".dm_%d", ( int )trap_Cvar_VariableValue( "protocol" ) ); - if (uiInfo.demoCount) { - if (uiInfo.demoCount > MAX_DEMOS) { + if( uiInfo.demoCount ) + { + if( uiInfo.demoCount > MAX_DEMOS ) uiInfo.demoCount = MAX_DEMOS; - } + demoname = demolist; - for ( i = 0; i < uiInfo.demoCount; i++ ) { + + for( i = 0; i < uiInfo.demoCount; i++ ) + { len = strlen( demoname ); - if (!Q_stricmp(demoname + len - strlen(demoExt), demoExt)) { - demoname[len-strlen(demoExt)] = '\0'; - } - Q_strupr(demoname); - uiInfo.demoList[i] = String_Alloc(demoname); + + if( !Q_stricmp( demoname + len - strlen( demoExt ), demoExt ) ) + demoname[len-strlen( demoExt )] = '\0'; + + Q_strupr( demoname ); + uiInfo.demoList[i] = String_Alloc( demoname ); demoname += len + 1; } } } -static void UI_Update(const char *name) { - int val = trap_Cvar_VariableValue(name); +static void UI_Update( const char *name ) +{ + int val = trap_Cvar_VariableValue( name ); + + if( Q_stricmp( name, "ui_SetName" ) == 0 ) + trap_Cvar_Set( "name", UI_Cvar_VariableString( "ui_Name" ) ); + else if( Q_stricmp( name, "ui_setRate" ) == 0 ) + { + float rate = trap_Cvar_VariableValue( "rate" ); - if (Q_stricmp(name, "ui_SetName") == 0) { - trap_Cvar_Set( "name", UI_Cvar_VariableString("ui_Name")); - } else if (Q_stricmp(name, "ui_setRate") == 0) { - float rate = trap_Cvar_VariableValue("rate"); - if (rate >= 5000) { - trap_Cvar_Set("cl_maxpackets", "30"); - trap_Cvar_Set("cl_packetdup", "1"); - } else if (rate >= 4000) { - trap_Cvar_Set("cl_maxpackets", "15"); - trap_Cvar_Set("cl_packetdup", "2"); // favor less prediction errors when there's packet loss - } else { - trap_Cvar_Set("cl_maxpackets", "15"); - trap_Cvar_Set("cl_packetdup", "1"); // favor lower bandwidth + if( rate >= 5000 ) + { + trap_Cvar_Set( "cl_maxpackets", "30" ); + trap_Cvar_Set( "cl_packetdup", "1" ); + } + else if( rate >= 4000 ) + { + trap_Cvar_Set( "cl_maxpackets", "15" ); + trap_Cvar_Set( "cl_packetdup", "2" ); // favor less prediction errors when there's packet loss + } + else + { + trap_Cvar_Set( "cl_maxpackets", "15" ); + trap_Cvar_Set( "cl_packetdup", "1" ); // favor lower bandwidth } - } else if (Q_stricmp(name, "ui_GetName") == 0) { - trap_Cvar_Set( "ui_Name", UI_Cvar_VariableString("name")); - } else if (Q_stricmp(name, "r_colorbits") == 0) { - switch (val) { + } + else if( Q_stricmp( name, "ui_GetName" ) == 0 ) + trap_Cvar_Set( "ui_Name", UI_Cvar_VariableString( "name" ) ); + else if( Q_stricmp( name, "r_colorbits" ) == 0 ) + { + switch( val ) + { case 0: trap_Cvar_SetValue( "r_depthbits", 0 ); trap_Cvar_SetValue( "r_stencilbits", 0 ); - break; + break; + case 16: trap_Cvar_SetValue( "r_depthbits", 16 ); trap_Cvar_SetValue( "r_stencilbits", 0 ); - break; + break; + case 32: trap_Cvar_SetValue( "r_depthbits", 24 ); - break; + break; } - } else if (Q_stricmp(name, "r_lodbias") == 0) { - switch (val) { + } + else if( Q_stricmp( name, "r_lodbias" ) == 0 ) + { + switch( val ) + { case 0: trap_Cvar_SetValue( "r_subdivisions", 4 ); - break; + break; + case 1: trap_Cvar_SetValue( "r_subdivisions", 12 ); - break; + break; + case 2: trap_Cvar_SetValue( "r_subdivisions", 20 ); - break; + break; } - } else if (Q_stricmp(name, "ui_glCustom") == 0) { - switch (val) { + } + else if( Q_stricmp( name, "ui_glCustom" ) == 0 ) + { + switch( val ) + { case 0: // high quality trap_Cvar_SetValue( "r_subdivisions", 4 ); trap_Cvar_SetValue( "r_vertexlight", 0 ); @@ -2371,7 +2662,8 @@ static void UI_Update(const char *name) { trap_Cvar_SetValue( "cg_brassTime", 2500 ); trap_Cvar_SetValue( "cg_bounceParticles", 1 ); trap_Cvar_Set( "r_texturemode", "GL_LINEAR_MIPMAP_LINEAR" ); - break; + break; + case 1: // normal trap_Cvar_SetValue( "r_subdivisions", 12 ); trap_Cvar_SetValue( "r_vertexlight", 0 ); @@ -2386,7 +2678,8 @@ static void UI_Update(const char *name) { trap_Cvar_Set( "r_texturemode", "GL_LINEAR_MIPMAP_LINEAR" ); trap_Cvar_SetValue( "cg_shadows", 0 ); trap_Cvar_SetValue( "cg_bounceParticles", 0 ); - break; + break; + case 2: // fast trap_Cvar_SetValue( "r_subdivisions", 8 ); trap_Cvar_SetValue( "r_vertexlight", 0 ); @@ -2401,7 +2694,8 @@ static void UI_Update(const char *name) { trap_Cvar_SetValue( "cg_brassTime", 0 ); trap_Cvar_SetValue( "cg_bounceParticles", 0 ); trap_Cvar_Set( "r_texturemode", "GL_LINEAR_MIPMAP_NEAREST" ); - break; + break; + case 3: // fastest trap_Cvar_SetValue( "r_subdivisions", 20 ); trap_Cvar_SetValue( "r_vertexlight", 1 ); @@ -2416,78 +2710,95 @@ static void UI_Update(const char *name) { trap_Cvar_SetValue( "r_inGameVideo", 0 ); trap_Cvar_SetValue( "cg_bounceParticles", 0 ); trap_Cvar_Set( "r_texturemode", "GL_LINEAR_MIPMAP_NEAREST" ); - break; + break; } - } else if (Q_stricmp(name, "ui_mousePitch") == 0) { - if (val == 0) { + } + else if( Q_stricmp( name, "ui_mousePitch" ) == 0 ) + { + if( val == 0 ) trap_Cvar_SetValue( "m_pitch", 0.022f ); - } else { + else trap_Cvar_SetValue( "m_pitch", -0.022f ); - } } } //FIXME: lookup table -static void UI_RunMenuScript(char **args) { - const char *name, *name2; +static void UI_RunMenuScript( char **args ) +{ + const char * name, *name2; char buff[1024]; const char *cmd; - if (String_Parse(args, &name)) { - if (Q_stricmp(name, "StartServer") == 0) { + if( String_Parse( args, &name ) ) + { + if( Q_stricmp( name, "StartServer" ) == 0 ) + { trap_Cvar_SetValue( "dedicated", Com_Clamp( 0, 2, ui_dedicated.integer ) ); - trap_Cmd_ExecuteText( EXEC_APPEND, va( "wait ; wait ; map %s\n", uiInfo.mapList[ui_selectedMap.integer].mapLoadName ) ); - } else if (Q_stricmp(name, "resetDefaults") == 0) { - trap_Cmd_ExecuteText( EXEC_APPEND, "exec default.cfg\n"); - trap_Cmd_ExecuteText( EXEC_APPEND, "cvar_restart\n"); + trap_Cmd_ExecuteText( EXEC_APPEND, va( "wait ; wait ; map %s\n", + uiInfo.mapList[ui_selectedMap.integer].mapLoadName ) ); + } + else if( Q_stricmp( name, "resetDefaults" ) == 0 ) + { + trap_Cmd_ExecuteText( EXEC_APPEND, "exec default.cfg\n" ); + trap_Cmd_ExecuteText( EXEC_APPEND, "cvar_restart\n" ); Controls_SetDefaults(); - trap_Cvar_Set("com_introPlayed", "1" ); + trap_Cvar_Set( "com_introPlayed", "1" ); trap_Cmd_ExecuteText( EXEC_APPEND, "vid_restart\n" ); - } else if (Q_stricmp(name, "loadArenas") == 0) { + } + else if( Q_stricmp( name, "loadArenas" ) == 0 ) + { UI_LoadArenas(); - Menu_SetFeederSelection(NULL, FEEDER_MAPS, 0, "createserver"); - } else if (Q_stricmp(name, "loadServerInfo") == 0) { + Menu_SetFeederSelection( NULL, FEEDER_MAPS, 0, "createserver" ); + } + else if( Q_stricmp( name, "loadServerInfo" ) == 0 ) UI_ServerInfo(); - } else if (Q_stricmp(name, "saveControls") == 0) { - Controls_SetConfig(qtrue); - } else if (Q_stricmp(name, "loadControls") == 0) { + else if( Q_stricmp( name, "saveControls" ) == 0 ) + Controls_SetConfig( qtrue ); + else if( Q_stricmp( name, "loadControls" ) == 0 ) Controls_GetConfig(); - } else if (Q_stricmp(name, "clearError") == 0) { - trap_Cvar_Set("com_errorMessage", ""); - } else if (Q_stricmp(name, "RefreshServers") == 0) { - UI_StartServerRefresh(qtrue); - UI_BuildServerDisplayList(qtrue); - } else if (Q_stricmp(name, "InitServerList") == 0) { + else if( Q_stricmp( name, "clearError" ) == 0 ) + trap_Cvar_Set( "com_errorMessage", "" ); + else if( Q_stricmp( name, "RefreshServers" ) == 0 ) + { + UI_StartServerRefresh( qtrue ); + UI_BuildServerDisplayList( qtrue ); + } + else if( Q_stricmp( name, "InitServerList" ) == 0 ) + { int time = trap_RealTime( NULL ); int last; int sortColumn; // set up default sorting - if(!uiInfo.serverStatus.sorted && Int_Parse(args, &sortColumn)) + + if( !uiInfo.serverStatus.sorted && Int_Parse( args, &sortColumn ) ) { uiInfo.serverStatus.sortKey = sortColumn; - uiInfo.serverStatus.sortDir = 0; + uiInfo.serverStatus.sortDir = 0; } // refresh if older than 3 days or if list is empty last = atoi( UI_Cvar_VariableString( va( "ui_lastServerRefresh_%i_time", - ui_netSource.integer ) ) ); + ui_netSource.integer ) ) ); + if( trap_LAN_GetServerCount( ui_netSource.integer ) < 1 || - ( time - last ) > 3600 ) + ( time - last ) > 3600 ) { - UI_StartServerRefresh(qtrue); - UI_BuildServerDisplayList(qtrue); + UI_StartServerRefresh( qtrue ); + UI_BuildServerDisplayList( qtrue ); } - } else if (Q_stricmp(name, "RefreshFilter") == 0) { - UI_StartServerRefresh(qfalse); - UI_BuildServerDisplayList(qtrue); - } else if (Q_stricmp(name, "LoadDemos") == 0) { + } + else if( Q_stricmp( name, "RefreshFilter" ) == 0 ) + { + UI_StartServerRefresh( qfalse ); + UI_BuildServerDisplayList( qtrue ); + } + else if( Q_stricmp( name, "LoadDemos" ) == 0 ) UI_LoadDemos(); - } else if (Q_stricmp(name, "LoadMovies") == 0) { + else if( Q_stricmp( name, "LoadMovies" ) == 0 ) UI_LoadMovies(); - } else if (Q_stricmp(name, "LoadMods") == 0) { + else if( Q_stricmp( name, "LoadMods" ) == 0 ) UI_LoadMods(); - } else if( Q_stricmp( name, "LoadTeams" ) == 0 ) UI_LoadTeams( ); else if( Q_stricmp( name, "JoinTeam" ) == 0 ) @@ -2532,6 +2843,7 @@ static void UI_RunMenuScript(char **args) { UI_LoadAlienUpgrades( ); //disallow the menu if it would be empty + if( uiInfo.alienUpgradeCount <= 0 ) Menus_CloseAll( ); } @@ -2587,88 +2899,137 @@ static void UI_RunMenuScript(char **args) { else trap_Cmd_ExecuteText( EXEC_APPEND, va( "say \"%s\"\n", buffer ) ); } - else if (Q_stricmp(name, "playMovie") == 0) { - if (uiInfo.previewMovie >= 0) { - trap_CIN_StopCinematic(uiInfo.previewMovie); - } - trap_Cmd_ExecuteText( EXEC_APPEND, va("cinematic %s.roq 2\n", uiInfo.movieList[uiInfo.movieIndex])); - } else if (Q_stricmp(name, "RunMod") == 0) { - trap_Cvar_Set( "fs_game", uiInfo.modList[uiInfo.modIndex].modName); + else if( Q_stricmp( name, "playMovie" ) == 0 ) + { + if( uiInfo.previewMovie >= 0 ) + trap_CIN_StopCinematic( uiInfo.previewMovie ); + + trap_Cmd_ExecuteText( EXEC_APPEND, va( "cinematic %s.roq 2\n", uiInfo.movieList[uiInfo.movieIndex] ) ); + } + else if( Q_stricmp( name, "RunMod" ) == 0 ) + { + trap_Cvar_Set( "fs_game", uiInfo.modList[uiInfo.modIndex].modName ); trap_Cmd_ExecuteText( EXEC_APPEND, "vid_restart;" ); - } else if (Q_stricmp(name, "RunDemo") == 0) { - trap_Cmd_ExecuteText( EXEC_APPEND, va("demo %s\n", uiInfo.demoList[uiInfo.demoIndex])); - } else if (Q_stricmp(name, "Tremulous") == 0) { - trap_Cvar_Set( "fs_game", ""); + } + else if( Q_stricmp( name, "RunDemo" ) == 0 ) + trap_Cmd_ExecuteText( EXEC_APPEND, va( "demo %s\n", uiInfo.demoList[uiInfo.demoIndex] ) ); + else if( Q_stricmp( name, "Tremulous" ) == 0 ) + { + trap_Cvar_Set( "fs_game", "" ); trap_Cmd_ExecuteText( EXEC_APPEND, "vid_restart;" ); - } else if (Q_stricmp(name, "closeJoin") == 0) { - if (uiInfo.serverStatus.refreshActive) { + } + else if( Q_stricmp( name, "closeJoin" ) == 0 ) + { + if( uiInfo.serverStatus.refreshActive ) + { UI_StopServerRefresh(); uiInfo.serverStatus.nextDisplayRefresh = 0; uiInfo.nextServerStatusRefresh = 0; uiInfo.nextFindPlayerRefresh = 0; - UI_BuildServerDisplayList(qtrue); - } else { - Menus_CloseByName("joinserver"); - Menus_ActivateByName("main"); + UI_BuildServerDisplayList( qtrue ); } - } else if (Q_stricmp(name, "StopRefresh") == 0) { + else + { + Menus_CloseByName( "joinserver" ); + Menus_ActivateByName( "main" ); + } + } + else if( Q_stricmp( name, "StopRefresh" ) == 0 ) + { UI_StopServerRefresh(); uiInfo.serverStatus.nextDisplayRefresh = 0; uiInfo.nextServerStatusRefresh = 0; uiInfo.nextFindPlayerRefresh = 0; - } else if (Q_stricmp(name, "UpdateFilter") == 0) { - if (ui_netSource.integer == AS_LOCAL) { - UI_StartServerRefresh(qtrue); - } - UI_BuildServerDisplayList(qtrue); - UI_FeederSelection(FEEDER_SERVERS, 0); - } else if (Q_stricmp(name, "ServerStatus") == 0) { - trap_LAN_GetServerAddressString(ui_netSource.integer, uiInfo.serverStatus.displayServers[uiInfo.serverStatus.currentServer], uiInfo.serverStatusAddress, sizeof(uiInfo.serverStatusAddress)); - UI_BuildServerStatus(qtrue); - } else if (Q_stricmp(name, "FoundPlayerServerStatus") == 0) { - Q_strncpyz(uiInfo.serverStatusAddress, uiInfo.foundPlayerServerAddresses[uiInfo.currentFoundPlayerServer], sizeof(uiInfo.serverStatusAddress)); - UI_BuildServerStatus(qtrue); - Menu_SetFeederSelection(NULL, FEEDER_FINDPLAYER, 0, NULL); - } else if (Q_stricmp(name, "FindPlayer") == 0) { - UI_BuildFindPlayerList(qtrue); + } + else if( Q_stricmp( name, "UpdateFilter" ) == 0 ) + { + if( ui_netSource.integer == AS_LOCAL ) + UI_StartServerRefresh( qtrue ); + + UI_BuildServerDisplayList( qtrue ); + UI_FeederSelection( FEEDER_SERVERS, 0 ); + } + else if( Q_stricmp( name, "ServerStatus" ) == 0 ) + { + trap_LAN_GetServerAddressString( ui_netSource.integer, + uiInfo.serverStatus.displayServers[uiInfo.serverStatus.currentServer], + uiInfo.serverStatusAddress, sizeof( uiInfo.serverStatusAddress ) ); + UI_BuildServerStatus( qtrue ); + } + else if( Q_stricmp( name, "FoundPlayerServerStatus" ) == 0 ) + { + Q_strncpyz( uiInfo.serverStatusAddress, + uiInfo.foundPlayerServerAddresses[uiInfo.currentFoundPlayerServer], + sizeof( uiInfo.serverStatusAddress ) ); + UI_BuildServerStatus( qtrue ); + Menu_SetFeederSelection( NULL, FEEDER_FINDPLAYER, 0, NULL ); + } + else if( Q_stricmp( name, "FindPlayer" ) == 0 ) + { + UI_BuildFindPlayerList( qtrue ); // clear the displayed server status info uiInfo.serverStatusInfo.numLines = 0; - Menu_SetFeederSelection(NULL, FEEDER_FINDPLAYER, 0, NULL); - } else if (Q_stricmp(name, "JoinServer") == 0) { - if (uiInfo.serverStatus.currentServer >= 0 && uiInfo.serverStatus.currentServer < uiInfo.serverStatus.numDisplayServers) { - trap_LAN_GetServerAddressString(ui_netSource.integer, uiInfo.serverStatus.displayServers[uiInfo.serverStatus.currentServer], buff, 1024); + Menu_SetFeederSelection( NULL, FEEDER_FINDPLAYER, 0, NULL ); + } + else if( Q_stricmp( name, "JoinServer" ) == 0 ) + { + if( uiInfo.serverStatus.currentServer >= 0 && + uiInfo.serverStatus.currentServer < uiInfo.serverStatus.numDisplayServers ) + { + trap_LAN_GetServerAddressString( ui_netSource.integer, + uiInfo.serverStatus.displayServers[uiInfo.serverStatus.currentServer], + buff, 1024 ); trap_Cmd_ExecuteText( EXEC_APPEND, va( "connect %s\n", buff ) ); } - } else if (Q_stricmp(name, "FoundPlayerJoinServer") == 0) { - if (uiInfo.currentFoundPlayerServer >= 0 && uiInfo.currentFoundPlayerServer < uiInfo.numFoundPlayerServers) { - trap_Cmd_ExecuteText( EXEC_APPEND, va( "connect %s\n", uiInfo.foundPlayerServerAddresses[uiInfo.currentFoundPlayerServer] ) ); + } + else if( Q_stricmp( name, "FoundPlayerJoinServer" ) == 0 ) + { + if( uiInfo.currentFoundPlayerServer >= 0 && + uiInfo.currentFoundPlayerServer < uiInfo.numFoundPlayerServers ) + { + trap_Cmd_ExecuteText( EXEC_APPEND, va( "connect %s\n", + uiInfo.foundPlayerServerAddresses[uiInfo.currentFoundPlayerServer] ) ); } - } else if (Q_stricmp(name, "Quit") == 0) { - trap_Cmd_ExecuteText( EXEC_NOW, "quit"); - } else if (Q_stricmp(name, "Leave") == 0) { + } + else if( Q_stricmp( name, "Quit" ) == 0 ) + trap_Cmd_ExecuteText( EXEC_NOW, "quit" ); + else if( Q_stricmp( name, "Leave" ) == 0 ) + { trap_Cmd_ExecuteText( EXEC_APPEND, "disconnect\n" ); trap_Key_SetCatcher( KEYCATCH_UI ); Menus_CloseAll(); - Menus_ActivateByName("main"); - } else if (Q_stricmp(name, "ServerSort") == 0) { + Menus_ActivateByName( "main" ); + } + else if( Q_stricmp( name, "ServerSort" ) == 0 ) + { int sortColumn; - if (Int_Parse(args, &sortColumn)) { + + if( Int_Parse( args, &sortColumn ) ) + { // if same column we're already sorting on then flip the direction - if (sortColumn == uiInfo.serverStatus.sortKey) { + + if( sortColumn == uiInfo.serverStatus.sortKey ) uiInfo.serverStatus.sortDir = !uiInfo.serverStatus.sortDir; - } + // make sure we sort again - UI_ServersSort(sortColumn, qtrue); + UI_ServersSort( sortColumn, qtrue ); + uiInfo.serverStatus.sorted = qtrue; } - } else if (Q_stricmp(name, "closeingame") == 0) { + } + else if( Q_stricmp( name, "closeingame" ) == 0 ) + { trap_Key_SetCatcher( trap_Key_GetCatcher() & ~KEYCATCH_UI ); trap_Key_ClearStates(); trap_Cvar_Set( "cl_paused", "0" ); Menus_CloseAll(); - } else if (Q_stricmp(name, "voteMap") == 0) { - if (ui_selectedMap.integer >=0 && ui_selectedMap.integer < uiInfo.mapCount) { - trap_Cmd_ExecuteText( EXEC_APPEND, va("callvote map %s\n",uiInfo.mapList[ui_selectedMap.integer].mapLoadName) ); + } + else if( Q_stricmp( name, "voteMap" ) == 0 ) + { + if( ui_selectedMap.integer >= 0 && ui_selectedMap.integer < uiInfo.mapCount ) + { + trap_Cmd_ExecuteText( EXEC_APPEND, va( "callvote map %s\n", + uiInfo.mapList[ui_selectedMap.integer].mapLoadName ) ); } } else if( Q_stricmp( name, "voteKick" ) == 0 ) @@ -2676,7 +3037,7 @@ static void UI_RunMenuScript(char **args) { if( uiInfo.playerIndex >= 0 && uiInfo.playerIndex < uiInfo.playerCount ) { trap_Cmd_ExecuteText( EXEC_APPEND, va( "callvote kick %d\n", - uiInfo.clientNums[ uiInfo.playerIndex ] ) ); + uiInfo.clientNums[ uiInfo.playerIndex ] ) ); } } else if( Q_stricmp( name, "voteMute" ) == 0 ) @@ -2684,7 +3045,7 @@ static void UI_RunMenuScript(char **args) { if( uiInfo.playerIndex >= 0 && uiInfo.playerIndex < uiInfo.playerCount ) { trap_Cmd_ExecuteText( EXEC_APPEND, va( "callvote mute %d\n", - uiInfo.clientNums[ uiInfo.playerIndex ] ) ); + uiInfo.clientNums[ uiInfo.playerIndex ] ) ); } } else if( Q_stricmp( name, "voteUnMute" ) == 0 ) @@ -2692,7 +3053,7 @@ static void UI_RunMenuScript(char **args) { if( uiInfo.playerIndex >= 0 && uiInfo.playerIndex < uiInfo.playerCount ) { trap_Cmd_ExecuteText( EXEC_APPEND, va( "callvote unmute %d\n", - uiInfo.clientNums[ uiInfo.playerIndex ] ) ); + uiInfo.clientNums[ uiInfo.playerIndex ] ) ); } } else if( Q_stricmp( name, "voteTeamKick" ) == 0 ) @@ -2700,7 +3061,7 @@ static void UI_RunMenuScript(char **args) { if( uiInfo.teamPlayerIndex >= 0 && uiInfo.teamPlayerIndex < uiInfo.myTeamCount ) { trap_Cmd_ExecuteText( EXEC_APPEND, va( "callteamvote kick %d\n", - uiInfo.teamClientNums[ uiInfo.teamPlayerIndex ] ) ); + uiInfo.teamClientNums[ uiInfo.teamPlayerIndex ] ) ); } } else if( Q_stricmp( name, "voteTeamDenyBuild" ) == 0 ) @@ -2708,7 +3069,7 @@ static void UI_RunMenuScript(char **args) { if( uiInfo.teamPlayerIndex >= 0 && uiInfo.teamPlayerIndex < uiInfo.myTeamCount ) { trap_Cmd_ExecuteText( EXEC_APPEND, va( "callteamvote denybuild %d\n", - uiInfo.teamClientNums[ uiInfo.teamPlayerIndex ] ) ); + uiInfo.teamClientNums[ uiInfo.teamPlayerIndex ] ) ); } } else if( Q_stricmp( name, "voteTeamAllowBuild" ) == 0 ) @@ -2716,124 +3077,155 @@ static void UI_RunMenuScript(char **args) { if( uiInfo.teamPlayerIndex >= 0 && uiInfo.teamPlayerIndex < uiInfo.myTeamCount ) { trap_Cmd_ExecuteText( EXEC_APPEND, va( "callteamvote allowbuild %d\n", - uiInfo.teamClientNums[ uiInfo.teamPlayerIndex ] ) ); + uiInfo.teamClientNums[ uiInfo.teamPlayerIndex ] ) ); } } - else if (Q_stricmp(name, "addFavorite") == 0) { - if (ui_netSource.integer != AS_FAVORITES) { + else if( Q_stricmp( name, "addFavorite" ) == 0 ) + { + if( ui_netSource.integer != AS_FAVORITES ) + { char name[MAX_NAME_LENGTH]; char addr[MAX_NAME_LENGTH]; int res; - trap_LAN_GetServerInfo(ui_netSource.integer, uiInfo.serverStatus.displayServers[uiInfo.serverStatus.currentServer], buff, MAX_STRING_CHARS); + trap_LAN_GetServerInfo( ui_netSource.integer, + uiInfo.serverStatus.displayServers[uiInfo.serverStatus.currentServer], + buff, MAX_STRING_CHARS ); name[0] = addr[0] = '\0'; - Q_strncpyz(name, Info_ValueForKey(buff, "hostname"), MAX_NAME_LENGTH); - Q_strncpyz(addr, Info_ValueForKey(buff, "addr"), MAX_NAME_LENGTH); - if (strlen(name) > 0 && strlen(addr) > 0) { - res = trap_LAN_AddServer(AS_FAVORITES, name, addr); - if (res == 0) { + Q_strncpyz( name, Info_ValueForKey( buff, "hostname" ), MAX_NAME_LENGTH ); + Q_strncpyz( addr, Info_ValueForKey( buff, "addr" ), MAX_NAME_LENGTH ); + + if( strlen( name ) > 0 && strlen( addr ) > 0 ) + { + res = trap_LAN_AddServer( AS_FAVORITES, name, addr ); + + if( res == 0 ) + { // server already in the list - Com_Printf("Favorite already in list\n"); + Com_Printf( "Favorite already in list\n" ); } - else if (res == -1) { + else if( res == -1 ) + { // list full - Com_Printf("Favorite list full\n"); + Com_Printf( "Favorite list full\n" ); } - else { + else + { // successfully added - Com_Printf("Added favorite server %s\n", addr); + Com_Printf( "Added favorite server %s\n", addr ); } } } - } else if (Q_stricmp(name, "deleteFavorite") == 0) { - if (ui_netSource.integer == AS_FAVORITES) { + } + else if( Q_stricmp( name, "deleteFavorite" ) == 0 ) + { + if( ui_netSource.integer == AS_FAVORITES ) + { char addr[MAX_NAME_LENGTH]; - trap_LAN_GetServerInfo(ui_netSource.integer, uiInfo.serverStatus.displayServers[uiInfo.serverStatus.currentServer], buff, MAX_STRING_CHARS); + trap_LAN_GetServerInfo( ui_netSource.integer, + uiInfo.serverStatus.displayServers[uiInfo.serverStatus.currentServer], + buff, MAX_STRING_CHARS ); addr[0] = '\0'; - Q_strncpyz(addr, Info_ValueForKey(buff, "addr"), MAX_NAME_LENGTH); - if (strlen(addr) > 0) { - trap_LAN_RemoveServer(AS_FAVORITES, addr); - } + Q_strncpyz( addr, Info_ValueForKey( buff, "addr" ), MAX_NAME_LENGTH ); + + if( strlen( addr ) > 0 ) + trap_LAN_RemoveServer( AS_FAVORITES, addr ); } - } else if (Q_stricmp(name, "createFavorite") == 0) { - if (ui_netSource.integer == AS_FAVORITES) { + } + else if( Q_stricmp( name, "createFavorite" ) == 0 ) + { + if( ui_netSource.integer == AS_FAVORITES ) + { char name[MAX_NAME_LENGTH]; char addr[MAX_NAME_LENGTH]; int res; name[0] = addr[0] = '\0'; - Q_strncpyz(name, UI_Cvar_VariableString("ui_favoriteName"), MAX_NAME_LENGTH); - Q_strncpyz(addr, UI_Cvar_VariableString("ui_favoriteAddress"), MAX_NAME_LENGTH); - if (strlen(name) > 0 && strlen(addr) > 0) { - res = trap_LAN_AddServer(AS_FAVORITES, name, addr); - if (res == 0) { + Q_strncpyz( name, UI_Cvar_VariableString( "ui_favoriteName" ), MAX_NAME_LENGTH ); + Q_strncpyz( addr, UI_Cvar_VariableString( "ui_favoriteAddress" ), MAX_NAME_LENGTH ); + + if( strlen( name ) > 0 && strlen( addr ) > 0 ) + { + res = trap_LAN_AddServer( AS_FAVORITES, name, addr ); + + if( res == 0 ) + { // server already in the list - Com_Printf("Favorite already in list\n"); + Com_Printf( "Favorite already in list\n" ); } - else if (res == -1) { + else if( res == -1 ) + { // list full - Com_Printf("Favorite list full\n"); + Com_Printf( "Favorite list full\n" ); } - else { + else + { // successfully added - Com_Printf("Added favorite server %s\n", addr); + Com_Printf( "Added favorite server %s\n", addr ); } } } - } else if (Q_stricmp(name, "glCustom") == 0) { - trap_Cvar_Set("ui_glCustom", "4"); - } else if (Q_stricmp(name, "update") == 0) { - if (String_Parse(args, &name2)) - UI_Update(name2); - } else if (Q_stricmp(name, "InitIgnoreList") == 0) { + } + else if( Q_stricmp( name, "glCustom" ) == 0 ) + trap_Cvar_Set( "ui_glCustom", "4" ); + else if( Q_stricmp( name, "update" ) == 0 ) + { + if( String_Parse( args, &name2 ) ) + UI_Update( name2 ); + } + else if( Q_stricmp( name, "InitIgnoreList" ) == 0 ) UI_BuildPlayerList(); - } else if (Q_stricmp(name, "ToggleIgnore") == 0) { + else if( Q_stricmp( name, "ToggleIgnore" ) == 0 ) + { if( uiInfo.ignoreIndex >= 0 && uiInfo.ignoreIndex < uiInfo.playerCount ) { if( BG_ClientListTest( &uiInfo.ignoreList[ uiInfo.myPlayerIndex ], - uiInfo.clientNums[ uiInfo.ignoreIndex ] ) ) + uiInfo.clientNums[ uiInfo.ignoreIndex ] ) ) { BG_ClientListRemove( &uiInfo.ignoreList[ uiInfo.myPlayerIndex ], - uiInfo.clientNums[ uiInfo.ignoreIndex ] ); - trap_Cmd_ExecuteText( EXEC_NOW, va( "unignore %i\n", - uiInfo.clientNums[ uiInfo.ignoreIndex ] ) ); + uiInfo.clientNums[ uiInfo.ignoreIndex ] ); + trap_Cmd_ExecuteText( EXEC_NOW, va( "unignore %i\n", + uiInfo.clientNums[ uiInfo.ignoreIndex ] ) ); } else { BG_ClientListAdd( &uiInfo.ignoreList[ uiInfo.myPlayerIndex ], - uiInfo.clientNums[ uiInfo.ignoreIndex ] ); - trap_Cmd_ExecuteText( EXEC_NOW, va( "ignore %i\n", - uiInfo.clientNums[ uiInfo.ignoreIndex ] ) ); + uiInfo.clientNums[ uiInfo.ignoreIndex ] ); + trap_Cmd_ExecuteText( EXEC_NOW, va( "ignore %i\n", + uiInfo.clientNums[ uiInfo.ignoreIndex ] ) ); } } - } else if (Q_stricmp(name, "IgnorePlayer") == 0) { + } + else if( Q_stricmp( name, "IgnorePlayer" ) == 0 ) + { if( uiInfo.ignoreIndex >= 0 && uiInfo.ignoreIndex < uiInfo.playerCount ) { if( !BG_ClientListTest( &uiInfo.ignoreList[ uiInfo.myPlayerIndex ], - uiInfo.clientNums[ uiInfo.ignoreIndex ] ) ) + uiInfo.clientNums[ uiInfo.ignoreIndex ] ) ) { BG_ClientListAdd( &uiInfo.ignoreList[ uiInfo.myPlayerIndex ], - uiInfo.clientNums[ uiInfo.ignoreIndex ] ); - trap_Cmd_ExecuteText( EXEC_NOW, va( "ignore %i\n", - uiInfo.clientNums[ uiInfo.ignoreIndex ] ) ); + uiInfo.clientNums[ uiInfo.ignoreIndex ] ); + trap_Cmd_ExecuteText( EXEC_NOW, va( "ignore %i\n", + uiInfo.clientNums[ uiInfo.ignoreIndex ] ) ); } } - } else if (Q_stricmp(name, "UnIgnorePlayer") == 0) { + } + else if( Q_stricmp( name, "UnIgnorePlayer" ) == 0 ) + { if( uiInfo.ignoreIndex >= 0 && uiInfo.ignoreIndex < uiInfo.playerCount ) { if( BG_ClientListTest( &uiInfo.ignoreList[ uiInfo.myPlayerIndex ], - uiInfo.clientNums[ uiInfo.ignoreIndex ] ) ) + uiInfo.clientNums[ uiInfo.ignoreIndex ] ) ) { BG_ClientListRemove( &uiInfo.ignoreList[ uiInfo.myPlayerIndex ], - uiInfo.clientNums[ uiInfo.ignoreIndex ] ); - trap_Cmd_ExecuteText( EXEC_NOW, va( "unignore %i\n", - uiInfo.clientNums[ uiInfo.ignoreIndex ] ) ); + uiInfo.clientNums[ uiInfo.ignoreIndex ] ); + trap_Cmd_ExecuteText( EXEC_NOW, va( "unignore %i\n", + uiInfo.clientNums[ uiInfo.ignoreIndex ] ) ); } } } - else { - Com_Printf("unknown UI script %s\n", name); - } + else + Com_Printf( "unknown UI script %s\n", name ); } } @@ -2842,37 +3234,44 @@ static void UI_RunMenuScript(char **args) { UI_FeederCount ================== */ -static int UI_FeederCount(float feederID) { - - if (feederID == FEEDER_CINEMATICS) { +static int UI_FeederCount( float feederID ) +{ + if( feederID == FEEDER_CINEMATICS ) return uiInfo.movieCount; - } else if (feederID == FEEDER_MAPS) { + else if( feederID == FEEDER_MAPS ) return uiInfo.mapCount; - } else if (feederID == FEEDER_SERVERS) { + else if( feederID == FEEDER_SERVERS ) return uiInfo.serverStatus.numDisplayServers; - } else if (feederID == FEEDER_SERVERSTATUS) { + else if( feederID == FEEDER_SERVERSTATUS ) return uiInfo.serverStatusInfo.numLines; - } else if (feederID == FEEDER_FINDPLAYER) { + else if( feederID == FEEDER_FINDPLAYER ) return uiInfo.numFoundPlayerServers; - } else if (feederID == FEEDER_PLAYER_LIST) { - if (uiInfo.uiDC.realTime > uiInfo.playerRefresh) { + else if( feederID == FEEDER_PLAYER_LIST ) + { + if( uiInfo.uiDC.realTime > uiInfo.playerRefresh ) + { uiInfo.playerRefresh = uiInfo.uiDC.realTime + 3000; UI_BuildPlayerList(); } + return uiInfo.playerCount; - } else if (feederID == FEEDER_TEAM_LIST) { - if (uiInfo.uiDC.realTime > uiInfo.playerRefresh) { + } + else if( feederID == FEEDER_TEAM_LIST ) + { + if( uiInfo.uiDC.realTime > uiInfo.playerRefresh ) + { uiInfo.playerRefresh = uiInfo.uiDC.realTime + 3000; UI_BuildPlayerList(); } + return uiInfo.myTeamCount; - } else if (feederID == FEEDER_IGNORE_LIST) { + } + else if( feederID == FEEDER_IGNORE_LIST ) return uiInfo.playerCount; - } else if (feederID == FEEDER_MODS) { + else if( feederID == FEEDER_MODS ) return uiInfo.modCount; - } else if (feederID == FEEDER_DEMOS) { + else if( feederID == FEEDER_DEMOS ) return uiInfo.demoCount; - } else if( feederID == FEEDER_TREMTEAMS ) return uiInfo.teamCount; else if( feederID == FEEDER_TREMHUMANITEMS ) @@ -2893,134 +3292,174 @@ static int UI_FeederCount(float feederID) { return 0; } -static const char *UI_SelectedMap(int index, int *actual) { +static const char *UI_SelectedMap( int index, int *actual ) +{ int i, c; c = 0; *actual = 0; - for (i = 0; i < uiInfo.mapCount; i++) { - if (c == index) { + + for( i = 0; i < uiInfo.mapCount; i++ ) + { + if( c == index ) + { *actual = i; return uiInfo.mapList[i].mapName; - } else { - c++; } + else + c++; } + return ""; } -static const char *UI_FeederItemText(float feederID, int index, int column, qhandle_t *handle) { +static const char *UI_FeederItemText( float feederID, int index, int column, qhandle_t *handle ) +{ static char info[MAX_STRING_CHARS]; static char hostname[1024]; static char clientBuff[32]; static int lastColumn = -1; static int lastTime = 0; *handle = -1; - if (feederID == FEEDER_MAPS) { + + if( feederID == FEEDER_MAPS ) + { int actual; - return UI_SelectedMap(index, &actual); - } else if (feederID == FEEDER_SERVERS) { - if (index >= 0 && index < uiInfo.serverStatus.numDisplayServers) { + return UI_SelectedMap( index, &actual ); + } + else if( feederID == FEEDER_SERVERS ) + { + if( index >= 0 && index < uiInfo.serverStatus.numDisplayServers ) + { int ping; - if (lastColumn != column || lastTime > uiInfo.uiDC.realTime + 5000) { - trap_LAN_GetServerInfo(ui_netSource.integer, uiInfo.serverStatus.displayServers[index], info, MAX_STRING_CHARS); + + if( lastColumn != column || lastTime > uiInfo.uiDC.realTime + 5000 ) + { + trap_LAN_GetServerInfo( ui_netSource.integer, uiInfo.serverStatus.displayServers[index], + info, MAX_STRING_CHARS ); lastColumn = column; lastTime = uiInfo.uiDC.realTime; } - ping = atoi(Info_ValueForKey(info, "ping")); - if (ping == -1) { + ping = atoi( Info_ValueForKey( info, "ping" ) ); + + if( ping == -1 ) + { // if we ever see a ping that is out of date, do a server refresh // UI_UpdatePendingPings(); } - switch (column) { - case SORT_HOST : - if (ping <= 0) { - return Info_ValueForKey(info, "addr"); - } else { - if ( ui_netSource.integer == AS_LOCAL ) { - Com_sprintf( hostname, sizeof(hostname), "%s [%s]", - Info_ValueForKey(info, "hostname"), - netnames[atoi(Info_ValueForKey(info, "nettype"))] ); + + switch( column ) + { + case SORT_HOST: + if( ping <= 0 ) + return Info_ValueForKey( info, "addr" ); + else + { + if( ui_netSource.integer == AS_LOCAL ) + { + Com_sprintf( hostname, sizeof( hostname ), "%s [%s]", + Info_ValueForKey( info, "hostname" ), + netnames[atoi( Info_ValueForKey( info, "nettype" ) )] ); return hostname; } else { char *text; - Com_sprintf( hostname, sizeof(hostname), "%s", Info_ValueForKey(info, "hostname")); + Com_sprintf( hostname, sizeof( hostname ), "%s", Info_ValueForKey( info, "hostname" ) ); // Strip leading whitespace text = hostname; + while( *text != '\0' && *text == ' ' ) text++; return text; } } - case SORT_MAP : - return Info_ValueForKey(info, "mapname"); - case SORT_CLIENTS : - Com_sprintf( clientBuff, sizeof(clientBuff), "%s (%s)", Info_ValueForKey(info, "clients"), Info_ValueForKey(info, "sv_maxclients")); + + case SORT_MAP: + return Info_ValueForKey( info, "mapname" ); + + case SORT_CLIENTS: + Com_sprintf( clientBuff, sizeof( clientBuff ), "%s (%s)", + Info_ValueForKey( info, "clients" ), Info_ValueForKey( info, "sv_maxclients" ) ); return clientBuff; - case SORT_PING : - if (ping <= 0) { + + case SORT_PING: + if( ping <= 0 ) return "..."; - } else { - return Info_ValueForKey(info, "ping"); - } + else + return Info_ValueForKey( info, "ping" ); } } - } else if (feederID == FEEDER_SERVERSTATUS) { - if ( index >= 0 && index < uiInfo.serverStatusInfo.numLines ) { - if ( column >= 0 && column < 4 ) { + } + else if( feederID == FEEDER_SERVERSTATUS ) + { + if( index >= 0 && index < uiInfo.serverStatusInfo.numLines ) + { + if( column >= 0 && column < 4 ) return uiInfo.serverStatusInfo.lines[index][column]; - } } - } else if (feederID == FEEDER_FINDPLAYER) { - if ( index >= 0 && index < uiInfo.numFoundPlayerServers ) { + } + else if( feederID == FEEDER_FINDPLAYER ) + { + if( index >= 0 && index < uiInfo.numFoundPlayerServers ) + { //return uiInfo.foundPlayerServerAddresses[index]; return uiInfo.foundPlayerServerNames[index]; } - } else if (feederID == FEEDER_PLAYER_LIST) { - if (index >= 0 && index < uiInfo.playerCount) { + } + else if( feederID == FEEDER_PLAYER_LIST ) + { + if( index >= 0 && index < uiInfo.playerCount ) return uiInfo.playerNames[index]; - } - } else if (feederID == FEEDER_TEAM_LIST) { - if (index >= 0 && index < uiInfo.myTeamCount) { + } + else if( feederID == FEEDER_TEAM_LIST ) + { + if( index >= 0 && index < uiInfo.myTeamCount ) return uiInfo.teamNames[index]; - } - } else if (feederID == FEEDER_IGNORE_LIST) { - if (index >= 0 && index < uiInfo.playerCount) { + } + else if( feederID == FEEDER_IGNORE_LIST ) + { + if( index >= 0 && index < uiInfo.playerCount ) + { switch( column ) { case 1: // am I ignoring him - return ( BG_ClientListTest(&uiInfo.ignoreList[ uiInfo.myPlayerIndex ], - uiInfo.clientNums[ index ] ) ) ? "X" : ""; + return ( BG_ClientListTest( &uiInfo.ignoreList[ uiInfo.myPlayerIndex ], + uiInfo.clientNums[ index ] ) ) ? "X" : ""; + case 2: // is he ignoring me return ( BG_ClientListTest( &uiInfo.ignoreList[ index ], - uiInfo.playerNumber ) ) ? "X" : ""; + uiInfo.playerNumber ) ) ? "X" : ""; + default: return uiInfo.playerNames[index]; } } - } else if (feederID == FEEDER_MODS) { - if (index >= 0 && index < uiInfo.modCount) { - if (uiInfo.modList[index].modDescr && *uiInfo.modList[index].modDescr) { + } + else if( feederID == FEEDER_MODS ) + { + if( index >= 0 && index < uiInfo.modCount ) + { + if( uiInfo.modList[index].modDescr && *uiInfo.modList[index].modDescr ) return uiInfo.modList[index].modDescr; - } else { + else return uiInfo.modList[index].modName; - } } - } else if (feederID == FEEDER_CINEMATICS) { - if (index >= 0 && index < uiInfo.movieCount) { + } + else if( feederID == FEEDER_CINEMATICS ) + { + if( index >= 0 && index < uiInfo.movieCount ) return uiInfo.movieList[index]; - } - } else if (feederID == FEEDER_DEMOS) { - if (index >= 0 && index < uiInfo.demoCount) { + } + else if( feederID == FEEDER_DEMOS ) + { + if( index >= 0 && index < uiInfo.demoCount ) return uiInfo.demoList[index]; - } } else if( feederID == FEEDER_TREMTEAMS ) { @@ -3067,76 +3506,109 @@ static const char *UI_FeederItemText(float feederID, int index, int column, qhan } -static qhandle_t UI_FeederItemImage(float feederID, int index) { - if (feederID == FEEDER_MAPS) { +static qhandle_t UI_FeederItemImage( float feederID, int index ) +{ + if( feederID == FEEDER_MAPS ) + { int actual; - UI_SelectedMap(index, &actual); + UI_SelectedMap( index, &actual ); index = actual; - if (index >= 0 && index < uiInfo.mapCount) { - if (uiInfo.mapList[index].levelShot == -1) { - uiInfo.mapList[index].levelShot = trap_R_RegisterShaderNoMip(uiInfo.mapList[index].imageName); - } + + if( index >= 0 && index < uiInfo.mapCount ) + { + if( uiInfo.mapList[index].levelShot == -1 ) + uiInfo.mapList[index].levelShot = trap_R_RegisterShaderNoMip( uiInfo.mapList[index].imageName ); + return uiInfo.mapList[index].levelShot; } } + return 0; } -static void UI_FeederSelection(float feederID, int index) { +static void UI_FeederSelection( float feederID, int index ) +{ static char info[MAX_STRING_CHARS]; - if (feederID == FEEDER_MAPS) { + + if( feederID == FEEDER_MAPS ) + { int actual, map; map = ui_selectedMap.integer; - if (uiInfo.mapList[map].cinematic >= 0) { - trap_CIN_StopCinematic(uiInfo.mapList[map].cinematic); + + if( uiInfo.mapList[map].cinematic >= 0 ) + { + trap_CIN_StopCinematic( uiInfo.mapList[map].cinematic ); uiInfo.mapList[map].cinematic = -1; } - UI_SelectedMap(index, &actual); + + UI_SelectedMap( index, &actual ); ui_selectedMap.integer = actual; - trap_Cvar_Set("ui_selectedMap", va("%d", actual)); - uiInfo.mapList[ui_selectedMap.integer].cinematic = trap_CIN_PlayCinematic(va("%s.roq", uiInfo.mapList[ui_selectedMap.integer].mapLoadName), 0, 0, 0, 0, (CIN_loop | CIN_silent) ); - } else if (feederID == FEEDER_SERVERS) { - const char *mapName = NULL; + trap_Cvar_Set( "ui_selectedMap", va( "%d", actual ) ); + uiInfo.mapList[ui_selectedMap.integer].cinematic = + trap_CIN_PlayCinematic( va( "%s.roq", uiInfo.mapList[ui_selectedMap.integer].mapLoadName ), + 0, 0, 0, 0, ( CIN_loop | CIN_silent ) ); + } + else if( feederID == FEEDER_SERVERS ) + { + const char * mapName = NULL; uiInfo.serverStatus.currentServer = index; - trap_LAN_GetServerInfo(ui_netSource.integer, uiInfo.serverStatus.displayServers[index], info, MAX_STRING_CHARS); - uiInfo.serverStatus.currentServerPreview = trap_R_RegisterShaderNoMip(va("levelshots/%s", Info_ValueForKey(info, "mapname"))); - if (uiInfo.serverStatus.currentServerCinematic >= 0) { - trap_CIN_StopCinematic(uiInfo.serverStatus.currentServerCinematic); + trap_LAN_GetServerInfo( ui_netSource.integer, uiInfo.serverStatus.displayServers[index], + info, MAX_STRING_CHARS ); + uiInfo.serverStatus.currentServerPreview = + trap_R_RegisterShaderNoMip( va( "levelshots/%s", Info_ValueForKey( info, "mapname" ) ) ); + + if( uiInfo.serverStatus.currentServerCinematic >= 0 ) + { + trap_CIN_StopCinematic( uiInfo.serverStatus.currentServerCinematic ); uiInfo.serverStatus.currentServerCinematic = -1; } - mapName = Info_ValueForKey(info, "mapname"); - if (mapName && *mapName) { - uiInfo.serverStatus.currentServerCinematic = trap_CIN_PlayCinematic(va("%s.roq", mapName), 0, 0, 0, 0, (CIN_loop | CIN_silent) ); + + mapName = Info_ValueForKey( info, "mapname" ); + + if( mapName && *mapName ) + { + uiInfo.serverStatus.currentServerCinematic = + trap_CIN_PlayCinematic( va( "%s.roq", mapName ), 0, 0, 0, 0, ( CIN_loop | CIN_silent ) ); } - } else if (feederID == FEEDER_SERVERSTATUS) { - // - } else if (feederID == FEEDER_FINDPLAYER) { + } + else if( feederID == FEEDER_SERVERSTATUS ) + { + } + else if( feederID == FEEDER_FINDPLAYER ) + { uiInfo.currentFoundPlayerServer = index; // - if ( index < uiInfo.numFoundPlayerServers-1) { + + if( index < uiInfo.numFoundPlayerServers - 1 ) + { // build a new server status for this server - Q_strncpyz(uiInfo.serverStatusAddress, uiInfo.foundPlayerServerAddresses[uiInfo.currentFoundPlayerServer], sizeof(uiInfo.serverStatusAddress)); - Menu_SetFeederSelection(NULL, FEEDER_SERVERSTATUS, 0, NULL); - UI_BuildServerStatus(qtrue); + Q_strncpyz( uiInfo.serverStatusAddress, + uiInfo.foundPlayerServerAddresses[uiInfo.currentFoundPlayerServer], + sizeof( uiInfo.serverStatusAddress ) ); + Menu_SetFeederSelection( NULL, FEEDER_SERVERSTATUS, 0, NULL ); + UI_BuildServerStatus( qtrue ); } - } else if (feederID == FEEDER_PLAYER_LIST) { + } + else if( feederID == FEEDER_PLAYER_LIST ) uiInfo.playerIndex = index; - } else if (feederID == FEEDER_TEAM_LIST) { + else if( feederID == FEEDER_TEAM_LIST ) uiInfo.teamPlayerIndex = index; - } else if (feederID == FEEDER_IGNORE_LIST) { + else if( feederID == FEEDER_IGNORE_LIST ) uiInfo.ignoreIndex = index; - } else if (feederID == FEEDER_MODS) { + else if( feederID == FEEDER_MODS ) uiInfo.modIndex = index; - } else if (feederID == FEEDER_CINEMATICS) { + else if( feederID == FEEDER_CINEMATICS ) + { uiInfo.movieIndex = index; - if (uiInfo.previewMovie >= 0) { - trap_CIN_StopCinematic(uiInfo.previewMovie); - } + + if( uiInfo.previewMovie >= 0 ) + trap_CIN_StopCinematic( uiInfo.previewMovie ); + uiInfo.previewMovie = -1; - } else if (feederID == FEEDER_DEMOS) { - uiInfo.demoIndex = index; } + else if( feederID == FEEDER_DEMOS ) + uiInfo.demoIndex = index; else if( feederID == FEEDER_TREMTEAMS ) uiInfo.teamIndex = index; else if( feederID == FEEDER_TREMHUMANITEMS ) @@ -3155,12 +3627,16 @@ static void UI_FeederSelection(float feederID, int index) { uiInfo.humanBuildIndex = index; } -static void UI_Pause(qboolean b) { - if (b) { +static void UI_Pause( qboolean b ) +{ + if( b ) + { // pause the game and set the ui keycatcher trap_Cvar_Set( "cl_paused", "1" ); trap_Key_SetCatcher( KEYCATCH_UI ); - } else { + } + else + { // unpause the game and clear the ui keycatcher trap_Key_SetCatcher( trap_Key_GetCatcher() & ~KEYCATCH_UI ); trap_Key_ClearStates(); @@ -3168,31 +3644,39 @@ static void UI_Pause(qboolean b) { } } -static int UI_PlayCinematic(const char *name, float x, float y, float w, float h) { - return trap_CIN_PlayCinematic(name, x, y, w, h, (CIN_loop | CIN_silent)); +static int UI_PlayCinematic( const char *name, float x, float y, float w, float h ) +{ + return trap_CIN_PlayCinematic( name, x, y, w, h, ( CIN_loop | CIN_silent ) ); } -static void UI_StopCinematic(int handle) { - if (handle >= 0) { - trap_CIN_StopCinematic(handle); - } else { - handle = abs(handle); - if (handle == UI_NETMAPCINEMATIC) { - if (uiInfo.serverStatus.currentServerCinematic >= 0) { - trap_CIN_StopCinematic(uiInfo.serverStatus.currentServerCinematic); +static void UI_StopCinematic( int handle ) +{ + if( handle >= 0 ) + trap_CIN_StopCinematic( handle ); + else + { + handle = abs( handle ); + + if( handle == UI_NETMAPCINEMATIC ) + { + if( uiInfo.serverStatus.currentServerCinematic >= 0 ) + { + trap_CIN_StopCinematic( uiInfo.serverStatus.currentServerCinematic ); uiInfo.serverStatus.currentServerCinematic = -1; } } } } -static void UI_DrawCinematic(int handle, float x, float y, float w, float h) { - trap_CIN_SetExtents(handle, x, y, w, h); - trap_CIN_DrawCinematic(handle); +static void UI_DrawCinematic( int handle, float x, float y, float w, float h ) +{ + trap_CIN_SetExtents( handle, x, y, w, h ); + trap_CIN_DrawCinematic( handle ); } -static void UI_RunCinematicFrame(int handle) { - trap_CIN_RunCinematic(handle); +static void UI_RunCinematicFrame( int handle ) +{ + trap_CIN_RunCinematic( handle ); } static float UI_GetValue( int ownerDraw ) @@ -3206,7 +3690,8 @@ static float UI_GetValue( int ownerDraw ) UI_Init ================= */ -void UI_Init( qboolean inGameLoad ) { +void UI_Init( qboolean inGameLoad ) +{ int start; BG_InitClassOverrides( ); @@ -3226,7 +3711,7 @@ void UI_Init( qboolean inGameLoad ) { // wide screen uiInfo.uiDC.aspectScale = ( ( 640.0f * uiInfo.uiDC.glconfig.vidHeight ) / - ( 480.0f * uiInfo.uiDC.glconfig.vidWidth ) ); + ( 480.0f * uiInfo.uiDC.glconfig.vidWidth ) ); uiInfo.uiDC.registerShaderNoMip = &trap_R_RegisterShaderNoMip; uiInfo.uiDC.setColor = &UI_SetColor; @@ -3275,7 +3760,7 @@ void UI_Init( qboolean inGameLoad ) { uiInfo.uiDC.drawCinematic = &UI_DrawCinematic; uiInfo.uiDC.runCinematicFrame = &UI_RunCinematicFrame; - Init_Display(&uiInfo.uiDC); + Init_Display( &uiInfo.uiDC ); String_Init(); @@ -3285,21 +3770,21 @@ void UI_Init( qboolean inGameLoad ) { start = trap_Milliseconds(); - UI_LoadMenus("ui/menus.txt", qtrue); - UI_LoadMenus("ui/ingame.txt", qfalse); - UI_LoadMenus("ui/tremulous.txt", qfalse); + UI_LoadMenus( "ui/menus.txt", qtrue ); + UI_LoadMenus( "ui/ingame.txt", qfalse ); + UI_LoadMenus( "ui/tremulous.txt", qfalse ); Menus_CloseAll(); trap_LAN_LoadCachedServers(); // sets defaults for ui temp cvars - trap_Cvar_Set("ui_mousePitch", (trap_Cvar_VariableValue("m_pitch") >= 0) ? "0" : "1"); + trap_Cvar_Set( "ui_mousePitch", ( trap_Cvar_VariableValue( "m_pitch" ) >= 0 ) ? "0" : "1" ); uiInfo.serverStatus.currentServerCinematic = -1; uiInfo.previewMovie = -1; - trap_Cvar_Register(NULL, "debug_protocol", "", 0 ); + trap_Cvar_Register( NULL, "debug_protocol", "", 0 ); } @@ -3308,17 +3793,21 @@ void UI_Init( qboolean inGameLoad ) { UI_KeyEvent ================= */ -void UI_KeyEvent( int key, qboolean down ) { +void UI_KeyEvent( int key, qboolean down ) +{ + if( Menu_Count() > 0 ) + { + menuDef_t * menu = Menu_GetFocused(); - if (Menu_Count() > 0) { - menuDef_t *menu = Menu_GetFocused(); - if (menu) { - if (key == K_ESCAPE && down && !Menus_AnyFullScreenVisible()) { + if( menu ) + { + if( key == K_ESCAPE && down && !Menus_AnyFullScreenVisible() ) Menus_CloseAll(); - } else { - Menu_HandleKey(menu, key, down ); - } - } else { + else + Menu_HandleKey( menu, key, down ); + } + else + { trap_Key_SetCatcher( trap_Key_GetCatcher() & ~KEYCATCH_UI ); trap_Key_ClearStates(); trap_Cvar_Set( "cl_paused", "0" ); @@ -3335,66 +3824,75 @@ void UI_MouseEvent( int dx, int dy ) { // update mouse screen position uiInfo.uiDC.cursorx += ( dx * uiInfo.uiDC.aspectScale ); - if (uiInfo.uiDC.cursorx < 0) + + if( uiInfo.uiDC.cursorx < 0 ) uiInfo.uiDC.cursorx = 0; - else if (uiInfo.uiDC.cursorx > SCREEN_WIDTH) + else if( uiInfo.uiDC.cursorx > SCREEN_WIDTH ) uiInfo.uiDC.cursorx = SCREEN_WIDTH; uiInfo.uiDC.cursory += dy; - if (uiInfo.uiDC.cursory < 0) + + if( uiInfo.uiDC.cursory < 0 ) uiInfo.uiDC.cursory = 0; - else if (uiInfo.uiDC.cursory > SCREEN_HEIGHT) + else if( uiInfo.uiDC.cursory > SCREEN_HEIGHT ) uiInfo.uiDC.cursory = SCREEN_HEIGHT; - if (Menu_Count() > 0) { - //menuDef_t *menu = Menu_GetFocused(); - //Menu_HandleMouseMove(menu, uiInfo.uiDC.cursorx, uiInfo.uiDC.cursory); - Display_MouseMove(NULL, uiInfo.uiDC.cursorx, uiInfo.uiDC.cursory); - } - + if( Menu_Count() > 0 ) + Display_MouseMove( NULL, uiInfo.uiDC.cursorx, uiInfo.uiDC.cursory ); } -void UI_SetActiveMenu( uiMenuCommand_t menu ) { +void UI_SetActiveMenu( uiMenuCommand_t menu ) +{ char buf[256]; // this should be the ONLY way the menu system is brought up // enusure minumum menu data is cached - if (Menu_Count() > 0) { + + if( Menu_Count() > 0 ) + { vec3_t v; v[0] = v[1] = v[2] = 0; - switch ( menu ) { - case UIMENU_NONE: - trap_Key_SetCatcher( trap_Key_GetCatcher() & ~KEYCATCH_UI ); - trap_Key_ClearStates(); - trap_Cvar_Set( "cl_paused", "0" ); - Menus_CloseAll(); - return; - case UIMENU_MAIN: - trap_Cvar_Set( "sv_killserver", "1" ); - trap_Key_SetCatcher( KEYCATCH_UI ); - Menus_CloseAll(); - Menus_ActivateByName("main"); - trap_Cvar_VariableStringBuffer("com_errorMessage", buf, sizeof(buf)); - if (strlen(buf)) { - if( trap_Cvar_VariableValue( "com_errorCode" ) == ERR_SERVERDISCONNECT ) - Menus_ActivateByName("drop_popmenu"); - else - Menus_ActivateByName("error_popmenu"); - } - return; - case UIMENU_INGAME: - trap_Cvar_Set( "cl_paused", "1" ); - trap_Key_SetCatcher( KEYCATCH_UI ); - UI_BuildPlayerList(); - Menus_CloseAll(); - Menus_ActivateByName("ingame"); - return; + switch( menu ) + { + case UIMENU_NONE: + trap_Key_SetCatcher( trap_Key_GetCatcher() & ~KEYCATCH_UI ); + trap_Key_ClearStates(); + trap_Cvar_Set( "cl_paused", "0" ); + Menus_CloseAll(); + + return; + + case UIMENU_MAIN: + trap_Cvar_Set( "sv_killserver", "1" ); + trap_Key_SetCatcher( KEYCATCH_UI ); + Menus_CloseAll(); + Menus_ActivateByName( "main" ); + trap_Cvar_VariableStringBuffer( "com_errorMessage", buf, sizeof( buf ) ); + + if( strlen( buf ) ) + { + if( trap_Cvar_VariableValue( "com_errorCode" ) == ERR_SERVERDISCONNECT ) + Menus_ActivateByName( "drop_popmenu" ); + else + Menus_ActivateByName( "error_popmenu" ); + } + + return; + + case UIMENU_INGAME: + trap_Cvar_Set( "cl_paused", "1" ); + trap_Key_SetCatcher( KEYCATCH_UI ); + UI_BuildPlayerList(); + Menus_CloseAll(); + Menus_ActivateByName( "ingame" ); + return; } } } -qboolean UI_IsFullscreen( void ) { +qboolean UI_IsFullscreen( void ) +{ return Menus_AnyFullScreenVisible(); } @@ -3405,80 +3903,108 @@ static char lastLoadingText[MAX_INFO_VALUE]; static void UI_ReadableSize ( char *buf, int bufsize, int value ) { - if (value > 1024*1024*1024 ) { // gigs - Com_sprintf( buf, bufsize, "%d", value / (1024*1024*1024) ); - Com_sprintf( buf+strlen(buf), bufsize-strlen(buf), ".%02d GB", - (value % (1024*1024*1024))*100 / (1024*1024*1024) ); - } else if (value > 1024*1024 ) { // megs - Com_sprintf( buf, bufsize, "%d", value / (1024*1024) ); - Com_sprintf( buf+strlen(buf), bufsize-strlen(buf), ".%02d MB", - (value % (1024*1024))*100 / (1024*1024) ); - } else if (value > 1024 ) { // kilos + if( value > 1024 * 1024 * 1024 ) + { // gigs + Com_sprintf( buf, bufsize, "%d", value / ( 1024 * 1024 * 1024 ) ); + Com_sprintf( buf + strlen( buf ), bufsize - strlen( buf ), ".%02d GB", + ( value % ( 1024 * 1024 * 1024 ) ) * 100 / ( 1024 * 1024 * 1024 ) ); + } + else if( value > 1024 * 1024 ) + { // megs + Com_sprintf( buf, bufsize, "%d", value / ( 1024 * 1024 ) ); + Com_sprintf( buf + strlen( buf ), bufsize - strlen( buf ), ".%02d MB", + ( value % ( 1024 * 1024 ) ) * 100 / ( 1024 * 1024 ) ); + } + else if( value > 1024 ) + { // kilos Com_sprintf( buf, bufsize, "%d KB", value / 1024 ); - } else { // bytes + } + else + { // bytes Com_sprintf( buf, bufsize, "%d bytes", value ); } } // Assumes time is in msec -static void UI_PrintTime ( char *buf, int bufsize, int time ) { +static void UI_PrintTime ( char *buf, int bufsize, int time ) +{ time /= 1000; // change to seconds - if (time > 3600) { // in the hours range - Com_sprintf( buf, bufsize, "%d hr %d min", time / 3600, (time % 3600) / 60 ); - } else if (time > 60) { // mins + if( time > 3600 ) + { // in the hours range + Com_sprintf( buf, bufsize, "%d hr %d min", time / 3600, ( time % 3600 ) / 60 ); + } + else if( time > 60 ) + { // mins Com_sprintf( buf, bufsize, "%d min %d sec", time / 60, time % 60 ); - } else { // secs + } + else + { // secs Com_sprintf( buf, bufsize, "%d sec", time ); } } // FIXME: move to ui_shared.c? -void Text_PaintCenter(float x, float y, float scale, vec4_t color, const char *text, float adjust) { - int len = UI_Text_Width(text, scale, 0); - UI_Text_Paint(x - len / 2, y, scale, color, text, 0, 0, ITEM_TEXTSTYLE_SHADOWEDMORE); +void Text_PaintCenter( float x, float y, float scale, vec4_t color, const char *text, float adjust ) +{ + int len = UI_Text_Width( text, scale, 0 ); + UI_Text_Paint( x - len / 2, y, scale, color, text, 0, 0, ITEM_TEXTSTYLE_SHADOWEDMORE ); } -void Text_PaintCenter_AutoWrapped(float x, float y, float xmax, float ystep, float scale, vec4_t color, const char *str, float adjust) { +void Text_PaintCenter_AutoWrapped( float x, float y, float xmax, float ystep, float scale, vec4_t color, const char *str, float adjust ) +{ int width; - char *s1,*s2,*s3; + char *s1, *s2, *s3; char c_bcp; char buf[1024]; - if (!str || str[0]=='\0') + if( !str || str[0] == '\0' ) return; - Q_strncpyz(buf, str, sizeof(buf)); + Q_strncpyz( buf, str, sizeof( buf ) ); + s1 = s2 = s3 = buf; - while (1) { - do { + while( 1 ) + { + do s3++; - } while (*s3!=' ' && *s3!='\0'); + while( *s3 != ' ' && *s3 != '\0' ); + c_bcp = *s3; + *s3 = '\0'; - width = UI_Text_Width(s1, scale, 0); + + width = UI_Text_Width( s1, scale, 0 ); + *s3 = c_bcp; - if (width > xmax) { - if (s1==s2) + + if( width > xmax ) + { + if( s1 == s2 ) { // fuck, don't have a clean cut, we'll overflow s2 = s3; } + *s2 = '\0'; - Text_PaintCenter(x, y, scale, color, s1, adjust); + Text_PaintCenter( x, y, scale, color, s1, adjust ); y += ystep; - if (c_bcp == '\0') + + if( c_bcp == '\0' ) { // that was the last word // we could start a new loop, but that wouldn't be much use // even if the word is too long, we would overflow it (see above) // so just print it now if needed s2++; - if (*s2 != '\0') // if we are printing an overflowing line we have s2 == s3 - Text_PaintCenter(x, y, scale, color, s2, adjust); + + if( *s2 != '\0' ) // if we are printing an overflowing line we have s2 == s3 + Text_PaintCenter( x, y, scale, color, s2, adjust ); + break; } + s2++; s1 = s2; s3 = s2; @@ -3486,9 +4012,10 @@ void Text_PaintCenter_AutoWrapped(float x, float y, float xmax, float ystep, flo else { s2 = s3; - if (c_bcp == '\0') // we reached the end + + if( c_bcp == '\0' ) // we reached the end { - Text_PaintCenter(x, y, scale, color, s1, adjust); + Text_PaintCenter( x, y, scale, color, s1, adjust ); break; } } @@ -3496,7 +4023,8 @@ void Text_PaintCenter_AutoWrapped(float x, float y, float xmax, float ystep, flo } -static void UI_DisplayDownloadInfo( const char *downloadName, float centerPoint, float yStart, float scale ) { +static void UI_DisplayDownloadInfo( const char *downloadName, float centerPoint, float yStart, float scale ) +{ static char dlText[] = "Downloading:"; static char etaText[] = "Estimated time left:"; static char xferText[] = "Transfer rate:"; @@ -3513,55 +4041,60 @@ static void UI_DisplayDownloadInfo( const char *downloadName, float centerPoint, leftWidth = 320; - UI_SetColor(colorWhite); - Text_PaintCenter(centerPoint, yStart + 112, scale, colorWhite, dlText, 0); - Text_PaintCenter(centerPoint, yStart + 192, scale, colorWhite, etaText, 0); - Text_PaintCenter(centerPoint, yStart + 248, scale, colorWhite, xferText, 0); + UI_SetColor( colorWhite ); + Text_PaintCenter( centerPoint, yStart + 112, scale, colorWhite, dlText, 0 ); + Text_PaintCenter( centerPoint, yStart + 192, scale, colorWhite, etaText, 0 ); + Text_PaintCenter( centerPoint, yStart + 248, scale, colorWhite, xferText, 0 ); - if (downloadSize > 0) { - s = va( "%s (%d%%)", downloadName, (int)( (float)downloadCount * 100.0f / downloadSize ) ); - } else { + if( downloadSize > 0 ) + s = va( "%s (%d%%)", downloadName, ( int )( ( float )downloadCount * 100.0f / downloadSize ) ); + else s = downloadName; - } - Text_PaintCenter(centerPoint, yStart+136, scale, colorWhite, s, 0); + Text_PaintCenter( centerPoint, yStart + 136, scale, colorWhite, s, 0 ); UI_ReadableSize( dlSizeBuf, sizeof dlSizeBuf, downloadCount ); UI_ReadableSize( totalSizeBuf, sizeof totalSizeBuf, downloadSize ); - if (downloadCount < 4096 || !downloadTime) { - Text_PaintCenter(leftWidth, yStart+216, scale, colorWhite, "estimating", 0); - Text_PaintCenter(leftWidth, yStart+160, scale, colorWhite, va("(%s of %s copied)", dlSizeBuf, totalSizeBuf), 0); - } else { - if ((uiInfo.uiDC.realTime - downloadTime) / 1000) { - xferRate = downloadCount / ((uiInfo.uiDC.realTime - downloadTime) / 1000); - } else { + if( downloadCount < 4096 || !downloadTime ) + { + Text_PaintCenter( leftWidth, yStart + 216, scale, colorWhite, "estimating", 0 ); + Text_PaintCenter( leftWidth, yStart + 160, scale, colorWhite, va( "(%s of %s copied)", dlSizeBuf, totalSizeBuf ), 0 ); + } + else + { + if( ( uiInfo.uiDC.realTime - downloadTime ) / 1000 ) + xferRate = downloadCount / ( ( uiInfo.uiDC.realTime - downloadTime ) / 1000 ); + else xferRate = 0; - } + UI_ReadableSize( xferRateBuf, sizeof xferRateBuf, xferRate ); // Extrapolate estimated completion time - if (downloadSize && xferRate) { + + if( downloadSize && xferRate ) + { int n = downloadSize / xferRate; // estimated time for entire d/l in secs // We do it in K (/1024) because we'd overflow around 4MB UI_PrintTime ( dlTimeBuf, sizeof dlTimeBuf, - (n - (((downloadCount/1024) * n) / (downloadSize/1024))) * 1000); - - Text_PaintCenter(leftWidth, yStart+216, scale, colorWhite, dlTimeBuf, 0); - Text_PaintCenter(leftWidth, yStart+160, scale, colorWhite, va("(%s of %s copied)", dlSizeBuf, totalSizeBuf), 0); - } else { - Text_PaintCenter(leftWidth, yStart+216, scale, colorWhite, "estimating", 0); - if (downloadSize) { - Text_PaintCenter(leftWidth, yStart+160, scale, colorWhite, va("(%s of %s copied)", dlSizeBuf, totalSizeBuf), 0); - } else { - Text_PaintCenter(leftWidth, yStart+160, scale, colorWhite, va("(%s copied)", dlSizeBuf), 0); - } + ( n - ( ( ( downloadCount / 1024 ) * n ) / ( downloadSize / 1024 ) ) ) * 1000 ); + + Text_PaintCenter( leftWidth, yStart + 216, scale, colorWhite, dlTimeBuf, 0 ); + Text_PaintCenter( leftWidth, yStart + 160, scale, colorWhite, va( "(%s of %s copied)", dlSizeBuf, totalSizeBuf ), 0 ); } + else + { + Text_PaintCenter( leftWidth, yStart + 216, scale, colorWhite, "estimating", 0 ); - if (xferRate) { - Text_PaintCenter(leftWidth, yStart+272, scale, colorWhite, va("%s/Sec", xferRateBuf), 0); + if( downloadSize ) + Text_PaintCenter( leftWidth, yStart + 160, scale, colorWhite, va( "(%s of %s copied)", dlSizeBuf, totalSizeBuf ), 0 ); + else + Text_PaintCenter( leftWidth, yStart + 160, scale, colorWhite, va( "(%s copied)", dlSizeBuf ), 0 ); } + + if( xferRate ) + Text_PaintCenter( leftWidth, yStart + 272, scale, colorWhite, va( "%s/Sec", xferRateBuf ), 0 ); } } @@ -3570,25 +4103,28 @@ static void UI_DisplayDownloadInfo( const char *downloadName, float centerPoint, UI_DrawConnectScreen ======================== */ -void UI_DrawConnectScreen( qboolean overlay ) { - char *s; +void UI_DrawConnectScreen( qboolean overlay ) +{ + char * s; uiClientState_t cstate; char info[MAX_INFO_VALUE]; char text[256]; float centerPoint, yStart, scale; - menuDef_t *menu = Menus_FindByName("Connect"); + menuDef_t *menu = Menus_FindByName( "Connect" ); - if ( !overlay && menu ) { - Menu_Paint(menu, qtrue); - } + if( !overlay && menu ) + Menu_Paint( menu, qtrue ); - if (!overlay) { + if( !overlay ) + { centerPoint = 320; yStart = 130; scale = 0.5f; - } else { + } + else + { centerPoint = 320; yStart = 32; scale = 0.6f; @@ -3599,61 +4135,71 @@ void UI_DrawConnectScreen( qboolean overlay ) { trap_GetClientState( &cstate ); info[0] = '\0'; - if( trap_GetConfigString( CS_SERVERINFO, info, sizeof(info) ) ) { - Text_PaintCenter(centerPoint, yStart, scale, colorWhite, va( "Loading %s", Info_ValueForKey( info, "mapname" )), 0); - } - if (!Q_stricmp(cstate.servername,"localhost")) { - Text_PaintCenter(centerPoint, yStart + 48, scale, colorWhite, va("Starting up..."), ITEM_TEXTSTYLE_SHADOWEDMORE); - } else { - strcpy(text, va("Connecting to %s", cstate.servername)); - Text_PaintCenter(centerPoint, yStart + 48, scale, colorWhite,text , ITEM_TEXTSTYLE_SHADOWEDMORE); + if( trap_GetConfigString( CS_SERVERINFO, info, sizeof( info ) ) ) + Text_PaintCenter( centerPoint, yStart, scale, colorWhite, va( "Loading %s", Info_ValueForKey( info, "mapname" ) ), 0 ); + + if( !Q_stricmp( cstate.servername, "localhost" ) ) + Text_PaintCenter( centerPoint, yStart + 48, scale, colorWhite, va( "Starting up..." ), ITEM_TEXTSTYLE_SHADOWEDMORE ); + else + { + strcpy( text, va( "Connecting to %s", cstate.servername ) ); + Text_PaintCenter( centerPoint, yStart + 48, scale, colorWhite, text , ITEM_TEXTSTYLE_SHADOWEDMORE ); } // display global MOTD at bottom - Text_PaintCenter(centerPoint, 600, scale, colorWhite, Info_ValueForKey( cstate.updateInfoString, "motd" ), 0); + Text_PaintCenter( centerPoint, 600, scale, colorWhite, Info_ValueForKey( cstate.updateInfoString, "motd" ), 0 ); + // print any server info (server full, bad version, etc) - if ( cstate.connState < CA_CONNECTED ) { - Text_PaintCenter_AutoWrapped(centerPoint, yStart + 176, 630, 20, scale, colorWhite, cstate.messageString, 0); - } + if( cstate.connState < CA_CONNECTED ) + Text_PaintCenter_AutoWrapped( centerPoint, yStart + 176, 630, 20, scale, colorWhite, cstate.messageString, 0 ); - if ( lastConnState > cstate.connState ) { + if( lastConnState > cstate.connState ) lastLoadingText[0] = '\0'; - } + lastConnState = cstate.connState; - switch ( cstate.connState ) { - case CA_CONNECTING: - s = va("Awaiting connection...%i", cstate.connectPacketCount); - break; - case CA_CHALLENGING: - s = va("Awaiting challenge...%i", cstate.connectPacketCount); - break; - case CA_CONNECTED: { - char downloadName[MAX_INFO_VALUE]; - - trap_Cvar_VariableStringBuffer( "cl_downloadName", downloadName, sizeof(downloadName) ); - if (*downloadName) { - UI_DisplayDownloadInfo( downloadName, centerPoint, yStart, scale ); - return; + switch( cstate.connState ) + { + case CA_CONNECTING: + s = va( "Awaiting connection...%i", cstate.connectPacketCount ); + break; + + case CA_CHALLENGING: + s = va( "Awaiting challenge...%i", cstate.connectPacketCount ); + break; + + case CA_CONNECTED: + { + char downloadName[MAX_INFO_VALUE]; + + trap_Cvar_VariableStringBuffer( "cl_downloadName", downloadName, sizeof( downloadName ) ); + + if( *downloadName ) + { + UI_DisplayDownloadInfo( downloadName, centerPoint, yStart, scale ); + return; + } } - } - s = "Awaiting gamestate..."; - break; - case CA_LOADING: - return; - case CA_PRIMED: - return; - default: - return; - } + s = "Awaiting gamestate..."; + break; + + case CA_LOADING: + return; - if (Q_stricmp(cstate.servername,"localhost")) { - Text_PaintCenter(centerPoint, yStart + 80, scale, colorWhite, s, 0); + case CA_PRIMED: + return; + + default: + return; } + + if( Q_stricmp( cstate.servername, "localhost" ) ) + Text_PaintCenter( centerPoint, yStart + 80, scale, colorWhite, s, 0 ); + // password required / connection rejected information goes here } @@ -3662,13 +4208,13 @@ void UI_DrawConnectScreen( qboolean overlay ) { UI_RegisterCvars ================= */ -void UI_RegisterCvars( void ) { +void UI_RegisterCvars( void ) +{ int i; cvarTable_t *cv; - for ( i = 0, cv = cvarTable ; i < cvarTableSize ; i++, cv++ ) { + for( i = 0, cv = cvarTable ; i < cvarTableSize ; i++, cv++ ) trap_Cvar_Register( cv->vmCvar, cv->cvarName, cv->defaultString, cv->cvarFlags ); - } } /* @@ -3676,11 +4222,11 @@ void UI_RegisterCvars( void ) { UI_UpdateCvars ================= */ -void UI_UpdateCvars( void ) { +void UI_UpdateCvars( void ) +{ int i; cvarTable_t *cv; - for ( i = 0, cv = cvarTable ; i < cvarTableSize ; i++, cv++ ) { + for( i = 0, cv = cvarTable ; i < cvarTableSize ; i++, cv++ ) trap_Cvar_Update( cv->vmCvar ); - } } diff --git a/src/ui/ui_public.h b/src/ui/ui_public.h index 5936319f..3de3bc7f 100644 --- a/src/ui/ui_public.h +++ b/src/ui/ui_public.h @@ -2,19 +2,19 @@ =========================================================================== Copyright (C) 1999-2005 Id Software, Inc. Copyright (C) 2000-2006 Tim Angus - + This file is part of Tremulous. - + Tremulous is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + Tremulous is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with Tremulous; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA @@ -26,16 +26,19 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define UI_API_VERSION 6 -typedef struct { +typedef struct +{ connstate_t connState; int connectPacketCount; int clientNum; char servername[MAX_STRING_CHARS]; char updateInfoString[MAX_STRING_CHARS]; char messageString[MAX_STRING_CHARS]; -} uiClientState_t; +} +uiClientState_t; -typedef enum { +typedef enum +{ UI_ERROR, UI_PRINT, UI_MILLISECONDS, @@ -133,13 +136,16 @@ typedef enum { UI_SQRT, UI_FLOOR, UI_CEIL -} uiImport_t; +} +uiImport_t; -typedef enum { +typedef enum +{ UIMENU_NONE, UIMENU_MAIN, UIMENU_INGAME -} uiMenuCommand_t; +} +uiMenuCommand_t; typedef enum { @@ -147,41 +153,44 @@ typedef enum SORT_MAP, SORT_CLIENTS, SORT_PING -} serverSortField_t; +} +serverSortField_t; -typedef enum { +typedef enum +{ UI_GETAPIVERSION = 0, // system reserved UI_INIT, -// void UI_Init( void ); + // void UI_Init( void ); UI_SHUTDOWN, -// void UI_Shutdown( void ); + // void UI_Shutdown( void ); UI_KEY_EVENT, -// void UI_KeyEvent( int key ); + // void UI_KeyEvent( int key ); UI_MOUSE_EVENT, -// void UI_MouseEvent( int dx, int dy ); + // void UI_MouseEvent( int dx, int dy ); UI_REFRESH, -// void UI_Refresh( int time ); + // void UI_Refresh( int time ); UI_IS_FULLSCREEN, -// qboolean UI_IsFullscreen( void ); + // qboolean UI_IsFullscreen( void ); UI_SET_ACTIVE_MENU, -// void UI_SetActiveMenu( uiMenuCommand_t menu ); + // void UI_SetActiveMenu( uiMenuCommand_t menu ); UI_CONSOLE_COMMAND, -// qboolean UI_ConsoleCommand( int realTime ); + // qboolean UI_ConsoleCommand( int realTime ); UI_DRAW_CONNECT_SCREEN -// void UI_DrawConnectScreen( qboolean overlay ); + // void UI_DrawConnectScreen( qboolean overlay ); -// if !overlay, the background will be drawn, otherwise it will be -// overlayed over whatever the cgame has drawn. -// a GetClientState syscall will be made to get the current strings -} uiExport_t; + // if !overlay, the background will be drawn, otherwise it will be + // overlayed over whatever the cgame has drawn. + // a GetClientState syscall will be made to get the current strings +} +uiExport_t; #endif diff --git a/src/ui/ui_shared.c b/src/ui/ui_shared.c index d587651f..108113ed 100644 --- a/src/ui/ui_shared.c +++ b/src/ui/ui_shared.c @@ -2,19 +2,19 @@ =========================================================================== Copyright (C) 1999-2005 Id Software, Inc. Copyright (C) 2000-2006 Tim Angus - + This file is part of Tremulous. - + Tremulous is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + Tremulous is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with Tremulous; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA @@ -28,7 +28,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define SCROLL_TIME_ADJUSTOFFSET 40 #define SCROLL_TIME_FLOOR 20 -typedef struct scrollInfo_s { +typedef struct scrollInfo_s +{ int nextScrollTime; int nextAdjustTime; int adjustValue; @@ -37,13 +38,21 @@ typedef struct scrollInfo_s { float yStart; itemDef_t *item; qboolean scrollDir; -} scrollInfo_t; +} +scrollInfo_t; static scrollInfo_t scrollInfo; // prevent compiler warnings -void voidFunction( void *var ) { return; } -qboolean voidFunction2( itemDef_t *var1, int var2 ) { return qfalse; } +void voidFunction( void *var ) +{ + return; +} + +qboolean voidFunction2( itemDef_t *var1, int var2 ) +{ + return qfalse; +} static CaptureFunc *captureFunc = voidFunction; static int captureFuncExpiry = 0; @@ -67,14 +76,14 @@ int openMenuCount = 0; #define DOUBLE_CLICK_DELAY 300 static int lastListBoxClickTime = 0; -void Item_RunScript(itemDef_t *item, const char *s); -void Item_SetupKeywordHash(void); -void Menu_SetupKeywordHash(void); -int BindingIDFromName(const char *name); -qboolean Item_Bind_HandleKey(itemDef_t *item, int key, qboolean down); -itemDef_t *Menu_SetPrevCursorItem(menuDef_t *menu); -itemDef_t *Menu_SetNextCursorItem(menuDef_t *menu); -static qboolean Menu_OverActiveItem(menuDef_t *menu, float x, float y); +void Item_RunScript( itemDef_t *item, const char *s ); +void Item_SetupKeywordHash( void ); +void Menu_SetupKeywordHash( void ); +int BindingIDFromName( const char *name ); +qboolean Item_Bind_HandleKey( itemDef_t *item, int key, qboolean down ); +itemDef_t *Menu_SetPrevCursorItem( menuDef_t *menu ); +itemDef_t *Menu_SetNextCursorItem( menuDef_t *menu ); +static qboolean Menu_OverActiveItem( menuDef_t *menu, float x, float y ); /* =============== @@ -120,7 +129,7 @@ UI_Alloc */ void *UI_Alloc( int size ) { - char *p; + char * p; if( allocPoint + size > MEM_POOL_SIZE ) { @@ -128,6 +137,7 @@ void *UI_Alloc( int size ) if( DC->Print ) DC->Print( "UI_Alloc: Failure. Out of memory!\n" ); + //DC->trap_Print(S_COLOR_YELLOW"WARNING: UI Out of Memory!\n"); return NULL; } @@ -165,26 +175,33 @@ qboolean UI_OutOfMemory( ) return a hash value for the string ================ */ -static long hashForString(const char *str) { +static long hashForString( const char *str ) +{ int i; long hash; char letter; hash = 0; i = 0; - while (str[i] != '\0') { - letter = tolower(str[i]); - hash+=(long)(letter)*(i+119); + + while( str[i] != '\0' ) + { + letter = tolower( str[i] ); + hash += ( long )( letter ) * ( i + 119 ); i++; } - hash &= (HASH_TABLE_SIZE-1); + + hash &= ( HASH_TABLE_SIZE - 1 ); return hash; } -typedef struct stringDef_s { +typedef struct stringDef_s +{ struct stringDef_s *next; const char *str; -} stringDef_t; +} + +stringDef_t; static int strPoolIndex = 0; static char strPool[STRING_POOL_SIZE]; @@ -193,68 +210,76 @@ static int strHandleCount = 0; static stringDef_t *strHandle[HASH_TABLE_SIZE]; -const char *String_Alloc(const char *p) { +const char *String_Alloc( const char *p ) +{ int len; long hash; stringDef_t *str, *last; static const char *staticNULL = ""; - if (p == NULL) { + if( p == NULL ) return NULL; - } - if (*p == 0) { + if( *p == 0 ) return staticNULL; - } - hash = hashForString(p); + hash = hashForString( p ); str = strHandle[hash]; - while (str) { - if (strcmp(p, str->str) == 0) { + + while( str ) + { + if( strcmp( p, str->str ) == 0 ) return str->str; - } + str = str->next; } - len = strlen(p); - if (len + strPoolIndex + 1 < STRING_POOL_SIZE) { + len = strlen( p ); + + if( len + strPoolIndex + 1 < STRING_POOL_SIZE ) + { int ph = strPoolIndex; - strcpy(&strPool[strPoolIndex], p); + strcpy( &strPool[strPoolIndex], p ); strPoolIndex += len + 1; str = strHandle[hash]; last = str; - while (str && str->next) { + + while( str && str->next ) + { last = str; str = str->next; } - str = UI_Alloc(sizeof(stringDef_t)); + str = UI_Alloc( sizeof( stringDef_t ) ); str->next = NULL; str->str = &strPool[ph]; - if (last) { + + if( last ) last->next = str; - } else { + else strHandle[hash] = str; - } + return &strPool[ph]; } + return NULL; } -void String_Report( void ) { +void String_Report( void ) +{ float f; - Com_Printf("Memory/String Pool Info\n"); - Com_Printf("----------------\n"); + Com_Printf( "Memory/String Pool Info\n" ); + Com_Printf( "----------------\n" ); f = strPoolIndex; f /= STRING_POOL_SIZE; f *= 100; - Com_Printf("String Pool is %.1f%% full, %i bytes out of %i used.\n", f, strPoolIndex, STRING_POOL_SIZE); + Com_Printf( "String Pool is %.1f%% full, %i bytes out of %i used.\n", f, strPoolIndex, STRING_POOL_SIZE ); f = allocPoint; f /= MEM_POOL_SIZE; f *= 100; - Com_Printf("Memory Pool is %.1f%% full, %i bytes out of %i used.\n", f, allocPoint, MEM_POOL_SIZE); + Com_Printf( "Memory Pool is %.1f%% full, %i bytes out of %i used.\n", f, allocPoint, MEM_POOL_SIZE ); } /* @@ -265,15 +290,22 @@ String_Init void String_Init( void ) { int i; + for( i = 0; i < HASH_TABLE_SIZE; i++ ) strHandle[ i ] = 0; strHandleCount = 0; + strPoolIndex = 0; + menuCount = 0; + openMenuCount = 0; + UI_InitMemory( ); + Item_SetupKeywordHash( ); + Menu_SetupKeywordHash( ); if( DC && DC->getBindingBuf ) @@ -285,21 +317,22 @@ void String_Init( void ) PC_SourceWarning ================= */ -void PC_SourceWarning(int handle, char *format, ...) { +void PC_SourceWarning( int handle, char *format, ... ) +{ int line; char filename[128]; va_list argptr; static char string[4096]; - va_start (argptr, format); - vsprintf (string, format, argptr); - va_end (argptr); + va_start( argptr, format ); + vsprintf( string, format, argptr ); + va_end( argptr ); filename[0] = '\0'; line = 0; - trap_Parse_SourceFileAndLine(handle, filename, &line); + trap_Parse_SourceFileAndLine( handle, filename, &line ); - Com_Printf(S_COLOR_YELLOW "WARNING: %s, line %d: %s\n", filename, line, string); + Com_Printf( S_COLOR_YELLOW "WARNING: %s, line %d: %s\n", filename, line, string ); } /* @@ -307,21 +340,22 @@ void PC_SourceWarning(int handle, char *format, ...) { PC_SourceError ================= */ -void PC_SourceError(int handle, char *format, ...) { +void PC_SourceError( int handle, char *format, ... ) +{ int line; char filename[128]; va_list argptr; static char string[4096]; - va_start (argptr, format); - vsprintf (string, format, argptr); - va_end (argptr); + va_start( argptr, format ); + vsprintf( string, format, argptr ); + va_end( argptr ); filename[0] = '\0'; line = 0; - trap_Parse_SourceFileAndLine(handle, filename, &line); + trap_Parse_SourceFileAndLine( handle, filename, &line ); - Com_Printf(S_COLOR_RED "ERROR: %s, line %d: %s\n", filename, line, string); + Com_Printf( S_COLOR_RED "ERROR: %s, line %d: %s\n", filename, line, string ); } /* @@ -329,17 +363,19 @@ void PC_SourceError(int handle, char *format, ...) { LerpColor ================= */ -void LerpColor(vec4_t a, vec4_t b, vec4_t c, float t) +void LerpColor( vec4_t a, vec4_t b, vec4_t c, float t ) { int i; // lerp and clamp each component - for (i=0; i<4; i++) + + for( i = 0; i < 4; i++ ) { - c[i] = a[i] + t*(b[i]-a[i]); - if (c[i] < 0) + c[i] = a[i] + t * ( b[i] - a[i] ); + + if( c[i] < 0 ) c[i] = 0; - else if (c[i] > 1.0) + else if( c[i] > 1.0 ) c[i] = 1.0; } } @@ -349,15 +385,18 @@ void LerpColor(vec4_t a, vec4_t b, vec4_t c, float t) Float_Parse ================= */ -qboolean Float_Parse(char **p, float *f) { - char *token; - token = COM_ParseExt(p, qfalse); - if (token && token[0] != 0) { - *f = atof(token); +qboolean Float_Parse( char **p, float *f ) +{ + char * token; + token = COM_ParseExt( p, qfalse ); + + if( token && token[0] != 0 ) + { + *f = atof( token ); return qtrue; - } else { - return qfalse; } + else + return qfalse; } #define MAX_EXPR_ELEMENTS 32 @@ -366,7 +405,8 @@ typedef enum { EXPR_OPERATOR, EXPR_VALUE -} exprType_t; +} +exprType_t; typedef struct exprToken_s { @@ -376,18 +416,20 @@ typedef struct exprToken_s char op; float val; } u; -} exprToken_t; +} +exprToken_t; typedef struct exprList_s { exprToken_t l[ MAX_EXPR_ELEMENTS ]; int f, b; -} exprList_t; +} +exprList_t; /* ================= OpPrec - + Return a value reflecting operator precedence ================= */ @@ -395,12 +437,23 @@ static ID_INLINE int OpPrec( char op ) { switch( op ) { - case '*': return 4; - case '/': return 3; - case '+': return 2; - case '-': return 1; - case '(': return 0; - default: return -1; + case '*': + return 4; + + case '/': + return 3; + + case '+': + return 2; + + case '-': + return 1; + + case '(': + return 0; + + default: + return -1; } } @@ -478,6 +531,7 @@ static qboolean PC_Expression_Parse( int handle, float *f ) { if( !expectingNumber ) return qfalse; + expectingNumber = !expectingNumber; PUSH_VAL( fifo, token.floatvalue ); @@ -493,6 +547,7 @@ static qboolean PC_Expression_Parse( int handle, float *f ) case ')': unmatchedParentheses--; + if( unmatchedParentheses < 0 ) return qfalse; @@ -504,6 +559,7 @@ static qboolean PC_Expression_Parse( int handle, float *f ) // Pop the '(' POP_STACK( stack ); + break; case '*': @@ -512,6 +568,7 @@ static qboolean PC_Expression_Parse( int handle, float *f ) case '-': if( expectingNumber ) return qfalse; + expectingNumber = !expectingNumber; if( EMPTY( stack ) ) @@ -528,6 +585,7 @@ static qboolean PC_Expression_Parse( int handle, float *f ) PUSH_OP( stack, token.string[ 0 ] ); } + break; default: @@ -563,10 +621,22 @@ static qboolean PC_Expression_Parse( int handle, float *f ) switch( op ) { - case '*': result = operand1 * operand2; break; - case '/': result = operand1 / operand2; break; - case '+': result = operand1 + operand2; break; - case '-': result = operand1 - operand2; break; + case '*': + result = operand1 * operand2; + break; + + case '/': + result = operand1 / operand2; + break; + + case '+': + result = operand1 + operand2; + break; + + case '-': + result = operand1 - operand2; + break; + default: Com_Error( ERR_FATAL, "Unknown operator '%c' in postfix string", op ); return qfalse; @@ -597,29 +667,36 @@ static qboolean PC_Expression_Parse( int handle, float *f ) PC_Float_Parse ================= */ -qboolean PC_Float_Parse(int handle, float *f) { +qboolean PC_Float_Parse( int handle, float *f ) +{ pc_token_t token; int negative = qfalse; - if (!trap_Parse_ReadToken(handle, &token)) + if( !trap_Parse_ReadToken( handle, &token ) ) return qfalse; if( token.string[ 0 ] == '(' ) return PC_Expression_Parse( handle, f ); - if (token.string[0] == '-') { - if (!trap_Parse_ReadToken(handle, &token)) + if( token.string[0] == '-' ) + { + if( !trap_Parse_ReadToken( handle, &token ) ) return qfalse; + negative = qtrue; } - if (token.type != TT_NUMBER) { - PC_SourceError(handle, "expected float but found %s\n", token.string); + + if( token.type != TT_NUMBER ) + { + PC_SourceError( handle, "expected float but found %s\n", token.string ); return qfalse; } - if (negative) - *f = -token.floatvalue; + + if( negative ) + * f = -token.floatvalue; else *f = token.floatvalue; + return qtrue; } @@ -628,16 +705,19 @@ qboolean PC_Float_Parse(int handle, float *f) { Color_Parse ================= */ -qboolean Color_Parse(char **p, vec4_t *c) { +qboolean Color_Parse( char **p, vec4_t *c ) +{ int i; float f; - for (i = 0; i < 4; i++) { - if (!Float_Parse(p, &f)) { + for( i = 0; i < 4; i++ ) + { + if( !Float_Parse( p, &f ) ) return qfalse; - } - (*c)[i] = f; + + ( *c )[i] = f; } + return qtrue; } @@ -646,16 +726,19 @@ qboolean Color_Parse(char **p, vec4_t *c) { PC_Color_Parse ================= */ -qboolean PC_Color_Parse(int handle, vec4_t *c) { +qboolean PC_Color_Parse( int handle, vec4_t *c ) +{ int i; float f; - for (i = 0; i < 4; i++) { - if (!PC_Float_Parse(handle, &f)) { + for( i = 0; i < 4; i++ ) + { + if( !PC_Float_Parse( handle, &f ) ) return qfalse; - } - (*c)[i] = f; + + ( *c )[i] = f; } + return qtrue; } @@ -664,16 +747,18 @@ qboolean PC_Color_Parse(int handle, vec4_t *c) { Int_Parse ================= */ -qboolean Int_Parse(char **p, int *i) { - char *token; - token = COM_ParseExt(p, qfalse); +qboolean Int_Parse( char **p, int *i ) +{ + char * token; + token = COM_ParseExt( p, qfalse ); - if (token && token[0] != 0) { - *i = atoi(token); + if( token && token[0] != 0 ) + { + *i = atoi( token ); return qtrue; - } else { - return qfalse; } + else + return qfalse; } /* @@ -681,11 +766,12 @@ qboolean Int_Parse(char **p, int *i) { PC_Int_Parse ================= */ -qboolean PC_Int_Parse(int handle, int *i) { +qboolean PC_Int_Parse( int handle, int *i ) +{ pc_token_t token; int negative = qfalse; - if (!trap_Parse_ReadToken(handle, &token)) + if( !trap_Parse_ReadToken( handle, &token ) ) return qfalse; if( token.string[ 0 ] == '(' ) @@ -694,25 +780,32 @@ qboolean PC_Int_Parse(int handle, int *i) { if( PC_Expression_Parse( handle, &f ) ) { - *i = (int)f; + *i = ( int )f; return qtrue; } else return qfalse; } - if (token.string[0] == '-') { - if (!trap_Parse_ReadToken(handle, &token)) + if( token.string[0] == '-' ) + { + if( !trap_Parse_ReadToken( handle, &token ) ) return qfalse; + negative = qtrue; } - if (token.type != TT_NUMBER) { - PC_SourceError(handle, "expected integer but found %s\n", token.string); + + if( token.type != TT_NUMBER ) + { + PC_SourceError( handle, "expected integer but found %s\n", token.string ); return qfalse; } + *i = token.intvalue; - if (negative) - *i = - *i; + + if( negative ) + * i = - *i; + return qtrue; } @@ -721,16 +814,20 @@ qboolean PC_Int_Parse(int handle, int *i) { Rect_Parse ================= */ -qboolean Rect_Parse(char **p, rectDef_t *r) { - if (Float_Parse(p, &r->x)) { - if (Float_Parse(p, &r->y)) { - if (Float_Parse(p, &r->w)) { - if (Float_Parse(p, &r->h)) { +qboolean Rect_Parse( char **p, rectDef_t *r ) +{ + if( Float_Parse( p, &r->x ) ) + { + if( Float_Parse( p, &r->y ) ) + { + if( Float_Parse( p, &r->w ) ) + { + if( Float_Parse( p, &r->h ) ) return qtrue; - } } } } + return qfalse; } @@ -739,16 +836,20 @@ qboolean Rect_Parse(char **p, rectDef_t *r) { PC_Rect_Parse ================= */ -qboolean PC_Rect_Parse(int handle, rectDef_t *r) { - if (PC_Float_Parse(handle, &r->x)) { - if (PC_Float_Parse(handle, &r->y)) { - if (PC_Float_Parse(handle, &r->w)) { - if (PC_Float_Parse(handle, &r->h)) { +qboolean PC_Rect_Parse( int handle, rectDef_t *r ) +{ + if( PC_Float_Parse( handle, &r->x ) ) + { + if( PC_Float_Parse( handle, &r->y ) ) + { + if( PC_Float_Parse( handle, &r->w ) ) + { + if( PC_Float_Parse( handle, &r->h ) ) return qtrue; - } } } } + return qfalse; } @@ -757,14 +858,18 @@ qboolean PC_Rect_Parse(int handle, rectDef_t *r) { String_Parse ================= */ -qboolean String_Parse(char **p, const char **out) { - char *token; +qboolean String_Parse( char **p, const char **out ) +{ + char * token; - token = COM_ParseExt(p, qfalse); - if (token && token[0] != 0) { - *(out) = String_Alloc(token); + token = COM_ParseExt( p, qfalse ); + + if( token && token[0] != 0 ) + { + *( out ) = String_Alloc( token ); return qtrue; } + return qfalse; } @@ -773,14 +878,16 @@ qboolean String_Parse(char **p, const char **out) { PC_String_Parse ================= */ -qboolean PC_String_Parse(int handle, const char **out) { +qboolean PC_String_Parse( int handle, const char **out ) +{ pc_token_t token; - if (!trap_Parse_ReadToken(handle, &token)) + if( !trap_Parse_ReadToken( handle, &token ) ) return qfalse; - *(out) = String_Alloc(token.string); - return qtrue; + *( out ) = String_Alloc( token.string ); + + return qtrue; } /* @@ -788,36 +895,40 @@ qboolean PC_String_Parse(int handle, const char **out) { PC_Script_Parse ================= */ -qboolean PC_Script_Parse(int handle, const char **out) { +qboolean PC_Script_Parse( int handle, const char **out ) +{ char script[1024]; pc_token_t token; - memset(script, 0, sizeof(script)); + memset( script, 0, sizeof( script ) ); // scripts start with { and have ; separated command lists.. commands are command, arg.. // basically we want everything between the { } as it will be interpreted at run time - if (!trap_Parse_ReadToken(handle, &token)) + if( !trap_Parse_ReadToken( handle, &token ) ) + return qfalse; + + if( Q_stricmp( token.string, "{" ) != 0 ) return qfalse; - if (Q_stricmp(token.string, "{") != 0) { - return qfalse; - } - while ( 1 ) { - if (!trap_Parse_ReadToken(handle, &token)) + while( 1 ) + { + if( !trap_Parse_ReadToken( handle, &token ) ) return qfalse; - if (Q_stricmp(token.string, "}") == 0) { - *out = String_Alloc(script); + if( Q_stricmp( token.string, "}" ) == 0 ) + { + *out = String_Alloc( script ); return qtrue; } - if (token.string[1] != '\0') { - Q_strcat(script, 1024, va("\"%s\"", token.string)); - } else { - Q_strcat(script, 1024, token.string); - } - Q_strcat(script, 1024, " "); + if( token.string[1] != '\0' ) + Q_strcat( script, 1024, va( "\"%s\"", token.string ) ); + else + Q_strcat( script, 1024, token.string ); + + Q_strcat( script, 1024, " " ); } + return qfalse; } @@ -827,7 +938,7 @@ qboolean PC_Script_Parse(int handle, const char **out) { /* ================== Init_Display - + Initializes the display with a structure to all the drawing routines ================== */ @@ -852,34 +963,44 @@ void GradientBar_Paint( rectDef_t *rect, vec4_t color ) /* ================== Window_Init - + Initializes a window structure ( windowDef_t ) with defaults - + ================== */ -void Window_Init(Window *w) { - memset(w, 0, sizeof(windowDef_t)); +void Window_Init( Window *w ) +{ + memset( w, 0, sizeof( windowDef_t ) ); w->borderSize = 1; w->foreColor[0] = w->foreColor[1] = w->foreColor[2] = w->foreColor[3] = 1.0; w->cinematic = -1; } -void Fade(int *flags, float *f, float clamp, int *nextTime, int offsetTime, qboolean bFlags, float fadeAmount) { - if (*flags & (WINDOW_FADINGOUT | WINDOW_FADINGIN)) { - if (DC->realTime > *nextTime) { +void Fade( int *flags, float *f, float clamp, int *nextTime, int offsetTime, qboolean bFlags, float fadeAmount ) +{ + if( *flags & ( WINDOW_FADINGOUT | WINDOW_FADINGIN ) ) + { + if( DC->realTime > *nextTime ) + { *nextTime = DC->realTime + offsetTime; - if (*flags & WINDOW_FADINGOUT) { + + if( *flags & WINDOW_FADINGOUT ) + { *f -= fadeAmount; - if (bFlags && *f <= 0.0) { - *flags &= ~(WINDOW_FADINGOUT | WINDOW_VISIBLE); - } - } else { + + if( bFlags && *f <= 0.0 ) + *flags &= ~( WINDOW_FADINGOUT | WINDOW_VISIBLE ); + } + else + { *f += fadeAmount; - if (*f >= clamp) { + + if( *f >= clamp ) + { *f = clamp; - if (bFlags) { + + if( bFlags ) *flags &= ~WINDOW_FADINGIN; - } } } } @@ -888,96 +1009,117 @@ void Fade(int *flags, float *f, float clamp, int *nextTime, int offsetTime, qboo -static void Window_Paint(Window *w, float fadeAmount, float fadeClamp, float fadeCycle) { +static void Window_Paint( Window *w, float fadeAmount, float fadeClamp, float fadeCycle ) +{ vec4_t color; rectDef_t fillRect = w->rect; - if ( DC->getCVarValue( "ui_developer" ) ) { + if( DC->getCVarValue( "ui_developer" ) ) + { color[0] = color[1] = color[2] = color[3] = 1; - DC->drawRect(w->rect.x, w->rect.y, w->rect.w, w->rect.h, 1, color); + DC->drawRect( w->rect.x, w->rect.y, w->rect.w, w->rect.h, 1, color ); } - if (w == NULL || (w->style == 0 && w->border == 0)) { + if( w == NULL || ( w->style == 0 && w->border == 0 ) ) return; - } - if (w->border != 0) { + if( w->border != 0 ) + { fillRect.x += w->borderSize; fillRect.y += w->borderSize; fillRect.w -= w->borderSize + 1; fillRect.h -= w->borderSize + 1; } - if (w->style == WINDOW_STYLE_FILLED) { + if( w->style == WINDOW_STYLE_FILLED ) + { // box, but possible a shader that needs filled - if (w->background) { - Fade(&w->flags, &w->backColor[3], fadeClamp, &w->nextTime, fadeCycle, qtrue, fadeAmount); - DC->setColor(w->backColor); - DC->drawHandlePic(fillRect.x, fillRect.y, fillRect.w, fillRect.h, w->background); - DC->setColor(NULL); - } else { - DC->fillRect(fillRect.x, fillRect.y, fillRect.w, fillRect.h, w->backColor); - } - } else if (w->style == WINDOW_STYLE_GRADIENT) { - GradientBar_Paint(&fillRect, w->backColor); + + if( w->background ) + { + Fade( &w->flags, &w->backColor[3], fadeClamp, &w->nextTime, fadeCycle, qtrue, fadeAmount ); + DC->setColor( w->backColor ); + DC->drawHandlePic( fillRect.x, fillRect.y, fillRect.w, fillRect.h, w->background ); + DC->setColor( NULL ); + } + else + DC->fillRect( fillRect.x, fillRect.y, fillRect.w, fillRect.h, w->backColor ); + } + else if( w->style == WINDOW_STYLE_GRADIENT ) + { + GradientBar_Paint( &fillRect, w->backColor ); // gradient bar - } else if (w->style == WINDOW_STYLE_SHADER) { - if (w->flags & WINDOW_FORECOLORSET) { - DC->setColor(w->foreColor); - } - DC->drawHandlePic(fillRect.x, fillRect.y, fillRect.w, fillRect.h, w->background); - DC->setColor(NULL); - } else if (w->style == WINDOW_STYLE_CINEMATIC) { - if (w->cinematic == -1) { - w->cinematic = DC->playCinematic(w->cinematicName, fillRect.x, fillRect.y, fillRect.w, fillRect.h); - if (w->cinematic == -1) { + } + else if( w->style == WINDOW_STYLE_SHADER ) + { + if( w->flags & WINDOW_FORECOLORSET ) + DC->setColor( w->foreColor ); + + DC->drawHandlePic( fillRect.x, fillRect.y, fillRect.w, fillRect.h, w->background ); + DC->setColor( NULL ); + } + else if( w->style == WINDOW_STYLE_CINEMATIC ) + { + if( w->cinematic == -1 ) + { + w->cinematic = DC->playCinematic( w->cinematicName, fillRect.x, fillRect.y, fillRect.w, fillRect.h ); + + if( w->cinematic == -1 ) w->cinematic = -2; - } } - if (w->cinematic >= 0) { - DC->runCinematicFrame(w->cinematic); - DC->drawCinematic(w->cinematic, fillRect.x, fillRect.y, fillRect.w, fillRect.h); + + if( w->cinematic >= 0 ) + { + DC->runCinematicFrame( w->cinematic ); + DC->drawCinematic( w->cinematic, fillRect.x, fillRect.y, fillRect.w, fillRect.h ); } } } -static void Border_Paint(Window *w) { - if (w == NULL || (w->style == 0 && w->border == 0)) { +static void Border_Paint( Window *w ) +{ + if( w == NULL || ( w->style == 0 && w->border == 0 ) ) return; - } - if (w->border == WINDOW_BORDER_FULL) { + if( w->border == WINDOW_BORDER_FULL ) + { // full - DC->drawRect(w->rect.x, w->rect.y, w->rect.w, w->rect.h, w->borderSize, w->borderColor); - } else if (w->border == WINDOW_BORDER_HORZ) { + DC->drawRect( w->rect.x, w->rect.y, w->rect.w, w->rect.h, w->borderSize, w->borderColor ); + } + else if( w->border == WINDOW_BORDER_HORZ ) + { // top/bottom - DC->setColor(w->borderColor); - DC->drawTopBottom(w->rect.x, w->rect.y, w->rect.w, w->rect.h, w->borderSize); + DC->setColor( w->borderColor ); + DC->drawTopBottom( w->rect.x, w->rect.y, w->rect.w, w->rect.h, w->borderSize ); DC->setColor( NULL ); - } else if (w->border == WINDOW_BORDER_VERT) { + } + else if( w->border == WINDOW_BORDER_VERT ) + { // left right - DC->setColor(w->borderColor); - DC->drawSides(w->rect.x, w->rect.y, w->rect.w, w->rect.h, w->borderSize); + DC->setColor( w->borderColor ); + DC->drawSides( w->rect.x, w->rect.y, w->rect.w, w->rect.h, w->borderSize ); DC->setColor( NULL ); - } else if (w->border == WINDOW_BORDER_KCGRADIENT) { + } + else if( w->border == WINDOW_BORDER_KCGRADIENT ) + { // this is just two gradient bars along each horz edge rectDef_t r = w->rect; r.h = w->borderSize; - GradientBar_Paint(&r, w->borderColor); + GradientBar_Paint( &r, w->borderColor ); r.y = w->rect.y + w->rect.h - 1; - GradientBar_Paint(&r, w->borderColor); + GradientBar_Paint( &r, w->borderColor ); } } -void Item_SetScreenCoords(itemDef_t *item, float x, float y) { - - if (item == NULL) { +void Item_SetScreenCoords( itemDef_t *item, float x, float y ) +{ + if( item == NULL ) return; - } - if (item->window.border != 0) { + if( item->window.border != 0 ) + { x += item->window.borderSize; y += item->window.borderSize; } @@ -993,47 +1135,49 @@ void Item_SetScreenCoords(itemDef_t *item, float x, float y) { } // FIXME: consolidate this with nearby stuff -void Item_UpdatePosition(itemDef_t *item) { +void Item_UpdatePosition( itemDef_t *item ) +{ float x, y; menuDef_t *menu; - if (item == NULL || item->parent == NULL) { + if( item == NULL || item->parent == NULL ) return; - } menu = item->parent; x = menu->window.rect.x; y = menu->window.rect.y; - if (menu->window.border != 0) { + if( menu->window.border != 0 ) + { x += menu->window.borderSize; y += menu->window.borderSize; } - Item_SetScreenCoords(item, x, y); + Item_SetScreenCoords( item, x, y ); } // menus -void Menu_UpdatePosition(menuDef_t *menu) { +void Menu_UpdatePosition( menuDef_t *menu ) +{ int i; float x, y; - if (menu == NULL) { + if( menu == NULL ) return; - } x = menu->window.rect.x; y = menu->window.rect.y; - if (menu->window.border != 0) { + + if( menu->window.border != 0 ) + { x += menu->window.borderSize; y += menu->window.borderSize; } - for (i = 0; i < menu->itemCount; i++) { - Item_SetScreenCoords(menu->items[i], x, y); - } + for( i = 0; i < menu->itemCount; i++ ) + Item_SetScreenCoords( menu->items[i], x, y ); } static void Menu_AspectiseRect( int bias, Rectangle *rect ) @@ -1057,6 +1201,7 @@ static void Menu_AspectiseRect( int bias, Rectangle *rect ) break; default: + case ASPECT_NONE: break; } @@ -1083,185 +1228,229 @@ void Menu_AspectCompensate( menuDef_t *menu ) { Menu_AspectiseRect( menu->items[ i ]->window.aspectBias, &menu->items[ i ]->window.rectClient ); + if( menu->items[ i ]->window.aspectBias != ASPECT_NONE ) menu->items[ i ]->textalignx *= DC->aspectScale; } } } -void Menu_PostParse(menuDef_t *menu) { - if (menu == NULL) { +void Menu_PostParse( menuDef_t *menu ) +{ + if( menu == NULL ) return; - } - if (menu->fullScreen) { + + if( menu->fullScreen ) + { menu->window.rect.x = 0; menu->window.rect.y = 0; menu->window.rect.w = 640; menu->window.rect.h = 480; } + Menu_AspectCompensate( menu ); - Menu_UpdatePosition(menu); + Menu_UpdatePosition( menu ); } -itemDef_t *Menu_ClearFocus(menuDef_t *menu) { +itemDef_t *Menu_ClearFocus( menuDef_t *menu ) +{ int i; itemDef_t *ret = NULL; - if (menu == NULL) { + if( menu == NULL ) return NULL; - } - for (i = 0; i < menu->itemCount; i++) { - if (menu->items[i]->window.flags & WINDOW_HASFOCUS) { + for( i = 0; i < menu->itemCount; i++ ) + { + if( menu->items[i]->window.flags & WINDOW_HASFOCUS ) ret = menu->items[i]; - } + menu->items[i]->window.flags &= ~WINDOW_HASFOCUS; - if (menu->items[i]->leaveFocus) { - Item_RunScript(menu->items[i], menu->items[i]->leaveFocus); - } + + if( menu->items[i]->leaveFocus ) + Item_RunScript( menu->items[i], menu->items[i]->leaveFocus ); } return ret; } -qboolean IsVisible(int flags) { - return (flags & WINDOW_VISIBLE && !(flags & WINDOW_FADINGOUT)); +qboolean IsVisible( int flags ) +{ + return ( flags & WINDOW_VISIBLE && !( flags & WINDOW_FADINGOUT ) ); } -qboolean Rect_ContainsPoint(rectDef_t *rect, float x, float y) { - if (rect) { - if (x > rect->x && x < rect->x + rect->w && y > rect->y && y < rect->y + rect->h) { +qboolean Rect_ContainsPoint( rectDef_t *rect, float x, float y ) +{ + if( rect ) + { + if( x > rect->x && x < rect->x + rect->w && y > rect->y && y < rect->y + rect->h ) return qtrue; - } } + return qfalse; } -int Menu_ItemsMatchingGroup(menuDef_t *menu, const char *name) { +int Menu_ItemsMatchingGroup( menuDef_t *menu, const char *name ) +{ int i; int count = 0; - for (i = 0; i < menu->itemCount; i++) { - if (Q_stricmp(menu->items[i]->window.name, name) == 0 || (menu->items[i]->window.group && Q_stricmp(menu->items[i]->window.group, name) == 0)) { + + for( i = 0; i < menu->itemCount; i++ ) + { + if( Q_stricmp( menu->items[i]->window.name, name ) == 0 || + ( menu->items[i]->window.group && Q_stricmp( menu->items[i]->window.group, name ) == 0 ) ) + { count++; } } + return count; } -itemDef_t *Menu_GetMatchingItemByNumber(menuDef_t *menu, int index, const char *name) { +itemDef_t *Menu_GetMatchingItemByNumber( menuDef_t *menu, int index, const char *name ) +{ int i; int count = 0; - for (i = 0; i < menu->itemCount; i++) { - if (Q_stricmp(menu->items[i]->window.name, name) == 0 || (menu->items[i]->window.group && Q_stricmp(menu->items[i]->window.group, name) == 0)) { - if (count == index) { + + for( i = 0; i < menu->itemCount; i++ ) + { + if( Q_stricmp( menu->items[i]->window.name, name ) == 0 || + ( menu->items[i]->window.group && Q_stricmp( menu->items[i]->window.group, name ) == 0 ) ) + { + if( count == index ) return menu->items[i]; - } + count++; } } + return NULL; } -void Script_SetColor(itemDef_t *item, char **args) { - const char *name; +void Script_SetColor( itemDef_t *item, char **args ) +{ + const char * name; int i; float f; vec4_t *out; // expecting type of color to set and 4 args for the color - if (String_Parse(args, &name)) { - out = NULL; - if (Q_stricmp(name, "backcolor") == 0) { - out = &item->window.backColor; - item->window.flags |= WINDOW_BACKCOLORSET; - } else if (Q_stricmp(name, "forecolor") == 0) { - out = &item->window.foreColor; - item->window.flags |= WINDOW_FORECOLORSET; - } else if (Q_stricmp(name, "bordercolor") == 0) { - out = &item->window.borderColor; - } - if (out) { - for (i = 0; i < 4; i++) { - if (!Float_Parse(args, &f)) { - return; - } - (*out)[i] = f; - } + if( String_Parse( args, &name ) ) + { + out = NULL; + + if( Q_stricmp( name, "backcolor" ) == 0 ) + { + out = &item->window.backColor; + item->window.flags |= WINDOW_BACKCOLORSET; + } + else if( Q_stricmp( name, "forecolor" ) == 0 ) + { + out = &item->window.foreColor; + item->window.flags |= WINDOW_FORECOLORSET; + } + else if( Q_stricmp( name, "bordercolor" ) == 0 ) + out = &item->window.borderColor; + + if( out ) + { + for( i = 0; i < 4; i++ ) + { + if( !Float_Parse( args, &f ) ) + return; + + ( *out )[i] = f; } + } } } -void Script_SetAsset(itemDef_t *item, char **args) { - const char *name; +void Script_SetAsset( itemDef_t *item, char **args ) +{ + const char * name; // expecting name to set asset to - if (String_Parse(args, &name)) { + + if( String_Parse( args, &name ) ) + { // check for a model - if (item->type == ITEM_TYPE_MODEL) { - } + + if( item->type == ITEM_TYPE_MODEL ) + {} + } + } -void Script_SetBackground(itemDef_t *item, char **args) { - const char *name; +void Script_SetBackground( itemDef_t *item, char **args ) +{ + const char * name; // expecting name to set asset to - if (String_Parse(args, &name)) { - item->window.background = DC->registerShaderNoMip(name); - } + + if( String_Parse( args, &name ) ) + item->window.background = DC->registerShaderNoMip( name ); } -itemDef_t *Menu_FindItemByName(menuDef_t *menu, const char *p) { +itemDef_t *Menu_FindItemByName( menuDef_t *menu, const char *p ) +{ int i; - if (menu == NULL || p == NULL) { + + if( menu == NULL || p == NULL ) return NULL; - } - for (i = 0; i < menu->itemCount; i++) { - if (Q_stricmp(p, menu->items[i]->window.name) == 0) { + for( i = 0; i < menu->itemCount; i++ ) + { + if( Q_stricmp( p, menu->items[i]->window.name ) == 0 ) return menu->items[i]; - } } return NULL; } -void Script_SetItemColor(itemDef_t *item, char **args) { - const char *itemname; +void Script_SetItemColor( itemDef_t *item, char **args ) +{ + const char * itemname; const char *name; vec4_t color; int i; vec4_t *out; // expecting type of color to set and 4 args for the color - if (String_Parse(args, &itemname) && String_Parse(args, &name)) { - itemDef_t *item2; + + if( String_Parse( args, &itemname ) && String_Parse( args, &name ) ) + { + itemDef_t * item2; int j; - int count = Menu_ItemsMatchingGroup(item->parent, itemname); + int count = Menu_ItemsMatchingGroup( item->parent, itemname ); - if (!Color_Parse(args, &color)) { + if( !Color_Parse( args, &color ) ) return; - } - for (j = 0; j < count; j++) { - item2 = Menu_GetMatchingItemByNumber(item->parent, j, itemname); - if (item2 != NULL) { + for( j = 0; j < count; j++ ) + { + item2 = Menu_GetMatchingItemByNumber( item->parent, j, itemname ); + + if( item2 != NULL ) + { out = NULL; - if (Q_stricmp(name, "backcolor") == 0) { + + if( Q_stricmp( name, "backcolor" ) == 0 ) out = &item2->window.backColor; - } else if (Q_stricmp(name, "forecolor") == 0) { + else if( Q_stricmp( name, "forecolor" ) == 0 ) + { out = &item2->window.foreColor; item2->window.flags |= WINDOW_FORECOLORSET; - } else if (Q_stricmp(name, "bordercolor") == 0) { - out = &item2->window.borderColor; } + else if( Q_stricmp( name, "bordercolor" ) == 0 ) + out = &item2->window.borderColor; - if (out) { - for (i = 0; i < 4; i++) { - (*out)[i] = color[i]; - } + if( out ) + { + for( i = 0; i < 4; i++ ) + ( *out )[i] = color[i]; } } } @@ -1269,20 +1458,28 @@ void Script_SetItemColor(itemDef_t *item, char **args) { } -void Menu_ShowItemByName(menuDef_t *menu, const char *p, qboolean bShow) { - itemDef_t *item; +void Menu_ShowItemByName( menuDef_t *menu, const char *p, qboolean bShow ) +{ + itemDef_t * item; int i; - int count = Menu_ItemsMatchingGroup(menu, p); - for (i = 0; i < count; i++) { - item = Menu_GetMatchingItemByNumber(menu, i, p); - if (item != NULL) { - if (bShow) { + int count = Menu_ItemsMatchingGroup( menu, p ); + + for( i = 0; i < count; i++ ) + { + item = Menu_GetMatchingItemByNumber( menu, i, p ); + + if( item != NULL ) + { + if( bShow ) item->window.flags |= WINDOW_VISIBLE; - } else { + else + { item->window.flags &= ~WINDOW_VISIBLE; // stop cinematics playing in the window - if (item->window.cinematic >= 0) { - DC->stopCinematic(item->window.cinematic); + + if( item->window.cinematic >= 0 ) + { + DC->stopCinematic( item->window.cinematic ); item->window.cinematic = -1; } } @@ -1290,235 +1487,284 @@ void Menu_ShowItemByName(menuDef_t *menu, const char *p, qboolean bShow) { } } -void Menu_FadeItemByName(menuDef_t *menu, const char *p, qboolean fadeOut) { - itemDef_t *item; +void Menu_FadeItemByName( menuDef_t *menu, const char *p, qboolean fadeOut ) +{ + itemDef_t * item; int i; - int count = Menu_ItemsMatchingGroup(menu, p); - for (i = 0; i < count; i++) { - item = Menu_GetMatchingItemByNumber(menu, i, p); - if (item != NULL) { - if (fadeOut) { - item->window.flags |= (WINDOW_FADINGOUT | WINDOW_VISIBLE); + int count = Menu_ItemsMatchingGroup( menu, p ); + + for( i = 0; i < count; i++ ) + { + item = Menu_GetMatchingItemByNumber( menu, i, p ); + + if( item != NULL ) + { + if( fadeOut ) + { + item->window.flags |= ( WINDOW_FADINGOUT | WINDOW_VISIBLE ); item->window.flags &= ~WINDOW_FADINGIN; - } else { - item->window.flags |= (WINDOW_VISIBLE | WINDOW_FADINGIN); + } + else + { + item->window.flags |= ( WINDOW_VISIBLE | WINDOW_FADINGIN ); item->window.flags &= ~WINDOW_FADINGOUT; } } } } -menuDef_t *Menus_FindByName(const char *p) { +menuDef_t *Menus_FindByName( const char *p ) +{ int i; - for (i = 0; i < menuCount; i++) { - if (Q_stricmp(Menus[i].window.name, p) == 0) { - return &Menus[i]; - } + + for( i = 0; i < menuCount; i++ ) + { + if( Q_stricmp( Menus[i].window.name, p ) == 0 ) + return & Menus[i]; } + return NULL; } -static void Menu_RunCloseScript(menuDef_t *menu) { - if (menu && menu->window.flags & WINDOW_VISIBLE && menu->onClose) { +static void Menu_RunCloseScript( menuDef_t *menu ) +{ + if( menu && menu->window.flags & WINDOW_VISIBLE && menu->onClose ) + { itemDef_t item; item.parent = menu; - Item_RunScript(&item, menu->onClose); + Item_RunScript( &item, menu->onClose ); } } static void Menus_Close( menuDef_t *menu ) { - if (menu != NULL) { - Menu_RunCloseScript(menu); - menu->window.flags &= ~(WINDOW_VISIBLE | WINDOW_HASFOCUS); + if( menu != NULL ) + { + Menu_RunCloseScript( menu ); + menu->window.flags &= ~( WINDOW_VISIBLE | WINDOW_HASFOCUS ); openMenuCount--; + if( openMenuCount > 0 ) Menus_Activate( menuStack[ openMenuCount - 1 ] ); } } -void Menus_CloseByName(const char *p) { - Menus_Close( Menus_FindByName(p) ); +void Menus_CloseByName( const char *p ) +{ + Menus_Close( Menus_FindByName( p ) ); } -void Menus_CloseAll( void ) { +void Menus_CloseAll( void ) +{ int i; - for (i = 0; i < menuCount; i++) { - Menus_Close(&Menus[i]); - } + + for( i = 0; i < menuCount; i++ ) + Menus_Close( &Menus[i] ); openMenuCount = 0; } -void Script_Show(itemDef_t *item, char **args) { - const char *name; - if (String_Parse(args, &name)) { - Menu_ShowItemByName(item->parent, name, qtrue); - } +void Script_Show( itemDef_t *item, char **args ) +{ + const char * name; + + if( String_Parse( args, &name ) ) + Menu_ShowItemByName( item->parent, name, qtrue ); } -void Script_Hide(itemDef_t *item, char **args) { - const char *name; - if (String_Parse(args, &name)) { - Menu_ShowItemByName(item->parent, name, qfalse); - } +void Script_Hide( itemDef_t *item, char **args ) +{ + const char * name; + + if( String_Parse( args, &name ) ) + Menu_ShowItemByName( item->parent, name, qfalse ); } -void Script_FadeIn(itemDef_t *item, char **args) { - const char *name; - if (String_Parse(args, &name)) { - Menu_FadeItemByName(item->parent, name, qfalse); - } +void Script_FadeIn( itemDef_t *item, char **args ) +{ + const char * name; + + if( String_Parse( args, &name ) ) + Menu_FadeItemByName( item->parent, name, qfalse ); } -void Script_FadeOut(itemDef_t *item, char **args) { - const char *name; - if (String_Parse(args, &name)) { - Menu_FadeItemByName(item->parent, name, qtrue); - } +void Script_FadeOut( itemDef_t *item, char **args ) +{ + const char * name; + + if( String_Parse( args, &name ) ) + Menu_FadeItemByName( item->parent, name, qtrue ); } -void Script_Open(itemDef_t *item, char **args) { - const char *name; - if (String_Parse(args, &name)) { - Menus_ActivateByName(name); - } +void Script_Open( itemDef_t *item, char **args ) +{ + const char * name; + + if( String_Parse( args, &name ) ) + Menus_ActivateByName( name ); } -void Script_ConditionalOpen(itemDef_t *item, char **args) { - const char *cvar; +void Script_ConditionalOpen( itemDef_t *item, char **args ) +{ + const char * cvar; const char *name1; const char *name2; float val; - if ( String_Parse(args, &cvar) && String_Parse(args, &name1) && String_Parse(args, &name2) ) { + if( String_Parse( args, &cvar ) && String_Parse( args, &name1 ) && String_Parse( args, &name2 ) ) + { val = DC->getCVarValue( cvar ); - if ( val == 0.f ) { - Menus_ActivateByName(name2); - } else { - Menus_ActivateByName(name1); - } + + if( val == 0.f ) + Menus_ActivateByName( name2 ); + else + Menus_ActivateByName( name1 ); } } -void Script_Close(itemDef_t *item, char **args) { - const char *name; - if (String_Parse(args, &name)) { - Menus_CloseByName(name); - } +void Script_Close( itemDef_t *item, char **args ) +{ + const char * name; + + if( String_Parse( args, &name ) ) + Menus_CloseByName( name ); } -void Menu_TransitionItemByName(menuDef_t *menu, const char *p, rectDef_t rectFrom, rectDef_t rectTo, int time, float amt) { - itemDef_t *item; +void Menu_TransitionItemByName( menuDef_t *menu, const char *p, rectDef_t rectFrom, rectDef_t rectTo, + int time, float amt ) +{ + itemDef_t * item; int i; - int count = Menu_ItemsMatchingGroup(menu, p); - for (i = 0; i < count; i++) { - item = Menu_GetMatchingItemByNumber(menu, i, p); - if (item != NULL) { - item->window.flags |= (WINDOW_INTRANSITION | WINDOW_VISIBLE); + int count = Menu_ItemsMatchingGroup( menu, p ); + + for( i = 0; i < count; i++ ) + { + item = Menu_GetMatchingItemByNumber( menu, i, p ); + + if( item != NULL ) + { + item->window.flags |= ( WINDOW_INTRANSITION | WINDOW_VISIBLE ); item->window.offsetTime = time; - memcpy(&item->window.rectClient, &rectFrom, sizeof(rectDef_t)); - memcpy(&item->window.rectEffects, &rectTo, sizeof(rectDef_t)); - item->window.rectEffects2.x = abs(rectTo.x - rectFrom.x) / amt; - item->window.rectEffects2.y = abs(rectTo.y - rectFrom.y) / amt; - item->window.rectEffects2.w = abs(rectTo.w - rectFrom.w) / amt; - item->window.rectEffects2.h = abs(rectTo.h - rectFrom.h) / amt; - Item_UpdatePosition(item); + memcpy( &item->window.rectClient, &rectFrom, sizeof( rectDef_t ) ); + memcpy( &item->window.rectEffects, &rectTo, sizeof( rectDef_t ) ); + item->window.rectEffects2.x = abs( rectTo.x - rectFrom.x ) / amt; + item->window.rectEffects2.y = abs( rectTo.y - rectFrom.y ) / amt; + item->window.rectEffects2.w = abs( rectTo.w - rectFrom.w ) / amt; + item->window.rectEffects2.h = abs( rectTo.h - rectFrom.h ) / amt; + Item_UpdatePosition( item ); } } } -void Script_Transition(itemDef_t *item, char **args) { - const char *name; +void Script_Transition( itemDef_t *item, char **args ) +{ + const char * name; rectDef_t rectFrom, rectTo; int time; float amt; - if (String_Parse(args, &name)) { - if ( Rect_Parse(args, &rectFrom) && Rect_Parse(args, &rectTo) && Int_Parse(args, &time) && Float_Parse(args, &amt)) { - Menu_TransitionItemByName(item->parent, name, rectFrom, rectTo, time, amt); + if( String_Parse( args, &name ) ) + { + if( Rect_Parse( args, &rectFrom ) && Rect_Parse( args, &rectTo ) && + Int_Parse( args, &time ) && Float_Parse( args, &amt ) ) + { + Menu_TransitionItemByName( item->parent, name, rectFrom, rectTo, time, amt ); } } } -void Menu_OrbitItemByName(menuDef_t *menu, const char *p, float x, float y, float cx, float cy, int time) { - itemDef_t *item; +void Menu_OrbitItemByName( menuDef_t *menu, const char *p, float x, float y, float cx, float cy, int time ) +{ + itemDef_t * item; int i; - int count = Menu_ItemsMatchingGroup(menu, p); - for (i = 0; i < count; i++) { - item = Menu_GetMatchingItemByNumber(menu, i, p); - if (item != NULL) { - item->window.flags |= (WINDOW_ORBITING | WINDOW_VISIBLE); + int count = Menu_ItemsMatchingGroup( menu, p ); + + for( i = 0; i < count; i++ ) + { + item = Menu_GetMatchingItemByNumber( menu, i, p ); + + if( item != NULL ) + { + item->window.flags |= ( WINDOW_ORBITING | WINDOW_VISIBLE ); item->window.offsetTime = time; item->window.rectEffects.x = cx; item->window.rectEffects.y = cy; item->window.rectClient.x = x; item->window.rectClient.y = y; - Item_UpdatePosition(item); + Item_UpdatePosition( item ); } } } -void Script_Orbit(itemDef_t *item, char **args) { - const char *name; +void Script_Orbit( itemDef_t *item, char **args ) +{ + const char * name; float cx, cy, x, y; int time; - if (String_Parse(args, &name)) { - if ( Float_Parse(args, &x) && Float_Parse(args, &y) && Float_Parse(args, &cx) && Float_Parse(args, &cy) && Int_Parse(args, &time) ) { - Menu_OrbitItemByName(item->parent, name, x, y, cx, cy, time); + if( String_Parse( args, &name ) ) + { + if( Float_Parse( args, &x ) && Float_Parse( args, &y ) && + Float_Parse( args, &cx ) && Float_Parse( args, &cy ) && Int_Parse( args, &time ) ) + { + Menu_OrbitItemByName( item->parent, name, x, y, cx, cy, time ); } } } -void Script_SetFocus(itemDef_t *item, char **args) { - const char *name; +void Script_SetFocus( itemDef_t *item, char **args ) +{ + const char * name; itemDef_t *focusItem; - if (String_Parse(args, &name)) { - focusItem = Menu_FindItemByName(item->parent, name); - if (focusItem && !(focusItem->window.flags & WINDOW_DECORATION)) { - Menu_ClearFocus(item->parent); + if( String_Parse( args, &name ) ) + { + focusItem = Menu_FindItemByName( item->parent, name ); + + if( focusItem && !( focusItem->window.flags & WINDOW_DECORATION ) ) + { + Menu_ClearFocus( item->parent ); focusItem->window.flags |= WINDOW_HASFOCUS; - if (focusItem->onFocus) { - Item_RunScript(focusItem, focusItem->onFocus); - } + + if( focusItem->onFocus ) + Item_RunScript( focusItem, focusItem->onFocus ); // Edit fields get activated too - if ( focusItem->type == ITEM_TYPE_EDITFIELD || focusItem->type == ITEM_TYPE_NUMERICFIELD) { + if( focusItem->type == ITEM_TYPE_EDITFIELD || focusItem->type == ITEM_TYPE_NUMERICFIELD ) + { g_editingField = qtrue; g_editItem = focusItem; } - if (DC->Assets.itemFocusSound) { + if( DC->Assets.itemFocusSound ) DC->startLocalSound( DC->Assets.itemFocusSound, CHAN_LOCAL_SOUND ); - } } } } void Script_Reset( itemDef_t *item, char **args ) { - const char *name; + const char * name; itemDef_t *resetItem; if( String_Parse( args, &name ) ) { resetItem = Menu_FindItemByName( item->parent, name ); + if( resetItem ) { if( resetItem->type == ITEM_TYPE_LISTBOX ) { - listBoxDef_t *listPtr = (listBoxDef_t*)resetItem->typeData; + listBoxDef_t * listPtr = ( listBoxDef_t* )resetItem->typeData; resetItem->cursorPos = 0; listPtr->startPos = 0; DC->feederSelection( resetItem->special, 0 ); @@ -1527,119 +1773,150 @@ void Script_Reset( itemDef_t *item, char **args ) } } -void Script_SetPlayerModel(itemDef_t *item, char **args) { - const char *name; - if (String_Parse(args, &name)) { - DC->setCVar("team_model", name); - } +void Script_SetPlayerModel( itemDef_t *item, char **args ) +{ + const char * name; + + if( String_Parse( args, &name ) ) + DC->setCVar( "team_model", name ); } -void Script_SetPlayerHead(itemDef_t *item, char **args) { - const char *name; - if (String_Parse(args, &name)) { - DC->setCVar("team_headmodel", name); - } +void Script_SetPlayerHead( itemDef_t *item, char **args ) +{ + const char * name; + + if( String_Parse( args, &name ) ) + DC->setCVar( "team_headmodel", name ); } -void Script_SetCvar(itemDef_t *item, char **args) { - const char *cvar, *val; - if (String_Parse(args, &cvar) && String_Parse(args, &val)) { - DC->setCVar(cvar, val); - } +void Script_SetCvar( itemDef_t *item, char **args ) +{ + const char * cvar, *val; + + if( String_Parse( args, &cvar ) && String_Parse( args, &val ) ) + DC->setCVar( cvar, val ); } -void Script_Exec(itemDef_t *item, char **args) { - const char *val; - if (String_Parse(args, &val)) { - DC->executeText(EXEC_APPEND, va("%s ; ", val)); - } +void Script_Exec( itemDef_t *item, char **args ) +{ + const char * val; + + if( String_Parse( args, &val ) ) + DC->executeText( EXEC_APPEND, va( "%s ; ", val ) ); } -void Script_Play(itemDef_t *item, char **args) { - const char *val; - if (String_Parse(args, &val)) { - DC->startLocalSound(DC->registerSound(val, qfalse), CHAN_LOCAL_SOUND); - } +void Script_Play( itemDef_t *item, char **args ) +{ + const char * val; + + if( String_Parse( args, &val ) ) + DC->startLocalSound( DC->registerSound( val, qfalse ), CHAN_LOCAL_SOUND ); } -void Script_playLooped(itemDef_t *item, char **args) { - const char *val; - if (String_Parse(args, &val)) { +void Script_playLooped( itemDef_t *item, char **args ) +{ + const char * val; + + if( String_Parse( args, &val ) ) + { DC->stopBackgroundTrack(); - DC->startBackgroundTrack(val, val); + DC->startBackgroundTrack( val, val ); } } -float UI_Text_Width(const char *text, float scale, int limit) { - int count,len; +float UI_Text_Width( const char *text, float scale, int limit ) +{ + int count, len; float out; glyphInfo_t *glyph; float useScale; const char *s = text; fontInfo_t *font = &DC->Assets.textFont; - if (scale <= DC->getCVarValue( "ui_smallFont" )) { + + if( scale <= DC->getCVarValue( "ui_smallFont" ) ) font = &DC->Assets.smallFont; - } else if (scale >= DC->getCVarValue( "ui_bigFont" )) { + else if( scale >= DC->getCVarValue( "ui_bigFont" ) ) font = &DC->Assets.bigFont; - } + useScale = scale * font->glyphScale; out = 0; - if (text) { + + if( text ) + { len = Q_PrintStrlen( text ); - if (limit > 0 && len > limit) { + + if( limit > 0 && len > limit ) len = limit; - } + count = 0; - while (s && *s && count < len) { - if ( Q_IsColorString(s) ) { + + while( s && *s && count < len ) + { + if( Q_IsColorString( s ) ) + { s += 2; continue; - } else { - glyph = &font->glyphs[(int)*s]; + } + else + { + glyph = &font->glyphs[( int )*s]; out += ( glyph->xSkip * DC->aspectScale ); s++; count++; } } } + return out * useScale; } -float UI_Text_Height(const char *text, float scale, int limit) { +float UI_Text_Height( const char *text, float scale, int limit ) +{ int len, count; float max; glyphInfo_t *glyph; float useScale; const char *s = text; fontInfo_t *font = &DC->Assets.textFont; - if (scale <= DC->getCVarValue( "ui_smallFont" )) { + + if( scale <= DC->getCVarValue( "ui_smallFont" ) ) font = &DC->Assets.smallFont; - } else if (scale >= DC->getCVarValue( "ui_bigFont" )) { + else if( scale >= DC->getCVarValue( "ui_bigFont" ) ) font = &DC->Assets.bigFont; - } + useScale = scale * font->glyphScale; max = 0; - if (text) { - len = strlen(text); - if (limit > 0 && len > limit) { + + if( text ) + { + len = strlen( text ); + + if( limit > 0 && len > limit ) len = limit; - } + count = 0; - while (s && *s && count < len) { - if ( Q_IsColorString(s) ) { + + while( s && *s && count < len ) + { + if( Q_IsColorString( s ) ) + { s += 2; continue; - } else { - glyph = &font->glyphs[(int)*s]; - if (max < glyph->height) { + } + else + { + glyph = &font->glyphs[( int )*s]; + + if( max < glyph->height ) max = glyph->height; - } + s++; count++; } } } + return max * useScale; } @@ -1657,18 +1934,21 @@ float UI_Text_EmHeight( float scale ) /* ================ UI_AdjustFrom640 - + Adjusted for resolution and screen aspect ratio ================ */ -void UI_AdjustFrom640( float *x, float *y, float *w, float *h ) { +void UI_AdjustFrom640( float *x, float *y, float *w, float *h ) +{ *x *= DC->xscale; *y *= DC->yscale; *w *= DC->xscale; *h *= DC->yscale; } -static void UI_Text_PaintChar(float x, float y, float width, float height, float scale, float s, float t, float s2, float t2, qhandle_t hShader) { +static void UI_Text_PaintChar( float x, float y, float width, float height, + float scale, float s, float t, float s2, float t2, qhandle_t hShader ) +{ float w, h; w = width * scale; h = height * scale; @@ -1685,7 +1965,7 @@ void UI_Text_Paint_Limit( float *maxX, float x, float y, float scale, if( text ) { - const char *s = text; + const char * s = text; float max = *maxX; float useScale; fontInfo_t *font = &DC->Assets.textFont; @@ -1696,7 +1976,9 @@ void UI_Text_Paint_Limit( float *maxX, float x, float y, float scale, font = &DC->Assets.bigFont; useScale = scale * font->glyphScale; + DC->setColor( color ); + len = strlen( text ); if( limit > 0 && len > limit ) @@ -1707,14 +1989,14 @@ void UI_Text_Paint_Limit( float *maxX, float x, float y, float scale, while( s && *s && count < len ) { float width, height, skip; - glyph = &font->glyphs[ (int)*s ]; + glyph = &font->glyphs[ ( int )*s ]; width = glyph->imageWidth * DC->aspectScale; height = glyph->imageHeight; skip = glyph->xSkip * DC->aspectScale; if( Q_IsColorString( s ) ) { - memcpy( newColor, g_color_table[ ColorIndex( *(s+1) ) ], sizeof( newColor ) ); + memcpy( newColor, g_color_table[ ColorIndex( *( s+1 ) ) ], sizeof( newColor ) ); newColor[ 3 ] = color[ 3 ]; DC->setColor( newColor ); s += 2; @@ -1750,55 +2032,68 @@ void UI_Text_Paint_Limit( float *maxX, float x, float y, float scale, } } -void UI_Text_Paint(float x, float y, float scale, vec4_t color, const char *text, float adjust, int limit, int style) { +void UI_Text_Paint( float x, float y, float scale, vec4_t color, const char *text, + float adjust, int limit, int style ) +{ int len, count; vec4_t newColor; glyphInfo_t *glyph; float useScale; fontInfo_t *font = &DC->Assets.textFont; - if (scale <= DC->getCVarValue( "ui_smallFont" )) { + + if( scale <= DC->getCVarValue( "ui_smallFont" ) ) font = &DC->Assets.smallFont; - } else if (scale >= DC->getCVarValue( "ui_bigFont" )) { + else if( scale >= DC->getCVarValue( "ui_bigFont" ) ) font = &DC->Assets.bigFont; - } + useScale = scale * font->glyphScale; - if (text) { - const char *s = text; + + if( text ) + { + const char * s = text; DC->setColor( color ); - memcpy(&newColor[0], &color[0], sizeof(vec4_t)); - len = strlen(text); - if (limit > 0 && len > limit) { + memcpy( &newColor[0], &color[0], sizeof( vec4_t ) ); + len = strlen( text ); + + if( limit > 0 && len > limit ) len = limit; - } + count = 0; - while (s && *s && count < len) { + + while( s && *s && count < len ) + { float width, height, skip; - glyph = &font->glyphs[(int)*s]; + glyph = &font->glyphs[( int )*s]; width = glyph->imageWidth * DC->aspectScale; height = glyph->imageHeight; skip = glyph->xSkip * DC->aspectScale; - if ( Q_IsColorString( s ) ) { - memcpy( newColor, g_color_table[ColorIndex(*(s+1))], sizeof( newColor ) ); + if( Q_IsColorString( s ) ) + { + memcpy( newColor, g_color_table[ColorIndex( *( s+1 ) )], sizeof( newColor ) ); newColor[3] = color[3]; DC->setColor( newColor ); s += 2; continue; - } else { + } + else + { float yadj = useScale * glyph->top; - if (style == ITEM_TEXTSTYLE_SHADOWED || style == ITEM_TEXTSTYLE_SHADOWEDMORE) { + + if( style == ITEM_TEXTSTYLE_SHADOWED || style == ITEM_TEXTSTYLE_SHADOWEDMORE ) + { int ofs = style == ITEM_TEXTSTYLE_SHADOWED ? 1 : 2; colorBlack[3] = newColor[3]; DC->setColor( colorBlack ); - UI_Text_PaintChar(x + ofs, y - yadj + ofs, - width, - height, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph); + UI_Text_PaintChar( x + ofs, y - yadj + ofs, + width, + height, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph ); DC->setColor( newColor ); colorBlack[3] = 1.0; } @@ -1825,108 +2120,119 @@ void UI_Text_Paint(float x, float y, float scale, vec4_t color, const char *text DC->setColor( glow ); UI_Text_PaintChar( x - 1.5, y - yadj - 1.5, - width + 3, - height + 3, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph ); + width + 3, + height + 3, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph ); DC->setColor( outer ); UI_Text_PaintChar( x - 1, y - yadj - 1, - width + 2, - height + 2, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph ); + width + 2, + height + 2, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph ); DC->setColor( inner ); UI_Text_PaintChar( x - 0.5, y - yadj - 0.5, - width + 1, - height + 1, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph ); + width + 1, + height + 1, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph ); DC->setColor( white ); } - UI_Text_PaintChar(x, y - yadj, - width, - height, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph); - - x += (skip * useScale) + adjust; + UI_Text_PaintChar( x, y - yadj, + width, + height, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph ); + + x += ( skip * useScale ) + adjust; s++; count++; } } + DC->setColor( NULL ); } } //FIXME: merge this with Text_Paint, somehow -void UI_Text_PaintWithCursor(float x, float y, float scale, vec4_t color, const char *text, int cursorPos, char cursor, int limit, int style) { +void UI_Text_PaintWithCursor( float x, float y, float scale, vec4_t color, const char *text, + int cursorPos, char cursor, int limit, int style ) +{ int len, count; vec4_t newColor; glyphInfo_t *glyph, *glyph2; float yadj; float useScale; fontInfo_t *font = &DC->Assets.textFont; - if (scale <= DC->getCVarValue( "ui_smallFont" )) { + + if( scale <= DC->getCVarValue( "ui_smallFont" ) ) font = &DC->Assets.smallFont; - } else if (scale >= DC->getCVarValue( "ui_bigFont" )) { + else if( scale >= DC->getCVarValue( "ui_bigFont" ) ) font = &DC->Assets.bigFont; - } + useScale = scale * font->glyphScale; - if (text) { + + if( text ) + { float width2, height2, skip2; const char *s = text; DC->setColor( color ); - memcpy(&newColor[0], &color[0], sizeof(vec4_t)); - len = strlen(text); - if (limit > 0 && len > limit) { + memcpy( &newColor[0], &color[0], sizeof( vec4_t ) ); + len = strlen( text ); + + if( limit > 0 && len > limit ) len = limit; - } + count = 0; - glyph2 = &font->glyphs[ (int) cursor]; + glyph2 = &font->glyphs[ ( int ) cursor]; width2 = glyph2->imageWidth * DC->aspectScale; height2 = glyph2->imageHeight; skip2 = glyph2->xSkip * DC->aspectScale; - while (s && *s && count < len) { + + while( s && *s && count < len ) + { float width, height, skip; - glyph = &font->glyphs[(int)*s]; + glyph = &font->glyphs[( int )*s]; width = glyph->imageWidth * DC->aspectScale; height = glyph->imageHeight; skip = glyph->xSkip * DC->aspectScale; yadj = useScale * glyph->top; - if (style == ITEM_TEXTSTYLE_SHADOWED || style == ITEM_TEXTSTYLE_SHADOWEDMORE) { + + if( style == ITEM_TEXTSTYLE_SHADOWED || style == ITEM_TEXTSTYLE_SHADOWEDMORE ) + { int ofs = style == ITEM_TEXTSTYLE_SHADOWED ? 1 : 2; colorBlack[3] = newColor[3]; DC->setColor( colorBlack ); - UI_Text_PaintChar(x + ofs, y - yadj + ofs, - width, - height, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph); + UI_Text_PaintChar( x + ofs, y - yadj + ofs, + width, + height, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph ); colorBlack[3] = 1.0; DC->setColor( newColor ); } @@ -1953,79 +2259,83 @@ void UI_Text_PaintWithCursor(float x, float y, float scale, vec4_t color, const DC->setColor( glow ); UI_Text_PaintChar( x - 1.5, y - yadj - 1.5, - width + 3, - height + 3, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph ); + width + 3, + height + 3, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph ); DC->setColor( outer ); UI_Text_PaintChar( x - 1, y - yadj - 1, - width + 2, - height + 2, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph ); + width + 2, + height + 2, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph ); DC->setColor( inner ); UI_Text_PaintChar( x - 0.5, y - yadj - 0.5, - width + 1, - height + 1, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph ); + width + 1, + height + 1, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph ); DC->setColor( white ); } - UI_Text_PaintChar(x, y - yadj, - width, - height, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph); + UI_Text_PaintChar( x, y - yadj, + width, + height, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph ); yadj = useScale * glyph2->top; - if (count == cursorPos && !((DC->realTime/BLINK_DIVISOR) & 1)) { - UI_Text_PaintChar(x, y - yadj, - width2, - height2, - useScale, - glyph2->s, - glyph2->t, - glyph2->s2, - glyph2->t2, - glyph2->glyph); + + if( count == cursorPos && !( ( DC->realTime / BLINK_DIVISOR ) & 1 ) ) + { + UI_Text_PaintChar( x, y - yadj, + width2, + height2, + useScale, + glyph2->s, + glyph2->t, + glyph2->s2, + glyph2->t2, + glyph2->glyph ); } - x += (skip * useScale); + x += ( skip * useScale ); s++; count++; } + // need to paint cursor at end of text - if (cursorPos == len && !((DC->realTime/BLINK_DIVISOR) & 1)) { - yadj = useScale * glyph2->top; - UI_Text_PaintChar(x, y - yadj, - width2, - height2, - useScale, - glyph2->s, - glyph2->t, - glyph2->s2, - glyph2->t2, - glyph2->glyph); + if( cursorPos == len && !( ( DC->realTime / BLINK_DIVISOR ) & 1 ) ) + { + yadj = useScale * glyph2->top; + UI_Text_PaintChar( x, y - yadj, + width2, + height2, + useScale, + glyph2->s, + glyph2->t, + glyph2->s2, + glyph2->t2, + glyph2->glyph ); } @@ -2034,168 +2344,197 @@ void UI_Text_PaintWithCursor(float x, float y, float scale, vec4_t color, const } commandDef_t commandList[] = + { + {"fadein", &Script_FadeIn}, // group/name + {"fadeout", &Script_FadeOut}, // group/name + {"show", &Script_Show}, // group/name + {"hide", &Script_Hide}, // group/name + {"setcolor", &Script_SetColor}, // works on this + {"open", &Script_Open}, // menu + {"conditionalopen", &Script_ConditionalOpen}, // menu + {"close", &Script_Close}, // menu + {"setasset", &Script_SetAsset}, // works on this + {"setbackground", &Script_SetBackground}, // works on this + {"setitemcolor", &Script_SetItemColor}, // group/name + {"setfocus", &Script_SetFocus}, // sets this background color to team color + {"reset", &Script_Reset}, // resets the state of the item argument + {"setplayermodel", &Script_SetPlayerModel}, // sets this background color to team color + {"setplayerhead", &Script_SetPlayerHead}, // sets this background color to team color + {"transition", &Script_Transition}, // group/name + {"setcvar", &Script_SetCvar}, // group/name + {"exec", &Script_Exec}, // group/name + {"play", &Script_Play}, // group/name + {"playlooped", &Script_playLooped}, // group/name + {"orbit", &Script_Orbit} // group/name + }; + +int scriptCommandCount = sizeof( commandList ) / sizeof( commandDef_t ); + + +void Item_RunScript( itemDef_t *item, const char *s ) { - {"fadein", &Script_FadeIn}, // group/name - {"fadeout", &Script_FadeOut}, // group/name - {"show", &Script_Show}, // group/name - {"hide", &Script_Hide}, // group/name - {"setcolor", &Script_SetColor}, // works on this - {"open", &Script_Open}, // menu - {"conditionalopen", &Script_ConditionalOpen}, // menu - {"close", &Script_Close}, // menu - {"setasset", &Script_SetAsset}, // works on this - {"setbackground", &Script_SetBackground}, // works on this - {"setitemcolor", &Script_SetItemColor}, // group/name - {"setfocus", &Script_SetFocus}, // sets this background color to team color - {"reset", &Script_Reset}, // resets the state of the item argument - {"setplayermodel", &Script_SetPlayerModel}, // sets this background color to team color - {"setplayerhead", &Script_SetPlayerHead}, // sets this background color to team color - {"transition", &Script_Transition}, // group/name - {"setcvar", &Script_SetCvar}, // group/name - {"exec", &Script_Exec}, // group/name - {"play", &Script_Play}, // group/name - {"playlooped", &Script_playLooped}, // group/name - {"orbit", &Script_Orbit} // group/name -}; - -int scriptCommandCount = sizeof(commandList) / sizeof(commandDef_t); - - -void Item_RunScript(itemDef_t *item, const char *s) { char script[1024], *p; int i; qboolean bRan; - memset(script, 0, sizeof(script)); - if (item && s && s[0]) { - Q_strcat(script, 1024, s); + memset( script, 0, sizeof( script ) ); + + if( item && s && s[0] ) + { + Q_strcat( script, 1024, s ); p = script; - while (1) { - const char *command; + + while( 1 ) + { + const char * command; // expect command then arguments, ; ends command, NULL ends script - if (!String_Parse(&p, &command)) { + + if( !String_Parse( &p, &command ) ) return; - } - if (command[0] == ';' && command[1] == '\0') { + if( command[0] == ';' && command[1] == '\0' ) continue; - } bRan = qfalse; - for (i = 0; i < scriptCommandCount; i++) { - if (Q_stricmp(command, commandList[i].name) == 0) { - (commandList[i].handler(item, &p)); + + for( i = 0; i < scriptCommandCount; i++ ) + { + if( Q_stricmp( command, commandList[i].name ) == 0 ) + { + ( commandList[i].handler( item, &p ) ); bRan = qtrue; break; } } + // not in our auto list, pass to handler - if (!bRan) { - DC->runScript(&p); - } + if( !bRan ) + DC->runScript( &p ); } } } -qboolean Item_EnableShowViaCvar(itemDef_t *item, int flag) { +qboolean Item_EnableShowViaCvar( itemDef_t *item, int flag ) +{ char script[1024], *p; - memset(script, 0, sizeof(script)); - if (item && item->enableCvar && *item->enableCvar && item->cvarTest && *item->cvarTest) { + memset( script, 0, sizeof( script ) ); + + if( item && item->enableCvar && *item->enableCvar && item->cvarTest && *item->cvarTest ) + { char buff[1024]; - DC->getCVarString(item->cvarTest, buff, sizeof(buff)); + DC->getCVarString( item->cvarTest, buff, sizeof( buff ) ); - Q_strcat(script, 1024, item->enableCvar); + Q_strcat( script, 1024, item->enableCvar ); p = script; - while (1) { - const char *val; + + while( 1 ) + { + const char * val; // expect value then ; or NULL, NULL ends list - if (!String_Parse(&p, &val)) { - return (item->cvarFlags & flag) ? qfalse : qtrue; - } - if (val[0] == ';' && val[1] == '\0') { + if( !String_Parse( &p, &val ) ) + return ( item->cvarFlags & flag ) ? qfalse : qtrue; + + if( val[0] == ';' && val[1] == '\0' ) continue; - } // enable it if any of the values are true - if (item->cvarFlags & flag) { - if (Q_stricmp(buff, val) == 0) { + if( item->cvarFlags & flag ) + { + if( Q_stricmp( buff, val ) == 0 ) return qtrue; - } - } else { + } + else + { // disable it if any of the values are true - if (Q_stricmp(buff, val) == 0) { + + if( Q_stricmp( buff, val ) == 0 ) return qfalse; - } } } - return (item->cvarFlags & flag) ? qfalse : qtrue; + + return ( item->cvarFlags & flag ) ? qfalse : qtrue; } + return qtrue; } // will optionaly set focus to this item -qboolean Item_SetFocus(itemDef_t *item, float x, float y) { +qboolean Item_SetFocus( itemDef_t *item, float x, float y ) +{ int i; itemDef_t *oldFocus; sfxHandle_t *sfx = &DC->Assets.itemFocusSound; qboolean playSound = qfalse; menuDef_t *parent; // sanity check, non-null, not a decoration and does not already have the focus - if (item == NULL || item->window.flags & WINDOW_DECORATION || item->window.flags & WINDOW_HASFOCUS || !(item->window.flags & WINDOW_VISIBLE)) { + + if( item == NULL || item->window.flags & WINDOW_DECORATION || + item->window.flags & WINDOW_HASFOCUS || !( item->window.flags & WINDOW_VISIBLE ) ) + { return qfalse; } - parent = (menuDef_t*)item->parent; + parent = ( menuDef_t* )item->parent; // items can be enabled and disabled based on cvars - if (item->cvarFlags & (CVAR_ENABLE | CVAR_DISABLE) && !Item_EnableShowViaCvar(item, CVAR_ENABLE)) { + + if( item->cvarFlags & ( CVAR_ENABLE | CVAR_DISABLE ) && !Item_EnableShowViaCvar( item, CVAR_ENABLE ) ) return qfalse; - } - if (item->cvarFlags & (CVAR_SHOW | CVAR_HIDE) && !Item_EnableShowViaCvar(item, CVAR_SHOW)) { + if( item->cvarFlags & ( CVAR_SHOW | CVAR_HIDE ) && !Item_EnableShowViaCvar( item, CVAR_SHOW ) ) return qfalse; - } - oldFocus = Menu_ClearFocus(item->parent); + oldFocus = Menu_ClearFocus( item->parent ); - if (item->type == ITEM_TYPE_TEXT) { + if( item->type == ITEM_TYPE_TEXT ) + { rectDef_t r; r = item->textRect; r.y -= r.h; - if (Rect_ContainsPoint(&r, x, y)) { + + if( Rect_ContainsPoint( &r, x, y ) ) + { item->window.flags |= WINDOW_HASFOCUS; - if (item->focusSound) { + + if( item->focusSound ) sfx = &item->focusSound; - } + playSound = qtrue; - } else { - if (oldFocus) { + } + else + { + if( oldFocus ) + { oldFocus->window.flags |= WINDOW_HASFOCUS; - if (oldFocus->onFocus) { - Item_RunScript(oldFocus, oldFocus->onFocus); - } + + if( oldFocus->onFocus ) + Item_RunScript( oldFocus, oldFocus->onFocus ); } } - } else { - item->window.flags |= WINDOW_HASFOCUS; - if (item->onFocus) { - Item_RunScript(item, item->onFocus); - } - if (item->focusSound) { + } + else + { + item->window.flags |= WINDOW_HASFOCUS; + + if( item->onFocus ) + Item_RunScript( item, item->onFocus ); + + if( item->focusSound ) sfx = &item->focusSound; - } + playSound = qtrue; } - if (playSound && sfx) { + if( playSound && sfx ) DC->startLocalSound( *sfx, CHAN_LOCAL_SOUND ); - } - for (i = 0; i < parent->itemCount; i++) { - if (parent->items[i] == item) { + for( i = 0; i < parent->itemCount; i++ ) + { + if( parent->items[i] == item ) + { parent->cursorItem = i; break; } @@ -2204,101 +2543,106 @@ qboolean Item_SetFocus(itemDef_t *item, float x, float y) { return qtrue; } -int Item_ListBox_MaxScroll(itemDef_t *item) { - listBoxDef_t *listPtr = (listBoxDef_t*)item->typeData; - int count = DC->feederCount(item->special); +int Item_ListBox_MaxScroll( itemDef_t *item ) +{ + listBoxDef_t * listPtr = ( listBoxDef_t* )item->typeData; + int count = DC->feederCount( item->special ); int max; - if (item->window.flags & WINDOW_HORIZONTAL) { - max = count - (item->window.rect.w / listPtr->elementWidth) + 1; - } - else { - max = count - (item->window.rect.h / listPtr->elementHeight) + 1; - } - if (max < 0) { + if( item->window.flags & WINDOW_HORIZONTAL ) + max = count - ( item->window.rect.w / listPtr->elementWidth ) + 1; + else + max = count - ( item->window.rect.h / listPtr->elementHeight ) + 1; + + if( max < 0 ) return 0; - } + return max; } -int Item_ListBox_ThumbPosition(itemDef_t *item) { +int Item_ListBox_ThumbPosition( itemDef_t *item ) +{ float max, pos, size; - listBoxDef_t *listPtr = (listBoxDef_t*)item->typeData; - - max = Item_ListBox_MaxScroll(item); - if (item->window.flags & WINDOW_HORIZONTAL) { - size = item->window.rect.w - (SCROLLBAR_WIDTH * 2) - 2; - if (max > 0) { - pos = (size-SCROLLBAR_WIDTH) / (float) max; - } else { + listBoxDef_t *listPtr = ( listBoxDef_t* )item->typeData; + + max = Item_ListBox_MaxScroll( item ); + + if( item->window.flags & WINDOW_HORIZONTAL ) + { + size = item->window.rect.w - ( SCROLLBAR_WIDTH * 2 ) - 2; + + if( max > 0 ) + pos = ( size - SCROLLBAR_WIDTH ) / ( float ) max; + else pos = 0; - } + pos *= listPtr->startPos; return item->window.rect.x + 1 + SCROLLBAR_WIDTH + pos; } - else { - size = item->window.rect.h - (SCROLLBAR_HEIGHT * 2) - 2; - if (max > 0) { - pos = (size-SCROLLBAR_HEIGHT) / (float) max; - } else { + else + { + size = item->window.rect.h - ( SCROLLBAR_HEIGHT * 2 ) - 2; + + if( max > 0 ) + pos = ( size - SCROLLBAR_HEIGHT ) / ( float ) max; + else pos = 0; - } + pos *= listPtr->startPos; return item->window.rect.y + 1 + SCROLLBAR_HEIGHT + pos; } } -int Item_ListBox_ThumbDrawPosition(itemDef_t *item) { +int Item_ListBox_ThumbDrawPosition( itemDef_t *item ) +{ int min, max; - if (itemCapture == item) { - if (item->window.flags & WINDOW_HORIZONTAL) { + if( itemCapture == item ) + { + if( item->window.flags & WINDOW_HORIZONTAL ) + { min = item->window.rect.x + SCROLLBAR_WIDTH + 1; - max = item->window.rect.x + item->window.rect.w - 2*SCROLLBAR_WIDTH - 1; - if (DC->cursorx >= min + SCROLLBAR_WIDTH/2 && DC->cursorx <= max + SCROLLBAR_WIDTH/2) { - return DC->cursorx - SCROLLBAR_WIDTH/2; - } - else { - return Item_ListBox_ThumbPosition(item); - } + max = item->window.rect.x + item->window.rect.w - 2 * SCROLLBAR_WIDTH - 1; + + if( DC->cursorx >= min + SCROLLBAR_WIDTH / 2 && DC->cursorx <= max + SCROLLBAR_WIDTH / 2 ) + return DC->cursorx - SCROLLBAR_WIDTH / 2; + else + return Item_ListBox_ThumbPosition( item ); } - else { + else + { min = item->window.rect.y + SCROLLBAR_HEIGHT + 1; - max = item->window.rect.y + item->window.rect.h - 2*SCROLLBAR_HEIGHT - 1; - if (DC->cursory >= min + SCROLLBAR_HEIGHT/2 && DC->cursory <= max + SCROLLBAR_HEIGHT/2) { - return DC->cursory - SCROLLBAR_HEIGHT/2; - } - else { - return Item_ListBox_ThumbPosition(item); - } + max = item->window.rect.y + item->window.rect.h - 2 * SCROLLBAR_HEIGHT - 1; + + if( DC->cursory >= min + SCROLLBAR_HEIGHT / 2 && DC->cursory <= max + SCROLLBAR_HEIGHT / 2 ) + return DC->cursory - SCROLLBAR_HEIGHT / 2; + else + return Item_ListBox_ThumbPosition( item ); } } - else { - return Item_ListBox_ThumbPosition(item); - } + else + return Item_ListBox_ThumbPosition( item ); } -float Item_Slider_ThumbPosition(itemDef_t *item) { +float Item_Slider_ThumbPosition( itemDef_t *item ) +{ float value, range, x; editFieldDef_t *editDef = item->typeData; - if (item->text) { + if( item->text ) x = item->textRect.x + item->textRect.w + ITEM_VALUE_OFFSET; - } else { + else x = item->window.rect.x; - } - if (editDef == NULL && item->cvar) { + if( editDef == NULL && item->cvar ) return x; - } - value = DC->getCVarValue(item->cvar); + value = DC->getCVarValue( item->cvar ); - if (value < editDef->minVal) { + if( value < editDef->minVal ) value = editDef->minVal; - } else if (value > editDef->maxVal) { + else if( value > editDef->maxVal ) value = editDef->maxVal; - } range = editDef->maxVal - editDef->minVal; value -= editDef->minVal; @@ -2317,375 +2661,474 @@ static float Item_Slider_VScale( itemDef_t *item ) return 1.0f; } -int Item_Slider_OverSlider(itemDef_t *item, float x, float y) { +int Item_Slider_OverSlider( itemDef_t *item, float x, float y ) +{ rectDef_t r; float vScale = Item_Slider_VScale( item ); - r.x = Item_Slider_ThumbPosition(item) - (SLIDER_THUMB_WIDTH / 2); + r.x = Item_Slider_ThumbPosition( item ) - ( SLIDER_THUMB_WIDTH / 2 ); r.y = item->textRect.y - item->textRect.h + - ( ( item->textRect.h - ( SLIDER_THUMB_HEIGHT * vScale ) ) / 2.0f ); + ( ( item->textRect.h - ( SLIDER_THUMB_HEIGHT * vScale ) ) / 2.0f ); r.w = SLIDER_THUMB_WIDTH; r.h = SLIDER_THUMB_HEIGHT * vScale; - if (Rect_ContainsPoint(&r, x, y)) { + if( Rect_ContainsPoint( &r, x, y ) ) return WINDOW_LB_THUMB; - } + return 0; } -int Item_ListBox_OverLB(itemDef_t *item, float x, float y) { +int Item_ListBox_OverLB( itemDef_t *item, float x, float y ) +{ rectDef_t r; listBoxDef_t *listPtr; int thumbstart; int count; - count = DC->feederCount(item->special); - listPtr = (listBoxDef_t*)item->typeData; - if (item->window.flags & WINDOW_HORIZONTAL) { + count = DC->feederCount( item->special ); + listPtr = ( listBoxDef_t* )item->typeData; + + if( item->window.flags & WINDOW_HORIZONTAL ) + { // check if on left arrow r.x = item->window.rect.x; r.y = item->window.rect.y + item->window.rect.h - SCROLLBAR_HEIGHT; r.w = SCROLLBAR_WIDTH; r.h = SCROLLBAR_HEIGHT; - if (Rect_ContainsPoint(&r, x, y)) { + + if( Rect_ContainsPoint( &r, x, y ) ) return WINDOW_LB_LEFTARROW; - } + // check if on right arrow r.x = item->window.rect.x + item->window.rect.w - SCROLLBAR_WIDTH; - if (Rect_ContainsPoint(&r, x, y)) { + + if( Rect_ContainsPoint( &r, x, y ) ) return WINDOW_LB_RIGHTARROW; - } + // check if on thumb - thumbstart = Item_ListBox_ThumbPosition(item); + thumbstart = Item_ListBox_ThumbPosition( item ); + r.x = thumbstart; - if (Rect_ContainsPoint(&r, x, y)) { + + if( Rect_ContainsPoint( &r, x, y ) ) return WINDOW_LB_THUMB; - } + r.x = item->window.rect.x + SCROLLBAR_WIDTH; r.w = thumbstart - r.x; - if (Rect_ContainsPoint(&r, x, y)) { + + if( Rect_ContainsPoint( &r, x, y ) ) return WINDOW_LB_PGUP; - } + r.x = thumbstart + SCROLLBAR_WIDTH; r.w = item->window.rect.x + item->window.rect.w - SCROLLBAR_WIDTH; - if (Rect_ContainsPoint(&r, x, y)) { + + if( Rect_ContainsPoint( &r, x, y ) ) return WINDOW_LB_PGDN; - } - } else { + } + else + { r.x = item->window.rect.x + item->window.rect.w - SCROLLBAR_WIDTH; r.y = item->window.rect.y; r.w = SCROLLBAR_WIDTH; r.h = SCROLLBAR_HEIGHT; - if (Rect_ContainsPoint(&r, x, y)) { + + if( Rect_ContainsPoint( &r, x, y ) ) return WINDOW_LB_LEFTARROW; - } + r.y = item->window.rect.y + item->window.rect.h - SCROLLBAR_HEIGHT; - if (Rect_ContainsPoint(&r, x, y)) { + + if( Rect_ContainsPoint( &r, x, y ) ) return WINDOW_LB_RIGHTARROW; - } - thumbstart = Item_ListBox_ThumbPosition(item); + + thumbstart = Item_ListBox_ThumbPosition( item ); r.y = thumbstart; - if (Rect_ContainsPoint(&r, x, y)) { + + if( Rect_ContainsPoint( &r, x, y ) ) return WINDOW_LB_THUMB; - } + r.y = item->window.rect.y + SCROLLBAR_HEIGHT; r.h = thumbstart - r.y; - if (Rect_ContainsPoint(&r, x, y)) { + + if( Rect_ContainsPoint( &r, x, y ) ) return WINDOW_LB_PGUP; - } + r.y = thumbstart + SCROLLBAR_HEIGHT; r.h = item->window.rect.y + item->window.rect.h - SCROLLBAR_HEIGHT; - if (Rect_ContainsPoint(&r, x, y)) { + + if( Rect_ContainsPoint( &r, x, y ) ) return WINDOW_LB_PGDN; - } } + return 0; } -void Item_ListBox_MouseEnter(itemDef_t *item, float x, float y) +void Item_ListBox_MouseEnter( itemDef_t *item, float x, float y ) { rectDef_t r; - listBoxDef_t *listPtr = (listBoxDef_t*)item->typeData; + listBoxDef_t *listPtr = ( listBoxDef_t* )item->typeData; - item->window.flags &= ~(WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW | WINDOW_LB_THUMB | WINDOW_LB_PGUP | WINDOW_LB_PGDN); - item->window.flags |= Item_ListBox_OverLB(item, x, y); + item->window.flags &= ~( WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW | WINDOW_LB_THUMB | + WINDOW_LB_PGUP | WINDOW_LB_PGDN ); + item->window.flags |= Item_ListBox_OverLB( item, x, y ); - if (item->window.flags & WINDOW_HORIZONTAL) { - if (!(item->window.flags & (WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW | WINDOW_LB_THUMB | WINDOW_LB_PGUP | WINDOW_LB_PGDN))) { + if( item->window.flags & WINDOW_HORIZONTAL ) + { + if( !( item->window.flags & ( WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW | WINDOW_LB_THUMB | + WINDOW_LB_PGUP | WINDOW_LB_PGDN ) ) ) + { // check for selection hit as we have exausted buttons and thumb - if (listPtr->elementStyle == LISTBOX_IMAGE) { + + if( listPtr->elementStyle == LISTBOX_IMAGE ) + { r.x = item->window.rect.x; r.y = item->window.rect.y; r.h = item->window.rect.h - SCROLLBAR_HEIGHT; r.w = item->window.rect.w - listPtr->drawPadding; - if (Rect_ContainsPoint(&r, x, y)) { - listPtr->cursorPos = (int)((x - r.x) / listPtr->elementWidth) + listPtr->startPos; - if (listPtr->cursorPos >= listPtr->endPos) { + + if( Rect_ContainsPoint( &r, x, y ) ) + { + listPtr->cursorPos = ( int )( ( x - r.x ) / listPtr->elementWidth ) + listPtr->startPos; + + if( listPtr->cursorPos >= listPtr->endPos ) listPtr->cursorPos = listPtr->endPos; - } } - } else { - // text hit.. } } - } else if (!(item->window.flags & (WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW | WINDOW_LB_THUMB | WINDOW_LB_PGUP | WINDOW_LB_PGDN))) { + } + else if( !( item->window.flags & ( WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW | + WINDOW_LB_THUMB | WINDOW_LB_PGUP | WINDOW_LB_PGDN ) ) ) + { r.x = item->window.rect.x; r.y = item->window.rect.y; r.w = item->window.rect.w - SCROLLBAR_WIDTH; r.h = item->window.rect.h - listPtr->drawPadding; - if (Rect_ContainsPoint(&r, x, y)) { - listPtr->cursorPos = (int)((y - 2 - r.y) / listPtr->elementHeight) + listPtr->startPos; - if (listPtr->cursorPos > listPtr->endPos) { + + if( Rect_ContainsPoint( &r, x, y ) ) + { + listPtr->cursorPos = ( int )( ( y - 2 - r.y ) / listPtr->elementHeight ) + listPtr->startPos; + + if( listPtr->cursorPos > listPtr->endPos ) listPtr->cursorPos = listPtr->endPos; - } } } } -void Item_MouseEnter(itemDef_t *item, float x, float y) { +void Item_MouseEnter( itemDef_t *item, float x, float y ) +{ rectDef_t r; - if (item) { + + if( item ) + { r = item->textRect; r.y -= r.h; // in the text rect? // items can be enabled and disabled based on cvars - if (item->cvarFlags & (CVAR_ENABLE | CVAR_DISABLE) && !Item_EnableShowViaCvar(item, CVAR_ENABLE)) { + + if( item->cvarFlags & ( CVAR_ENABLE | CVAR_DISABLE ) && !Item_EnableShowViaCvar( item, CVAR_ENABLE ) ) return; - } - if (item->cvarFlags & (CVAR_SHOW | CVAR_HIDE) && !Item_EnableShowViaCvar(item, CVAR_SHOW)) { + if( item->cvarFlags & ( CVAR_SHOW | CVAR_HIDE ) && !Item_EnableShowViaCvar( item, CVAR_SHOW ) ) return; - } - if (Rect_ContainsPoint(&r, x, y)) { - if (!(item->window.flags & WINDOW_MOUSEOVERTEXT)) { - Item_RunScript(item, item->mouseEnterText); + if( Rect_ContainsPoint( &r, x, y ) ) + { + if( !( item->window.flags & WINDOW_MOUSEOVERTEXT ) ) + { + Item_RunScript( item, item->mouseEnterText ); item->window.flags |= WINDOW_MOUSEOVERTEXT; } - if (!(item->window.flags & WINDOW_MOUSEOVER)) { - Item_RunScript(item, item->mouseEnter); + + if( !( item->window.flags & WINDOW_MOUSEOVER ) ) + { + Item_RunScript( item, item->mouseEnter ); item->window.flags |= WINDOW_MOUSEOVER; } - } else { + } + else + { // not in the text rect - if (item->window.flags & WINDOW_MOUSEOVERTEXT) { + + if( item->window.flags & WINDOW_MOUSEOVERTEXT ) + { // if we were - Item_RunScript(item, item->mouseExitText); + Item_RunScript( item, item->mouseExitText ); item->window.flags &= ~WINDOW_MOUSEOVERTEXT; } - if (!(item->window.flags & WINDOW_MOUSEOVER)) { - Item_RunScript(item, item->mouseEnter); + + if( !( item->window.flags & WINDOW_MOUSEOVER ) ) + { + Item_RunScript( item, item->mouseEnter ); item->window.flags |= WINDOW_MOUSEOVER; } - if (item->type == ITEM_TYPE_LISTBOX) { - Item_ListBox_MouseEnter(item, x, y); - } + if( item->type == ITEM_TYPE_LISTBOX ) + Item_ListBox_MouseEnter( item, x, y ); } } } -void Item_MouseLeave(itemDef_t *item) { - if (item) { - if (item->window.flags & WINDOW_MOUSEOVERTEXT) { - Item_RunScript(item, item->mouseExitText); +void Item_MouseLeave( itemDef_t *item ) +{ + if( item ) + { + if( item->window.flags & WINDOW_MOUSEOVERTEXT ) + { + Item_RunScript( item, item->mouseExitText ); item->window.flags &= ~WINDOW_MOUSEOVERTEXT; } - Item_RunScript(item, item->mouseExit); - item->window.flags &= ~(WINDOW_LB_RIGHTARROW | WINDOW_LB_LEFTARROW); + + Item_RunScript( item, item->mouseExit ); + item->window.flags &= ~( WINDOW_LB_RIGHTARROW | WINDOW_LB_LEFTARROW ); } } -itemDef_t *Menu_HitTest(menuDef_t *menu, float x, float y) { +itemDef_t *Menu_HitTest( menuDef_t *menu, float x, float y ) +{ int i; - for (i = 0; i < menu->itemCount; i++) { - if (Rect_ContainsPoint(&menu->items[i]->window.rect, x, y)) { + + for( i = 0; i < menu->itemCount; i++ ) + { + if( Rect_ContainsPoint( &menu->items[i]->window.rect, x, y ) ) return menu->items[i]; - } } + return NULL; } -void Item_SetMouseOver(itemDef_t *item, qboolean focus) { - if (item) { - if (focus) { +void Item_SetMouseOver( itemDef_t *item, qboolean focus ) +{ + if( item ) + { + if( focus ) item->window.flags |= WINDOW_MOUSEOVER; - } else { + else item->window.flags &= ~WINDOW_MOUSEOVER; - } } } -qboolean Item_OwnerDraw_HandleKey(itemDef_t *item, int key) { - if (item && DC->ownerDrawHandleKey) { - return DC->ownerDrawHandleKey(item->window.ownerDraw, item->window.ownerDrawFlags, &item->special, key); - } +qboolean Item_OwnerDraw_HandleKey( itemDef_t *item, int key ) +{ + if( item && DC->ownerDrawHandleKey ) + return DC->ownerDrawHandleKey( item->window.ownerDraw, item->window.ownerDrawFlags, &item->special, key ); + return qfalse; } -qboolean Item_ListBox_HandleKey(itemDef_t *item, int key, qboolean down, qboolean force) { - listBoxDef_t *listPtr = (listBoxDef_t*)item->typeData; - int count = DC->feederCount(item->special); +qboolean Item_ListBox_HandleKey( itemDef_t *item, int key, qboolean down, qboolean force ) +{ + listBoxDef_t * listPtr = ( listBoxDef_t* )item->typeData; + int count = DC->feederCount( item->special ); int max, viewmax; - if (force || (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory) && item->window.flags & WINDOW_HASFOCUS)) { - max = Item_ListBox_MaxScroll(item); - if (item->window.flags & WINDOW_HORIZONTAL) { - viewmax = (item->window.rect.w / listPtr->elementWidth); - if ( key == K_LEFTARROW || key == K_KP_LEFTARROW ) + if( force || ( Rect_ContainsPoint( &item->window.rect, DC->cursorx, DC->cursory ) && + item->window.flags & WINDOW_HASFOCUS ) ) + { + max = Item_ListBox_MaxScroll( item ); + + if( item->window.flags & WINDOW_HORIZONTAL ) + { + viewmax = ( item->window.rect.w / listPtr->elementWidth ); + + if( key == K_LEFTARROW || key == K_KP_LEFTARROW ) { - if (!listPtr->notselectable) { + if( !listPtr->notselectable ) + { listPtr->cursorPos--; - if (listPtr->cursorPos < 0) { + + if( listPtr->cursorPos < 0 ) listPtr->cursorPos = 0; - } - if (listPtr->cursorPos < listPtr->startPos) { + + if( listPtr->cursorPos < listPtr->startPos ) listPtr->startPos = listPtr->cursorPos; - } - if (listPtr->cursorPos >= listPtr->startPos + viewmax) { + + if( listPtr->cursorPos >= listPtr->startPos + viewmax ) listPtr->startPos = listPtr->cursorPos - viewmax + 1; - } + item->cursorPos = listPtr->cursorPos; - DC->feederSelection(item->special, item->cursorPos); + DC->feederSelection( item->special, item->cursorPos ); } - else { + else + { listPtr->startPos--; - if (listPtr->startPos < 0) + + if( listPtr->startPos < 0 ) listPtr->startPos = 0; } + return qtrue; } - if ( key == K_RIGHTARROW || key == K_KP_RIGHTARROW ) + + if( key == K_RIGHTARROW || key == K_KP_RIGHTARROW ) { - if (!listPtr->notselectable) { + if( !listPtr->notselectable ) + { listPtr->cursorPos++; - if (listPtr->cursorPos < listPtr->startPos) { + + if( listPtr->cursorPos < listPtr->startPos ) listPtr->startPos = listPtr->cursorPos; - } - if (listPtr->cursorPos >= count) { - listPtr->cursorPos = count-1; - } - if (listPtr->cursorPos >= listPtr->startPos + viewmax) { + + if( listPtr->cursorPos >= count ) + listPtr->cursorPos = count - 1; + + if( listPtr->cursorPos >= listPtr->startPos + viewmax ) listPtr->startPos = listPtr->cursorPos - viewmax + 1; - } + item->cursorPos = listPtr->cursorPos; - DC->feederSelection(item->special, item->cursorPos); + DC->feederSelection( item->special, item->cursorPos ); } - else { + else + { listPtr->startPos++; - if (listPtr->startPos >= count) - listPtr->startPos = count-1; + + if( listPtr->startPos >= count ) + listPtr->startPos = count - 1; } + return qtrue; } } - else { - viewmax = (item->window.rect.h / listPtr->elementHeight); - if ( key == K_UPARROW || key == K_KP_UPARROW ) + else + { + viewmax = ( item->window.rect.h / listPtr->elementHeight ); + + if( key == K_UPARROW || key == K_KP_UPARROW ) { - if (!listPtr->notselectable) { + if( !listPtr->notselectable ) + { listPtr->cursorPos--; - if (listPtr->cursorPos < 0) { + + if( listPtr->cursorPos < 0 ) listPtr->cursorPos = 0; - } - if (listPtr->cursorPos < listPtr->startPos) { + + if( listPtr->cursorPos < listPtr->startPos ) listPtr->startPos = listPtr->cursorPos; - } - if (listPtr->cursorPos >= listPtr->startPos + viewmax) { + + if( listPtr->cursorPos >= listPtr->startPos + viewmax ) listPtr->startPos = listPtr->cursorPos - viewmax + 1; - } + item->cursorPos = listPtr->cursorPos; - DC->feederSelection(item->special, item->cursorPos); + DC->feederSelection( item->special, item->cursorPos ); } - else { + else + { listPtr->startPos--; - if (listPtr->startPos < 0) + + if( listPtr->startPos < 0 ) listPtr->startPos = 0; } + return qtrue; } - if ( key == K_DOWNARROW || key == K_KP_DOWNARROW ) + + if( key == K_DOWNARROW || key == K_KP_DOWNARROW ) { - if (!listPtr->notselectable) { + if( !listPtr->notselectable ) + { listPtr->cursorPos++; - if (listPtr->cursorPos < listPtr->startPos) { + + if( listPtr->cursorPos < listPtr->startPos ) listPtr->startPos = listPtr->cursorPos; - } - if (listPtr->cursorPos >= count) { - listPtr->cursorPos = count-1; - } - if (listPtr->cursorPos >= listPtr->startPos + viewmax) { + + if( listPtr->cursorPos >= count ) + listPtr->cursorPos = count - 1; + + if( listPtr->cursorPos >= listPtr->startPos + viewmax ) listPtr->startPos = listPtr->cursorPos - viewmax + 1; - } + item->cursorPos = listPtr->cursorPos; - DC->feederSelection(item->special, item->cursorPos); + DC->feederSelection( item->special, item->cursorPos ); } - else { + else + { listPtr->startPos++; - if (listPtr->startPos > max) + + if( listPtr->startPos > max ) listPtr->startPos = max; } + return qtrue; } } + // mouse hit - if (key == K_MOUSE1 || key == K_MOUSE2) { - if (item->window.flags & WINDOW_LB_LEFTARROW) { + if( key == K_MOUSE1 || key == K_MOUSE2 ) + { + if( item->window.flags & WINDOW_LB_LEFTARROW ) + { listPtr->startPos--; - if (listPtr->startPos < 0) { + + if( listPtr->startPos < 0 ) listPtr->startPos = 0; - } - } else if (item->window.flags & WINDOW_LB_RIGHTARROW) { + } + else if( item->window.flags & WINDOW_LB_RIGHTARROW ) + { // one down listPtr->startPos++; - if (listPtr->startPos > max) { + + if( listPtr->startPos > max ) listPtr->startPos = max; - } - } else if (item->window.flags & WINDOW_LB_PGUP) { + } + else if( item->window.flags & WINDOW_LB_PGUP ) + { // page up listPtr->startPos -= viewmax; - if (listPtr->startPos < 0) { + + if( listPtr->startPos < 0 ) listPtr->startPos = 0; - } - } else if (item->window.flags & WINDOW_LB_PGDN) { + } + else if( item->window.flags & WINDOW_LB_PGDN ) + { // page down listPtr->startPos += viewmax; - if (listPtr->startPos > max) { + + if( listPtr->startPos > max ) listPtr->startPos = max; - } - } else if (item->window.flags & WINDOW_LB_THUMB) { + } + else if( item->window.flags & WINDOW_LB_THUMB ) + { // Display_SetCaptureItem(item); - } else { + } + else + { // select an item - if (item->cursorPos != listPtr->cursorPos) { + + if( item->cursorPos != listPtr->cursorPos ) + { item->cursorPos = listPtr->cursorPos; - DC->feederSelection(item->special, item->cursorPos); - } - if (DC->realTime < lastListBoxClickTime && listPtr->doubleClick) { - Item_RunScript(item, listPtr->doubleClick); + DC->feederSelection( item->special, item->cursorPos ); } + + if( DC->realTime < lastListBoxClickTime && listPtr->doubleClick ) + Item_RunScript( item, listPtr->doubleClick ); + lastListBoxClickTime = DC->realTime + DOUBLE_CLICK_DELAY; } + return qtrue; } // Scroll wheel - if (key == K_MWHEELUP) { + if( key == K_MWHEELUP ) + { listPtr->startPos--; - if (listPtr->startPos < 0) { + + if( listPtr->startPos < 0 ) listPtr->startPos = 0; - } + return qtrue; } - if (key == K_MWHEELDOWN) { + + if( key == K_MWHEELDOWN ) + { listPtr->startPos++; - if (listPtr->startPos > max) { + + if( listPtr->startPos > max ) listPtr->startPos = max; - } + return qtrue; } @@ -2698,73 +3141,94 @@ qboolean Item_ListBox_HandleKey(itemDef_t *item, int key, qboolean down, qboolea return qtrue; } - if ( key == K_HOME || key == K_KP_HOME) { + if( key == K_HOME || key == K_KP_HOME ) + { // home listPtr->startPos = 0; return qtrue; } - if ( key == K_END || key == K_KP_END) { + + if( key == K_END || key == K_KP_END ) + { // end listPtr->startPos = max; return qtrue; } - if (key == K_PGUP || key == K_KP_PGUP ) { + + if( key == K_PGUP || key == K_KP_PGUP ) + { // page up - if (!listPtr->notselectable) { + + if( !listPtr->notselectable ) + { listPtr->cursorPos -= viewmax; - if (listPtr->cursorPos < 0) { + + if( listPtr->cursorPos < 0 ) listPtr->cursorPos = 0; - } - if (listPtr->cursorPos < listPtr->startPos) { + + if( listPtr->cursorPos < listPtr->startPos ) listPtr->startPos = listPtr->cursorPos; - } - if (listPtr->cursorPos >= listPtr->startPos + viewmax) { + + if( listPtr->cursorPos >= listPtr->startPos + viewmax ) listPtr->startPos = listPtr->cursorPos - viewmax + 1; - } + item->cursorPos = listPtr->cursorPos; - DC->feederSelection(item->special, item->cursorPos); + DC->feederSelection( item->special, item->cursorPos ); } - else { + else + { listPtr->startPos -= viewmax; - if (listPtr->startPos < 0) { + + if( listPtr->startPos < 0 ) listPtr->startPos = 0; - } } + return qtrue; } - if ( key == K_PGDN || key == K_KP_PGDN ) { + + if( key == K_PGDN || key == K_KP_PGDN ) + { // page down - if (!listPtr->notselectable) { + + if( !listPtr->notselectable ) + { listPtr->cursorPos += viewmax; - if (listPtr->cursorPos < listPtr->startPos) { + + if( listPtr->cursorPos < listPtr->startPos ) listPtr->startPos = listPtr->cursorPos; - } - if (listPtr->cursorPos >= count) { - listPtr->cursorPos = count-1; - } - if (listPtr->cursorPos >= listPtr->startPos + viewmax) { + + if( listPtr->cursorPos >= count ) + listPtr->cursorPos = count - 1; + + if( listPtr->cursorPos >= listPtr->startPos + viewmax ) listPtr->startPos = listPtr->cursorPos - viewmax + 1; - } + item->cursorPos = listPtr->cursorPos; - DC->feederSelection(item->special, item->cursorPos); + DC->feederSelection( item->special, item->cursorPos ); } - else { + else + { listPtr->startPos += viewmax; - if (listPtr->startPos > max) { + + if( listPtr->startPos > max ) listPtr->startPos = max; - } } + return qtrue; } } + return qfalse; } -qboolean Item_YesNo_HandleKey(itemDef_t *item, int key) { - - if (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory) && item->window.flags & WINDOW_HASFOCUS && item->cvar) { - if (key == K_MOUSE1 || key == K_ENTER || key == K_MOUSE2 || key == K_MOUSE3) { - DC->setCVar(item->cvar, va("%i", !DC->getCVarValue(item->cvar))); +qboolean Item_YesNo_HandleKey( itemDef_t *item, int key ) +{ + if( Rect_ContainsPoint( &item->window.rect, DC->cursorx, DC->cursory ) && + item->window.flags & WINDOW_HASFOCUS && item->cvar ) + { + if( key == K_MOUSE1 || key == K_ENTER || key == K_MOUSE2 || key == K_MOUSE3 ) + { + DC->setCVar( item->cvar, va( "%i", !DC->getCVarValue( item->cvar ) ) ); return qtrue; } } @@ -2773,91 +3237,114 @@ qboolean Item_YesNo_HandleKey(itemDef_t *item, int key) { } -int Item_Multi_CountSettings(itemDef_t *item) { - multiDef_t *multiPtr = (multiDef_t*)item->typeData; - if (multiPtr == NULL) { +int Item_Multi_CountSettings( itemDef_t *item ) +{ + multiDef_t * multiPtr = ( multiDef_t* )item->typeData; + + if( multiPtr == NULL ) return 0; - } + return multiPtr->count; } -int Item_Multi_FindCvarByValue(itemDef_t *item) { +int Item_Multi_FindCvarByValue( itemDef_t *item ) +{ char buff[1024]; float value = 0; int i; - multiDef_t *multiPtr = (multiDef_t*)item->typeData; - if (multiPtr) { - if (multiPtr->strDef) { - DC->getCVarString(item->cvar, buff, sizeof(buff)); - } else { - value = DC->getCVarValue(item->cvar); - } - for (i = 0; i < multiPtr->count; i++) { - if (multiPtr->strDef) { - if (Q_stricmp(buff, multiPtr->cvarStr[i]) == 0) { + multiDef_t *multiPtr = ( multiDef_t* )item->typeData; + + if( multiPtr ) + { + if( multiPtr->strDef ) + DC->getCVarString( item->cvar, buff, sizeof( buff ) ); + else + value = DC->getCVarValue( item->cvar ); + + for( i = 0; i < multiPtr->count; i++ ) + { + if( multiPtr->strDef ) + { + if( Q_stricmp( buff, multiPtr->cvarStr[i] ) == 0 ) return i; - } - } else { - if (multiPtr->cvarValue[i] == value) { + } + else + { + if( multiPtr->cvarValue[i] == value ) return i; - } } } } + return 0; } -const char *Item_Multi_Setting(itemDef_t *item) { +const char *Item_Multi_Setting( itemDef_t *item ) +{ char buff[1024]; float value = 0; int i; - multiDef_t *multiPtr = (multiDef_t*)item->typeData; - if (multiPtr) { - if (multiPtr->strDef) { - DC->getCVarString(item->cvar, buff, sizeof(buff)); - } else { - value = DC->getCVarValue(item->cvar); - } - for (i = 0; i < multiPtr->count; i++) { - if (multiPtr->strDef) { - if (Q_stricmp(buff, multiPtr->cvarStr[i]) == 0) { + multiDef_t *multiPtr = ( multiDef_t* )item->typeData; + + if( multiPtr ) + { + if( multiPtr->strDef ) + DC->getCVarString( item->cvar, buff, sizeof( buff ) ); + else + value = DC->getCVarValue( item->cvar ); + + for( i = 0; i < multiPtr->count; i++ ) + { + if( multiPtr->strDef ) + { + if( Q_stricmp( buff, multiPtr->cvarStr[i] ) == 0 ) return multiPtr->cvarList[i]; - } - } else { - if (multiPtr->cvarValue[i] == value) { + } + else + { + if( multiPtr->cvarValue[i] == value ) return multiPtr->cvarList[i]; - } } } } + return ""; } -qboolean Item_Multi_HandleKey(itemDef_t *item, int key) { - multiDef_t *multiPtr = (multiDef_t*)item->typeData; - if (multiPtr) { - if (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory) && item->window.flags & WINDOW_HASFOCUS && item->cvar) { - if (key == K_MOUSE1 || key == K_ENTER || key == K_MOUSE2 || key == K_MOUSE3) { - int current = Item_Multi_FindCvarByValue(item) + 1; - int max = Item_Multi_CountSettings(item); - if ( current < 0 || current >= max ) { +qboolean Item_Multi_HandleKey( itemDef_t *item, int key ) +{ + multiDef_t * multiPtr = ( multiDef_t* )item->typeData; + + if( multiPtr ) + { + if( Rect_ContainsPoint( &item->window.rect, DC->cursorx, DC->cursory ) && + item->window.flags & WINDOW_HASFOCUS && item->cvar ) + { + if( key == K_MOUSE1 || key == K_ENTER || key == K_MOUSE2 || key == K_MOUSE3 ) + { + int current = Item_Multi_FindCvarByValue( item ) + 1; + int max = Item_Multi_CountSettings( item ); + + if( current < 0 || current >= max ) current = 0; - } - if (multiPtr->strDef) { - DC->setCVar(item->cvar, multiPtr->cvarStr[current]); - } else { + + if( multiPtr->strDef ) + DC->setCVar( item->cvar, multiPtr->cvarStr[current] ); + else + { float value = multiPtr->cvarValue[current]; - if (((float)((int) value)) == value) { - DC->setCVar(item->cvar, va("%i", (int) value )); - } - else { - DC->setCVar(item->cvar, va("%f", value )); - } + + if( ( ( float )( ( int ) value ) ) == value ) + DC->setCVar( item->cvar, va( "%i", ( int ) value ) ); + else + DC->setCVar( item->cvar, va( "%f", value ) ); } + return qtrue; } } } + return qfalse; } @@ -2866,19 +3353,19 @@ qboolean Item_Multi_HandleKey(itemDef_t *item, int key) { static void Item_TextField_CalcPaintOffset( itemDef_t *item, char *buff ) { - editFieldDef_t *editPtr = (editFieldDef_t*)item->typeData; + editFieldDef_t * editPtr = ( editFieldDef_t* )item->typeData; if( item->cursorPos < editPtr->paintOffset ) - { editPtr->paintOffset = item->cursorPos; - } else { // If there is a maximum field width + if( editPtr->maxFieldWidth > 0 ) { // If the cursor is at the end of the string, maximise the amount of the // string that's visible + if( buff[ item->cursorPos + 1 ] == '\0' ) { while( UI_Text_Width( &buff[ editPtr->paintOffset ], item->textscale, 0 ) <= @@ -2889,6 +3376,7 @@ static void Item_TextField_CalcPaintOffset( itemDef_t *item, char *buff ) buff[ item->cursorPos + 1 ] = '\0'; // Shift paintOffset so that the cursor is visible + while( UI_Text_Width( &buff[ editPtr->paintOffset ], item->textscale, 0 ) > ( editPtr->maxFieldWidth - EDIT_CURSOR_WIDTH ) ) editPtr->paintOffset++; @@ -2896,12 +3384,12 @@ static void Item_TextField_CalcPaintOffset( itemDef_t *item, char *buff ) } } -qboolean Item_TextField_HandleKey(itemDef_t *item, int key) +qboolean Item_TextField_HandleKey( itemDef_t *item, int key ) { char buff[1024]; int len; itemDef_t *newItem = NULL; - editFieldDef_t *editPtr = (editFieldDef_t*)item->typeData; + editFieldDef_t *editPtr = ( editFieldDef_t* )item->typeData; qboolean releaseFocus = qtrue; if( item->cvar ) @@ -2923,13 +3411,14 @@ qboolean Item_TextField_HandleKey(itemDef_t *item, int key) if( key == 'h' - 'a' + 1 ) { // ctrl-h is backspace - if ( item->cursorPos > 0 ) + + if( item->cursorPos > 0 ) { - memmove( &buff[item->cursorPos - 1], &buff[item->cursorPos], len + 1 - item->cursorPos); + memmove( &buff[item->cursorPos - 1], &buff[item->cursorPos], len + 1 - item->cursorPos ); item->cursorPos--; } - DC->setCVar(item->cvar, buff); + DC->setCVar( item->cvar, buff ); } else if( key < 32 || !item->cvar ) { @@ -2945,9 +3434,9 @@ qboolean Item_TextField_HandleKey(itemDef_t *item, int key) } else { - if (!DC->getOverstrikeMode()) + if( !DC->getOverstrikeMode() ) { - if (( len == MAX_EDITFIELD - 1 ) || (editPtr->maxChars && len >= editPtr->maxChars)) + if( ( len == MAX_EDITFIELD - 1 ) || ( editPtr->maxChars && len >= editPtr->maxChars ) ) { // Reached maximum field length releaseFocus = qfalse; @@ -2959,9 +3448,11 @@ qboolean Item_TextField_HandleKey(itemDef_t *item, int key) else { // Reached maximum field length - if (editPtr->maxChars && item->cursorPos >= editPtr->maxChars) + + if( editPtr->maxChars && item->cursorPos >= editPtr->maxChars ) releaseFocus = qfalse; - goto exit; + + goto exit; } buff[ item->cursorPos ] = key; @@ -2980,36 +3471,42 @@ qboolean Item_TextField_HandleKey(itemDef_t *item, int key) case K_KP_DEL: if( item->cursorPos < len ) { - memmove( buff + item->cursorPos, buff + item->cursorPos + 1, len - item->cursorPos); - DC->setCVar(item->cvar, buff); + memmove( buff + item->cursorPos, buff + item->cursorPos + 1, len - item->cursorPos ); + DC->setCVar( item->cvar, buff ); } + break; case K_RIGHTARROW: case K_KP_RIGHTARROW: if( item->cursorPos < len ) item->cursorPos++; + break; case K_LEFTARROW: case K_KP_LEFTARROW: if( item->cursorPos > 0 ) item->cursorPos--; + break; case K_HOME: case K_KP_HOME: item->cursorPos = 0; + break; case K_END: case K_KP_END: item->cursorPos = len; + break; case K_INS: case K_KP_INS: - DC->setOverstrikeMode(!DC->getOverstrikeMode()); + DC->setOverstrikeMode( !DC->getOverstrikeMode() ); + break; case K_TAB: @@ -3017,16 +3514,16 @@ qboolean Item_TextField_HandleKey(itemDef_t *item, int key) case K_KP_DOWNARROW: case K_UPARROW: case K_KP_UPARROW: - newItem = Menu_SetNextCursorItem(item->parent); + newItem = Menu_SetNextCursorItem( item->parent ); + if( newItem && ( newItem->type == ITEM_TYPE_EDITFIELD || newItem->type == ITEM_TYPE_NUMERICFIELD ) ) - { g_editItem = newItem; - } else { releaseFocus = qtrue; goto exit; } + break; case K_ENTER: @@ -3053,134 +3550,149 @@ exit: return !releaseFocus; } -static void Scroll_ListBox_AutoFunc(void *p) { - scrollInfo_t *si = (scrollInfo_t*)p; - if (DC->realTime > si->nextScrollTime) { +static void Scroll_ListBox_AutoFunc( void *p ) +{ + scrollInfo_t * si = ( scrollInfo_t* )p; + + if( DC->realTime > si->nextScrollTime ) + { // need to scroll which is done by simulating a click to the item // this is done a bit sideways as the autoscroll "knows" that the item is a listbox // so it calls it directly - Item_ListBox_HandleKey(si->item, si->scrollKey, qtrue, qfalse); + Item_ListBox_HandleKey( si->item, si->scrollKey, qtrue, qfalse ); si->nextScrollTime = DC->realTime + si->adjustValue; } - if (DC->realTime > si->nextAdjustTime) { + if( DC->realTime > si->nextAdjustTime ) + { si->nextAdjustTime = DC->realTime + SCROLL_TIME_ADJUST; - if (si->adjustValue > SCROLL_TIME_FLOOR) { + + if( si->adjustValue > SCROLL_TIME_FLOOR ) si->adjustValue -= SCROLL_TIME_ADJUSTOFFSET; - } } } -static void Scroll_ListBox_ThumbFunc(void *p) { - scrollInfo_t *si = (scrollInfo_t*)p; +static void Scroll_ListBox_ThumbFunc( void *p ) +{ + scrollInfo_t * si = ( scrollInfo_t* )p; rectDef_t r; int pos, max; - listBoxDef_t *listPtr = (listBoxDef_t*)si->item->typeData; - if (si->item->window.flags & WINDOW_HORIZONTAL) { - if (DC->cursorx == si->xStart) { + listBoxDef_t *listPtr = ( listBoxDef_t* )si->item->typeData; + + if( si->item->window.flags & WINDOW_HORIZONTAL ) + { + if( DC->cursorx == si->xStart ) return; - } + r.x = si->item->window.rect.x + SCROLLBAR_WIDTH + 1; r.y = si->item->window.rect.y + si->item->window.rect.h - SCROLLBAR_HEIGHT - 1; - r.w = si->item->window.rect.w - (SCROLLBAR_WIDTH*2) - 2; + r.w = si->item->window.rect.w - ( SCROLLBAR_WIDTH * 2 ) - 2; r.h = SCROLLBAR_HEIGHT; - max = Item_ListBox_MaxScroll(si->item); + max = Item_ListBox_MaxScroll( si->item ); // - pos = (DC->cursorx - r.x - SCROLLBAR_WIDTH/2) * max / (r.w - SCROLLBAR_WIDTH); - if (pos < 0) { + pos = ( DC->cursorx - r.x - SCROLLBAR_WIDTH / 2 ) * max / ( r.w - SCROLLBAR_WIDTH ); + + if( pos < 0 ) pos = 0; - } - else if (pos > max) { + else if( pos > max ) pos = max; - } + listPtr->startPos = pos; si->xStart = DC->cursorx; } - else if (DC->cursory != si->yStart) { - + else if( DC->cursory != si->yStart ) + { r.x = si->item->window.rect.x + si->item->window.rect.w - SCROLLBAR_WIDTH - 1; r.y = si->item->window.rect.y + SCROLLBAR_HEIGHT + 1; r.w = SCROLLBAR_WIDTH; - r.h = si->item->window.rect.h - (SCROLLBAR_HEIGHT*2) - 2; - max = Item_ListBox_MaxScroll(si->item); + r.h = si->item->window.rect.h - ( SCROLLBAR_HEIGHT * 2 ) - 2; + max = Item_ListBox_MaxScroll( si->item ); // - pos = (DC->cursory - r.y - SCROLLBAR_HEIGHT/2) * max / (r.h - SCROLLBAR_HEIGHT); - if (pos < 0) { + pos = ( DC->cursory - r.y - SCROLLBAR_HEIGHT / 2 ) * max / ( r.h - SCROLLBAR_HEIGHT ); + + if( pos < 0 ) pos = 0; - } - else if (pos > max) { + else if( pos > max ) pos = max; - } + listPtr->startPos = pos; si->yStart = DC->cursory; } - if (DC->realTime > si->nextScrollTime) { + if( DC->realTime > si->nextScrollTime ) + { // need to scroll which is done by simulating a click to the item // this is done a bit sideways as the autoscroll "knows" that the item is a listbox // so it calls it directly - Item_ListBox_HandleKey(si->item, si->scrollKey, qtrue, qfalse); + Item_ListBox_HandleKey( si->item, si->scrollKey, qtrue, qfalse ); si->nextScrollTime = DC->realTime + si->adjustValue; } - if (DC->realTime > si->nextAdjustTime) { + if( DC->realTime > si->nextAdjustTime ) + { si->nextAdjustTime = DC->realTime + SCROLL_TIME_ADJUST; - if (si->adjustValue > SCROLL_TIME_FLOOR) { + + if( si->adjustValue > SCROLL_TIME_FLOOR ) si->adjustValue -= SCROLL_TIME_ADJUSTOFFSET; - } } } -static void Scroll_Slider_ThumbFunc(void *p) { +static void Scroll_Slider_ThumbFunc( void *p ) +{ float x, value, cursorx; - scrollInfo_t *si = (scrollInfo_t*)p; + scrollInfo_t *si = ( scrollInfo_t* )p; editFieldDef_t *editDef = si->item->typeData; - if (si->item->text) { + if( si->item->text ) x = si->item->textRect.x + si->item->textRect.w + ITEM_VALUE_OFFSET; - } else { + else x = si->item->window.rect.x; - } cursorx = DC->cursorx; - if (cursorx < x) { + if( cursorx < x ) cursorx = x; - } else if (cursorx > x + SLIDER_WIDTH) { + else if( cursorx > x + SLIDER_WIDTH ) cursorx = x + SLIDER_WIDTH; - } + value = cursorx - x; value /= SLIDER_WIDTH; - value *= (editDef->maxVal - editDef->minVal); + value *= ( editDef->maxVal - editDef->minVal ); value += editDef->minVal; - DC->setCVar(si->item->cvar, va("%f", value)); + DC->setCVar( si->item->cvar, va( "%f", value ) ); } -void Item_StartCapture(itemDef_t *item, int key) { +void Item_StartCapture( itemDef_t *item, int key ) +{ int flags; // Don't allow captureFunc to be overridden + if( captureFunc != voidFunction ) return; - switch (item->type) { + switch( item->type ) + { case ITEM_TYPE_EDITFIELD: case ITEM_TYPE_NUMERICFIELD: - case ITEM_TYPE_LISTBOX: { - flags = Item_ListBox_OverLB(item, DC->cursorx, DC->cursory); - if (flags & (WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW)) { + flags = Item_ListBox_OverLB( item, DC->cursorx, DC->cursory ); + + if( flags & ( WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW ) ) + { scrollInfo.nextScrollTime = DC->realTime + SCROLL_TIME_START; scrollInfo.nextAdjustTime = DC->realTime + SCROLL_TIME_ADJUST; scrollInfo.adjustValue = SCROLL_TIME_START; scrollInfo.scrollKey = key; - scrollInfo.scrollDir = (flags & WINDOW_LB_LEFTARROW) ? qtrue : qfalse; + scrollInfo.scrollDir = ( flags & WINDOW_LB_LEFTARROW ) ? qtrue : qfalse; scrollInfo.item = item; UI_InstallCaptureFunc( Scroll_ListBox_AutoFunc, &scrollInfo, 0 ); itemCapture = item; - } else if (flags & WINDOW_LB_THUMB) { + } + else if( flags & WINDOW_LB_THUMB ) + { scrollInfo.scrollKey = key; scrollInfo.item = item; scrollInfo.xStart = DC->cursorx; @@ -3188,12 +3700,16 @@ void Item_StartCapture(itemDef_t *item, int key) { UI_InstallCaptureFunc( Scroll_ListBox_ThumbFunc, &scrollInfo, 0 ); itemCapture = item; } + break; } + case ITEM_TYPE_SLIDER: { - flags = Item_Slider_OverSlider(item, DC->cursorx, DC->cursory); - if (flags & WINDOW_LB_THUMB) { + flags = Item_Slider_OverSlider( item, DC->cursorx, DC->cursory ); + + if( flags & WINDOW_LB_THUMB ) + { scrollInfo.scrollKey = key; scrollInfo.item = item; scrollInfo.xStart = DC->cursorx; @@ -3201,107 +3717,130 @@ void Item_StartCapture(itemDef_t *item, int key) { UI_InstallCaptureFunc( Scroll_Slider_ThumbFunc, &scrollInfo, 0 ); itemCapture = item; } + break; } } } -void Item_StopCapture(itemDef_t *item) { - +void Item_StopCapture( itemDef_t *item ) +{ } -qboolean Item_Slider_HandleKey(itemDef_t *item, int key, qboolean down) { +qboolean Item_Slider_HandleKey( itemDef_t *item, int key, qboolean down ) +{ float x, value, width, work; - if (item->window.flags & WINDOW_HASFOCUS && item->cvar && Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory)) { - if (key == K_MOUSE1 || key == K_ENTER || key == K_MOUSE2 || key == K_MOUSE3) { - editFieldDef_t *editDef = item->typeData; - if (editDef) { + if( item->window.flags & WINDOW_HASFOCUS && item->cvar && + Rect_ContainsPoint( &item->window.rect, DC->cursorx, DC->cursory ) ) + { + if( key == K_MOUSE1 || key == K_ENTER || key == K_MOUSE2 || key == K_MOUSE3 ) + { + editFieldDef_t * editDef = item->typeData; + + if( editDef ) + { rectDef_t testRect; width = SLIDER_WIDTH; - if (item->text) { + + if( item->text ) x = item->textRect.x + item->textRect.w + ITEM_VALUE_OFFSET; - } else { + else x = item->window.rect.x; - } testRect = item->window.rect; testRect.x = x; - value = (float)SLIDER_THUMB_WIDTH / 2; + value = ( float )SLIDER_THUMB_WIDTH / 2; testRect.x -= value; - testRect.w = (SLIDER_WIDTH + (float)SLIDER_THUMB_WIDTH / 2); - if (Rect_ContainsPoint(&testRect, DC->cursorx, DC->cursory)) { + testRect.w = ( SLIDER_WIDTH + ( float )SLIDER_THUMB_WIDTH / 2 ); + + if( Rect_ContainsPoint( &testRect, DC->cursorx, DC->cursory ) ) + { work = DC->cursorx - x; value = work / width; - value *= (editDef->maxVal - editDef->minVal); + value *= ( editDef->maxVal - editDef->minVal ); // vm fuckage // value = (((float)(DC->cursorx - x)/ SLIDER_WIDTH) * (editDef->maxVal - editDef->minVal)); value += editDef->minVal; - DC->setCVar(item->cvar, va("%f", value)); + DC->setCVar( item->cvar, va( "%f", value ) ); return qtrue; } } } } + return qfalse; } -qboolean Item_HandleKey(itemDef_t *item, int key, qboolean down) { - - if (itemCapture) { - Item_StopCapture(itemCapture); +qboolean Item_HandleKey( itemDef_t *item, int key, qboolean down ) +{ + if( itemCapture ) + { + Item_StopCapture( itemCapture ); itemCapture = NULL; UI_RemoveCaptureFunc( ); - } else { - if ( down && ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_MOUSE3 ) ) { - Item_StartCapture(item, key); - } + } + else + { + if( down && ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_MOUSE3 ) ) + Item_StartCapture( item, key ); } - if (!down) { + if( !down ) return qfalse; - } - switch (item->type) { + switch( item->type ) + { case ITEM_TYPE_BUTTON: return qfalse; break; + case ITEM_TYPE_RADIOBUTTON: return qfalse; break; + case ITEM_TYPE_CHECKBOX: return qfalse; break; + case ITEM_TYPE_EDITFIELD: case ITEM_TYPE_NUMERICFIELD: //return Item_TextField_HandleKey(item, key); return qfalse; break; + case ITEM_TYPE_COMBO: return qfalse; break; + case ITEM_TYPE_LISTBOX: - return Item_ListBox_HandleKey(item, key, down, qfalse); + return Item_ListBox_HandleKey( item, key, down, qfalse ); break; + case ITEM_TYPE_YESNO: - return Item_YesNo_HandleKey(item, key); + return Item_YesNo_HandleKey( item, key ); break; + case ITEM_TYPE_MULTI: - return Item_Multi_HandleKey(item, key); + return Item_Multi_HandleKey( item, key ); break; + case ITEM_TYPE_OWNERDRAW: - return Item_OwnerDraw_HandleKey(item, key); + return Item_OwnerDraw_HandleKey( item, key ); break; + case ITEM_TYPE_BIND: - return Item_Bind_HandleKey(item, key, down); + return Item_Bind_HandleKey( item, key, down ); break; + case ITEM_TYPE_SLIDER: - return Item_Slider_HandleKey(item, key, down); + return Item_Slider_HandleKey( item, key, down ); break; - //case ITEM_TYPE_IMAGE: - // Item_Image_Paint(item); - // break; + //case ITEM_TYPE_IMAGE: + // Item_Image_Paint(item); + // break; + default: return qfalse; break; @@ -3310,59 +3849,72 @@ qboolean Item_HandleKey(itemDef_t *item, int key, qboolean down) { //return qfalse; } -void Item_Action(itemDef_t *item) { - if (item) { - Item_RunScript(item, item->action); - } +void Item_Action( itemDef_t *item ) +{ + if( item ) + Item_RunScript( item, item->action ); } -itemDef_t *Menu_SetPrevCursorItem(menuDef_t *menu) { +itemDef_t *Menu_SetPrevCursorItem( menuDef_t *menu ) +{ qboolean wrapped = qfalse; int oldCursor = menu->cursorItem; - if (menu->cursorItem < 0) { - menu->cursorItem = menu->itemCount-1; + if( menu->cursorItem < 0 ) + { + menu->cursorItem = menu->itemCount - 1; wrapped = qtrue; } - while (menu->cursorItem > -1) { - + while( menu->cursorItem > -1 ) + { menu->cursorItem--; - if (menu->cursorItem < 0 && !wrapped) { + + if( menu->cursorItem < 0 && !wrapped ) + { wrapped = qtrue; - menu->cursorItem = menu->itemCount -1; + menu->cursorItem = menu->itemCount - 1; } - if (Item_SetFocus(menu->items[menu->cursorItem], DC->cursorx, DC->cursory)) { - Menu_HandleMouseMove(menu, menu->items[menu->cursorItem]->window.rect.x + 1, menu->items[menu->cursorItem]->window.rect.y + 1); + if( Item_SetFocus( menu->items[menu->cursorItem], DC->cursorx, DC->cursory ) ) + { + Menu_HandleMouseMove( menu, menu->items[menu->cursorItem]->window.rect.x + 1, + menu->items[menu->cursorItem]->window.rect.y + 1 ); return menu->items[menu->cursorItem]; } } + menu->cursorItem = oldCursor; return NULL; } -itemDef_t *Menu_SetNextCursorItem(menuDef_t *menu) { - +itemDef_t *Menu_SetNextCursorItem( menuDef_t *menu ) +{ qboolean wrapped = qfalse; int oldCursor = menu->cursorItem; - if (menu->cursorItem == -1) { + if( menu->cursorItem == -1 ) + { menu->cursorItem = 0; wrapped = qtrue; } - while (menu->cursorItem < menu->itemCount) { - + while( menu->cursorItem < menu->itemCount ) + { menu->cursorItem++; - if (menu->cursorItem >= menu->itemCount && !wrapped) { + + if( menu->cursorItem >= menu->itemCount && !wrapped ) + { wrapped = qtrue; menu->cursorItem = 0; } - if (Item_SetFocus(menu->items[menu->cursorItem], DC->cursorx, DC->cursory)) { - Menu_HandleMouseMove(menu, menu->items[menu->cursorItem]->window.rect.x + 1, menu->items[menu->cursorItem]->window.rect.y + 1); + + if( Item_SetFocus( menu->items[menu->cursorItem], DC->cursorx, DC->cursory ) ) + { + Menu_HandleMouseMove( menu, menu->items[menu->cursorItem]->window.rect.x + 1, + menu->items[menu->cursorItem]->window.rect.y + 1 ); return menu->items[menu->cursorItem]; } @@ -3372,31 +3924,38 @@ itemDef_t *Menu_SetNextCursorItem(menuDef_t *menu) { return NULL; } -static void Window_CloseCinematic(windowDef_t *window) { - if (window->style == WINDOW_STYLE_CINEMATIC && window->cinematic >= 0) { - DC->stopCinematic(window->cinematic); +static void Window_CloseCinematic( windowDef_t *window ) +{ + if( window->style == WINDOW_STYLE_CINEMATIC && window->cinematic >= 0 ) + { + DC->stopCinematic( window->cinematic ); window->cinematic = -1; } } -static void Menu_CloseCinematics(menuDef_t *menu) { - if (menu) { +static void Menu_CloseCinematics( menuDef_t *menu ) +{ + if( menu ) + { int i; - Window_CloseCinematic(&menu->window); - for (i = 0; i < menu->itemCount; i++) { - Window_CloseCinematic(&menu->items[i]->window); - if (menu->items[i]->type == ITEM_TYPE_OWNERDRAW) { - DC->stopCinematic(0-menu->items[i]->window.ownerDraw); - } + Window_CloseCinematic( &menu->window ); + + for( i = 0; i < menu->itemCount; i++ ) + { + Window_CloseCinematic( &menu->items[i]->window ); + + if( menu->items[i]->type == ITEM_TYPE_OWNERDRAW ) + DC->stopCinematic( 0 - menu->items[i]->window.ownerDraw ); } } } -static void Display_CloseCinematics( void ) { +static void Display_CloseCinematics( void ) +{ int i; - for (i = 0; i < menuCount; i++) { - Menu_CloseCinematics(&Menus[i]); - } + + for( i = 0; i < menuCount; i++ ) + Menu_CloseCinematics( &Menus[i] ); } void Menus_Activate( menuDef_t *menu ) @@ -3407,7 +3966,7 @@ void Menus_Activate( menuDef_t *menu ) if( openMenuCount > 0 && menuStack[ openMenuCount - 1 ] == menu ) onTopOfMenuStack = qtrue; - menu->window.flags |= (WINDOW_HASFOCUS | WINDOW_VISIBLE); + menu->window.flags |= ( WINDOW_HASFOCUS | WINDOW_VISIBLE ); // If being opened for the first time if( !onTopOfMenuStack ) @@ -3420,7 +3979,7 @@ void Menus_Activate( menuDef_t *menu ) } if( menu->soundName && *menu->soundName ) - DC->startBackgroundTrack(menu->soundName, menu->soundName); + DC->startBackgroundTrack( menu->soundName, menu->soundName ); Display_CloseCinematics( ); @@ -3430,11 +3989,12 @@ void Menus_Activate( menuDef_t *menu ) { if( menu->items[ i ]->type == ITEM_TYPE_LISTBOX ) { - listBoxDef_t *listPtr = (listBoxDef_t*)menu->items[ i ]->typeData; + listBoxDef_t * listPtr = ( listBoxDef_t* )menu->items[ i ]->typeData; menu->items[ i ]->cursorPos = 0; listPtr->startPos = 0; DC->feederSelection( menu->items[ i ]->special, 0 ); } + } if( openMenuCount < MAX_OPEN_MENUS ) @@ -3442,101 +4002,124 @@ void Menus_Activate( menuDef_t *menu ) } } -int Display_VisibleMenuCount( void ) { +int Display_VisibleMenuCount( void ) +{ int i, count; count = 0; - for (i = 0; i < menuCount; i++) { - if (Menus[i].window.flags & (WINDOW_FORCED | WINDOW_VISIBLE)) { + + for( i = 0; i < menuCount; i++ ) + { + if( Menus[i].window.flags & ( WINDOW_FORCED | WINDOW_VISIBLE ) ) count++; - } } + return count; } -void Menus_HandleOOBClick(menuDef_t *menu, int key, qboolean down) { - if (menu) { +void Menus_HandleOOBClick( menuDef_t *menu, int key, qboolean down ) +{ + if( menu ) + { int i; // basically the behaviour we are looking for is if there are windows in the stack.. see if // the cursor is within any of them.. if not close them otherwise activate them and pass the // key on.. force a mouse move to activate focus and script stuff - if (down && menu->window.flags & WINDOW_OOB_CLICK) { + + if( down && menu->window.flags & WINDOW_OOB_CLICK ) Menus_Close( menu ); - } - for (i = 0; i < menuCount; i++) { - if (Menu_OverActiveItem(&Menus[i], DC->cursorx, DC->cursory)) { + for( i = 0; i < menuCount; i++ ) + { + if( Menu_OverActiveItem( &Menus[i], DC->cursorx, DC->cursory ) ) + { Menus_Close( menu ); - Menus_Activate(&Menus[i]); - Menu_HandleMouseMove(&Menus[i], DC->cursorx, DC->cursory); - Menu_HandleKey(&Menus[i], key, down); + Menus_Activate( &Menus[i] ); + Menu_HandleMouseMove( &Menus[i], DC->cursorx, DC->cursory ); + Menu_HandleKey( &Menus[i], key, down ); } } - if (Display_VisibleMenuCount() == 0) { - if (DC->Pause) { - DC->Pause(qfalse); - } + if( Display_VisibleMenuCount() == 0 ) + { + if( DC->Pause ) + DC->Pause( qfalse ); } + Display_CloseCinematics(); } } -static rectDef_t *Item_CorrectedTextRect(itemDef_t *item) { +static rectDef_t *Item_CorrectedTextRect( itemDef_t *item ) +{ static rectDef_t rect; - memset(&rect, 0, sizeof(rectDef_t)); - if (item) { + memset( &rect, 0, sizeof( rectDef_t ) ); + + if( item ) + { rect = item->textRect; - if (rect.w) { + + if( rect.w ) rect.y -= rect.h; - } } + return ▭ } -void Menu_HandleKey(menuDef_t *menu, int key, qboolean down) { +void Menu_HandleKey( menuDef_t *menu, int key, qboolean down ) +{ int i; itemDef_t *item = NULL; qboolean inHandler = qfalse; - if (inHandler) { + if( inHandler ) return; - } inHandler = qtrue; - if (g_waitingForKey && down) { - Item_Bind_HandleKey(g_bindItem, key, down); + + if( g_waitingForKey && down ) + { + Item_Bind_HandleKey( g_bindItem, key, down ); inHandler = qfalse; return; } - if (g_editingField && down) { - if (!Item_TextField_HandleKey(g_editItem, key)) { + if( g_editingField && down ) + { + if( !Item_TextField_HandleKey( g_editItem, key ) ) + { g_editingField = qfalse; Item_RunScript( g_editItem, g_editItem->onTextEntry ); g_editItem = NULL; inHandler = qfalse; return; - } else if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_MOUSE3) { + } + else if( key == K_MOUSE1 || key == K_MOUSE2 || key == K_MOUSE3 ) + { g_editingField = qfalse; Item_RunScript( g_editItem, g_editItem->onTextEntry ); g_editItem = NULL; - Display_MouseMove(NULL, DC->cursorx, DC->cursory); - } else if (key == K_TAB || key == K_UPARROW || key == K_DOWNARROW) { - return; + Display_MouseMove( NULL, DC->cursorx, DC->cursory ); } + else if( key == K_TAB || key == K_UPARROW || key == K_DOWNARROW ) + return; } - if (menu == NULL) { + if( menu == NULL ) + { inHandler = qfalse; return; } - // see if the mouse is within the window bounds and if so is this a mouse click - if (down && !(menu->window.flags & WINDOW_POPUP) && !Rect_ContainsPoint(&menu->window.rect, DC->cursorx, DC->cursory)) { + // see if the mouse is within the window bounds and if so is this a mouse click + if( down && !( menu->window.flags & WINDOW_POPUP ) && + !Rect_ContainsPoint( &menu->window.rect, DC->cursorx, DC->cursory ) ) + { static qboolean inHandleKey = qfalse; - if (!inHandleKey && ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_MOUSE3 ) ) { + + if( !inHandleKey && ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_MOUSE3 ) ) + { inHandleKey = qtrue; - Menus_HandleOOBClick(menu, key, down); + Menus_HandleOOBClick( menu, key, down ); inHandleKey = qfalse; inHandler = qfalse; return; @@ -3544,76 +4127,92 @@ void Menu_HandleKey(menuDef_t *menu, int key, qboolean down) { } // get the item with focus - for (i = 0; i < menu->itemCount; i++) { - if (menu->items[i]->window.flags & WINDOW_HASFOCUS) { + for( i = 0; i < menu->itemCount; i++ ) + { + if( menu->items[i]->window.flags & WINDOW_HASFOCUS ) item = menu->items[i]; - } } - if (item != NULL) { - if (Item_HandleKey(item, key, down)) { - Item_Action(item); + if( item != NULL ) + { + if( Item_HandleKey( item, key, down ) ) + { + Item_Action( item ); inHandler = qfalse; return; } } - if (!down) { + if( !down ) + { inHandler = qfalse; return; } // default handling - switch ( key ) { - + switch( key ) + { case K_F12: - if (DC->getCVarValue("developer")) { - DC->executeText(EXEC_APPEND, "screenshot\n"); - } + if( DC->getCVarValue( "developer" ) ) + DC->executeText( EXEC_APPEND, "screenshot\n" ); + break; + case K_KP_UPARROW: case K_UPARROW: - Menu_SetPrevCursorItem(menu); + Menu_SetPrevCursorItem( menu ); break; case K_ESCAPE: - if (!g_waitingForKey && menu->onESC) { + if( !g_waitingForKey && menu->onESC ) + { itemDef_t it; it.parent = menu; - Item_RunScript(&it, menu->onESC); + Item_RunScript( &it, menu->onESC ); } + break; + case K_TAB: case K_KP_DOWNARROW: case K_DOWNARROW: - Menu_SetNextCursorItem(menu); + Menu_SetNextCursorItem( menu ); break; case K_MOUSE1: case K_MOUSE2: - if (item) { - if (item->type == ITEM_TYPE_TEXT) { - if (Rect_ContainsPoint(Item_CorrectedTextRect(item), DC->cursorx, DC->cursory)) { - Item_Action(item); - } - } else if (item->type == ITEM_TYPE_EDITFIELD || item->type == ITEM_TYPE_NUMERICFIELD) { - if (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory)) { + if( item ) + { + if( item->type == ITEM_TYPE_TEXT ) + { + if( Rect_ContainsPoint( Item_CorrectedTextRect( item ), DC->cursorx, DC->cursory ) ) + Item_Action( item ); + } + else if( item->type == ITEM_TYPE_EDITFIELD || item->type == ITEM_TYPE_NUMERICFIELD ) + { + if( Rect_ContainsPoint( &item->window.rect, DC->cursorx, DC->cursory ) ) + { char buffer[ MAX_STRING_CHARS ] = { 0 }; if( item->cvar ) DC->getCVarString( item->cvar, buffer, sizeof( buffer ) ); item->cursorPos = strlen( buffer ); + Item_TextField_CalcPaintOffset( item, buffer ); + g_editingField = qtrue; + g_editItem = item; } - } else { - if (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory)) { - Item_Action(item); - } + } + else + { + if( Rect_ContainsPoint( &item->window.rect, DC->cursorx, DC->cursory ) ) + Item_Action( item ); } } + break; case K_JOY1: @@ -3637,113 +4236,131 @@ void Menu_HandleKey(menuDef_t *menu, int key, qboolean down) { case K_AUX15: case K_AUX16: break; + case K_KP_ENTER: case K_ENTER: - if (item) { - if (item->type == ITEM_TYPE_EDITFIELD || item->type == ITEM_TYPE_NUMERICFIELD) { + if( item ) + { + if( item->type == ITEM_TYPE_EDITFIELD || item->type == ITEM_TYPE_NUMERICFIELD ) + { char buffer[ MAX_STRING_CHARS ] = { 0 }; if( item->cvar ) DC->getCVarString( item->cvar, buffer, sizeof( buffer ) ); item->cursorPos = strlen( buffer ); + Item_TextField_CalcPaintOffset( item, buffer ); + g_editingField = qtrue; + g_editItem = item; - } else { - Item_Action(item); } + else + Item_Action( item ); } + break; } + inHandler = qfalse; } -void ToWindowCoords(float *x, float *y, windowDef_t *window) { - if (window->border != 0) { +void ToWindowCoords( float *x, float *y, windowDef_t *window ) +{ + if( window->border != 0 ) + { *x += window->borderSize; *y += window->borderSize; } + *x += window->rect.x; *y += window->rect.y; } -void Rect_ToWindowCoords(rectDef_t *rect, windowDef_t *window) { - ToWindowCoords(&rect->x, &rect->y, window); +void Rect_ToWindowCoords( rectDef_t *rect, windowDef_t *window ) +{ + ToWindowCoords( &rect->x, &rect->y, window ); } -void Item_SetTextExtents(itemDef_t *item, int *width, int *height, const char *text) { - const char *textPtr = (text) ? text : item->text; +void Item_SetTextExtents( itemDef_t *item, int *width, int *height, const char *text ) +{ + const char * textPtr = ( text ) ? text : item->text; - if (textPtr == NULL ) { + if( textPtr == NULL ) return; - } *width = item->textRect.w; *height = item->textRect.h; // keeps us from computing the widths and heights more than once - if (*width == 0 || (item->type == ITEM_TYPE_OWNERDRAW && item->textalignment == ALIGN_CENTER)) { + + if( *width == 0 || ( item->type == ITEM_TYPE_OWNERDRAW && item->textalignment == ALIGN_CENTER ) ) + { int originalWidth; - if (item->type == ITEM_TYPE_EDITFIELD && item->textalignment == ALIGN_CENTER && item->cvar) { + if( item->type == ITEM_TYPE_EDITFIELD && item->textalignment == ALIGN_CENTER && item->cvar ) + { //FIXME: this will only be called once? char buff[256]; - DC->getCVarString(item->cvar, buff, 256); - originalWidth = UI_Text_Width(item->text, item->textscale, 0) + - UI_Text_Width(buff, item->textscale, 0); - } else { - originalWidth = UI_Text_Width(item->text, item->textscale, 0); + DC->getCVarString( item->cvar, buff, 256 ); + originalWidth = UI_Text_Width( item->text, item->textscale, 0 ) + + UI_Text_Width( buff, item->textscale, 0 ); } + else + originalWidth = UI_Text_Width( item->text, item->textscale, 0 ); - *width = UI_Text_Width(textPtr, item->textscale, 0); - *height = UI_Text_Height(textPtr, item->textscale, 0); + *width = UI_Text_Width( textPtr, item->textscale, 0 ); + *height = UI_Text_Height( textPtr, item->textscale, 0 ); item->textRect.w = *width; item->textRect.h = *height; - if (item->textvalignment == VALIGN_BOTTOM) { + if( item->textvalignment == VALIGN_BOTTOM ) item->textRect.y = item->textaligny + item->window.rect.h; - } else if (item->textvalignment == VALIGN_CENTER) { + else if( item->textvalignment == VALIGN_CENTER ) item->textRect.y = item->textaligny + ( ( *height + item->window.rect.h ) / 2.0f ); - } else if (item->textvalignment == VALIGN_TOP) { + else if( item->textvalignment == VALIGN_TOP ) item->textRect.y = item->textaligny + *height; - } - if (item->textalignment == ALIGN_LEFT) { + if( item->textalignment == ALIGN_LEFT ) item->textRect.x = item->textalignx; - } else if (item->textalignment == ALIGN_CENTER) { + else if( item->textalignment == ALIGN_CENTER ) item->textRect.x = item->textalignx + ( ( item->window.rect.w - originalWidth ) / 2.0f ); - } else if (item->textalignment == ALIGN_RIGHT) { + else if( item->textalignment == ALIGN_RIGHT ) item->textRect.x = item->textalignx + item->window.rect.w - originalWidth; - } - ToWindowCoords(&item->textRect.x, &item->textRect.y, &item->window); + ToWindowCoords( &item->textRect.x, &item->textRect.y, &item->window ); } } -void Item_TextColor(itemDef_t *item, vec4_t *newColor) { +void Item_TextColor( itemDef_t *item, vec4_t *newColor ) +{ vec4_t lowLight; - menuDef_t *parent = (menuDef_t*)item->parent; + menuDef_t *parent = ( menuDef_t* )item->parent; - Fade(&item->window.flags, &item->window.foreColor[3], parent->fadeClamp, &item->window.nextTime, parent->fadeCycle, qtrue, parent->fadeAmount); + Fade( &item->window.flags, &item->window.foreColor[3], parent->fadeClamp, + &item->window.nextTime, parent->fadeCycle, qtrue, parent->fadeAmount ); - if (item->window.flags & WINDOW_HASFOCUS) { - memcpy(newColor, &parent->focusColor, sizeof(vec4_t)); - } else if (item->textStyle == ITEM_TEXTSTYLE_BLINK && !((DC->realTime/BLINK_DIVISOR) & 1)) { + if( item->window.flags & WINDOW_HASFOCUS ) + memcpy( newColor, &parent->focusColor, sizeof( vec4_t ) ); + else if( item->textStyle == ITEM_TEXTSTYLE_BLINK && !( ( DC->realTime / BLINK_DIVISOR ) & 1 ) ) + { lowLight[0] = 0.8 * item->window.foreColor[0]; lowLight[1] = 0.8 * item->window.foreColor[1]; lowLight[2] = 0.8 * item->window.foreColor[2]; lowLight[3] = 0.8 * item->window.foreColor[3]; - LerpColor(item->window.foreColor,lowLight,*newColor,0.5+0.5*sin(DC->realTime / PULSE_DIVISOR)); - } else { - memcpy(newColor, &item->window.foreColor, sizeof(vec4_t)); + LerpColor( item->window.foreColor, lowLight, *newColor, 0.5 + 0.5 * sin( DC->realTime / PULSE_DIVISOR ) ); + } + else + { + memcpy( newColor, &item->window.foreColor, sizeof( vec4_t ) ); // items can be enabled and disabled based on cvars } - if (item->enableCvar != NULL && *item->enableCvar && item->cvarTest != NULL && *item->cvarTest) { - if (item->cvarFlags & (CVAR_ENABLE | CVAR_DISABLE) && !Item_EnableShowViaCvar(item, CVAR_ENABLE)) { - memcpy(newColor, &parent->disableColor, sizeof(vec4_t)); - } + if( item->enableCvar != NULL && *item->enableCvar && item->cvarTest != NULL && *item->cvarTest ) + { + if( item->cvarFlags & ( CVAR_ENABLE | CVAR_DISABLE ) && !Item_EnableShowViaCvar( item, CVAR_ENABLE ) ) + memcpy( newColor, &parent->disableColor, sizeof( vec4_t ) ); } } @@ -3759,7 +4376,7 @@ static const char *Item_Text_Wrap( const char *text, float scale, float width ) unsigned int i; if( strlen( text ) >= sizeof( out ) ) - return NULL; + return NULL; *paint = '\0'; @@ -3768,6 +4385,7 @@ static const char *Item_Text_Wrap( const char *text, float scale, float width ) Com_Memset( c, 0, sizeof( c ) ); // Skip leading whitespace + while( *p ) { if( Q_IsColorString( p ) ) @@ -3786,11 +4404,16 @@ static const char *Item_Text_Wrap( const char *text, float scale, float width ) break; testLength = 1; + eol = p; + q = p; + while( Q_IsColorString( q ) ) q += 2; + q++; + while( Q_IsColorString( q ) ) q += 2; @@ -3804,9 +4427,11 @@ static const char *Item_Text_Wrap( const char *text, float scale, float width ) // Point q at the end of the current testLength q = p; + for( i = 0; i < testLength; ) { // Skip color escapes + while( Q_IsColorString( q ) ) { q += 2; @@ -3841,10 +4466,12 @@ static const char *Item_Text_Wrap( const char *text, float scale, float width ) // Add colour code (might be empty) Q_strcat( out, sizeof( out ), c ); + paint = out + strlen( out ); // Copy text strncpy( paint, p, eol - p ); + paint[ eol - p ] = '\0'; // Add a \n if it's not there already @@ -3852,6 +4479,7 @@ static const char *Item_Text_Wrap( const char *text, float scale, float width ) Q_strcat( out, sizeof( out ), "\n" ); paint = out + strlen( out ); + p = eol; } @@ -3870,7 +4498,9 @@ typedef struct char lines[ MAX_WRAP_LINES ][ MAX_WRAP_TEXT ]; float lineCoords[ MAX_WRAP_LINES ][ 2 ]; int numLines; -} wrapCache_t; +} + +wrapCache_t; static wrapCache_t wrapCache[ MAX_WRAP_CACHE ]; static int cacheWriteIndex = 0; @@ -3879,7 +4509,7 @@ static int cacheReadLineNum = 0; static void UI_CreateCacheEntry( const char *text, rectDef_t *rect, float scale ) { - wrapCache_t *cacheEntry = &wrapCache[ cacheWriteIndex ]; + wrapCache_t * cacheEntry = &wrapCache[ cacheWriteIndex ]; Q_strncpyz( cacheEntry->text, text, sizeof( cacheEntry->text ) ); cacheEntry->rect.x = rect->x; @@ -3892,14 +4522,16 @@ static void UI_CreateCacheEntry( const char *text, rectDef_t *rect, float scale static void UI_AddCacheEntryLine( const char *text, float x, float y ) { - wrapCache_t *cacheEntry = &wrapCache[ cacheWriteIndex ]; + wrapCache_t * cacheEntry = &wrapCache[ cacheWriteIndex ]; if( cacheEntry->numLines >= MAX_WRAP_LINES ) return; Q_strncpyz( cacheEntry->lines[ cacheEntry->numLines ], text, sizeof( cacheEntry->lines[ 0 ] ) ); + cacheEntry->lineCoords[ cacheEntry->numLines ][ 0 ] = x; + cacheEntry->lineCoords[ cacheEntry->numLines ][ 1 ] = y; cacheEntry->numLines++; @@ -3932,7 +4564,9 @@ static qboolean UI_CheckWrapCache( const char *text, rectDef_t *rect, float scal // This is a match cacheReadIndex = i; + cacheReadLineNum = 0; + return qtrue; } @@ -3942,13 +4576,15 @@ static qboolean UI_CheckWrapCache( const char *text, rectDef_t *rect, float scal static qboolean UI_NextWrapLine( const char **text, float *x, float *y ) { - wrapCache_t *cacheEntry = &wrapCache[ cacheReadIndex ]; + wrapCache_t * cacheEntry = &wrapCache[ cacheReadIndex ]; if( cacheReadLineNum >= cacheEntry->numLines ) return qfalse; *text = cacheEntry->lines[ cacheReadLineNum ]; + *x = cacheEntry->lineCoords[ cacheReadLineNum ][ 0 ]; + *y = cacheEntry->lineCoords[ cacheReadLineNum ][ 1 ]; cacheReadLineNum++; @@ -3982,13 +4618,13 @@ void Item_Text_Wrapped_Paint( itemDef_t *item ) Item_TextColor( item, &color ); // Check if this block is cached - if( (qboolean)DC->getCVarValue( "ui_textWrapCache" ) && + if( ( qboolean )DC->getCVarValue( "ui_textWrapCache" ) && UI_CheckWrapCache( textPtr, &item->window.rect, item->textscale ) ) { while( UI_NextWrapLine( &p, &x, &y ) ) { UI_Text_Paint( x, y, item->textscale, color, - p, 0, 0, item->textStyle ); + p, 0, 0, item->textStyle ); } } else @@ -4015,13 +4651,15 @@ void Item_Text_Wrapped_Paint( itemDef_t *item ) // Count lines totalLines = 0; + for( i = 0; i < textLength; i++ ) { if( textPtr[ i ] == '\n' ) totalLines++; } - paintLines = (int)floor( ( h + lineSpacing ) / lineHeight ); + paintLines = ( int )floor( ( h + lineSpacing ) / lineHeight ); + if( paintLines > totalLines ) paintLines = totalLines; @@ -4030,6 +4668,7 @@ void Item_Text_Wrapped_Paint( itemDef_t *item ) switch( item->textvalignment ) { default: + case VALIGN_BOTTOM: paintY = y + ( h - textHeight ); break; @@ -4044,6 +4683,7 @@ void Item_Text_Wrapped_Paint( itemDef_t *item ) } p = textPtr; + for( i = 0, lineNum = 0; i < textLength && lineNum < paintLines; i++ ) { int lineLength = &textPtr[ i ] - p; @@ -4089,8 +4729,8 @@ void Item_Text_Wrapped_Paint( itemDef_t *item ) Item_SetTextExtents( &lineItem, &width, &height, buff ); UI_Text_Paint( lineItem.textRect.x, lineItem.textRect.y, - lineItem.textscale, color, buff, 0, 0, - lineItem.textStyle ); + lineItem.textscale, color, buff, 0, 0, + lineItem.textStyle ); UI_AddCacheEntryLine( buff, lineItem.textRect.x, lineItem.textRect.y ); lineNum++; @@ -4140,98 +4780,70 @@ void UI_DrawTextBlock( rectDef_t *rect, float text_x, float text_y, vec4_t color Item_Text_Wrapped_Paint( &textItem ); } -void Item_Text_Paint(itemDef_t *item) { +void Item_Text_Paint( itemDef_t *item ) +{ char text[1024]; const char *textPtr; int height, width; vec4_t color; - if (item->window.flags & WINDOW_WRAPPED) { - Item_Text_Wrapped_Paint(item); + if( item->window.flags & WINDOW_WRAPPED ) + { + Item_Text_Wrapped_Paint( item ); return; } - if (item->text == NULL) { - if (item->cvar == NULL) { + if( item->text == NULL ) + { + if( item->cvar == NULL ) return; - } - else { - DC->getCVarString(item->cvar, text, sizeof(text)); + else + { + DC->getCVarString( item->cvar, text, sizeof( text ) ); textPtr = text; } } - else { + else textPtr = item->text; - } // this needs to go here as it sets extents for cvar types as well - Item_SetTextExtents(item, &width, &height, textPtr); + Item_SetTextExtents( item, &width, &height, textPtr ); - if (*textPtr == '\0') { + if( *textPtr == '\0' ) return; - } - - - Item_TextColor(item, &color); - - //FIXME: this is a fucking mess -/* - adjust = 0; - if (item->textStyle == ITEM_TEXTSTYLE_OUTLINED || item->textStyle == ITEM_TEXTSTYLE_OUTLINESHADOWED) { - adjust = 0.5; - } - - if (item->textStyle == ITEM_TEXTSTYLE_SHADOWED || item->textStyle == ITEM_TEXTSTYLE_OUTLINESHADOWED) { - Fade(&item->window.flags, &DC->Assets.shadowColor[3], DC->Assets.fadeClamp, &item->window.nextTime, DC->Assets.fadeCycle, qfalse); - UI_Text_Paint(item->textRect.x + DC->Assets.shadowX, item->textRect.y + DC->Assets.shadowY, item->textscale, DC->Assets.shadowColor, textPtr, adjust); - } -*/ -// if (item->textStyle == ITEM_TEXTSTYLE_OUTLINED || item->textStyle == ITEM_TEXTSTYLE_OUTLINESHADOWED) { -// Fade(&item->window.flags, &item->window.outlineColor[3], DC->Assets.fadeClamp, &item->window.nextTime, DC->Assets.fadeCycle, qfalse); -// /* -// Text_Paint(item->textRect.x-1, item->textRect.y-1, item->textscale, item->window.foreColor, textPtr, adjust); -// Text_Paint(item->textRect.x, item->textRect.y-1, item->textscale, item->window.foreColor, textPtr, adjust); -// Text_Paint(item->textRect.x+1, item->textRect.y-1, item->textscale, item->window.foreColor, textPtr, adjust); -// Text_Paint(item->textRect.x-1, item->textRect.y, item->textscale, item->window.foreColor, textPtr, adjust); -// Text_Paint(item->textRect.x+1, item->textRect.y, item->textscale, item->window.foreColor, textPtr, adjust); -// Text_Paint(item->textRect.x-1, item->textRect.y+1, item->textscale, item->window.foreColor, textPtr, adjust); -// Text_Paint(item->textRect.x, item->textRect.y+1, item->textscale, item->window.foreColor, textPtr, adjust); -// Text_Paint(item->textRect.x+1, item->textRect.y+1, item->textscale, item->window.foreColor, textPtr, adjust); -// */ -// UI_Text_Paint(item->textRect.x - 1, item->textRect.y + 1, item->textscale * 1.02, item->window.outlineColor, textPtr, adjust); -// } + Item_TextColor( item, &color ); - UI_Text_Paint(item->textRect.x, item->textRect.y, item->textscale, color, textPtr, 0, 0, item->textStyle); + UI_Text_Paint( item->textRect.x, item->textRect.y, item->textscale, color, textPtr, 0, 0, item->textStyle ); } -void Item_TextField_Paint(itemDef_t *item) +void Item_TextField_Paint( itemDef_t *item ) { char buff[1024]; vec4_t newColor; - int offset = (item->text && *item->text) ? ITEM_VALUE_OFFSET : 0; - menuDef_t *parent = (menuDef_t*)item->parent; - editFieldDef_t *editPtr = (editFieldDef_t*)item->typeData; + int offset = ( item->text && *item->text ) ? ITEM_VALUE_OFFSET : 0; + menuDef_t *parent = ( menuDef_t* )item->parent; + editFieldDef_t *editPtr = ( editFieldDef_t* )item->typeData; char cursor = DC->getOverstrikeMode() ? '|' : '_'; qboolean editing = ( item->window.flags & WINDOW_HASFOCUS && g_editingField ); const int cursorWidth = editing ? EDIT_CURSOR_WIDTH : 0; //FIXME: causes duplicate printing if item->text is not set (NULL) - Item_Text_Paint(item); + Item_Text_Paint( item ); buff[0] = '\0'; - if (item->cvar) - DC->getCVarString(item->cvar, buff, sizeof(buff)); + if( item->cvar ) + DC->getCVarString( item->cvar, buff, sizeof( buff ) ); // maxFieldWidth hasn't been set, so use the item's rect if( editPtr->maxFieldWidth == 0 ) { editPtr->maxFieldWidth = item->window.rect.w - - ( item->textRect.w + offset + ( item->textRect.x - item->window.rect.x ) ); + ( item->textRect.w + offset + ( item->textRect.x - item->window.rect.x ) ); if( editPtr->maxFieldWidth < MIN_FIELD_WIDTH ) editPtr->maxFieldWidth = MIN_FIELD_WIDTH; @@ -4245,158 +4857,168 @@ void Item_TextField_Paint(itemDef_t *item) ( editPtr->maxFieldWidth - cursorWidth ) && strlen( buff ) > 0 ) buff[ strlen( buff ) - 1 ] = '\0'; - parent = (menuDef_t*)item->parent; + parent = ( menuDef_t* )item->parent; - if (item->window.flags & WINDOW_HASFOCUS) - memcpy(newColor, &parent->focusColor, sizeof(vec4_t)); + if( item->window.flags & WINDOW_HASFOCUS ) + memcpy( newColor, &parent->focusColor, sizeof( vec4_t ) ); else - memcpy(&newColor, &item->window.foreColor, sizeof(vec4_t)); + memcpy( &newColor, &item->window.foreColor, sizeof( vec4_t ) ); if( editing ) { UI_Text_PaintWithCursor( item->textRect.x + item->textRect.w + offset, - item->textRect.y, item->textscale, newColor, - buff + editPtr->paintOffset, - item->cursorPos - editPtr->paintOffset, - cursor, editPtr->maxPaintChars, item->textStyle ); + item->textRect.y, item->textscale, newColor, + buff + editPtr->paintOffset, + item->cursorPos - editPtr->paintOffset, + cursor, editPtr->maxPaintChars, item->textStyle ); } else { UI_Text_Paint( item->textRect.x + item->textRect.w + offset, - item->textRect.y, item->textscale, newColor, - buff + editPtr->paintOffset, 0, - editPtr->maxPaintChars, item->textStyle ); + item->textRect.y, item->textscale, newColor, + buff + editPtr->paintOffset, 0, + editPtr->maxPaintChars, item->textStyle ); } } -void Item_YesNo_Paint(itemDef_t *item) { +void Item_YesNo_Paint( itemDef_t *item ) +{ vec4_t newColor; float value; int offset; - menuDef_t *parent = (menuDef_t*)item->parent; + menuDef_t *parent = ( menuDef_t* )item->parent; - value = (item->cvar) ? DC->getCVarValue(item->cvar) : 0; + value = ( item->cvar ) ? DC->getCVarValue( item->cvar ) : 0; - if (item->window.flags & WINDOW_HASFOCUS) { - memcpy(newColor, &parent->focusColor, sizeof(vec4_t)); - } else { - memcpy(&newColor, &item->window.foreColor, sizeof(vec4_t)); - } + if( item->window.flags & WINDOW_HASFOCUS ) + memcpy( newColor, &parent->focusColor, sizeof( vec4_t ) ); + else + memcpy( &newColor, &item->window.foreColor, sizeof( vec4_t ) ); - offset = (item->text && *item->text) ? ITEM_VALUE_OFFSET : 0; - if (item->text) { - Item_Text_Paint(item); - UI_Text_Paint(item->textRect.x + item->textRect.w + offset, item->textRect.y, item->textscale, newColor, (value != 0) ? "Yes" : "No", 0, 0, item->textStyle); - } else { - UI_Text_Paint(item->textRect.x, item->textRect.y, item->textscale, newColor, (value != 0) ? "Yes" : "No", 0, 0, item->textStyle); + offset = ( item->text && *item->text ) ? ITEM_VALUE_OFFSET : 0; + + if( item->text ) + { + Item_Text_Paint( item ); + UI_Text_Paint( item->textRect.x + item->textRect.w + offset, item->textRect.y, item->textscale, + newColor, ( value != 0 ) ? "Yes" : "No", 0, 0, item->textStyle ); } + else + UI_Text_Paint( item->textRect.x, item->textRect.y, item->textscale, newColor, ( value != 0 ) ? "Yes" : "No", 0, 0, item->textStyle ); } -void Item_Multi_Paint(itemDef_t *item) { +void Item_Multi_Paint( itemDef_t *item ) +{ vec4_t newColor; const char *text = ""; - menuDef_t *parent = (menuDef_t*)item->parent; + menuDef_t *parent = ( menuDef_t* )item->parent; - if (item->window.flags & WINDOW_HASFOCUS) { - memcpy(newColor, &parent->focusColor, sizeof(vec4_t)); - } else { - memcpy(&newColor, &item->window.foreColor, sizeof(vec4_t)); - } + if( item->window.flags & WINDOW_HASFOCUS ) + memcpy( newColor, &parent->focusColor, sizeof( vec4_t ) ); + else + memcpy( &newColor, &item->window.foreColor, sizeof( vec4_t ) ); - text = Item_Multi_Setting(item); + text = Item_Multi_Setting( item ); - if (item->text) { - Item_Text_Paint(item); - UI_Text_Paint(item->textRect.x + item->textRect.w + ITEM_VALUE_OFFSET, item->textRect.y, item->textscale, newColor, text, 0, 0, item->textStyle); - } else { - UI_Text_Paint(item->textRect.x, item->textRect.y, item->textscale, newColor, text, 0, 0, item->textStyle); + if( item->text ) + { + Item_Text_Paint( item ); + UI_Text_Paint( item->textRect.x + item->textRect.w + ITEM_VALUE_OFFSET, item->textRect.y, + item->textscale, newColor, text, 0, 0, item->textStyle ); } + else + UI_Text_Paint( item->textRect.x, item->textRect.y, item->textscale, newColor, text, 0, 0, item->textStyle ); } -typedef struct { +typedef struct +{ char *command; int id; int defaultbind1; int defaultbind2; int bind1; int bind2; -} bind_t; +} + +bind_t; typedef struct { char* name; float defaultvalue; float value; -} configcvar_t; - +} -static bind_t g_bindings[] = -{ - { "+scores", K_TAB, -1, -1, -1 }, - { "+button2", K_ENTER, -1, -1, -1 }, - { "+speed", K_SHIFT, -1, -1, -1 }, - { "boost", 'x', -1, -1, -1 }, // human sprinting - { "+forward", K_UPARROW, -1, -1, -1 }, - { "+back", K_DOWNARROW, -1, -1, -1 }, - { "+moveleft", ',', -1, -1, -1 }, - { "+moveright", '.', -1, -1, -1 }, - { "+moveup", K_SPACE, -1, -1, -1 }, - { "+movedown", 'c', -1, -1, -1 }, - { "+left", K_LEFTARROW, -1, -1, -1 }, - { "+right", K_RIGHTARROW, -1, -1, -1 }, - { "+strafe", K_ALT, -1, -1, -1 }, - { "+lookup", K_PGDN, -1, -1, -1 }, - { "+lookdown", K_DEL, -1, -1, -1 }, - { "+mlook", '/', -1, -1, -1 }, - { "centerview", K_END, -1, -1, -1 }, - { "+zoom", -1, -1, -1, -1 }, - { "weapon 1", '1', -1, -1, -1 }, - { "weapon 2", '2', -1, -1, -1 }, - { "weapon 3", '3', -1, -1, -1 }, - { "weapon 4", '4', -1, -1, -1 }, - { "weapon 5", '5', -1, -1, -1 }, - { "weapon 6", '6', -1, -1, -1 }, - { "weapon 7", '7', -1, -1, -1 }, - { "weapon 8", '8', -1, -1, -1 }, - { "weapon 9", '9', -1, -1, -1 }, - { "weapon 10", '0', -1, -1, -1 }, - { "weapon 11", -1, -1, -1, -1 }, - { "weapon 12", -1, -1, -1, -1 }, - { "weapon 13", -1, -1, -1, -1 }, - { "+attack", K_MOUSE1, -1, -1, -1 }, - { "+button5", K_MOUSE2, -1, -1, -1 }, // secondary attack - { "reload", 'r', -1, -1, -1 }, // reload - { "buy ammo", 'b', -1, -1, -1 }, // buy ammo - { "itemact medkit", 'm', -1, -1, -1 }, // use medkit - { "+button7", 'q', -1, -1, -1 }, // buildable use - { "deconstruct", 'e', -1, -1, -1 }, // buildable destroy - { "weapprev", '[', -1, -1, -1 }, - { "weapnext", ']', -1, -1, -1 }, - { "+button3", K_MOUSE3, -1, -1, -1 }, - { "+button4", K_MOUSE4, -1, -1, -1 }, - { "vote yes", K_F1, -1, -1, -1 }, - { "vote no", K_F2, -1, -1, -1 }, - { "teamvote yes", K_F3, -1, -1, -1 }, - { "teamvote no", K_F4, -1, -1, -1 }, - { "scoresUp", K_KP_PGUP, -1, -1, -1 }, - { "scoresDown", K_KP_PGDN, -1, -1, -1 }, - { "messagemode", -1, -1, -1, -1 }, - { "messagemode2", -1, -1, -1, -1 }, - { "messagemode3", -1, -1, -1, -1 }, - { "messagemode4", -1, -1, -1, -1 } -}; +configcvar_t; -static const int g_bindCount = sizeof(g_bindings) / sizeof(bind_t); +static bind_t g_bindings[] = + { + { "+scores", K_TAB, -1, -1, -1 }, + { "+button2", K_ENTER, -1, -1, -1 }, + { "+speed", K_SHIFT, -1, -1, -1 }, + { "boost", 'x', -1, -1, -1 }, // human sprinting + { "+forward", K_UPARROW, -1, -1, -1 }, + { "+back", K_DOWNARROW, -1, -1, -1 }, + { "+moveleft", ',', -1, -1, -1 }, + { "+moveright", '.', -1, -1, -1 }, + { "+moveup", K_SPACE, -1, -1, -1 }, + { "+movedown", 'c', -1, -1, -1 }, + { "+left", K_LEFTARROW, -1, -1, -1 }, + { "+right", K_RIGHTARROW, -1, -1, -1 }, + { "+strafe", K_ALT, -1, -1, -1 }, + { "+lookup", K_PGDN, -1, -1, -1 }, + { "+lookdown", K_DEL, -1, -1, -1 }, + { "+mlook", '/', -1, -1, -1 }, + { "centerview", K_END, -1, -1, -1 }, + { "+zoom", -1, -1, -1, -1 }, + { "weapon 1", '1', -1, -1, -1 }, + { "weapon 2", '2', -1, -1, -1 }, + { "weapon 3", '3', -1, -1, -1 }, + { "weapon 4", '4', -1, -1, -1 }, + { "weapon 5", '5', -1, -1, -1 }, + { "weapon 6", '6', -1, -1, -1 }, + { "weapon 7", '7', -1, -1, -1 }, + { "weapon 8", '8', -1, -1, -1 }, + { "weapon 9", '9', -1, -1, -1 }, + { "weapon 10", '0', -1, -1, -1 }, + { "weapon 11", -1, -1, -1, -1 }, + { "weapon 12", -1, -1, -1, -1 }, + { "weapon 13", -1, -1, -1, -1 }, + { "+attack", K_MOUSE1, -1, -1, -1 }, + { "+button5", K_MOUSE2, -1, -1, -1 }, // secondary attack + { "reload", 'r', -1, -1, -1 }, // reload + { "buy ammo", 'b', -1, -1, -1 }, // buy ammo + { "itemact medkit", 'm', -1, -1, -1 }, // use medkit + { "+button7", 'q', -1, -1, -1 }, // buildable use + { "deconstruct", 'e', -1, -1, -1 }, // buildable destroy + { "weapprev", '[', -1, -1, -1 }, + { "weapnext", ']', -1, -1, -1 }, + { "+button3", K_MOUSE3, -1, -1, -1 }, + { "+button4", K_MOUSE4, -1, -1, -1 }, + { "vote yes", K_F1, -1, -1, -1 }, + { "vote no", K_F2, -1, -1, -1 }, + { "teamvote yes", K_F3, -1, -1, -1 }, + { "teamvote no", K_F4, -1, -1, -1 }, + { "scoresUp", K_KP_PGUP, -1, -1, -1 }, + { "scoresDown", K_KP_PGDN, -1, -1, -1 }, + { "messagemode", -1, -1, -1, -1 }, + { "messagemode2", -1, -1, -1, -1 }, + { "messagemode3", -1, -1, -1, -1 }, + { "messagemode4", -1, -1, -1, -1 } + }; + + +static const int g_bindCount = sizeof( g_bindings ) / sizeof( bind_t ); /* ================= Controls_GetKeyAssignment ================= */ -static void Controls_GetKeyAssignment (char *command, int *twokeys) +static void Controls_GetKeyAssignment ( char *command, int *twokeys ) { int count; int j; @@ -4405,18 +5027,20 @@ static void Controls_GetKeyAssignment (char *command, int *twokeys) twokeys[0] = twokeys[1] = -1; count = 0; - for ( j = 0; j < 256; j++ ) + for( j = 0; j < 256; j++ ) { DC->getBindingBuf( j, b, 256 ); - if ( *b == 0 ) { + + if( *b == 0 ) continue; - } - if ( !Q_stricmp( b, command ) ) { + + if( !Q_stricmp( b, command ) ) + { twokeys[count] = j; count++; - if (count == 2) { + + if( count == 2 ) break; - } } } } @@ -4432,6 +5056,7 @@ void Controls_GetConfig( void ) int twokeys[ 2 ]; // iterate each command, get its numeric binding + for( i = 0; i < g_bindCount; i++ ) { Controls_GetKeyAssignment( g_bindings[ i ].command, twokeys ); @@ -4439,15 +5064,6 @@ void Controls_GetConfig( void ) g_bindings[ i ].bind1 = twokeys[ 0 ]; g_bindings[ i ].bind2 = twokeys[ 1 ]; } - - //s_controls.invertmouse.curvalue = DC->getCVarValue( "m_pitch" ) < 0; - //s_controls.smoothmouse.curvalue = UI_ClampCvar( 0, 1, Controls_GetCvarValue( "m_filter" ) ); - //s_controls.alwaysrun.curvalue = UI_ClampCvar( 0, 1, Controls_GetCvarValue( "cl_run" ) ); - //s_controls.autoswitch.curvalue = UI_ClampCvar( 0, 1, Controls_GetCvarValue( "cg_autoswitch" ) ); - //s_controls.sensitivity.curvalue = UI_ClampCvar( 2, 30, Controls_GetCvarValue( "sensitivity" ) ); - //s_controls.joyenable.curvalue = UI_ClampCvar( 0, 1, Controls_GetCvarValue( "in_joystick" ) ); - //s_controls.joythreshold.curvalue = UI_ClampCvar( 0.05, 0.75, Controls_GetCvarValue( "joy_threshold" ) ); - //s_controls.freelook.curvalue = UI_ClampCvar( 0, 1, Controls_GetCvarValue( "cl_freelook" ) ); } /* @@ -4455,37 +5071,24 @@ void Controls_GetConfig( void ) Controls_SetConfig ================= */ -void Controls_SetConfig(qboolean restart) +void Controls_SetConfig( qboolean restart ) { int i; // iterate each command, get its numeric binding - for (i=0; i < g_bindCount; i++) - { - if (g_bindings[i].bind1 != -1) + for( i = 0; i < g_bindCount; i++ ) + { + if( g_bindings[i].bind1 != -1 ) { DC->setBinding( g_bindings[i].bind1, g_bindings[i].command ); - if (g_bindings[i].bind2 != -1) + if( g_bindings[i].bind2 != -1 ) DC->setBinding( g_bindings[i].bind2, g_bindings[i].command ); } } - //if ( s_controls.invertmouse.curvalue ) - // DC->setCVar("m_pitch", va("%f),-fabs( DC->getCVarValue( "m_pitch" ) ) ); - //else - // trap_Cvar_SetValue( "m_pitch", fabs( DC->getCVarValue( "m_pitch" ) ) ); - - //trap_Cvar_SetValue( "m_filter", s_controls.smoothmouse.curvalue ); - //trap_Cvar_SetValue( "cl_run", s_controls.alwaysrun.curvalue ); - //trap_Cvar_SetValue( "cg_autoswitch", s_controls.autoswitch.curvalue ); - //trap_Cvar_SetValue( "sensitivity", s_controls.sensitivity.curvalue ); - //trap_Cvar_SetValue( "in_joystick", s_controls.joyenable.curvalue ); - //trap_Cvar_SetValue( "joy_threshold", s_controls.joythreshold.curvalue ); - //trap_Cvar_SetValue( "cl_freelook", s_controls.freelook.curvalue ); - DC->executeText(EXEC_APPEND, "in_restart\n"); - //trap_Cmd_ExecuteText( EXEC_APPEND, "in_restart\n" ); + DC->executeText( EXEC_APPEND, "in_restart\n" ); } /* @@ -4498,114 +5101,121 @@ void Controls_SetDefaults( void ) int i; // iterate each command, set its default binding - for (i=0; i < g_bindCount; i++) + + for( i = 0; i < g_bindCount; i++ ) { g_bindings[i].bind1 = g_bindings[i].defaultbind1; g_bindings[i].bind2 = g_bindings[i].defaultbind2; } - - //s_controls.invertmouse.curvalue = Controls_GetCvarDefault( "m_pitch" ) < 0; - //s_controls.smoothmouse.curvalue = Controls_GetCvarDefault( "m_filter" ); - //s_controls.alwaysrun.curvalue = Controls_GetCvarDefault( "cl_run" ); - //s_controls.autoswitch.curvalue = Controls_GetCvarDefault( "cg_autoswitch" ); - //s_controls.sensitivity.curvalue = Controls_GetCvarDefault( "sensitivity" ); - //s_controls.joyenable.curvalue = Controls_GetCvarDefault( "in_joystick" ); - //s_controls.joythreshold.curvalue = Controls_GetCvarDefault( "joy_threshold" ); - //s_controls.freelook.curvalue = Controls_GetCvarDefault( "cl_freelook" ); } -int BindingIDFromName(const char *name) { +int BindingIDFromName( const char *name ) +{ int i; - for (i=0; i < g_bindCount; i++) + + for( i = 0; i < g_bindCount; i++ ) { - if (Q_stricmp(name, g_bindings[i].command) == 0) { + if( Q_stricmp( name, g_bindings[i].command ) == 0 ) return i; - } } + return -1; } char g_nameBind1[32]; char g_nameBind2[32]; -void BindingFromName(const char *cvar) { +void BindingFromName( const char *cvar ) +{ int i, b1, b2; // iterate each command, set its default binding - for (i=0; i < g_bindCount; i++) + + for( i = 0; i < g_bindCount; i++ ) { - if (Q_stricmp(cvar, g_bindings[i].command) == 0) { + if( Q_stricmp( cvar, g_bindings[i].command ) == 0 ) + { b1 = g_bindings[i].bind1; - if (b1 == -1) { + + if( b1 == -1 ) break; + + DC->keynumToStringBuf( b1, g_nameBind1, 32 ); + Q_strupr( g_nameBind1 ); + + b2 = g_bindings[i].bind2; + + if( b2 != -1 ) + { + DC->keynumToStringBuf( b2, g_nameBind2, 32 ); + Q_strupr( g_nameBind2 ); + strcat( g_nameBind1, " or " ); + strcat( g_nameBind1, g_nameBind2 ); } - DC->keynumToStringBuf( b1, g_nameBind1, 32 ); - Q_strupr(g_nameBind1); - b2 = g_bindings[i].bind2; - if (b2 != -1) - { - DC->keynumToStringBuf( b2, g_nameBind2, 32 ); - Q_strupr(g_nameBind2); - strcat( g_nameBind1, " or " ); - strcat( g_nameBind1, g_nameBind2 ); - } return; } } - strcpy(g_nameBind1, "???"); + + strcpy( g_nameBind1, "???" ); } -void Item_Slider_Paint(itemDef_t *item) { +void Item_Slider_Paint( itemDef_t *item ) +{ vec4_t newColor; float x, y, value; - menuDef_t *parent = (menuDef_t*)item->parent; + menuDef_t *parent = ( menuDef_t* )item->parent; float vScale = Item_Slider_VScale( item ); - value = (item->cvar) ? DC->getCVarValue(item->cvar) : 0; + value = ( item->cvar ) ? DC->getCVarValue( item->cvar ) : 0; - if (item->window.flags & WINDOW_HASFOCUS) { - memcpy(newColor, &parent->focusColor, sizeof(vec4_t)); - } else { - memcpy(&newColor, &item->window.foreColor, sizeof(vec4_t)); - } + if( item->window.flags & WINDOW_HASFOCUS ) + memcpy( newColor, &parent->focusColor, sizeof( vec4_t ) ); + else + memcpy( &newColor, &item->window.foreColor, sizeof( vec4_t ) ); - if (item->text) { - Item_Text_Paint(item); + if( item->text ) + { + Item_Text_Paint( item ); x = item->textRect.x + item->textRect.w + ITEM_VALUE_OFFSET; y = item->textRect.y - item->textRect.h + - ( ( item->textRect.h - ( SLIDER_HEIGHT * vScale ) ) / 2.0f ); - } else { + ( ( item->textRect.h - ( SLIDER_HEIGHT * vScale ) ) / 2.0f ); + } + else + { x = item->window.rect.x; y = item->window.rect.y; } - DC->setColor(newColor); + DC->setColor( newColor ); DC->drawHandlePic( x, y, SLIDER_WIDTH, SLIDER_HEIGHT * vScale, DC->Assets.sliderBar ); y = item->textRect.y - item->textRect.h + - ( ( item->textRect.h - ( SLIDER_THUMB_HEIGHT * vScale ) ) / 2.0f ); + ( ( item->textRect.h - ( SLIDER_THUMB_HEIGHT * vScale ) ) / 2.0f ); - x = Item_Slider_ThumbPosition(item); - DC->drawHandlePic( x - (SLIDER_THUMB_WIDTH / 2), y, - SLIDER_THUMB_WIDTH, SLIDER_THUMB_HEIGHT * vScale, DC->Assets.sliderThumb ); + x = Item_Slider_ThumbPosition( item ); + DC->drawHandlePic( x - ( SLIDER_THUMB_WIDTH / 2 ), y, + SLIDER_THUMB_WIDTH, SLIDER_THUMB_HEIGHT * vScale, DC->Assets.sliderThumb ); } -void Item_Bind_Paint(itemDef_t *item) { +void Item_Bind_Paint( itemDef_t *item ) +{ vec4_t newColor, lowLight; float value; int maxChars = 0; - menuDef_t *parent = (menuDef_t*)item->parent; - editFieldDef_t *editPtr = (editFieldDef_t*)item->typeData; - if (editPtr) { + menuDef_t *parent = ( menuDef_t* )item->parent; + editFieldDef_t *editPtr = ( editFieldDef_t* )item->typeData; + + if( editPtr ) maxChars = editPtr->maxPaintChars; - } - value = (item->cvar) ? DC->getCVarValue(item->cvar) : 0; + value = ( item->cvar ) ? DC->getCVarValue( item->cvar ) : 0; - if (item->window.flags & WINDOW_HASFOCUS) { - if (g_bindItem == item) { + if( item->window.flags & WINDOW_HASFOCUS ) + { + if( g_bindItem == item ) + { lowLight[0] = 0.8f * parent->focusColor[0]; lowLight[1] = 0.8f * parent->focusColor[1]; lowLight[2] = 0.8f * parent->focusColor[2]; @@ -4613,71 +5223,78 @@ void Item_Bind_Paint(itemDef_t *item) { LerpColor( parent->focusColor, lowLight, newColor, 0.5 + 0.5 * sin( DC->realTime / PULSE_DIVISOR ) ); - } else { - memcpy(&newColor, &parent->focusColor, sizeof(vec4_t)); } - } else { - memcpy(&newColor, &item->window.foreColor, sizeof(vec4_t)); + else + memcpy( &newColor, &parent->focusColor, sizeof( vec4_t ) ); } + else + memcpy( &newColor, &item->window.foreColor, sizeof( vec4_t ) ); - if (item->text) { - Item_Text_Paint(item); + if( item->text ) + { + Item_Text_Paint( item ); if( g_bindItem == item && g_waitingForKey ) { UI_Text_Paint( item->textRect.x + item->textRect.w + ITEM_VALUE_OFFSET, item->textRect.y, - item->textscale, newColor, "Press key", 0, maxChars, item->textStyle); + item->textscale, newColor, "Press key", 0, maxChars, item->textStyle ); } else { - BindingFromName(item->cvar); + BindingFromName( item->cvar ); UI_Text_Paint( item->textRect.x + item->textRect.w + ITEM_VALUE_OFFSET, item->textRect.y, - item->textscale, newColor, g_nameBind1, 0, maxChars, item->textStyle); + item->textscale, newColor, g_nameBind1, 0, maxChars, item->textStyle ); } - } else { - UI_Text_Paint(item->textRect.x, item->textRect.y, item->textscale, newColor, (value != 0) ? "FIXME" : "FIXME", 0, maxChars, item->textStyle); } + else + UI_Text_Paint( item->textRect.x, item->textRect.y, item->textscale, newColor, + ( value != 0 ) ? "FIXME" : "FIXME", 0, maxChars, item->textStyle ); } -qboolean Display_KeyBindPending( void ) { +qboolean Display_KeyBindPending( void ) +{ return g_waitingForKey; } -qboolean Item_Bind_HandleKey(itemDef_t *item, int key, qboolean down) { +qboolean Item_Bind_HandleKey( itemDef_t *item, int key, qboolean down ) +{ int id; int i; - if (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory) && !g_waitingForKey) + if( Rect_ContainsPoint( &item->window.rect, DC->cursorx, DC->cursory ) && !g_waitingForKey ) { - if (down && (key == K_MOUSE1 || key == K_ENTER)) { + if( down && ( key == K_MOUSE1 || key == K_ENTER ) ) + { g_waitingForKey = qtrue; g_bindItem = item; } + return qtrue; } else { - if (!g_waitingForKey || g_bindItem == NULL) { + if( !g_waitingForKey || g_bindItem == NULL ) return qtrue; - } - if (key & K_CHAR_FLAG) { + if( key & K_CHAR_FLAG ) return qtrue; - } - switch (key) + switch( key ) { case K_ESCAPE: g_waitingForKey = qfalse; return qtrue; case K_BACKSPACE: - id = BindingIDFromName(item->cvar); - if (id != -1) { + id = BindingIDFromName( item->cvar ); + + if( id != -1 ) + { g_bindings[id].bind1 = -1; g_bindings[id].bind2 = -1; } - Controls_SetConfig(qtrue); + + Controls_SetConfig( qtrue ); g_waitingForKey = qfalse; g_bindItem = NULL; return qtrue; @@ -4687,17 +5304,14 @@ qboolean Item_Bind_HandleKey(itemDef_t *item, int key, qboolean down) { } } - if (key != -1) + if( key != -1 ) { - - for (i=0; i < g_bindCount; i++) + for( i = 0; i < g_bindCount; i++ ) { - - if (g_bindings[i].bind2 == key) { + if( g_bindings[i].bind2 == key ) g_bindings[i].bind2 = -1; - } - if (g_bindings[i].bind1 == key) + if( g_bindings[i].bind1 == key ) { g_bindings[i].bind1 = g_bindings[i].bind2; g_bindings[i].bind2 = -1; @@ -4706,26 +5320,30 @@ qboolean Item_Bind_HandleKey(itemDef_t *item, int key, qboolean down) { } - id = BindingIDFromName(item->cvar); + id = BindingIDFromName( item->cvar ); - if (id != -1) { - if (key == -1) { - if( g_bindings[id].bind1 != -1 ) { + if( id != -1 ) + { + if( key == -1 ) + { + if( g_bindings[id].bind1 != -1 ) + { DC->setBinding( g_bindings[id].bind1, "" ); g_bindings[id].bind1 = -1; } - if( g_bindings[id].bind2 != -1 ) { + + if( g_bindings[id].bind2 != -1 ) + { DC->setBinding( g_bindings[id].bind2, "" ); g_bindings[id].bind2 = -1; } } - else if (g_bindings[id].bind1 == -1) { + else if( g_bindings[id].bind1 == -1 ) g_bindings[id].bind1 = key; - } - else if (g_bindings[id].bind1 != key && g_bindings[id].bind2 == -1) { + else if( g_bindings[id].bind1 != key && g_bindings[id].bind2 == -1 ) g_bindings[id].bind2 = key; - } - else { + else + { DC->setBinding( g_bindings[id].bind1, "" ); DC->setBinding( g_bindings[id].bind2, "" ); g_bindings[id].bind1 = key; @@ -4733,7 +5351,7 @@ qboolean Item_Bind_HandleKey(itemDef_t *item, int key, qboolean down) { } } - Controls_SetConfig(qtrue); + Controls_SetConfig( qtrue ); g_waitingForKey = qfalse; return qtrue; @@ -4741,7 +5359,8 @@ qboolean Item_Bind_HandleKey(itemDef_t *item, int key, qboolean down) { -void AdjustFrom640(float *x, float *y, float *w, float *h) { +void AdjustFrom640( float *x, float *y, float *w, float *h ) +{ //*x = *x * DC->scale + DC->bias; *x *= DC->xscale; *y *= DC->yscale; @@ -4749,26 +5368,29 @@ void AdjustFrom640(float *x, float *y, float *w, float *h) { *h *= DC->yscale; } -void Item_Model_Paint(itemDef_t *item) { +void Item_Model_Paint( itemDef_t *item ) +{ float x, y, w, h; refdef_t refdef; refEntity_t ent; vec3_t mins, maxs, origin; vec3_t angles; - modelDef_t *modelPtr = (modelDef_t*)item->typeData; + modelDef_t *modelPtr = ( modelDef_t* )item->typeData; - if (modelPtr == NULL) { + if( modelPtr == NULL ) return; - } // setup the refdef memset( &refdef, 0, sizeof( refdef ) ); + refdef.rdflags = RDF_NOWORLDMODEL; + AxisClear( refdef.viewaxis ); - x = item->window.rect.x+1; - y = item->window.rect.y+1; - w = item->window.rect.w-2; - h = item->window.rect.h-2; + + x = item->window.rect.x + 1; + y = item->window.rect.y + 1; + w = item->window.rect.w - 2; + h = item->window.rect.h - 2; AdjustFrom640( &x, &y, &w, &h ); @@ -4783,15 +5405,17 @@ void Item_Model_Paint(itemDef_t *item) { origin[1] = 0.5 * ( mins[1] + maxs[1] ); // calculate distance so the model nearly fills the box - if (qtrue) { + if( qtrue ) + { float len = 0.5 * ( maxs[2] - mins[2] ); origin[0] = len / 0.268; // len / tan( fov/2 ) //origin[0] = len / tan(w/2); - } else { - origin[0] = item->textscale; } - refdef.fov_x = (modelPtr->fov_x) ? modelPtr->fov_x : w; - refdef.fov_y = (modelPtr->fov_y) ? modelPtr->fov_y : h; + else + origin[0] = item->textscale; + + refdef.fov_x = ( modelPtr->fov_x ) ? modelPtr->fov_x : w; + refdef.fov_y = ( modelPtr->fov_y ) ? modelPtr->fov_y : h; //refdef.fov_x = (int)((float)refdef.width / 640.0f * 90.0f); //xx = refdef.width / tan( refdef.fov_x / 360 * M_PI ); @@ -4804,19 +5428,23 @@ void Item_Model_Paint(itemDef_t *item) { // add the model - memset( &ent, 0, sizeof(ent) ); + memset( &ent, 0, sizeof( ent ) ); //adjust = 5.0 * sin( (float)uis.realtime / 500 ); //adjust = 360 % (int)((float)uis.realtime / 1000); //VectorSet( angles, 0, 0, 1 ); // use item storage to track - if (modelPtr->rotationSpeed) { - if (DC->realTime > item->window.nextTime) { + + if( modelPtr->rotationSpeed ) + { + if( DC->realTime > item->window.nextTime ) + { item->window.nextTime = DC->realTime + modelPtr->rotationSpeed; - modelPtr->angle = (int)(modelPtr->angle + 1) % 360; + modelPtr->angle = ( int )( modelPtr->angle + 1 ) % 360; } } + VectorSet( angles, 0, modelPtr->angle, 0 ); AnglesToAxis( angles, ent.axis ); @@ -4832,20 +5460,23 @@ void Item_Model_Paint(itemDef_t *item) { } -void Item_Image_Paint(itemDef_t *item) { - if (item == NULL) { +void Item_Image_Paint( itemDef_t *item ) +{ + if( item == NULL ) return; - } - DC->drawHandlePic(item->window.rect.x+1, item->window.rect.y+1, item->window.rect.w-2, item->window.rect.h-2, item->asset); + + DC->drawHandlePic( item->window.rect.x + 1, item->window.rect.y + 1, + item->window.rect.w - 2, item->window.rect.h - 2, item->asset ); } -void Item_ListBox_Paint(itemDef_t *item) { +void Item_ListBox_Paint( itemDef_t *item ) +{ float x, y, size, thumb; int i, count; qhandle_t image; qhandle_t optionalImage; - listBoxDef_t *listPtr = (listBoxDef_t*)item->typeData; - menuDef_t *menu = (menuDef_t *)item->parent; + listBoxDef_t *listPtr = ( listBoxDef_t* )item->typeData; + menuDef_t *menu = ( menuDef_t * )item->parent; float one, two; if( menu->window.aspectBias != ASPECT_NONE || item->window.aspectBias != ASPECT_NONE ) @@ -4863,28 +5494,32 @@ void Item_ListBox_Paint(itemDef_t *item) { // elements are enumerated from the DC and either text or image handles are acquired from the DC as well // textscale is used to size the text, textalignx and textaligny are used to size image elements // there is no clipping available so only the last completely visible item is painted - count = DC->feederCount(item->special); + count = DC->feederCount( item->special ); + // default is vertical if horizontal flag is not here - if (item->window.flags & WINDOW_HORIZONTAL) { + if( item->window.flags & WINDOW_HORIZONTAL ) + { //FIXME: unmaintained cruft? + if( !listPtr->noscrollbar ) { // draw scrollbar in bottom of the window // bar x = item->window.rect.x + 1; y = item->window.rect.y + item->window.rect.h - SCROLLBAR_HEIGHT - 1; - DC->drawHandlePic(x, y, SCROLLBAR_WIDTH, SCROLLBAR_HEIGHT, DC->Assets.scrollBarArrowLeft); + DC->drawHandlePic( x, y, SCROLLBAR_WIDTH, SCROLLBAR_HEIGHT, DC->Assets.scrollBarArrowLeft ); x += SCROLLBAR_WIDTH - 1; - size = item->window.rect.w - (SCROLLBAR_WIDTH * 2); - DC->drawHandlePic(x, y, size+1, SCROLLBAR_HEIGHT, DC->Assets.scrollBar); + size = item->window.rect.w - ( SCROLLBAR_WIDTH * 2 ); + DC->drawHandlePic( x, y, size + 1, SCROLLBAR_HEIGHT, DC->Assets.scrollBar ); x += size - 1; - DC->drawHandlePic(x, y, SCROLLBAR_WIDTH, SCROLLBAR_HEIGHT, DC->Assets.scrollBarArrowRight); + DC->drawHandlePic( x, y, SCROLLBAR_WIDTH, SCROLLBAR_HEIGHT, DC->Assets.scrollBarArrowRight ); // thumb - thumb = Item_ListBox_ThumbDrawPosition(item);//Item_ListBox_ThumbPosition(item); - if (thumb > x - SCROLLBAR_WIDTH - 1) { + thumb = Item_ListBox_ThumbDrawPosition( item );//Item_ListBox_ThumbPosition(item); + + if( thumb > x - SCROLLBAR_WIDTH - 1 ) thumb = x - SCROLLBAR_WIDTH - 1; - } - DC->drawHandlePic(thumb, y, SCROLLBAR_WIDTH, SCROLLBAR_HEIGHT, DC->Assets.scrollBarThumb); + + DC->drawHandlePic( thumb, y, SCROLLBAR_WIDTH, SCROLLBAR_HEIGHT, DC->Assets.scrollBarThumb ); // listPtr->endPos = listPtr->startPos; } @@ -4892,96 +5527,121 @@ void Item_ListBox_Paint(itemDef_t *item) { size = item->window.rect.w - 2; // items // size contains max available space - if (listPtr->elementStyle == LISTBOX_IMAGE) { + + if( listPtr->elementStyle == LISTBOX_IMAGE ) + { // fit = 0; x = item->window.rect.x + 1; y = item->window.rect.y + 1; - for (i = listPtr->startPos; i < count; i++) { + + for( i = listPtr->startPos; i < count; i++ ) + { // always draw at least one // which may overdraw the box if it is too small for the element - image = DC->feederItemImage(item->special, i); - if (image) { - DC->drawHandlePic(x+1, y+1, listPtr->elementWidth - 2, listPtr->elementHeight - 2, image); - } + image = DC->feederItemImage( item->special, i ); - if (i == item->cursorPos) { - DC->drawRect(x, y, listPtr->elementWidth-1, listPtr->elementHeight-1, item->window.borderSize, item->window.borderColor); + if( image ) + DC->drawHandlePic( x + 1, y + 1, listPtr->elementWidth - 2, listPtr->elementHeight - 2, image ); + + if( i == item->cursorPos ) + { + DC->drawRect( x, y, listPtr->elementWidth - 1, listPtr->elementHeight - 1, + item->window.borderSize, item->window.borderColor ); } listPtr->endPos++; size -= listPtr->elementWidth; - if (size < listPtr->elementWidth) { + + if( size < listPtr->elementWidth ) + { listPtr->drawPadding = size; //listPtr->elementWidth - size; break; } + x += listPtr->elementWidth; // fit++; } - } else { - // } - } else { + } + else + { if( !listPtr->noscrollbar ) { // draw scrollbar to right side of the window x = item->window.rect.x + item->window.rect.w - SCROLLBAR_WIDTH - one; y = item->window.rect.y + 1; - DC->drawHandlePic(x, y, SCROLLBAR_WIDTH, SCROLLBAR_HEIGHT, DC->Assets.scrollBarArrowUp); + DC->drawHandlePic( x, y, SCROLLBAR_WIDTH, SCROLLBAR_HEIGHT, DC->Assets.scrollBarArrowUp ); y += SCROLLBAR_HEIGHT - 1; listPtr->endPos = listPtr->startPos; - size = item->window.rect.h - (SCROLLBAR_HEIGHT * 2); - DC->drawHandlePic(x, y, SCROLLBAR_WIDTH, size+1, DC->Assets.scrollBar); + size = item->window.rect.h - ( SCROLLBAR_HEIGHT * 2 ); + DC->drawHandlePic( x, y, SCROLLBAR_WIDTH, size + 1, DC->Assets.scrollBar ); y += size - 1; - DC->drawHandlePic(x, y, SCROLLBAR_WIDTH, SCROLLBAR_HEIGHT, DC->Assets.scrollBarArrowDown); + DC->drawHandlePic( x, y, SCROLLBAR_WIDTH, SCROLLBAR_HEIGHT, DC->Assets.scrollBarArrowDown ); // thumb - thumb = Item_ListBox_ThumbDrawPosition(item);//Item_ListBox_ThumbPosition(item); - if (thumb > y - SCROLLBAR_HEIGHT - 1) { + thumb = Item_ListBox_ThumbDrawPosition( item );//Item_ListBox_ThumbPosition(item); + + if( thumb > y - SCROLLBAR_HEIGHT - 1 ) thumb = y - SCROLLBAR_HEIGHT - 1; - } - DC->drawHandlePic(x, thumb, SCROLLBAR_WIDTH, SCROLLBAR_HEIGHT, DC->Assets.scrollBarThumb); + + DC->drawHandlePic( x, thumb, SCROLLBAR_WIDTH, SCROLLBAR_HEIGHT, DC->Assets.scrollBarThumb ); } // adjust size for item painting size = item->window.rect.h - 2; - if (listPtr->elementStyle == LISTBOX_IMAGE) { + + if( listPtr->elementStyle == LISTBOX_IMAGE ) + { // fit = 0; x = item->window.rect.x + one; y = item->window.rect.y + 1; - for (i = listPtr->startPos; i < count; i++) { + + for( i = listPtr->startPos; i < count; i++ ) + { // always draw at least one // which may overdraw the box if it is too small for the element - image = DC->feederItemImage(item->special, i); - if (image) { - DC->drawHandlePic(x+one, y+1, listPtr->elementWidth - two, listPtr->elementHeight - 2, image); - } + image = DC->feederItemImage( item->special, i ); + + if( image ) + DC->drawHandlePic( x + one, y + 1, listPtr->elementWidth - two, listPtr->elementHeight - 2, image ); - if (i == item->cursorPos) { + if( i == item->cursorPos ) + { DC->drawRect( x, y, listPtr->elementWidth - one, listPtr->elementHeight - 1, - item->window.borderSize, item->window.borderColor); + item->window.borderSize, item->window.borderColor ); } listPtr->endPos++; size -= listPtr->elementWidth; - if (size < listPtr->elementHeight) { + + if( size < listPtr->elementHeight ) + { listPtr->drawPadding = listPtr->elementHeight - size; break; } + y += listPtr->elementHeight; // fit++; } - } else { + } + else + { float m = UI_Text_EmHeight( item->textscale ); x = item->window.rect.x + one; y = item->window.rect.y + 1; - for (i = listPtr->startPos; i < count; i++) { + + for( i = listPtr->startPos; i < count; i++ ) + { char text[ MAX_STRING_CHARS ]; // always draw at least one // which may overdraw the box if it is too small for the element - if (listPtr->numColumns > 0) { + if( listPtr->numColumns > 0 ) + { int j; - for (j = 0; j < listPtr->numColumns; j++) { + + for( j = 0; j < listPtr->numColumns; j++ ) + { float columnPos; float width, height; @@ -4998,16 +5658,21 @@ void Item_ListBox_Paint(itemDef_t *item) { height = listPtr->columnInfo[ j ].width; - Q_strncpyz( text, DC->feederItemText(item->special, i, j, &optionalImage), sizeof( text ) ); - if (optionalImage >= 0) { + Q_strncpyz( text, DC->feederItemText( item->special, i, j, &optionalImage ), sizeof( text ) ); + + if( optionalImage >= 0 ) + { DC->drawHandlePic( x + columnPos, y + ( ( listPtr->elementHeight - height ) / 2.0f ), - width, height, optionalImage); - } else if (text) { + width, height, optionalImage ); + } + else if( text ) + { int alignOffset = 0.0f, tw; tw = UI_Text_Width( text, item->textscale, 0 ); // Shorten the string if it's too long + while( tw > width && strlen( text ) > 0 ) { text[ strlen( text ) - 1 ] = '\0'; @@ -5033,12 +5698,14 @@ void Item_ListBox_Paint(itemDef_t *item) { } UI_Text_Paint( x + columnPos + alignOffset, - y + m + ( ( listPtr->elementHeight - m ) / 2.0f ), - item->textscale, item->window.foreColor, text, 0, - 0, item->textStyle ); + y + m + ( ( listPtr->elementHeight - m ) / 2.0f ), + item->textscale, item->window.foreColor, text, 0, + 0, item->textStyle ); } } - } else { + } + else + { float offset; if( menu->window.aspectBias != ASPECT_NONE || item->window.aspectBias != ASPECT_NONE ) @@ -5046,27 +5713,33 @@ void Item_ListBox_Paint(itemDef_t *item) { else offset = 4.0f; - Q_strncpyz( text, DC->feederItemText(item->special, i, 0, &optionalImage), sizeof( text ) ); - if (optionalImage >= 0) { - DC->drawHandlePic(x + offset, y, listPtr->elementHeight, listPtr->elementHeight, optionalImage); - } else if (text) { + Q_strncpyz( text, DC->feederItemText( item->special, i, 0, &optionalImage ), sizeof( text ) ); + + if( optionalImage >= 0 ) + DC->drawHandlePic( x + offset, y, listPtr->elementHeight, listPtr->elementHeight, optionalImage ); + else if( text ) + { UI_Text_Paint( x + offset, y + m + ( ( listPtr->elementHeight - m ) / 2.0f ), - item->textscale, item->window.foreColor, text, 0, - 0, item->textStyle ); + item->textscale, item->window.foreColor, text, 0, + 0, item->textStyle ); } } - if (i == item->cursorPos) { + if( i == item->cursorPos ) + { DC->fillRect( x, y, item->window.rect.w - SCROLLBAR_WIDTH - ( two * item->window.borderSize ), - listPtr->elementHeight, item->window.outlineColor); + listPtr->elementHeight, item->window.outlineColor ); } listPtr->endPos++; size -= listPtr->elementHeight; - if (size < listPtr->elementHeight) { + + if( size < listPtr->elementHeight ) + { listPtr->drawPadding = listPtr->elementHeight - size; break; } + y += listPtr->elementHeight; // fit++; } @@ -5077,84 +5750,99 @@ void Item_ListBox_Paint(itemDef_t *item) { listPtr->endPos--; } - -void Item_OwnerDraw_Paint(itemDef_t *item) { - menuDef_t *parent; +void Item_OwnerDraw_Paint( itemDef_t *item ) +{ + menuDef_t * parent; const char *text; - if (item == NULL) { + if( item == NULL ) return; - } - parent = (menuDef_t*)item->parent; - if (DC->ownerDrawItem) { + parent = ( menuDef_t* )item->parent; + + if( DC->ownerDrawItem ) + { vec4_t color, lowLight; - menuDef_t *parent = (menuDef_t*)item->parent; - Fade(&item->window.flags, &item->window.foreColor[3], parent->fadeClamp, &item->window.nextTime, parent->fadeCycle, qtrue, parent->fadeAmount); - memcpy(&color, &item->window.foreColor, sizeof(color)); - if (item->numColors > 0 && DC->getValue) { + menuDef_t *parent = ( menuDef_t* )item->parent; + Fade( &item->window.flags, &item->window.foreColor[3], parent->fadeClamp, &item->window.nextTime, + parent->fadeCycle, qtrue, parent->fadeAmount ); + memcpy( &color, &item->window.foreColor, sizeof( color ) ); + + if( item->numColors > 0 && DC->getValue ) + { // if the value is within one of the ranges then set color to that, otherwise leave at default int i; - float f = DC->getValue(item->window.ownerDraw); - for (i = 0; i < item->numColors; i++) { - if (f >= item->colorRanges[i].low && f <= item->colorRanges[i].high) { - memcpy(&color, &item->colorRanges[i].color, sizeof(color)); + float f = DC->getValue( item->window.ownerDraw ); + + for( i = 0; i < item->numColors; i++ ) + { + if( f >= item->colorRanges[i].low && f <= item->colorRanges[i].high ) + { + memcpy( &color, &item->colorRanges[i].color, sizeof( color ) ); break; } } } - if (item->window.flags & WINDOW_HASFOCUS) { - memcpy(color, &parent->focusColor, sizeof(vec4_t)); - } else if (item->textStyle == ITEM_TEXTSTYLE_BLINK && !((DC->realTime/BLINK_DIVISOR) & 1)) { + if( item->window.flags & WINDOW_HASFOCUS ) + memcpy( color, &parent->focusColor, sizeof( vec4_t ) ); + else if( item->textStyle == ITEM_TEXTSTYLE_BLINK && !( ( DC->realTime / BLINK_DIVISOR ) & 1 ) ) + { lowLight[0] = 0.8 * item->window.foreColor[0]; lowLight[1] = 0.8 * item->window.foreColor[1]; lowLight[2] = 0.8 * item->window.foreColor[2]; lowLight[3] = 0.8 * item->window.foreColor[3]; - LerpColor(item->window.foreColor,lowLight,color,0.5+0.5*sin(DC->realTime / PULSE_DIVISOR)); + LerpColor( item->window.foreColor, lowLight, color, 0.5 + 0.5 * sin( DC->realTime / PULSE_DIVISOR ) ); } - if (item->cvarFlags & (CVAR_ENABLE | CVAR_DISABLE) && !Item_EnableShowViaCvar(item, CVAR_ENABLE)) { - Com_Memcpy(color, parent->disableColor, sizeof(vec4_t)); - } + if( item->cvarFlags & ( CVAR_ENABLE | CVAR_DISABLE ) && !Item_EnableShowViaCvar( item, CVAR_ENABLE ) ) + Com_Memcpy( color, parent->disableColor, sizeof( vec4_t ) ); - if( DC->ownerDrawText && ( text = DC->ownerDrawText( item->window.ownerDraw ) ) ) { - if (item->text && *item->text) { - Item_Text_Paint(item); + if( DC->ownerDrawText && ( text = DC->ownerDrawText( item->window.ownerDraw ) ) ) + { + if( item->text && *item->text ) + { + Item_Text_Paint( item ); - UI_Text_Paint(item->textRect.x + item->textRect.w + ITEM_VALUE_OFFSET, - item->textRect.y, item->textscale, - color, text, 0, 0, item->textStyle); - } else { + UI_Text_Paint( item->textRect.x + item->textRect.w + ITEM_VALUE_OFFSET, + item->textRect.y, item->textscale, + color, text, 0, 0, item->textStyle ); + } + else + { item->text = text; - Item_Text_Paint(item); + Item_Text_Paint( item ); item->text = NULL; } - } else { - DC->ownerDrawItem(item->window.rect.x, item->window.rect.y, - item->window.rect.w, item->window.rect.h, - item->textalignx, item->textaligny, - item->window.ownerDraw, item->window.ownerDrawFlags, - item->alignment, item->textalignment, item->textvalignment, - item->special, item->textscale, color, - item->window.background, item->textStyle ); + } + else + { + DC->ownerDrawItem( item->window.rect.x, item->window.rect.y, + item->window.rect.w, item->window.rect.h, + item->textalignx, item->textaligny, + item->window.ownerDraw, item->window.ownerDrawFlags, + item->alignment, item->textalignment, item->textvalignment, + item->special, item->textscale, color, + item->window.background, item->textStyle ); } } } -void Item_Paint(itemDef_t *item) { +void Item_Paint( itemDef_t *item ) +{ vec4_t red; - menuDef_t *parent = (menuDef_t*)item->parent; + menuDef_t *parent = ( menuDef_t* )item->parent; red[0] = red[3] = 1; red[1] = red[2] = 0; - if (item == NULL) { + if( item == NULL ) return; - } - if (item->window.flags & WINDOW_ORBITING) { - if (DC->realTime > item->window.nextTime) { + if( item->window.flags & WINDOW_ORBITING ) + { + if( DC->realTime > item->window.nextTime ) + { float rx, ry, a, c, s, w, h; item->window.nextTime = DC->realTime + item->window.offsetTime; @@ -5164,215 +5852,279 @@ void Item_Paint(itemDef_t *item) { rx = item->window.rectClient.x + w - item->window.rectEffects.x; ry = item->window.rectClient.y + h - item->window.rectEffects.y; a = 3 * M_PI / 180; - c = cos(a); - s = sin(a); - item->window.rectClient.x = (rx * c - ry * s) + item->window.rectEffects.x - w; - item->window.rectClient.y = (rx * s + ry * c) + item->window.rectEffects.y - h; - Item_UpdatePosition(item); + c = cos( a ); + s = sin( a ); + item->window.rectClient.x = ( rx * c - ry * s ) + item->window.rectEffects.x - w; + item->window.rectClient.y = ( rx * s + ry * c ) + item->window.rectEffects.y - h; + Item_UpdatePosition( item ); } } - if (item->window.flags & WINDOW_INTRANSITION) { - if (DC->realTime > item->window.nextTime) { + if( item->window.flags & WINDOW_INTRANSITION ) + { + if( DC->realTime > item->window.nextTime ) + { int done = 0; item->window.nextTime = DC->realTime + item->window.offsetTime; // transition the x,y - if (item->window.rectClient.x == item->window.rectEffects.x) { + + if( item->window.rectClient.x == item->window.rectEffects.x ) done++; - } else { - if (item->window.rectClient.x < item->window.rectEffects.x) { + else + { + if( item->window.rectClient.x < item->window.rectEffects.x ) + { item->window.rectClient.x += item->window.rectEffects2.x; - if (item->window.rectClient.x > item->window.rectEffects.x) { + + if( item->window.rectClient.x > item->window.rectEffects.x ) + { item->window.rectClient.x = item->window.rectEffects.x; done++; } - } else { + } + else + { item->window.rectClient.x -= item->window.rectEffects2.x; - if (item->window.rectClient.x < item->window.rectEffects.x) { + + if( item->window.rectClient.x < item->window.rectEffects.x ) + { item->window.rectClient.x = item->window.rectEffects.x; done++; } } } - if (item->window.rectClient.y == item->window.rectEffects.y) { + + if( item->window.rectClient.y == item->window.rectEffects.y ) done++; - } else { - if (item->window.rectClient.y < item->window.rectEffects.y) { + else + { + if( item->window.rectClient.y < item->window.rectEffects.y ) + { item->window.rectClient.y += item->window.rectEffects2.y; - if (item->window.rectClient.y > item->window.rectEffects.y) { + + if( item->window.rectClient.y > item->window.rectEffects.y ) + { item->window.rectClient.y = item->window.rectEffects.y; done++; } - } else { + } + else + { item->window.rectClient.y -= item->window.rectEffects2.y; - if (item->window.rectClient.y < item->window.rectEffects.y) { + + if( item->window.rectClient.y < item->window.rectEffects.y ) + { item->window.rectClient.y = item->window.rectEffects.y; done++; } } } - if (item->window.rectClient.w == item->window.rectEffects.w) { + + if( item->window.rectClient.w == item->window.rectEffects.w ) done++; - } else { - if (item->window.rectClient.w < item->window.rectEffects.w) { + else + { + if( item->window.rectClient.w < item->window.rectEffects.w ) + { item->window.rectClient.w += item->window.rectEffects2.w; - if (item->window.rectClient.w > item->window.rectEffects.w) { + + if( item->window.rectClient.w > item->window.rectEffects.w ) + { item->window.rectClient.w = item->window.rectEffects.w; done++; } - } else { + } + else + { item->window.rectClient.w -= item->window.rectEffects2.w; - if (item->window.rectClient.w < item->window.rectEffects.w) { + + if( item->window.rectClient.w < item->window.rectEffects.w ) + { item->window.rectClient.w = item->window.rectEffects.w; done++; } } } - if (item->window.rectClient.h == item->window.rectEffects.h) { + + if( item->window.rectClient.h == item->window.rectEffects.h ) done++; - } else { - if (item->window.rectClient.h < item->window.rectEffects.h) { + else + { + if( item->window.rectClient.h < item->window.rectEffects.h ) + { item->window.rectClient.h += item->window.rectEffects2.h; - if (item->window.rectClient.h > item->window.rectEffects.h) { + + if( item->window.rectClient.h > item->window.rectEffects.h ) + { item->window.rectClient.h = item->window.rectEffects.h; done++; } - } else { + } + else + { item->window.rectClient.h -= item->window.rectEffects2.h; - if (item->window.rectClient.h < item->window.rectEffects.h) { + + if( item->window.rectClient.h < item->window.rectEffects.h ) + { item->window.rectClient.h = item->window.rectEffects.h; done++; } } } - Item_UpdatePosition(item); + Item_UpdatePosition( item ); - if (done == 4) { + if( done == 4 ) item->window.flags &= ~WINDOW_INTRANSITION; - } } } - if (item->window.ownerDrawFlags && DC->ownerDrawVisible) { - if (!DC->ownerDrawVisible(item->window.ownerDrawFlags)) { + if( item->window.ownerDrawFlags && DC->ownerDrawVisible ) + { + if( !DC->ownerDrawVisible( item->window.ownerDrawFlags ) ) item->window.flags &= ~WINDOW_VISIBLE; - } else { + else item->window.flags |= WINDOW_VISIBLE; - } } - if (item->cvarFlags & (CVAR_SHOW | CVAR_HIDE)) { - if (!Item_EnableShowViaCvar(item, CVAR_SHOW)) { + if( item->cvarFlags & ( CVAR_SHOW | CVAR_HIDE ) ) + { + if( !Item_EnableShowViaCvar( item, CVAR_SHOW ) ) return; - } } - if (item->window.flags & WINDOW_TIMEDVISIBLE) { - + if( item->window.flags & WINDOW_TIMEDVISIBLE ) + { } - if (!(item->window.flags & WINDOW_VISIBLE)) { + if( !( item->window.flags & WINDOW_VISIBLE ) ) return; - } - Window_Paint(&item->window, parent->fadeAmount , parent->fadeClamp, parent->fadeCycle); + Window_Paint( &item->window, parent->fadeAmount , parent->fadeClamp, parent->fadeCycle ); - if (DC->getCVarValue( "ui_developer" )) { + if( DC->getCVarValue( "ui_developer" ) ) + { vec4_t color; - rectDef_t *r = Item_CorrectedTextRect(item); + rectDef_t *r = Item_CorrectedTextRect( item ); color[1] = color[3] = 1; color[0] = color[2] = 0; - DC->drawRect(r->x, r->y, r->w, r->h, 1, color); + DC->drawRect( r->x, r->y, r->w, r->h, 1, color ); } - switch (item->type) { + switch( item->type ) + { case ITEM_TYPE_OWNERDRAW: - Item_OwnerDraw_Paint(item); + Item_OwnerDraw_Paint( item ); break; + case ITEM_TYPE_TEXT: case ITEM_TYPE_BUTTON: - Item_Text_Paint(item); + Item_Text_Paint( item ); break; + case ITEM_TYPE_RADIOBUTTON: break; + case ITEM_TYPE_CHECKBOX: break; + case ITEM_TYPE_EDITFIELD: case ITEM_TYPE_NUMERICFIELD: - Item_TextField_Paint(item); + Item_TextField_Paint( item ); break; + case ITEM_TYPE_COMBO: break; + case ITEM_TYPE_LISTBOX: - Item_ListBox_Paint(item); + Item_ListBox_Paint( item ); break; + //case ITEM_TYPE_IMAGE: // Item_Image_Paint(item); // break; + case ITEM_TYPE_MODEL: - Item_Model_Paint(item); + Item_Model_Paint( item ); break; + case ITEM_TYPE_YESNO: - Item_YesNo_Paint(item); + Item_YesNo_Paint( item ); break; + case ITEM_TYPE_MULTI: - Item_Multi_Paint(item); + Item_Multi_Paint( item ); break; + case ITEM_TYPE_BIND: - Item_Bind_Paint(item); + Item_Bind_Paint( item ); break; + case ITEM_TYPE_SLIDER: - Item_Slider_Paint(item); + Item_Slider_Paint( item ); break; + default: break; } - Border_Paint(&item->window); + Border_Paint( &item->window ); } -void Menu_Init(menuDef_t *menu) { - memset(menu, 0, sizeof(menuDef_t)); +void Menu_Init( menuDef_t *menu ) +{ + memset( menu, 0, sizeof( menuDef_t ) ); menu->cursorItem = -1; menu->fadeAmount = DC->Assets.fadeAmount; menu->fadeClamp = DC->Assets.fadeClamp; menu->fadeCycle = DC->Assets.fadeCycle; - Window_Init(&menu->window); + Window_Init( &menu->window ); menu->window.aspectBias = ALIGN_CENTER; } -itemDef_t *Menu_GetFocusedItem(menuDef_t *menu) { +itemDef_t *Menu_GetFocusedItem( menuDef_t *menu ) +{ int i; - if (menu) { - for (i = 0; i < menu->itemCount; i++) { - if (menu->items[i]->window.flags & WINDOW_HASFOCUS) { + + if( menu ) + { + for( i = 0; i < menu->itemCount; i++ ) + { + if( menu->items[i]->window.flags & WINDOW_HASFOCUS ) return menu->items[i]; - } } } + return NULL; } -menuDef_t *Menu_GetFocused( void ) { +menuDef_t *Menu_GetFocused( void ) +{ int i; - for (i = 0; i < menuCount; i++) { - if (Menus[i].window.flags & WINDOW_HASFOCUS && Menus[i].window.flags & WINDOW_VISIBLE) { - return &Menus[i]; - } + + for( i = 0; i < menuCount; i++ ) + { + if( Menus[i].window.flags & WINDOW_HASFOCUS && Menus[i].window.flags & WINDOW_VISIBLE ) + return & Menus[i]; } + return NULL; } -void Menu_ScrollFeeder(menuDef_t *menu, int feeder, qboolean down) { - if (menu) { +void Menu_ScrollFeeder( menuDef_t *menu, int feeder, qboolean down ) +{ + if( menu ) + { int i; - for (i = 0; i < menu->itemCount; i++) { - if (menu->items[i]->special == feeder) { - Item_ListBox_HandleKey(menu->items[i], (down) ? K_DOWNARROW : K_UPARROW, qtrue, qtrue); + + for( i = 0; i < menu->itemCount; i++ ) + { + if( menu->items[i]->special == feeder ) + { + Item_ListBox_HandleKey( menu->items[i], ( down ) ? K_DOWNARROW : K_UPARROW, qtrue, qtrue ); return; } } @@ -5381,185 +6133,207 @@ void Menu_ScrollFeeder(menuDef_t *menu, int feeder, qboolean down) { -void Menu_SetFeederSelection(menuDef_t *menu, int feeder, int index, const char *name) { - if (menu == NULL) { - if (name == NULL) { +void Menu_SetFeederSelection( menuDef_t *menu, int feeder, int index, const char *name ) +{ + if( menu == NULL ) + { + if( name == NULL ) menu = Menu_GetFocused(); - } else { - menu = Menus_FindByName(name); - } + else + menu = Menus_FindByName( name ); } - if (menu) { + if( menu ) + { int i; - for (i = 0; i < menu->itemCount; i++) { - if (menu->items[i]->special == feeder) { - if (index == 0) { - listBoxDef_t *listPtr = (listBoxDef_t*)menu->items[i]->typeData; + + for( i = 0; i < menu->itemCount; i++ ) + { + if( menu->items[i]->special == feeder ) + { + if( index == 0 ) + { + listBoxDef_t * listPtr = ( listBoxDef_t* )menu->items[i]->typeData; listPtr->cursorPos = 0; listPtr->startPos = 0; } + menu->items[i]->cursorPos = index; - DC->feederSelection(menu->items[i]->special, menu->items[i]->cursorPos); + DC->feederSelection( menu->items[i]->special, menu->items[i]->cursorPos ); return; } } } } -qboolean Menus_AnyFullScreenVisible( void ) { +qboolean Menus_AnyFullScreenVisible( void ) +{ int i; - for (i = 0; i < menuCount; i++) { - if (Menus[i].window.flags & WINDOW_VISIBLE && Menus[i].fullScreen) { + + for( i = 0; i < menuCount; i++ ) + { + if( Menus[i].window.flags & WINDOW_VISIBLE && Menus[i].fullScreen ) return qtrue; - } } + return qfalse; } -menuDef_t *Menus_ActivateByName(const char *p) { +menuDef_t *Menus_ActivateByName( const char *p ) +{ int i; menuDef_t *m = NULL; // Activate one menu - for (i = 0; i < menuCount; i++) { - if (Q_stricmp(Menus[i].window.name, p) == 0) { + + for( i = 0; i < menuCount; i++ ) + { + if( Q_stricmp( Menus[i].window.name, p ) == 0 ) + { m = &Menus[i]; - Menus_Activate(m); + Menus_Activate( m ); break; } } // Defocus the others - for (i = 0; i < menuCount; i++) { - if (Q_stricmp(Menus[i].window.name, p) != 0) { + for( i = 0; i < menuCount; i++ ) + { + if( Q_stricmp( Menus[i].window.name, p ) != 0 ) Menus[i].window.flags &= ~WINDOW_HASFOCUS; - } } return m; } -void Item_Init(itemDef_t *item) { - memset(item, 0, sizeof(itemDef_t)); +void Item_Init( itemDef_t *item ) +{ + memset( item, 0, sizeof( itemDef_t ) ); item->textscale = 0.55f; - Window_Init(&item->window); + Window_Init( &item->window ); item->window.aspectBias = ASPECT_NONE; } -void Menu_HandleMouseMove(menuDef_t *menu, float x, float y) { +void Menu_HandleMouseMove( menuDef_t *menu, float x, float y ) +{ int i, pass; qboolean focusSet = qfalse; itemDef_t *overItem; - if (menu == NULL) { + + if( menu == NULL ) return; - } - if (!(menu->window.flags & (WINDOW_VISIBLE | WINDOW_FORCED))) { + if( !( menu->window.flags & ( WINDOW_VISIBLE | WINDOW_FORCED ) ) ) return; - } - if (itemCapture) { + if( itemCapture ) + { //Item_MouseMove(itemCapture, x, y); return; } - if (g_waitingForKey || g_editingField) { + if( g_waitingForKey || g_editingField ) return; - } // FIXME: this is the whole issue of focus vs. mouse over.. // need a better overall solution as i don't like going through everything twice - for (pass = 0; pass < 2; pass++) { - for (i = 0; i < menu->itemCount; i++) { + for( pass = 0; pass < 2; pass++ ) + { + for( i = 0; i < menu->itemCount; i++ ) + { // turn off focus each item // menu->items[i].window.flags &= ~WINDOW_HASFOCUS; - if (!(menu->items[i]->window.flags & (WINDOW_VISIBLE | WINDOW_FORCED))) { + if( !( menu->items[i]->window.flags & ( WINDOW_VISIBLE | WINDOW_FORCED ) ) ) continue; - } // items can be enabled and disabled based on cvars - if (menu->items[i]->cvarFlags & (CVAR_ENABLE | CVAR_DISABLE) && !Item_EnableShowViaCvar(menu->items[i], CVAR_ENABLE)) { + if( menu->items[i]->cvarFlags & ( CVAR_ENABLE | CVAR_DISABLE ) && + !Item_EnableShowViaCvar( menu->items[i], CVAR_ENABLE ) ) continue; - } - if (menu->items[i]->cvarFlags & (CVAR_SHOW | CVAR_HIDE) && !Item_EnableShowViaCvar(menu->items[i], CVAR_SHOW)) { + if( menu->items[i]->cvarFlags & ( CVAR_SHOW | CVAR_HIDE ) && + !Item_EnableShowViaCvar( menu->items[i], CVAR_SHOW ) ) continue; - } - if (Rect_ContainsPoint(&menu->items[i]->window.rect, x, y)) { - if (pass == 1) { + if( Rect_ContainsPoint( &menu->items[i]->window.rect, x, y ) ) + { + if( pass == 1 ) + { overItem = menu->items[i]; - if (overItem->type == ITEM_TYPE_TEXT && overItem->text) { - if (!Rect_ContainsPoint(Item_CorrectedTextRect(overItem), x, y)) { + + if( overItem->type == ITEM_TYPE_TEXT && overItem->text ) + { + if( !Rect_ContainsPoint( Item_CorrectedTextRect( overItem ), x, y ) ) continue; - } } + // if we are over an item - if (IsVisible(overItem->window.flags)) { + if( IsVisible( overItem->window.flags ) ) + { // different one - Item_MouseEnter(overItem, x, y); + Item_MouseEnter( overItem, x, y ); // Item_SetMouseOver(overItem, qtrue); // if item is not a decoration see if it can take focus - if (!focusSet) { - focusSet = Item_SetFocus(overItem, x, y); - } + + if( !focusSet ) + focusSet = Item_SetFocus( overItem, x, y ); } } - } else if (menu->items[i]->window.flags & WINDOW_MOUSEOVER) { - Item_MouseLeave(menu->items[i]); - Item_SetMouseOver(menu->items[i], qfalse); + } + else if( menu->items[i]->window.flags & WINDOW_MOUSEOVER ) + { + Item_MouseLeave( menu->items[i] ); + Item_SetMouseOver( menu->items[i], qfalse ); } } } } -void Menu_Paint(menuDef_t *menu, qboolean forcePaint) { +void Menu_Paint( menuDef_t *menu, qboolean forcePaint ) +{ int i; - if (menu == NULL) { + if( menu == NULL ) return; - } - if (!(menu->window.flags & WINDOW_VISIBLE) && !forcePaint) { + if( !( menu->window.flags & WINDOW_VISIBLE ) && !forcePaint ) return; - } - if (menu->window.ownerDrawFlags && DC->ownerDrawVisible && !DC->ownerDrawVisible(menu->window.ownerDrawFlags)) { + if( menu->window.ownerDrawFlags && DC->ownerDrawVisible && !DC->ownerDrawVisible( menu->window.ownerDrawFlags ) ) return; - } - if (forcePaint) { + if( forcePaint ) menu->window.flags |= WINDOW_FORCED; - } // draw the background if necessary - if (menu->fullScreen) { + if( menu->fullScreen ) + { // implies a background shader // FIXME: make sure we have a default shader if fullscreen is set with no background DC->drawHandlePic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, menu->window.background ); } // paint the background and or border - Window_Paint(&menu->window, menu->fadeAmount, menu->fadeClamp, menu->fadeCycle ); - Border_Paint(&menu->window); + Window_Paint( &menu->window, menu->fadeAmount, menu->fadeClamp, menu->fadeCycle ); - for (i = 0; i < menu->itemCount; i++) { - Item_Paint(menu->items[i]); - } + Border_Paint( &menu->window ); - if (DC->getCVarValue( "ui_developer" )) { + for( i = 0; i < menu->itemCount; i++ ) + Item_Paint( menu->items[i] ); + + if( DC->getCVarValue( "ui_developer" ) ) + { vec4_t color; color[0] = color[2] = color[3] = 1; color[1] = 0; - DC->drawRect(menu->window.rect.x, menu->window.rect.y, menu->window.rect.w, menu->window.rect.h, 1, color); + DC->drawRect( menu->window.rect.x, menu->window.rect.y, menu->window.rect.w, menu->window.rect.h, 1, color ); } } @@ -5568,27 +6342,36 @@ void Menu_Paint(menuDef_t *menu, qboolean forcePaint) { Item_ValidateTypeData =============== */ -void Item_ValidateTypeData(itemDef_t *item) { - if (item->typeData) { +void Item_ValidateTypeData( itemDef_t *item ) +{ + if( item->typeData ) return; - } - if (item->type == ITEM_TYPE_LISTBOX) { - item->typeData = UI_Alloc(sizeof(listBoxDef_t)); - memset(item->typeData, 0, sizeof(listBoxDef_t)); - } else if (item->type == ITEM_TYPE_EDITFIELD || item->type == ITEM_TYPE_NUMERICFIELD || item->type == ITEM_TYPE_YESNO || item->type == ITEM_TYPE_BIND || item->type == ITEM_TYPE_SLIDER || item->type == ITEM_TYPE_TEXT) { - item->typeData = UI_Alloc(sizeof(editFieldDef_t)); - memset(item->typeData, 0, sizeof(editFieldDef_t)); - if (item->type == ITEM_TYPE_EDITFIELD) { - if (!((editFieldDef_t *) item->typeData)->maxPaintChars) { - ((editFieldDef_t *) item->typeData)->maxPaintChars = MAX_EDITFIELD; - } + if( item->type == ITEM_TYPE_LISTBOX ) + { + item->typeData = UI_Alloc( sizeof( listBoxDef_t ) ); + memset( item->typeData, 0, sizeof( listBoxDef_t ) ); + } + else if( item->type == ITEM_TYPE_EDITFIELD || + item->type == ITEM_TYPE_NUMERICFIELD || + item->type == ITEM_TYPE_YESNO || + item->type == ITEM_TYPE_BIND || + item->type == ITEM_TYPE_SLIDER || + item->type == ITEM_TYPE_TEXT ) + { + item->typeData = UI_Alloc( sizeof( editFieldDef_t ) ); + memset( item->typeData, 0, sizeof( editFieldDef_t ) ); + + if( item->type == ITEM_TYPE_EDITFIELD ) + { + if( !( ( editFieldDef_t * ) item->typeData )->maxPaintChars ) + ( ( editFieldDef_t * ) item->typeData )->maxPaintChars = MAX_EDITFIELD; } - } else if (item->type == ITEM_TYPE_MULTI) { - item->typeData = UI_Alloc(sizeof(multiDef_t)); - } else if (item->type == ITEM_TYPE_MODEL) { - item->typeData = UI_Alloc(sizeof(modelDef_t)); } + else if( item->type == ITEM_TYPE_MULTI ) + item->typeData = UI_Alloc( sizeof( multiDef_t ) ); + else if( item->type == ITEM_TYPE_MODEL ) + item->typeData = UI_Alloc( sizeof( modelDef_t ) ); } /* @@ -5602,47 +6385,56 @@ Keyword Hash typedef struct keywordHash_s { char *keyword; - qboolean (*func)(itemDef_t *item, int handle); + qboolean ( *func )( itemDef_t *item, int handle ); + struct keywordHash_s *next; -} keywordHash_t; +} -int KeywordHash_Key(char *keyword) { +keywordHash_t; + +int KeywordHash_Key( char *keyword ) +{ int register hash, i; hash = 0; - for (i = 0; keyword[i] != '\0'; i++) { - if (keyword[i] >= 'A' && keyword[i] <= 'Z') - hash += (keyword[i] + ('a' - 'A')) * (119 + i); + + for( i = 0; keyword[i] != '\0'; i++ ) + { + if( keyword[i] >= 'A' && keyword[i] <= 'Z' ) + hash += ( keyword[i] + ( 'a' - 'A' ) ) * ( 119 + i ); else - hash += keyword[i] * (119 + i); + hash += keyword[i] * ( 119 + i ); } - hash = (hash ^ (hash >> 10) ^ (hash >> 20)) & (KEYWORDHASH_SIZE-1); + + hash = ( hash ^ ( hash >> 10 ) ^ ( hash >> 20 ) ) & ( KEYWORDHASH_SIZE - 1 ); return hash; } -void KeywordHash_Add(keywordHash_t *table[], keywordHash_t *key) { +void KeywordHash_Add( keywordHash_t *table[], keywordHash_t *key ) +{ int hash; - hash = KeywordHash_Key(key->keyword); -/* - if (table[hash]) { - int collision = qtrue; - } -*/ + hash = KeywordHash_Key( key->keyword ); + /* + if(table[hash]) int collision = qtrue; + */ key->next = table[hash]; table[hash] = key; } -keywordHash_t *KeywordHash_Find(keywordHash_t *table[], char *keyword) +keywordHash_t *KeywordHash_Find( keywordHash_t *table[], char *keyword ) { - keywordHash_t *key; + keywordHash_t * key; int hash; - hash = KeywordHash_Key(keyword); - for (key = table[hash]; key; key = key->next) { - if (!Q_stricmp(key->keyword, keyword)) + hash = KeywordHash_Key( keyword ); + + for( key = table[hash]; key; key = key->next ) + { + if( !Q_stricmp( key->keyword, keyword ) ) return key; } + return NULL; } @@ -5653,268 +6445,309 @@ Item Keyword Parse functions */ // name <string> -qboolean ItemParse_name( itemDef_t *item, int handle ) { - if (!PC_String_Parse(handle, &item->window.name)) { +qboolean ItemParse_name( itemDef_t *item, int handle ) +{ + if( !PC_String_Parse( handle, &item->window.name ) ) return qfalse; - } + return qtrue; } // name <string> -qboolean ItemParse_focusSound( itemDef_t *item, int handle ) { - const char *temp; - if (!PC_String_Parse(handle, &temp)) { +qboolean ItemParse_focusSound( itemDef_t *item, int handle ) +{ + const char * temp; + + if( !PC_String_Parse( handle, &temp ) ) return qfalse; - } - item->focusSound = DC->registerSound(temp, qfalse); + + item->focusSound = DC->registerSound( temp, qfalse ); return qtrue; } // text <string> -qboolean ItemParse_text( itemDef_t *item, int handle ) { - if (!PC_String_Parse(handle, &item->text)) { +qboolean ItemParse_text( itemDef_t *item, int handle ) +{ + if( !PC_String_Parse( handle, &item->text ) ) return qfalse; - } + return qtrue; } // group <string> -qboolean ItemParse_group( itemDef_t *item, int handle ) { - if (!PC_String_Parse(handle, &item->window.group)) { +qboolean ItemParse_group( itemDef_t *item, int handle ) +{ + if( !PC_String_Parse( handle, &item->window.group ) ) return qfalse; - } + return qtrue; } // asset_model <string> -qboolean ItemParse_asset_model( itemDef_t *item, int handle ) { - const char *temp; +qboolean ItemParse_asset_model( itemDef_t *item, int handle ) +{ + const char * temp; modelDef_t *modelPtr; - Item_ValidateTypeData(item); - modelPtr = (modelDef_t*)item->typeData; + Item_ValidateTypeData( item ); + modelPtr = ( modelDef_t* )item->typeData; - if (!PC_String_Parse(handle, &temp)) { + if( !PC_String_Parse( handle, &temp ) ) return qfalse; - } - item->asset = DC->registerModel(temp); + + item->asset = DC->registerModel( temp ); modelPtr->angle = rand() % 360; return qtrue; } // asset_shader <string> -qboolean ItemParse_asset_shader( itemDef_t *item, int handle ) { - const char *temp; +qboolean ItemParse_asset_shader( itemDef_t *item, int handle ) +{ + const char * temp; - if (!PC_String_Parse(handle, &temp)) { + if( !PC_String_Parse( handle, &temp ) ) return qfalse; - } - item->asset = DC->registerShaderNoMip(temp); + + item->asset = DC->registerShaderNoMip( temp ); return qtrue; } // model_origin <number> <number> <number> -qboolean ItemParse_model_origin( itemDef_t *item, int handle ) { - modelDef_t *modelPtr; - Item_ValidateTypeData(item); - modelPtr = (modelDef_t*)item->typeData; +qboolean ItemParse_model_origin( itemDef_t *item, int handle ) +{ + modelDef_t * modelPtr; + Item_ValidateTypeData( item ); + modelPtr = ( modelDef_t* )item->typeData; - if (PC_Float_Parse(handle, &modelPtr->origin[0])) { - if (PC_Float_Parse(handle, &modelPtr->origin[1])) { - if (PC_Float_Parse(handle, &modelPtr->origin[2])) { + if( PC_Float_Parse( handle, &modelPtr->origin[0] ) ) + { + if( PC_Float_Parse( handle, &modelPtr->origin[1] ) ) + { + if( PC_Float_Parse( handle, &modelPtr->origin[2] ) ) return qtrue; - } } } + return qfalse; } // model_fovx <number> -qboolean ItemParse_model_fovx( itemDef_t *item, int handle ) { - modelDef_t *modelPtr; - Item_ValidateTypeData(item); - modelPtr = (modelDef_t*)item->typeData; +qboolean ItemParse_model_fovx( itemDef_t *item, int handle ) +{ + modelDef_t * modelPtr; + Item_ValidateTypeData( item ); + modelPtr = ( modelDef_t* )item->typeData; - if (!PC_Float_Parse(handle, &modelPtr->fov_x)) { + if( !PC_Float_Parse( handle, &modelPtr->fov_x ) ) return qfalse; - } + return qtrue; } // model_fovy <number> -qboolean ItemParse_model_fovy( itemDef_t *item, int handle ) { - modelDef_t *modelPtr; - Item_ValidateTypeData(item); - modelPtr = (modelDef_t*)item->typeData; +qboolean ItemParse_model_fovy( itemDef_t *item, int handle ) +{ + modelDef_t * modelPtr; + Item_ValidateTypeData( item ); + modelPtr = ( modelDef_t* )item->typeData; - if (!PC_Float_Parse(handle, &modelPtr->fov_y)) { + if( !PC_Float_Parse( handle, &modelPtr->fov_y ) ) return qfalse; - } + return qtrue; } // model_rotation <integer> -qboolean ItemParse_model_rotation( itemDef_t *item, int handle ) { - modelDef_t *modelPtr; - Item_ValidateTypeData(item); - modelPtr = (modelDef_t*)item->typeData; +qboolean ItemParse_model_rotation( itemDef_t *item, int handle ) +{ + modelDef_t * modelPtr; + Item_ValidateTypeData( item ); + modelPtr = ( modelDef_t* )item->typeData; - if (!PC_Int_Parse(handle, &modelPtr->rotationSpeed)) { + if( !PC_Int_Parse( handle, &modelPtr->rotationSpeed ) ) return qfalse; - } + return qtrue; } // model_angle <integer> -qboolean ItemParse_model_angle( itemDef_t *item, int handle ) { - modelDef_t *modelPtr; - Item_ValidateTypeData(item); - modelPtr = (modelDef_t*)item->typeData; +qboolean ItemParse_model_angle( itemDef_t *item, int handle ) +{ + modelDef_t * modelPtr; + Item_ValidateTypeData( item ); + modelPtr = ( modelDef_t* )item->typeData; - if (!PC_Int_Parse(handle, &modelPtr->angle)) { + if( !PC_Int_Parse( handle, &modelPtr->angle ) ) return qfalse; - } + return qtrue; } // rect <rectangle> -qboolean ItemParse_rect( itemDef_t *item, int handle ) { - if (!PC_Rect_Parse(handle, &item->window.rectClient)) { +qboolean ItemParse_rect( itemDef_t *item, int handle ) +{ + if( !PC_Rect_Parse( handle, &item->window.rectClient ) ) return qfalse; - } + return qtrue; } // aspectBias <bias> -qboolean ItemParse_aspectBias( itemDef_t *item, int handle ) { - if (!PC_Int_Parse(handle, &item->window.aspectBias)) { +qboolean ItemParse_aspectBias( itemDef_t *item, int handle ) +{ + if( !PC_Int_Parse( handle, &item->window.aspectBias ) ) return qfalse; - } + return qtrue; } // style <integer> -qboolean ItemParse_style( itemDef_t *item, int handle ) { - if (!PC_Int_Parse(handle, &item->window.style)) { +qboolean ItemParse_style( itemDef_t *item, int handle ) +{ + if( !PC_Int_Parse( handle, &item->window.style ) ) return qfalse; - } + return qtrue; } // decoration -qboolean ItemParse_decoration( itemDef_t *item, int handle ) { +qboolean ItemParse_decoration( itemDef_t *item, int handle ) +{ item->window.flags |= WINDOW_DECORATION; return qtrue; } // notselectable -qboolean ItemParse_notselectable( itemDef_t *item, int handle ) { - listBoxDef_t *listPtr; - Item_ValidateTypeData(item); - listPtr = (listBoxDef_t*)item->typeData; - if (item->type == ITEM_TYPE_LISTBOX && listPtr) { +qboolean ItemParse_notselectable( itemDef_t *item, int handle ) +{ + listBoxDef_t * listPtr; + Item_ValidateTypeData( item ); + listPtr = ( listBoxDef_t* )item->typeData; + + if( item->type == ITEM_TYPE_LISTBOX && listPtr ) listPtr->notselectable = qtrue; - } + return qtrue; } // noscrollbar -qboolean ItemParse_noscrollbar( itemDef_t *item, int handle ) { - listBoxDef_t *listPtr; - Item_ValidateTypeData(item); - listPtr = (listBoxDef_t*)item->typeData; - if (item->type == ITEM_TYPE_LISTBOX && listPtr) { +qboolean ItemParse_noscrollbar( itemDef_t *item, int handle ) +{ + listBoxDef_t * listPtr; + Item_ValidateTypeData( item ); + listPtr = ( listBoxDef_t* )item->typeData; + + if( item->type == ITEM_TYPE_LISTBOX && listPtr ) listPtr->noscrollbar = qtrue; - } + return qtrue; } // auto wrapped -qboolean ItemParse_wrapped( itemDef_t *item, int handle ) { +qboolean ItemParse_wrapped( itemDef_t *item, int handle ) +{ item->window.flags |= WINDOW_WRAPPED; return qtrue; } // horizontalscroll -qboolean ItemParse_horizontalscroll( itemDef_t *item, int handle ) { +qboolean ItemParse_horizontalscroll( itemDef_t *item, int handle ) +{ item->window.flags |= WINDOW_HORIZONTAL; return qtrue; } // type <integer> -qboolean ItemParse_type( itemDef_t *item, int handle ) { - if (!PC_Int_Parse(handle, &item->type)) { +qboolean ItemParse_type( itemDef_t *item, int handle ) +{ + if( !PC_Int_Parse( handle, &item->type ) ) return qfalse; - } - Item_ValidateTypeData(item); + + Item_ValidateTypeData( item ); return qtrue; } // elementwidth, used for listbox image elements // uses textalignx for storage -qboolean ItemParse_elementwidth( itemDef_t *item, int handle ) { - listBoxDef_t *listPtr; +qboolean ItemParse_elementwidth( itemDef_t *item, int handle ) +{ + listBoxDef_t * listPtr; + + Item_ValidateTypeData( item ); + listPtr = ( listBoxDef_t* )item->typeData; - Item_ValidateTypeData(item); - listPtr = (listBoxDef_t*)item->typeData; - if (!PC_Float_Parse(handle, &listPtr->elementWidth)) { + if( !PC_Float_Parse( handle, &listPtr->elementWidth ) ) return qfalse; - } + return qtrue; } // elementheight, used for listbox image elements // uses textaligny for storage -qboolean ItemParse_elementheight( itemDef_t *item, int handle ) { - listBoxDef_t *listPtr; +qboolean ItemParse_elementheight( itemDef_t *item, int handle ) +{ + listBoxDef_t * listPtr; - Item_ValidateTypeData(item); - listPtr = (listBoxDef_t*)item->typeData; - if (!PC_Float_Parse(handle, &listPtr->elementHeight)) { + Item_ValidateTypeData( item ); + listPtr = ( listBoxDef_t* )item->typeData; + + if( !PC_Float_Parse( handle, &listPtr->elementHeight ) ) return qfalse; - } + return qtrue; } // feeder <float> -qboolean ItemParse_feeder( itemDef_t *item, int handle ) { - if (!PC_Float_Parse(handle, &item->special)) { +qboolean ItemParse_feeder( itemDef_t *item, int handle ) +{ + if( !PC_Float_Parse( handle, &item->special ) ) return qfalse; - } + return qtrue; } // elementtype, used to specify what type of elements a listbox contains // uses textstyle for storage -qboolean ItemParse_elementtype( itemDef_t *item, int handle ) { - listBoxDef_t *listPtr; +qboolean ItemParse_elementtype( itemDef_t *item, int handle ) +{ + listBoxDef_t * listPtr; - Item_ValidateTypeData(item); - if (!item->typeData) + Item_ValidateTypeData( item ); + + if( !item->typeData ) return qfalse; - listPtr = (listBoxDef_t*)item->typeData; - if (!PC_Int_Parse(handle, &listPtr->elementStyle)) { + + listPtr = ( listBoxDef_t* )item->typeData; + + if( !PC_Int_Parse( handle, &listPtr->elementStyle ) ) return qfalse; - } + return qtrue; } // columns sets a number of columns and an x pos and width per.. -qboolean ItemParse_columns( itemDef_t *item, int handle ) { +qboolean ItemParse_columns( itemDef_t *item, int handle ) +{ int num, i; listBoxDef_t *listPtr; - Item_ValidateTypeData(item); - if (!item->typeData) + Item_ValidateTypeData( item ); + + if( !item->typeData ) return qfalse; - listPtr = (listBoxDef_t*)item->typeData; - if (PC_Int_Parse(handle, &num)) { - if (num > MAX_LB_COLUMNS) { + + listPtr = ( listBoxDef_t* )item->typeData; + + if( PC_Int_Parse( handle, &num ) ) + { + if( num > MAX_LB_COLUMNS ) num = MAX_LB_COLUMNS; - } + listPtr->numColumns = num; - for (i = 0; i < num; i++) { + + for( i = 0; i < num; i++ ) + { int pos, width, align; if( PC_Int_Parse( handle, &pos ) && @@ -5924,309 +6757,354 @@ qboolean ItemParse_columns( itemDef_t *item, int handle ) { listPtr->columnInfo[i].pos = pos; listPtr->columnInfo[i].width = width; listPtr->columnInfo[i].align = align; - } else { - return qfalse; } + else + return qfalse; } - } else { - return qfalse; } + else + return qfalse; + return qtrue; } -qboolean ItemParse_border( itemDef_t *item, int handle ) { - if (!PC_Int_Parse(handle, &item->window.border)) { +qboolean ItemParse_border( itemDef_t *item, int handle ) +{ + if( !PC_Int_Parse( handle, &item->window.border ) ) return qfalse; - } + return qtrue; } -qboolean ItemParse_bordersize( itemDef_t *item, int handle ) { - if (!PC_Float_Parse(handle, &item->window.borderSize)) { +qboolean ItemParse_bordersize( itemDef_t *item, int handle ) +{ + if( !PC_Float_Parse( handle, &item->window.borderSize ) ) return qfalse; - } + return qtrue; } -qboolean ItemParse_visible( itemDef_t *item, int handle ) { +qboolean ItemParse_visible( itemDef_t *item, int handle ) +{ int i; - if (!PC_Int_Parse(handle, &i)) { + if( !PC_Int_Parse( handle, &i ) ) return qfalse; - } - if (i) { + + if( i ) item->window.flags |= WINDOW_VISIBLE; - } + return qtrue; } -qboolean ItemParse_ownerdraw( itemDef_t *item, int handle ) { - if (!PC_Int_Parse(handle, &item->window.ownerDraw)) { +qboolean ItemParse_ownerdraw( itemDef_t *item, int handle ) +{ + if( !PC_Int_Parse( handle, &item->window.ownerDraw ) ) return qfalse; - } + item->type = ITEM_TYPE_OWNERDRAW; return qtrue; } -qboolean ItemParse_align( itemDef_t *item, int handle ) { - if (!PC_Int_Parse(handle, &item->alignment)) { +qboolean ItemParse_align( itemDef_t *item, int handle ) +{ + if( !PC_Int_Parse( handle, &item->alignment ) ) return qfalse; - } + return qtrue; } -qboolean ItemParse_textalign( itemDef_t *item, int handle ) { - if (!PC_Int_Parse(handle, &item->textalignment)) { +qboolean ItemParse_textalign( itemDef_t *item, int handle ) +{ + if( !PC_Int_Parse( handle, &item->textalignment ) ) return qfalse; - } + return qtrue; } -qboolean ItemParse_textvalign( itemDef_t *item, int handle ) { - if (!PC_Int_Parse(handle, &item->textvalignment)) { +qboolean ItemParse_textvalign( itemDef_t *item, int handle ) +{ + if( !PC_Int_Parse( handle, &item->textvalignment ) ) return qfalse; - } + return qtrue; } -qboolean ItemParse_textalignx( itemDef_t *item, int handle ) { - if (!PC_Float_Parse(handle, &item->textalignx)) { +qboolean ItemParse_textalignx( itemDef_t *item, int handle ) +{ + if( !PC_Float_Parse( handle, &item->textalignx ) ) return qfalse; - } + return qtrue; } -qboolean ItemParse_textaligny( itemDef_t *item, int handle ) { - if (!PC_Float_Parse(handle, &item->textaligny)) { +qboolean ItemParse_textaligny( itemDef_t *item, int handle ) +{ + if( !PC_Float_Parse( handle, &item->textaligny ) ) return qfalse; - } + return qtrue; } -qboolean ItemParse_textscale( itemDef_t *item, int handle ) { - if (!PC_Float_Parse(handle, &item->textscale)) { +qboolean ItemParse_textscale( itemDef_t *item, int handle ) +{ + if( !PC_Float_Parse( handle, &item->textscale ) ) return qfalse; - } + return qtrue; } -qboolean ItemParse_textstyle( itemDef_t *item, int handle ) { - if (!PC_Int_Parse(handle, &item->textStyle)) { +qboolean ItemParse_textstyle( itemDef_t *item, int handle ) +{ + if( !PC_Int_Parse( handle, &item->textStyle ) ) return qfalse; - } + return qtrue; } -qboolean ItemParse_backcolor( itemDef_t *item, int handle ) { +qboolean ItemParse_backcolor( itemDef_t *item, int handle ) +{ int i; float f; - for (i = 0; i < 4; i++) { - if (!PC_Float_Parse(handle, &f)) { + for( i = 0; i < 4; i++ ) + { + if( !PC_Float_Parse( handle, &f ) ) return qfalse; - } + item->window.backColor[i] = f; } + return qtrue; } -qboolean ItemParse_forecolor( itemDef_t *item, int handle ) { +qboolean ItemParse_forecolor( itemDef_t *item, int handle ) +{ int i; float f; - for (i = 0; i < 4; i++) { - if (!PC_Float_Parse(handle, &f)) { + for( i = 0; i < 4; i++ ) + { + if( !PC_Float_Parse( handle, &f ) ) return qfalse; - } + item->window.foreColor[i] = f; item->window.flags |= WINDOW_FORECOLORSET; } + return qtrue; } -qboolean ItemParse_bordercolor( itemDef_t *item, int handle ) { +qboolean ItemParse_bordercolor( itemDef_t *item, int handle ) +{ int i; float f; - for (i = 0; i < 4; i++) { - if (!PC_Float_Parse(handle, &f)) { + for( i = 0; i < 4; i++ ) + { + if( !PC_Float_Parse( handle, &f ) ) return qfalse; - } + item->window.borderColor[i] = f; } + return qtrue; } -qboolean ItemParse_outlinecolor( itemDef_t *item, int handle ) { - if (!PC_Color_Parse(handle, &item->window.outlineColor)){ +qboolean ItemParse_outlinecolor( itemDef_t *item, int handle ) +{ + if( !PC_Color_Parse( handle, &item->window.outlineColor ) ) return qfalse; - } + return qtrue; } -qboolean ItemParse_background( itemDef_t *item, int handle ) { - const char *temp; +qboolean ItemParse_background( itemDef_t *item, int handle ) +{ + const char * temp; - if (!PC_String_Parse(handle, &temp)) { + if( !PC_String_Parse( handle, &temp ) ) return qfalse; - } - item->window.background = DC->registerShaderNoMip(temp); + + item->window.background = DC->registerShaderNoMip( temp ); return qtrue; } -qboolean ItemParse_cinematic( itemDef_t *item, int handle ) { - if (!PC_String_Parse(handle, &item->window.cinematicName)) { +qboolean ItemParse_cinematic( itemDef_t *item, int handle ) +{ + if( !PC_String_Parse( handle, &item->window.cinematicName ) ) return qfalse; - } + return qtrue; } -qboolean ItemParse_doubleClick( itemDef_t *item, int handle ) { - listBoxDef_t *listPtr; +qboolean ItemParse_doubleClick( itemDef_t *item, int handle ) +{ + listBoxDef_t * listPtr; + + Item_ValidateTypeData( item ); - Item_ValidateTypeData(item); - if (!item->typeData) { + if( !item->typeData ) return qfalse; - } - listPtr = (listBoxDef_t*)item->typeData; + listPtr = ( listBoxDef_t* )item->typeData; - if (!PC_Script_Parse(handle, &listPtr->doubleClick)) { + if( !PC_Script_Parse( handle, &listPtr->doubleClick ) ) return qfalse; - } + return qtrue; } -qboolean ItemParse_onFocus( itemDef_t *item, int handle ) { - if (!PC_Script_Parse(handle, &item->onFocus)) { +qboolean ItemParse_onFocus( itemDef_t *item, int handle ) +{ + if( !PC_Script_Parse( handle, &item->onFocus ) ) return qfalse; - } + return qtrue; } -qboolean ItemParse_leaveFocus( itemDef_t *item, int handle ) { - if (!PC_Script_Parse(handle, &item->leaveFocus)) { +qboolean ItemParse_leaveFocus( itemDef_t *item, int handle ) +{ + if( !PC_Script_Parse( handle, &item->leaveFocus ) ) return qfalse; - } + return qtrue; } -qboolean ItemParse_mouseEnter( itemDef_t *item, int handle ) { - if (!PC_Script_Parse(handle, &item->mouseEnter)) { +qboolean ItemParse_mouseEnter( itemDef_t *item, int handle ) +{ + if( !PC_Script_Parse( handle, &item->mouseEnter ) ) return qfalse; - } + return qtrue; } -qboolean ItemParse_mouseExit( itemDef_t *item, int handle ) { - if (!PC_Script_Parse(handle, &item->mouseExit)) { +qboolean ItemParse_mouseExit( itemDef_t *item, int handle ) +{ + if( !PC_Script_Parse( handle, &item->mouseExit ) ) return qfalse; - } + return qtrue; } -qboolean ItemParse_mouseEnterText( itemDef_t *item, int handle ) { - if (!PC_Script_Parse(handle, &item->mouseEnterText)) { +qboolean ItemParse_mouseEnterText( itemDef_t *item, int handle ) +{ + if( !PC_Script_Parse( handle, &item->mouseEnterText ) ) return qfalse; - } + return qtrue; } -qboolean ItemParse_mouseExitText( itemDef_t *item, int handle ) { - if (!PC_Script_Parse(handle, &item->mouseExitText)) { +qboolean ItemParse_mouseExitText( itemDef_t *item, int handle ) +{ + if( !PC_Script_Parse( handle, &item->mouseExitText ) ) return qfalse; - } + return qtrue; } -qboolean ItemParse_onTextEntry( itemDef_t *item, int handle ) { - if (!PC_Script_Parse(handle, &item->onTextEntry)) { +qboolean ItemParse_onTextEntry( itemDef_t *item, int handle ) +{ + if( !PC_Script_Parse( handle, &item->onTextEntry ) ) return qfalse; - } + return qtrue; } -qboolean ItemParse_action( itemDef_t *item, int handle ) { - if (!PC_Script_Parse(handle, &item->action)) { +qboolean ItemParse_action( itemDef_t *item, int handle ) +{ + if( !PC_Script_Parse( handle, &item->action ) ) return qfalse; - } + return qtrue; } -qboolean ItemParse_special( itemDef_t *item, int handle ) { - if (!PC_Float_Parse(handle, &item->special)) { +qboolean ItemParse_special( itemDef_t *item, int handle ) +{ + if( !PC_Float_Parse( handle, &item->special ) ) return qfalse; - } + return qtrue; } -qboolean ItemParse_cvarTest( itemDef_t *item, int handle ) { - if (!PC_String_Parse(handle, &item->cvarTest)) { +qboolean ItemParse_cvarTest( itemDef_t *item, int handle ) +{ + if( !PC_String_Parse( handle, &item->cvarTest ) ) return qfalse; - } + return qtrue; } -qboolean ItemParse_cvar( itemDef_t *item, int handle ) { - editFieldDef_t *editPtr; +qboolean ItemParse_cvar( itemDef_t *item, int handle ) +{ + editFieldDef_t * editPtr; + + Item_ValidateTypeData( item ); - Item_ValidateTypeData(item); - if (!PC_String_Parse(handle, &item->cvar)) { + if( !PC_String_Parse( handle, &item->cvar ) ) return qfalse; - } - if (item->typeData) { - editPtr = (editFieldDef_t*)item->typeData; + + if( item->typeData ) + { + editPtr = ( editFieldDef_t* )item->typeData; editPtr->minVal = -1; editPtr->maxVal = -1; editPtr->defVal = -1; } + return qtrue; } -qboolean ItemParse_maxChars( itemDef_t *item, int handle ) { - editFieldDef_t *editPtr; +qboolean ItemParse_maxChars( itemDef_t *item, int handle ) +{ + editFieldDef_t * editPtr; int maxChars; - Item_ValidateTypeData(item); - if (!item->typeData) + Item_ValidateTypeData( item ); + + if( !item->typeData ) return qfalse; - if (!PC_Int_Parse(handle, &maxChars)) { + if( !PC_Int_Parse( handle, &maxChars ) ) return qfalse; - } - editPtr = (editFieldDef_t*)item->typeData; + + editPtr = ( editFieldDef_t* )item->typeData; editPtr->maxChars = maxChars; return qtrue; } -qboolean ItemParse_maxPaintChars( itemDef_t *item, int handle ) { - editFieldDef_t *editPtr; +qboolean ItemParse_maxPaintChars( itemDef_t *item, int handle ) +{ + editFieldDef_t * editPtr; int maxChars; - Item_ValidateTypeData(item); - if (!item->typeData) + Item_ValidateTypeData( item ); + + if( !item->typeData ) return qfalse; - if (!PC_Int_Parse(handle, &maxChars)) { + if( !PC_Int_Parse( handle, &maxChars ) ) return qfalse; - } - editPtr = (editFieldDef_t*)item->typeData; + + editPtr = ( editFieldDef_t* )item->typeData; editPtr->maxPaintChars = maxChars; return qtrue; } -qboolean ItemParse_maxFieldWidth( itemDef_t *item, int handle ) { - editFieldDef_t *editPtr; +qboolean ItemParse_maxFieldWidth( itemDef_t *item, int handle ) +{ + editFieldDef_t * editPtr; int maxFieldWidth; - Item_ValidateTypeData(item); - if (!item->typeData) + Item_ValidateTypeData( item ); + + if( !item->typeData ) return qfalse; - if (!PC_Int_Parse(handle, &maxFieldWidth)) { + if( !PC_Int_Parse( handle, &maxFieldWidth ) ) return qfalse; - } - editPtr = (editFieldDef_t*)item->typeData; + + editPtr = ( editFieldDef_t* )item->typeData; if( maxFieldWidth < MIN_FIELD_WIDTH ) editPtr->maxFieldWidth = MIN_FIELD_WIDTH; @@ -6238,171 +7116,210 @@ qboolean ItemParse_maxFieldWidth( itemDef_t *item, int handle ) { -qboolean ItemParse_cvarFloat( itemDef_t *item, int handle ) { - editFieldDef_t *editPtr; +qboolean ItemParse_cvarFloat( itemDef_t *item, int handle ) +{ + editFieldDef_t * editPtr; + + Item_ValidateTypeData( item ); - Item_ValidateTypeData(item); - if (!item->typeData) + if( !item->typeData ) return qfalse; - editPtr = (editFieldDef_t*)item->typeData; - if (PC_String_Parse(handle, &item->cvar) && - PC_Float_Parse(handle, &editPtr->defVal) && - PC_Float_Parse(handle, &editPtr->minVal) && - PC_Float_Parse(handle, &editPtr->maxVal)) { + + editPtr = ( editFieldDef_t* )item->typeData; + + if( PC_String_Parse( handle, &item->cvar ) && + PC_Float_Parse( handle, &editPtr->defVal ) && + PC_Float_Parse( handle, &editPtr->minVal ) && + PC_Float_Parse( handle, &editPtr->maxVal ) ) return qtrue; - } + return qfalse; } -qboolean ItemParse_cvarStrList( itemDef_t *item, int handle ) { +qboolean ItemParse_cvarStrList( itemDef_t *item, int handle ) +{ pc_token_t token; multiDef_t *multiPtr; int pass; - Item_ValidateTypeData(item); - if (!item->typeData) + Item_ValidateTypeData( item ); + + if( !item->typeData ) return qfalse; - multiPtr = (multiDef_t*)item->typeData; + + multiPtr = ( multiDef_t* )item->typeData; + multiPtr->count = 0; + multiPtr->strDef = qtrue; - if (!trap_Parse_ReadToken(handle, &token)) + if( !trap_Parse_ReadToken( handle, &token ) ) return qfalse; - if (*token.string != '{') { + + if( *token.string != '{' ) return qfalse; - } pass = 0; - while ( 1 ) { - if (!trap_Parse_ReadToken(handle, &token)) { - PC_SourceError(handle, "end of file inside menu item\n"); + + while( 1 ) + { + if( !trap_Parse_ReadToken( handle, &token ) ) + { + PC_SourceError( handle, "end of file inside menu item\n" ); return qfalse; } - if (*token.string == '}') { + if( *token.string == '}' ) return qtrue; - } - if (*token.string == ',' || *token.string == ';') { + if( *token.string == ',' || *token.string == ';' ) continue; - } - if (pass == 0) { - multiPtr->cvarList[multiPtr->count] = String_Alloc(token.string); + if( pass == 0 ) + { + multiPtr->cvarList[multiPtr->count] = String_Alloc( token.string ); pass = 1; - } else { - multiPtr->cvarStr[multiPtr->count] = String_Alloc(token.string); + } + else + { + multiPtr->cvarStr[multiPtr->count] = String_Alloc( token.string ); pass = 0; multiPtr->count++; - if (multiPtr->count >= MAX_MULTI_CVARS) { + + if( multiPtr->count >= MAX_MULTI_CVARS ) return qfalse; - } } } + return qfalse; } -qboolean ItemParse_cvarFloatList( itemDef_t *item, int handle ) { +qboolean ItemParse_cvarFloatList( itemDef_t *item, int handle ) +{ pc_token_t token; multiDef_t *multiPtr; - Item_ValidateTypeData(item); - if (!item->typeData) + Item_ValidateTypeData( item ); + + if( !item->typeData ) return qfalse; - multiPtr = (multiDef_t*)item->typeData; + + multiPtr = ( multiDef_t* )item->typeData; + multiPtr->count = 0; + multiPtr->strDef = qfalse; - if (!trap_Parse_ReadToken(handle, &token)) + if( !trap_Parse_ReadToken( handle, &token ) ) return qfalse; - if (*token.string != '{') { + + if( *token.string != '{' ) return qfalse; - } - while ( 1 ) { - if (!trap_Parse_ReadToken(handle, &token)) { - PC_SourceError(handle, "end of file inside menu item\n"); + while( 1 ) + { + if( !trap_Parse_ReadToken( handle, &token ) ) + { + PC_SourceError( handle, "end of file inside menu item\n" ); return qfalse; } - if (*token.string == '}') { + if( *token.string == '}' ) return qtrue; - } - if (*token.string == ',' || *token.string == ';') { + if( *token.string == ',' || *token.string == ';' ) continue; - } - multiPtr->cvarList[multiPtr->count] = String_Alloc(token.string); - if (!PC_Float_Parse(handle, &multiPtr->cvarValue[multiPtr->count])) { + multiPtr->cvarList[multiPtr->count] = String_Alloc( token.string ); + + if( !PC_Float_Parse( handle, &multiPtr->cvarValue[multiPtr->count] ) ) return qfalse; - } multiPtr->count++; - if (multiPtr->count >= MAX_MULTI_CVARS) { + + if( multiPtr->count >= MAX_MULTI_CVARS ) return qfalse; - } } + return qfalse; } -qboolean ItemParse_addColorRange( itemDef_t *item, int handle ) { +qboolean ItemParse_addColorRange( itemDef_t *item, int handle ) +{ colorRangeDef_t color; - if (PC_Float_Parse(handle, &color.low) && - PC_Float_Parse(handle, &color.high) && - PC_Color_Parse(handle, &color.color) ) { - if (item->numColors < MAX_COLOR_RANGES) { - memcpy(&item->colorRanges[item->numColors], &color, sizeof(color)); + if( PC_Float_Parse( handle, &color.low ) && + PC_Float_Parse( handle, &color.high ) && + PC_Color_Parse( handle, &color.color ) ) + { + if( item->numColors < MAX_COLOR_RANGES ) + { + memcpy( &item->colorRanges[item->numColors], &color, sizeof( color ) ); item->numColors++; } + return qtrue; } + return qfalse; } -qboolean ItemParse_ownerdrawFlag( itemDef_t *item, int handle ) { +qboolean ItemParse_ownerdrawFlag( itemDef_t *item, int handle ) +{ int i; - if (!PC_Int_Parse(handle, &i)) { + + if( !PC_Int_Parse( handle, &i ) ) return qfalse; - } + item->window.ownerDrawFlags |= i; return qtrue; } -qboolean ItemParse_enableCvar( itemDef_t *item, int handle ) { - if (PC_Script_Parse(handle, &item->enableCvar)) { +qboolean ItemParse_enableCvar( itemDef_t *item, int handle ) +{ + if( PC_Script_Parse( handle, &item->enableCvar ) ) + { item->cvarFlags = CVAR_ENABLE; return qtrue; } + return qfalse; } -qboolean ItemParse_disableCvar( itemDef_t *item, int handle ) { - if (PC_Script_Parse(handle, &item->enableCvar)) { +qboolean ItemParse_disableCvar( itemDef_t *item, int handle ) +{ + if( PC_Script_Parse( handle, &item->enableCvar ) ) + { item->cvarFlags = CVAR_DISABLE; return qtrue; } + return qfalse; } -qboolean ItemParse_showCvar( itemDef_t *item, int handle ) { - if (PC_Script_Parse(handle, &item->enableCvar)) { +qboolean ItemParse_showCvar( itemDef_t *item, int handle ) +{ + if( PC_Script_Parse( handle, &item->enableCvar ) ) + { item->cvarFlags = CVAR_SHOW; return qtrue; } + return qfalse; } -qboolean ItemParse_hideCvar( itemDef_t *item, int handle ) { - if (PC_Script_Parse(handle, &item->enableCvar)) { +qboolean ItemParse_hideCvar( itemDef_t *item, int handle ) +{ + if( PC_Script_Parse( handle, &item->enableCvar ) ) + { item->cvarFlags = CVAR_HIDE; return qtrue; } + return qfalse; } @@ -6499,50 +7416,62 @@ void Item_SetupKeywordHash( void ) Item_Parse =============== */ -qboolean Item_Parse(int handle, itemDef_t *item) { +qboolean Item_Parse( int handle, itemDef_t *item ) +{ pc_token_t token; keywordHash_t *key; - if (!trap_Parse_ReadToken(handle, &token)) + if( !trap_Parse_ReadToken( handle, &token ) ) return qfalse; - if (*token.string != '{') { + + if( *token.string != '{' ) return qfalse; - } - while ( 1 ) { - if (!trap_Parse_ReadToken(handle, &token)) { - PC_SourceError(handle, "end of file inside menu item\n"); + + while( 1 ) + { + if( !trap_Parse_ReadToken( handle, &token ) ) + { + PC_SourceError( handle, "end of file inside menu item\n" ); return qfalse; } - if (*token.string == '}') { + if( *token.string == '}' ) return qtrue; - } - key = KeywordHash_Find(itemParseKeywordHash, token.string); - if (!key) { - PC_SourceError(handle, "unknown menu item keyword %s", token.string); + key = KeywordHash_Find( itemParseKeywordHash, token.string ); + + if( !key ) + { + PC_SourceError( handle, "unknown menu item keyword %s", token.string ); continue; } - if ( !key->func(item, handle) ) { - PC_SourceError(handle, "couldn't parse menu item keyword %s", token.string); + + if( !key->func( item, handle ) ) + { + PC_SourceError( handle, "couldn't parse menu item keyword %s", token.string ); return qfalse; } } + return qfalse; } // Item_InitControls // init's special control types -void Item_InitControls(itemDef_t *item) { - if (item == NULL) { +void Item_InitControls( itemDef_t *item ) +{ + if( item == NULL ) return; - } - if (item->type == ITEM_TYPE_LISTBOX) { - listBoxDef_t *listPtr = (listBoxDef_t*)item->typeData; + + if( item->type == ITEM_TYPE_LISTBOX ) + { + listBoxDef_t * listPtr = ( listBoxDef_t* )item->typeData; item->cursorPos = 0; - if (listPtr) { + + if( listPtr ) + { listPtr->cursorPos = 0; listPtr->startPos = 0; listPtr->endPos = 0; @@ -6557,301 +7486,355 @@ Menu Keyword Parse functions =============== */ -qboolean MenuParse_font( itemDef_t *item, int handle ) { - menuDef_t *menu = (menuDef_t*)item; - if (!PC_String_Parse(handle, &menu->font)) { +qboolean MenuParse_font( itemDef_t *item, int handle ) +{ + menuDef_t * menu = ( menuDef_t* )item; + + if( !PC_String_Parse( handle, &menu->font ) ) return qfalse; - } - if (!DC->Assets.fontRegistered) { - DC->registerFont(menu->font, 48, &DC->Assets.textFont); + + if( !DC->Assets.fontRegistered ) + { + DC->registerFont( menu->font, 48, &DC->Assets.textFont ); DC->Assets.fontRegistered = qtrue; } + return qtrue; } -qboolean MenuParse_name( itemDef_t *item, int handle ) { - menuDef_t *menu = (menuDef_t*)item; - if (!PC_String_Parse(handle, &menu->window.name)) { +qboolean MenuParse_name( itemDef_t *item, int handle ) +{ + menuDef_t * menu = ( menuDef_t* )item; + + if( !PC_String_Parse( handle, &menu->window.name ) ) return qfalse; - } - if (Q_stricmp(menu->window.name, "main") == 0) { - // default main as having focus - //menu->window.flags |= WINDOW_HASFOCUS; - } + return qtrue; } -qboolean MenuParse_fullscreen( itemDef_t *item, int handle ) { - menuDef_t *menu = (menuDef_t*)item; - if (!PC_Int_Parse(handle, (int*) &menu->fullScreen)) { +qboolean MenuParse_fullscreen( itemDef_t *item, int handle ) +{ + menuDef_t * menu = ( menuDef_t* )item; + + if( !PC_Int_Parse( handle, ( int* ) & menu->fullScreen ) ) return qfalse; - } + return qtrue; } -qboolean MenuParse_rect( itemDef_t *item, int handle ) { - menuDef_t *menu = (menuDef_t*)item; - if (!PC_Rect_Parse(handle, &menu->window.rect)) { +qboolean MenuParse_rect( itemDef_t *item, int handle ) +{ + menuDef_t * menu = ( menuDef_t* )item; + + if( !PC_Rect_Parse( handle, &menu->window.rect ) ) return qfalse; - } + return qtrue; } -qboolean MenuParse_aspectBias( itemDef_t *item, int handle ) { - menuDef_t *menu = (menuDef_t*)item; - if (!PC_Int_Parse(handle, &menu->window.aspectBias)) { +qboolean MenuParse_aspectBias( itemDef_t *item, int handle ) +{ + menuDef_t * menu = ( menuDef_t* )item; + + if( !PC_Int_Parse( handle, &menu->window.aspectBias ) ) return qfalse; - } + return qtrue; } -qboolean MenuParse_style( itemDef_t *item, int handle ) { - menuDef_t *menu = (menuDef_t*)item; - if (!PC_Int_Parse(handle, &menu->window.style)) { +qboolean MenuParse_style( itemDef_t *item, int handle ) +{ + menuDef_t * menu = ( menuDef_t* )item; + + if( !PC_Int_Parse( handle, &menu->window.style ) ) return qfalse; - } + return qtrue; } -qboolean MenuParse_visible( itemDef_t *item, int handle ) { +qboolean MenuParse_visible( itemDef_t *item, int handle ) +{ int i; - menuDef_t *menu = (menuDef_t*)item; + menuDef_t *menu = ( menuDef_t* )item; - if (!PC_Int_Parse(handle, &i)) { + if( !PC_Int_Parse( handle, &i ) ) return qfalse; - } - if (i) { + + if( i ) menu->window.flags |= WINDOW_VISIBLE; - } + return qtrue; } -qboolean MenuParse_onOpen( itemDef_t *item, int handle ) { - menuDef_t *menu = (menuDef_t*)item; - if (!PC_Script_Parse(handle, &menu->onOpen)) { +qboolean MenuParse_onOpen( itemDef_t *item, int handle ) +{ + menuDef_t * menu = ( menuDef_t* )item; + + if( !PC_Script_Parse( handle, &menu->onOpen ) ) return qfalse; - } + return qtrue; } -qboolean MenuParse_onClose( itemDef_t *item, int handle ) { - menuDef_t *menu = (menuDef_t*)item; - if (!PC_Script_Parse(handle, &menu->onClose)) { +qboolean MenuParse_onClose( itemDef_t *item, int handle ) +{ + menuDef_t * menu = ( menuDef_t* )item; + + if( !PC_Script_Parse( handle, &menu->onClose ) ) return qfalse; - } + return qtrue; } -qboolean MenuParse_onESC( itemDef_t *item, int handle ) { - menuDef_t *menu = (menuDef_t*)item; - if (!PC_Script_Parse(handle, &menu->onESC)) { +qboolean MenuParse_onESC( itemDef_t *item, int handle ) +{ + menuDef_t * menu = ( menuDef_t* )item; + + if( !PC_Script_Parse( handle, &menu->onESC ) ) return qfalse; - } + return qtrue; } -qboolean MenuParse_border( itemDef_t *item, int handle ) { - menuDef_t *menu = (menuDef_t*)item; - if (!PC_Int_Parse(handle, &menu->window.border)) { +qboolean MenuParse_border( itemDef_t *item, int handle ) +{ + menuDef_t * menu = ( menuDef_t* )item; + + if( !PC_Int_Parse( handle, &menu->window.border ) ) return qfalse; - } + return qtrue; } -qboolean MenuParse_borderSize( itemDef_t *item, int handle ) { - menuDef_t *menu = (menuDef_t*)item; - if (!PC_Float_Parse(handle, &menu->window.borderSize)) { +qboolean MenuParse_borderSize( itemDef_t *item, int handle ) +{ + menuDef_t * menu = ( menuDef_t* )item; + + if( !PC_Float_Parse( handle, &menu->window.borderSize ) ) return qfalse; - } + return qtrue; } -qboolean MenuParse_backcolor( itemDef_t *item, int handle ) { +qboolean MenuParse_backcolor( itemDef_t *item, int handle ) +{ int i; float f; - menuDef_t *menu = (menuDef_t*)item; + menuDef_t *menu = ( menuDef_t* )item; - for (i = 0; i < 4; i++) { - if (!PC_Float_Parse(handle, &f)) { + for( i = 0; i < 4; i++ ) + { + if( !PC_Float_Parse( handle, &f ) ) return qfalse; - } + menu->window.backColor[i] = f; } + return qtrue; } -qboolean MenuParse_forecolor( itemDef_t *item, int handle ) { +qboolean MenuParse_forecolor( itemDef_t *item, int handle ) +{ int i; float f; - menuDef_t *menu = (menuDef_t*)item; + menuDef_t *menu = ( menuDef_t* )item; - for (i = 0; i < 4; i++) { - if (!PC_Float_Parse(handle, &f)) { + for( i = 0; i < 4; i++ ) + { + if( !PC_Float_Parse( handle, &f ) ) return qfalse; - } + menu->window.foreColor[i] = f; menu->window.flags |= WINDOW_FORECOLORSET; } + return qtrue; } -qboolean MenuParse_bordercolor( itemDef_t *item, int handle ) { +qboolean MenuParse_bordercolor( itemDef_t *item, int handle ) +{ int i; float f; - menuDef_t *menu = (menuDef_t*)item; + menuDef_t *menu = ( menuDef_t* )item; - for (i = 0; i < 4; i++) { - if (!PC_Float_Parse(handle, &f)) { + for( i = 0; i < 4; i++ ) + { + if( !PC_Float_Parse( handle, &f ) ) return qfalse; - } + menu->window.borderColor[i] = f; } + return qtrue; } -qboolean MenuParse_focuscolor( itemDef_t *item, int handle ) { +qboolean MenuParse_focuscolor( itemDef_t *item, int handle ) +{ int i; float f; - menuDef_t *menu = (menuDef_t*)item; + menuDef_t *menu = ( menuDef_t* )item; - for (i = 0; i < 4; i++) { - if (!PC_Float_Parse(handle, &f)) { + for( i = 0; i < 4; i++ ) + { + if( !PC_Float_Parse( handle, &f ) ) return qfalse; - } + menu->focusColor[i] = f; } + return qtrue; } -qboolean MenuParse_disablecolor( itemDef_t *item, int handle ) { +qboolean MenuParse_disablecolor( itemDef_t *item, int handle ) +{ int i; float f; - menuDef_t *menu = (menuDef_t*)item; - for (i = 0; i < 4; i++) { - if (!PC_Float_Parse(handle, &f)) { + menuDef_t *menu = ( menuDef_t* )item; + + for( i = 0; i < 4; i++ ) + { + if( !PC_Float_Parse( handle, &f ) ) return qfalse; - } + menu->disableColor[i] = f; } + return qtrue; } -qboolean MenuParse_outlinecolor( itemDef_t *item, int handle ) { - menuDef_t *menu = (menuDef_t*)item; - if (!PC_Color_Parse(handle, &menu->window.outlineColor)){ +qboolean MenuParse_outlinecolor( itemDef_t *item, int handle ) +{ + menuDef_t * menu = ( menuDef_t* )item; + + if( !PC_Color_Parse( handle, &menu->window.outlineColor ) ) return qfalse; - } + return qtrue; } -qboolean MenuParse_background( itemDef_t *item, int handle ) { - const char *buff; - menuDef_t *menu = (menuDef_t*)item; +qboolean MenuParse_background( itemDef_t *item, int handle ) +{ + const char * buff; + menuDef_t *menu = ( menuDef_t* )item; - if (!PC_String_Parse(handle, &buff)) { + if( !PC_String_Parse( handle, &buff ) ) return qfalse; - } - menu->window.background = DC->registerShaderNoMip(buff); + + menu->window.background = DC->registerShaderNoMip( buff ); return qtrue; } -qboolean MenuParse_cinematic( itemDef_t *item, int handle ) { - menuDef_t *menu = (menuDef_t*)item; +qboolean MenuParse_cinematic( itemDef_t *item, int handle ) +{ + menuDef_t * menu = ( menuDef_t* )item; - if (!PC_String_Parse(handle, &menu->window.cinematicName)) { + if( !PC_String_Parse( handle, &menu->window.cinematicName ) ) return qfalse; - } + return qtrue; } -qboolean MenuParse_ownerdrawFlag( itemDef_t *item, int handle ) { +qboolean MenuParse_ownerdrawFlag( itemDef_t *item, int handle ) +{ int i; - menuDef_t *menu = (menuDef_t*)item; + menuDef_t *menu = ( menuDef_t* )item; - if (!PC_Int_Parse(handle, &i)) { + if( !PC_Int_Parse( handle, &i ) ) return qfalse; - } + menu->window.ownerDrawFlags |= i; return qtrue; } -qboolean MenuParse_ownerdraw( itemDef_t *item, int handle ) { - menuDef_t *menu = (menuDef_t*)item; +qboolean MenuParse_ownerdraw( itemDef_t *item, int handle ) +{ + menuDef_t * menu = ( menuDef_t* )item; - if (!PC_Int_Parse(handle, &menu->window.ownerDraw)) { + if( !PC_Int_Parse( handle, &menu->window.ownerDraw ) ) return qfalse; - } + return qtrue; } // decoration -qboolean MenuParse_popup( itemDef_t *item, int handle ) { - menuDef_t *menu = (menuDef_t*)item; +qboolean MenuParse_popup( itemDef_t *item, int handle ) +{ + menuDef_t * menu = ( menuDef_t* )item; menu->window.flags |= WINDOW_POPUP; return qtrue; } -qboolean MenuParse_outOfBounds( itemDef_t *item, int handle ) { - menuDef_t *menu = (menuDef_t*)item; +qboolean MenuParse_outOfBounds( itemDef_t *item, int handle ) +{ + menuDef_t * menu = ( menuDef_t* )item; menu->window.flags |= WINDOW_OOB_CLICK; return qtrue; } -qboolean MenuParse_soundLoop( itemDef_t *item, int handle ) { - menuDef_t *menu = (menuDef_t*)item; +qboolean MenuParse_soundLoop( itemDef_t *item, int handle ) +{ + menuDef_t * menu = ( menuDef_t* )item; - if (!PC_String_Parse(handle, &menu->soundName)) { + if( !PC_String_Parse( handle, &menu->soundName ) ) return qfalse; - } + return qtrue; } -qboolean MenuParse_fadeClamp( itemDef_t *item, int handle ) { - menuDef_t *menu = (menuDef_t*)item; +qboolean MenuParse_fadeClamp( itemDef_t *item, int handle ) +{ + menuDef_t * menu = ( menuDef_t* )item; - if (!PC_Float_Parse(handle, &menu->fadeClamp)) { + if( !PC_Float_Parse( handle, &menu->fadeClamp ) ) return qfalse; - } + return qtrue; } -qboolean MenuParse_fadeAmount( itemDef_t *item, int handle ) { - menuDef_t *menu = (menuDef_t*)item; +qboolean MenuParse_fadeAmount( itemDef_t *item, int handle ) +{ + menuDef_t * menu = ( menuDef_t* )item; - if (!PC_Float_Parse(handle, &menu->fadeAmount)) { + if( !PC_Float_Parse( handle, &menu->fadeAmount ) ) return qfalse; - } + return qtrue; } -qboolean MenuParse_fadeCycle( itemDef_t *item, int handle ) { - menuDef_t *menu = (menuDef_t*)item; +qboolean MenuParse_fadeCycle( itemDef_t *item, int handle ) +{ + menuDef_t * menu = ( menuDef_t* )item; - if (!PC_Int_Parse(handle, &menu->fadeCycle)) { + if( !PC_Int_Parse( handle, &menu->fadeCycle ) ) return qfalse; - } + return qtrue; } -qboolean MenuParse_itemDef( itemDef_t *item, int handle ) { - menuDef_t *menu = (menuDef_t*)item; - if (menu->itemCount < MAX_MENUITEMS) { - menu->items[menu->itemCount] = UI_Alloc(sizeof(itemDef_t)); - Item_Init(menu->items[menu->itemCount]); - if (!Item_Parse(handle, menu->items[menu->itemCount])) { +qboolean MenuParse_itemDef( itemDef_t *item, int handle ) +{ + menuDef_t * menu = ( menuDef_t* )item; + + if( menu->itemCount < MAX_MENUITEMS ) + { + menu->items[menu->itemCount] = UI_Alloc( sizeof( itemDef_t ) ); + Item_Init( menu->items[menu->itemCount] ); + + if( !Item_Parse( handle, menu->items[menu->itemCount] ) ) return qfalse; - } - Item_InitControls(menu->items[menu->itemCount]); + + Item_InitControls( menu->items[menu->itemCount] ); menu->items[menu->itemCount++]->parent = menu; } + return qtrue; } @@ -6901,7 +7884,7 @@ void Menu_SetupKeywordHash( void ) memset( menuParseKeywordHash, 0, sizeof( menuParseKeywordHash ) ); - for(i = 0; menuParseKeywords[ i ].keyword; i++ ) + for( i = 0; menuParseKeywords[ i ].keyword; i++ ) KeywordHash_Add( menuParseKeywordHash, &menuParseKeywords[ i ] ); } @@ -6910,38 +7893,45 @@ void Menu_SetupKeywordHash( void ) Menu_Parse =============== */ -qboolean Menu_Parse(int handle, menuDef_t *menu) { +qboolean Menu_Parse( int handle, menuDef_t *menu ) +{ pc_token_t token; keywordHash_t *key; - if (!trap_Parse_ReadToken(handle, &token)) + if( !trap_Parse_ReadToken( handle, &token ) ) return qfalse; - if (*token.string != '{') { + + if( *token.string != '{' ) return qfalse; - } - while ( 1 ) { + while( 1 ) + { + memset( &token, 0, sizeof( pc_token_t ) ); - memset(&token, 0, sizeof(pc_token_t)); - if (!trap_Parse_ReadToken(handle, &token)) { - PC_SourceError(handle, "end of file inside menu\n"); + if( !trap_Parse_ReadToken( handle, &token ) ) + { + PC_SourceError( handle, "end of file inside menu\n" ); return qfalse; } - if (*token.string == '}') { + if( *token.string == '}' ) return qtrue; - } - key = KeywordHash_Find(menuParseKeywordHash, token.string); - if (!key) { - PC_SourceError(handle, "unknown menu keyword %s", token.string); + key = KeywordHash_Find( menuParseKeywordHash, token.string ); + + if( !key ) + { + PC_SourceError( handle, "unknown menu keyword %s", token.string ); continue; } - if ( !key->func((itemDef_t*)menu, handle) ) { - PC_SourceError(handle, "couldn't parse menu keyword %s", token.string); + + if( !key->func( ( itemDef_t* )menu, handle ) ) + { + PC_SourceError( handle, "couldn't parse menu keyword %s", token.string ); return qfalse; } } + return qfalse; } @@ -6950,23 +7940,29 @@ qboolean Menu_Parse(int handle, menuDef_t *menu) { Menu_New =============== */ -void Menu_New(int handle) { - menuDef_t *menu = &Menus[menuCount]; +void Menu_New( int handle ) +{ + menuDef_t * menu = &Menus[menuCount]; + + if( menuCount < MAX_MENUS ) + { + Menu_Init( menu ); - if (menuCount < MAX_MENUS) { - Menu_Init(menu); - if (Menu_Parse(handle, menu)) { - Menu_PostParse(menu); + if( Menu_Parse( handle, menu ) ) + { + Menu_PostParse( menu ); menuCount++; } } } -int Menu_Count( void ) { +int Menu_Count( void ) +{ return menuCount; } -void Menu_PaintAll( void ) { +void Menu_PaintAll( void ) +{ int i; if( g_editingField || g_waitingForKey ) @@ -6974,21 +7970,21 @@ void Menu_PaintAll( void ) { else DC->setCVar( "ui_hideCursor", "0" ); - if ( captureFunc != voidFunction ) { - if( captureFuncExpiry > 0 && DC->realTime > captureFuncExpiry ) { + if( captureFunc != voidFunction ) + { + if( captureFuncExpiry > 0 && DC->realTime > captureFuncExpiry ) UI_RemoveCaptureFunc( ); - } else { - captureFunc(captureData); - } + else + captureFunc( captureData ); } - for (i = 0; i < Menu_Count(); i++) { - Menu_Paint(&Menus[i], qfalse); - } + for( i = 0; i < Menu_Count(); i++ ) + Menu_Paint( &Menus[i], qfalse ); - if (DC->getCVarValue( "ui_developer" )) { + if( DC->getCVarValue( "ui_developer" ) ) + { vec4_t v = {1, 1, 1, 1}; - UI_Text_Paint(5, 25, .5, v, va("fps: %f", DC->FPS), 0, 0, 0); + UI_Text_Paint( 5, 25, .5, v, va( "fps: %f", DC->FPS ), 0, 0, 0 ); } } @@ -6997,146 +7993,168 @@ void Menu_Reset( void ) menuCount = 0; } -displayContextDef_t *Display_GetContext( void ) { +displayContextDef_t *Display_GetContext( void ) +{ return DC; } -void *Display_CaptureItem(int x, int y) { +void *Display_CaptureItem( int x, int y ) +{ int i; - for (i = 0; i < menuCount; i++) { - // turn off focus each item - // menu->items[i].window.flags &= ~WINDOW_HASFOCUS; - if (Rect_ContainsPoint(&Menus[i].window.rect, x, y)) { - return &Menus[i]; - } + for( i = 0; i < menuCount; i++ ) + { + if( Rect_ContainsPoint( &Menus[i].window.rect, x, y ) ) + return & Menus[i]; } + return NULL; } // FIXME: -qboolean Display_MouseMove(void *p, float x, float y) { +qboolean Display_MouseMove( void *p, float x, float y ) +{ int i; menuDef_t *menu = p; - if (menu == NULL) { + if( menu == NULL ) + { menu = Menu_GetFocused(); - if (menu) { - if (menu->window.flags & WINDOW_POPUP) { - Menu_HandleMouseMove(menu, x, y); + + if( menu ) + { + if( menu->window.flags & WINDOW_POPUP ) + { + Menu_HandleMouseMove( menu, x, y ); return qtrue; } } - for (i = 0; i < menuCount; i++) { - Menu_HandleMouseMove(&Menus[i], x, y); - } - } else { + + for( i = 0; i < menuCount; i++ ) + Menu_HandleMouseMove( &Menus[i], x, y ); + } + else + { menu->window.rect.x += x; menu->window.rect.y += y; - Menu_UpdatePosition(menu); + Menu_UpdatePosition( menu ); } + return qtrue; } -int Display_CursorType(int x, int y) { +int Display_CursorType( int x, int y ) +{ int i; - for (i = 0; i < menuCount; i++) { + + for( i = 0; i < menuCount; i++ ) + { rectDef_t r2; r2.x = Menus[i].window.rect.x - 3; r2.y = Menus[i].window.rect.y - 3; r2.w = r2.h = 7; - if (Rect_ContainsPoint(&r2, x, y)) { + + if( Rect_ContainsPoint( &r2, x, y ) ) return CURSOR_SIZER; - } } + return CURSOR_ARROW; } -void Display_HandleKey(int key, qboolean down, int x, int y) { - menuDef_t *menu = Display_CaptureItem(x, y); - if (menu == NULL) { +void Display_HandleKey( int key, qboolean down, int x, int y ) +{ + menuDef_t * menu = Display_CaptureItem( x, y ); + + if( menu == NULL ) menu = Menu_GetFocused(); - } - if (menu) { - Menu_HandleKey(menu, key, down ); - } + + if( menu ) + Menu_HandleKey( menu, key, down ); } -static void Window_CacheContents(windowDef_t *window) { - if (window) { - if (window->cinematicName) { - int cin = DC->playCinematic(window->cinematicName, 0, 0, 0, 0); - DC->stopCinematic(cin); +static void Window_CacheContents( windowDef_t *window ) +{ + if( window ) + { + if( window->cinematicName ) + { + int cin = DC->playCinematic( window->cinematicName, 0, 0, 0, 0 ); + DC->stopCinematic( cin ); } } } -static void Item_CacheContents(itemDef_t *item) { - if (item) { - Window_CacheContents(&item->window); - } +static void Item_CacheContents( itemDef_t *item ) +{ + if( item ) + Window_CacheContents( &item->window ); } -static void Menu_CacheContents(menuDef_t *menu) { - if (menu) { +static void Menu_CacheContents( menuDef_t *menu ) +{ + if( menu ) + { int i; - Window_CacheContents(&menu->window); - for (i = 0; i < menu->itemCount; i++) { - Item_CacheContents(menu->items[i]); - } + Window_CacheContents( &menu->window ); - if (menu->soundName && *menu->soundName) { - DC->registerSound(menu->soundName, qfalse); - } + for( i = 0; i < menu->itemCount; i++ ) + Item_CacheContents( menu->items[i] ); + + if( menu->soundName && *menu->soundName ) + DC->registerSound( menu->soundName, qfalse ); } } -void Display_CacheAll( void ) { +void Display_CacheAll( void ) +{ int i; - for (i = 0; i < menuCount; i++) { - Menu_CacheContents(&Menus[i]); - } + + for( i = 0; i < menuCount; i++ ) + Menu_CacheContents( &Menus[i] ); } -static qboolean Menu_OverActiveItem(menuDef_t *menu, float x, float y) { - if (menu && menu->window.flags & (WINDOW_VISIBLE | WINDOW_FORCED)) { - if (Rect_ContainsPoint(&menu->window.rect, x, y)) { +static qboolean Menu_OverActiveItem( menuDef_t *menu, float x, float y ) +{ + if( menu && menu->window.flags & ( WINDOW_VISIBLE | WINDOW_FORCED ) ) + { + if( Rect_ContainsPoint( &menu->window.rect, x, y ) ) + { int i; - for (i = 0; i < menu->itemCount; i++) { - // turn off focus each item - // menu->items[i].window.flags &= ~WINDOW_HASFOCUS; - if (!(menu->items[i]->window.flags & (WINDOW_VISIBLE | WINDOW_FORCED))) { + for( i = 0; i < menu->itemCount; i++ ) + { + if( !( menu->items[i]->window.flags & ( WINDOW_VISIBLE | WINDOW_FORCED ) ) ) continue; - } - if (menu->items[i]->window.flags & WINDOW_DECORATION) { + if( menu->items[i]->window.flags & WINDOW_DECORATION ) continue; - } - if (Rect_ContainsPoint(&menu->items[i]->window.rect, x, y)) { - itemDef_t *overItem = menu->items[i]; - if (overItem->type == ITEM_TYPE_TEXT && overItem->text) { - if (Rect_ContainsPoint(Item_CorrectedTextRect(overItem), x, y)) { + if( Rect_ContainsPoint( &menu->items[i]->window.rect, x, y ) ) + { + itemDef_t * overItem = menu->items[i]; + + if( overItem->type == ITEM_TYPE_TEXT && overItem->text ) + { + if( Rect_ContainsPoint( Item_CorrectedTextRect( overItem ), x, y ) ) return qtrue; - } else { + else continue; - } - } else { - return qtrue; } + else + return qtrue; } } } } + return qfalse; } diff --git a/src/ui/ui_shared.h b/src/ui/ui_shared.h index 58bd2b6f..6c6be08c 100644 --- a/src/ui/ui_shared.h +++ b/src/ui/ui_shared.h @@ -2,19 +2,19 @@ =========================================================================== Copyright (C) 1999-2005 Id Software, Inc. Copyright (C) 2000-2006 Tim Angus - + This file is part of Tremulous. - + Tremulous is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + Tremulous is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with Tremulous; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA @@ -109,23 +109,29 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define SLIDER_THUMB_HEIGHT 20.0f #define NUM_CROSSHAIRS 10 -typedef struct { +typedef struct +{ const char *command; const char *args[MAX_SCRIPT_ARGS]; -} scriptDef_t; +} +scriptDef_t; -typedef struct { +typedef struct +{ float x; // horiz position float y; // vert position float w; // width float h; // height; -} rectDef_t; +} +rectDef_t; typedef rectDef_t Rectangle; // FIXME: do something to separate text vs window stuff -typedef struct { + +typedef struct +{ Rectangle rect; // client coord rectangle int aspectBias; // direction in which to aspect compensate Rectangle rectClient; // screen coord rectangle @@ -148,15 +154,18 @@ typedef struct { vec4_t borderColor; // border color vec4_t outlineColor; // border color qhandle_t background; // background asset -} windowDef_t; +} +windowDef_t; typedef windowDef_t Window; -typedef struct { +typedef struct +{ vec4_t color; float low; float high; -} colorRangeDef_t; +} +colorRangeDef_t; // FIXME: combine flags into bitfields to save space // FIXME: consolidate all of the common stuff in one structure for menus and items @@ -170,13 +179,16 @@ typedef struct { // #define MAX_LB_COLUMNS 16 -typedef struct columnInfo_s { +typedef struct columnInfo_s +{ int pos; int width; int align; -} columnInfo_t; +} +columnInfo_t; -typedef struct listBoxDef_s { +typedef struct listBoxDef_s +{ int startPos; int endPos; int drawPadding; @@ -189,9 +201,12 @@ typedef struct listBoxDef_s { const char *doubleClick; qboolean notselectable; qboolean noscrollbar; -} listBoxDef_t; +} + +listBoxDef_t; -typedef struct editFieldDef_s { +typedef struct editFieldDef_s +{ float minVal; // edit field limits float maxVal; // float defVal; // @@ -200,32 +215,38 @@ typedef struct editFieldDef_s { int maxPaintChars; // for edit fields int maxFieldWidth; // for edit fields int paintOffset; // -} editFieldDef_t; +} +editFieldDef_t; #define MAX_MULTI_CVARS 32 -typedef struct multiDef_s { +typedef struct multiDef_s +{ const char *cvarList[MAX_MULTI_CVARS]; const char *cvarStr[MAX_MULTI_CVARS]; float cvarValue[MAX_MULTI_CVARS]; int count; qboolean strDef; -} multiDef_t; +} +multiDef_t; -typedef struct modelDef_s { +typedef struct modelDef_s +{ int angle; vec3_t origin; float fov_x; float fov_y; int rotationSpeed; -} modelDef_t; +} +modelDef_t; #define CVAR_ENABLE 0x00000001 #define CVAR_DISABLE 0x00000002 #define CVAR_SHOW 0x00000004 #define CVAR_HIDE 0x00000008 -typedef struct itemDef_s { +typedef struct itemDef_s +{ Window window; // common positional, border, style, layout info Rectangle textRect; // rectangle the text ( if any ) consumes int type; // text, button, radiobutton, checkbox, textfield, listbox, combo @@ -257,9 +278,11 @@ typedef struct itemDef_s { float special; // used for feeder id's etc.. diff per type int cursorPos; // cursor position in characters void *typeData; // type specific data ptr's -} itemDef_t; +} +itemDef_t; -typedef struct { +typedef struct +{ Window window; const char *font; // font qboolean fullScreen; // covers entire screen @@ -277,9 +300,11 @@ typedef struct { vec4_t focusColor; // focus color for items vec4_t disableColor; // focus color for items itemDef_t *items[MAX_MENUITEMS]; // items this menu contains -} menuDef_t; +} +menuDef_t; -typedef struct { +typedef struct +{ const char *fontStr; const char *cursorStr; const char *gradientStr; @@ -312,60 +337,64 @@ typedef struct { float shadowFadeClamp; qboolean fontRegistered; -} cachedAssets_t; +} +cachedAssets_t; -typedef struct { +typedef struct +{ const char *name; - void (*handler) (itemDef_t *item, char** args); -} commandDef_t; - -typedef struct { - qhandle_t (*registerShaderNoMip) (const char *p); - void (*setColor) (const vec4_t v); - void (*drawHandlePic) (float x, float y, float w, float h, qhandle_t asset); - void (*drawStretchPic) (float x, float y, float w, float h, float s1, float t1, float s2, float t2, qhandle_t hShader ); - qhandle_t (*registerModel) (const char *p); - void (*modelBounds) (qhandle_t model, vec3_t min, vec3_t max); - void (*fillRect) ( float x, float y, float w, float h, const vec4_t color); - void (*drawRect) ( float x, float y, float w, float h, float size, const vec4_t color); - void (*drawSides) (float x, float y, float w, float h, float size); - void (*drawTopBottom) (float x, float y, float w, float h, float size); - void (*clearScene) (void); - void (*addRefEntityToScene) (const refEntity_t *re ); - void (*renderScene) ( const refdef_t *fd ); - void (*registerFont) (const char *pFontname, int pointSize, fontInfo_t *font); - void (*ownerDrawItem) (float x, float y, float w, float h, float text_x, float text_y, int ownerDraw, int ownerDrawFlags, int align, int textalign, int textvalign, float special, float scale, vec4_t color, qhandle_t shader, int textStyle); - float (*getValue) (int ownerDraw); - qboolean (*ownerDrawVisible) (int flags); - void (*runScript)(char **p); - void (*getCVarString)(const char *cvar, char *buffer, int bufsize); - float (*getCVarValue)(const char *cvar); - void (*setCVar)(const char *cvar, const char *value); - void (*drawTextWithCursor)(float x, float y, float scale, vec4_t color, const char *text, int cursorPos, char cursor, int limit, int style); - void (*setOverstrikeMode)(qboolean b); - qboolean (*getOverstrikeMode)( void ); - void (*startLocalSound)( sfxHandle_t sfx, int channelNum ); - qboolean (*ownerDrawHandleKey)(int ownerDraw, int flags, float *special, int key); - int (*feederCount)(float feederID); - const char *(*feederItemText)(float feederID, int index, int column, qhandle_t *handle); - qhandle_t (*feederItemImage)(float feederID, int index); - void (*feederSelection)(float feederID, int index); - void (*keynumToStringBuf)( int keynum, char *buf, int buflen ); - void (*getBindingBuf)( int keynum, char *buf, int buflen ); - void (*setBinding)( int keynum, const char *binding ); - void (*executeText)(int exec_when, const char *text ); - void (*Error)(int level, const char *error, ...); - void (*Print)(const char *msg, ...); - void (*Pause)(qboolean b); - int (*ownerDrawWidth)(int ownerDraw, float scale); - const char *(*ownerDrawText)(int ownerDraw); - sfxHandle_t (*registerSound)(const char *name, qboolean compressed); - void (*startBackgroundTrack)( const char *intro, const char *loop); - void (*stopBackgroundTrack)( void ); - int (*playCinematic)(const char *name, float x, float y, float w, float h); - void (*stopCinematic)(int handle); - void (*drawCinematic)(int handle, float x, float y, float w, float h); - void (*runCinematicFrame)(int handle); + void ( *handler ) ( itemDef_t *item, char** args ); +} +commandDef_t; + +typedef struct +{ + qhandle_t ( *registerShaderNoMip ) ( const char *p ); + void ( *setColor ) ( const vec4_t v ); + void ( *drawHandlePic ) ( float x, float y, float w, float h, qhandle_t asset ); + void ( *drawStretchPic ) ( float x, float y, float w, float h, float s1, float t1, float s2, float t2, qhandle_t hShader ); + qhandle_t ( *registerModel ) ( const char *p ); + void ( *modelBounds ) ( qhandle_t model, vec3_t min, vec3_t max ); + void ( *fillRect ) ( float x, float y, float w, float h, const vec4_t color ); + void ( *drawRect ) ( float x, float y, float w, float h, float size, const vec4_t color ); + void ( *drawSides ) ( float x, float y, float w, float h, float size ); + void ( *drawTopBottom ) ( float x, float y, float w, float h, float size ); + void ( *clearScene ) ( void ); + void ( *addRefEntityToScene ) ( const refEntity_t *re ); + void ( *renderScene ) ( const refdef_t *fd ); + void ( *registerFont ) ( const char *pFontname, int pointSize, fontInfo_t *font ); + void ( *ownerDrawItem ) ( float x, float y, float w, float h, float text_x, float text_y, int ownerDraw, int ownerDrawFlags, int align, int textalign, int textvalign, float special, float scale, vec4_t color, qhandle_t shader, int textStyle ); + float ( *getValue ) ( int ownerDraw ); + qboolean ( *ownerDrawVisible ) ( int flags ); + void ( *runScript )( char **p ); + void ( *getCVarString )( const char *cvar, char *buffer, int bufsize ); + float ( *getCVarValue )( const char *cvar ); + void ( *setCVar )( const char *cvar, const char *value ); + void ( *drawTextWithCursor )( float x, float y, float scale, vec4_t color, const char *text, int cursorPos, char cursor, int limit, int style ); + void ( *setOverstrikeMode )( qboolean b ); + qboolean ( *getOverstrikeMode )( void ); + void ( *startLocalSound )( sfxHandle_t sfx, int channelNum ); + qboolean ( *ownerDrawHandleKey )( int ownerDraw, int flags, float *special, int key ); + int ( *feederCount )( float feederID ); + const char *( *feederItemText )( float feederID, int index, int column, qhandle_t *handle ); + qhandle_t ( *feederItemImage )( float feederID, int index ); + void ( *feederSelection )( float feederID, int index ); + void ( *keynumToStringBuf )( int keynum, char *buf, int buflen ); + void ( *getBindingBuf )( int keynum, char *buf, int buflen ); + void ( *setBinding )( int keynum, const char *binding ); + void ( *executeText )( int exec_when, const char *text ); + void ( *Error )( int level, const char *error, ... ); + void ( *Print )( const char *msg, ... ); + void ( *Pause )( qboolean b ); + int ( *ownerDrawWidth )( int ownerDraw, float scale ); + const char *( *ownerDrawText )( int ownerDraw ); + sfxHandle_t ( *registerSound )( const char *name, qboolean compressed ); + void ( *startBackgroundTrack )( const char *intro, const char *loop ); + void ( *stopBackgroundTrack )( void ); + int ( *playCinematic )( const char *name, float x, float y, float w, float h ); + void ( *stopCinematic )( int handle ); + void ( *drawCinematic )( int handle, float x, float y, float w, float h ); + void ( *runCinematicFrame )( int handle ); float yscale; float xscale; @@ -384,55 +413,56 @@ typedef struct { qhandle_t cursor; float FPS; -} displayContextDef_t; +} +displayContextDef_t; -const char *String_Alloc(const char *p); +const char *String_Alloc( const char *p ); void String_Init( void ); void String_Report( void ); -void Init_Display(displayContextDef_t *dc); -void Display_ExpandMacros(char * buff); -void Menu_Init(menuDef_t *menu); -void Item_Init(itemDef_t *item); -void Menu_PostParse(menuDef_t *menu); +void Init_Display( displayContextDef_t *dc ); +void Display_ExpandMacros( char * buff ); +void Menu_Init( menuDef_t *menu ); +void Item_Init( itemDef_t *item ); +void Menu_PostParse( menuDef_t *menu ); menuDef_t *Menu_GetFocused( void ); -void Menu_HandleKey(menuDef_t *menu, int key, qboolean down); -void Menu_HandleMouseMove(menuDef_t *menu, float x, float y); -void Menu_ScrollFeeder(menuDef_t *menu, int feeder, qboolean down); -qboolean Float_Parse(char **p, float *f); -qboolean Color_Parse(char **p, vec4_t *c); -qboolean Int_Parse(char **p, int *i); -qboolean Rect_Parse(char **p, rectDef_t *r); -qboolean String_Parse(char **p, const char **out); -qboolean Script_Parse(char **p, const char **out); -qboolean PC_Float_Parse(int handle, float *f); -qboolean PC_Color_Parse(int handle, vec4_t *c); -qboolean PC_Int_Parse(int handle, int *i); -qboolean PC_Rect_Parse(int handle, rectDef_t *r); -qboolean PC_String_Parse(int handle, const char **out); -qboolean PC_Script_Parse(int handle, const char **out); +void Menu_HandleKey( menuDef_t *menu, int key, qboolean down ); +void Menu_HandleMouseMove( menuDef_t *menu, float x, float y ); +void Menu_ScrollFeeder( menuDef_t *menu, int feeder, qboolean down ); +qboolean Float_Parse( char **p, float *f ); +qboolean Color_Parse( char **p, vec4_t *c ); +qboolean Int_Parse( char **p, int *i ); +qboolean Rect_Parse( char **p, rectDef_t *r ); +qboolean String_Parse( char **p, const char **out ); +qboolean Script_Parse( char **p, const char **out ); +qboolean PC_Float_Parse( int handle, float *f ); +qboolean PC_Color_Parse( int handle, vec4_t *c ); +qboolean PC_Int_Parse( int handle, int *i ); +qboolean PC_Rect_Parse( int handle, rectDef_t *r ); +qboolean PC_String_Parse( int handle, const char **out ); +qboolean PC_Script_Parse( int handle, const char **out ); int Menu_Count( void ); -void Menu_New(int handle); +void Menu_New( int handle ); void Menu_PaintAll( void ); -menuDef_t *Menus_ActivateByName(const char *p); +menuDef_t *Menus_ActivateByName( const char *p ); void Menu_Reset( void ); qboolean Menus_AnyFullScreenVisible( void ); -void Menus_Activate(menuDef_t *menu); +void Menus_Activate( menuDef_t *menu ); displayContextDef_t *Display_GetContext( void ); -void *Display_CaptureItem(int x, int y); -qboolean Display_MouseMove(void *p, float x, float y); -int Display_CursorType(int x, int y); +void *Display_CaptureItem( int x, int y ); +qboolean Display_MouseMove( void *p, float x, float y ); +int Display_CursorType( int x, int y ); qboolean Display_KeyBindPending( void ); -menuDef_t *Menus_FindByName(const char *p); -void Menus_CloseByName(const char *p); -void Display_HandleKey(int key, qboolean down, int x, int y); -void LerpColor(vec4_t a, vec4_t b, vec4_t c, float t); +menuDef_t *Menus_FindByName( const char *p ); +void Menus_CloseByName( const char *p ); +void Display_HandleKey( int key, qboolean down, int x, int y ); +void LerpColor( vec4_t a, vec4_t b, vec4_t c, float t ); void Menus_CloseAll( void ); -void Menu_Paint(menuDef_t *menu, qboolean forcePaint); -void Menu_SetFeederSelection(menuDef_t *menu, int feeder, int index, const char *name); +void Menu_Paint( menuDef_t *menu, qboolean forcePaint ); +void Menu_SetFeederSelection( menuDef_t *menu, int feeder, int index, const char *name ); void Display_CacheAll( void ); -typedef void (CaptureFunc) (void *p); +typedef void ( CaptureFunc ) ( void *p ); void UI_InstallCaptureFunc( CaptureFunc *f, void *data, int timeout ); void UI_RemoveCaptureFunc( void ); @@ -442,7 +472,7 @@ void UI_InitMemory( void ); qboolean UI_OutOfMemory( void ); void Controls_GetConfig( void ); -void Controls_SetConfig(qboolean restart); +void Controls_SetConfig( qboolean restart ); void Controls_SetDefaults( void ); //for cg_draw.c @@ -450,11 +480,11 @@ void Item_Text_Wrapped_Paint( itemDef_t *item ); void UI_DrawTextBlock( rectDef_t *rect, float text_x, float text_y, vec4_t color, float scale, int textalign, int textvalign, int textStyle, const char *text ); -void UI_Text_Paint(float x, float y, float scale, vec4_t color, const char *text, float adjust, int limit, int style); +void UI_Text_Paint( float x, float y, float scale, vec4_t color, const char *text, float adjust, int limit, int style ); void UI_Text_Paint_Limit( float *maxX, float x, float y, float scale, vec4_t color, const char* text, float adjust, int limit ); -float UI_Text_Width(const char *text, float scale, int limit); -float UI_Text_Height(const char *text, float scale, int limit); +float UI_Text_Width( const char *text, float scale, int limit ); +float UI_Text_Height( const char *text, float scale, int limit ); float UI_Text_EmWidth( float scale ); float UI_Text_EmHeight( float scale ); diff --git a/src/ui/ui_syscalls.c b/src/ui/ui_syscalls.c index 528658e4..0c8143f7 100644 --- a/src/ui/ui_syscalls.c +++ b/src/ui/ui_syscalls.c @@ -2,19 +2,19 @@ =========================================================================== Copyright (C) 1999-2005 Id Software, Inc. Copyright (C) 2000-2006 Tim Angus - + This file is part of Tremulous. - + Tremulous is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + Tremulous is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with Tremulous; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA @@ -26,362 +26,448 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // this file is only included when building a dll // syscalls.asm is included instead when building a qvm -static intptr_t (QDECL *syscall)( intptr_t arg, ... ) = (intptr_t (QDECL *)( intptr_t, ...))-1; +static intptr_t ( QDECL *syscall )( intptr_t arg, ... ) = ( intptr_t ( QDECL * )( intptr_t, ... ) ) - 1; -void dllEntry( intptr_t (QDECL *syscallptr)( intptr_t arg,... ) ) { +void dllEntry( intptr_t ( QDECL *syscallptr )( intptr_t arg, ... ) ) +{ syscall = syscallptr; } -int PASSFLOAT( float x ) { +int PASSFLOAT( float x ) +{ float floatTemp; floatTemp = x; - return *(int *)&floatTemp; + return *( int * ) & floatTemp; } -void trap_Print( const char *string ) { +void trap_Print( const char *string ) +{ syscall( UI_PRINT, string ); } -void trap_Error( const char *string ) { +void trap_Error( const char *string ) +{ syscall( UI_ERROR, string ); } -int trap_Milliseconds( void ) { +int trap_Milliseconds( void ) +{ return syscall( UI_MILLISECONDS ); } -void trap_Cvar_Register( vmCvar_t *cvar, const char *var_name, const char *value, int flags ) { +void trap_Cvar_Register( vmCvar_t *cvar, const char *var_name, const char *value, int flags ) +{ syscall( UI_CVAR_REGISTER, cvar, var_name, value, flags ); } -void trap_Cvar_Update( vmCvar_t *cvar ) { +void trap_Cvar_Update( vmCvar_t *cvar ) +{ syscall( UI_CVAR_UPDATE, cvar ); } -void trap_Cvar_Set( const char *var_name, const char *value ) { +void trap_Cvar_Set( const char *var_name, const char *value ) +{ syscall( UI_CVAR_SET, var_name, value ); } -float trap_Cvar_VariableValue( const char *var_name ) { +float trap_Cvar_VariableValue( const char *var_name ) +{ int temp; temp = syscall( UI_CVAR_VARIABLEVALUE, var_name ); - return (*(float*)&temp); + return ( *( float* ) & temp ); } -void trap_Cvar_VariableStringBuffer( const char *var_name, char *buffer, int bufsize ) { +void trap_Cvar_VariableStringBuffer( const char *var_name, char *buffer, int bufsize ) +{ syscall( UI_CVAR_VARIABLESTRINGBUFFER, var_name, buffer, bufsize ); } -void trap_Cvar_SetValue( const char *var_name, float value ) { +void trap_Cvar_SetValue( const char *var_name, float value ) +{ syscall( UI_CVAR_SETVALUE, var_name, PASSFLOAT( value ) ); } -void trap_Cvar_Reset( const char *name ) { +void trap_Cvar_Reset( const char *name ) +{ syscall( UI_CVAR_RESET, name ); } -void trap_Cvar_Create( const char *var_name, const char *var_value, int flags ) { +void trap_Cvar_Create( const char *var_name, const char *var_value, int flags ) +{ syscall( UI_CVAR_CREATE, var_name, var_value, flags ); } -void trap_Cvar_InfoStringBuffer( int bit, char *buffer, int bufsize ) { +void trap_Cvar_InfoStringBuffer( int bit, char *buffer, int bufsize ) +{ syscall( UI_CVAR_INFOSTRINGBUFFER, bit, buffer, bufsize ); } -int trap_Argc( void ) { +int trap_Argc( void ) +{ return syscall( UI_ARGC ); } -void trap_Argv( int n, char *buffer, int bufferLength ) { +void trap_Argv( int n, char *buffer, int bufferLength ) +{ syscall( UI_ARGV, n, buffer, bufferLength ); } -void trap_Cmd_ExecuteText( int exec_when, const char *text ) { +void trap_Cmd_ExecuteText( int exec_when, const char *text ) +{ syscall( UI_CMD_EXECUTETEXT, exec_when, text ); } -int trap_FS_FOpenFile( const char *qpath, fileHandle_t *f, fsMode_t mode ) { +int trap_FS_FOpenFile( const char *qpath, fileHandle_t *f, fsMode_t mode ) +{ return syscall( UI_FS_FOPENFILE, qpath, f, mode ); } -void trap_FS_Read( void *buffer, int len, fileHandle_t f ) { +void trap_FS_Read( void *buffer, int len, fileHandle_t f ) +{ syscall( UI_FS_READ, buffer, len, f ); } -void trap_FS_Write( const void *buffer, int len, fileHandle_t f ) { +void trap_FS_Write( const void *buffer, int len, fileHandle_t f ) +{ syscall( UI_FS_WRITE, buffer, len, f ); } -void trap_FS_FCloseFile( fileHandle_t f ) { +void trap_FS_FCloseFile( fileHandle_t f ) +{ syscall( UI_FS_FCLOSEFILE, f ); } -int trap_FS_GetFileList( const char *path, const char *extension, char *listbuf, int bufsize ) { +int trap_FS_GetFileList( const char *path, const char *extension, char *listbuf, int bufsize ) +{ return syscall( UI_FS_GETFILELIST, path, extension, listbuf, bufsize ); } -int trap_FS_Seek( fileHandle_t f, long offset, int origin ) { - return syscall( UI_FS_SEEK, f, offset, origin ); +int trap_FS_Seek( fileHandle_t f, long offset, int origin ) +{ + return syscall( UI_FS_SEEK, f, offset, origin ); } -qhandle_t trap_R_RegisterModel( const char *name ) { +qhandle_t trap_R_RegisterModel( const char *name ) +{ return syscall( UI_R_REGISTERMODEL, name ); } -qhandle_t trap_R_RegisterSkin( const char *name ) { +qhandle_t trap_R_RegisterSkin( const char *name ) +{ return syscall( UI_R_REGISTERSKIN, name ); } -void trap_R_RegisterFont(const char *fontName, int pointSize, fontInfo_t *font) { +void trap_R_RegisterFont( const char *fontName, int pointSize, fontInfo_t *font ) +{ syscall( UI_R_REGISTERFONT, fontName, pointSize, font ); } -qhandle_t trap_R_RegisterShaderNoMip( const char *name ) { +qhandle_t trap_R_RegisterShaderNoMip( const char *name ) +{ return syscall( UI_R_REGISTERSHADERNOMIP, name ); } -void trap_R_ClearScene( void ) { +void trap_R_ClearScene( void ) +{ syscall( UI_R_CLEARSCENE ); } -void trap_R_AddRefEntityToScene( const refEntity_t *re ) { +void trap_R_AddRefEntityToScene( const refEntity_t *re ) +{ syscall( UI_R_ADDREFENTITYTOSCENE, re ); } -void trap_R_AddPolyToScene( qhandle_t hShader , int numVerts, const polyVert_t *verts ) { +void trap_R_AddPolyToScene( qhandle_t hShader , int numVerts, const polyVert_t *verts ) +{ syscall( UI_R_ADDPOLYTOSCENE, hShader, numVerts, verts ); } -void trap_R_AddLightToScene( const vec3_t org, float intensity, float r, float g, float b ) { - syscall( UI_R_ADDLIGHTTOSCENE, org, PASSFLOAT(intensity), PASSFLOAT(r), PASSFLOAT(g), PASSFLOAT(b) ); +void trap_R_AddLightToScene( const vec3_t org, float intensity, float r, float g, float b ) +{ + syscall( UI_R_ADDLIGHTTOSCENE, org, PASSFLOAT( intensity ), PASSFLOAT( r ), PASSFLOAT( g ), PASSFLOAT( b ) ); } -void trap_R_RenderScene( const refdef_t *fd ) { +void trap_R_RenderScene( const refdef_t *fd ) +{ syscall( UI_R_RENDERSCENE, fd ); } -void trap_R_SetColor( const float *rgba ) { +void trap_R_SetColor( const float *rgba ) +{ syscall( UI_R_SETCOLOR, rgba ); } -void trap_R_DrawStretchPic( float x, float y, float w, float h, float s1, float t1, float s2, float t2, qhandle_t hShader ) { - syscall( UI_R_DRAWSTRETCHPIC, PASSFLOAT(x), PASSFLOAT(y), PASSFLOAT(w), PASSFLOAT(h), PASSFLOAT(s1), PASSFLOAT(t1), PASSFLOAT(s2), PASSFLOAT(t2), hShader ); +void trap_R_DrawStretchPic( float x, float y, float w, float h, float s1, float t1, float s2, float t2, qhandle_t hShader ) +{ + syscall( UI_R_DRAWSTRETCHPIC, PASSFLOAT( x ), PASSFLOAT( y ), PASSFLOAT( w ), PASSFLOAT( h ), PASSFLOAT( s1 ), PASSFLOAT( t1 ), PASSFLOAT( s2 ), PASSFLOAT( t2 ), hShader ); } -void trap_R_ModelBounds( clipHandle_t model, vec3_t mins, vec3_t maxs ) { +void trap_R_ModelBounds( clipHandle_t model, vec3_t mins, vec3_t maxs ) +{ syscall( UI_R_MODELBOUNDS, model, mins, maxs ); } -void trap_UpdateScreen( void ) { +void trap_UpdateScreen( void ) +{ syscall( UI_UPDATESCREEN ); } -int trap_CM_LerpTag( orientation_t *tag, clipHandle_t mod, int startFrame, int endFrame, float frac, const char *tagName ) { - return syscall( UI_CM_LERPTAG, tag, mod, startFrame, endFrame, PASSFLOAT(frac), tagName ); +int trap_CM_LerpTag( orientation_t *tag, clipHandle_t mod, int startFrame, int endFrame, float frac, const char *tagName ) +{ + return syscall( UI_CM_LERPTAG, tag, mod, startFrame, endFrame, PASSFLOAT( frac ), tagName ); } -void trap_S_StartLocalSound( sfxHandle_t sfx, int channelNum ) { +void trap_S_StartLocalSound( sfxHandle_t sfx, int channelNum ) +{ syscall( UI_S_STARTLOCALSOUND, sfx, channelNum ); } -sfxHandle_t trap_S_RegisterSound( const char *sample, qboolean compressed ) { +sfxHandle_t trap_S_RegisterSound( const char *sample, qboolean compressed ) +{ return syscall( UI_S_REGISTERSOUND, sample, compressed ); } -void trap_Key_KeynumToStringBuf( int keynum, char *buf, int buflen ) { +void trap_Key_KeynumToStringBuf( int keynum, char *buf, int buflen ) +{ syscall( UI_KEY_KEYNUMTOSTRINGBUF, keynum, buf, buflen ); } -void trap_Key_GetBindingBuf( int keynum, char *buf, int buflen ) { +void trap_Key_GetBindingBuf( int keynum, char *buf, int buflen ) +{ syscall( UI_KEY_GETBINDINGBUF, keynum, buf, buflen ); } -void trap_Key_SetBinding( int keynum, const char *binding ) { +void trap_Key_SetBinding( int keynum, const char *binding ) +{ syscall( UI_KEY_SETBINDING, keynum, binding ); } -qboolean trap_Key_IsDown( int keynum ) { +qboolean trap_Key_IsDown( int keynum ) +{ return syscall( UI_KEY_ISDOWN, keynum ); } -qboolean trap_Key_GetOverstrikeMode( void ) { +qboolean trap_Key_GetOverstrikeMode( void ) +{ return syscall( UI_KEY_GETOVERSTRIKEMODE ); } -void trap_Key_SetOverstrikeMode( qboolean state ) { +void trap_Key_SetOverstrikeMode( qboolean state ) +{ syscall( UI_KEY_SETOVERSTRIKEMODE, state ); } -void trap_Key_ClearStates( void ) { +void trap_Key_ClearStates( void ) +{ syscall( UI_KEY_CLEARSTATES ); } -int trap_Key_GetCatcher( void ) { +int trap_Key_GetCatcher( void ) +{ return syscall( UI_KEY_GETCATCHER ); } -void trap_Key_SetCatcher( int catcher ) { +void trap_Key_SetCatcher( int catcher ) +{ syscall( UI_KEY_SETCATCHER, catcher ); } -void trap_GetClipboardData( char *buf, int bufsize ) { +void trap_GetClipboardData( char *buf, int bufsize ) +{ syscall( UI_GETCLIPBOARDDATA, buf, bufsize ); } -void trap_GetClientState( uiClientState_t *state ) { +void trap_GetClientState( uiClientState_t *state ) +{ syscall( UI_GETCLIENTSTATE, state ); } -void trap_GetGlconfig( glconfig_t *glconfig ) { +void trap_GetGlconfig( glconfig_t *glconfig ) +{ syscall( UI_GETGLCONFIG, glconfig ); } -int trap_GetConfigString( int index, char* buff, int buffsize ) { +int trap_GetConfigString( int index, char* buff, int buffsize ) +{ return syscall( UI_GETCONFIGSTRING, index, buff, buffsize ); } -int trap_LAN_GetServerCount( int source ) { +int trap_LAN_GetServerCount( int source ) +{ return syscall( UI_LAN_GETSERVERCOUNT, source ); } -void trap_LAN_GetServerAddressString( int source, int n, char *buf, int buflen ) { +void trap_LAN_GetServerAddressString( int source, int n, char *buf, int buflen ) +{ syscall( UI_LAN_GETSERVERADDRESSSTRING, source, n, buf, buflen ); } -void trap_LAN_GetServerInfo( int source, int n, char *buf, int buflen ) { +void trap_LAN_GetServerInfo( int source, int n, char *buf, int buflen ) +{ syscall( UI_LAN_GETSERVERINFO, source, n, buf, buflen ); } -int trap_LAN_GetServerPing( int source, int n ) { +int trap_LAN_GetServerPing( int source, int n ) +{ return syscall( UI_LAN_GETSERVERPING, source, n ); } -int trap_LAN_GetPingQueueCount( void ) { +int trap_LAN_GetPingQueueCount( void ) +{ return syscall( UI_LAN_GETPINGQUEUECOUNT ); } -int trap_LAN_ServerStatus( const char *serverAddress, char *serverStatus, int maxLen ) { +int trap_LAN_ServerStatus( const char *serverAddress, char *serverStatus, int maxLen ) +{ return syscall( UI_LAN_SERVERSTATUS, serverAddress, serverStatus, maxLen ); } -void trap_LAN_SaveCachedServers( void ) { +void trap_LAN_SaveCachedServers( void ) +{ syscall( UI_LAN_SAVECACHEDSERVERS ); } -void trap_LAN_LoadCachedServers( void ) { +void trap_LAN_LoadCachedServers( void ) +{ syscall( UI_LAN_LOADCACHEDSERVERS ); } -void trap_LAN_ResetPings(int n) { +void trap_LAN_ResetPings( int n ) +{ syscall( UI_LAN_RESETPINGS, n ); } -void trap_LAN_ClearPing( int n ) { +void trap_LAN_ClearPing( int n ) +{ syscall( UI_LAN_CLEARPING, n ); } -void trap_LAN_GetPing( int n, char *buf, int buflen, int *pingtime ) { +void trap_LAN_GetPing( int n, char *buf, int buflen, int *pingtime ) +{ syscall( UI_LAN_GETPING, n, buf, buflen, pingtime ); } -void trap_LAN_GetPingInfo( int n, char *buf, int buflen ) { +void trap_LAN_GetPingInfo( int n, char *buf, int buflen ) +{ syscall( UI_LAN_GETPINGINFO, n, buf, buflen ); } -void trap_LAN_MarkServerVisible( int source, int n, qboolean visible ) { +void trap_LAN_MarkServerVisible( int source, int n, qboolean visible ) +{ syscall( UI_LAN_MARKSERVERVISIBLE, source, n, visible ); } -int trap_LAN_ServerIsVisible( int source, int n) { +int trap_LAN_ServerIsVisible( int source, int n ) +{ return syscall( UI_LAN_SERVERISVISIBLE, source, n ); } -qboolean trap_LAN_UpdateVisiblePings( int source ) { +qboolean trap_LAN_UpdateVisiblePings( int source ) +{ return syscall( UI_LAN_UPDATEVISIBLEPINGS, source ); } -int trap_LAN_AddServer(int source, const char *name, const char *addr) { +int trap_LAN_AddServer( int source, const char *name, const char *addr ) +{ return syscall( UI_LAN_ADDSERVER, source, name, addr ); } -void trap_LAN_RemoveServer(int source, const char *addr) { +void trap_LAN_RemoveServer( int source, const char *addr ) +{ syscall( UI_LAN_REMOVESERVER, source, addr ); } -int trap_LAN_CompareServers( int source, int sortKey, int sortDir, int s1, int s2 ) { +int trap_LAN_CompareServers( int source, int sortKey, int sortDir, int s1, int s2 ) +{ return syscall( UI_LAN_COMPARESERVERS, source, sortKey, sortDir, s1, s2 ); } -int trap_MemoryRemaining( void ) { +int trap_MemoryRemaining( void ) +{ return syscall( UI_MEMORY_REMAINING ); } -int trap_Parse_AddGlobalDefine( char *define ) { +int trap_Parse_AddGlobalDefine( char *define ) +{ return syscall( UI_PARSE_ADD_GLOBAL_DEFINE, define ); } -int trap_Parse_LoadSource( const char *filename ) { +int trap_Parse_LoadSource( const char *filename ) +{ return syscall( UI_PARSE_LOAD_SOURCE, filename ); } -int trap_Parse_FreeSource( int handle ) { +int trap_Parse_FreeSource( int handle ) +{ return syscall( UI_PARSE_FREE_SOURCE, handle ); } -int trap_Parse_ReadToken( int handle, pc_token_t *pc_token ) { +int trap_Parse_ReadToken( int handle, pc_token_t *pc_token ) +{ return syscall( UI_PARSE_READ_TOKEN, handle, pc_token ); } -int trap_Parse_SourceFileAndLine( int handle, char *filename, int *line ) { +int trap_Parse_SourceFileAndLine( int handle, char *filename, int *line ) +{ return syscall( UI_PARSE_SOURCE_FILE_AND_LINE, handle, filename, line ); } -void trap_S_StopBackgroundTrack( void ) { +void trap_S_StopBackgroundTrack( void ) +{ syscall( UI_S_STOPBACKGROUNDTRACK ); } -void trap_S_StartBackgroundTrack( const char *intro, const char *loop) { +void trap_S_StartBackgroundTrack( const char *intro, const char *loop ) +{ syscall( UI_S_STARTBACKGROUNDTRACK, intro, loop ); } -int trap_RealTime(qtime_t *qtime) { +int trap_RealTime( qtime_t *qtime ) +{ return syscall( UI_REAL_TIME, qtime ); } // this returns a handle. arg0 is the name in the format "idlogo.roq", set arg1 to NULL, alteredstates to qfalse (do not alter gamestate) -int trap_CIN_PlayCinematic( const char *arg0, int xpos, int ypos, int width, int height, int bits) { - return syscall(UI_CIN_PLAYCINEMATIC, arg0, xpos, ypos, width, height, bits); +int trap_CIN_PlayCinematic( const char *arg0, int xpos, int ypos, int width, int height, int bits ) +{ + return syscall( UI_CIN_PLAYCINEMATIC, arg0, xpos, ypos, width, height, bits ); } // stops playing the cinematic and ends it. should always return FMV_EOF // cinematics must be stopped in reverse order of when they are started -e_status trap_CIN_StopCinematic(int handle) { - return syscall(UI_CIN_STOPCINEMATIC, handle); +e_status trap_CIN_StopCinematic( int handle ) +{ + return syscall( UI_CIN_STOPCINEMATIC, handle ); } // will run a frame of the cinematic but will not draw it. Will return FMV_EOF if the end of the cinematic has been reached. -e_status trap_CIN_RunCinematic (int handle) { - return syscall(UI_CIN_RUNCINEMATIC, handle); +e_status trap_CIN_RunCinematic ( int handle ) +{ + return syscall( UI_CIN_RUNCINEMATIC, handle ); } // draws the current frame -void trap_CIN_DrawCinematic (int handle) { - syscall(UI_CIN_DRAWCINEMATIC, handle); +void trap_CIN_DrawCinematic ( int handle ) +{ + syscall( UI_CIN_DRAWCINEMATIC, handle ); } // allows you to resize the animation dynamically -void trap_CIN_SetExtents (int handle, int x, int y, int w, int h) { - syscall(UI_CIN_SETEXTENTS, handle, x, y, w, h); +void trap_CIN_SetExtents ( int handle, int x, int y, int w, int h ) +{ + syscall( UI_CIN_SETEXTENTS, handle, x, y, w, h ); } -void trap_R_RemapShader( const char *oldShader, const char *newShader, const char *timeOffset ) { +void trap_R_RemapShader( const char *oldShader, const char *newShader, const char *timeOffset ) +{ syscall( UI_R_REMAP_SHADER, oldShader, newShader, timeOffset ); } -void trap_SetPbClStatus( int status ) { - syscall( UI_SET_PBCLSTATUS, status ); +void trap_SetPbClStatus( int status ) +{ + syscall( UI_SET_PBCLSTATUS, status ); } |