mirror of
https://github.com/fabiangreffrath/woof.git
synced 2025-09-20 18:37:48 -04:00
Level-stats format settings (#1967)
* Level-stats format settings * Various changes - Use formatting function updated in `HU_Start()` - Removed automap format setting - Disable menu item when widget is disabled - Moved and renamed menu item * More changes - Hardcoded parameters into formatting functions - Made menu item call `HU_Start()` - Renamed "Percentage" to "Percent" - Fixed Clang-Tidy warning * Simplify formatting functions (Fabian's patch) Co-Authored-By: Fabian Greffrath <fabian@greffrath.com>
This commit is contained in:
parent
7e9a70c2eb
commit
65d6a2edd3
@ -523,6 +523,55 @@ static void HU_widget_build_speed(void);
|
||||
|
||||
static hu_multiline_t *w_stats;
|
||||
|
||||
typedef enum {
|
||||
STATSFORMAT_RATIO,
|
||||
STATSFORMAT_BOOLEAN,
|
||||
STATSFORMAT_PERCENT,
|
||||
STATSFORMAT_REMAINING,
|
||||
STATSFORMAT_COUNT,
|
||||
|
||||
NUM_STATSFORMATS
|
||||
} statsformat_t;
|
||||
|
||||
static statsformat_t hud_stats_format;
|
||||
|
||||
static void StatsFormatFunc_Ratio(char *buffer, size_t size, const int count, const int total)
|
||||
{
|
||||
M_snprintf(buffer, size, "%d/%d", count, total);
|
||||
}
|
||||
|
||||
static void StatsFormatFunc_Boolean(char *buffer, size_t size, const int count, const int total)
|
||||
{
|
||||
M_snprintf(buffer, size, "%s", (count >= total) ? "YES" : "NO");
|
||||
}
|
||||
|
||||
static void StatsFormatFunc_Percent(char *buffer, size_t size, const int count, const int total)
|
||||
{
|
||||
M_snprintf(buffer, size, "%d%%", !total ? 100 : count * 100 / total);
|
||||
}
|
||||
|
||||
static void StatsFormatFunc_Remaining(char *buffer, size_t size, const int count, const int total)
|
||||
{
|
||||
M_snprintf(buffer, size, "%d", total - count);
|
||||
}
|
||||
|
||||
static void StatsFormatFunc_Count(char *buffer, size_t size, const int count, const int total)
|
||||
{
|
||||
M_snprintf(buffer, size, "%d", count);
|
||||
}
|
||||
|
||||
typedef void (*StatsFormatFunc_t)(char *buffer, size_t size, const int count, const int total);
|
||||
|
||||
static const StatsFormatFunc_t StatsFormatFuncs[NUM_STATSFORMATS] = {
|
||||
StatsFormatFunc_Ratio,
|
||||
StatsFormatFunc_Boolean,
|
||||
StatsFormatFunc_Percent,
|
||||
StatsFormatFunc_Remaining,
|
||||
StatsFormatFunc_Count,
|
||||
};
|
||||
|
||||
static StatsFormatFunc_t StatsFormatFunc;
|
||||
|
||||
void HU_Start(void)
|
||||
{
|
||||
int i;
|
||||
@ -609,6 +658,8 @@ void HU_Start(void)
|
||||
// [FG] in deathmatch: w_keys.builder = HU_widget_build_frag()
|
||||
w_stats = deathmatch ? &w_keys : &w_monsec;
|
||||
|
||||
StatsFormatFunc = StatsFormatFuncs[hud_stats_format];
|
||||
|
||||
HUlib_init_multiline(&w_sttime, 1,
|
||||
&boom_font, colrngs[CR_GRAY],
|
||||
NULL, HU_widget_build_sttime);
|
||||
@ -1233,27 +1284,33 @@ static void HU_widget_build_monsec(void)
|
||||
secretcolor = (fullsecretcount >= totalsecret) ? '0'+CR_BLUE : '0'+CR_GRAY;
|
||||
itemcolor = (fullitemcount >= totalitems) ? '0'+CR_BLUE : '0'+CR_GRAY;
|
||||
|
||||
char kill_str[16], item_str[16], secret_str[16];
|
||||
|
||||
StatsFormatFunc(kill_str, sizeof(kill_str), fullkillcount, max_kill_requirement);
|
||||
StatsFormatFunc(item_str, sizeof(item_str), fullitemcount, totalitems);
|
||||
StatsFormatFunc(secret_str, sizeof(secret_str), fullsecretcount, totalsecret);
|
||||
|
||||
if (hud_widget_layout)
|
||||
{
|
||||
M_snprintf(hud_stringbuffer, sizeof(hud_stringbuffer),
|
||||
"\x1b%cK\t\x1b%c%d/%d", ('0'+CR_RED), killcolor, fullkillcount, max_kill_requirement);
|
||||
"\x1b%cK\t\x1b%c%s", ('0'+CR_RED), killcolor, kill_str);
|
||||
HUlib_add_string_to_cur_line(&w_monsec, hud_stringbuffer);
|
||||
|
||||
M_snprintf(hud_stringbuffer, sizeof(hud_stringbuffer),
|
||||
"\x1b%cI\t\x1b%c%d/%d", ('0'+CR_RED), itemcolor, fullitemcount, totalitems);
|
||||
"\x1b%cI\t\x1b%c%s", ('0'+CR_RED), itemcolor, item_str);
|
||||
HUlib_add_string_to_cur_line(&w_monsec, hud_stringbuffer);
|
||||
|
||||
M_snprintf(hud_stringbuffer, sizeof(hud_stringbuffer),
|
||||
"\x1b%cS\t\x1b%c%d/%d", ('0'+CR_RED), secretcolor, fullsecretcount, totalsecret);
|
||||
"\x1b%cS\t\x1b%c%s", ('0'+CR_RED), secretcolor, secret_str);
|
||||
HUlib_add_string_to_cur_line(&w_monsec, hud_stringbuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
M_snprintf(hud_stringbuffer, sizeof(hud_stringbuffer),
|
||||
"\x1b%cK \x1b%c%d/%d \x1b%cI \x1b%c%d/%d \x1b%cS \x1b%c%d/%d",
|
||||
'0'+CR_RED, killcolor, fullkillcount, max_kill_requirement,
|
||||
'0'+CR_RED, itemcolor, fullitemcount, totalitems,
|
||||
'0'+CR_RED, secretcolor, fullsecretcount, totalsecret);
|
||||
"\x1b%cK \x1b%c%s \x1b%cI \x1b%c%s \x1b%cS \x1b%c%s",
|
||||
'0'+CR_RED, killcolor, kill_str,
|
||||
'0'+CR_RED, itemcolor, item_str,
|
||||
'0'+CR_RED, secretcolor, secret_str);
|
||||
|
||||
HUlib_add_string_to_cur_line(&w_monsec, hud_stringbuffer);
|
||||
}
|
||||
@ -2191,6 +2248,10 @@ void HU_BindHUDVariables(void)
|
||||
ss_stat, wad_no,
|
||||
"Show level stats (kills, items, and secrets) widget (1 = On automap; "
|
||||
"2 = On HUD; 3 = Always)");
|
||||
M_BindNum("hud_stats_format", &hud_stats_format, NULL,
|
||||
STATSFORMAT_RATIO, STATSFORMAT_RATIO, NUM_STATSFORMATS-1,
|
||||
ss_stat, wad_no,
|
||||
"Format of level stats (0 = Ratio; 1 = Boolean; 2 = Percent; 3 = Remaining; 4 = Count)");
|
||||
M_BindNum("hud_level_time", &hud_level_time, NULL,
|
||||
HUD_WIDGET_OFF, HUD_WIDGET_OFF, HUD_WIDGET_ALWAYS,
|
||||
ss_stat, wad_no,
|
||||
|
@ -321,6 +321,7 @@ enum
|
||||
str_hudmode,
|
||||
str_show_widgets,
|
||||
str_show_adv_widgets,
|
||||
str_stats_format,
|
||||
str_crosshair,
|
||||
str_crosshair_target,
|
||||
str_hudcolor,
|
||||
@ -1882,16 +1883,22 @@ static setup_menu_t stat_settings1[] = {
|
||||
MI_END
|
||||
};
|
||||
|
||||
static void UpdateStatsFormatItem(void);
|
||||
|
||||
static const char *show_widgets_strings[] = {"Off", "Automap", "HUD", "Always"};
|
||||
static const char *show_adv_widgets_strings[] = {"Off", "Automap", "HUD",
|
||||
"Always", "Advanced"};
|
||||
|
||||
static const char *stats_format_strings[] = {
|
||||
"Ratio", "Boolean", "Percent", "Remaining", "Count"
|
||||
};
|
||||
|
||||
static setup_menu_t stat_settings2[] = {
|
||||
|
||||
{"Widget Types", S_SKIP | S_TITLE, H_X, M_SPC},
|
||||
|
||||
{"Show Level Stats", S_CHOICE, H_X, M_SPC, {"hud_level_stats"},
|
||||
.strings_id = str_show_widgets},
|
||||
.strings_id = str_show_widgets, .action = UpdateStatsFormatItem},
|
||||
|
||||
{"Show Level Time", S_CHOICE, H_X, M_SPC, {"hud_level_time"},
|
||||
.strings_id = str_show_widgets},
|
||||
@ -1909,6 +1916,9 @@ static setup_menu_t stat_settings2[] = {
|
||||
|
||||
{"Widget Appearance", S_SKIP | S_TITLE, H_X, M_SPC},
|
||||
|
||||
{"Level Stats Format", S_CHOICE, H_X, M_SPC, {"hud_stats_format"},
|
||||
.strings_id = str_stats_format, .action = HU_Start},
|
||||
|
||||
{"Use Doom Font", S_CHOICE, H_X, M_SPC, {"hud_widget_font"},
|
||||
.strings_id = str_show_widgets},
|
||||
|
||||
@ -1973,6 +1983,11 @@ static setup_menu_t stat_settings4[] = {
|
||||
static setup_menu_t *stat_settings[] = {stat_settings1, stat_settings2,
|
||||
stat_settings3, stat_settings4, NULL};
|
||||
|
||||
static void UpdateStatsFormatItem(void)
|
||||
{
|
||||
DisableItem(!hud_level_stats, stat_settings2, "hud_stats_format");
|
||||
}
|
||||
|
||||
static void UpdateCrosshairItems(void)
|
||||
{
|
||||
DisableItem(!hud_crosshair, stat_settings3, "hud_crosshair_health");
|
||||
@ -4786,6 +4801,7 @@ static const char **selectstrings[] = {
|
||||
NULL, // str_hudmode
|
||||
show_widgets_strings,
|
||||
show_adv_widgets_strings,
|
||||
stats_format_strings,
|
||||
crosshair_strings,
|
||||
crosshair_target_strings,
|
||||
hudcolor_strings,
|
||||
@ -4870,6 +4886,7 @@ void MN_SetupResetMenu(void)
|
||||
DisableItem(!brightmaps_found || force_brightmaps, gen_settings5,
|
||||
"brightmaps");
|
||||
UpdateInterceptsEmuItem();
|
||||
UpdateStatsFormatItem();
|
||||
UpdateCrosshairItems();
|
||||
UpdateCenteredWeaponItem();
|
||||
UpdateGamepadItems();
|
||||
|
Loading…
x
Reference in New Issue
Block a user