Browse Source

Stores - IsPlayerInStore() (#7843)

pull/7424/merge
Eric Robinson 1 year ago committed by GitHub
parent
commit
8eddf55c3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      Source/control.cpp
  2. 8
      Source/controls/game_controls.cpp
  3. 4
      Source/controls/plrctrls.cpp
  4. 2
      Source/controls/touch/event_handlers.cpp
  5. 2
      Source/controls/touch/renderers.cpp
  6. 40
      Source/diablo.cpp
  7. 4
      Source/engine/render/scrollrt.cpp
  8. 2
      Source/inv.cpp
  9. 6
      Source/qol/itemlabels.cpp
  10. 2
      Source/qol/stash.cpp
  11. 9
      Source/stores.cpp
  12. 1
      Source/stores.h
  13. 2
      Source/track.cpp

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

8
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);

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

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

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

40
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;
}

4
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);

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

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

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

9
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

1
Source/stores.h

@ -104,5 +104,6 @@ void TakePlrsMoney(int cost);
void StoreEnter();
void CheckStoreBtn();
void ReleaseStoreBtn();
bool IsPlayerInStore();
} // namespace devilution

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

Loading…
Cancel
Save