diff options
-rw-r--r-- | src/cgame/cg_main.c | 8 | ||||
-rw-r--r-- | src/game/bg_misc.c | 39 | ||||
-rw-r--r-- | src/game/bg_public.h | 2 | ||||
-rw-r--r-- | src/game/g_main.c | 2 | ||||
-rw-r--r-- | src/ui/ui_main.c | 9 | ||||
-rw-r--r-- | src/ui/ui_shared.c | 35 | ||||
-rw-r--r-- | src/ui/ui_shared.h | 1 |
7 files changed, 71 insertions, 25 deletions
diff --git a/src/cgame/cg_main.c b/src/cgame/cg_main.c index 9a40a5c3..070992bd 100644 --- a/src/cgame/cg_main.c +++ b/src/cgame/cg_main.c @@ -1680,14 +1680,18 @@ void CG_AssetCache( void ) cgDC.Assets.sliderThumb = trap_R_RegisterShaderNoMip( ASSET_SLIDER_THUMB ); if( cg_emoticons.integer ) - cgDC.Assets.emoticonCount = BG_LoadEmoticons( cgDC.Assets.emoticons ); + { + cgDC.Assets.emoticonCount = BG_LoadEmoticons( cgDC.Assets.emoticons, + cgDC.Assets.emoticonWidths ); + } else cgDC.Assets.emoticonCount = 0; for( i = 0; i < cgDC.Assets.emoticonCount; i++ ) { cgDC.Assets.emoticonShaders[ i ] = trap_R_RegisterShaderNoMip( - va( "emoticons/%s.tga", cgDC.Assets.emoticons[ i ] ) ); + va( "emoticons/%s_%dx1.tga", cgDC.Assets.emoticons[ i ], + cgDC.Assets.emoticonWidths[ i ] ) ); } } diff --git a/src/game/bg_misc.c b/src/game/bg_misc.c index 244ee482..270ae89b 100644 --- a/src/game/bg_misc.c +++ b/src/game/bg_misc.c @@ -3861,18 +3861,19 @@ weapon_t BG_PrimaryWeapon( int stats[ ] ) BG_LoadEmoticons ============ */ -int BG_LoadEmoticons( char names[ ][ MAX_EMOTICON_NAME_LEN ] ) +int BG_LoadEmoticons( char names[ ][ MAX_EMOTICON_NAME_LEN ], int widths[ ] ) { int numFiles; - char fileList[ MAX_EMOTICONS * ( MAX_EMOTICON_NAME_LEN + 5 ) ] = {""}; + char fileList[ MAX_EMOTICONS * ( MAX_EMOTICON_NAME_LEN + 9 ) ] = {""}; int i; char *filePtr; int fileLen; - char emoticon[ MAX_EMOTICON_NAME_LEN + 5 ] = {""}; + char emoticon[ MAX_EMOTICON_NAME_LEN + 9 ] = {""}; int loaded = 0; int count; + int width = 0; - numFiles = trap_FS_GetFileList( "emoticons", ".tga", fileList, + numFiles = trap_FS_GetFileList( "emoticons", "x1.tga", fileList, sizeof( fileList ) ); if( numFiles < 1 ) @@ -3890,12 +3891,18 @@ int BG_LoadEmoticons( char names[ ][ MAX_EMOTICON_NAME_LEN ] ) } fileLen = strlen( filePtr ); - if( fileLen > MAX_EMOTICON_NAME_LEN + 5 ) + if( fileLen > MAX_EMOTICON_NAME_LEN + 8 ) { Com_Printf( S_COLOR_YELLOW "WARNING: MAX_EMOTICON_NAME_LEN is %d. " "skipping \"%s\", filename too long", MAX_EMOTICON_NAME_LEN, filePtr ); continue; } + if( fileLen < 9 ) + { + Com_Printf( S_COLOR_YELLOW "WARNING: skipping \"%s\", filename too short", + filePtr ); + continue; + } if( !trap_FS_FOpenFile( va( "emoticons/%s", filePtr ), NULL, FS_READ ) ) { Com_Printf( S_COLOR_YELLOW "WARNING: BG_LoadEmoticons(): detected " @@ -3903,10 +3910,30 @@ int BG_LoadEmoticons( char names[ ][ MAX_EMOTICON_NAME_LEN ] ) filePtr ); break; } + Q_strncpyz( emoticon, filePtr, sizeof( emoticon ) ); - emoticon[ fileLen - 4 ] = '\0'; + + if( emoticon[ fileLen - 8 ] != '_' ) + { + Com_Printf( S_COLOR_YELLOW "WARNING: skipping \"%s\", filename invalid", + filePtr ); + continue; + } + + width = atoi( va( "%c", emoticon[ fileLen - 7 ] ) ); + + if( width < 1 || width > 9 ) + { + Com_Printf( S_COLOR_YELLOW "WARNING: skipping \"%s\", invalid width", + filePtr ); + continue; + } + + emoticon[ fileLen - 8 ] = '\0'; Q_strncpyz( names[ count ], emoticon, sizeof( names[ count ] ) ); + if( widths ) + widths[ count ] = width; count++; loaded = count; } diff --git a/src/game/bg_public.h b/src/game/bg_public.h index 2a6f1874..4547bb80 100644 --- a/src/game/bg_public.h +++ b/src/game/bg_public.h @@ -1298,4 +1298,4 @@ voiceTrack_t *BG_VoiceTrackFind( voiceTrack_t *head, team_t team, class_t class, weapon_t weapon, int enthusiasm, int *trackNum ); -int BG_LoadEmoticons( char names[ ][ MAX_EMOTICON_NAME_LEN ] ); +int BG_LoadEmoticons( char names[ ][ MAX_EMOTICON_NAME_LEN ], int widths[ ] ); diff --git a/src/game/g_main.c b/src/game/g_main.c index e3db3c23..42f07eda 100644 --- a/src/game/g_main.c +++ b/src/game/g_main.c @@ -607,7 +607,7 @@ void G_InitGame( int levelTime, int randomSeed, int restart ) trap_LocateGameData( level.gentities, level.num_entities, sizeof( gentity_t ), &level.clients[ 0 ].ps, sizeof( level.clients[ 0 ] ) ); - level.emoticonCount = BG_LoadEmoticons( level.emoticons ); + level.emoticonCount = BG_LoadEmoticons( level.emoticons, NULL ); trap_SetConfigstring( CS_INTERMISSION, "0" ); diff --git a/src/ui/ui_main.c b/src/ui/ui_main.c index 8d18372d..730cc498 100644 --- a/src/ui/ui_main.c +++ b/src/ui/ui_main.c @@ -206,14 +206,19 @@ void AssetCache( void ) uiInfo.uiDC.Assets.sliderThumb = trap_R_RegisterShaderNoMip( ASSET_SLIDER_THUMB ); if( ui_emoticons.integer ) - uiInfo.uiDC.Assets.emoticonCount = BG_LoadEmoticons( uiInfo.uiDC.Assets.emoticons ); + { + uiInfo.uiDC.Assets.emoticonCount = BG_LoadEmoticons( + uiInfo.uiDC.Assets.emoticons, + uiInfo.uiDC.Assets.emoticonWidths ); + } else uiInfo.uiDC.Assets.emoticonCount = 0; for( i = 0; i < uiInfo.uiDC.Assets.emoticonCount; i++ ) { uiInfo.uiDC.Assets.emoticonShaders[ i ] = trap_R_RegisterShaderNoMip( - va( "emoticons/%s.tga", uiInfo.uiDC.Assets.emoticons[ i ] ) ); + va( "emoticons/%s_%dx1.tga", uiInfo.uiDC.Assets.emoticons[ i ], + uiInfo.uiDC.Assets.emoticonWidths[ i ] ) ); } } diff --git a/src/ui/ui_shared.c b/src/ui/ui_shared.c index f2fe9b28..850ac52f 100644 --- a/src/ui/ui_shared.c +++ b/src/ui/ui_shared.c @@ -1834,7 +1834,8 @@ void Script_playLooped( itemDef_t *item, char **args ) } } -static qboolean UI_Text_Emoticon( const char *s, qboolean *escaped, int *length, qhandle_t *h ) +static qboolean UI_Text_Emoticon( const char *s, qboolean *escaped, + int *length, qhandle_t *h, int *width ) { char name[ MAX_EMOTICON_NAME_LEN ] = {""}; const char *p = s; @@ -1867,6 +1868,8 @@ static qboolean UI_Text_Emoticon( const char *s, qboolean *escaped, int *length, } if( h ) *h = DC->Assets.emoticonShaders[ j ]; + if( width ) + *width = DC->Assets.emoticonWidths[ j ]; *length = i + 2; return qtrue; } @@ -1891,7 +1894,7 @@ float UI_Text_Width( const char *text, float scale, int limit ) fontInfo_t *font = &DC->Assets.textFont; int emoticonLen; qboolean emoticonEscaped; - float emoticonWidth; + float emoticonW; int emoticons = 0; if( scale <= DC->getCVarValue( "ui_smallFont" ) ) @@ -1900,7 +1903,7 @@ float UI_Text_Width( const char *text, float scale, int limit ) font = &DC->Assets.bigFont; useScale = scale * font->glyphScale; - emoticonWidth = UI_Text_Height( "[", scale, 0 ) * DC->aspectScale; + emoticonW = UI_Text_Height( "[", scale, 0 ) * DC->aspectScale; out = 0; if( text ) @@ -1921,7 +1924,7 @@ float UI_Text_Width( const char *text, float scale, int limit ) s += 2; continue; } - else if ( UI_Text_Emoticon( s, &emoticonEscaped, &emoticonLen, NULL ) ) + else if ( UI_Text_Emoticon( s, &emoticonEscaped, &emoticonLen, NULL, NULL ) ) { if( emoticonEscaped ) { @@ -1940,7 +1943,7 @@ float UI_Text_Width( const char *text, float scale, int limit ) } } - return ( out * useScale ) + ( emoticons * emoticonWidth ); + return ( out * useScale ) + ( emoticons * emoticonW ); } float UI_Text_Height( const char *text, float scale, int limit ) @@ -2038,6 +2041,7 @@ void UI_Text_Paint_Limit( float *maxX, float x, float y, float scale, qhandle_t emoticonHandle = 0; float emoticonH, emoticonW; qboolean emoticonEscaped; + int emoticonWidth; emoticonH = UI_Text_Height( "[", scale, 0 ); emoticonW = emoticonH * DC->aspectScale; @@ -2085,7 +2089,8 @@ void UI_Text_Paint_Limit( float *maxX, float x, float y, float scale, s += 2; continue; } - else if( UI_Text_Emoticon( s, &emoticonEscaped, &emoticonLen, &emoticonHandle ) ) + else if( UI_Text_Emoticon( s, &emoticonEscaped, &emoticonLen, + &emoticonHandle, &emoticonWidth ) ) { if( emoticonEscaped ) { @@ -2095,9 +2100,10 @@ void UI_Text_Paint_Limit( float *maxX, float x, float y, float scale, { s += emoticonLen; DC->setColor( NULL ); - DC->drawHandlePic( x, y - yadj, emoticonW, emoticonH, emoticonHandle ); + DC->drawHandlePic( x, y - yadj, ( emoticonW * emoticonWidth ), + emoticonH, emoticonHandle ); DC->setColor( newColor ); - x += emoticonW; + x += ( emoticonW * emoticonWidth ); continue; } } @@ -2139,6 +2145,7 @@ void UI_Text_Paint( float x, float y, float scale, vec4_t color, const char *tex qhandle_t emoticonHandle = 0; float emoticonH, emoticonW; qboolean emoticonEscaped; + int emoticonWidth; if( scale <= DC->getCVarValue( "ui_smallFont" ) ) font = &DC->Assets.smallFont; @@ -2179,7 +2186,8 @@ void UI_Text_Paint( float x, float y, float scale, vec4_t color, const char *tex s += 2; continue; } - else if( UI_Text_Emoticon( s, &emoticonEscaped, &emoticonLen, &emoticonHandle ) ) + else if( UI_Text_Emoticon( s, &emoticonEscaped, &emoticonLen, + &emoticonHandle, &emoticonWidth ) ) { if( emoticonEscaped ) { @@ -2188,9 +2196,10 @@ void UI_Text_Paint( float x, float y, float scale, vec4_t color, const char *tex else { DC->setColor( NULL ); - DC->drawHandlePic( x, y - yadj, emoticonW, emoticonH, emoticonHandle ); + DC->drawHandlePic( x, y - yadj, ( emoticonW * emoticonWidth ), + emoticonH, emoticonHandle ); DC->setColor( newColor ); - x += emoticonW; + x += ( emoticonW * emoticonWidth ); s += emoticonLen; continue; } @@ -4611,7 +4620,7 @@ static const char *Item_Text_Wrap( const char *text, float scale, float width ) c[ 1 ] = q[ 1 ]; q += 2; } - while( UI_Text_Emoticon( q, &emoticonEscaped, &emoticonLen, NULL ) ) + while( UI_Text_Emoticon( q, &emoticonEscaped, &emoticonLen, NULL, NULL ) ) { if( emoticonEscaped ) q++; @@ -4631,7 +4640,7 @@ static const char *Item_Text_Wrap( const char *text, float scale, float width ) c[ 1 ] = q[ 1 ]; q += 2; } - while( UI_Text_Emoticon( q, &emoticonEscaped, &emoticonLen, NULL ) ) + while( UI_Text_Emoticon( q, &emoticonEscaped, &emoticonLen, NULL, NULL ) ) { if( emoticonEscaped ) q++; diff --git a/src/ui/ui_shared.h b/src/ui/ui_shared.h index fe9b03fe..48bf78cd 100644 --- a/src/ui/ui_shared.h +++ b/src/ui/ui_shared.h @@ -343,6 +343,7 @@ typedef struct qboolean fontRegistered; char emoticons[ MAX_EMOTICONS ][ MAX_EMOTICON_NAME_LEN ]; qhandle_t emoticonShaders[ MAX_EMOTICONS ]; + int emoticonWidths[ MAX_EMOTICONS ]; int emoticonCount; } cachedAssets_t; |