From 8eddf55c3f082c711fde7ca8f63d6bbce187b9ae Mon Sep 17 00:00:00 2001 From: Eric Robinson <68359262+kphoenix137@users.noreply.github.com> Date: Sat, 15 Mar 2025 17:18:28 -0400 Subject: [PATCH] Stores - IsPlayerInStore() (#7843) --- Source/control.cpp | 2 +- Source/controls/game_controls.cpp | 8 ++--- Source/controls/plrctrls.cpp | 4 +-- Source/controls/touch/event_handlers.cpp | 2 +- Source/controls/touch/renderers.cpp | 2 +- Source/diablo.cpp | 40 ++++++++++++------------ Source/engine/render/scrollrt.cpp | 4 +-- Source/inv.cpp | 2 +- Source/qol/itemlabels.cpp | 6 ++-- Source/qol/stash.cpp | 2 +- Source/stores.cpp | 9 ++++-- Source/stores.h | 1 + Source/track.cpp | 2 +- 13 files changed, 45 insertions(+), 39 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index cb046f8ee..61a5e9954 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -690,7 +690,7 @@ bool IsLevelUpButtonVisible() if (ControlMode == ControlTypes::VirtualGamepad) { return false; } - if (ActiveStore != TalkID::None || IsStashOpen) { + if (IsPlayerInStore() || IsStashOpen) { return false; } if (QuestLogIsOpen && GetLeftPanel().contains(GetMainPanel().position + Displacement { 0, -74 })) { diff --git a/Source/controls/game_controls.cpp b/Source/controls/game_controls.cpp index 0a58ead49..3d5dcc352 100644 --- a/Source/controls/game_controls.cpp +++ b/Source/controls/game_controls.cpp @@ -115,7 +115,7 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrlEvent, Game if (ControllerActionHeld == GameActionType_NONE) { ControllerActionHeld = GameActionType_PRIMARY_ACTION; } - } else if (sgpCurrentMenu != nullptr || ActiveStore != TalkID::None || QuestLogIsOpen) { + } else if (sgpCurrentMenu != nullptr || IsPlayerInStore() || QuestLogIsOpen) { *action = GameActionSendKey { SDLK_RETURN, false }; } else { *action = GameActionSendKey { SDLK_SPACE, false }; @@ -152,12 +152,12 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrlEvent, Game return true; } if (VirtualGamepadState.healthButton.isHeld && VirtualGamepadState.healthButton.didStateChange) { - if (!QuestLogIsOpen && !SpellbookFlag && ActiveStore == TalkID::None) + if (!QuestLogIsOpen && !SpellbookFlag && !IsPlayerInStore()) *action = GameAction(GameActionType_USE_HEALTH_POTION); return true; } if (VirtualGamepadState.manaButton.isHeld && VirtualGamepadState.manaButton.didStateChange) { - if (!QuestLogIsOpen && !SpellbookFlag && ActiveStore == TalkID::None) + if (!QuestLogIsOpen && !SpellbookFlag && !IsPlayerInStore()) *action = GameAction(GameActionType_USE_MANA_POTION); return true; } @@ -177,7 +177,7 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrlEvent, Game SDL_Keycode translation = SDLK_UNKNOWN; - if (gmenu_is_active() || ActiveStore != TalkID::None) + if (gmenu_is_active() || IsPlayerInStore()) translation = TranslateControllerButtonToGameMenuKey(ctrlEvent.button); else if (inGameMenu) translation = TranslateControllerButtonToMenuKey(ctrlEvent.button); diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index b7f567f36..a6fbce484 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -59,7 +59,7 @@ quest_id pcursquest = Q_INVALID; */ bool InGameMenu() { - return ActiveStore != TalkID::None + return IsPlayerInStore() || HelpFlag || ChatLogFlag || ChatFlag @@ -1433,7 +1433,7 @@ HandleLeftStickOrDPadFn GetLeftStickOrDPadGameUIHandler() if (QuestLogIsOpen) { return &QuestLogMove; } - if (ActiveStore != TalkID::None) { + if (IsPlayerInStore()) { return &StoreMove; } return nullptr; diff --git a/Source/controls/touch/event_handlers.cpp b/Source/controls/touch/event_handlers.cpp index f3d47290a..a065926e3 100644 --- a/Source/controls/touch/event_handlers.cpp +++ b/Source/controls/touch/event_handlers.cpp @@ -70,7 +70,7 @@ bool HandleGameMenuInteraction(const SDL_Event &event) bool HandleStoreInteraction(const SDL_Event &event) { - if (ActiveStore == TalkID::None) + if (!IsPlayerInStore()) return false; if (event.type == SDL_FINGERDOWN) CheckStoreBtn(); diff --git a/Source/controls/touch/renderers.cpp b/Source/controls/touch/renderers.cpp index 15650d18e..881083e08 100644 --- a/Source/controls/touch/renderers.cpp +++ b/Source/controls/touch/renderers.cpp @@ -405,7 +405,7 @@ VirtualGamepadButtonType PrimaryActionButtonRenderer::GetButtonType() VirtualGamepadButtonType PrimaryActionButtonRenderer::GetTownButtonType() { - if (ActiveStore != TalkID::None || pcursmonst != -1) + if (IsPlayerInStore() || pcursmonst != -1) return GetTalkButtonType(virtualPadButton->isHeld); return GetBlankButtonType(virtualPadButton->isHeld); } diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 9f0284db3..97c46f906 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -347,7 +347,7 @@ void LeftMouseDown(uint16_t modState) return; } - if (ActiveStore != TalkID::None) { + if (IsPlayerInStore()) { CheckStoreBtn(); return; } @@ -411,7 +411,7 @@ void LeftMouseUp(uint16_t modState) } if (LevelButtonDown) CheckLevelButtonUp(); - if (ActiveStore != TalkID::None) + if (IsPlayerInStore()) ReleaseStoreBtn(); } @@ -433,7 +433,7 @@ void RightMouseDown(bool isShiftHeld) doom_close(); return; } - if (ActiveStore != TalkID::None) + if (IsPlayerInStore()) return; if (SpellSelectFlag) { SetSpell(); @@ -583,7 +583,7 @@ void PressKey(SDL_Keycode vkey, uint16_t modState) if ((modState & KMOD_ALT) != 0) { options.Graphics.fullscreen.SetValue(!IsFullScreen()); if (!demo::IsRunning()) SaveOptions(); - } else if (ActiveStore != TalkID::None) { + } else if (IsPlayerInStore()) { StoreEnter(); } else if (QuestLogIsOpen) { QuestlogEnter(); @@ -592,7 +592,7 @@ void PressKey(SDL_Keycode vkey, uint16_t modState) } return; case SDLK_UP: - if (ActiveStore != TalkID::None) { + if (IsPlayerInStore()) { StoreUp(); } else if (QuestLogIsOpen) { QuestlogUp(); @@ -607,7 +607,7 @@ void PressKey(SDL_Keycode vkey, uint16_t modState) } return; case SDLK_DOWN: - if (ActiveStore != TalkID::None) { + if (IsPlayerInStore()) { StoreDown(); } else if (QuestLogIsOpen) { QuestlogDown(); @@ -622,14 +622,14 @@ void PressKey(SDL_Keycode vkey, uint16_t modState) } return; case SDLK_PAGEUP: - if (ActiveStore != TalkID::None) { + if (IsPlayerInStore()) { StorePrior(); } else if (ChatLogFlag) { ChatLogScrollTop(); } return; case SDLK_PAGEDOWN: - if (ActiveStore != TalkID::None) { + if (IsPlayerInStore()) { StoreNext(); } else if (ChatLogFlag) { ChatLogScrollBottom(); @@ -650,7 +650,7 @@ void PressKey(SDL_Keycode vkey, uint16_t modState) void HandleMouseButtonDown(Uint8 button, uint16_t modState) { - if (ActiveStore != TalkID::None && (button == SDL_BUTTON_X1 + if (IsPlayerInStore() && (button == SDL_BUTTON_X1 #if !SDL_VERSION_ATLEAST(2, 0, 0) || button == 8 #endif @@ -760,7 +760,7 @@ void GameEventHandler(const SDL_Event &event, uint16_t modState) #if SDL_VERSION_ATLEAST(2, 0, 0) case SDL_MOUSEWHEEL: if (event.wheel.y > 0) { // Up - if (ActiveStore != TalkID::None) { + if (IsPlayerInStore()) { StoreUp(); } else if (QuestLogIsOpen) { QuestlogUp(); @@ -778,7 +778,7 @@ void GameEventHandler(const SDL_Event &event, uint16_t modState) KeymapperPress(MouseScrollUpButton); } } else if (event.wheel.y < 0) { // down - if (ActiveStore != TalkID::None) { + if (IsPlayerInStore()) { StoreDown(); } else if (QuestLogIsOpen) { QuestlogDown(); @@ -1520,7 +1520,7 @@ void HelpKeyPressed() { if (HelpFlag) { HelpFlag = false; - } else if (ActiveStore != TalkID::None) { + } else if (IsPlayerInStore()) { InfoString = StringOrView {}; AddInfoBoxString(_("No help available")); /// BUGFIX: message isn't displayed AddInfoBoxString(_("while in stores")); @@ -1544,7 +1544,7 @@ void HelpKeyPressed() void InventoryKeyPressed() { - if (ActiveStore != TalkID::None) + if (IsPlayerInStore()) return; invflag = !invflag; if (!IsLeftPanelOpen() && CanPanelsCoverView()) { @@ -1565,7 +1565,7 @@ void InventoryKeyPressed() void CharacterSheetKeyPressed() { - if (ActiveStore != TalkID::None) + if (IsPlayerInStore()) return; if (!IsRightPanelOpen() && CanPanelsCoverView()) { if (CharFlag) { // We are closing the character sheet @@ -1583,7 +1583,7 @@ void CharacterSheetKeyPressed() void QuestLogKeyPressed() { - if (ActiveStore != TalkID::None) + if (IsPlayerInStore()) return; if (!QuestLogIsOpen) { StartQuestlog(); @@ -1608,7 +1608,7 @@ void QuestLogKeyPressed() void DisplaySpellsKeyPressed() { - if (ActiveStore != TalkID::None) + if (IsPlayerInStore()) return; CloseCharPanel(); QuestLogIsOpen = false; @@ -1624,7 +1624,7 @@ void DisplaySpellsKeyPressed() void SpellBookKeyPressed() { - if (ActiveStore != TalkID::None) + if (IsPlayerInStore()) return; SpellbookFlag = !SpellbookFlag; if (!IsLeftPanelOpen() && CanPanelsCoverView()) { @@ -1790,7 +1790,7 @@ void InitKeymapActions() SDLK_F3, [] { gamemenu_load_game(false); }, nullptr, - [&]() { return !gbIsMultiplayer && gbValidSaveFile && ActiveStore == TalkID::None && IsGameRunning(); }); + [&]() { return !gbIsMultiplayer && gbValidSaveFile && !IsPlayerInStore() && IsGameRunning(); }); #ifndef NOEXIT options.Keymapper.AddAction( "QuitGame", @@ -2358,7 +2358,7 @@ void InitPadmapActions() ControllerButton_NONE, [] { gamemenu_load_game(false); }, nullptr, - [&]() { return !gbIsMultiplayer && gbValidSaveFile && ActiveStore == TalkID::None && IsGameRunning(); }); + [&]() { return !gbIsMultiplayer && gbValidSaveFile && !IsPlayerInStore() && IsGameRunning(); }); options.Padmapper.AddAction( "Item Highlighting", N_("Item highlighting"), @@ -2809,7 +2809,7 @@ bool PressEscKey() rv = true; } - if (ActiveStore != TalkID::None) { + if (IsPlayerInStore()) { StoreESC(); rv = true; } diff --git a/Source/engine/render/scrollrt.cpp b/Source/engine/render/scrollrt.cpp index 1a573d7d4..e9e5b92e6 100644 --- a/Source/engine/render/scrollrt.cpp +++ b/Source/engine/render/scrollrt.cpp @@ -643,7 +643,7 @@ void DrawItem(const Surface &out, int8_t itemIndex, Point targetBufferPosition, const Item &item = Items[itemIndex]; const ClxSprite sprite = item.AnimInfo.currentSprite(); const Point position = targetBufferPosition + item.getRenderingOffset(sprite); - if (ActiveStore == TalkID::None && (itemIndex == pcursitem || AutoMapShowItems)) { + if (!IsPlayerInStore() && (itemIndex == pcursitem || AutoMapShowItems)) { ClxDrawOutlineSkipColorZero(out, GetOutlineColor(item, false), position, sprite); } ClxDrawLight(out, position, sprite, lightTableIndex); @@ -1249,7 +1249,7 @@ void DrawView(const Surface &out, Point startPosition) DrawMonsterHealthBar(out); DrawFloatingNumbers(out, startPosition, offset); - if (ActiveStore != TalkID::None && !qtextflag) + if (IsPlayerInStore() && !qtextflag) DrawSText(out); if (invflag) { DrawInv(out); diff --git a/Source/inv.cpp b/Source/inv.cpp index 14c1e5c5b..826f7b57a 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -2068,7 +2068,7 @@ bool UseInvItem(int cii) return true; if (pcurs != CURSOR_HAND) return true; - if (ActiveStore != TalkID::None) + if (IsPlayerInStore()) return true; if (cii < INVITEM_INV_FIRST) return false; diff --git a/Source/qol/itemlabels.cpp b/Source/qol/itemlabels.cpp index c01ad23e6..240640b65 100644 --- a/Source/qol/itemlabels.cpp +++ b/Source/qol/itemlabels.cpp @@ -99,7 +99,7 @@ void ResetItemlabelHighlighted() bool IsHighlightingLabelsEnabled() { - return ActiveStore == TalkID::None && highlightKeyPressed != *GetOptions().Gameplay.showItemLabels; + return !IsPlayerInStore() && highlightKeyPressed != *GetOptions().Gameplay.showItemLabels; } void AddItemToLabelQueue(int id, Point position) @@ -194,7 +194,7 @@ void DrawItemNameLabels(const Surface &out) if (!gmenu_is_active() && PauseMode == 0 && !MyPlayerIsDead - && ActiveStore == TalkID::None + && !IsPlayerInStore() && IsMouseOverGameArea() && LastMouseButtonAction == MouseActionType::None) { isLabelHighlighted = true; @@ -202,7 +202,7 @@ void DrawItemNameLabels(const Surface &out) pcursitem = label.id; } } - if (pcursitem == label.id && ActiveStore == TalkID::None) + if (pcursitem == label.id && !IsPlayerInStore()) FillRect(clippedOut, label.pos.x, label.pos.y, label.width, labelHeight, PAL8_BLUE + 6); else DrawHalfTransparentRectTo(clippedOut, label.pos.x, label.pos.y, label.width, labelHeight); diff --git a/Source/qol/stash.cpp b/Source/qol/stash.cpp index 4f447a2c7..8f6df4fc2 100644 --- a/Source/qol/stash.cpp +++ b/Source/qol/stash.cpp @@ -463,7 +463,7 @@ bool UseStashItem(uint16_t c) return true; if (pcurs != CURSOR_HAND) return true; - if (ActiveStore != TalkID::None) + if (IsPlayerInStore()) return true; Item *item = &Stash.stashList[c]; diff --git a/Source/stores.cpp b/Source/stores.cpp index 47341b9d1..5c60ddf29 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -2703,12 +2703,12 @@ void CheckStoreBtn() if (!IsTextFullSize) { if (!windowRect.contains(MousePosition)) { - while (ActiveStore != TalkID::None) + while (IsPlayerInStore()) StoreESC(); } } else { if (!windowRectFull.contains(MousePosition)) { - while (ActiveStore != TalkID::None) + while (IsPlayerInStore()) StoreESC(); } } @@ -2775,4 +2775,9 @@ void ReleaseStoreBtn() CountdownScrollDown = -1; } +bool IsPlayerInStore() +{ + return ActiveStore != TalkID::None; +} + } // namespace devilution diff --git a/Source/stores.h b/Source/stores.h index af6e8e1df..12a1ebdcc 100644 --- a/Source/stores.h +++ b/Source/stores.h @@ -104,5 +104,6 @@ void TakePlrsMoney(int cost); void StoreEnter(); void CheckStoreBtn(); void ReleaseStoreBtn(); +bool IsPlayerInStore(); } // namespace devilution diff --git a/Source/track.cpp b/Source/track.cpp index 12fe591aa..868f098d9 100644 --- a/Source/track.cpp +++ b/Source/track.cpp @@ -67,7 +67,7 @@ void RepeatMouseAction() if (sgbMouseDown == CLICK_NONE && ControllerActionHeld == GameActionType_NONE) return; - if (ActiveStore != TalkID::None) + if (IsPlayerInStore()) return; if (LastMouseButtonAction == MouseActionType::None)