Skip to content

Commit

Permalink
Cleanup panel code (Part 2) (#7421)
Browse files Browse the repository at this point in the history
  • Loading branch information
kphoenix137 committed Sep 18, 2024
1 parent b0cb1b9 commit 6396af1
Show file tree
Hide file tree
Showing 27 changed files with 533 additions and 501 deletions.
402 changes: 217 additions & 185 deletions Source/control.cpp

Large diffs are not rendered by default.

70 changes: 35 additions & 35 deletions Source/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,30 @@ constexpr Size SidePanelSize { 320, 352 };

constexpr Rectangle InfoBoxRect = { { 177, 46 }, { 288, 64 } };

extern bool dropGoldFlag;
extern bool DropGoldFlag;
extern TextInputCursorState GoldDropCursor;
extern char GoldDropText[21];

extern bool chrbtn[4];
extern bool lvlbtndown;
extern bool chrbtnactive;
extern bool CharPanelButton[4];
extern bool LevelButtonDown;
extern bool CharPanelButtonActive;
extern UiFlags InfoColor;
extern int sbooktab;
extern bool talkflag;
extern bool sbookflag;
extern bool chrflag;
extern int SpellbookTab;
extern bool ChatFlag;
extern bool SpellbookFlag;
extern bool CharFlag;
extern StringOrView InfoString;
extern bool panelflag;
extern bool panbtndown;
extern bool spselflag;
extern bool MainPanelFlag;
extern bool MainPanelButtonDown;
extern bool SpellSelectFlag;
const Rectangle &GetMainPanel();
const Rectangle &GetLeftPanel();
const Rectangle &GetRightPanel();
bool IsLeftPanelOpen();
bool IsRightPanelOpen();
extern std::optional<OwnedSurface> pBtmBuff;
extern OptionalOwnedClxSpriteList pGBoxBuff;
extern Rectangle PanelButtonRect[8];
extern std::optional<OwnedSurface> BottomBuffer;
extern OptionalOwnedClxSpriteList GoldBoxBuffer;
extern Rectangle MainPanelButtonRect[8];

void CalculatePanelAreas();
bool IsChatAvailable();
Expand All @@ -82,8 +82,8 @@ inline bool CanPanelsCoverView()
return GetScreenWidth() <= mainPanel.size.width && GetScreenHeight() <= SidePanelSize.height + mainPanel.size.height;
}

void AddPanelString(std::string_view str);
void AddPanelString(std::string &&str);
void AddInfoBoxString(std::string_view str);
void AddInfoBoxString(std::string &&str);
void DrawPanelBox(const Surface &out, SDL_Rect srcRect, Point targetPosition);
Point GetPanelPosition(UiPanels panel, Point offset = { 0, 0 });

Expand Down Expand Up @@ -125,28 +125,28 @@ void DrawFlaskValues(const Surface &out, Point pos, int currValue, int maxValue)
*
* @see Player::UpdateHitPointPercentage() and Player::UpdateManaPercentage()
*/
void control_update_life_mana();
void UpdateLifeManaPercent();

void InitControlPan();
void DrawCtrlPan(const Surface &out);
void InitMainPanel();
void DrawMainPanel(const Surface &out);

/**
* Draws the control panel buttons in their current state. If the button is in the default
* state draw it from the panel cel(extract its sub-rect). Else draw it from the buttons cel.
*/
void DrawCtrlBtns(const Surface &out);
void DrawMainPanelButtons(const Surface &out);

/**
* Clears panel button flags.
*/
void ClearPanBtn();
void ResetMainPanelButtons();

/**
* Checks if the mouse cursor is within any of the panel buttons and flag it if so.
*/
void DoPanBtn();
void CheckMainPanelButton();

void control_check_btn_press();
void CheckMainPanelButtonDead();
void DoAutoMap();
void CycleAutomapType();

