restore Doom font option (#1992)

* move "Level Stats Format" under "Widget Appearance"

* set font during parsing

* always load hu_font
This commit is contained in:
Roman Fomin 2024-11-08 14:07:19 +07:00 committed by GitHub
parent f66ca8d62e
commit 80bc8d49c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 126 additions and 88 deletions

View File

@ -174,7 +174,7 @@ const char *JS_GetString(json_t *json)
return json->valuestring;
}
const char *JS_GetStringRef(json_t *json, const char *string)
const char *JS_GetStringValue(json_t *json, const char *string)
{
json_t *obj = JS_GetObject(json, string);
if (JS_IsString(obj))
@ -183,13 +183,3 @@ const char *JS_GetStringRef(json_t *json, const char *string)
}
return NULL;
}
const char *JS_GetStringCopy(json_t *json, const char *string)
{
json_t *obj = JS_GetObject(json, string);
if (JS_IsString(obj))
{
return M_StringDuplicate(obj->valuestring);
}
return NULL;
}

View File

@ -44,8 +44,7 @@ double JS_GetNumber(json_t *json);
double JS_GetNumberValue(json_t *json, const char *string);
int JS_GetInteger(json_t *json);
const char *JS_GetString(json_t *json);
const char *JS_GetStringRef(json_t *json, const char *string);
const char *JS_GetStringCopy(json_t *json, const char *string);
const char *JS_GetStringValue(json_t *json, const char *string);
int JS_GetArraySize(json_t *json);
json_t *JS_GetArrayItem(json_t *json, int index);

View File

