diff --git a/src/g_shared/shared_hud.cpp b/src/g_shared/shared_hud.cpp index 6f5f0d1bf..15d272094 100644 --- a/src/g_shared/shared_hud.cpp +++ b/src/g_shared/shared_hud.cpp @@ -95,6 +95,65 @@ CVAR (Int, hudcolor_stats, CR_GREEN, CVAR_ARCHIVE) // For the stats values the CVAR(Bool, map_point_coordinates, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) // show player or map coordinates? +//--------------------------------------------------------------------------- +// +// Create Alternative HUD +// +//--------------------------------------------------------------------------- + +CUSTOM_CVAR(Bool, hud_althud_forceinternal, false, CVAR_ARCHIVE | CVAR_NOINITCALL) +{ + if (StatusBar) + StatusBar->CreateAltHUD(); +} + +static DObject* DoCreateAltHUD(const FName classname) +{ + if (classname == NAME_None) + return nullptr; + + const auto cls = PClass::FindClass(classname); + if (!cls) + { + Printf(TEXTCOLOR_RED "Unknown alternative HUD class \"%s\"\n", classname.GetChars()); + return nullptr; + } + + if (!cls->IsDescendantOf(NAME_AltHud)) + { + Printf(TEXTCOLOR_RED "Alternative HUD class \"%s\" is not derived from AltHud\n", classname.GetChars()); + return nullptr; + } + + const auto althud = cls->CreateNew(); + + IFVIRTUALPTRNAME(althud, NAME_AltHud, Init) + { + VMValue params[] = { althud }; + VMCall(func, params, countof(params), nullptr, 0); + } + + return althud; +} + +void DBaseStatusBar::CreateAltHUD() +{ + if (AltHud) + { + AltHud->Destroy(); + AltHud = nullptr; + } + + if (!hud_althud_forceinternal) + AltHud = DoCreateAltHUD(gameinfo.althudclass); + + if (!AltHud) + AltHud = DoCreateAltHUD(NAME_AltHud); + + assert(AltHud); +} + + //--------------------------------------------------------------------------- // // draw the HUD diff --git a/src/g_statusbar/sbar.h b/src/g_statusbar/sbar.h index 2ea329fc6..fee3a8b94 100644 --- a/src/g_statusbar/sbar.h +++ b/src/g_statusbar/sbar.h @@ -436,6 +436,8 @@ public: virtual void SetMugShotState (const char *state_name, bool wait_till_done=false, bool reset=false); void DrawLog(); uint32_t GetTranslation() const; + + void CreateAltHUD(); void DrawAltHUD(); void DrawGraphic(FTextureID texture, double x, double y, int flags, double Alpha, double boxwidth, double boxheight, double scaleX, double scaleY); diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index 5e9bc2c0a..0e3f68714 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -366,36 +366,6 @@ void ST_CreateStatusBar(bool bTitleLevel) // Constructor // //--------------------------------------------------------------------------- - -static DObject* CreateAltHud(const FName classname) -{ - if (classname == NAME_None) - return nullptr; - - auto cls = PClass::FindClass(classname); - if (!cls) - { - Printf(TEXTCOLOR_RED "Unknown alternative HUD class \"%s\"\n", classname.GetChars()); - return nullptr; - } - - if (!cls->IsDescendantOf(NAME_AltHud)) - { - Printf(TEXTCOLOR_RED "Alternative HUD class \"%s\" is not derived from AltHud\n", classname.GetChars()); - return nullptr; - } - - auto althud = cls->CreateNew(); - - IFVIRTUALPTRNAME(althud, NAME_AltHud, Init) - { - VMValue params[] = { althud }; - VMCall(func, params, countof(params), nullptr, 0); - } - - return althud; -} - DBaseStatusBar::DBaseStatusBar () { CompleteBorder = false; @@ -408,13 +378,7 @@ DBaseStatusBar::DBaseStatusBar () ShowLog = false; defaultScale = { (double)CleanXfac, (double)CleanYfac }; - // Create the AltHud object. - AltHud = CreateAltHud(gameinfo.althudclass); - - if (!AltHud) - AltHud = CreateAltHud(NAME_AltHud); - - assert(AltHud); + CreateAltHUD(); } static void ValidateResolution(int &hres, int &vres)