Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup panel code (Part 1) #7417

Merged
merged 13 commits into from
Sep 16, 2024
298 changes: 170 additions & 128 deletions Source/control.cpp

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions Source/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ namespace devilution {

constexpr Size SidePanelSize { 320, 352 };

// Info box displacement of the top-left corner relative to GetMainPanel().position.
constexpr Displacement InfoBoxTopLeft { 177, 46 };
constexpr Size InfoBoxSize { 288, 64 };
constexpr Rectangle InfoBoxRect = { { 177, 46 }, { 288, 64 } };

extern bool dropGoldFlag;
extern TextInputCursorState GoldDropCursor;
Expand All @@ -62,7 +60,7 @@ bool IsLeftPanelOpen();
bool IsRightPanelOpen();
extern std::optional<OwnedSurface> pBtmBuff;
extern OptionalOwnedClxSpriteList pGBoxBuff;
extern SDL_Rect PanBtnPos[8];
extern Rectangle PanelButtonRect[8];

void CalculatePanelAreas();
bool IsChatAvailable();
Expand Down Expand Up @@ -123,7 +121,7 @@ void DrawFlaskValues(const Surface &out, Point pos, int currValue, int maxValue)
/**
* @brief calls on the active player object to update HP/Mana percentage variables
*
* This is used to ensure that DrawFlask routines display an accurate representation of the players health/mana
* This is used to ensure that DrawFlaskAbovePanel routines display an accurate representation of the players health/mana
*
* @see Player::UpdateHitPointPercentage() and Player::UpdateManaPercentage()
*/
Expand Down Expand Up @@ -192,6 +190,6 @@ void OpenGoldDrop(int8_t invIndex, int max);
void CloseGoldDrop();
int GetGoldDropMax();
bool HandleGoldDropTextInputEvent(const SDL_Event &event);
extern Rectangle ChrBtnsRect[4];
extern Rectangle CharButtonRect[4];

} // namespace devilution
4 changes: 2 additions & 2 deletions Source/controls/plrctrls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ void AttrIncBtnSnap(AxisDirection dir)
int slot = 0;
Rectangle button;
for (int i = 0; i < 4; i++) {
button = ChrBtnsRect[i];
button = CharButtonRect[i];
button.position = GetPanelPosition(UiPanels::Character, button.position);
if (button.contains(MousePosition)) {
slot = i;
Expand All @@ -579,7 +579,7 @@ void AttrIncBtnSnap(AxisDirection dir)
}

// move cursor to our new location
button = ChrBtnsRect[slot];
button = CharButtonRect[slot];
button.position = GetPanelPosition(UiPanels::Character, button.position);
SetCursorPos(button.Center());
}
Expand Down
2 changes: 1 addition & 1 deletion Source/controls/touch/renderers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ bool InteractsWithCharButton(Point point)
if (myPlayer.GetBaseAttributeValue(attribute) >= myPlayer.GetMaximumAttributeValue(attribute))
continue;
auto buttonId = static_cast<size_t>(attribute);
Rectangle button = ChrBtnsRect[buttonId];
Rectangle button = CharButtonRect[buttonId];
button.position = GetPanelPosition(UiPanels::Character, button.position);
if (button.contains(point)) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion Source/engine/render/scrollrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ void DrawMain(int dwHgt, bool drawDesc, bool drawHp, bool drawMana, bool drawSba
// When chat input is displayed, the belt is hidden and the chat moves up.
DoBlitScreen({ mainPanelPosition + Displacement { 171, 6 }, { 298, 116 } });
} else {
DoBlitScreen({ mainPanelPosition + InfoBoxTopLeft, InfoBoxSize });
DoBlitScreen({ mainPanelPosition + Displacement { InfoBoxRect.position.x, InfoBoxRect.position.y }, { InfoBoxRect.size } });
}
}
if (drawMana) {
Expand Down
2 changes: 1 addition & 1 deletion Source/panels/mainpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void DrawButtonOnPanel(Point position, std::string_view text, int frame)

void RenderMainButton(const Surface &out, int buttonId, std::string_view text, int frame)
{
Point panelPosition { PanBtnPos[buttonId].x + 4, PanBtnPos[buttonId].y + 17 };
Point panelPosition { PanelButtonRect[buttonId].position + Displacement { 4, 17 } };
DrawButtonOnPanel(panelPosition, text, frame);
if (IsChatAvailable())
DrawButtonOnPanel(panelPosition + Displacement { 0, GetMainPanel().size.height + 16 }, text, frame);
Expand Down
4 changes: 2 additions & 2 deletions Source/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ struct Player {
// Maximum achievable HP is approximately 1200. Diablo uses fixed point integers where the last 6 bits are
// fractional values. This means that we will never overflow HP values normally by doing this multiplication
// as the max value is representable in 17 bits and the multiplication result will be at most 23 bits
_pHPPer = std::clamp(_pHitPoints * 80 / _pMaxHP, 0, 80); // hp should never be greater than maxHP but just in case
_pHPPer = std::clamp(_pHitPoints * 81 / _pMaxHP, 0, 81); // hp should never be greater than maxHP but just in case
}

return _pHPPer;
Expand All @@ -700,7 +700,7 @@ struct Player {
if (_pMaxMana <= 0) {
_pManaPer = 0;
} else {
_pManaPer = std::clamp(_pMana * 80 / _pMaxMana, 0, 80);
_pManaPer = std::clamp(_pMana * 81 / _pMaxMana, 0, 81);
}

return _pManaPer;
Expand Down
Loading