Skip to content
Permalink
Browse files

- 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
  • Loading branch information
alexey-lysiuk committed Nov 20, 2019
1 parent a3741ab commit a7f2df4fef49709a7d8b520b4501acdf5d9a5e02
@@ -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)
@@ -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")
@@ -158,6 +158,7 @@ struct gameinfo_t
FString statusbar;
int statusbarfile = -1;
FName statusbarclass;
FName althudclass;
int statusbarclassfile = -1;
FName MessageBoxClass;
FName backpacktype;
@@ -1088,3 +1088,4 @@ xx(PlayerTeam)
xx(PlayerColors)
xx(PlayerSkin)
xx(NewPlayerMenu)
xx(AltHud)
@@ -44,7 +44,7 @@ class AltHud ui
const POWERUPICONSIZE = 32;


void Init()
virtual void Init()
{
switch (gameinfo.gametype)
{

0 comments on commit a7f2df4

Please sign in to comment.
You can’t perform that action at this time.