Skip to content

Commit

Permalink
overlay: fix FPS, healthbar, and arrows from overlapping
Browse files Browse the repository at this point in the history
Resolves #787.
  • Loading branch information
lahm86 authored Apr 3, 2023
1 parent 841599c commit ffcaef5
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- fixed the text and bar scaling from being able to be set below the max and min (#698)
- fixed a data issue in Colosseum, which prevented a bat from triggering (#750)
- fixed lightning and gun flash continuing to animate in the inventory, pause and statistics screens (#767)
- fixed the FPS, healthbar, and arrows from overlapping on the inventory screen (#787)
- improved the control of Lara's braid to result in smoother animation and to detect floor collision (#761)
- increased the number of effects from 100 to 1000 (#623)
- removed the fix_pyramid_secret gameflow sequence (now handled by data injection) (#788)
Expand Down
4 changes: 2 additions & 2 deletions src/game/game/game_pause.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ bool Game_Pause(void)
Music_Pause();
Sound_StopAmbientSounds();
Sound_StopAllSamples();
g_GameInfo.status = GMS_IN_PAUSE;
g_GameInfo.status |= GMS_IN_PAUSE;

Output_FadeToSemiBlack(true);
int32_t select = Game_Pause_Loop();
Expand All @@ -159,6 +159,6 @@ bool Game_Pause(void)
Music_Unpause();
Requester_Remove(&m_PauseRequester);
Game_Pause_RemoveText();
g_GameInfo.status = GMS_IN_GAME;
g_GameInfo.status &= ~GMS_IN_PAUSE;
return select < 0;
}
10 changes: 7 additions & 3 deletions src/game/inventory/inventory.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,10 @@ static int32_t Inv_ConstructAndDisplay(int inv_mode)
Inv_Ring_NotActive();
}

Overlay_DrawFPSInfo();
bool inv_ring_above = g_InvMode == INV_GAME_MODE
&& ((ring.type == RT_MAIN && g_InvKeysObjects)
|| (ring.type == RT_OPTION && g_InvMainObjects));
Overlay_DrawFPSInfo(inv_ring_above);
Text_Draw();

m_InvNFrames = Output_DumpScreen();
Expand Down Expand Up @@ -1001,8 +1004,9 @@ static int32_t Inv_ConstructAndDisplay(int inv_mode)

int32_t Inv_Display(int inv_mode)
{
g_GameInfo.status = GMS_IN_INVENTORY;
GAME_STATUS current_status = g_GameInfo.status;
g_GameInfo.status |= GMS_IN_INVENTORY;
int32_t inv_result = Inv_ConstructAndDisplay(inv_mode);
g_GameInfo.status = GMS_IN_GAME;
g_GameInfo.status = current_status;
return inv_result;
}
22 changes: 22 additions & 0 deletions src/game/inventory/inventory_ring.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "game/inventory/inventory_ring.h"

#include "config.h"
#include "game/gameflow.h"
#include "game/inventory.h"
#include "game/inventory/inventory_vars.h"
Expand All @@ -11,6 +12,7 @@
#include "global/vars.h"
#include "math/math_misc.h"

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>

Expand Down Expand Up @@ -343,6 +345,26 @@ void Inv_Ring_Active(INVENTORY_ITEM *inv_item)
default:
break;
}

if (inv_item->object_number == O_MEDI_OPTION
|| inv_item->object_number == O_BIGMEDI_OPTION) {
if (g_Config.healthbar_location == BL_TOP_LEFT) {
Text_Hide(m_InvUpArrow1, true);
} else if (g_Config.healthbar_location == BL_TOP_RIGHT) {
Text_Hide(m_InvUpArrow2, true);
} else if (g_Config.healthbar_location == BL_BOTTOM_LEFT) {
Text_Hide(m_InvDownArrow1, true);
} else if (g_Config.healthbar_location == BL_BOTTOM_RIGHT) {
Text_Hide(m_InvDownArrow2, true);
}
g_GameInfo.status |= GMS_IN_INVENTORY_HEALTH;
} else {
Text_Hide(m_InvUpArrow1, false);
Text_Hide(m_InvUpArrow2, false);
Text_Hide(m_InvDownArrow1, false);
Text_Hide(m_InvDownArrow2, false);
g_GameInfo.status &= ~GMS_IN_INVENTORY_HEALTH;
}
}

void Inv_Ring_NotActive(void)
Expand Down
42 changes: 40 additions & 2 deletions src/game/overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ static void Overlay_BarGetLocation(
- m_BarOffsetY[bar_info->location];
}

if ((g_GameInfo.status & GMS_IN_INVENTORY)
&& (bar_info->location == BL_TOP_CENTER
|| bar_info->location == BL_BOTTOM_CENTER)) {
double scale_bar_to_text =
g_Config.ui.text_scale / g_Config.ui.bar_scale;
*y = screen_margin_v + m_BarOffsetY[bar_info->location]
+ scale_bar_to_text * (TEXT_HEIGHT + bar_spacing);
}

m_BarOffsetY[bar_info->location] += *height + bar_spacing;
}

Expand Down Expand Up @@ -482,11 +491,21 @@ void Overlay_DrawPickups(void)
}
}

