From 6eab875ec20efd5a83777a785fef7c6c38e484b7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 26 Oct 2022 00:22:23 +0200 Subject: [PATCH] - added option to show hub and episode names on the alt HUD. Still very much work in progress because few mods have set this up. CVARs default to off and are not exposed to the menu. --- src/d_main.cpp | 4 --- src/g_level.cpp | 30 +++++++++++++++++++ src/g_statusbar/shared_hud.cpp | 2 ++ src/gamedata/statistics.cpp | 6 ++++ wadsrc/static/zscript/doombase.zs | 3 ++ wadsrc/static/zscript/ui/statusbar/alt_hud.zs | 28 +++++++++++++++-- 6 files changed, 66 insertions(+), 7 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index 1939c6a79f..383eb53dd3 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -31,10 +31,6 @@ #include #endif -#ifdef HAVE_FPU_CONTROL -#include -#endif - #if defined(__unix__) || defined(__APPLE__) #include #endif diff --git a/src/g_level.cpp b/src/g_level.cpp index 1b9545fa69..0efb077f59 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -85,6 +85,7 @@ #include "c_buttons.h" #include "screenjob.h" #include "types.h" +#include "gstrings.h" #include "gi.h" @@ -101,6 +102,7 @@ void STAT_StartNewGame(const char *lev); void STAT_ChangeLevel(const char *newl, FLevelLocals *Level); +FString STAT_EpisodeName(); EXTERN_CVAR(Bool, save_formatted) EXTERN_CVAR (Float, sv_gravity) @@ -2430,3 +2432,31 @@ void FLevelLocals::SetMusic() { S_ChangeMusic(Music, musicorder); } + + +DEFINE_ACTION_FUNCTION(FLevelLocals, GetClusterName) +{ + PARAM_SELF_STRUCT_PROLOGUE(FLevelLocals) + cluster_info_t* cluster = FindClusterInfo(self->cluster); + FString retval; + + if (cluster) + { + if (cluster->flags & CLUSTER_LOOKUPNAME) + retval = GStrings(cluster->ClusterName); + else + retval = cluster->ClusterName; + } + ACTION_RETURN_STRING(retval); +} + +DEFINE_ACTION_FUNCTION(FLevelLocals, GetEpisodeName) +{ + // this is a bit of a crapshoot because ZDoom never assigned a level to an episode + // and retroactively fixing this is not possible. + // This will need some heuristics to assign a proper episode to each existing level. + // Stuff for later. for now this just checks the STAT module for the currently running episode, + // which should be fine unless cheating. + ACTION_RETURN_STRING(GStrings.localize(STAT_EpisodeName())); +} + diff --git a/src/g_statusbar/shared_hud.cpp b/src/g_statusbar/shared_hud.cpp index 88d749508b..a6a6ea4107 100644 --- a/src/g_statusbar/shared_hud.cpp +++ b/src/g_statusbar/shared_hud.cpp @@ -63,6 +63,8 @@ CVAR (Bool, hud_showitems, false,CVAR_ARCHIVE); // Show item stats on HUD CVAR (Bool, hud_showstats, false, CVAR_ARCHIVE); // for stamina and accuracy. CVAR (Bool, hud_showscore, false, CVAR_ARCHIVE); // for user maintained score CVAR (Bool, hud_showweapons, true, CVAR_ARCHIVE); // Show weapons collected +CVAR (Bool, am_showepisode, false, CVAR_ARCHIVE); // Show current episode name +CVAR (Bool, am_showcluster, false, CVAR_ARCHIVE); // Show current cluster name CVAR (Int , hud_showammo, 2, CVAR_ARCHIVE); // Show ammo collected CVAR (Int , hud_showtime, 0, CVAR_ARCHIVE); // Show time on HUD CVAR (Int , hud_showtimestat, 0, CVAR_ARCHIVE); // Show time on HUD as statistics widget diff --git a/src/gamedata/statistics.cpp b/src/gamedata/statistics.cpp index b14c97c2be..39f67a9987 100644 --- a/src/gamedata/statistics.cpp +++ b/src/gamedata/statistics.cpp @@ -561,6 +561,12 @@ void STAT_Serialize(FSerializer &arc) } +FString STAT_EpisodeName() +{ + if (StartEpisode == nullptr) return ""; + return StartEpisode->mEpisodeName; +} + //========================================================================== // // show statistics diff --git a/wadsrc/static/zscript/doombase.zs b/wadsrc/static/zscript/doombase.zs index 09a90d3a14..1d6210bc5c 100644 --- a/wadsrc/static/zscript/doombase.zs +++ b/wadsrc/static/zscript/doombase.zs @@ -511,6 +511,9 @@ struct LevelLocals native native void ExitLevel(int position, bool keepFacing); native void SecretExitLevel(int position); native void ChangeLevel(string levelname, int position = 0, int flags = 0, int skill = -1); + + native String GetClusterName(); + native String GetEpisodeName(); } // a few values of this need to be readable by the play code. diff --git a/wadsrc/static/zscript/ui/statusbar/alt_hud.zs b/wadsrc/static/zscript/ui/statusbar/alt_hud.zs index 4175caece3..8054e3d07f 100644 --- a/wadsrc/static/zscript/ui/statusbar/alt_hud.zs +++ b/wadsrc/static/zscript/ui/statusbar/alt_hud.zs @@ -973,9 +973,31 @@ class AltHud ui let amstr = Level.FormatMapName(hudcolor_titl); font = generic_ui? NewSmallFont : SmallFont.CanPrint(amstr)? SmallFont : OriginalSmallFont; - screen.DrawText(font, Font.CR_BRICK, 2, hudheight - fonth - 1, amstr, - DTA_KeepRatio, true, - DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight); + bottom = hudheight - fonth - 1; + + screen.DrawText(font, Font.CR_BRICK, 2, bottom, amstr, + DTA_KeepRatio, true, DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight); + + if (am_showcluster && (Level.clusterflags & Level.CLUSTER_HUB)) + { + let text = Level.GetClusterName(); + if (text != "") + { + bottom -= fonth; + screen.DrawText(font, Font.CR_ORANGE, 2, bottom, text, + DTA_KeepRatio, true, DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight); + } + } + if (am_showepisode) + { + let text = Level.GetEpisodeName(); + if (text != "") + { + bottom -= fonth; + screen.DrawText(font, Font.CR_RED, 2, bottom, text, + DTA_KeepRatio, true, DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight); + } + } DrawCoordinates(CPlayer, false); }