diff --git a/docs/hud.md b/docs/hud.md index 2b578705c..559b63a24 100644 --- a/docs/hud.md +++ b/docs/hud.md @@ -114,6 +114,8 @@ Unless otherwise specified, argument values are integers. For toggles, a 1 means - Uses the message font - `map_title`: shows the current map's title - Uses the message font + - Supports 1 argument: `cycle_author` + - `cycle_author`: cycles between map title and author on automap - `message`: shows the current player message - Uses the message font - Supports 1 argument: `center` diff --git a/prboom2/src/dsda/configuration.c b/prboom2/src/dsda/configuration.c index b93501a44..11b18b094 100644 --- a/prboom2/src/dsda/configuration.c +++ b/prboom2/src/dsda/configuration.c @@ -1057,6 +1057,10 @@ dsda_config_t dsda_config[dsda_config_count] = { "map_title", dsda_config_map_title, CONF_BOOL(1), NULL, NOT_STRICT, dsda_RefreshMapTitle }, + [dsda_config_map_title_author_cycle] = { + "map_title_author_cycle", dsda_config_map_title_author_cycle, + CONF_BOOL(1), NULL, NOT_STRICT + }, [dsda_config_map_trail] = { "map_trail", dsda_config_map_trail, CONF_BOOL(0), NULL, STRICT_INT(0), AM_initPlayerTrail diff --git a/prboom2/src/dsda/configuration.h b/prboom2/src/dsda/configuration.h index c75cf43aa..b5edb6c21 100644 --- a/prboom2/src/dsda/configuration.h +++ b/prboom2/src/dsda/configuration.h @@ -233,6 +233,7 @@ typedef enum { dsda_config_map_totals, dsda_config_map_time, dsda_config_map_title, + dsda_config_map_title_author_cycle, dsda_config_map_trail, dsda_config_map_trail_collisions, dsda_config_map_trail_size, diff --git a/prboom2/src/dsda/hud_components/map_title.c b/prboom2/src/dsda/hud_components/map_title.c index 98fc993f6..11f2d3628 100644 --- a/prboom2/src/dsda/hud_components/map_title.c +++ b/prboom2/src/dsda/hud_components/map_title.c @@ -19,21 +19,62 @@ #include "map_title.h" +extern dsda_string_t hud_title_cycle; +extern dsda_string_t hud_title; +extern dsda_string_t hud_author; + typedef struct { dsda_text_t component; + dboolean cycle_author; } local_component_t; static local_component_t* local; +int titleTime = 3 * TICRATE; +short titleCounter; +short titleSwap; + +void dsda_UpdateTitleSwap(void) +{ + // Reset / init counter + if (hud_title_cycle.string == NULL) + { + titleSwap = 0; + titleCounter = titleTime; + dsda_StringPrintF(&hud_title_cycle, hud_title.string); + } + + // Restart counter + init swap + if (--titleCounter <= 0) + { + titleSwap ^= 1; + titleCounter = titleTime; + } + + // Swap title to map or author + if (titleCounter == titleTime) + { + if (titleSwap) + dsda_StringPrintF(&hud_title_cycle, "Author: %s", hud_author.string); + else + dsda_StringPrintF(&hud_title_cycle, hud_title.string); + } +} + + static void dsda_UpdateComponentText(char* str, size_t max_size) { - extern dsda_string_t hud_title; + dboolean cycle_title_active = (hud_author.string != NULL) && + (local->cycle_author || dsda_IntConfig(dsda_config_map_title_author_cycle)); + + if (cycle_title_active) + dsda_UpdateTitleSwap(); snprintf( str, max_size, "%s%s", dsda_TextColor(dsda_tc_map_title), - hud_title.string + cycle_title_active ? hud_title_cycle.string : hud_title.string ); } @@ -41,6 +82,8 @@ void dsda_InitMapTitleHC(int x_offset, int y_offset, int vpt, int* args, int arg *data = Z_Calloc(1, sizeof(local_component_t)); local = *data; + local->cycle_author = arg_count > 0 ? !!args[0] : false; + dsda_InitBlockyHC(&local->component, x_offset, y_offset, vpt); } diff --git a/prboom2/src/hu_stuff.c b/prboom2/src/hu_stuff.c index ed4f88642..3784c5878 100644 --- a/prboom2/src/hu_stuff.c +++ b/prboom2/src/hu_stuff.c @@ -94,6 +94,7 @@ void HU_InitThresholds(void) } dsda_string_t hud_title; +dsda_string_t hud_title_cycle; static void HU_FetchTitle(void) { @@ -103,6 +104,19 @@ static void HU_FetchTitle(void) dsda_HUTitle(&hud_title); } +dsda_string_t hud_author; + +static void HU_FetchAuthor(void) +{ + const char* author = dsda_MapAuthor(); + + if (hud_author.string) + dsda_FreeString(&hud_author); + + if (author && author[0]) + dsda_StringPrintF(&hud_author, author); +} + static void HU_InitMessages(void) { custom_message_p = &custom_message[displayplayer]; @@ -310,17 +324,15 @@ void HU_AnnounceMap(void) if (gamemap != last_gamemap || gameepisode != last_gameepisode) { - const char *author; last_gamemap = gamemap; last_gameepisode = gameepisode; - author = dsda_MapAuthor(); - if (author && author[0]) + if (hud_author.string) { dsda_string_t message; - dsda_StringPrintF(&message, "%s by %s", hud_title.string, author); + dsda_StringPrintF(&message, "%s by %s", hud_title.string, hud_author.string); dsda_AddAlert(message.string); dsda_FreeString(&message); } @@ -348,6 +360,7 @@ void HU_Start(void) HU_InitPlayer(); HU_InitMessages(); HU_FetchTitle(); + HU_FetchAuthor(); HU_InitCrosshair(); dsda_InitExHud(); @@ -423,6 +436,12 @@ void HU_Ticker(void) } } + // Reset map/author cycle when leaving automap + if (hud_title_cycle.string && !automap_active) + { + dsda_FreeString(&hud_title_cycle); + } + dsda_UpdateExHud(); } diff --git a/prboom2/src/m_misc.c b/prboom2/src/m_misc.c index 0b50309f6..29fdd61a8 100644 --- a/prboom2/src/m_misc.c +++ b/prboom2/src/m_misc.c @@ -243,6 +243,7 @@ cfg_def_t cfg_defs[] = MIGRATED_SETTING(dsda_config_map_totals), MIGRATED_SETTING(dsda_config_map_time), MIGRATED_SETTING(dsda_config_map_title), + MIGRATED_SETTING(dsda_config_map_title_author_cycle), MIGRATED_SETTING(dsda_config_map_trail), MIGRATED_SETTING(dsda_config_map_trail_collisions), MIGRATED_SETTING(dsda_config_map_trail_size),