From a7f2df4fef49709a7d8b520b4501acdf5d9a5e02 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Wed, 20 Nov 2019 18:33:22 +0200 Subject: [PATCH] - added ability to set custom alternative HUD Use GAMEINFO key 'althudclass' to specify own class derived from AltHud https://forum.zdoom.org/viewtopic.php?t=66422 --- src/g_statusbar/shared_sbar.cpp | 48 ++++++++++++++----- src/gamedata/gi.cpp | 1 + src/gamedata/gi.h | 1 + src/utility/namedef.h | 1 + wadsrc/static/zscript/ui/statusbar/alt_hud.zs | 2 +- 5 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index aa09670802..cb72968947 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -335,6 +335,35 @@ void ST_CreateStatusBar(bool bTitleLevel) // //--------------------------------------------------------------------------- +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; @@ -347,20 +376,13 @@ DBaseStatusBar::DBaseStatusBar () ShowLog = false; defaultScale = { (double)CleanXfac, (double)CleanYfac }; - // Create the AltHud object. Todo: Make class type configurable. - FName classname = "AltHud"; - auto cls = PClass::FindClass(classname); - if (cls) - { - AltHud = cls->CreateNew(); + // Create the AltHud object. + AltHud = CreateAltHud(gameinfo.althudclass); - VMFunction * func = PClass::FindFunction(classname, "Init"); - if (func != nullptr) - { - VMValue params[] = { AltHud }; - VMCall(func, params, countof(params), nullptr, 0); - } - } + if (!AltHud) + AltHud = CreateAltHud(NAME_AltHud); + + assert(AltHud); } static void ValidateResolution(int &hres, int &vres) diff --git a/src/gamedata/gi.cpp b/src/gamedata/gi.cpp index 380fc66b6c..a952313a5d 100644 --- a/src/gamedata/gi.cpp +++ b/src/gamedata/gi.cpp @@ -390,6 +390,7 @@ void FMapInfoParser::ParseGameInfo() GAMEINFOKEY_STRING(backpacktype, "backpacktype") GAMEINFOKEY_STRING_STAMPED(statusbar, "statusbar", statusbarfile) GAMEINFOKEY_STRING_STAMPED(statusbarclass, "statusbarclass", statusbarclassfile) + GAMEINFOKEY_STRING(althudclass, "althudclass") GAMEINFOKEY_MUSIC(intermissionMusic, intermissionOrder, "intermissionMusic") GAMEINFOKEY_STRING(CursorPic, "CursorPic") GAMEINFOKEY_STRING(MessageBoxClass, "MessageBoxClass") diff --git a/src/gamedata/gi.h b/src/gamedata/gi.h index 8a57cfbd50..d1dc534e3c 100644 --- a/src/gamedata/gi.h +++ b/src/gamedata/gi.h @@ -158,6 +158,7 @@ struct gameinfo_t FString statusbar; int statusbarfile = -1; FName statusbarclass; + FName althudclass; int statusbarclassfile = -1; FName MessageBoxClass; FName backpacktype; diff --git a/src/utility/namedef.h b/src/utility/namedef.h index ec9d4b6bd6..e2063f8a77 100644 --- a/src/utility/namedef.h +++ b/src/utility/namedef.h @@ -1088,3 +1088,4 @@ xx(PlayerTeam) xx(PlayerColors) xx(PlayerSkin) xx(NewPlayerMenu) +xx(AltHud) diff --git a/wadsrc/static/zscript/ui/statusbar/alt_hud.zs b/wadsrc/static/zscript/ui/statusbar/alt_hud.zs index b0efdc5411..b791c899fd 100644 --- a/wadsrc/static/zscript/ui/statusbar/alt_hud.zs +++ b/wadsrc/static/zscript/ui/statusbar/alt_hud.zs @@ -44,7 +44,7 @@ class AltHud ui const POWERUPICONSIZE = 32; - void Init() + virtual void Init() { switch (gameinfo.gametype) {