diff --git a/Source/control.cpp b/Source/control.cpp index e35c74132..f2b66280d 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -69,7 +69,6 @@ int dropGoldValue; */ bool drawmanaflag; bool chrbtnactive; -int pnumlines; UiFlags InfoColor; int sbooktab; int8_t initialDropGoldIndex; @@ -150,7 +149,6 @@ char TalkMessage[MAX_SEND_STR_LEN]; bool TalkButtonsDown[3]; int sgbPlrTalkTbl; bool WhisperList[MAX_PLRS]; -char panelstr[4][64]; enum panel_button_id : uint8_t { PanelButtonCharinfo, @@ -261,20 +259,20 @@ void PrintInfo(const Surface &out) if (talkflag) return; - const int LineStart[] = { 70, 58, 52, 48, 46 }; - const int LineHeights[] = { 30, 24, 18, 15, 12 }; + const int space[] = { 18, 12, 6, 3, 0 }; + Rectangle infoArea { GetMainPanel().position + Displacement { 177, 46 }, { 288, 60 } }; - Rectangle line { GetMainPanel().position + Displacement { 177, LineStart[pnumlines] }, { 288, 12 } }; + const int newLineCount = std::count(InfoString.str().begin(), InfoString.str().end(), '\n'); + const int spaceIndex = std::min(4, newLineCount); + const int spacing = space[spaceIndex]; + const int lineHeight = 12 + spacing; - if (!InfoString.empty()) { - DrawString(out, InfoString, line, InfoColor | UiFlags::AlignCenter | UiFlags::KerningFitSpacing, 2); - line.position.y += LineHeights[pnumlines]; - } + // Adjusting the line height to add spacing between lines + // will also add additional space beneath the last line + // which throws off the vertical centering + infoArea.position.y += spacing / 2; - for (int i = 0; i < pnumlines; i++) { - DrawString(out, panelstr[i], line, InfoColor | UiFlags::AlignCenter | UiFlags::KerningFitSpacing, 2); - line.position.y += LineHeights[pnumlines]; - } + DrawString(out, InfoString, infoArea, InfoColor | UiFlags::AlignCenter | UiFlags::VerticalCenter | UiFlags::KerningFitSpacing, 2, lineHeight); } int CapStatPointsToAdd(int remainingStatPoints, const Player &player, CharacterAttribute attribute) @@ -463,17 +461,10 @@ bool IsChatAvailable() void AddPanelString(string_view str) { - if (pnumlines >= 4) { - Log("AddPanelString failed - not enough lines"); - return; - } - CopyUtf8(panelstr[pnumlines], str, sizeof(*panelstr)); - pnumlines++; -} - -void ClearPanel() -{ - pnumlines = 0; + if (InfoString.empty()) + InfoString = str; + else + InfoString = StrCat(InfoString, "\n", str); } Point GetPanelPosition(UiPanels panel, Point offset) @@ -602,7 +593,6 @@ void InitControlPan() buttonEnabled = false; chrbtnactive = false; InfoString = {}; - ClearPanel(); drawhpflag = true; drawmanaflag = true; chrflag = false; @@ -723,7 +713,6 @@ void CheckPanelInfo() { panelflag = false; const Point mainPanelPosition = GetMainPanel().position; - ClearPanel(); for (int i = 0; i < PanelButtonIndex; i++) { int xend = PanBtnPos[i].x + mainPanelPosition.x + PanBtnPos[i].w; int yend = PanBtnPos[i].y + mainPanelPosition.y + PanBtnPos[i].h; @@ -891,7 +880,6 @@ void DrawInfoBox(const Surface &out) if (!panelflag && !trigflag && pcursinvitem == -1 && pcursstashitem == uint16_t(-1) && !spselflag) { InfoString = {}; InfoColor = UiFlags::ColorWhite; - ClearPanel(); } Player &myPlayer = *MyPlayer; if (spselflag || trigflag) { @@ -919,7 +907,6 @@ void DrawInfoBox(const Surface &out) const auto &monster = Monsters[pcursmonst]; InfoColor = UiFlags::ColorWhite; InfoString = monster.name(); - ClearPanel(); if (monster.isUnique()) { InfoColor = UiFlags::ColorWhitegold; PrintUniqueHistory(); @@ -934,12 +921,11 @@ void DrawInfoBox(const Surface &out) InfoColor = UiFlags::ColorWhitegold; auto &target = Players[pcursplr]; InfoString = string_view(target._pName); - ClearPanel(); AddPanelString(fmt::format(fmt::runtime(_("{:s}, Level: {:d}")), _(ClassStrTbl[static_cast(target._pClass)]), target._pLevel)); AddPanelString(fmt::format(fmt::runtime(_("Hit Points {:d} of {:d}")), target._pHitPoints >> 6, target._pMaxHP >> 6)); } } - if (!InfoString.empty() || pnumlines != 0) + if (!InfoString.empty()) PrintInfo(out); } diff --git a/Source/control.h b/Source/control.h index b5f777152..2e0ba0c94 100644 --- a/Source/control.h +++ b/Source/control.h @@ -39,7 +39,6 @@ extern bool lvlbtndown; extern int dropGoldValue; extern bool drawmanaflag; extern bool chrbtnactive; -extern DVL_API_FOR_TEST int pnumlines; extern UiFlags InfoColor; extern int sbooktab; extern int8_t initialDropGoldIndex; @@ -77,7 +76,6 @@ void SetSpeedSpell(size_t slot); void ToggleSpell(size_t slot); void AddPanelString(string_view str); -void ClearPanel(); void DrawPanelBox(const Surface &out, SDL_Rect srcRect, Point targetPosition); Point GetPanelPosition(UiPanels panel, Point offset = { 0, 0 }); diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index 4d004fbdd..689a29dbc 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -1687,7 +1687,6 @@ void plrctrls_after_check_curs_move() } if (!invflag) { InfoString = {}; - ClearPanel(); FindActor(); FindItemOrObject(); FindTrigger(); diff --git a/Source/cursor.cpp b/Source/cursor.cpp index f7533446d..409335768 100644 --- a/Source/cursor.cpp +++ b/Source/cursor.cpp @@ -240,7 +240,6 @@ void CheckTown() if (missile._mitype == MIS_TOWN) { if (EntranceBoundaryContains(missile.position.tile, cursPosition)) { trigflag = true; - ClearPanel(); InfoString = _("Town Portal"); AddPanelString(fmt::format(fmt::runtime(_("from {:s}")), Players[missile._misource]._pName)); cursPosition = missile.position.tile; @@ -255,7 +254,6 @@ void CheckRportal() if (missile._mitype == MIS_RPORTAL) { if (EntranceBoundaryContains(missile.position.tile, cursPosition)) { trigflag = true; - ClearPanel(); InfoString = _("Portal to"); AddPanelString(!setlevel ? _("The Unholy Altar") : _("level 15")); cursPosition = missile.position.tile; diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 2265f4163..cf1d45b48 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -1279,7 +1279,7 @@ void TimeoutCursor(bool bTimeout) if (sgnTimeoutCurs == CURSOR_NONE && sgbMouseDown == CLICK_NONE) { sgnTimeoutCurs = pcurs; multi_net_ping(); - ClearPanel(); + InfoString = {}; AddPanelString(_("-- Network timeout --")); AddPanelString(_("-- Waiting for players --")); NewCursor(CURSOR_HOURGLASS); @@ -1289,7 +1289,7 @@ void TimeoutCursor(bool bTimeout) } else if (sgnTimeoutCurs != CURSOR_NONE) { NewCursor(sgnTimeoutCurs); sgnTimeoutCurs = CURSOR_NONE; - ClearPanel(); + InfoString = {}; force_redraw = 255; } } @@ -1299,7 +1299,7 @@ void HelpKeyPressed() if (HelpFlag) { HelpFlag = false; } else if (stextflag != STORE_NONE) { - ClearPanel(); + InfoString = {}; AddPanelString(_("No help available")); /// BUGFIX: message isn't displayed AddPanelString(_("while in stores")); LastMouseButtonAction = MouseActionType::None; diff --git a/Source/inv.cpp b/Source/inv.cpp index 1d4fa9a49..5a455be0a 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -1912,7 +1912,6 @@ int8_t CheckInvHLight() Item *pi = nullptr; Player &myPlayer = *MyPlayer; - ClearPanel(); if (r >= SLOTXY_HEAD_FIRST && r <= SLOTXY_HEAD_LAST) { rv = INVLOC_HEAD; pi = &myPlayer.InvBody[rv]; diff --git a/Source/levels/trigs.cpp b/Source/levels/trigs.cpp index 98ed4fc02..b1cebf83f 100644 --- a/Source/levels/trigs.cpp +++ b/Source/levels/trigs.cpp @@ -810,10 +810,6 @@ void CheckTrigForce() break; } } - - if (trigflag) { - ClearPanel(); - } } void CheckTriggers() diff --git a/Source/panels/spell_list.cpp b/Source/panels/spell_list.cpp index 9584e0fc9..4a3bd68f4 100644 --- a/Source/panels/spell_list.cpp +++ b/Source/panels/spell_list.cpp @@ -133,7 +133,6 @@ void DrawSpell(const Surface &out) void DrawSpellList(const Surface &out) { InfoString = {}; - ClearPanel(); Player &myPlayer = *MyPlayer; @@ -277,8 +276,6 @@ void SetSpell() return; } - ClearPanel(); - Player &myPlayer = *MyPlayer; myPlayer._pRSpell = pSpell; myPlayer._pRSplType = pSplType; diff --git a/Source/qol/stash.cpp b/Source/qol/stash.cpp index 287a18a72..e689b19a0 100644 --- a/Source/qol/stash.cpp +++ b/Source/qol/stash.cpp @@ -420,8 +420,6 @@ uint16_t CheckStashHLight(Point mousePosition) InfoColor = UiFlags::ColorWhite; - ClearPanel(); - StashStruct::StashCell itemId = Stash.GetItemIdAtPosition(slot); if (itemId == StashStruct::EmptyCell) { return -1; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4770e5e65..f03650ff4 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -14,7 +14,6 @@ set(tests appfat_test automap_test codec_test - control_test cursor_test dead_test diablo_test diff --git a/test/control_test.cpp b/test/control_test.cpp deleted file mode 100644 index 4cba8b1dd..000000000 --- a/test/control_test.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include - -#include "control.h" - -using namespace devilution; - -TEST(Control, ClearPanel) -{ - pnumlines = 1; - ClearPanel(); - EXPECT_EQ(pnumlines, 0); -}