From 635f378722bc4462ed7550fde644a422c0844b7f Mon Sep 17 00:00:00 2001 From: obligaron Date: Mon, 8 Nov 2021 00:04:44 +0100 Subject: [PATCH] Add OptionEntry Experience Bar --- Source/msg.cpp | 2 +- Source/objects.cpp | 2 +- Source/options.cpp | 16 ++++++++++++++-- Source/options.h | 2 +- Source/player.cpp | 4 ++-- Source/qol/xpbar.cpp | 6 +++--- 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Source/msg.cpp b/Source/msg.cpp index 98ed0760f..a0adb21eb 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -1844,7 +1844,7 @@ DWORD OnCheatExperience(const TCmd *pCmd, int pnum) // NOLINT(misc-unused-parame SendPacket(pnum, pCmd, sizeof(*pCmd)); else if (Players[pnum]._pLevel < MAXCHARLEVEL - 1) { Players[pnum]._pExperience = Players[pnum]._pNextExper; - if (sgOptions.Gameplay.bExperienceBar) { + if (*sgOptions.Gameplay.experienceBar) { force_redraw = 255; } NextPlrLevel(pnum); diff --git a/Source/objects.cpp b/Source/objects.cpp index 69e97a4f2..273b51aee 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -3346,7 +3346,7 @@ bool OperateShrineGlowing(int pnum) else myPlayer._pExperience = 0; - if (sgOptions.Gameplay.bExperienceBar) + if (*sgOptions.Gameplay.experienceBar) force_redraw = 255; CheckStats(Players[pnum]); diff --git a/Source/options.cpp b/Source/options.cpp index 6464b8f48..724dc7a4a 100644 --- a/Source/options.cpp +++ b/Source/options.cpp @@ -28,6 +28,7 @@ #include "diablo.h" #include "engine/demomode.h" #include "options.h" +#include "qol/xpbar.h" #include "utils/file_util.h" #include "utils/language.h" #include "utils/paths.h" @@ -198,6 +199,16 @@ void OptionGrabInputChanged() #endif } +void OptionExperienceBarChanged() +{ + if (!gbRunGame) + return; + if (*sgOptions.Gameplay.experienceBar) + InitXPBar(); + else + FreeXPBar(); +} + } // namespace void SetIniValue(const char *sectionName, const char *keyName, const char *value, int len) @@ -275,7 +286,6 @@ void LoadOptions() sgOptions.Graphics.bShowFPS = (GetIniInt("Graphics", "Show FPS", 0) != 0); sgOptions.Gameplay.nTickRate = GetIniInt("Game", "Speed", 20); - sgOptions.Gameplay.bExperienceBar = GetIniBool("Game", "Experience Bar", AUTO_PICKUP_DEFAULT(false)); sgOptions.Gameplay.bEnemyHealthBar = GetIniBool("Game", "Enemy Health Bar", false); sgOptions.Gameplay.bAutoGoldPickup = GetIniBool("Game", "Auto Gold Pickup", AUTO_PICKUP_DEFAULT(false)); sgOptions.Gameplay.bAdriaRefillsMana = GetIniBool("Game", "Adria Refills Mana", false); @@ -423,7 +433,6 @@ void SaveOptions() SetIniValue("Graphics", "Show FPS", sgOptions.Graphics.bShowFPS); SetIniValue("Game", "Speed", sgOptions.Gameplay.nTickRate); - SetIniValue("Game", "Experience Bar", sgOptions.Gameplay.bExperienceBar); SetIniValue("Game", "Enemy Health Bar", sgOptions.Gameplay.bEnemyHealthBar); SetIniValue("Game", "Auto Gold Pickup", sgOptions.Gameplay.bAutoGoldPickup); SetIniValue("Game", "Adria Refills Mana", sgOptions.Gameplay.bAdriaRefillsMana); @@ -633,8 +642,10 @@ GameplayOptions::GameplayOptions() , friendlyFire("Friendly Fire", OptionEntryFlags::CantChangeInMultiPlayer, N_("Friendly Fire"), N_("Allow arrow/spell damage between players in multiplayer even when the friendly mode is on."), true) , testBard("Test Bard", OptionEntryFlags::CantChangeInGame, N_("Test Bard"), N_("Force the Bard character type to appear in the hero selection menu."), false) , testBarbarian("Test Barbarian", OptionEntryFlags::CantChangeInGame, N_("Test Barbarian"), N_("Force the Barbarian character type to appear in the hero selection menu."), false) + , experienceBar("Experience Bar", OptionEntryFlags::None, N_("Experience Bar"), N_("Experience Bar is added to the UI at the bottom of the screen."), AUTO_PICKUP_DEFAULT(false)) { grabInput.SetValueChangedCallback(OptionGrabInputChanged); + grabInput.SetValueChangedCallback(OptionExperienceBarChanged); } std::vector GameplayOptions::GetEntries() { @@ -646,6 +657,7 @@ std::vector GameplayOptions::GetEntries() &friendlyFire, &testBard, &testBarbarian, + &experienceBar, }; } diff --git a/Source/options.h b/Source/options.h index 21370fd84..bd2e7b291 100644 --- a/Source/options.h +++ b/Source/options.h @@ -286,7 +286,7 @@ struct GameplayOptions : OptionCategoryBase { /** @brief Enable the babarian hero class. */ OptionEntryBoolean testBarbarian; /** @brief Show the current level progress. */ - bool bExperienceBar; + OptionEntryBoolean experienceBar; /** @brief Show enemy health at the top of the screen. */ bool bEnemyHealthBar; /** @brief Automatically pick up gold when walking over it. */ diff --git a/Source/player.cpp b/Source/player.cpp index 6439ec238..8090e1019 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -1874,7 +1874,7 @@ void ValidatePlayer() myPlayer._pLevel = MAXCHARLEVEL - 1; if (myPlayer._pExperience > myPlayer._pNextExper) { myPlayer._pExperience = myPlayer._pNextExper; - if (sgOptions.Gameplay.bExperienceBar) { + if (*sgOptions.Gameplay.experienceBar) { force_redraw = 255; } } @@ -2628,7 +2628,7 @@ void AddPlrExperience(int pnum, int lvl, int exp) // Overflow is only possible if a kill grants more than (2^32-1 - MaxExperience) XP in one go, which doesn't happen in normal gameplay player._pExperience = std::min(player._pExperience + clampedExp, MaxExperience); - if (sgOptions.Gameplay.bExperienceBar) { + if (*sgOptions.Gameplay.experienceBar) { force_redraw = 255; } diff --git a/Source/qol/xpbar.cpp b/Source/qol/xpbar.cpp index 13ad8e206..9ce0007e5 100644 --- a/Source/qol/xpbar.cpp +++ b/Source/qol/xpbar.cpp @@ -49,7 +49,7 @@ void DrawEndCap(const Surface &out, Point point, int idx, const ColorGradient &g void InitXPBar() { - if (sgOptions.Gameplay.bExperienceBar) { + if (*sgOptions.Gameplay.experienceBar) { LoadMaskedArt("data\\xpbar.pcx", &xpbarArt, 1, 1); if (xpbarArt.surface == nullptr) { @@ -67,7 +67,7 @@ void FreeXPBar() void DrawXPBar(const Surface &out) { - if (!sgOptions.Gameplay.bExperienceBar || talkflag) + if (!*sgOptions.Gameplay.experienceBar || talkflag) return; const auto &player = Players[MyPlayerId]; @@ -109,7 +109,7 @@ void DrawXPBar(const Surface &out) bool CheckXPBarInfo() { - if (!sgOptions.Gameplay.bExperienceBar) + if (!*sgOptions.Gameplay.experienceBar) return false; const int backX = PANEL_LEFT + PANEL_WIDTH / 2 - 155;