Skip to content

Commit

Permalink
Merge pull request #300 from Bobbar/port_crosshair_alpha
Browse files Browse the repository at this point in the history
Crosshair Alpha Proof of Concept
  • Loading branch information
fgsfdsfgs authored Dec 22, 2023
2 parents 461bf8d + 1698f53 commit a82ac02
Show file tree
Hide file tree
Showing 9 changed files with 259 additions and 0 deletions.
1 change: 1 addition & 0 deletions port/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +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);
configRegisterUInt(strFmt("Game.Player%d.CrosshairColour", i), &g_PlayerExtCfg[j].crosshaircolour, 0, 0xFFFFFFFF);
}
}
158 changes: 158 additions & 0 deletions port/src/optionsmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,156 @@ static MenuItemHandlerResult menuhandlerCrosshairSway(s32 operation, struct menu
return 0;
}

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 >> 24) & 0xFF;
break;

case MENUOP_SET:
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;
}

return 0;
}

struct menuitem g_ExtendedGameCrosshairColourMenuItems[] = {
{
MENUITEMTYPE_SLIDER,
0,
MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SLIDER_WIDE,
(uintptr_t)"Red",
255,
menuhandlerCrosshair_R,
},
{
MENUITEMTYPE_SLIDER,
0,
MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SLIDER_WIDE,
(uintptr_t)"Green",
255,
menuhandlerCrosshair_G,
},
{
MENUITEMTYPE_SLIDER,
0,
MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SLIDER_WIDE,
(uintptr_t)"Blue",
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_COLORBOX,
0,
0,
0,
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[] = {
{
MENUITEMTYPE_DROPDOWN,
Expand All @@ -970,6 +1120,14 @@ struct menuitem g_ExtendedGameMenuItems[] = {
20,
menuhandlerCrosshairSway,
},
{
MENUITEMTYPE_SELECTABLE,
0,
MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SELECTABLE_OPENSDIALOG,
(uintptr_t)"Crosshair Colour\n",
0,
(void*)&g_ExtendedGameCrosshairColourMenuDialog,
},
{
MENUITEMTYPE_SEPARATOR,
0,
Expand Down
3 changes: 3 additions & 0 deletions src/game/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
35 changes: 35 additions & 0 deletions src/game/menuitem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -4349,6 +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;
Expand Down
1 change: 1 addition & 0 deletions src/game/mplayer/mplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ struct mpweapon g_MpWeapons[NUM_MPWEAPONS] = {
.crosshairsway = 1.f, \
.crouchmode = CROUCHMODE_TOGGLE_ANALOG, \
.extcontrols = true, \
.crosshaircolour = 0x00ff0028, \
}

struct extplayerconfig g_PlayerExtCfg[MAX_PLAYERS] = {
Expand Down
52 changes: 52 additions & 0 deletions src/game/sight.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/include/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/include/game/menuitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading

0 comments on commit a82ac02

Please sign in to comment.