Skip to content

Commit

Permalink
Replace hardcoded hud style values with enum
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-drexler committed Jan 13, 2024
1 parent b72ba40 commit bd14f4f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Quake/gl_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1121,11 +1121,11 @@ void Draw_GetCanvasTransform (canvastype type, drawtransform_t *transform)
Draw_Transform (vid.guiwidth/s, vid.guiheight/s, s, CANVAS_ALIGN_CENTERX, CANVAS_ALIGN_CENTERY, transform);
break;
case CANVAS_SBAR:
if (scr_hudstyle.value > 2) // qw hud could cut off if too short
if (hudstyle == HUD_QUAKEWORLD) // qw hud could cut off if too short
s = CLAMP (1.0f, scr_sbarscale.value, (float)vid.guiheight / 240.0f);
else
s = CLAMP(1.0f, scr_sbarscale.value, (float)vid.guiwidth / 320.0f);
if (cl.gametype == GAME_DEATHMATCH && (scr_hudstyle.value < 1 || scr_hudstyle.value > 2) )
if (cl.gametype == GAME_DEATHMATCH && (hudstyle == HUD_CLASSIC || hudstyle == HUD_QUAKEWORLD))
Draw_Transform (320, 48, s, CANVAS_ALIGN_LEFT, CANVAS_ALIGN_BOTTOM, transform);
else
Draw_Transform (320, 48, s, CANVAS_ALIGN_CENTERX, CANVAS_ALIGN_BOTTOM, transform);
Expand Down
28 changes: 22 additions & 6 deletions Quake/gl_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ float scr_disabled_time;

int scr_tileclear_updates = 0; //johnfitz

hudstyle_t hudstyle;

void SCR_ScreenShot_f (void);

/*
Expand Down Expand Up @@ -399,7 +401,7 @@ static void SCR_CalcRefdef (void)
scale = CLAMP (1.0f, scr_sbarscale.value, (float)glwidth / 320.0f);
scale *= (float) vid.height / vid.guiheight;

if (size >= 120 || cl.intermission || scr_sbaralpha.value < 1 || scr_hudstyle.value >= 1 || cl.qcvm.extfuncs.CSQC_DrawHud) //johnfitz -- scr_sbaralpha.value
if (size >= 120 || cl.intermission || scr_sbaralpha.value < 1 || hudstyle != HUD_CLASSIC || cl.qcvm.extfuncs.CSQC_DrawHud) //johnfitz -- scr_sbaralpha.value
sb_lines = 0;
else if (size >= 110)
sb_lines = 24 * scale;
Expand Down Expand Up @@ -495,6 +497,20 @@ void SCR_PixelAspect_f (cvar_t *cvar)
VID_RecalcInterfaceSize ();
}

/*
==================
SCR_HUDStyle_f
Updates hudstyle variable and invalidates refdef when scr_hudstyle changes
==================
*/
void SCR_HUDStyle_f (cvar_t *cvar)
{
int val = (int) cvar->value;
hudstyle = (hudstyle_t) CLAMP (0, val, (int) HUD_COUNT - 1);
vid.recalc_refdef = 1;
}

//============================================================================

