From b916c8e4280c8f68d660254596712afc77c572da Mon Sep 17 00:00:00 2001 From: obligaron Date: Thu, 13 Apr 2023 22:48:39 +0200 Subject: [PATCH] Introduce Open/Close/ToggleCharPanel --- Source/control.cpp | 35 +++++++++++++++++++++++++---------- Source/control.h | 3 +++ Source/controls/plrctrls.cpp | 9 +++------ Source/diablo.cpp | 15 ++++++--------- Source/qol/chatlog.cpp | 2 +- Source/stores.cpp | 2 +- 6 files changed, 39 insertions(+), 27 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index 47c3dde4f..245d99c42 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -598,6 +598,27 @@ void FocusOnCharInfo() SetCursorPos(ChrBtnsRect[stat].Center()); } +void OpenCharPanel() +{ + QuestLogIsOpen = false; + CloseGoldWithdraw(); + IsStashOpen = false; + chrflag = true; +} + +void CloseCharPanel() +{ + chrflag = false; +} + +void ToggleCharPanel() +{ + if (chrflag) + CloseCharPanel(); + else + OpenCharPanel(); +} + void AddPanelString(string_view str) { if (InfoString.empty()) @@ -742,7 +763,7 @@ void InitControlPan() InfoString = {}; RedrawComponent(PanelDrawComponent::Health); RedrawComponent(PanelDrawComponent::Mana); - chrflag = false; + CloseCharPanel(); spselflag = false; sbooktab = 0; sbookflag = false; @@ -945,13 +966,10 @@ void CheckBtnUp() switch (i) { case PanelButtonCharinfo: - QuestLogIsOpen = false; - CloseGoldWithdraw(); - IsStashOpen = false; - chrflag = !chrflag; + ToggleCharPanel(); break; case PanelButtonQlog: - chrflag = false; + CloseCharPanel(); CloseGoldWithdraw(); IsStashOpen = false; if (!QuestLogIsOpen) @@ -1088,10 +1106,7 @@ void ReleaseLvlBtn() { const Point mainPanelPosition = GetMainPanel().position; if (MousePosition.x >= 40 + mainPanelPosition.x && MousePosition.x <= 81 + mainPanelPosition.x && MousePosition.y >= -39 + mainPanelPosition.y && MousePosition.y <= -17 + mainPanelPosition.y) { - QuestLogIsOpen = false; - CloseGoldWithdraw(); - IsStashOpen = false; - chrflag = true; + OpenCharPanel(); } lvlbtndown = false; } diff --git a/Source/control.h b/Source/control.h index a45f682b5..eae004760 100644 --- a/Source/control.h +++ b/Source/control.h @@ -64,6 +64,9 @@ bool IsChatAvailable(); * @brief Moves the mouse to the first attribute "+" button. */ void FocusOnCharInfo(); +void OpenCharPanel(); +void CloseCharPanel(); +void ToggleCharPanel(); /** * @brief Check if the UI can cover the game area entierly diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index 49435cbde..979ecc065 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -1623,7 +1623,7 @@ void ProcessGameAction(const GameAction &action) DoSpeedBook(); else spselflag = false; - chrflag = false; + CloseCharPanel(); QuestLogIsOpen = false; sbookflag = false; CloseGoldWithdraw(); @@ -1631,11 +1631,8 @@ void ProcessGameAction(const GameAction &action) } break; case GameActionType_TOGGLE_CHARACTER_INFO: - chrflag = !chrflag; + ToggleCharPanel(); if (chrflag) { - QuestLogIsOpen = false; - CloseGoldWithdraw(); - IsStashOpen = false; spselflag = false; if (pcurs == CURSOR_DISARM) NewCursor(CURSOR_HAND); @@ -1645,7 +1642,7 @@ void ProcessGameAction(const GameAction &action) case GameActionType_TOGGLE_QUEST_LOG: if (!QuestLogIsOpen) { StartQuestlog(); - chrflag = false; + CloseCharPanel(); CloseGoldWithdraw(); IsStashOpen = false; spselflag = false; diff --git a/Source/diablo.cpp b/Source/diablo.cpp index b6c820677..c0c29242c 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -454,7 +454,7 @@ void ClosePanels() } } CloseInventory(); - chrflag = false; + CloseCharPanel(); sbookflag = false; QuestLogIsOpen = false; } @@ -1448,7 +1448,7 @@ void HelpKeyPressed() LastMouseButtonAction = MouseActionType::None; } else { CloseInventory(); - chrflag = false; + CloseCharPanel(); sbookflag = false; spselflag = false; if (qtextflag && leveltype == DTYPE_TOWN) { @@ -1488,9 +1488,8 @@ void CharacterSheetKeyPressed() { if (stextflag != TalkID::None) return; - chrflag = !chrflag; if (!IsRightPanelOpen() && CanPanelsCoverView()) { - if (!chrflag) { // We closed the character sheet + if (chrflag) { // We are closing the character sheet if (MousePosition.x > 160 && MousePosition.y < GetMainPanel().position.y) { SetCursorPos(MousePosition - Displacement { 160, 0 }); } @@ -1500,9 +1499,7 @@ void CharacterSheetKeyPressed() } } } - QuestLogIsOpen = false; - CloseGoldWithdraw(); - IsStashOpen = false; + ToggleCharPanel(); } void QuestLogKeyPressed() @@ -1525,7 +1522,7 @@ void QuestLogKeyPressed() } } } - chrflag = false; + CloseCharPanel(); CloseGoldWithdraw(); IsStashOpen = false; } @@ -1534,7 +1531,7 @@ void DisplaySpellsKeyPressed() { if (stextflag != TalkID::None) return; - chrflag = false; + CloseCharPanel(); QuestLogIsOpen = false; CloseInventory(); sbookflag = false; diff --git a/Source/qol/chatlog.cpp b/Source/qol/chatlog.cpp index a3c7b4561..fbd635c8b 100644 --- a/Source/qol/chatlog.cpp +++ b/Source/qol/chatlog.cpp @@ -99,7 +99,7 @@ void ToggleChatLog() } else { stextflag = TalkID::None; CloseInventory(); - chrflag = false; + CloseCharPanel(); sbookflag = false; spselflag = false; if (qtextflag && leveltype == DTYPE_TOWN) { diff --git a/Source/stores.cpp b/Source/stores.cpp index 1ad17d31a..5f005d18f 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -2331,7 +2331,7 @@ void StartStore(TalkID s) } sbookflag = false; CloseInventory(); - chrflag = false; + CloseCharPanel(); RenderGold = false; QuestLogIsOpen = false; CloseGoldDrop();