From 589be4af4b01e627618b9bd07193de4be4acd278 Mon Sep 17 00:00:00 2001 From: LegendaryGuard Date: Sat, 26 Aug 2023 00:29:40 +0200 Subject: [PATCH] cgame - q3_ui: Implement classic Crosshair Color --- docs/bfp_cvars_task.md | 1 + source/cgame/cg_cvar.h | 1 + source/cgame/cg_draw.c | 30 ++++++++- source/q3_ui/ui_preferences.c | 122 ++++++++++++++++++++++++++++++++++ 4 files changed, 152 insertions(+), 2 deletions(-) diff --git a/docs/bfp_cvars_task.md b/docs/bfp_cvars_task.md index fb5b79b..b5ecad7 100644 --- a/docs/bfp_cvars_task.md +++ b/docs/bfp_cvars_task.md @@ -76,6 +76,7 @@ - [x] ~~cg_yrgolroxor~~ - [x] ~~cg_thirdPersonHeight~~ +- [x] ~~cg_crosshairColor~~ #### Cvar Gametypes: diff --git a/source/cgame/cg_cvar.h b/source/cgame/cg_cvar.h index a2377fe..f952a13 100644 --- a/source/cgame/cg_cvar.h +++ b/source/cgame/cg_cvar.h @@ -31,6 +31,7 @@ CG_CVAR( cg_drawAttacker, "cg_drawAttacker", "1", CVAR_ARCHIVE ) CG_CVAR( cg_drawCrosshair, "cg_drawCrosshair", "4", CVAR_ARCHIVE ) CG_CVAR( cg_drawCrosshairNames, "cg_drawCrosshairNames", "1", CVAR_ARCHIVE ) CG_CVAR( cg_drawRewards, "cg_drawRewards", "1", CVAR_ARCHIVE ) +CG_CVAR( cg_crosshairColor, "cg_crosshairColor", "7", CVAR_ARCHIVE ) // BFP - Crosshair color CG_CVAR( cg_crosshairSize, "cg_crosshairSize", "24", CVAR_ARCHIVE ) CG_CVAR( cg_crosshairHealth, "cg_crosshairHealth", "1", CVAR_ARCHIVE ) CG_CVAR( cg_crosshairX, "cg_crosshairX", "0", CVAR_ARCHIVE ) diff --git a/source/cgame/cg_draw.c b/source/cgame/cg_draw.c index 6e96db5..70928f6 100644 --- a/source/cgame/cg_draw.c +++ b/source/cgame/cg_draw.c @@ -1661,6 +1661,32 @@ CROSSHAIR ================================================================================ */ +/* +================= +CG_SetCrosshairColor +================= +*/ +static void CG_SetCrosshairColor( void ) { // BFP - Crosshair color + static int colorNum; + static float *colors[] = { + colorBlack, + colorBlue, + colorGreen, + colorCyan, + colorRed, + colorMagenta, + colorYellow, + colorWhite + }; + + colorNum = cg_crosshairColor.integer; + if ( !colorNum ) { // In BFP, if this cvar is 0, then set to the default value + colorNum = 7; + } + colorNum = ( colorNum - 1 ) % ARRAY_LEN( colors ); + + trap_R_SetColor( colors[colorNum] ); +} /* ================= @@ -1700,10 +1726,10 @@ static void CG_DrawCrosshair(void) { CG_ColorForHealth( hcolor ); trap_R_SetColor( hcolor ); - } else { - trap_R_SetColor( NULL ); } + CG_SetCrosshairColor(); // BFP - Crosshair color + w = h = cg_crosshairSize.value; // pulse the size of the crosshair when picking up items diff --git a/source/q3_ui/ui_preferences.c b/source/q3_ui/ui_preferences.c index aaa35d8..b1bd224 100644 --- a/source/q3_ui/ui_preferences.c +++ b/source/q3_ui/ui_preferences.c @@ -37,6 +37,16 @@ GAME OPTIONS MENU #define ART_BACK0 "menu/art/back_0" #define ART_BACK1 "menu/art/back_1" +// BFP - Crosshair color bar +#define ART_FX_BASE "menu/art/fx_base" +#define ART_FX_BLUE "menu/art/fx_blue" +#define ART_FX_CYAN "menu/art/fx_cyan" +#define ART_FX_GREEN "menu/art/fx_grn" +#define ART_FX_RED "menu/art/fx_red" +#define ART_FX_TEAL "menu/art/fx_teal" +#define ART_FX_WHITE "menu/art/fx_white" +#define ART_FX_YELLOW "menu/art/fx_yel" + #define PREFERENCES_X_POS 360 #define ID_CROSSHAIR 127 @@ -51,6 +61,7 @@ GAME OPTIONS MENU #define ID_DRAWTEAMOVERLAY 136 #define ID_ALLOWDOWNLOAD 137 #define ID_BACK 138 +#define ID_CROSSHAIRCOLOR 139 // BFP - Crosshair color id #define NUM_CROSSHAIRS 10 @@ -63,6 +74,7 @@ typedef struct { menubitmap_s framer; menulist_s crosshair; + menulist_s crosshaircolor; // BFP - Crosshair color menuradiobutton_s simpleitems; menuradiobutton_s brass; menuradiobutton_s wallmarks; @@ -76,10 +88,40 @@ typedef struct { menubitmap_s back; qhandle_t crosshairShader[NUM_CROSSHAIRS]; + + // BFP - Crosshair color bar + qhandle_t fxBasePic; + qhandle_t fxPic[7]; } preferences_t; static preferences_t s_preferences; +// BFP - Crosshair color bar table +/*=================================================== + INDEX - UI SLIDER BAR COLOR VALUE > CGAME VALUE + 0 - RED 4 > 5 + 1 - YELLOW 2 > 7 + 2 - GREEN 3 > 3 + 3 - TEAL (CYAN) 0 > 4 + 4 - BLUE 5 > 2 + 5 - MAGENTA 1 > 6 + 6 - WHITE 6 > 8 +===================================================== +If any number isn't in the UI table to assign, it will always map to WHITE +*/ +static int gamecodetoui[] = {4,2,3,0,5,1,6}; +static int uitogamecode[] = {5,7,3,4,2,6,8}; +static float *uiColors[] = { + colorRed, + colorYellow, + colorGreen, + colorCyan, + colorBlue, + colorMagenta, + colorWhite +}; +static int uiColorIndex; + static const char *teamoverlay_names[] = { "off", @@ -90,7 +132,22 @@ static const char *teamoverlay_names[] = }; static void Preferences_SetMenuItems( void ) { + int c; + s_preferences.crosshair.curvalue = (int)trap_Cvar_VariableValue( "cg_drawCrosshair" ) % NUM_CROSSHAIRS; + + // BFP - Crosshair color value + c = (int)trap_Cvar_VariableValue( "cg_crosshairColor" ) - 1; + if ( c == -1 ) { // keep it to YELLOW + c = 6; + } + if ( c < -1 || c == 0 || c > 7 ) { // if there are other numbers, set to WHITE + c = 6; + } else { + c = ( c - 1 ) % ARRAY_LEN( uiColors ); + } + uiColorIndex = s_preferences.crosshaircolor.curvalue = gamecodetoui[c]; + s_preferences.simpleitems.curvalue = trap_Cvar_VariableValue( "cg_simpleItems" ) != 0; s_preferences.brass.curvalue = trap_Cvar_VariableValue( "cg_brassTime" ) != 0; s_preferences.wallmarks.curvalue = trap_Cvar_VariableValue( "cg_marks" ) != 0; @@ -118,6 +175,15 @@ static void Preferences_Event( void* ptr, int notification ) { trap_Cvar_SetValue( "cg_drawCrosshair", s_preferences.crosshair.curvalue ); break; + // BFP - Crosshair color + case ID_CROSSHAIRCOLOR: + uiColorIndex++; + if( uiColorIndex > ( ARRAY_LEN( uiColors ) - 1 ) ) { + uiColorIndex = 0; + } + trap_Cvar_SetValue( "cg_crosshairColor", uitogamecode[s_preferences.crosshaircolor.curvalue] ); + break; + case ID_SIMPLEITEMS: trap_Cvar_SetValue( "cg_simpleItems", s_preferences.simpleitems.curvalue ); break; @@ -214,10 +280,39 @@ static void Crosshair_Draw( void *self ) { if( !s->curvalue ) { return; } + + trap_R_SetColor( uiColors[uiColorIndex] ); // BFP - Draw color to the crosshair UI_DrawHandlePic( x + SMALLCHAR_WIDTH, y - 4, 24, 24, s_preferences.crosshairShader[s->curvalue] ); } +/* +================= +CrosshairColor_Draw +================= +*/ +static void CrosshairColor_Draw( void *self ) { // BFP - For crosshair color bar + menulist_s *item; + float *color; + int style; + qboolean focus; + + item = (menulist_s *)self; + focus = (item->generic.parent->cursor == item->generic.menuPosition); + + style = UI_LEFT|UI_SMALLFONT; + color = text_color_normal; + if( focus ) { + style |= UI_PULSE; + color = text_color_highlight; + } + UI_DrawString( item->generic.x - SMALLCHAR_WIDTH, item->generic.y, item->generic.name, style|UI_RIGHT, color ); + + UI_DrawHandlePic( item->generic.x + BIGCHAR_HEIGHT+4 - 20, item->generic.y + 8, 128, 8, s_preferences.fxBasePic ); + UI_DrawHandlePic( item->generic.x + BIGCHAR_HEIGHT+4 + item->curvalue * 16 + 8 - 20, item->generic.y + 6, 16, 12, s_preferences.fxPic[item->curvalue] ); +} + + static void Preferences_MenuInit( void ) { int y; @@ -265,7 +360,23 @@ static void Preferences_MenuInit( void ) { s_preferences.crosshair.generic.left = PREFERENCES_X_POS - ( ( (int)strlen(s_preferences.crosshair.generic.name) + 1 ) * SMALLCHAR_WIDTH ); s_preferences.crosshair.generic.right = PREFERENCES_X_POS + 48; + // BFP - Crosshair color bar y += BIGCHAR_HEIGHT+2+4; + s_preferences.crosshaircolor.generic.type = MTYPE_SPINCONTROL; + s_preferences.crosshaircolor.generic.flags = QMF_NODEFAULTINIT; + s_preferences.crosshaircolor.generic.x = PREFERENCES_X_POS - 24; + s_preferences.crosshaircolor.generic.y = y; + s_preferences.crosshaircolor.generic.name = "Crosshair Color:"; + s_preferences.crosshaircolor.generic.callback = Preferences_Event; + s_preferences.crosshaircolor.generic.ownerdraw = CrosshairColor_Draw; + s_preferences.crosshaircolor.generic.id = ID_CROSSHAIRCOLOR; + s_preferences.crosshaircolor.generic.top = y - 4; + s_preferences.crosshaircolor.generic.bottom = y + 20; + s_preferences.crosshaircolor.generic.left = PREFERENCES_X_POS - ( ( (int)strlen(s_preferences.crosshaircolor.generic.name) + 1 ) * SMALLCHAR_WIDTH ); + s_preferences.crosshaircolor.generic.right = PREFERENCES_X_POS + 48; + s_preferences.crosshaircolor.numitems = 7; + + y += BIGCHAR_HEIGHT+20+4; s_preferences.simpleitems.generic.type = MTYPE_RADIOBUTTON; s_preferences.simpleitems.generic.name = "Simple Items:"; s_preferences.simpleitems.generic.flags = QMF_PULSEIFFOCUS|QMF_SMALLFONT; @@ -373,6 +484,7 @@ static void Preferences_MenuInit( void ) { Menu_AddItem( &s_preferences.menu, &s_preferences.framer ); Menu_AddItem( &s_preferences.menu, &s_preferences.crosshair ); + Menu_AddItem( &s_preferences.menu, &s_preferences.crosshaircolor ); // BFP - Crosshair color bar Menu_AddItem( &s_preferences.menu, &s_preferences.simpleitems ); Menu_AddItem( &s_preferences.menu, &s_preferences.wallmarks ); Menu_AddItem( &s_preferences.menu, &s_preferences.brass ); @@ -405,6 +517,16 @@ void Preferences_Cache( void ) { for( n = 0; n < NUM_CROSSHAIRS; n++ ) { s_preferences.crosshairShader[n] = trap_R_RegisterShaderNoMip( va("gfx/2d/crosshair%c", 'a' + n ) ); } + + // BFP - Crosshair color bar + s_preferences.fxBasePic = trap_R_RegisterShaderNoMip( ART_FX_BASE ); + s_preferences.fxPic[0] = trap_R_RegisterShaderNoMip( ART_FX_RED ); + s_preferences.fxPic[1] = trap_R_RegisterShaderNoMip( ART_FX_YELLOW ); + s_preferences.fxPic[2] = trap_R_RegisterShaderNoMip( ART_FX_GREEN ); + s_preferences.fxPic[3] = trap_R_RegisterShaderNoMip( ART_FX_TEAL ); + s_preferences.fxPic[4] = trap_R_RegisterShaderNoMip( ART_FX_BLUE ); + s_preferences.fxPic[5] = trap_R_RegisterShaderNoMip( ART_FX_CYAN ); + s_preferences.fxPic[6] = trap_R_RegisterShaderNoMip( ART_FX_WHITE ); }