Skip to content

Commit

Permalink
tr2/overlay: improve ammo counter placement
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Dec 30, 2024
1 parent 39ee43b commit bf63297
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 27 deletions.
37 changes: 21 additions & 16 deletions src/tr2/game/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,33 @@ static void M_InsertBar(
const int32_t percent, const COLOR_NAME bar_color_main,
const COLOR_NAME bar_color_highlight)
{
const int32_t z_offset = 8;

struct {
int32_t x1, y1, x2, y2;
COLOR_NAME color;
} rects[] = {
{ l, t, l + w, t + h, COLOR_WHITE },
{ l + 1, t + 1, l + w, t + h, COLOR_GRAY },
{ l + 1, t + 1, l + w - 1, t + h - 1, COLOR_BLACK },
{ l + 2, t + 2, l + (w - 2) * percent / 100, t + h - 2,
bar_color_main },
{ l + 2, t + 3, l + (w - 2) * percent / 100, t + 4,
bar_color_highlight },
{ 0, 0, w, h, COLOR_WHITE },
{ 1, 1, w, h, COLOR_GRAY },
{ 1, 1, w - 1, h - 1, COLOR_BLACK },
{ 2, 2, (w - 2) * percent / 100, h - 2, bar_color_main },
{ 2, 3, (w - 2) * percent / 100, 4, bar_color_highlight },
};

const int32_t z_offset = 8;
const int32_t x_offset = l < 0
? g_PhdWinWidth + Scaler_Calc(l, SCALER_TARGET_GENERIC)
- Scaler_Calc(w - 1, SCALER_TARGET_BAR)
: Scaler_Calc(l, SCALER_TARGET_GENERIC);
const int32_t y_offset = t < 0
? g_PhdWinHeight + Scaler_Calc(t, SCALER_TARGET_GENERIC)
- Scaler_Calc(h - 1, SCALER_TARGET_BAR)
: Scaler_Calc(t, SCALER_TARGET_GENERIC);

for (int32_t i = 0; i < 5; i++) {
Render_InsertFlatRect(
Scaler_Calc(rects[i].x1, SCALER_TARGET_BAR),
Scaler_Calc(rects[i].y1, SCALER_TARGET_BAR),
Scaler_Calc(rects[i].x2, SCALER_TARGET_BAR),
Scaler_Calc(rects[i].y2, SCALER_TARGET_BAR),
x_offset + Scaler_Calc(rects[i].x1, SCALER_TARGET_BAR),
y_offset + Scaler_Calc(rects[i].y1, SCALER_TARGET_BAR),
x_offset + Scaler_Calc(rects[i].x2, SCALER_TARGET_BAR),
y_offset + Scaler_Calc(rects[i].y2, SCALER_TARGET_BAR),
g_PhdNearZ + z_offset * (5 - i),
g_NamedColors[rects[i].color].palette_index);
}
Expand Down Expand Up @@ -752,14 +758,13 @@ void Output_DrawScreenFBox(
void Output_DrawHealthBar(const int32_t percent)
{
g_IsShadeEffect = false;
M_InsertBar(6, 6, 105, 9, percent, COLOR_RED, COLOR_ORANGE);
M_InsertBar(8, 8, 105, 9, percent, COLOR_RED, COLOR_ORANGE);
}

void Output_DrawAirBar(const int32_t percent)
{
g_IsShadeEffect = false;
const int32_t w = Scaler_CalcInverse(g_PhdWinWidth, SCALER_TARGET_BAR);
M_InsertBar(w - 112, 6, 105, 9, percent, COLOR_BLUE, COLOR_WHITE);
M_InsertBar(-8, 8, 105, 9, percent, COLOR_BLUE, COLOR_WHITE);
}

int16_t Output_FindColor(
Expand Down
15 changes: 11 additions & 4 deletions src/tr2/game/overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "game/music.h"
#include "game/objects/common.h"
#include "game/output.h"
#include "game/scaler.h"
#include "game/text.h"
#include "game/viewport.h"
#include "global/vars.h"

Expand All @@ -26,7 +28,6 @@

#define FLASH_FRAMES 5
#define AMMO_X (-10)
#define AMMO_Y 35
#define MODE_INFO_X (-16)
#define MODE_INFO_Y (-16)

Expand All @@ -53,6 +54,7 @@ static bool m_FlashState = false;
static int32_t m_FlashCounter = 0;
static int32_t m_DisplayModeInfoTimer = 0;
static TEXTSTRING *m_DisplayModeTextInfo = NULL;
static int32_t m_AmmoTextY = 0;
static TEXTSTRING *m_AmmoTextInfo = NULL;

static float M_Ease(int32_t cur_frame, int32_t max_frames);
Expand Down Expand Up @@ -137,14 +139,15 @@ void Overlay_DrawAssaultTimer(void)

void Overlay_DrawGameInfo(const bool pickup_state)
{
Overlay_DrawAmmoInfo();
Overlay_DrawModeInfo();
m_AmmoTextY = ABS(AMMO_X) + TEXT_HEIGHT;
if (g_OverlayStatus > 0) {
Overlay_DrawHealthBar();
Overlay_DrawAirBar();
Overlay_DrawPickups(pickup_state);
Overlay_DrawAssaultTimer();
}
Overlay_DrawAmmoInfo();
Overlay_DrawModeInfo();
Console_Draw();
Text_Draw();
}
Expand Down Expand Up @@ -241,6 +244,9 @@ void Overlay_DrawAirBar(void)
Output_DrawAirBar(m_FlashState ? percent : 0);
} else {
Output_DrawAirBar(percent);
m_AmmoTextY += 10 * Scaler_GetScale(SCALER_TARGET_BAR)
/ Scaler_GetScale(SCALER_TARGET_TEXT);
m_AmmoTextY += 3;
}
}

Expand Down Expand Up @@ -322,9 +328,10 @@ void Overlay_DrawAmmoInfo(void)

Overlay_MakeAmmoString(buffer);
if (m_AmmoTextInfo != NULL) {
Text_SetPos(m_AmmoTextInfo, AMMO_X, m_AmmoTextY);
Text_ChangeText(m_AmmoTextInfo, buffer);
} else {
m_AmmoTextInfo = Text_Create(AMMO_X, AMMO_Y, buffer);
m_AmmoTextInfo = Text_Create(AMMO_X, m_AmmoTextY, buffer);
Text_AlignRight(m_AmmoTextInfo, true);
}
}
Expand Down
16 changes: 9 additions & 7 deletions src/tr2/game/scaler.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@ static int32_t M_DoCalc(
return MIN(scale_x, scale_y);
}

