Skip to content

Commit

Permalink
overlay: fix reset and unbind progress bars in controls menu
Browse files Browse the repository at this point in the history
  • Loading branch information
walkawayy committed Aug 23, 2023
1 parent 35394c2 commit 07bb33a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- fixed the incorrect starting animation on centaurs that spawn from statues (#926, regression from 2.15)
- fixed jump-twist animations at times being interrupted (#932, regression from 2.15.1)
- fixed walk-run-jump at times breaking when TR2 jumping is enabled (OG bug in TR2+) (#934)
- fixed the reset and unbind progress bars in the controls menu for non-default bar scaling (#930)
- improve spanish localization and added translation for rotated pickups

## [2.15.3](https://github.com/rr-/Tomb1Main/compare/2.15.2...2.15.3) - 2023-08-15
Expand Down
1 change: 1 addition & 0 deletions src/game/option/option_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ static void Option_ControlProgressBar(TEXTSTRING *txt, int32_t timer)
} else if (txt->flags.right) {
x += Screen_GetResWidthDownscaledText() - width;
}

if (txt->flags.centre_v) {
y += Screen_GetResHeightDownscaledText() / 2;
} else if (txt->flags.bottom) {
Expand Down
59 changes: 59 additions & 0 deletions src/game/overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,65 @@ void Overlay_BarDraw(BAR_INFO *bar_info)
}
}

void Overlay_BarDrawTextScaled(BAR_INFO *bar_info)
{
const RGBA8888 rgb_bgnd = { 0, 0, 0, 255 };
const RGBA8888 rgb_border = { 53, 53, 53, 255 };

int32_t width = 200;
int32_t height = 10;

int32_t x = 0;
int32_t y = 0;
Overlay_BarGetLocation(bar_info, &width, &height, &x, &y);

int32_t padding = Screen_GetRenderScaleText(2);
int32_t border = Screen_GetRenderScaleText(2);

int32_t sx = Screen_GetRenderScaleText(x) - padding;
int32_t sy = Screen_GetRenderScaleText(y) - padding;
int32_t sw = Screen_GetRenderScaleText(width) + padding * 2;
int32_t sh = Screen_GetRenderScaleText(height) + padding * 2;

// border
Output_DrawScreenFlatQuad(
sx - border, sy - border, sw + 2 * border, sh + 2 * border, rgb_border);

// background
Output_DrawScreenFlatQuad(sx, sy, sw, sh, rgb_bgnd);

int32_t percent = Overlay_BarGetPercent(bar_info);

// Check if bar should flash or not
Overlay_BarBlink(bar_info);

if (percent && !bar_info->blink) {
width = width * percent / 100;

sx = Screen_GetRenderScaleText(x);
sy = Screen_GetRenderScaleText(y);
sw = Screen_GetRenderScaleText(width);
sh = Screen_GetRenderScaleText(height);

if (g_Config.enable_smooth_bars) {
for (int i = 0; i < COLOR_STEPS - 1; i++) {
RGBA8888 c1 = m_ColorBarMap[bar_info->color][i];
RGBA8888 c2 = m_ColorBarMap[bar_info->color][i + 1];
int32_t lsy = sy + i * sh / (COLOR_STEPS - 1);
int32_t lsh = sy + (i + 1) * sh / (COLOR_STEPS - 1) - lsy;
Output_DrawScreenGradientQuad(sx, lsy, sw, lsh, c1, c1, c2, c2);
}
} else {
for (int i = 0; i < COLOR_STEPS; i++) {
RGBA8888 color = m_ColorBarMap[bar_info->color][i];
int32_t lsy = sy + i * sh / COLOR_STEPS;
int32_t lsh = sy + (i + 1) * sh / COLOR_STEPS - lsy;
Output_DrawScreenFlatQuad(sx, lsy, sw, lsh, color);
}
}
}
}

static void Overlay_OnAmmoTextRemoval(const TEXTSTRING *textstring)
{
m_AmmoText = NULL;
Expand Down
1 change: 1 addition & 0 deletions src/game/overlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void Overlay_Init(void);
void Overlay_BarSetHealthTimer(int16_t health_bar_timer);
void Overlay_BarHealthTimerTick(void);
void Overlay_BarDraw(struct BAR_INFO *bar_info);
void Overlay_BarDrawTextScaled(BAR_INFO *bar_info);
void Overlay_BarDrawHealth(void);
void Overlay_BarDrawAir(void);
void Overlay_BarDrawEnemy(void);
Expand Down
2 changes: 1 addition & 1 deletion src/game/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ static void Text_DrawText(TEXTSTRING *textstring)
}

if (textstring->flags.progress_bar && textstring->progress_bar.value) {
Overlay_BarDraw(&textstring->progress_bar);
Overlay_BarDrawTextScaled(&textstring->progress_bar);
}

if (textstring->flags.outline) {
Expand Down

0 comments on commit 07bb33a

Please sign in to comment.