diff options
author | Christopher Schwarz <lakitu7@gmail.com> | 2009-10-12 19:17:00 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2013-01-03 00:16:48 +0000 |
commit | cf8d239dbe92720a24e8968c0b00ec2d4eec060f (patch) | |
tree | f587fcdfcd80f8e6e9e3342dde57d2172f4c7ec6 /src/ui | |
parent | 244808767a99cc237a477262420c43c126732088 (diff) |
* (bug 4295) Add an option to view Tremulous news to the main menu
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/ui_local.h | 16 | ||||
-rw-r--r-- | src/ui/ui_main.c | 78 | ||||
-rw-r--r-- | src/ui/ui_public.h | 1 | ||||
-rw-r--r-- | src/ui/ui_syscalls.asm | 1 | ||||
-rw-r--r-- | src/ui/ui_syscalls.c | 5 |
5 files changed, 101 insertions, 0 deletions
diff --git a/src/ui/ui_local.h b/src/ui/ui_local.h index 241cb6d8..1f7ecf40 100644 --- a/src/ui/ui_local.h +++ b/src/ui/ui_local.h @@ -41,6 +41,7 @@ int UI_AdjustTimeByGame( int time ); void UI_ClearScores( void ); void UI_LoadArenas( void ); void UI_ServerInfo( void ); +void UI_UpdateNews( qboolean ); void UI_RegisterCvars( void ); void UI_UpdateCvars( void ); @@ -53,6 +54,8 @@ void UI_DrawConnectScreen( qboolean overlay ); #define MAX_DISPLAY_SERVERS 2048 #define MAX_SERVERSTATUS_LINES 128 #define MAX_SERVERSTATUS_TEXT 1024 +#define MAX_NEWS_LINES 50 +#define MAX_NEWS_LINEWIDTH 85 #define MAX_FOUNDPLAYER_SERVERS 16 #define MAX_MODS 64 #define MAX_DEMOS 256 @@ -148,6 +151,15 @@ serverStatusInfo_t; typedef struct { + char text[MAX_NEWS_LINES][MAX_NEWS_LINEWIDTH]; + int numLines; + qboolean refreshActive; + int refreshtime; +} +newsInfo_t; + +typedef struct +{ const char *modName; const char *modDescr; } @@ -262,6 +274,9 @@ typedef struct serverStatus_t serverStatus; + // for showing the game news window + newsInfo_t newsInfo; + // for the showing the status of a server char serverStatusAddress[MAX_ADDRESSLENGTH]; serverStatusInfo_t serverStatusInfo; @@ -365,6 +380,7 @@ 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 ); +qboolean trap_GetNews( qboolean force ); 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 ); diff --git a/src/ui/ui_main.c b/src/ui/ui_main.c index 3eb63c5d..ab96fa3e 100644 --- a/src/ui/ui_main.c +++ b/src/ui/ui_main.c @@ -1138,6 +1138,8 @@ void UI_Refresh( int realtime ) UI_BuildServerStatus( qfalse ); // refresh find player list UI_BuildFindPlayerList( qfalse ); + // refresh news + UI_UpdateNews( qfalse ); } // draw cursor @@ -2856,6 +2858,8 @@ static void UI_RunMenuScript( char **args ) } else if( Q_stricmp( name, "loadServerInfo" ) == 0 ) UI_ServerInfo(); + else if( Q_stricmp( name, "getNews" ) == 0 ) + UI_UpdateNews( qtrue ); else if( Q_stricmp( name, "saveControls" ) == 0 ) Controls_SetConfig( qtrue ); else if( Q_stricmp( name, "loadControls" ) == 0 ) @@ -3356,6 +3360,8 @@ static int UI_FeederCount( float feederID ) return uiInfo.serverStatus.numFeaturedServers; else if( feederID == FEEDER_SERVERSTATUS ) return uiInfo.serverStatusInfo.numLines; + else if( feederID == FEEDER_NEWS ) + return uiInfo.newsInfo.numLines; else if( feederID == FEEDER_FINDPLAYER ) return uiInfo.numFoundPlayerServers; else if( feederID == FEEDER_PLAYER_LIST ) @@ -3524,6 +3530,13 @@ static const char *UI_FeederItemText( float feederID, int index, int column, qha return uiInfo.serverStatusInfo.lines[index][column]; } } + else if( feederID == FEEDER_NEWS ) + { + if( index >= 0 && index < uiInfo.newsInfo.numLines ) + { + return uiInfo.newsInfo.text[index]; + } + } else if( feederID == FEEDER_FINDPLAYER ) { if( index >= 0 && index < uiInfo.numFoundPlayerServers ) @@ -4473,3 +4486,68 @@ void UI_UpdateCvars( void ) for( i = 0, cv = cvarTable ; i < cvarTableSize ; i++, cv++ ) trap_Cvar_Update( cv->vmCvar ); } + +/* +================= +UI_UpdateNews +================= +*/ +void UI_UpdateNews( qboolean begin ) +{ + char newsString[ MAX_NEWS_STRING ]; + const char *c; + const char *wrapped; + int line = 0; + int linePos = 0; + qboolean finished; + + if( begin && !uiInfo.newsInfo.refreshActive ) { + uiInfo.newsInfo.refreshtime = uiInfo.uiDC.realTime + 10000; + uiInfo.newsInfo.refreshActive = qtrue; + } + else if( !uiInfo.newsInfo.refreshActive ) // do nothing + return; + else if( uiInfo.uiDC.realTime > uiInfo.newsInfo.refreshtime ) { + strcpy( uiInfo.newsInfo.text[ 0 ], + "^1Error: Timed out while contacting the server."); + uiInfo.newsInfo.numLines = 1; + return; + } + + // start the news fetching + finished = trap_GetNews( begin ); + + // parse what comes back. Parse newlines and otherwise chop when necessary + trap_Cvar_VariableStringBuffer( "cl_newsString", newsString, + sizeof( newsString ) ); + + wrapped = Item_Text_Wrap( newsString, .25, 300 ); + + for( c = wrapped; *c != '\0'; ++c ) { + if( linePos == (MAX_NEWS_LINEWIDTH - 1) || *c == '\n' ) { + uiInfo.newsInfo.text[ line ][ linePos ] = '\0'; + + if( line == ( MAX_NEWS_LINES - 1 ) ) + break; + + linePos = 0; + line++; + + if( *c != '\n' ) { + uiInfo.newsInfo.text[ line ][ linePos ] = *c; + linePos++; + } + } else if( isprint( *c ) ) { + uiInfo.newsInfo.text[ line ][ linePos ] = *c; + linePos++; + } + } + + uiInfo.newsInfo.text[ line ] [linePos ] = '\0'; + uiInfo.newsInfo.numLines = line + 1; + + if( finished ) + uiInfo.newsInfo.refreshActive = qfalse; + +} + diff --git a/src/ui/ui_public.h b/src/ui/ui_public.h index 26c6fbd4..bcaf3d5c 100644 --- a/src/ui/ui_public.h +++ b/src/ui/ui_public.h @@ -126,6 +126,7 @@ typedef enum UI_PARSE_FREE_SOURCE, UI_PARSE_READ_TOKEN, UI_PARSE_SOURCE_FILE_AND_LINE, + UI_GETNEWS, UI_MEMSET = 100, UI_MEMCPY, diff --git a/src/ui/ui_syscalls.asm b/src/ui/ui_syscalls.asm index fb37c736..0880d419 100644 --- a/src/ui/ui_syscalls.asm +++ b/src/ui/ui_syscalls.asm @@ -86,6 +86,7 @@ equ trap_Parse_LoadSource -82 equ trap_Parse_FreeSource -83 equ trap_Parse_ReadToken -84 equ trap_Parse_SourceFileAndLine -85 +equ trap_GetNews -86 equ memset -101 diff --git a/src/ui/ui_syscalls.c b/src/ui/ui_syscalls.c index f1d252cd..29938149 100644 --- a/src/ui/ui_syscalls.c +++ b/src/ui/ui_syscalls.c @@ -322,6 +322,11 @@ int trap_LAN_ServerStatus( const char *serverAddress, char *serverStatus, int ma return syscall( UI_LAN_SERVERSTATUS, serverAddress, serverStatus, maxLen ); } +qboolean trap_GetNews( qboolean force ) +{ + return syscall( UI_GETNEWS, force ); +} + void trap_LAN_SaveCachedServers( void ) { syscall( UI_LAN_SAVECACHEDSERVERS ); |