From f41580907488e297f2521eccb63f4f5d44aa7504 Mon Sep 17 00:00:00 2001 From: "Tony J. White" Date: Wed, 13 Dec 2006 17:05:11 +0000 Subject: * (bug 2944) cg_drawClock added --- src/cgame/cg_draw.c | 76 +++++++++++++++++++++++++++++++++++++ src/cgame/cg_local.h | 2 + src/cgame/cg_main.c | 2 + ui/ingame_options.menu | 21 ++++++++++ ui/menudef.h | 1 + ui/tremulous_alien_builder_hud.menu | 21 +++++++++- ui/tremulous_alien_general_hud.menu | 21 +++++++++- ui/tremulous_default_hud.menu | 20 +++++++++- ui/tremulous_human_hud.menu | 21 +++++++++- 9 files changed, 177 insertions(+), 8 deletions(-) diff --git a/src/cgame/cg_draw.c b/src/cgame/cg_draw.c index ed7ba1d8..dd86371c 100644 --- a/src/cgame/cg_draw.c +++ b/src/cgame/cg_draw.c @@ -1944,6 +1944,79 @@ static void CG_DrawTimer( rectDef_t *rect, float text_x, float text_y, } } +/* +================= +CG_DrawClock +================= +*/ +static void CG_DrawClock( rectDef_t *rect, float text_x, float text_y, + float scale, vec4_t color, int align, int textStyle ) +{ + char *s; + int i, tx, w, totalWidth, strLength; + qtime_t qt; + int t; + + if( !cg_drawClock.integer ) + return; + + t = trap_RealTime( &qt ); + + if( cg_drawClock.integer == 2 ) + { + s = va( "%02d%s%02d", qt.tm_hour, ( qt.tm_sec % 2 ) ? ":" : " ", + qt.tm_min ); + } + else + { + char *pm = "am"; + int h = qt.tm_hour; + + if( h == 0 ) + h = 12; + else if( h == 12 ) + pm = "pm"; + else if( h > 12 ) + { + h -= 12; + pm = "pm"; + } + + s = va( "%d%s%02d%s", h, ( qt.tm_sec % 2 ) ? ":" : " ", qt.tm_min, pm ); + } + w = CG_Text_Width( "0", scale, 0 ); + strLength = CG_DrawStrlen( s ); + totalWidth = w * strLength; + + switch( align ) + { + case ITEM_ALIGN_LEFT: + tx = rect->x; + break; + + case ITEM_ALIGN_RIGHT: + tx = rect->x + rect->w - totalWidth; + break; + + case ITEM_ALIGN_CENTER: + tx = rect->x + ( rect->w / 2.0f ) - ( totalWidth / 2.0f ); + break; + + default: + tx = 0.0f; + } + + for( i = 0; i < strLength; i++ ) + { + char c[ 2 ]; + + c[ 0 ] = s[ i ]; + c[ 1 ] = '\0'; + + CG_Text_Paint( text_x + tx + i * w, rect->y + text_y, scale, color, c, 0, 0, textStyle ); + } +} + /* ================== CG_DrawSnapshot @@ -2713,6 +2786,9 @@ void CG_OwnerDraw( float x, float y, float w, float h, float text_x, case CG_TIMER: CG_DrawTimer( &rect, text_x, text_y, scale, color, align, textStyle ); break; + case CG_CLOCK: + CG_DrawClock( &rect, text_x, text_y, scale, color, align, textStyle ); + break; case CG_TIMER_MINS: CG_DrawTimerMins( &rect, color ); break; diff --git a/src/cgame/cg_local.h b/src/cgame/cg_local.h index 27d89d24..f32941a8 100644 --- a/src/cgame/cg_local.h +++ b/src/cgame/cg_local.h @@ -1391,6 +1391,7 @@ extern vmCvar_t cg_swingSpeed; extern vmCvar_t cg_shadows; extern vmCvar_t cg_gibs; extern vmCvar_t cg_drawTimer; +extern vmCvar_t cg_drawClock; extern vmCvar_t cg_drawFPS; extern vmCvar_t cg_drawDemoState; extern vmCvar_t cg_drawSnapshot; @@ -2038,6 +2039,7 @@ void trap_CIN_DrawCinematic( int handle ); void trap_CIN_SetExtents( int handle, int x, int y, int w, int h ); void trap_SnapVector( float *v ); +int trap_RealTime( qtime_t *tm ); qboolean trap_loadCamera( const char *name ); void trap_startCamera( int time ); diff --git a/src/cgame/cg_main.c b/src/cgame/cg_main.c index 926ccd88..db4134c0 100644 --- a/src/cgame/cg_main.c +++ b/src/cgame/cg_main.c @@ -120,6 +120,7 @@ vmCvar_t cg_swingSpeed; vmCvar_t cg_shadows; vmCvar_t cg_gibs; vmCvar_t cg_drawTimer; +vmCvar_t cg_drawClock; vmCvar_t cg_drawFPS; vmCvar_t cg_drawDemoState; vmCvar_t cg_drawSnapshot; @@ -263,6 +264,7 @@ static cvarTable_t cvarTable[ ] = { &cg_draw2D, "cg_draw2D", "1", CVAR_ARCHIVE }, { &cg_drawStatus, "cg_drawStatus", "1", CVAR_ARCHIVE }, { &cg_drawTimer, "cg_drawTimer", "1", CVAR_ARCHIVE }, + { &cg_drawClock, "cg_drawClock", "0", CVAR_ARCHIVE }, { &cg_drawFPS, "cg_drawFPS", "1", CVAR_ARCHIVE }, { &cg_drawDemoState, "cg_drawDemoState", "1", CVAR_ARCHIVE }, { &cg_drawSnapshot, "cg_drawSnapshot", "0", CVAR_ARCHIVE }, diff --git a/ui/ingame_options.menu b/ui/ingame_options.menu index 53bcc07f..7bbcbb83 100644 --- a/ui/ingame_options.menu +++ b/ui/ingame_options.menu @@ -296,6 +296,27 @@ play "sound/misc/menu1.wav"; } } + + itemDef + { + name game + group optionsGrp + type ITEM_TYPE_MULTI + text "Show Clock:" + cvar "cg_drawClock" + cvarFloatList { "No" 0 "12 Hour" 1 "24 Hour" 2 } + rect 90 235 192 15 + textalign ITEM_ALIGN_RIGHT + textalignx 128 + textaligny 12 + textscale .25 + forecolor 1 1 1 1 + visible 0 + action + { + play "sound/misc/menu1.wav"; + } + } //////// CONTROLS diff --git a/ui/menudef.h b/ui/menudef.h index dbd5b193..0463e1aa 100644 --- a/ui/menudef.h +++ b/ui/menudef.h @@ -258,6 +258,7 @@ #define CG_CONSOLE 91 #define CG_TUTORIAL 119 +#define CG_CLOCK 120 diff --git a/ui/tremulous_alien_builder_hud.menu b/ui/tremulous_alien_builder_hud.menu index cd177266..bf75327c 100644 --- a/ui/tremulous_alien_builder_hud.menu +++ b/ui/tremulous_alien_builder_hud.menu @@ -65,7 +65,7 @@ itemDef { name "demoRecording" - rect 596 100 32 32 + rect 596 120 32 32 style WINDOW_STYLE_EMPTY visible 1 decoration @@ -79,7 +79,7 @@ itemDef { name "demoPlayback" - rect 596 100 32 32 + rect 596 120 32 32 style WINDOW_STYLE_EMPTY visible 1 decoration @@ -330,6 +330,23 @@ ownerdraw CG_TIMER } + //CLOCK + itemDef + { + name "clock" + rect 572 90 56 22 + style WINDOW_STYLE_EMPTY + visible 1 + decoration + forecolor 1.0 0.0 0.0 1 + align ITEM_ALIGN_RIGHT + textalignx 0 + textaligny 18 + textscale 0.25 + textstyle ITEM_TEXTSTYLE_NORMAL + ownerdraw CG_CLOCK + } + //ALIENSENSE itemDef { diff --git a/ui/tremulous_alien_general_hud.menu b/ui/tremulous_alien_general_hud.menu index 6ed8721f..cc816008 100644 --- a/ui/tremulous_alien_general_hud.menu +++ b/ui/tremulous_alien_general_hud.menu @@ -65,7 +65,7 @@ itemDef { name "demoRecording" - rect 596 100 32 32 + rect 596 120 32 32 style WINDOW_STYLE_EMPTY visible 1 decoration @@ -79,7 +79,7 @@ itemDef { name "demoPlayback" - rect 596 100 32 32 + rect 596 120 32 32 style WINDOW_STYLE_EMPTY visible 1 decoration @@ -319,6 +319,23 @@ ownerdraw CG_TIMER } + //CLOCK + itemDef + { + name "clock" + rect 572 90 56 22 + style WINDOW_STYLE_EMPTY + visible 1 + decoration + forecolor 1.0 0.0 0.0 1 + align ITEM_ALIGN_RIGHT + textalignx 0 + textaligny 18 + textscale 0.25 + textstyle ITEM_TEXTSTYLE_NORMAL + ownerdraw CG_CLOCK + } + //ALIENSENSE itemDef { diff --git a/ui/tremulous_default_hud.menu b/ui/tremulous_default_hud.menu index b8385c53..0eed6404 100644 --- a/ui/tremulous_default_hud.menu +++ b/ui/tremulous_default_hud.menu @@ -74,6 +74,22 @@ textstyle ITEM_TEXTSTYLE_NORMAL ownerdraw CG_TIMER } + //CLOCK + itemDef + { + name "clock" + rect 572 90 56 22 + style WINDOW_STYLE_EMPTY + visible 1 + decoration + forecolor 1 1 1 1 + align ITEM_ALIGN_RIGHT + textalignx 0 + textaligny 18 + textscale 0.25 + textstyle ITEM_TEXTSTYLE_NORMAL + ownerdraw CG_CLOCK + } //SNAPSHOT itemDef @@ -109,7 +125,7 @@ itemDef { name "demoRecording" - rect 596 100 32 32 + rect 596 120 32 32 style WINDOW_STYLE_EMPTY visible 1 decoration @@ -123,7 +139,7 @@ itemDef { name "demoPlayback" - rect 596 100 32 32 + rect 596 120 32 32 style WINDOW_STYLE_EMPTY visible 1 decoration diff --git a/ui/tremulous_human_hud.menu b/ui/tremulous_human_hud.menu index d362fc6a..8fe00950 100644 --- a/ui/tremulous_human_hud.menu +++ b/ui/tremulous_human_hud.menu @@ -65,7 +65,7 @@ itemDef { name "demoRecording" - rect 596 100 32 32 + rect 596 120 32 32 style WINDOW_STYLE_EMPTY visible 1 decoration @@ -79,7 +79,7 @@ itemDef { name "demoPlayback" - rect 596 100 32 32 + rect 596 120 32 32 style WINDOW_STYLE_EMPTY visible 1 decoration @@ -124,6 +124,23 @@ textstyle ITEM_TEXTSTYLE_NORMAL ownerdraw CG_TIMER } + + //CLOCK + itemDef + { + name "clock" + rect 572 90 56 22 + style WINDOW_STYLE_EMPTY + visible 1 + decoration + forecolor 0.0 0.8 1.0 1 + align ITEM_ALIGN_RIGHT + textalignx 0 + textaligny 18 + textscale 0.25 + textstyle ITEM_TEXTSTYLE_NORMAL + ownerdraw CG_CLOCK + } //SNAPSHOT itemDef -- cgit