unify Vanilla Doom and Boom widgets, do not hard-code HUDs anymore (#1632)

This commit is contained in:
Fabian Greffrath 2024-04-02 16:49:50 +02:00 committed by GitHub
parent 1246eccee8
commit a1c804c064
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 96 additions and 159 deletions

View File

@ -0,0 +1,30 @@
hud 0
rate topleft
monsec topleft
sttime topleft
coord topright
fps topright
hud 1
rate topleft
armor bottomleft
health bottomleft
ammo bottomleft
weapon bottomleft
keys bottomleft
monsec bottomleft
sttime bottomleft
coord topright
fps topright
hud 2
rate topleft
health topright
armor topright
ammo bottomright
weapon bottomright
keys bottomleft
monsec bottomleft
sttime bottomleft
coord topright
fps topright

View File

@ -137,72 +137,9 @@ static hu_multiline_t w_fps;
static hu_multiline_t w_rate;
#define MAX_HUDS 3
#define MAX_WIDGETS_D 5
#define MAX_WIDGETS_B 12
#define MAX_WIDGETS 16
#define W_SECRET_Y ((SCREENHEIGHT - ST_HEIGHT) / 4)
static hu_widget_t doom_widgets[MAX_HUDS][MAX_WIDGETS_D] = {
{
{&w_title, align_direct, align_bottom, 0},
{&w_message, align_direct, align_top, 0},
{&w_chat, align_direct, align_top, 0},
{&w_secret, align_center, align_direct, 0, W_SECRET_Y},
{NULL}
}, {
{&w_title, align_direct, align_bottom, 0},
{&w_message, align_direct, align_top, 0},
{&w_chat, align_direct, align_top, 0},
{&w_secret, align_center, align_direct, 0, W_SECRET_Y},
{NULL}
}, {
{&w_title, align_direct, align_bottom, 0},
{&w_message, align_direct, align_top, 0},
{&w_chat, align_direct, align_top, 0},
{&w_secret, align_center, align_direct, 0, W_SECRET_Y},
{NULL}
}
};
static hu_widget_t boom_widgets[MAX_HUDS][MAX_WIDGETS_B] = {
{
{&w_rate, align_left, align_top},
{&w_monsec, align_left, align_top},
{&w_sttime, align_left, align_top},
{&w_coord, align_right, align_top},
{&w_fps, align_right, align_top},
{NULL}
}, {
{&w_rate, align_left, align_top},
{&w_armor, align_left, align_bottom},
{&w_health, align_left, align_bottom},
{&w_ammo, align_left, align_bottom},
{&w_weapon, align_left, align_bottom},
{&w_keys, align_left, align_bottom},
{&w_monsec, align_left, align_bottom},
{&w_sttime, align_left, align_bottom},
{&w_coord, align_right, align_top},
{&w_fps, align_right, align_top},
{NULL}
}, {
{&w_rate, align_left, align_top},
{&w_health, align_right, align_top},
{&w_armor, align_right, align_top},
{&w_ammo, align_right, align_bottom},
{&w_weapon, align_right, align_bottom},
{&w_keys, align_left, align_bottom},
{&w_monsec, align_left, align_bottom},
{&w_sttime, align_left, align_bottom},
{&w_coord , align_right, align_top},
{&w_fps, align_right, align_top},
{NULL}
}
};
static hu_widget_t *doom_widget = doom_widgets[0],
*boom_widget = boom_widgets[0];
static hu_widget_t widgets[MAX_HUDS][MAX_WIDGETS];
static void HU_ParseHUD (void);
static void HU_set_centered_message (boolean);
@ -494,19 +431,19 @@ static void HU_set_centered_message(boolean init)
for (i = 0; i < MAX_HUDS; i++)
{
hu_widget_t *const d_w = doom_widgets[i];
hu_widget_t *const w = widgets[i];
for (j = 0; d_w[j].multiline; j++)
for (j = 0; w[j].multiline; j++)
{
if (d_w[j].multiline == &w_message)
if (w[j].multiline == &w_message)
{
// [FG] save original alignment
if (init)
{
d_w[j].h_align_orig = d_w[j].h_align;
w[j].h_align_orig = w[j].h_align;
}
d_w[j].h_align = message_centered ? align_center : d_w[j].h_align_orig;
w[j].h_align = message_centered ? align_center : w[j].h_align_orig;
}
}
}
@ -525,7 +462,7 @@ static boolean hud_pending;
void HU_disable_all_widgets (void)
{
hu_widget_t *w = boom_widget;
hu_widget_t *w = widgets[hud_active];
while (w->multiline)
{
@ -1486,17 +1423,16 @@ int hud_time_use;
//
void HU_Drawer(void)
{
hu_widget_t *w;
hu_widget_t *w = widgets[hud_active];
if (hud_pending)
return;
HUlib_reset_align_offsets();
w = doom_widget;
while (w->multiline)
{
if (*w->multiline->on)
if ((w->multiline->on && *w->multiline->on) || w->multiline->built)
{
HUlib_draw_widget(w);
}
@ -1507,16 +1443,6 @@ void HU_Drawer(void)
{
ST_Drawer (false, true);
}
w = boom_widget;
while (w->multiline)
{
if (w->multiline->built)
{
HUlib_draw_widget(w);
}
w++;
}
}
// [FG] draw Time widget on intermission screen
@ -1543,27 +1469,16 @@ void WI_DrawTimeWidget(void)
void HU_Erase(void)
{
hu_widget_t *w;
hu_widget_t *w = widgets[hud_active];
if (automapactive || !scaledviewx)
return;
HUlib_reset_align_offsets();
w = doom_widget;
while (w->multiline)
{
if (*w->multiline->on)
{
HUlib_erase_widget(w);
}
w++;
}
w = boom_widget;
while (w->multiline)
{
if (w->multiline->built)
if ((w->multiline->on && *w->multiline->on) || w->multiline->built)
{
HUlib_erase_widget(w);
}
@ -1584,8 +1499,6 @@ static int bscounter;
void HU_Ticker(void)
{
doom_widget = doom_widgets[hud_active];
boom_widget = boom_widgets[hud_active];
plr = &players[displayplayer]; // killough 3/7/98
HU_disable_all_widgets();
@ -1952,22 +1865,17 @@ boolean HU_Responder(event_t *ev)
// [FG] dynamic HUD alignment
typedef struct {
static const struct {
const char *name, *altname;
hu_multiline_t *const multiline;
} multiline_names_t;
static const multiline_names_t
doom_names[] = {
} multiline_names[] = {
{"title", NULL, &w_title},
{"message", NULL, &w_message},
// [FG] TODO due to its variable width and the trailing cursor,
// the w_chat widget *must* currently remain left-aligned
// {"chat", NULL, &w_chat},
{"secret", NULL, &w_secret},
{NULL},
},
boom_names[] = {
{"ammo", NULL, &w_ammo},
{"armor", NULL, &w_armor},
{"health", NULL, &w_health},
@ -1982,7 +1890,7 @@ static const multiline_names_t
{NULL},
};
static boolean HU_ReplaceInDoomWidgets (hu_multiline_t *multiline, int hud, align_t h_align, align_t v_align, int x, int y)
static boolean HU_ReplaceInWidgets (hu_multiline_t *multiline, int hud, align_t h_align, align_t v_align, int x, int y)
{
int i;
@ -1991,14 +1899,19 @@ static boolean HU_ReplaceInDoomWidgets (hu_multiline_t *multiline, int hud, alig
return false;
}
for (i = 0; i < MAX_WIDGETS_D - 1; i++)
for (i = 0; i < MAX_WIDGETS - 1; i++)
{
if (doom_widgets[hud][i].multiline == multiline)
if (widgets[hud][i].multiline == NULL)
{
doom_widgets[hud][i].h_align = h_align;
doom_widgets[hud][i].v_align = v_align;
doom_widgets[hud][i].x = x;
doom_widgets[hud][i].y = y;
break;
}
if (widgets[hud][i].multiline == multiline)
{
widgets[hud][i].h_align = h_align;
widgets[hud][i].v_align = v_align;
widgets[hud][i].x = x;
widgets[hud][i].y = y;
return true;
}
@ -2007,7 +1920,7 @@ static boolean HU_ReplaceInDoomWidgets (hu_multiline_t *multiline, int hud, alig
return false;
}
static boolean HU_AddToBoomWidgets (hu_multiline_t *multiline, int hud, align_t h_align, align_t v_align, int x, int y)
static boolean HU_AppendToWidgets (hu_multiline_t *multiline, int hud, align_t h_align, align_t v_align, int x, int y)
{
int i;
@ -2016,54 +1929,54 @@ static boolean HU_AddToBoomWidgets (hu_multiline_t *multiline, int hud, align_t
return false;
}
for (i = 0; i < MAX_WIDGETS_B - 1; i++)
for (i = 0; i < MAX_WIDGETS - 1; i++)
{
if (boom_widgets[hud][i].multiline == NULL)
if (widgets[hud][i].multiline == NULL)
{
break;
}
}
if (i + 1 >= MAX_WIDGETS_B)
if (i + 1 >= MAX_WIDGETS)
{
return false;
}
boom_widgets[hud][i].multiline = multiline;
boom_widgets[hud][i].h_align = h_align;
boom_widgets[hud][i].v_align = v_align;
boom_widgets[hud][i].x = x;
boom_widgets[hud][i].y = y;
widgets[hud][i].multiline = multiline;
widgets[hud][i].h_align = h_align;
widgets[hud][i].v_align = v_align;
widgets[hud][i].x = x;
widgets[hud][i].y = y;
boom_widgets[hud][i + 1].multiline = NULL;
widgets[hud][i + 1].multiline = NULL;
return true;
}
static boolean HU_AddToWidgets (hu_multiline_t *multiline, const multiline_names_t *names, int hud, align_t h_align, align_t v_align, int x, int y)
static boolean HU_AddToWidgets (hu_multiline_t *multiline, int hud, align_t h_align, align_t v_align, int x, int y)
{
if (names == doom_names)
if (HU_ReplaceInWidgets(multiline, hud, h_align, v_align, x, y))
{
return HU_ReplaceInDoomWidgets(multiline, hud, h_align, v_align, x, y);
return true;
}
else if (names == boom_names)
else if (HU_AppendToWidgets(multiline, hud, h_align, v_align, x, y))
{
return HU_AddToBoomWidgets(multiline, hud, h_align, v_align, x, y);
return true;
}
return false;
}
static hu_multiline_t *HU_MultilineByName (const char *name, const multiline_names_t *names)
static hu_multiline_t *HU_MultilineByName (const char *name)
{
int i;
for (i = 0; names[i].name; i++)
for (i = 0; multiline_names[i].name; i++)
{
if (strcasecmp(name, names[i].name) == 0 ||
(names[i].altname && strcasecmp(name, names[i].altname) == 0))
if (strcasecmp(name, multiline_names[i].name) == 0 ||
(multiline_names[i].altname && strcasecmp(name, multiline_names[i].altname) == 0))
{
return names[i].multiline;
return multiline_names[i].multiline;
}
}
@ -2072,14 +1985,7 @@ static hu_multiline_t *HU_MultilineByName (const char *name, const multiline_nam
static boolean HU_AddHUDCoords (char *name, int hud, int x, int y)
{
const multiline_names_t *names = doom_names;
hu_multiline_t *multiline = HU_MultilineByName(name, names);
if (multiline == NULL)
{
names = boom_names;
multiline = HU_MultilineByName(name, names);
}
hu_multiline_t *multiline = HU_MultilineByName(name);
if (multiline == NULL)
{
@ -2101,19 +2007,12 @@ static boolean HU_AddHUDCoords (char *name, int hud, int x, int y)
return false;
}
return HU_AddToWidgets(multiline, names, hud, align_direct, align_direct, x, y);
return HU_AddToWidgets(multiline, hud, align_direct, align_direct, x, y);
}
static boolean HU_AddHUDAlignment (char *name, int hud, char *alignstr)
{
const multiline_names_t *names = doom_names;
hu_multiline_t *multiline = HU_MultilineByName(name, names);
if (multiline == NULL)
{
names = boom_names;
multiline = HU_MultilineByName(name, names);
}
hu_multiline_t *multiline = HU_MultilineByName(name);
if (multiline == NULL)
{
@ -2122,27 +2021,27 @@ static boolean HU_AddHUDAlignment (char *name, int hud, char *alignstr)
if (!strcasecmp(alignstr, "topleft") || !strcasecmp(alignstr, "upperleft"))
{
return HU_AddToWidgets(multiline, names, hud, align_left, align_top, 0, 0);
return HU_AddToWidgets(multiline, hud, align_left, align_top, 0, 0);
}
else if (!strcasecmp(alignstr, "topright") || !strcasecmp(alignstr, "upperright"))
{
return HU_AddToWidgets(multiline, names, hud, align_right, align_top, 0, 0);
return HU_AddToWidgets(multiline, hud, align_right, align_top, 0, 0);
}
else if (!strcasecmp(alignstr, "topcenter") || !strcasecmp(alignstr, "uppercenter"))
{
return HU_AddToWidgets(multiline, names, hud, align_center, align_top, 0, 0);
return HU_AddToWidgets(multiline, hud, align_center, align_top, 0, 0);
}
else if (!strcasecmp(alignstr, "bottomleft") || !strcasecmp(alignstr, "lowerleft"))
{
return HU_AddToWidgets(multiline, names, hud, align_left, align_bottom, 0, 0);
return HU_AddToWidgets(multiline, hud, align_left, align_bottom, 0, 0);
}
else if (!strcasecmp(alignstr, "bottomright") || !strcasecmp(alignstr, "lowerright"))
{
return HU_AddToWidgets(multiline, names, hud, align_right, align_bottom, 0, 0);
return HU_AddToWidgets(multiline, hud, align_right, align_bottom, 0, 0);
}
else if (!strcasecmp(alignstr, "bottomcenter")|| !strcasecmp(alignstr, "lowercenter"))
{
return HU_AddToWidgets(multiline, names, hud, align_center, align_bottom, 0, 0);
return HU_AddToWidgets(multiline, hud, align_center, align_bottom, 0, 0);
}
return false;
@ -2151,11 +2050,20 @@ static boolean HU_AddHUDAlignment (char *name, int hud, char *alignstr)
static void HU_ParseHUD (void)
{
u_scanner_t *s;
int hud = -1;
int hud;
int lumpnum;
const char *data;
int length;
// [FG] initialize HUDs with Vanilla Doom widgets
for (hud = 0; hud < MAX_HUDS; hud++)
{
HU_AddToWidgets(&w_title, hud, align_direct, align_bottom, 0, 0);
HU_AddToWidgets(&w_message, hud, align_direct, align_top, 0, 0);
HU_AddToWidgets(&w_chat, hud, align_direct, align_top, 0, 0);
HU_AddToWidgets(&w_secret , hud, align_center, align_direct, 0, (SCREENHEIGHT - ST_HEIGHT) / 4);
}
if ((lumpnum = W_CheckNumForName("WOOFHUD")) == -1)
{
return;
@ -2186,7 +2094,6 @@ static void HU_ParseHUD (void)
U_Error(s, "HUD (%d) must be between 0 and %d", hud, MAX_HUDS - 1);
}
memset(boom_widgets[hud], 0, sizeof(boom_widgets[hud]));
continue;
}