int32_t Scaler_Calc(const int32_t unit, const SCALER_TARGET target)
double Scaler_GetScale(const SCALER_TARGET target)
{
double scale = 1.0;
switch (target) {
case SCALER_TARGET_BAR:
scale = g_Config.ui.bar_scale;
break;
return g_Config.ui.bar_scale;
case SCALER_TARGET_TEXT:
scale = g_Config.ui.text_scale;
break;
return g_Config.ui.text_scale;
default:
return 1.0;
}
}

return M_DoCalc(unit, 640, 480, scale);
int32_t Scaler_Calc(const int32_t unit, const SCALER_TARGET target)
{
return M_DoCalc(unit, 640, 480, Scaler_GetScale(target));
}

int32_t Scaler_CalcInverse(const int32_t unit, const SCALER_TARGET target)
Expand Down
2 changes: 2 additions & 0 deletions src/tr2/game/scaler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#include <stdint.h>

typedef enum {
SCALER_TARGET_GENERIC,
SCALER_TARGET_BAR,
SCALER_TARGET_TEXT,
} SCALER_TARGET;

double Scaler_GetScale(const SCALER_TARGET target);
int32_t Scaler_Calc(int32_t unit, SCALER_TARGET target);
int32_t Scaler_CalcInverse(int32_t unit, SCALER_TARGET target);

0 comments on commit bf63297

Please sign in to comment.