Expand All @@ -160,36 +160,36 @@ void CheckPanelInfo();
* Check if the mouse is within a control panel button that's flagged.
* Takes appropriate action if so.
*/
void CheckBtnUp();
void CheckMainPanelButtonUp();
void FreeControlPan();

/**
* Sets a string to be drawn in the info box and then draws it.
*/
void DrawInfoBox(const Surface &out);
void CheckLvlBtn();
void ReleaseLvlBtn();
void DrawLevelUpIcon(const Surface &out);
void CheckLevelButton();
void CheckLevelButtonUp();
void DrawLevelButton(const Surface &out);
void CheckChrBtns();
void ReleaseChrBtns(bool addAllStatPoints);
void DrawDurIcon(const Surface &out);
void RedBack(const Surface &out);
void DrawSpellBook(const Surface &out);
void DrawGoldSplit(const Surface &out);
void control_drop_gold(SDL_Keycode vkey);
void DrawTalkPan(const Surface &out);
bool control_check_talk_btn();
void control_release_talk_btn();
void control_type_message();
void control_reset_talk();
bool IsTalkActive();
void DrawChatBox(const Surface &out);
bool CheckMuteButton();
void CheckMuteButtonUp();
void TypeChatMessage();
void ResetChat();
bool IsChatActive();
bool HandleTalkTextInputEvent(const SDL_Event &event);
bool control_presskeys(SDL_Keycode vkey);
bool CheckKeypress(SDL_Keycode vkey);
void DiabloHotkeyMsg(uint32_t dwMsg);
void OpenGoldDrop(int8_t invIndex, int max);
void CloseGoldDrop();
int GetGoldDropMax();
bool HandleGoldDropTextInputEvent(const SDL_Event &event);
extern Rectangle CharButtonRect[4];
extern Rectangle CharPanelButtonRect[4];

} // namespace devilution
2 changes: 1 addition & 1 deletion Source/controls/controller_motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ bool IsPressedForMovement(ControllerButton button)
return !PadMenuNavigatorActive
&& IsControllerButtonPressed(button)
&& !IsMovementOverriddenByPadmapper(button)
&& !(spselflag && TriggersQuickSpellAction(button));
&& !(SpellSelectFlag && TriggersQuickSpellAction(button));
}

