Skip to content

Commit

Permalink
fix bar placement
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Feb 22, 2021
1 parent 4071641 commit 7a501bf
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 31 deletions.
22 changes: 11 additions & 11 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ static int8_t ReadBarLocationConfig(
if (!value_str) {
return default_value;
} else if (!strcmp(value_str, "top-left")) {
return T1M_BL_VTOP | T1M_BL_HLEFT;
return T1M_BL_TOP_LEFT;
} else if (!strcmp(value_str, "top-center")) {
return T1M_BL_VTOP | T1M_BL_HCENTER;
return T1M_BL_TOP_CENTER;
} else if (!strcmp(value_str, "top-right")) {
return T1M_BL_VTOP | T1M_BL_HRIGHT;
return T1M_BL_TOP_RIGHT;
} else if (!strcmp(value_str, "bottom-left")) {
return T1M_BL_VBOTTOM | T1M_BL_HLEFT;
return T1M_BL_BOTTOM_LEFT;
} else if (!strcmp(value_str, "bottom-center")) {
return T1M_BL_VBOTTOM | T1M_BL_HCENTER;
return T1M_BL_BOTTOM_CENTER;
} else if (!strcmp(value_str, "bottom-right")) {
return T1M_BL_VBOTTOM | T1M_BL_HRIGHT;
return T1M_BL_BOTTOM_RIGHT;
}
return default_value;
}
Expand Down Expand Up @@ -87,12 +87,12 @@ int T1MReadConfig()
T1MConfig.healthbar_showing_mode =
ReadBarShowingMode(json, "healthbar_showing_mode");

T1MConfig.healthbar_location = ReadBarLocationConfig(
json, "healthbar_location", T1M_BL_VTOP | T1M_BL_HLEFT);
T1MConfig.airbar_location = ReadBarLocationConfig(
json, "airbar_location", T1M_BL_VTOP | T1M_BL_HRIGHT);
T1MConfig.healthbar_location =
ReadBarLocationConfig(json, "healthbar_location", T1M_BL_TOP_LEFT);
T1MConfig.airbar_location =
ReadBarLocationConfig(json, "airbar_location", T1M_BL_TOP_RIGHT);
T1MConfig.enemy_healthbar_location = ReadBarLocationConfig(
json, "enemy_healthbar_location", T1M_BL_VBOTTOM | T1M_BL_HLEFT);
json, "enemy_healthbar_location", T1M_BL_BOTTOM_LEFT);

free(json);
free(cfg_data);
Expand Down
11 changes: 6 additions & 5 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
#include <stdint.h>

typedef enum {
T1M_BL_HCENTER = 1 << 0,
T1M_BL_HLEFT = 1 << 1,
T1M_BL_HRIGHT = 1 << 2,
T1M_BL_VTOP = 1 << 3,
T1M_BL_VBOTTOM = 1 << 4,
T1M_BL_TOP_LEFT = 0,
T1M_BL_TOP_CENTER = 1,
T1M_BL_TOP_RIGHT = 2,
T1M_BL_BOTTOM_LEFT = 3,
T1M_BL_BOTTOM_CENTER = 4,
T1M_BL_BOTTOM_RIGHT = 5,
} T1M_BAR_LOCATION;

typedef enum {
Expand Down
6 changes: 6 additions & 0 deletions src/game/health.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

void DrawGameInfo()
{
#ifdef T1M_FEAT_UI
for (int i = 0; i < 6; i++) {
BarOffsetY[i] = 0;
}
#endif

DrawAmmoInfo();
if (OverlayFlag > 0) {
DrawHealthBar();
Expand Down
4 changes: 4 additions & 0 deletions src/game/vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
#ifdef T1M_FEAT_GAMEPLAY
int16_t StoredLaraHealth = 0;
#endif

#ifdef T1M_FEAT_UI
int16_t BarOffsetY[6];
#endif
4 changes: 4 additions & 0 deletions src/game/vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,8 @@ extern int32_t FloorDataSize;
extern int16_t StoredLaraHealth;
#endif

#ifdef T1M_FEAT_UI
extern int16_t BarOffsetY[6];
#endif

#endif
24 changes: 9 additions & 15 deletions src/specific/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ static int color_bar[][COLOR_BAR_SIZE] = {
{ 18, 17, 18, 19, 21 },
};

#ifdef T1M_FEAT_UI
static int BarOffsetY = 0;
#endif

#ifdef T1M_FEAT_UI
int MulDiv(int x, int y, int z)
{
Expand Down Expand Up @@ -63,25 +59,24 @@ void BarLocation(
int8_t bar_location, int32_t scale, int32_t width, int32_t height,
int32_t* x, int32_t* y)
{
if (bar_location & T1M_BL_HCENTER) {
*x = (PhdWinWidth - width) / 2;
} else if (bar_location & T1M_BL_HLEFT) {
if (bar_location == T1M_BL_TOP_LEFT || bar_location == T1M_BL_BOTTOM_LEFT) {
*x = 8 * scale;
} else if (bar_location & T1M_BL_HRIGHT) {
} else if (
bar_location == T1M_BL_TOP_RIGHT
|| bar_location == T1M_BL_BOTTOM_RIGHT) {
*x = PhdWinWidth - width - 8 * scale;
} else {
*x = (PhdWinWidth - width) / 2;
}

if (bar_location & T1M_BL_VTOP) {
*y = 8 * scale + BarOffsetY;
} else if (bar_location & T1M_BL_VBOTTOM) {
*y = PhdWinHeight - height - 8 * scale - BarOffsetY;
if (bar_location == T1M_BL_TOP_LEFT || bar_location == T1M_BL_TOP_CENTER
|| bar_location == T1M_BL_TOP_RIGHT) {
*y = 8 * scale + BarOffsetY[bar_location];
} else {
*y = (PhdWinHeight - height) / 2 + BarOffsetY;
*y = PhdWinHeight - height - 8 * scale - BarOffsetY[bar_location];
}

BarOffsetY += height + 4 * scale;
BarOffsetY[bar_location] += height + 4 * scale;
}
#endif

Expand Down Expand Up @@ -119,7 +114,6 @@ void RenderBar(int value, int value_max, int bar_type)
int x;
int y;
if (bar_type == BT_LARA_HEALTH) {
BarOffsetY = 0;
BarLocation(T1MConfig.healthbar_location, scale, width, height, &x, &y);
} else if (bar_type == BT_LARA_AIR) {
BarLocation(T1MConfig.airbar_location, scale, width, height, &x, &y);
Expand Down

0 comments on commit 7a501bf

Please sign in to comment.