From 342e186f794d83c6832be5f621dc3b3b913e8d9d Mon Sep 17 00:00:00 2001 From: Bobby Lovell Date: Wed, 13 Dec 2023 13:06:48 -0500 Subject: [PATCH 01/10] Add option to change crosshair alpha, and could provide fully custom colors. Proof of concept. --- port/src/main.c | 2 ++ port/src/optionsmenu.c | 35 +++++++++++++++++++++++++ src/game/mplayer/mplayer.c | 3 ++- src/game/sight.c | 52 ++++++++++++++++++++++++++++++++++++++ src/include/types.h | 2 ++ 5 files changed, 93 insertions(+), 1 deletion(-) diff --git a/port/src/main.c b/port/src/main.c index 38d4da332..fbad0859c 100644 --- a/port/src/main.c +++ b/port/src/main.c @@ -166,5 +166,7 @@ PD_CONSTRUCTOR static void gameConfigInit(void) configRegisterFloat(strFmt("Game.Player%d.CrosshairSway", i), &g_PlayerExtCfg[j].crosshairsway, 0.f, 10.f); configRegisterInt(strFmt("Game.Player%d.CrouchMode", i), &g_PlayerExtCfg[j].crouchmode, 0, CROUCHMODE_TOGGLE_ANALOG); configRegisterInt(strFmt("Game.Player%d.ExtendedControls", i), &g_PlayerExtCfg[j].extcontrols, 0, 1); + configRegisterInt(strFmt("Game.Player%d.CrosshairAlpha", i), &g_PlayerExtCfg[j].crosshairalpha, 0, 255); + } } diff --git a/port/src/optionsmenu.c b/port/src/optionsmenu.c index e77e95322..24f353383 100644 --- a/port/src/optionsmenu.c +++ b/port/src/optionsmenu.c @@ -903,6 +903,33 @@ static MenuItemHandlerResult menuhandlerCrosshairSway(s32 operation, struct menu return 0; } +#define SIGHT_COLOUR_R 0; +#define SIGHT_COLOUR_G 255; +#define SIGHT_COLOUR_B 0; + +static u32 RGBAToINT(u32 r, u32 g, u32 b, u32 a) +{ + return (((r) & 0xff) << 24 | ((g) & 0xff) << 16 | ((b) & 0xff) << 8 | ((a) & 0xff)); +} + +static MenuItemHandlerResult menuhandlerCrosshairAlpha(s32 operation, struct menuitem* item, union handlerdata* data) +{ + switch (operation) { + case MENUOP_GETSLIDER: + data->slider.value = g_PlayerExtCfg[g_ExtMenuPlayer].crosshairalpha; + break; + case MENUOP_SET: + g_PlayerExtCfg[g_ExtMenuPlayer].crosshairalpha = data->slider.value; + + g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour = RGBAToINT(SIGHT_COLOUR_R, SIGHT_COLOUR_G, SIGHT_COLOUR_B, g_PlayerExtCfg[g_ExtMenuPlayer].crosshairalpha); + + break; + } + + return 0; +} + + struct menuitem g_ExtendedGameMenuItems[] = { { MENUITEMTYPE_DROPDOWN, @@ -928,6 +955,14 @@ struct menuitem g_ExtendedGameMenuItems[] = { 20, menuhandlerCrosshairSway, }, + { + MENUITEMTYPE_SLIDER, + 0, + MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SLIDER_WIDE, + (uintptr_t)"Crosshair Alpha", + 255, + menuhandlerCrosshairAlpha, + }, { MENUITEMTYPE_SEPARATOR, 0, diff --git a/src/game/mplayer/mplayer.c b/src/game/mplayer/mplayer.c index d91f60a4e..5dd2584ce 100644 --- a/src/game/mplayer/mplayer.c +++ b/src/game/mplayer/mplayer.c @@ -121,7 +121,8 @@ struct mpweapon g_MpWeapons[NUM_MPWEAPONS] = { .radialmenuspeed = 4.f, \ .crosshairsway = 1.f, \ .crouchmode = CROUCHMODE_TOGGLE_ANALOG, \ - .extcontrols = true, \ + .crosshairalpha = 40, \ + .crosshaircolour = 0x00ff0028, \ } struct extplayerconfig g_PlayerExtCfg[MAX_PLAYERS] = { diff --git a/src/game/sight.c b/src/game/sight.c index 6dc76bd64..1206cac7d 100644 --- a/src/game/sight.c +++ b/src/game/sight.c @@ -459,7 +459,11 @@ Gfx *sightDrawAimer(Gfx *gdl, s32 x, s32 y, s32 radius, s32 cornergap, u32 colou s32 viewright = viewleft + viewwidth - 1; s32 viewbottom = viewtop + viewheight - 1; +#ifndef PLATFORM_N64 + gdl = textSetPrimColour(gdl, PLAYER_EXTCFG().crosshaircolour); +#else gdl = textSetPrimColour(gdl, 0x00ff0028); +#endif #ifndef PLATFORM_N64 x = sightGetAdjustedX(x); @@ -619,7 +623,11 @@ Gfx *sightDrawDelayedAimer(Gfx *gdl, s32 x, s32 y, s32 radius, s32 cornergap, u3 boxx = xpos; boxy = ypos; +#ifndef PLATFORM_N64 + gdl = textSetPrimColour(gdl, PLAYER_EXTCFG().crosshaircolour); +#else gdl = textSetPrimColour(gdl, 0x00ff0028); +#endif // Fill a 3x3 box at the live crosshair gDPHudRectangle(gdl++, x - 1, y - 1, x + 1, y - 1); @@ -677,7 +685,13 @@ Gfx *sightDrawDefault(Gfx *gdl, bool sighton) // SIGHTTRACKTYPE_NONE is used for unarmed, but this appears to be // unreachable. The aimer is never drawn when unarmed. if (sighton) { + +#ifndef PLATFORM_N64 + colour = PLAYER_EXTCFG().crosshaircolour; +#else colour = 0x00ff0028; +#endif + radius = 8; cornergap = 5; gdl = sightDrawAimer(gdl, x, y, radius, cornergap, colour); @@ -687,7 +701,13 @@ Gfx *sightDrawDefault(Gfx *gdl, bool sighton) // For most guns, render the aimer if holding R if (sighton) { if (g_Vars.currentplayer->lookingatprop.prop == NULL) { + +#ifndef PLATFORM_N64 + colour = PLAYER_EXTCFG().crosshaircolour; +#else colour = 0x00ff0028; +#endif + radius = 8; cornergap = 5; } else { @@ -716,7 +736,13 @@ Gfx *sightDrawDefault(Gfx *gdl, bool sighton) s32 texty; if (g_Vars.currentplayer->lookingatprop.prop == NULL) { + +#ifndef PLATFORM_N64 + colour = PLAYER_EXTCFG().crosshaircolour; +#else colour = 0x00ff0028; +#endif + radius = 8; cornergap = 5; } else { @@ -761,7 +787,13 @@ Gfx *sightDrawDefault(Gfx *gdl, bool sighton) if (sighton) { if (g_Vars.currentplayer->lookingatprop.prop == NULL) { + +#ifndef PLATFORM_N64 + colour = PLAYER_EXTCFG().crosshaircolour; +#else colour = 0x00ff0028; +#endif + radius = 8; cornergap = 5; } else { @@ -832,7 +864,13 @@ Gfx *sightDrawDefault(Gfx *gdl, bool sighton) if (sighton) { if (g_Vars.currentplayer->lookingatprop.prop == NULL) { + +#ifndef PLATFORM_N64 + colour = PLAYER_EXTCFG().crosshaircolour; +#else colour = 0x00ff0028; +#endif + radius = 8; cornergap = 5; } else { @@ -1252,7 +1290,12 @@ Gfx *sightDrawZoom(Gfx *gdl, bool sighton) if (showzoomrange) { gdl = text0f153628(gdl); + +#ifndef PLATFORM_N64 + gdl = textSetPrimColour(gdl, PLAYER_EXTCFG().crosshaircolour); +#else gdl = textSetPrimColour(gdl, 0x00ff0028); +#endif if (frac < 0.2f) { cornerwidth *= 0.2f; @@ -1436,7 +1479,12 @@ Gfx *sightDrawMaian(Gfx *gdl, bool sighton) gSPTri4(gdl++, 0, 4, 5, 5, 3, 6, 7, 6, 1, 4, 7, 2); gdl = func0f0d49c8(gdl); + +#ifndef PLATFORM_N64 + gdl = textSetPrimColour(gdl, PLAYER_EXTCFG().crosshaircolour); +#else gdl = textSetPrimColour(gdl, 0x00ff0028); +#endif // Draw border over inner points gDPHudRectangle(gdl++, x - 4, y - 4, x - 4, y + 4); // left @@ -1464,7 +1512,11 @@ Gfx *sightDrawTarget(Gfx *gdl) mainOverrideVariable("sout", &var80070f9c); mainOverrideVariable("sin", &var80070fa0); +#ifndef PLATFORM_N64 + gdl = textSetPrimColour(gdl, PLAYER_EXTCFG().crosshaircolour); +#else gdl = textSetPrimColour(gdl, 0x00ff0028); +#endif #ifndef PLATFORM_N64 gSPSetExtraGeometryModeEXT(gdl++, G_ASPECT_CENTER_EXT); diff --git a/src/include/types.h b/src/include/types.h index 67a8eddaf..4737f178b 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -6139,6 +6139,8 @@ struct extplayerconfig { f32 radialmenuspeed; f32 crosshairsway; s32 extcontrols; + u32 crosshairalpha; + u32 crosshaircolour; }; #endif From 2a6625278ab6c79d3568de80cad8380cddd9c539 Mon Sep 17 00:00:00 2001 From: Bobby Lovell Date: Wed, 13 Dec 2023 13:48:06 -0500 Subject: [PATCH 02/10] - Fix RGB defines - Just store the colour and parse RGBA values when modifying. --- port/src/main.c | 3 +-- port/src/optionsmenu.c | 12 ++++++------ src/game/mplayer/mplayer.c | 1 - src/include/types.h | 1 - 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/port/src/main.c b/port/src/main.c index fbad0859c..3b53d781c 100644 --- a/port/src/main.c +++ b/port/src/main.c @@ -166,7 +166,6 @@ PD_CONSTRUCTOR static void gameConfigInit(void) configRegisterFloat(strFmt("Game.Player%d.CrosshairSway", i), &g_PlayerExtCfg[j].crosshairsway, 0.f, 10.f); configRegisterInt(strFmt("Game.Player%d.CrouchMode", i), &g_PlayerExtCfg[j].crouchmode, 0, CROUCHMODE_TOGGLE_ANALOG); configRegisterInt(strFmt("Game.Player%d.ExtendedControls", i), &g_PlayerExtCfg[j].extcontrols, 0, 1); - configRegisterInt(strFmt("Game.Player%d.CrosshairAlpha", i), &g_PlayerExtCfg[j].crosshairalpha, 0, 255); - + configRegisterInt(strFmt("Game.Player%d.CrosshairColour", i), &g_PlayerExtCfg[j].crosshaircolour, 0, 0xFFFFFFFF); } } diff --git a/port/src/optionsmenu.c b/port/src/optionsmenu.c index 24f353383..34a28e74b 100644 --- a/port/src/optionsmenu.c +++ b/port/src/optionsmenu.c @@ -903,9 +903,10 @@ static MenuItemHandlerResult menuhandlerCrosshairSway(s32 operation, struct menu return 0; } -#define SIGHT_COLOUR_R 0; -#define SIGHT_COLOUR_G 255; -#define SIGHT_COLOUR_B 0; +// Stock sight RGB. +#define SIGHT_COLOUR_R 0 +#define SIGHT_COLOUR_G 255 +#define SIGHT_COLOUR_B 0 static u32 RGBAToINT(u32 r, u32 g, u32 b, u32 a) { @@ -916,12 +917,11 @@ static MenuItemHandlerResult menuhandlerCrosshairAlpha(s32 operation, struct men { switch (operation) { case MENUOP_GETSLIDER: - data->slider.value = g_PlayerExtCfg[g_ExtMenuPlayer].crosshairalpha; + data->slider.value = g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour & 0xFF; break; case MENUOP_SET: - g_PlayerExtCfg[g_ExtMenuPlayer].crosshairalpha = data->slider.value; - g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour = RGBAToINT(SIGHT_COLOUR_R, SIGHT_COLOUR_G, SIGHT_COLOUR_B, g_PlayerExtCfg[g_ExtMenuPlayer].crosshairalpha); + g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour = RGBAToINT(SIGHT_COLOUR_R, SIGHT_COLOUR_G, SIGHT_COLOUR_B, data->slider.value); break; } diff --git a/src/game/mplayer/mplayer.c b/src/game/mplayer/mplayer.c index 5dd2584ce..825d62a33 100644 --- a/src/game/mplayer/mplayer.c +++ b/src/game/mplayer/mplayer.c @@ -121,7 +121,6 @@ struct mpweapon g_MpWeapons[NUM_MPWEAPONS] = { .radialmenuspeed = 4.f, \ .crosshairsway = 1.f, \ .crouchmode = CROUCHMODE_TOGGLE_ANALOG, \ - .crosshairalpha = 40, \ .crosshaircolour = 0x00ff0028, \ } diff --git a/src/include/types.h b/src/include/types.h index 4737f178b..81b71ca6d 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -6139,7 +6139,6 @@ struct extplayerconfig { f32 radialmenuspeed; f32 crosshairsway; s32 extcontrols; - u32 crosshairalpha; u32 crosshaircolour; }; From fb05725c34c6ea278c9d99423a0dda51111b0c06 Mon Sep 17 00:00:00 2001 From: Bobby Lovell Date: Thu, 14 Dec 2023 10:13:27 -0500 Subject: [PATCH 03/10] - Implement RGBA. - Add preview label. --- port/src/optionsmenu.c | 164 ++++++++++++++++++++++++++++++++----- src/game/mplayer/mplayer.c | 2 +- 2 files changed, 145 insertions(+), 21 deletions(-) diff --git a/port/src/optionsmenu.c b/port/src/optionsmenu.c index 34a28e74b..81dbbb6db 100644 --- a/port/src/optionsmenu.c +++ b/port/src/optionsmenu.c @@ -903,32 +903,156 @@ static MenuItemHandlerResult menuhandlerCrosshairSway(s32 operation, struct menu return 0; } -// Stock sight RGB. -#define SIGHT_COLOUR_R 0 -#define SIGHT_COLOUR_G 255 -#define SIGHT_COLOUR_B 0 - -static u32 RGBAToINT(u32 r, u32 g, u32 b, u32 a) -{ - return (((r) & 0xff) << 24 | ((g) & 0xff) << 16 | ((b) & 0xff) << 8 | ((a) & 0xff)); -} - -static MenuItemHandlerResult menuhandlerCrosshairAlpha(s32 operation, struct menuitem* item, union handlerdata* data) +static MenuItemHandlerResult menuhandlerCrosshair_R(s32 operation, struct menuitem* item, union handlerdata* data) { switch (operation) { case MENUOP_GETSLIDER: - data->slider.value = g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour & 0xFF; + data->slider.value = (g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour >> 24) & 0xFF; break; + case MENUOP_SET: - - g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour = RGBAToINT(SIGHT_COLOUR_R, SIGHT_COLOUR_G, SIGHT_COLOUR_B, data->slider.value); - + u32 newColor = g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour & 0xFFFFFF | data->slider.value << 24; + g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour = newColor; break; } return 0; } +static MenuItemHandlerResult menuhandlerCrosshair_G(s32 operation, struct menuitem* item, union handlerdata* data) +{ + switch (operation) { + case MENUOP_GETSLIDER: + data->slider.value = (g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour >> 16) & 0xFF; + break; + + case MENUOP_SET: + u32 newColor = g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour & 0xFF00FFFF | data->slider.value << 16; + g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour = newColor; + break; + } + + return 0; +} + +static MenuItemHandlerResult menuhandlerCrosshair_B(s32 operation, struct menuitem* item, union handlerdata* data) +{ + switch (operation) { + case MENUOP_GETSLIDER: + data->slider.value = (g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour >> 8) & 0xFF; + break; + + case MENUOP_SET: + u32 newColor = g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour & 0xFFFF00FF | data->slider.value << 8; + g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour = newColor; + break; + } + + return 0; +} + +static MenuItemHandlerResult menuhandlerCrosshair_A(s32 operation, struct menuitem* item, union handlerdata* data) +{ + switch (operation) { + case MENUOP_GETSLIDER: + data->slider.value = g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour & 0xFF; + break; + + case MENUOP_SET: + u32 newColor = g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour & 0xFFFFFF00 | data->slider.value; + g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour = newColor; + break; + } + + return 0; +} + +static MenuItemHandlerResult menuhandlerCrosshairColorPreview(s32 operation, struct menuitem* item, union handlerdata* data) +{ + if (operation == MENUOP_GETCOLOUR) { + data->label.colour1 = g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour; + data->label.colour2 = g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour; + } + + return 0; +} + +struct menuitem g_ExtendedGameCrosshairColourMenuItems[] = { + { + MENUITEMTYPE_SLIDER, + 0, + MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SLIDER_WIDE, + (uintptr_t)"R", + 255, + menuhandlerCrosshair_R, + }, + { + MENUITEMTYPE_SLIDER, + 0, + MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SLIDER_WIDE, + (uintptr_t)"G", + 255, + menuhandlerCrosshair_G, + }, + { + MENUITEMTYPE_SLIDER, + 0, + MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SLIDER_WIDE, + (uintptr_t)"B", + 255, + menuhandlerCrosshair_B, + }, + { + MENUITEMTYPE_SLIDER, + 0, + MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SLIDER_WIDE, + (uintptr_t)"Alpha", + 255, + menuhandlerCrosshair_A, + }, + { + MENUITEMTYPE_SEPARATOR, + 0, + 0, + 0, + 0, + NULL, + }, + { + MENUITEMTYPE_LABEL, + 0, + MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_LABEL_CUSTOMCOLOUR, + (uintptr_t)"PREVIEW\n", + 0, + menuhandlerCrosshairColorPreview, + }, + { + MENUITEMTYPE_SEPARATOR, + 0, + 0, + 0, + 0, + NULL, + }, + { + MENUITEMTYPE_SELECTABLE, + 0, + MENUITEMFLAG_SELECTABLE_CLOSESDIALOG, + L_OPTIONS_213, // "Back" + 0, + NULL, + }, + { MENUITEMTYPE_END }, +}; + +struct menudialogdef g_ExtendedGameCrosshairColourMenuDialog = { + MENUDIALOGTYPE_DEFAULT, + (uintptr_t)"Crosshair Colour", + g_ExtendedGameCrosshairColourMenuItems, + NULL, + MENUDIALOGFLAG_LITERAL_TEXT, + NULL, +}; struct menuitem g_ExtendedGameMenuItems[] = { { @@ -956,12 +1080,12 @@ struct menuitem g_ExtendedGameMenuItems[] = { menuhandlerCrosshairSway, }, { - MENUITEMTYPE_SLIDER, + MENUITEMTYPE_SELECTABLE, 0, - MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SLIDER_WIDE, - (uintptr_t)"Crosshair Alpha", - 255, - menuhandlerCrosshairAlpha, + MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SELECTABLE_OPENSDIALOG, + (uintptr_t)"Crosshair Colour\n", + 0, + (void*)&g_ExtendedGameCrosshairColourMenuDialog, }, { MENUITEMTYPE_SEPARATOR, diff --git a/src/game/mplayer/mplayer.c b/src/game/mplayer/mplayer.c index 825d62a33..b83d21d01 100644 --- a/src/game/mplayer/mplayer.c +++ b/src/game/mplayer/mplayer.c @@ -121,7 +121,7 @@ struct mpweapon g_MpWeapons[NUM_MPWEAPONS] = { .radialmenuspeed = 4.f, \ .crosshairsway = 1.f, \ .crouchmode = CROUCHMODE_TOGGLE_ANALOG, \ - .crosshaircolour = 0x00ff0028, \ + .crosshaircolour = 0x00ff0028, \ // Stock green color. } struct extplayerconfig g_PlayerExtCfg[MAX_PLAYERS] = { From 894ea53b291c968501c2959d8482056ba9dec8d4 Mon Sep 17 00:00:00 2001 From: Bobby Lovell Date: Thu, 14 Dec 2023 10:18:43 -0500 Subject: [PATCH 04/10] Spell out colors... --- port/src/optionsmenu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/port/src/optionsmenu.c b/port/src/optionsmenu.c index 81dbbb6db..931c95923 100644 --- a/port/src/optionsmenu.c +++ b/port/src/optionsmenu.c @@ -982,7 +982,7 @@ struct menuitem g_ExtendedGameCrosshairColourMenuItems[] = { MENUITEMTYPE_SLIDER, 0, MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SLIDER_WIDE, - (uintptr_t)"R", + (uintptr_t)"Red", 255, menuhandlerCrosshair_R, }, @@ -990,7 +990,7 @@ struct menuitem g_ExtendedGameCrosshairColourMenuItems[] = { MENUITEMTYPE_SLIDER, 0, MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SLIDER_WIDE, - (uintptr_t)"G", + (uintptr_t)"Green", 255, menuhandlerCrosshair_G, }, @@ -998,7 +998,7 @@ struct menuitem g_ExtendedGameCrosshairColourMenuItems[] = { MENUITEMTYPE_SLIDER, 0, MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SLIDER_WIDE, - (uintptr_t)"B", + (uintptr_t)"Blue", 255, menuhandlerCrosshair_B, }, From 8421140e3fbbde18f6d4f4afc4470c3ee3398455 Mon Sep 17 00:00:00 2001 From: Bobby Lovell Date: Thu, 14 Dec 2023 10:31:47 -0500 Subject: [PATCH 05/10] Remove comment. --- src/game/mplayer/mplayer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/mplayer/mplayer.c b/src/game/mplayer/mplayer.c index b83d21d01..825d62a33 100644 --- a/src/game/mplayer/mplayer.c +++ b/src/game/mplayer/mplayer.c @@ -121,7 +121,7 @@ struct mpweapon g_MpWeapons[NUM_MPWEAPONS] = { .radialmenuspeed = 4.f, \ .crosshairsway = 1.f, \ .crouchmode = CROUCHMODE_TOGGLE_ANALOG, \ - .crosshaircolour = 0x00ff0028, \ // Stock green color. + .crosshaircolour = 0x00ff0028, \ } struct extplayerconfig g_PlayerExtCfg[MAX_PLAYERS] = { From 519bd95a7516ca6798caae5fa6e35baa3667dc47 Mon Sep 17 00:00:00 2001 From: Bobby Lovell Date: Thu, 14 Dec 2023 14:49:13 -0500 Subject: [PATCH 06/10] Center preview text. --- port/src/optionsmenu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/port/src/optionsmenu.c b/port/src/optionsmenu.c index 931c95923..c700b8dcb 100644 --- a/port/src/optionsmenu.c +++ b/port/src/optionsmenu.c @@ -1021,7 +1021,7 @@ struct menuitem g_ExtendedGameCrosshairColourMenuItems[] = { { MENUITEMTYPE_LABEL, 0, - MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_LABEL_CUSTOMCOLOUR, + MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_LABEL_CUSTOMCOLOUR | MENUITEMFLAG_SELECTABLE_CENTRE, (uintptr_t)"PREVIEW\n", 0, menuhandlerCrosshairColorPreview, From 79fb976bcfd12b1767279c0e9a2818c083eb1491 Mon Sep 17 00:00:00 2001 From: Bobby Lovell Date: Thu, 14 Dec 2023 16:03:29 -0500 Subject: [PATCH 07/10] Implement a simple colored box menu item type and use that for the preview. --- port/src/optionsmenu.c | 7 +++---- src/game/menu.c | 3 +++ src/game/menuitem.c | 31 +++++++++++++++++++++++++++++++ src/include/constants.h | 4 ++++ src/include/game/menuitem.h | 4 ++++ 5 files changed, 45 insertions(+), 4 deletions(-) diff --git a/port/src/optionsmenu.c b/port/src/optionsmenu.c index c700b8dcb..b3f80e207 100644 --- a/port/src/optionsmenu.c +++ b/port/src/optionsmenu.c @@ -971,7 +971,6 @@ static MenuItemHandlerResult menuhandlerCrosshairColorPreview(s32 operation, str { if (operation == MENUOP_GETCOLOUR) { data->label.colour1 = g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour; - data->label.colour2 = g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour; } return 0; @@ -1019,10 +1018,10 @@ struct menuitem g_ExtendedGameCrosshairColourMenuItems[] = { NULL, }, { - MENUITEMTYPE_LABEL, + MENUITEMTYPE_COLORBOX, + 0, + 0, 0, - MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_LABEL_CUSTOMCOLOUR | MENUITEMFLAG_SELECTABLE_CENTRE, - (uintptr_t)"PREVIEW\n", 0, menuhandlerCrosshairColorPreview, }, diff --git a/src/game/menu.c b/src/game/menu.c index b63ad6315..46e743aca 100644 --- a/src/game/menu.c +++ b/src/game/menu.c @@ -1178,6 +1178,9 @@ bool menuIsItemFocusable(struct menuitem *item, struct menudialog *dialog, s32 a case MENUITEMTYPE_METER: case MENUITEMTYPE_MARQUEE: case MENUITEMTYPE_CONTROLLER: +#ifndef PLATFORM_N64 + case MENUITEMTYPE_COLORBOX: +#endif return false; case MENUITEMTYPE_10: case MENUITEMTYPE_14: diff --git a/src/game/menuitem.c b/src/game/menuitem.c index 11e53274d..d780e74ab 100644 --- a/src/game/menuitem.c +++ b/src/game/menuitem.c @@ -2109,6 +2109,36 @@ Gfx *menuitemMeterRender(Gfx *gdl, struct menurendercontext *context) return gdl; } +#ifndef PLATFORM_N64 + +// Draws a colored box which fills the background of the menu item. +Gfx* menuitemColorBoxRender(Gfx *gdl, struct menurendercontext *context) +{ + u32 width = context->width; + u32 height = context->height; + u32 colour1; + s32 x1; + s32 x2; + + x1 = context->x; + x2 = x1 + width; + + union handlerdata data; + if (context->item->handlervoid) { + context->item->handlervoid(MENUOP_GETCOLOUR, context->item, &data); + } + + colour1 = data.label.colour1; + + gdl = textSetPrimColour(gdl, colour1); + gDPFillRectangleScaled(gdl++, x1, context->y, x2, context->y + height); + gdl = text0f153838(gdl); + + return gdl; +} + +#endif + Gfx *menuitemSelectableRender(Gfx *gdl, struct menurendercontext *context) { u32 leftcolour; @@ -4349,6 +4379,7 @@ Gfx *menuitemRender(Gfx *gdl, struct menurendercontext *context) case MENUITEMTYPE_CAROUSEL: return menuitemCarouselRender(gdl, context); case MENUITEMTYPE_MODEL: return menuitemModelRender(gdl, context); case MENUITEMTYPE_CONTROLLER: return menuitemControllerRender(gdl, context); + case MENUITEMTYPE_COLORBOX: return menuitemColorBoxRender(gdl, context); } return gdl; diff --git a/src/include/constants.h b/src/include/constants.h index 943f172d3..8b39686d4 100644 --- a/src/include/constants.h +++ b/src/include/constants.h @@ -1692,6 +1692,10 @@ #define MENUITEMTYPE_CONTROLLER 0x19 #define MENUITEMTYPE_END 0x1a +#ifndef PLATFORM_N64 +#define MENUITEMTYPE_COLORBOX 0x1b +#endif + #define MENUMODELFLAG_HASSCALE 0x01 #define MENUMODELFLAG_HASPOSITION 0x02 #define MENUMODELFLAG_HASROTATION 0x04 diff --git a/src/include/game/menuitem.h b/src/include/game/menuitem.h index 27747bf71..79b868989 100644 --- a/src/include/game/menuitem.h +++ b/src/include/game/menuitem.h @@ -32,6 +32,10 @@ Gfx *menuitemLabelRender(Gfx *gdl, struct menurendercontext *context); Gfx *menuitemMeterRender(Gfx *gdl, struct menurendercontext *context); +#ifndef PLATFORM_N64 +Gfx *menuitemColorBoxRender(Gfx *gdl, struct menurendercontext *context); +#endif + Gfx *menuitemSelectableRender(Gfx *gdl, struct menurendercontext *context); bool menuitemSelectableTick(struct menuitem *item, struct menuinputs *inputs, u32 tickflags); From e84d83e404bc5abf4e7eefaaf136e3512aeae35e Mon Sep 17 00:00:00 2001 From: Bobby Lovell Date: Thu, 14 Dec 2023 16:08:53 -0500 Subject: [PATCH 08/10] Add missing ndef. --- src/game/menuitem.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/game/menuitem.c b/src/game/menuitem.c index d780e74ab..0f5d68b6b 100644 --- a/src/game/menuitem.c +++ b/src/game/menuitem.c @@ -4379,7 +4379,11 @@ Gfx *menuitemRender(Gfx *gdl, struct menurendercontext *context) case MENUITEMTYPE_CAROUSEL: return menuitemCarouselRender(gdl, context); case MENUITEMTYPE_MODEL: return menuitemModelRender(gdl, context); case MENUITEMTYPE_CONTROLLER: return menuitemControllerRender(gdl, context); + +#ifndef PLATFORM_N64 case MENUITEMTYPE_COLORBOX: return menuitemColorBoxRender(gdl, context); +#endif + } return gdl; From 880a7a0971b07afbceb02c6cc4039e9716d963e4 Mon Sep 17 00:00:00 2001 From: Bobby Lovell Date: Fri, 15 Dec 2023 08:10:31 -0500 Subject: [PATCH 09/10] Add back line inadvertently removed in 342e186f794d83c6832be5f621dc3b3b913e8d9d --- src/game/mplayer/mplayer.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/game/mplayer/mplayer.c b/src/game/mplayer/mplayer.c index 825d62a33..409d6c246 100644 --- a/src/game/mplayer/mplayer.c +++ b/src/game/mplayer/mplayer.c @@ -121,6 +121,7 @@ struct mpweapon g_MpWeapons[NUM_MPWEAPONS] = { .radialmenuspeed = 4.f, \ .crosshairsway = 1.f, \ .crouchmode = CROUCHMODE_TOGGLE_ANALOG, \ + .extcontrols = true, \ .crosshaircolour = 0x00ff0028, \ } From 1698f53728d254c36b588cbae8af4fa13927fa46 Mon Sep 17 00:00:00 2001 From: Bobby Lovell Date: Sat, 16 Dec 2023 10:20:32 -0500 Subject: [PATCH 10/10] Update main.c to use new UInt config for crosshair color --- port/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/port/src/main.c b/port/src/main.c index 743b8a699..8f8ec2af8 100644 --- a/port/src/main.c +++ b/port/src/main.c @@ -167,6 +167,6 @@ PD_CONSTRUCTOR static void gameConfigInit(void) configRegisterFloat(strFmt("Game.Player%d.CrosshairSway", i), &g_PlayerExtCfg[j].crosshairsway, 0.f, 10.f); configRegisterInt(strFmt("Game.Player%d.CrouchMode", i), &g_PlayerExtCfg[j].crouchmode, 0, CROUCHMODE_TOGGLE_ANALOG); configRegisterInt(strFmt("Game.Player%d.ExtendedControls", i), &g_PlayerExtCfg[j].extcontrols, 0, 1); - configRegisterInt(strFmt("Game.Player%d.CrosshairColour", i), &g_PlayerExtCfg[j].crosshaircolour, 0, 0xFFFFFFFF); + configRegisterUInt(strFmt("Game.Player%d.CrosshairColour", i), &g_PlayerExtCfg[j].crosshaircolour, 0, 0xFFFFFFFF); } }