/*
Expand Down Expand Up @@ -529,15 +545,15 @@ void SCR_Init (void)
Cvar_RegisterVariable (&scr_showfps);
Cvar_RegisterVariable (&scr_showspeed);
Cvar_RegisterVariable (&scr_clock);
Cvar_RegisterVariable (&scr_hudstyle);
Cvar_RegisterVariable (&cl_screenshotname);
//johnfitz
Cvar_RegisterVariable (&scr_usekfont); // 2021 re-release
Cvar_SetCallback (&scr_fov, SCR_Callback_refdef);
Cvar_SetCallback (&scr_fov_adapt, SCR_Callback_refdef);
Cvar_SetCallback (&scr_zoomfov, SCR_Callback_refdef);
Cvar_SetCallback (&scr_viewsize, SCR_Callback_refdef);
Cvar_SetCallback (&scr_hudstyle, SCR_Callback_refdef);
Cvar_SetCallback (&scr_hudstyle, SCR_HUDStyle_f);
Cvar_RegisterVariable (&scr_hudstyle);
Cvar_RegisterVariable (&scr_fov);
Cvar_RegisterVariable (&scr_fov_adapt);
Cvar_RegisterVariable (&scr_zoomfov);
Expand Down Expand Up @@ -615,7 +631,7 @@ void SCR_DrawFPS (void)
else
sprintf (st, "%.2f ms", 1000.f / lastfps);
x = 320 - (strlen(st)<<3);
if (scr_hudstyle.value >= 1)
if (hudstyle != HUD_CLASSIC)
{
x = 320 - 16 - (strlen(st)<<3);
y = 8;
Expand Down Expand Up @@ -702,7 +718,7 @@ void SCR_DrawClock (void)
return;

//draw it
if (scr_hudstyle.value < 1)
if (hudstyle == HUD_CLASSIC)
{
GL_SetCanvas (CANVAS_BOTTOMRIGHT);
Draw_String (320 - (strlen(str)<<3), 200 - 8, str);
Expand Down Expand Up @@ -868,7 +884,7 @@ void SCR_DrawSaving (void)

x = 320 - 16 - draw_disc->width;
y = 8;
if (scr_hudstyle.value >= 1 && scr_viewsize.value < 130)
if (hudstyle != HUD_CLASSIC && scr_viewsize.value < 130)
{
if (scr_clock.value) y += 8;
if (scr_showfps.value) y += 8;
Expand Down
18 changes: 9 additions & 9 deletions Quake/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -3607,7 +3607,7 @@ void M_AdjustSliders (int dir)
break;

case OPT_HUDSTYLE: // hud style
Cvar_SetValueQuick (&scr_hudstyle, ((int) q_max (scr_hudstyle.value, 0.f) + 4 + dir) % 4);
Cvar_SetValueQuick (&scr_hudstyle, ((int) q_max (scr_hudstyle.value, 0.f) + (int) HUD_COUNT + dir) % (int) HUD_COUNT);
break;

case OPT_ALWAYRUN: // always run
Expand Down Expand Up @@ -4042,14 +4042,14 @@ static void M_Options_DrawItem (int y, int item)
break;

case OPT_HUDSTYLE:
if (scr_hudstyle.value < 1)
M_Print (x, y, "Classic");
else if (scr_hudstyle.value < 2)
M_Print (x, y, "Modern 1");
else if (scr_hudstyle.value < 3)
M_Print (x, y, "Modern 2");
else
M_Print(x, y, "QuakeWorld");
switch (hudstyle)
{
case HUD_MODERN_CENTERAMMO: M_Print (x, y, "Modern 1"); break;
case HUD_MODERN_SIDEAMMO: M_Print (x, y, "Modern 2"); break;
case HUD_QUAKEWORLD: M_Print (x, y, "QuakeWorld"); break;
default:
case HUD_CLASSIC: M_Print (x, y, "Classic"); break;
}
break;

case OPT_SNDVOL:
Expand Down
12 changes: 6 additions & 6 deletions Quake/sbar.c
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ void Sbar_DrawInventory2 (void)
{
pic = Sbar_InventoryBarPic ();

if (scr_hudstyle.value >= 2) // right side, 2x2
if (hudstyle == HUD_MODERN_SIDEAMMO || hudstyle == HUD_QUAKEWORLD) // right side, 2x2
{
const int ITEM_WIDTH = 52;
x = (int)(glcanvas.right - SBAR2_MARGIN_X - ITEM_WIDTH * 2 + 0.5f);
Expand All @@ -1147,7 +1147,7 @@ void Sbar_DrawInventory2 (void)
}

// items
if (scr_viewsize.value < 110 && scr_hudstyle.value >= 2)
if (scr_viewsize.value < 110 && (hudstyle == HUD_MODERN_SIDEAMMO || hudstyle == HUD_QUAKEWORLD))
{
x = (int)(glcanvas.right - SBAR2_MARGIN_X - 16 + 0.5f);
y = (int)(glcanvas.bottom - SBAR2_MARGIN_Y - 68 - 20 + 0.5f);
Expand Down Expand Up @@ -1260,7 +1260,7 @@ static void Sbar_DrawSigils (void)
x = 160 - 32/2;
if (sb_showscores)
y = -20;
else if (scr_hudstyle.value < 2)
else if (hudstyle == HUD_CLASSIC || hudstyle == HUD_MODERN_CENTERAMMO)
y = -8;
else
y = -4;
Expand Down Expand Up @@ -1686,11 +1686,11 @@ void Sbar_Draw (void)
invuln = (cl.items & IT_INVULNERABILITY) != 0;
armor = invuln ? 666 : cl.stats[STAT_ARMOR];

if (scr_hudstyle.value < 1 || scr_hudstyle.value > 2)
if (hudstyle == HUD_CLASSIC || hudstyle == HUD_QUAKEWORLD)
{
GL_SetCanvas (CANVAS_SBAR); //johnfitz

if (scr_hudstyle.value < 1) //classic hud
if (hudstyle == HUD_CLASSIC) //classic hud
{
if (scr_viewsize.value < 110) //johnfitz -- check viewsize instead of sb_lines
{
Expand Down Expand Up @@ -1724,7 +1724,7 @@ void Sbar_Draw (void)
}
else if (scr_viewsize.value < 120) //johnfitz -- check viewsize instead of sb_lines
{
if (scr_hudstyle.value < 1)
if (hudstyle == HUD_CLASSIC)
Sbar_DrawPicAlpha (0, 0, sb_sbar, scr_sbaralpha.value); //johnfitz -- scr_sbaralpha

// keys (hipnotic only)
Expand Down
11 changes: 11 additions & 0 deletions Quake/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,18 @@ extern cvar_t scr_scale;
extern cvar_t scr_crosshairscale;
//johnfitz

typedef enum hudstyle_t
{
HUD_CLASSIC,
HUD_MODERN_CENTERAMMO, // Modern 1
HUD_MODERN_SIDEAMMO, // Modern 2
HUD_QUAKEWORLD,

HUD_COUNT,
} hudstyle_t;

extern cvar_t scr_hudstyle;
extern hudstyle_t hudstyle;

extern int scr_tileclear_updates; //johnfitz

Expand Down

0 comments on commit bd14f4f

Please sign in to comment.