Browse Source

Add OptionEntry Experience Bar

pull/3594/head
obligaron 4 years ago committed by Anders Jenbo
parent
commit
635f378722
  1. 2
      Source/msg.cpp
  2. 2
      Source/objects.cpp
  3. 16
      Source/options.cpp
  4. 2
      Source/options.h
  5. 4
      Source/player.cpp
  6. 6
      Source/qol/xpbar.cpp

2
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);

2
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]);

16
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<OptionEntryBase *> GameplayOptions::GetEntries()
{
@ -646,6 +657,7 @@ std::vector<OptionEntryBase *> GameplayOptions::GetEntries()
&friendlyFire,
&testBard,
&testBarbarian,
&experienceBar,
};
}

2
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. */

4
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;
}

6
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;

Loading…
Cancel
Save