From 82ab76b22bcc58b7ad4ab31436dd708bcdfc705d Mon Sep 17 00:00:00 2001 From: qndel Date: Sat, 24 Oct 2020 04:10:54 +0200 Subject: [PATCH] :sparkles: Experience bar --- Source/diablo.cpp | 24 +++++++++++++----------- Source/diablo.h | 1 + Source/player.h | 1 + Source/scrollrt.cpp | 1 + SourceX/qol.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ SourceX/qol.h | 1 + 6 files changed, 57 insertions(+), 11 deletions(-) diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 46ad19424..5bfcfe78e 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -423,6 +423,7 @@ static void SaveOptions() setIniInt("Game", "Cow Quest", sgOptions.bCowQuest); setIniInt("Game", "Test Bard", sgOptions.bTestBard); setIniInt("Game", "Test Barbarian", sgOptions.bTestBarbarian); + setIniInt("Game", "Experience Bar", sgOptions.bExperienceBar); setIniInt("Game", "Enemy Health Bar", sgOptions.bEnemyHealthBar); setIniValue("Network", "Bind Address", sgOptions.szBindAddress); @@ -465,6 +466,7 @@ static void LoadOptions() sgOptions.bCowQuest = getIniBool("Game", "Cow Quest", false); sgOptions.bTestBard = getIniBool("Game", "Test Bard", false); sgOptions.bTestBarbarian = getIniBool("Game", "Test Barbarian", false); + sgOptions.bExperienceBar = getIniBool("Game", "Experience Bar", false); sgOptions.bEnemyHealthBar = getIniBool("Game", "Enemy Health Bar", false); getIniValue("Network", "Bind Address", sgOptions.szBindAddress, sizeof(sgOptions.szBindAddress), "0.0.0.0"); @@ -849,17 +851,17 @@ static void ReleaseKey(int vkey) static void ClosePanels() { - if (PANELS_COVER) { - if (!chrflag && !questlog && (invflag || sbookflag) && MouseX < 480 && MouseY < PANEL_TOP) { - SetCursorPos(MouseX + 160, MouseY); - } else if (!invflag && !sbookflag && (chrflag || questlog) && MouseX > 160 && MouseY < PANEL_TOP) { - SetCursorPos(MouseX - 160, MouseY); - } - } - invflag = FALSE; - chrflag = FALSE; - sbookflag = FALSE; - questlog = FALSE; + if (PANELS_COVER) { + if (!chrflag && !questlog && (invflag || sbookflag) && MouseX < 480 && MouseY < PANEL_TOP) { + SetCursorPos(MouseX + 160, MouseY); + } else if (!invflag && !sbookflag && (chrflag || questlog) && MouseX > 160 && MouseY < PANEL_TOP) { + SetCursorPos(MouseX - 160, MouseY); + } + } + invflag = FALSE; + chrflag = FALSE; + sbookflag = FALSE; + questlog = FALSE; } bool PressEscKey() diff --git a/Source/diablo.h b/Source/diablo.h index f349a3f3f..0f70bb1d0 100644 --- a/Source/diablo.h +++ b/Source/diablo.h @@ -43,6 +43,7 @@ typedef struct Options { bool bCowQuest; // Enable the cow quest bool bTestBard; // Enable the bard hero class bool bTestBarbarian; // Enable the babarian hero class + bool bExperienceBar; // Show the current level progress bool bEnemyHealthBar; // Show enemy health at the top of the screen char szBindAddress[129]; // Optionally bind to a specific network interface diff --git a/Source/player.h b/Source/player.h index a2b43381e..1b4c740a2 100644 --- a/Source/player.h +++ b/Source/player.h @@ -268,6 +268,7 @@ extern int MagicTbl[NUM_CLASSES]; extern int DexterityTbl[NUM_CLASSES]; extern int VitalityTbl[NUM_CLASSES]; extern int MaxStats[NUM_CLASSES][4]; +extern int ExpLvlsTbl[MAXCHARLEVEL]; extern const char *const ClassStrTblOld[]; extern const char *const ClassStrTbl[]; diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index d6cf1b477..66ff4ef5a 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -1579,6 +1579,7 @@ void DrawAndBlit() DrawTalkPan(out); hgt = SCREEN_HEIGHT; } + DrawXPBar(); scrollrt_draw_cursor_item(); DrawFPS(out); diff --git a/SourceX/qol.cpp b/SourceX/qol.cpp index fa7641d6f..d28466d63 100644 --- a/SourceX/qol.cpp +++ b/SourceX/qol.cpp @@ -134,4 +134,44 @@ void DrawMonsterHealthBar() PrintGameStr(out, xPos2 + width / 2 - GetTextWidth(vulnText), yPos + yOffset + height + borderSize + 12, vulnText, COL_RED); } +void DrawXPBar() +{ + if (!sgOptions.bExperienceBar) + return; + + int barWidth = 306; + int barHeight = 5; + int yPos = SCREEN_HEIGHT - 9; // y position of xp bar + int xPos = (SCREEN_WIDTH - barWidth) / 2 + 5; // x position of xp bar + int dividerHeight = 3; + int numDividers = 10; + int barColor = 198; + int emptyBarColor = 0; + int frameColor = 245; + bool space = true; // add 1 pixel separator on top/bottom of the bar + + CelOutputBuffer out = GlobalBackBuffer(); + PrintGameStr(out, xPos - 22, yPos + 6, "XP", COL_WHITE); + int charLevel = plr[myplr]._pLevel; + if (charLevel == MAXCHARLEVEL - 1) + return; + + int curXp = ExpLvlsTbl[charLevel]; + int prevXp = ExpLvlsTbl[charLevel - 1]; + int prevXpDelta = curXp - prevXp; + int prevXpDelta_1 = plr[myplr]._pExperience - prevXp; + if (plr[myplr]._pExperience < prevXp) + return; + + int visibleBar = barWidth * (unsigned __int64)prevXpDelta_1 / prevXpDelta; + FillRect(xPos, yPos, barWidth, barHeight, emptyBarColor); + FillRect(xPos, yPos + (space ? 1 : 0), visibleBar, barHeight - (space ? 2 : 0), barColor); + FastDrawHorizLine(xPos - 1, yPos - 1, barWidth + 2, frameColor); + FastDrawHorizLine(xPos - 1, yPos + barHeight, barWidth + 2, frameColor); + FastDrawVertLine(xPos - 1, yPos - 1, barHeight + 2, frameColor); + FastDrawVertLine(xPos + barWidth, yPos - 1, barHeight + 2, frameColor); + for (int i = 1; i < numDividers; i++) + FastDrawVertLine(xPos - 1 + (barWidth * i / numDividers), yPos - dividerHeight - 1, barHeight + dividerHeight * 2 + 2, frameColor); +} + DEVILUTION_END_NAMESPACE diff --git a/SourceX/qol.h b/SourceX/qol.h index a3b533aa0..d62cd485e 100644 --- a/SourceX/qol.h +++ b/SourceX/qol.h @@ -9,6 +9,7 @@ DEVILUTION_BEGIN_NAMESPACE void DrawMonsterHealthBar(); +void DrawXPBar(); DEVILUTION_END_NAMESPACE