From db814dc333184bbaf105fb3024626f16b618a5e2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 2 Dec 2018 14:24:26 +0100 Subject: [PATCH] - properly hook up the alt HUD with the status bar. --- src/d_main.cpp | 2 +- src/g_shared/shared_hud.cpp | 56 ++++----------------------------- src/g_statusbar/sbar.h | 4 +++ src/g_statusbar/shared_sbar.cpp | 20 ++++++++++-- 4 files changed, 29 insertions(+), 53 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index ac83318ad..7827bffd2 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -773,7 +773,7 @@ void D_Display () if (hud_althud && viewheight == SCREENHEIGHT && screenblocks > 10) { StatusBar->DrawBottomStuff (HUD_AltHud); - if (DrawFSHUD || automapactive) DrawHUD(); + if (DrawFSHUD || automapactive) StatusBar->DrawAltHUD(); if (players[consoleplayer].camera && players[consoleplayer].camera->player && !automapactive) { StatusBar->DrawCrosshair(); diff --git a/src/g_shared/shared_hud.cpp b/src/g_shared/shared_hud.cpp index c10af90e1..998d3f514 100644 --- a/src/g_shared/shared_hud.cpp +++ b/src/g_shared/shared_hud.cpp @@ -31,11 +31,6 @@ ** */ -// NOTE: Some stuff in here might seem a little redundant but I wanted this -// to be as true as possible to my original intent which means that it -// only uses that code from ZDoom's status bar that is the same as any -// copy would be. - #include "doomtype.h" #include "doomdef.h" #include "v_video.h" @@ -57,17 +52,6 @@ #include -#define HUMETA_AltIcon 0x10f000 - -EXTERN_CVAR(Bool,am_follow) -EXTERN_CVAR (Int, con_scaletext) -EXTERN_CVAR (Bool, idmypos) -EXTERN_CVAR (Int, screenblocks) -EXTERN_CVAR(Bool, hud_aspectscale) - -EXTERN_CVAR (Bool, am_showtime) -EXTERN_CVAR (Bool, am_showtotaltime) - CVAR(Int,hud_althudscale, 0, CVAR_ARCHIVE) // Scale the hud to 640x400? CVAR(Bool,hud_althud, false, CVAR_ARCHIVE) // Enable/Disable the alternate HUD @@ -108,55 +92,27 @@ 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? -static FFont * HudFont; // The font for the health and armor display -static FFont * IndexFont; // The font for the inventory indices - -// Icons -static FTexture * healthpic; // Health icon -static FTexture * berserkpic; // Berserk icon (Doom only) -static FTexture * fragpic; // Frags icon -static FTexture * invgems[2]; // Inventory arrows -static FTextureID tnt1a0; // We need this to check for empty sprites. - -static int hudwidth, hudheight; // current width/height for HUD display -static int statspace; - //--------------------------------------------------------------------------- // -// draw the overlay +// draw the HUD // //--------------------------------------------------------------------------- +EXTERN_CVAR(Bool, hud_aspectscale) -void DrawHUD() +void DBaseStatusBar::DrawAltHUD() { player_t * CPlayer = StatusBar->CPlayer; players[consoleplayer].inventorytics = 0; int scale = GetUIScale(hud_althudscale); - hudwidth = SCREENWIDTH / scale; - hudheight = hud_aspectscale ? int(SCREENHEIGHT / (scale*1.2)) : SCREENHEIGHT / scale; - - // Until the script export is complete we need to do some manual setup here - auto cls = PClass::FindClass("AltHud"); - if (!cls) return; - DObject *althud = cls->CreateNew(); // scripted parts. This is here to make a gradual transition - - { - IFVM(AltHud, Init) - { - VMValue params[] = { althud }; - VMCall(func, params, countof(params), nullptr, 0); - } - } + int hudwidth = SCREENWIDTH / scale; + int hudheight = hud_aspectscale ? int(SCREENHEIGHT / (scale*1.2)) : SCREENHEIGHT / scale; IFVM(AltHud, Draw) { - VMValue params[] = { althud, CPlayer, hudwidth, hudheight }; + VMValue params[] = { AltHud, CPlayer, hudwidth, hudheight }; VMCall(func, params, countof(params), nullptr, 0); } - - if (althud) althud->Destroy(); - althud = nullptr; } diff --git a/src/g_statusbar/sbar.h b/src/g_statusbar/sbar.h index 2f895081a..ca3b683ab 100644 --- a/src/g_statusbar/sbar.h +++ b/src/g_statusbar/sbar.h @@ -432,6 +432,7 @@ public: virtual void SetMugShotState (const char *state_name, bool wait_till_done=false, bool reset=false); void DrawLog(); uint32_t GetTranslation() const; + void DrawAltHUD(); void DrawGraphic(FTextureID texture, double x, double y, int flags, double Alpha, double boxwidth, double boxheight, double scaleX, double scaleY); void DrawString(FFont *font, const FString &cstring, double x, double y, int flags, double Alpha, int translation, int spacing, bool monospaced, int shadowX, int shadowY); @@ -454,6 +455,9 @@ public: void RefreshBackground () const; +private: + DObject *AltHud = nullptr; + public: AInventory *ValidateInvFirst (int numVisible) const; diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index 3b03a100f..c24f1b2f7 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -70,6 +70,7 @@ IMPLEMENT_POINTERS_START(DBaseStatusBar) IMPLEMENT_POINTER(Messages[0]) IMPLEMENT_POINTER(Messages[1]) IMPLEMENT_POINTER(Messages[2]) + IMPLEMENT_POINTER(AltHud) IMPLEMENT_POINTERS_END EXTERN_CVAR (Bool, am_showmonsters) @@ -358,6 +359,22 @@ DBaseStatusBar::DBaseStatusBar () CPlayer = NULL; 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(); + + VMFunction * func = nullptr; + PClass::FindFunction(&func, classname, "Init"); + if (func != nullptr) + { + VMValue params[] = { AltHud }; + VMCall(func, params, countof(params), nullptr, 0); + } + } } static void ValidateResolution(int &hres, int &vres) @@ -421,6 +438,7 @@ void DBaseStatusBar::OnDestroy () } Messages[i] = NULL; } + if (AltHud) AltHud->Destroy(); Super::OnDestroy(); } @@ -987,8 +1005,6 @@ void DBaseStatusBar::CallDraw(EHudState state, double ticFrac) BeginStatusBar(BaseSBarHorizontalResolution, BaseSBarVerticalResolution, BaseRelTop, false); } - - void DBaseStatusBar::DrawLog () { int hudwidth, hudheight;