- 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
This commit is contained in:
alexey.lysiuk 2019-11-20 18:33:22 +02:00
parent a3741abbf3
commit a7f2df4fef
5 changed files with 39 additions and 14 deletions

View file

@ -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)

View file

@ -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")

View file

@ -158,6 +158,7 @@ struct gameinfo_t
FString statusbar;
int statusbarfile = -1;
FName statusbarclass;
FName althudclass;
int statusbarclassfile = -1;
FName MessageBoxClass;
FName backpacktype;

View file

@ -1088,3 +1088,4 @@ xx(PlayerTeam)
xx(PlayerColors)
xx(PlayerSkin)
xx(NewPlayerMenu)
xx(AltHud)

View file

@ -44,7 +44,7 @@ class AltHud ui
const POWERUPICONSIZE = 32;
void Init()
virtual void Init()
{
switch (gameinfo.gametype)
{