@ -1878,6 +1878,13 @@ static setup_menu_t stat_settings2[] = {
{"Use-Button Timer", S_ONOFF, H_X, M_SPC, {"hud_time_use"}},
MI_GAP,
{"Widget Appearance", S_SKIP | S_TITLE, H_X, M_SPC},
{"Use Doom Font", S_CHOICE, H_X, M_SPC, {"hud_widget_font"},
.strings_id = str_show_widgets},
{"Level Stats Format", S_CHOICE, H_X, M_SPC, {"hud_stats_format"},
.strings_id = str_stats_format},

View File

@ -28,6 +28,9 @@
#include "w_wad.h"
#include "z_zone.h"
static numberfont_t *numberfonts;
static hudfont_t *hudfonts;
static boolean ParseSbarCondition(json_t *json, sbarcondition_t *out)
{
json_t *condition = JS_GetObject(json, "condition");
@ -78,13 +81,13 @@ static boolean ParseSbarElemType(json_t *json, sbarelementtype_t type,
out->y_pos = JS_GetInteger(y_pos);
out->alignment = JS_GetInteger(alignment);
const char *tranmap = JS_GetStringRef(json, "tranmap");
const char *tranmap = JS_GetStringValue(json, "tranmap");
if (tranmap)
{
out->tranmap = W_CacheLumpName(tranmap, PU_STATIC);
}
const char *translation = JS_GetStringRef(json, "translation");
const char *translation = JS_GetStringValue(json, "translation");
out->cr = translation ? V_CRByName(translation) : CR_NONE;
out->crboom = CR_NONE;
@ -146,13 +149,20 @@ static boolean ParseSbarElemType(json_t *json, sbarelementtype_t type,
case sbe_percent:
{
sbe_number_t *number = calloc(1, sizeof(*number));
json_t *font = JS_GetObject(json, "font");
if (!JS_IsString(font))
const char *font_name = JS_GetStringValue(json, "font");
if (!font_name)
{
return false;
}
number->font_name = M_StringDuplicate(JS_GetString(font));
numberfont_t *font;
array_foreach(font, numberfonts)
{
if (!strcmp(font->name, font_name))
{
number->font = font;
break;
}
}
json_t *type = JS_GetObject(json, "type");
json_t *param = JS_GetObject(json, "param");
json_t *maxlength = JS_GetObject(json, "maxlength");
@ -171,14 +181,20 @@ static boolean ParseSbarElemType(json_t *json, sbarelementtype_t type,
case sbe_widget:
{
sbe_widget_t *widget = calloc(1, sizeof(*widget));
json_t *font = JS_GetObject(json, "font");
if (!JS_IsString(font))
const char *font_name = JS_GetStringValue(json, "font");
if (!font_name)
{
return false;
}
widget->font_name = M_StringDuplicate(JS_GetString(font));
hudfont_t *font;
array_foreach(font, hudfonts)
{
if (!strcmp(font->name, font_name))
{
widget->default_font = widget->font = font;
break;
}
}
json_t *type = JS_GetObject(json, "type");
if (!JS_IsNumber(type))
{
@ -249,7 +265,7 @@ static boolean ParseNumberFont(json_t *json, numberfont_t *out)
}
out->name = M_StringDuplicate(JS_GetString(name));
const char *stem = JS_GetStringRef(json, "stem");
const char *stem = JS_GetStringValue(json, "stem");
if (!stem)
{
return false;
@ -314,28 +330,8 @@ static boolean ParseNumberFont(json_t *json, numberfont_t *out)
return true;
}
static boolean ParseHUDFont(json_t *json, hudfont_t *out)
static void LoadHUDFont(hudfont_t *out)
{
json_t *name = JS_GetObject(json, "name");
if (!JS_IsString(name))
{
return false;
}
out->name = M_StringDuplicate(JS_GetString(name));
const char *stem = JS_GetStringRef(json, "stem");
if (!stem)
{
return false;
}
json_t *type = JS_GetObject(json, "type");
if (!JS_IsNumber(type))
{
return false;
}
out->type = JS_GetInteger(type);
char lump[9] = {0};
int found;
int maxwidth = 0;
@ -343,7 +339,7 @@ static boolean ParseHUDFont(json_t *json, hudfont_t *out)
for (int i = 0; i < HU_FONTSIZE; ++i)
{
M_snprintf(lump, sizeof(lump), "%s%03d", stem, i + HU_FONTSTART);
M_snprintf(lump, sizeof(lump), "%s%03d", out->stem, i + HU_FONTSTART);
found = W_CheckNumForName(lump);
if (found < 0)
{
@ -368,10 +364,53 @@ static boolean ParseHUDFont(json_t *json, hudfont_t *out)
default:
break;
}
}
static boolean ParseHUDFont(json_t *json, hudfont_t *out)
{
json_t *name = JS_GetObject(json, "name");
if (!JS_IsString(name))
{
return false;
}
out->name = M_StringDuplicate(JS_GetString(name));
const char *stem = JS_GetStringValue(json, "stem");
if (!stem)
{
return false;
}
out->stem = M_StringDuplicate(stem);
json_t *type = JS_GetObject(json, "type");
if (!JS_IsNumber(type))
{
return false;
}
out->type = JS_GetInteger(type);
LoadHUDFont(out);
return true;
}
hudfont_t *LoadSTCFN(void)
{
hudfont_t *font;
array_foreach(font, hudfonts)
{
if (!strcasecmp(font->stem, "STCFN"))
{
return font;
}
}
font = calloc(1, sizeof(*font));
font->stem = "STCFN";
font->type = sbf_proportional;
LoadHUDFont(font);
return font;
}
static boolean ParseStatusBar(json_t *json, statusbar_t *out)
{
json_t *height = JS_GetObject(json, "height");
@ -383,7 +422,8 @@ static boolean ParseStatusBar(json_t *json, statusbar_t *out)
out->height = JS_GetInteger(height);
out->fullscreenrender = JS_GetBoolean(fullscreenrender);
out->fillflat = JS_GetStringCopy(json, "fillflat");
const char *fillflat = JS_GetStringValue(json, "fillflat");
out->fillflat = fillflat ? M_StringDuplicate(fillflat) : NULL;
json_t *js_children = JS_GetObject(json, "children");
json_t *js_child = NULL;
@ -433,7 +473,7 @@ sbardef_t *ST_ParseSbarDef(void)
numberfont_t numberfont = {0};
if (ParseNumberFont(js_numberfont, &numberfont))
{
array_push(out->numberfonts, numberfont);
array_push(numberfonts, numberfont);
}
}
@ -445,7 +485,7 @@ sbardef_t *ST_ParseSbarDef(void)
hudfont_t hudfont = {0};
if (ParseHUDFont(js_hudfont, &hudfont))
{
array_push(out->hudfonts, hudfont);
array_push(hudfonts, hudfont);
}
}
@ -484,7 +524,7 @@ sbardef_t *ST_ParseSbarDef(void)
hudfont_t hudfont = {0};
if (ParseHUDFont(js_hudfont, &hudfont))
{
array_push(out->hudfonts, hudfont);
array_push(hudfonts, hudfont);
}
}

View File

@ -164,7 +164,6 @@ typedef struct
typedef struct
{
const char *font_name;
numberfont_t *font;
sbarnumbertype_t type;
int param;
@ -192,7 +191,7 @@ typedef struct
typedef struct sbe_widget_s
{
sbarwidgettype_t type;
const char *font_name;
hudfont_t *default_font;
hudfont_t *font;
widgetline_t *lines;
@ -254,6 +253,7 @@ struct numberfont_s
struct hudfont_s
{
const char *name;
const char *stem;
fonttype_t type;
int monowidth;
int maxheight;
@ -262,11 +262,11 @@ struct hudfont_s
typedef struct
{
numberfont_t *numberfonts;
hudfont_t *hudfonts;
statusbar_t *statusbars;
} sbardef_t;
sbardef_t *ST_ParseSbarDef(void);
hudfont_t *LoadSTCFN(void);
#endif

View File

@ -716,6 +716,7 @@ static void UpdateFace(sbe_face_t *face, player_t *player)
static void UpdateNumber(sbarelem_t *elem, player_t *player)
{
sbe_number_t *number = elem->subtype.number;
numberfont_t *font = number->font;
int value = ResolveNumber(number, player);
int power = (value < 0 ? number->maxlength - 1 : number->maxlength);
@ -723,18 +724,6 @@ static void UpdateNumber(sbarelem_t *elem, player_t *player)
int valglyphs = 0;
int numvalues = 0;
numberfont_t *font = number->font;
if (font == NULL)
{
array_foreach(font, sbardef->numberfonts)
{
if (!strcmp(font->name, number->font_name))
{
break;
}
}
}
if (value < 0 && font->minus != NULL)
{
value = MAX(-max, value);
@ -791,18 +780,7 @@ static void UpdateNumber(sbarelem_t *elem, player_t *player)
static void UpdateLines(sbarelem_t *elem)
{
sbe_widget_t *widget = elem->subtype.widget;
hudfont_t *font = widget->font;
if (font == NULL)
{
array_foreach(font, sbardef->hudfonts)
{
if (!strcmp(font->name, widget->font_name))
{
break;
}
}
}
widgetline_t *line;
array_foreach(line, widget->lines)
@ -1731,6 +1709,7 @@ void ST_Start(void)
HU_StartCrosshair();
}
hudfont_t *stcfnt;
patch_t **hu_font = NULL;
void ST_Init(void)
@ -1744,19 +1723,12 @@ void ST_Init(void)
LoadFacePatches();
hudfont_t *hudfont;
array_foreach(hudfont, sbardef->hudfonts)
{
if (!strcmp(hudfont->name, "Console"))
{
hu_font = hudfont->characters;
break;
}
}
stcfnt = LoadSTCFN();
hu_font = stcfnt->characters;
if (!hu_font)
{
I_Error("ST_Init: \"Console\" font not found");
I_Error("ST_Init: \"STCFN\" font not found");
}
HU_InitCrosshair();

View File

@ -69,6 +69,7 @@ extern int health_green; // health amount above is blue, below is green
extern boolean palette_changes;
extern struct hudfont_s *stcfnt;
extern struct patch_s **hu_font;
void WI_DrawWidgets(void);

View File

@ -38,6 +38,7 @@
#include "s_sound.h"
#include "sounds.h"
#include "st_sbardef.h"
#include "st_stuff.h"
#include "i_timer.h"
#include "v_video.h"
#include "u_mapinfo.h"
@ -51,6 +52,7 @@ widgetstate_t hud_level_stats;
widgetstate_t hud_level_time;
boolean hud_time_use;
widgetstate_t hud_player_coords;
widgetstate_t hud_widget_font;
static boolean hud_map_announce;
static boolean message_colorized;
@ -645,6 +647,18 @@ static boolean WidgetEnabled(widgetstate_t state)
return true;
}
static void ForceDoomFont(sbe_widget_t *widget)
{
if (WidgetEnabled(hud_widget_font))
{
widget->font = stcfnt;
}
else
{
widget->font = widget->default_font;
}
}
static void UpdateCoord(sbe_widget_t *widget, player_t *player)
{
if (hud_player_coords == HUD_WIDGET_ADVANCED)
@ -660,6 +674,8 @@ static void UpdateCoord(sbe_widget_t *widget, player_t *player)
return;
}
ForceDoomFont(widget);
fixed_t x, y, z; // killough 10/98:
void AM_Coordinates(const mobj_t *, fixed_t *, fixed_t *, fixed_t *);
@ -735,6 +751,8 @@ static void UpdateMonSec(sbe_widget_t *widget)
return;
}
ForceDoomFont(widget);
static char string[120];
int fullkillcount = 0;
@ -792,6 +810,8 @@ static void UpdateStTime(sbe_widget_t *widget, player_t *player)
return;
}
ForceDoomFont(widget);
static char string[80];
int offset = 0;
@ -835,6 +855,8 @@ static void UpdateFPS(sbe_widget_t *widget, player_t *player)
return;
}
ForceDoomFont(widget);
static char string[20];
M_snprintf(string, sizeof(string), GRAY_S "%d " GREEN_S "FPS", fps);
ST_AddLine(widget, string);
@ -876,6 +898,8 @@ static void UpdateSpeed(sbe_widget_t *widget, player_t *player)
return;
}
ForceDoomFont(widget);
static const double factor[] = {TICRATE, 2.4003, 525.0 / 352.0};
static const char *units[] = {"ups", "km/h", "mph"};
const int type = speedometer - 1;
@ -1078,6 +1102,11 @@ void ST_BindHUDVariables(void)
"Hide empty commands from command history widget");
M_BindBool("hud_time_use", &hud_time_use, NULL, false, ss_stat, wad_no,
"Show split time when pressing the use-button");
M_BindNum("hud_widget_font", &hud_widget_font, NULL,
HUD_WIDGET_OFF, HUD_WIDGET_OFF, HUD_WIDGET_ALWAYS,
ss_stat, wad_no,
"Use standard Doom font for widgets (1 = On automap; 2 = On HUD; 3 "
"= Always)");
M_BindNum("hudcolor_titl", &hudcolor_titl, NULL,
CR_GOLD, CR_BRICK, CR_NONE, ss_none, wad_yes,