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 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<std::size_t>(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);
}

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

1
Source/controls/plrctrls.cpp

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

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

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

1
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];

4
Source/levels/trigs.cpp

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

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

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

1
test/CMakeLists.txt

@ -14,7 +14,6 @@ set(tests
appfat_test
automap_test
codec_test
control_test
cursor_test
dead_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