void Overlay_DrawFPSInfo(void)
void Overlay_DrawFPSInfo(bool inv_ring_above)
{
static int32_t elapsed = 0;

if (g_Config.rendering.enable_fps_counter) {
static int32_t elapsed = 0;

const int32_t text_offset_x = 3;
const int32_t text_height = 17;
const int32_t text_inv_offset_y = 3;
double scale_fps_to_bar =
g_Config.ui.bar_scale / g_Config.ui.text_scale;
int16_t x = 21;
int16_t y = 10;

if (Clock_GetMS() - elapsed >= 1000) {
if (m_FPSText) {
char fps_buf[20];
Expand All @@ -501,6 +520,25 @@ void Overlay_DrawFPSInfo(void)
g_FPSCounter = 0;
elapsed = Clock_GetMS();
}

bool inv_health_showable = (g_GameInfo.status & GMS_IN_INVENTORY_HEALTH)
&& m_HealthBar.location == BL_TOP_LEFT;
bool game_bar_showable = !(g_GameInfo.status & GMS_IN_INVENTORY)
&& (m_HealthBar.location == BL_TOP_LEFT
|| m_AirBar.location == BL_TOP_LEFT
|| m_EnemyBar.location == BL_TOP_LEFT);

if (inv_health_showable || game_bar_showable) {
x = (x * scale_fps_to_bar) + text_offset_x;
y = text_height
+ scale_fps_to_bar * (y + m_BarOffsetY[BL_TOP_LEFT]);
} else if ((g_GameInfo.status & GMS_IN_INVENTORY) && inv_ring_above) {
y += (text_height * 2) + text_inv_offset_y;
} else {
y += text_height;
}

Text_SetPos(m_FPSText, x, y);
} else if (m_FPSText) {
Text_Remove(m_FPSText);
m_FPSText = NULL;
Expand All @@ -515,7 +553,7 @@ void Overlay_DrawGameInfo(void)
Overlay_BarDrawEnemy();
Overlay_DrawPickups();
Overlay_DrawAmmoInfo();
Overlay_DrawFPSInfo();
Overlay_DrawFPSInfo(false);

Text_Draw();
}
Expand Down
3 changes: 2 additions & 1 deletion src/game/overlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "global/types.h"

#include <stdbool.h>
#include <stdint.h>

struct BAR_INFO;
Expand All @@ -17,7 +18,7 @@ void Overlay_BarDrawEnemy(void);
void Overlay_RemoveAmmoText(void);
void Overlay_DrawAmmoInfo(void);
void Overlay_DrawPickups(void);
void Overlay_DrawFPSInfo(void);
void Overlay_DrawFPSInfo(bool inv_ring_above);
void Overlay_DrawGameInfo(void);

void Overlay_AddPickup(int16_t object_num);
Expand Down
4 changes: 2 additions & 2 deletions src/game/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ void Stats_Show(int32_t level_num)
return;
}

g_GameInfo.status = GMS_IN_STATS;
g_GameInfo.status |= GMS_IN_STATS;

char buf[100];
char time_str[100];
Expand Down Expand Up @@ -381,7 +381,7 @@ void Stats_Show(int32_t level_num)
}

Output_FadeReset();
g_GameInfo.status = GMS_IN_GAME;
g_GameInfo.status &= ~GMS_IN_STATS;
}

void Stats_ShowTotal(const char *filename)
Expand Down
7 changes: 4 additions & 3 deletions src/global/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1566,9 +1566,10 @@ typedef struct RESUME_INFO {

typedef enum GAME_STATUS {
GMS_IN_GAME = 0,
GMS_IN_INVENTORY = 1,
GMS_IN_PAUSE = 2,
GMS_IN_STATS = 3,
GMS_IN_INVENTORY = 1 << 0,
GMS_IN_PAUSE = 1 << 1,
GMS_IN_STATS = 1 << 2,
GMS_IN_INVENTORY_HEALTH = 1 << 3,
} GAME_STATUS;

typedef struct GAME_INFO {
Expand Down

0 comments on commit ffcaef5

Please sign in to comment.