Browse Source

Get rid of panelstr, pnumlines, and ClearPanel()

pull/5389/head
staphen 4 years ago committed by Anders Jenbo
parent
commit
8b6db3a678
  1. 46
      Source/control.cpp
  2. 2
      Source/control.h
  3. 1
      Source/controls/plrctrls.cpp
  4. 2
      Source/cursor.cpp
  5. 6
      Source/diablo.cpp
  6. 1
      Source/inv.cpp
  7. 4
      Source/levels/trigs.cpp
  8. 3
      Source/panels/spell_list.cpp
  9. 2
      Source/qol/stash.cpp
  10. 1
      test/CMakeLists.txt
  11. 12
      test/control_test.cpp

46
Source/control.cpp

@ -69,7 +69,6 @@ int dropGoldValue;
*/ */
bool drawmanaflag; bool drawmanaflag;
bool chrbtnactive; bool chrbtnactive;
int pnumlines;
UiFlags InfoColor; UiFlags InfoColor;
int sbooktab; int sbooktab;
int8_t initialDropGoldIndex; int8_t initialDropGoldIndex;
@ -150,7 +149,6 @@ char TalkMessage[MAX_SEND_STR_LEN];
bool TalkButtonsDown[3]; bool TalkButtonsDown[3];
int sgbPlrTalkTbl; int sgbPlrTalkTbl;
bool WhisperList[MAX_PLRS]; bool WhisperList[MAX_PLRS];
char panelstr[4][64];
enum panel_button_id : uint8_t { enum panel_button_id : uint8_t {
PanelButtonCharinfo, PanelButtonCharinfo,
@ -261,20 +259,20 @@ void PrintInfo(const Surface &out)
if (talkflag) if (talkflag)
return; return;
const int LineStart[] = { 70, 58, 52, 48, 46 }; const int space[] = { 18, 12, 6, 3, 0 };
const int LineHeights[] = { 30, 24, 18, 15, 12 }; 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()) { // Adjusting the line height to add spacing between lines
DrawString(out, InfoString, line, InfoColor | UiFlags::AlignCenter | UiFlags::KerningFitSpacing, 2); // will also add additional space beneath the last line
line.position.y += LineHeights[pnumlines]; // which throws off the vertical centering
} infoArea.position.y += spacing / 2;
for (int i = 0; i < pnumlines; i++) { DrawString(out, InfoString, infoArea, InfoColor | UiFlags::AlignCenter | UiFlags::VerticalCenter | UiFlags::KerningFitSpacing, 2, lineHeight);
DrawString(out, panelstr[i], line, InfoColor | UiFlags::AlignCenter | UiFlags::KerningFitSpacing, 2);
line.position.y += LineHeights[pnumlines];
}
} }
int CapStatPointsToAdd(int remainingStatPoints, const Player &player, CharacterAttribute attribute) int CapStatPointsToAdd(int remainingStatPoints, const Player &player, CharacterAttribute attribute)
@ -463,17 +461,10 @@ bool IsChatAvailable()
void AddPanelString(string_view str) void AddPanelString(string_view str)
{ {
if (pnumlines >= 4) { if (InfoString.empty())
Log("AddPanelString failed - not enough lines"); InfoString = str;
return; else
} InfoString = StrCat(InfoString, "\n", str);
CopyUtf8(panelstr[pnumlines], str, sizeof(*panelstr));
pnumlines++;
}
void ClearPanel()
{
pnumlines = 0;
} }
Point GetPanelPosition(UiPanels panel, Point offset) Point GetPanelPosition(UiPanels panel, Point offset)
@ -602,7 +593,6 @@ void InitControlPan()
buttonEnabled = false; buttonEnabled = false;
chrbtnactive = false; chrbtnactive = false;
InfoString = {}; InfoString = {};
ClearPanel();
drawhpflag = true; drawhpflag = true;
drawmanaflag = true; drawmanaflag = true;
chrflag = false; chrflag = false;
@ -723,7 +713,6 @@ void CheckPanelInfo()
{ {
panelflag = false; panelflag = false;
const Point mainPanelPosition = GetMainPanel().position; const Point mainPanelPosition = GetMainPanel().position;
ClearPanel();
for (int i = 0; i < PanelButtonIndex; i++) { for (int i = 0; i < PanelButtonIndex; i++) {
int xend = PanBtnPos[i].x + mainPanelPosition.x + PanBtnPos[i].w; int xend = PanBtnPos[i].x + mainPanelPosition.x + PanBtnPos[i].w;
int yend = PanBtnPos[i].y + mainPanelPosition.y + PanBtnPos[i].h; 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) { if (!panelflag && !trigflag && pcursinvitem == -1 && pcursstashitem == uint16_t(-1) && !spselflag) {
InfoString = {}; InfoString = {};
InfoColor = UiFlags::ColorWhite; InfoColor = UiFlags::ColorWhite;
ClearPanel();
} }
Player &myPlayer = *MyPlayer; Player &myPlayer = *MyPlayer;
if (spselflag || trigflag) { if (spselflag || trigflag) {
@ -919,7 +907,6 @@ void DrawInfoBox(const Surface &out)
const auto &monster = Monsters[pcursmonst]; const auto &monster = Monsters[pcursmonst];
InfoColor = UiFlags::ColorWhite; InfoColor = UiFlags::ColorWhite;
InfoString = monster.name(); InfoString = monster.name();
ClearPanel();
if (monster.isUnique()) { if (monster.isUnique()) {
InfoColor = UiFlags::ColorWhitegold; InfoColor = UiFlags::ColorWhitegold;
PrintUniqueHistory(); PrintUniqueHistory();
@ -934,12 +921,11 @@ void DrawInfoBox(const Surface &out)
InfoColor = UiFlags::ColorWhitegold; InfoColor = UiFlags::ColorWhitegold;
auto &target = Players[pcursplr]; auto &target = Players[pcursplr];
InfoString = string_view(target._pName); InfoString = string_view(target._pName);
ClearPanel();
AddPanelString(fmt::format(fmt::runtime(_("{:s}, Level: {:d}")), _(ClassStrTbl[static_cast<std::size_t>(target._pClass)]), target._pLevel)); AddPanelString(fmt::format(fmt::runtime(_("{:s}, Level: {:d}")), _(ClassStrTbl[static_cast<std::size_t>(target._pClass)]), target._pLevel));
AddPanelString(fmt::format(fmt::runtime(_("Hit Points {:d} of {:d}")), target._pHitPoints >> 6, target._pMaxHP >> 6)); 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); PrintInfo(out);
} }

2
Source/control.h

@ -39,7 +39,6 @@ extern bool lvlbtndown;
extern int dropGoldValue; extern int dropGoldValue;
extern bool drawmanaflag; extern bool drawmanaflag;
extern bool chrbtnactive; extern bool chrbtnactive;
extern DVL_API_FOR_TEST int pnumlines;
extern UiFlags InfoColor; extern UiFlags InfoColor;
extern int sbooktab; extern int sbooktab;
extern int8_t initialDropGoldIndex; extern int8_t initialDropGoldIndex;
@ -77,7 +76,6 @@ void SetSpeedSpell(size_t slot);
void ToggleSpell(size_t slot); void ToggleSpell(size_t slot);
void AddPanelString(string_view str); void AddPanelString(string_view str);
void ClearPanel();
void DrawPanelBox(const Surface &out, SDL_Rect srcRect, Point targetPosition); void DrawPanelBox(const Surface &out, SDL_Rect srcRect, Point targetPosition);
Point GetPanelPosition(UiPanels panel, Point offset = { 0, 0 }); Point GetPanelPosition(UiPanels panel, Point offset = { 0, 0 });

1
Source/controls/plrctrls.cpp

@ -1687,7 +1687,6 @@ void plrctrls_after_check_curs_move()
} }
if (!invflag) { if (!invflag) {
InfoString = {}; InfoString = {};
ClearPanel();
FindActor(); FindActor();
FindItemOrObject(); FindItemOrObject();
FindTrigger(); FindTrigger();

2
Source/cursor.cpp

@ -240,7 +240,6 @@ void CheckTown()
if (missile._mitype == MIS_TOWN) { if (missile._mitype == MIS_TOWN) {
if (EntranceBoundaryContains(missile.position.tile, cursPosition)) { if (EntranceBoundaryContains(missile.position.tile, cursPosition)) {
trigflag = true; trigflag = true;
ClearPanel();
InfoString = _("Town Portal"); InfoString = _("Town Portal");
AddPanelString(fmt::format(fmt::runtime(_("from {:s}")), Players[missile._misource]._pName)); AddPanelString(fmt::format(fmt::runtime(_("from {:s}")), Players[missile._misource]._pName));
cursPosition = missile.position.tile; cursPosition = missile.position.tile;
@ -255,7 +254,6 @@ void CheckRportal()
if (missile._mitype == MIS_RPORTAL) { if (missile._mitype == MIS_RPORTAL) {
if (EntranceBoundaryContains(missile.position.tile, cursPosition)) { if (EntranceBoundaryContains(missile.position.tile, cursPosition)) {
trigflag = true; trigflag = true;
ClearPanel();
InfoString = _("Portal to"); InfoString = _("Portal to");
AddPanelString(!setlevel ? _("The Unholy Altar") : _("level 15")); AddPanelString(!setlevel ? _("The Unholy Altar") : _("level 15"));
cursPosition = missile.position.tile; cursPosition = missile.position.tile;

6
Source/diablo.cpp

@ -1279,7 +1279,7 @@ void TimeoutCursor(bool bTimeout)
if (sgnTimeoutCurs == CURSOR_NONE && sgbMouseDown == CLICK_NONE) { if (sgnTimeoutCurs == CURSOR_NONE && sgbMouseDown == CLICK_NONE) {
sgnTimeoutCurs = pcurs; sgnTimeoutCurs = pcurs;
multi_net_ping(); multi_net_ping();
ClearPanel(); InfoString = {};
AddPanelString(_("-- Network timeout --")); AddPanelString(_("-- Network timeout --"));
AddPanelString(_("-- Waiting for players --")); AddPanelString(_("-- Waiting for players --"));
NewCursor(CURSOR_HOURGLASS); NewCursor(CURSOR_HOURGLASS);
@ -1289,7 +1289,7 @@ void TimeoutCursor(bool bTimeout)
} else if (sgnTimeoutCurs != CURSOR_NONE) { } else if (sgnTimeoutCurs != CURSOR_NONE) {
NewCursor(sgnTimeoutCurs); NewCursor(sgnTimeoutCurs);
sgnTimeoutCurs = CURSOR_NONE; sgnTimeoutCurs = CURSOR_NONE;
ClearPanel(); InfoString = {};
force_redraw = 255; force_redraw = 255;
} }
} }
@ -1299,7 +1299,7 @@ void HelpKeyPressed()
if (HelpFlag) { if (HelpFlag) {
HelpFlag = false; HelpFlag = false;
} else if (stextflag != STORE_NONE) { } else if (stextflag != STORE_NONE) {
ClearPanel(); InfoString = {};
AddPanelString(_("No help available")); /// BUGFIX: message isn't displayed AddPanelString(_("No help available")); /// BUGFIX: message isn't displayed
AddPanelString(_("while in stores")); AddPanelString(_("while in stores"));
LastMouseButtonAction = MouseActionType::None; LastMouseButtonAction = MouseActionType::None;

1
Source/inv.cpp

@ -1912,7 +1912,6 @@ int8_t CheckInvHLight()
Item *pi = nullptr; Item *pi = nullptr;
Player &myPlayer = *MyPlayer; Player &myPlayer = *MyPlayer;
ClearPanel();
if (r >= SLOTXY_HEAD_FIRST && r <= SLOTXY_HEAD_LAST) { if (r >= SLOTXY_HEAD_FIRST && r <= SLOTXY_HEAD_LAST) {
rv = INVLOC_HEAD; rv = INVLOC_HEAD;
pi = &myPlayer.InvBody[rv]; pi = &myPlayer.InvBody[rv];

4
Source/levels/trigs.cpp

@ -810,10 +810,6 @@ void CheckTrigForce()
break; break;
} }
} }
if (trigflag) {
ClearPanel();
}
} }
void CheckTriggers() void CheckTriggers()

3
Source/panels/spell_list.cpp

@ -133,7 +133,6 @@ void DrawSpell(const Surface &out)
void DrawSpellList(const Surface &out) void DrawSpellList(const Surface &out)
{ {
InfoString = {}; InfoString = {};
ClearPanel();
Player &myPlayer = *MyPlayer; Player &myPlayer = *MyPlayer;
@ -277,8 +276,6 @@ void SetSpell()
return; return;
} }
ClearPanel();
Player &myPlayer = *MyPlayer; Player &myPlayer = *MyPlayer;
myPlayer._pRSpell = pSpell; myPlayer._pRSpell = pSpell;
myPlayer._pRSplType = pSplType; myPlayer._pRSplType = pSplType;

2
Source/qol/stash.cpp

@ -420,8 +420,6 @@ uint16_t CheckStashHLight(Point mousePosition)
InfoColor = UiFlags::ColorWhite; InfoColor = UiFlags::ColorWhite;
ClearPanel();
StashStruct::StashCell itemId = Stash.GetItemIdAtPosition(slot); StashStruct::StashCell itemId = Stash.GetItemIdAtPosition(slot);
if (itemId == StashStruct::EmptyCell) { if (itemId == StashStruct::EmptyCell) {
return -1; return -1;

1
test/CMakeLists.txt

@ -14,7 +14,6 @@ set(tests
appfat_test appfat_test
automap_test automap_test
codec_test codec_test
control_test
cursor_test cursor_test
dead_test dead_test
diablo_test diablo_test

12
test/control_test.cpp

@ -1,12 +0,0 @@
#include <gtest/gtest.h>
#include "control.h"
using namespace devilution;
TEST(Control, ClearPanel)
{
pnumlines = 1;
ClearPanel();
EXPECT_EQ(pnumlines, 0);
}
Loading…
Cancel
Save