From e791c957d9827340952af037685c7f19d9272dfc Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 26 Mar 2017 22:04:58 +0200 Subject: [PATCH] - implemented the regular Doom status bar. The DOOM status bar and HUD are complete, except the inventory bar. --- src/d_main.cpp | 10 +- src/d_player.h | 1 + src/g_inventory/a_keys.cpp | 13 +- src/g_inventory/a_keys.h | 2 +- src/g_statusbar/sbar.h | 1 + src/g_statusbar/sbarinfo.cpp | 1 + src/g_statusbar/shared_sbar.cpp | 7 +- src/p_user.cpp | 18 +++ wadsrc/static/zscript/actor.txt | 1 + wadsrc/static/zscript/shared/player.txt | 1 + wadsrc/static/zscript/statusbar/doom_sbar.txt | 143 ++++++++++-------- wadsrc/static/zscript/statusbar/statusbar.txt | 33 ++-- 12 files changed, 131 insertions(+), 100 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index 7216881d4d..22ba39cfe4 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2568,14 +2568,8 @@ void D_DoomMain (void) P_SetupWeapons_ntohton(); - //SBarInfo support. - // This needs special checking because there are two distinct methods of defining status bars. - // SBARINFO should only be picked if it is the most recently defined one, so that both - // methods can override each other if loaded in sequence. - if (gameinfo.statusbarfile > gameinfo.statusbarclassfile) - { - SBarInfo::Load(); - } + //SBarInfo support. Note that the first SBARINFO lump contains the mugshot definition so it even needs to be read when a regular status bar is being used. + SBarInfo::Load(); HUD_InitHud(); if (!batchrun) diff --git a/src/d_player.h b/src/d_player.h index 4a718778bd..f9da0d120b 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -532,6 +532,7 @@ public: // [Nash] set player FOV void SetFOV(float fov); + bool HasWeaponsInSlot(int slot) const; }; // Bookkeeping on players - state. diff --git a/src/g_inventory/a_keys.cpp b/src/g_inventory/a_keys.cpp index 75d98c2c7d..701b98b000 100644 --- a/src/g_inventory/a_keys.cpp +++ b/src/g_inventory/a_keys.cpp @@ -464,7 +464,7 @@ void P_DeinitKeyMessages() // //=========================================================================== -bool P_CheckKeys (AActor *owner, int keynum, bool remote) +bool P_CheckKeys (AActor *owner, int keynum, bool remote, bool quiet) { const char *failtext = NULL; FSoundID *failsound; @@ -479,6 +479,7 @@ bool P_CheckKeys (AActor *owner, int keynum, bool remote) if (!locks[keynum]) { + if (quiet) return false; if (keynum == 103 && (gameinfo.flags & GI_SHAREWARE)) failtext = "$TXT_RETAIL_ONLY"; else @@ -490,6 +491,7 @@ bool P_CheckKeys (AActor *owner, int keynum, bool remote) else { if (locks[keynum]->check(owner)) return true; + if (quiet) return false; failtext = remote? locks[keynum]->RemoteMsg : locks[keynum]->Message; failsound = &locks[keynum]->locksound[0]; numfailsounds = locks[keynum]->locksound.Size(); @@ -519,6 +521,15 @@ bool P_CheckKeys (AActor *owner, int keynum, bool remote) return false; } +DEFINE_ACTION_FUNCTION(AActor, CheckKeys) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_INT(locknum); + PARAM_BOOL(remote); + PARAM_BOOL_DEF(quiet); + ACTION_RETURN_BOOL(P_CheckKeys(self, locknum, remote, quiet)); +} + //========================================================================== // // These functions can be used to get color information for diff --git a/src/g_inventory/a_keys.h b/src/g_inventory/a_keys.h index 328ff04a60..05eff11897 100644 --- a/src/g_inventory/a_keys.h +++ b/src/g_inventory/a_keys.h @@ -4,7 +4,7 @@ class AActor; class AInventory; -bool P_CheckKeys (AActor *owner, int keynum, bool remote); +bool P_CheckKeys (AActor *owner, int keynum, bool remote, bool quiet = false); void P_InitKeyMessages (); void P_DeinitKeyMessages (); int P_GetMapColorForLock (int lock); diff --git a/src/g_statusbar/sbar.h b/src/g_statusbar/sbar.h index 88860291ed..cdb191354c 100644 --- a/src/g_statusbar/sbar.h +++ b/src/g_statusbar/sbar.h @@ -530,6 +530,7 @@ enum DI_Flags DI_TEXT_ALIGN = 0x1800000, DI_ALPHAMAPPED = 0x2000000, + DI_NOSHADOW = 0x4000000, }; #endif /* __SBAR_H__ */ diff --git a/src/g_statusbar/sbarinfo.cpp b/src/g_statusbar/sbarinfo.cpp index ae97c7c89a..ae39fdca81 100644 --- a/src/g_statusbar/sbarinfo.cpp +++ b/src/g_statusbar/sbarinfo.cpp @@ -446,6 +446,7 @@ void SBarInfo::Load() { FreeSBarInfoScript(); MugShotStates.Clear(); + if(gameinfo.statusbar.IsNotEmpty()) { int lump = Wads.CheckNumForFullName(gameinfo.statusbar, true); diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index 382db0c929..fd1b914b17 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -1846,7 +1846,7 @@ void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, d } // This is not really such a great way to draw shadows because they can overlap with previously drawn characters. // This may have to be changed to draw the shadow text up front separately. - if (shadowX != 0 || shadowY != 0) + if ((shadowX != 0 || shadowY != 0) && !(flags & DI_NOSHADOW)) { screen->DrawChar(font, CR_UNTRANSLATED, rx + shadowX, ry + shadowY, ch, DTA_DestWidthF, rw, @@ -2033,10 +2033,9 @@ DEFINE_ACTION_FUNCTION(DBaseStatusBar, ReceivedWeapon) DEFINE_ACTION_FUNCTION(DBaseStatusBar, GetMugshot) { PARAM_SELF_PROLOGUE(DBaseStatusBar); - PARAM_POINTER(player, player_t); - PARAM_STRING(def_face); PARAM_INT(accuracy); PARAM_INT_DEF(stateflags); - auto tex = self->mugshot.GetFace(player, def_face, accuracy, (FMugShot::StateFlags)stateflags); + PARAM_STRING_DEF(def_face); + auto tex = self->mugshot.GetFace(self->CPlayer, def_face, accuracy, (FMugShot::StateFlags)stateflags); ACTION_RETURN_INT(tex ? tex->id.GetIndex() : -1); } diff --git a/src/p_user.cpp b/src/p_user.cpp index 19de4cb186..ae4cfda780 100644 --- a/src/p_user.cpp +++ b/src/p_user.cpp @@ -707,6 +707,24 @@ void player_t::SendPitchLimits() const } +bool player_t::HasWeaponsInSlot(int slot) const +{ + for (int i = 0; i < weapons.Slots[slot].Size(); i++) + { + PClassActor *weap = weapons.Slots[slot].GetWeapon(i); + if (weap != NULL && mo->FindInventory(weap)) return true; + } + return false; +} + +DEFINE_ACTION_FUNCTION(_PlayerInfo, HasWeaponsInSlot) +{ + PARAM_SELF_STRUCT_PROLOGUE(player_t); + PARAM_INT(slot); + ACTION_RETURN_BOOL(self->HasWeaponsInSlot(slot)); +} + + DEFINE_ACTION_FUNCTION(_PlayerInfo, GetUserName) { PARAM_SELF_STRUCT_PROLOGUE(player_t); diff --git a/wadsrc/static/zscript/actor.txt b/wadsrc/static/zscript/actor.txt index 71b4a7915c..af9ff38d6b 100644 --- a/wadsrc/static/zscript/actor.txt +++ b/wadsrc/static/zscript/actor.txt @@ -501,6 +501,7 @@ class Actor : Thinker native native static int FindUniqueTid(int start = 0, int limit = 0); native void SetShade(color col); native clearscope int GetRenderStyle() const; + native clearscope bool CheckKeys(int locknum, bool remote, bool quiet = false); native clearscope string GetTag(string defstr = "") const; native void SetTag(string defstr = ""); diff --git a/wadsrc/static/zscript/shared/player.txt b/wadsrc/static/zscript/shared/player.txt index a37617289a..138db474b1 100644 --- a/wadsrc/static/zscript/shared/player.txt +++ b/wadsrc/static/zscript/shared/player.txt @@ -373,6 +373,7 @@ usercmd_t original_cmd; native float GetAutoaim() const; native bool GetNoAutostartMap() const; native void SetFOV(float fov); + native clearscope bool HasWeaponsInSlot(int slot) const; clearscope int fragSum () const { diff --git a/wadsrc/static/zscript/statusbar/doom_sbar.txt b/wadsrc/static/zscript/statusbar/doom_sbar.txt index b0d0c50138..cd77b7752a 100644 --- a/wadsrc/static/zscript/statusbar/doom_sbar.txt +++ b/wadsrc/static/zscript/statusbar/doom_sbar.txt @@ -1,6 +1,7 @@ class DoomStatusBar : BaseStatusBar { HUDFont mHUDFont; + HUDFont mIndexFont; //DrawInventoryBarParms diparms; @@ -20,6 +21,8 @@ class DoomStatusBar : BaseStatusBar // Create the font used for the fullscreen HUD Font fnt = "HUDFONT_DOOM"; mHUDFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true, 1, 1); + fnt = "INDEXFONT_DOOM"; + mIndexFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true); } override void NewGame () @@ -48,11 +51,83 @@ class DoomStatusBar : BaseStatusBar protected void DrawMainBar (double TicFrac) { - //DrawTexture(Images[imgINVBACK], (0, 0), true, 1.0, itemAlign:ALIGN_OFFSETS); - //DrawTexture(Images[imgINVTOP], (0, -8), true, 1.0, itemAlign:ALIGN_OFFSETS); + DrawImage("STBAR", (0, 0), DI_ITEM_OFFSETS); + DrawImage("STTPRCNT", (90, 3), DI_ITEM_OFFSETS); + DrawImage("STTPRCNT", (221, 3), DI_ITEM_OFFSETS); + + Inventory a1, a2; + int amt1; + [a1, a2, amt1] = GetCurrentAmmo(); + DrawString(mHUDFont, FormatNumber(amt1, 3), (44, 3), DI_TEXT_ALIGN_RIGHT|DI_NOSHADOW); + DrawString(mHUDFont, FormatNumber(CPlayer.health, 3), (90, 3), DI_TEXT_ALIGN_RIGHT|DI_NOSHADOW); + DrawString(mHUDFont, FormatNumber(GetArmorAmount(), 3), (221, 3), DI_TEXT_ALIGN_RIGHT|DI_NOSHADOW); - // Health - //DrawString("Indexfont_Strife_Green", FormatNumber(CPlayer.health, 3, 5, 0), (86, -6), 1.0, Font.CR_UNTRANSLATED, TEXT_RIGHT, 0, 7, true, 1, 1); + bool locks[6]; + String image; + for(int i = 0; i < 6; i++) locks[i] = CPlayer.mo.CheckKeys(i + 1, false, true); + // key 1 + if (locks[1] && locks[4]) image = "STKEYS6"; + else if (locks[1]) image = "STKEYS0"; + else if (locks[4]) image = "STKEYS3"; + DrawImage(image, (239, 3), DI_ITEM_OFFSETS); + // key 2 + if (locks[2] && locks[5]) image = "STKEYS7"; + else if (locks[2]) image = "STKEYS1"; + else if (locks[5]) image = "STKEYS4"; + else image = ""; + DrawImage(image, (239, 13), DI_ITEM_OFFSETS); + // key 3 + if (locks[0] && locks[3]) image = "STKEYS8"; + else if (locks[0]) image = "STKEYS2"; + else if (locks[3]) image = "STKEYS5"; + else image = ""; + DrawImage(image, (239, 23), DI_ITEM_OFFSETS); + + int maxamt; + [amt1, maxamt] = GetAmount("Clip"); + DrawString(mIndexFont, FormatNumber(amt1, 3), (288, 5), DI_TEXT_ALIGN_RIGHT); + DrawString(mIndexFont, FormatNumber(maxamt, 3), (314, 5), DI_TEXT_ALIGN_RIGHT); + + [amt1, maxamt] = GetAmount("Shell"); + DrawString(mIndexFont, FormatNumber(amt1, 3), (288, 11), DI_TEXT_ALIGN_RIGHT); + DrawString(mIndexFont, FormatNumber(maxamt, 3), (314, 11), DI_TEXT_ALIGN_RIGHT); + + [amt1, maxamt] = GetAmount("RocketAmmo"); + DrawString(mIndexFont, FormatNumber(amt1, 3), (288, 17), DI_TEXT_ALIGN_RIGHT); + DrawString(mIndexFont, FormatNumber(maxamt, 3), (314, 17), DI_TEXT_ALIGN_RIGHT); + + [amt1, maxamt] = GetAmount("Cell"); + DrawString(mIndexFont, FormatNumber(amt1, 3), (288, 23), DI_TEXT_ALIGN_RIGHT); + DrawString(mIndexFont, FormatNumber(maxamt, 3), (314, 23), DI_TEXT_ALIGN_RIGHT); + + if (deathmatch || teamplay) + { + DrawString(mHUDFont, FormatNumber(CPlayer.FragCount, 3), (138, 3), DI_TEXT_ALIGN_RIGHT); + } + else + { + DrawImage("STARMS", (104, 0), DI_ITEM_OFFSETS); + DrawImage(CPlayer.HasWeaponsInSlot(2)? "STYSNUM2" : "STGNUM2", (111, 3), DI_ITEM_OFFSETS); + DrawImage(CPlayer.HasWeaponsInSlot(3)? "STYSNUM3" : "STGNUM3", (123, 3), DI_ITEM_OFFSETS); + DrawImage(CPlayer.HasWeaponsInSlot(4)? "STYSNUM4" : "STGNUM4", (135, 3), DI_ITEM_OFFSETS); + DrawImage(CPlayer.HasWeaponsInSlot(5)? "STYSNUM5" : "STGNUM5", (111, 13), DI_ITEM_OFFSETS); + DrawImage(CPlayer.HasWeaponsInSlot(6)? "STYSNUM6" : "STGNUM6", (123, 13), DI_ITEM_OFFSETS); + DrawImage(CPlayer.HasWeaponsInSlot(7)? "STYSNUM7" : "STGNUM7", (135, 13), DI_ITEM_OFFSETS); + } + + if (multiplayer) + { + DrawImage("STFBANY", (143, 0), DI_ITEM_OFFSETS|DI_TRANSLATABLE); + } + + if (CPlayer.mo.InvSel != null) + { + //drawinventorybar Doom, 7, INDEXFONT, 50, 170; + } + else + { + DrawTexture(GetMugShot(5), (143, 0), DI_ITEM_OFFSETS); + } } protected void DrawFullScreenStuff () @@ -91,7 +166,7 @@ class DoomStatusBar : BaseStatusBar } if (deathmatch) { - DrawString(mHUDFont, FormatNumber(CPlayer.fragSum(), 3), (-3, 1), DI_TEXT_ALIGN_RIGHT); + DrawString(mHUDFont, FormatNumber(CPlayer.FragCount, 3), (-3, 1), DI_TEXT_ALIGN_RIGHT); } // Draw the keys. This does not use a special draw function like SBARINFO because the specifics will be different for each mod @@ -122,61 +197,3 @@ class DoomStatusBar : BaseStatusBar } } } - -/* -statusbar normal // Standard Doom Status bar -{ - drawimage "STBAR", 0, 168; - drawimage "STTPRCNT", 90, 171; - drawimage "STTPRCNT", 221, 171; - drawnumber 3, HUDFONT_DOOM, untranslated, ammo1, 44, 171; - drawnumber 3, HUDFONT_DOOM, untranslated, health, 90, 171; - drawnumber 3, HUDFONT_DOOM, untranslated, armor, 221, 171; - - //keys - drawswitchableimage keyslot 2 && 5, "nullimage", "STKEYS0", "STKEYS3", "STKEYS6", 239, 171; - drawswitchableimage keyslot 3 && 6, "nullimage", "STKEYS1", "STKEYS4", "STKEYS7", 239, 181; - drawswitchableimage keyslot 1 && 4, "nullimage", "STKEYS2", "STKEYS5", "STKEYS8", 239, 191; - - drawnumber 3, INDEXFONT_DOOM, untranslated, ammo(Clip), 288, 173; - drawnumber 3, INDEXFONT_DOOM, untranslated, ammo(Shell), 288, 179; - drawnumber 3, INDEXFONT_DOOM, untranslated, ammo(RocketAmmo), 288, 185; - drawnumber 3, INDEXFONT_DOOM, untranslated, ammo(Cell), 288, 191; - - drawnumber 3, INDEXFONT_DOOM, untranslated, ammocapacity(Clip), 314, 173; - drawnumber 3, INDEXFONT_DOOM, untranslated, ammocapacity(Shell), 314, 179; - drawnumber 3, INDEXFONT_DOOM, untranslated, ammocapacity(RocketAmmo), 314, 185; - drawnumber 3, INDEXFONT_DOOM, untranslated, ammocapacity(Cell), 314, 191; - gamemode deathmatch, teamgame - { - drawnumber 2, HUDFONT_DOOM, untranslated, frags, 138, 171; - } - gamemode cooperative, singleplayer - { - drawimage "STARMS", 104, 168; - drawswitchableimage weaponslot 2, "STGNUM2", "STYSNUM2", 111, 172; - drawswitchableimage weaponslot 3, "STGNUM3", "STYSNUM3", 123, 172; - drawswitchableimage weaponslot 4, "STGNUM4", "STYSNUM4", 135, 172; - drawswitchableimage weaponslot 5, "STGNUM5", "STYSNUM5", 111, 182; - drawswitchableimage weaponslot 6, "STGNUM6", "STYSNUM6", 123, 182; - drawswitchableimage weaponslot 7, "STGNUM7", "STYSNUM7", 135, 182; - } - gamemode cooperative, deathmatch, teamgame - { - drawimage translatable "STFBANY", 143, 169; - } - drawselectedinventory alternateonempty, INDEXFONT, 143, 168 - { - drawmugshot "STF", 5, 143, 168; - } -} - -statusbar inventory // Standard bar overlay (ZDoom Addition) -{ - drawinventorybar Doom, 7, INDEXFONT, 50, 170; -} - -statusbar inventoryfullscreen, fullscreenoffsets // ZDoom HUD overlay. -{ -} -*/ \ No newline at end of file diff --git a/wadsrc/static/zscript/statusbar/statusbar.txt b/wadsrc/static/zscript/statusbar/statusbar.txt index e7c85f615b..45d15c0d42 100644 --- a/wadsrc/static/zscript/statusbar/statusbar.txt +++ b/wadsrc/static/zscript/statusbar/statusbar.txt @@ -129,6 +129,7 @@ class BaseStatusBar native ui DI_TEXT_ALIGN_CENTER = 0x1000000, DI_ALPHAMAPPED = 0x2000000, + DI_NOSHADOW = 0x4000000, }; enum IconType @@ -151,14 +152,6 @@ class BaseStatusBar native ui HEXENARMOR_AMULET, }; - enum SBGameModes - { - GAMEMODE_SINGLEPLAYER = 0x1, - GAMEMODE_COOPERATIVE = 0x2, - GAMEMODE_DEATHMATCH = 0x4, - GAMEMODE_TEAMGAME = 0x8 - }; - enum AmmoModes { AMMO_PRIMARY, @@ -226,7 +219,7 @@ class BaseStatusBar native ui virtual bool MustDrawLog(int state) { return true; } native void RefreshBackground () const; - native TextureID GetMugshot(PlayerInfo player, String default_face, int accuracy, int stateflags=MugShot.STANDARD); + native TextureID GetMugshot(int accuracy, int stateflags=MugShot.STANDARD, String default_face = "STF"); // These functions are kept native solely for performance reasons. They get called repeatedly and can drag down performance easily if they get too slow. native Inventory ValidateInvFirst (int numVisible) const; @@ -338,6 +331,14 @@ class BaseStatusBar native ui return armor? armor.Amount : 0; } + int, int GetAmount(class item) + { + let it = CPlayer.mo.FindInventory(item); + int ret1 = it? it.Amount : GetDefaultByType(item).Amount; + int ret2 = it? it.MaxAmount : GetDefaultByType(item).MaxAmount; + return ret1, ret2; + } + int GetMaxAmount(class item) { let it = CPlayer.mo.FindInventory(item); @@ -393,20 +394,6 @@ class BaseStatusBar native ui // //============================================================================ - //============================================================================ - // - // checks current game mode against a flag mask - // - //============================================================================ - - bool CheckGameMode(int ValidModes) - { - return (!multiplayer && (ValidModes & GAMEMODE_SINGLEPLAYER)) || - (deathmatch && (ValidModes & GAMEMODE_DEATHMATCH)) || - (multiplayer && !deathmatch && (ValidModes & GAMEMODE_COOPERATIVE)) || - (teamplay && (ValidModes & GAMEMODE_TEAMGAME)); - } - //============================================================================ // // checks ammo use of current weapon