void SetSimulatingMouseWithPadmapper(bool value)
Expand Down
20 changes: 10 additions & 10 deletions Source/controls/game_controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrlEvent, Game
return true;
}
if (VirtualGamepadState.primaryActionButton.isHeld && VirtualGamepadState.primaryActionButton.didStateChange) {
if (!inGameMenu && !QuestLogIsOpen && !sbookflag) {
if (!inGameMenu && !QuestLogIsOpen && !SpellbookFlag) {
*action = GameAction(GameActionType_PRIMARY_ACTION);
if (ControllerActionHeld == GameActionType_NONE) {
ControllerActionHeld = GameActionType_PRIMARY_ACTION;
Expand All @@ -142,41 +142,41 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrlEvent, Game
return true;
}
if (VirtualGamepadState.secondaryActionButton.isHeld && VirtualGamepadState.secondaryActionButton.didStateChange) {
if (!inGameMenu && !QuestLogIsOpen && !sbookflag) {
if (!inGameMenu && !QuestLogIsOpen && !SpellbookFlag) {
*action = GameAction(GameActionType_SECONDARY_ACTION);
if (ControllerActionHeld == GameActionType_NONE)
ControllerActionHeld = GameActionType_SECONDARY_ACTION;
}
return true;
}
if (VirtualGamepadState.spellActionButton.isHeld && VirtualGamepadState.spellActionButton.didStateChange) {
if (!inGameMenu && !QuestLogIsOpen && !sbookflag) {
if (!inGameMenu && !QuestLogIsOpen && !SpellbookFlag) {
*action = GameAction(GameActionType_CAST_SPELL);
if (ControllerActionHeld == GameActionType_NONE)
ControllerActionHeld = GameActionType_CAST_SPELL;
}
return true;
}
if (VirtualGamepadState.cancelButton.isHeld && VirtualGamepadState.cancelButton.didStateChange) {
if (inGameMenu || DoomFlag || spselflag)
if (inGameMenu || DoomFlag || SpellSelectFlag)
*action = GameActionSendKey { SDLK_ESCAPE, false };
else if (invflag)
*action = GameAction(GameActionType_TOGGLE_INVENTORY);
else if (sbookflag)
else if (SpellbookFlag)
*action = GameAction(GameActionType_TOGGLE_SPELL_BOOK);
else if (QuestLogIsOpen)
*action = GameAction(GameActionType_TOGGLE_QUEST_LOG);
else if (chrflag)
else if (CharFlag)
*action = GameAction(GameActionType_TOGGLE_CHARACTER_INFO);
return true;
}
if (VirtualGamepadState.healthButton.isHeld && VirtualGamepadState.healthButton.didStateChange) {
if (!QuestLogIsOpen && !sbookflag && stextflag == TalkID::None)
if (!QuestLogIsOpen && !SpellbookFlag && stextflag == TalkID::None)
*action = GameAction(GameActionType_USE_HEALTH_POTION);
return true;
}
if (VirtualGamepadState.manaButton.isHeld && VirtualGamepadState.manaButton.didStateChange) {
if (!QuestLogIsOpen && !sbookflag && stextflag == TalkID::None)
if (!QuestLogIsOpen && !SpellbookFlag && stextflag == TalkID::None)
*action = GameAction(GameActionType_USE_MANA_POTION);
return true;
}
Expand All @@ -202,7 +202,7 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrlEvent, Game
translation = TranslateControllerButtonToMenuKey(ctrlEvent.button);
else if (QuestLogIsOpen)
translation = TranslateControllerButtonToQuestLogKey(ctrlEvent.button);
else if (sbookflag)
else if (SpellbookFlag)
translation = TranslateControllerButtonToSpellbookKey(ctrlEvent.button);

if (translation != SDLK_UNKNOWN) {
Expand Down Expand Up @@ -233,7 +233,7 @@ void PressControllerButton(ControllerButton button)

if (PadHotspellMenuActive) {
auto quickSpellAction = [](size_t slot) {
if (spselflag) {
if (SpellSelectFlag) {
SetSpeedSpell(slot);
return;
}
Expand Down
54 changes: 27 additions & 27 deletions Source/controls/plrctrls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ bool InGameMenu()
return stextflag != TalkID::None
|| HelpFlag
|| ChatLogFlag
|| talkflag
|| ChatFlag
|| qtextflag
|| gmenu_is_active()
|| PauseMode == 2
Expand Down Expand Up @@ -555,14 +555,14 @@ void AttrIncBtnSnap(AxisDirection dir)
if (dir.y == AxisDirectionY_NONE)
return;

if (chrbtnactive && MyPlayer->_pStatPts <= 0)
if (CharPanelButtonActive && MyPlayer->_pStatPts <= 0)
return;

// first, find our cursor location
int slot = 0;
Rectangle button;
for (int i = 0; i < 4; i++) {
button = CharButtonRect[i];
button = CharPanelButtonRect[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 = CharButtonRect[slot];
button = CharPanelButtonRect[slot];
button.position = GetPanelPosition(UiPanels::Character, button.position);
SetCursorPos(button.Center());
}
Expand Down Expand Up @@ -1054,7 +1054,7 @@ bool BlurInventory()
CloseInventory();
if (pcurs > CURSOR_HAND)
NewCursor(CURSOR_HAND);
if (chrflag)
if (CharFlag)
FocusOnCharInfo();

return true;
Expand Down Expand Up @@ -1242,11 +1242,11 @@ void SpellBookMove(AxisDirection dir)
dir = repeater.Get(dir);

if (dir.x == AxisDirectionX_LEFT) {
if (sbooktab > 0)
sbooktab--;
if (SpellbookTab > 0)
SpellbookTab--;
} else if (dir.x == AxisDirectionX_RIGHT) {
if ((gbIsHellfire && sbooktab < 4) || (!gbIsHellfire && sbooktab < 3))
sbooktab++;
if ((gbIsHellfire && SpellbookTab < 4) || (!gbIsHellfire && SpellbookTab < 3))
SpellbookTab++;
}
}

Expand Down Expand Up @@ -1335,13 +1335,13 @@ HandleLeftStickOrDPadFn GetLeftStickOrDPadGameUIHandler()
if (invflag) {
return &CheckInventoryMove;
}
if (chrflag && MyPlayer->_pStatPts > 0) {
if (CharFlag && MyPlayer->_pStatPts > 0) {
return &AttrIncBtnSnap;
}
if (spselflag) {
if (SpellSelectFlag) {
return &HotSpellMove;
}
if (sbookflag) {
if (SpellbookFlag) {
return &SpellBookMove;
}
if (QuestLogIsOpen) {
Expand Down Expand Up @@ -1603,21 +1603,21 @@ void ProcessGameAction(const GameAction &action)
break;
case GameActionType_TOGGLE_QUICK_SPELL_MENU:
if (!invflag || BlurInventory()) {
if (!spselflag)
if (!SpellSelectFlag)
DoSpeedBook();
else
spselflag = false;
SpellSelectFlag = false;
CloseCharPanel();
QuestLogIsOpen = false;
sbookflag = false;
SpellbookFlag = false;
CloseGoldWithdraw();
CloseStash();
}
break;
case GameActionType_TOGGLE_CHARACTER_INFO:
ToggleCharPanel();
if (chrflag) {
spselflag = false;
if (CharFlag) {
SpellSelectFlag = false;
if (pcurs == CURSOR_DISARM)
NewCursor(CURSOR_HAND);
FocusOnCharInfo();
Expand All @@ -1629,7 +1629,7 @@ void ProcessGameAction(const GameAction &action)
CloseCharPanel();
CloseGoldWithdraw();
CloseStash();
spselflag = false;
SpellSelectFlag = false;
} else {
QuestLogIsOpen = false;
}
Expand All @@ -1638,8 +1638,8 @@ void ProcessGameAction(const GameAction &action)
if (invflag) {
BlurInventory();
} else {
sbookflag = false;
spselflag = false;
SpellbookFlag = false;
SpellSelectFlag = false;
invflag = true;
if (pcurs == CURSOR_DISARM)
NewCursor(CURSOR_HAND);
Expand All @@ -1649,8 +1649,8 @@ void ProcessGameAction(const GameAction &action)
case GameActionType_TOGGLE_SPELL_BOOK:
if (BlurInventory()) {
CloseInventory();
spselflag = false;
sbookflag = !sbookflag;
SpellSelectFlag = false;
SpellbookFlag = !SpellbookFlag;
}
break;
}
Expand Down Expand Up @@ -1888,14 +1888,14 @@ void PerformPrimaryAction()
return;
}

if (spselflag) {
if (SpellSelectFlag) {
SetSpell();
return;
}

if (chrflag && !chrbtnactive && MyPlayer->_pStatPts > 0) {
if (CharFlag && !CharPanelButtonActive && MyPlayer->_pStatPts > 0) {
CheckChrBtns();
if (chrbtnactive)
if (CharPanelButtonActive)
ReleaseChrBtns(false);
return;
}
Expand Down Expand Up @@ -1969,7 +1969,7 @@ bool TryDropItem()

void PerformSpellAction()
{
if (InGameMenu() || QuestLogIsOpen || sbookflag)
if (InGameMenu() || QuestLogIsOpen || SpellbookFlag)
return;

if (invflag) {
Expand All @@ -1994,7 +1994,7 @@ void PerformSpellAction()
if (pcurs > CURSOR_HAND)
NewCursor(CURSOR_HAND);

if (spselflag) {
if (SpellSelectFlag) {
SetSpell();
return;
}
Expand Down
Loading

0 comments on commit 6396af1

Please sign in to comment.