Skip to content

Commit

Permalink
Cleanup stores
Browse files Browse the repository at this point in the history
Update

Refactor Smith menu

Clean up the smith main menu with helper functions, and prevent utilizing the line number to figure out what functions to call.

Clean up Main Menu more

Separate strings

Refactor and general fns

Note: There is a bug where wirt's item can only be clicked on the item name

Consolidate Sell functions

Consolidate canselltotowner

Fix bad rebase

Fix accidental change

Add IsPlayerInStore()

Rename/organize

Update stores.cpp

Update stores.h

Rename playerItemIdx

Renames and fix

IsPlayerInStore()

RestoreResource()
  • Loading branch information
kphoenix137 committed Sep 20, 2024
1 parent 974f517 commit 508bfa3
Show file tree
Hide file tree
Showing 21 changed files with 1,599 additions and 1,570 deletions.
2 changes: 1 addition & 1 deletion Source/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ bool IsLevelUpButtonVisible()
if (ControlMode == ControlTypes::VirtualGamepad) {
return false;
}
if (stextflag != TalkID::None || IsStashOpen) {
if (Stores.IsPlayerInStore() || IsStashOpen) {
return false;
}
if (QuestLogIsOpen && GetLeftPanel().contains(GetMainPanel().position + Displacement { 0, -74 })) {
Expand Down
8 changes: 4 additions & 4 deletions Source/controls/game_controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrlEvent, Game
if (ControllerActionHeld == GameActionType_NONE) {
ControllerActionHeld = GameActionType_PRIMARY_ACTION;
}
} else if (sgpCurrentMenu != nullptr || stextflag != TalkID::None || QuestLogIsOpen) {
} else if (sgpCurrentMenu != nullptr || Stores.IsPlayerInStore() || QuestLogIsOpen) {
*action = GameActionSendKey { SDLK_RETURN, false };
} else {
*action = GameActionSendKey { SDLK_SPACE, false };
Expand Down Expand Up @@ -171,12 +171,12 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrlEvent, Game
return true;
}
if (VirtualGamepadState.healthButton.isHeld && VirtualGamepadState.healthButton.didStateChange) {
if (!QuestLogIsOpen && !SpellbookFlag && stextflag == TalkID::None)
if (!QuestLogIsOpen && !SpellbookFlag && !Stores.IsPlayerInStore())
*action = GameAction(GameActionType_USE_HEALTH_POTION);
return true;
}
if (VirtualGamepadState.manaButton.isHeld && VirtualGamepadState.manaButton.didStateChange) {
if (!QuestLogIsOpen && !SpellbookFlag && stextflag == TalkID::None)
if (!QuestLogIsOpen && !SpellbookFlag && !Stores.IsPlayerInStore())
*action = GameAction(GameActionType_USE_MANA_POTION);
return true;
}
Expand All @@ -196,7 +196,7 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrlEvent, Game

SDL_Keycode translation = SDLK_UNKNOWN;

if (gmenu_is_active() || stextflag != TalkID::None)
if (gmenu_is_active() || Stores.IsPlayerInStore())
translation = TranslateControllerButtonToGameMenuKey(ctrlEvent.button);
else if (inGameMenu)
translation = TranslateControllerButtonToMenuKey(ctrlEvent.button);
Expand Down
8 changes: 4 additions & 4 deletions Source/controls/plrctrls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ quest_id pcursquest = Q_INVALID;
*/
bool InGameMenu()
{
return stextflag != TalkID::None
return Stores.IsPlayerInStore()
|| HelpFlag
|| ChatLogFlag
|| ChatFlag
Expand Down Expand Up @@ -1320,9 +1320,9 @@ void StoreMove(AxisDirection moveDir)
static AxisDirectionRepeater repeater;
moveDir = repeater.Get(moveDir);
if (moveDir.y == AxisDirectionY_UP)
StoreUp();
Stores.StoreUp();
else if (moveDir.y == AxisDirectionY_DOWN)
StoreDown();
Stores.StoreDown();
}

using HandleLeftStickOrDPadFn = void (*)(devilution::AxisDirection);
Expand All @@ -1347,7 +1347,7 @@ HandleLeftStickOrDPadFn GetLeftStickOrDPadGameUIHandler()
if (QuestLogIsOpen) {
return &QuestLogMove;
}
if (stextflag != TalkID::None) {
if (Stores.IsPlayerInStore()) {
return &StoreMove;
}
return nullptr;
Expand Down
4 changes: 2 additions & 2 deletions Source/controls/touch/event_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ bool HandleGameMenuInteraction(const SDL_Event &event)

bool HandleStoreInteraction(const SDL_Event &event)
{
if (stextflag == TalkID::None)
if (!Stores.IsPlayerInStore())
return false;
if (event.type == SDL_FINGERDOWN)
CheckStoreBtn();
Stores.CheckStoreButton();
return true;
}

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 @@ -430,7 +430,7 @@ VirtualGamepadButtonType PrimaryActionButtonRenderer::GetButtonType()

VirtualGamepadButtonType PrimaryActionButtonRenderer::GetTownButtonType()
{
if (stextflag != TalkID::None || pcursmonst != -1)
if (Stores.IsPlayerInStore() || pcursmonst != -1)
return GetTalkButtonType(virtualPadButton->isHeld);
return GetBlankButtonType(virtualPadButton->isHeld);
}
Expand Down
70 changes: 35 additions & 35 deletions Source/diablo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void FreeGame()
FreeGMenu();
FreeQuestText();
FreeInfoBoxGfx();
FreeStoreMem();
Stores.FreeStoreMem();

for (Player &player : Players)
ResetPlayerGFX(player);
Expand Down Expand Up @@ -353,8 +353,8 @@ void LeftMouseDown(uint16_t modState)
return;
}

if (stextflag != TalkID::None) {
CheckStoreBtn();
if (Stores.IsPlayerInStore()) {
Stores.CheckStoreButton();
return;
}

Expand Down Expand Up @@ -417,8 +417,8 @@ void LeftMouseUp(uint16_t modState)
}
if (LevelButtonDown)
CheckLevelButtonUp();
if (stextflag != TalkID::None)
ReleaseStoreBtn();
if (Stores.IsPlayerInStore())
Stores.ReleaseStoreButton();
}

void RightMouseDown(bool isShiftHeld)
Expand All @@ -439,7 +439,7 @@ void RightMouseDown(bool isShiftHeld)
doom_close();
return;
}
if (stextflag != TalkID::None)
if (Stores.IsPlayerInStore())
return;
if (SpellSelectFlag) {
SetSpell();
Expand Down Expand Up @@ -576,17 +576,17 @@ void PressKey(SDL_Keycode vkey, uint16_t modState)
if ((modState & KMOD_ALT) != 0) {
sgOptions.Graphics.fullscreen.SetValue(!IsFullScreen());
SaveOptions();
} else if (stextflag != TalkID::None) {
StoreEnter();
} else if (Stores.IsPlayerInStore()) {
Stores.StoreEnter();
} else if (QuestLogIsOpen) {
QuestlogEnter();
} else {
TypeChatMessage();
}
return;
case SDLK_UP:
if (stextflag != TalkID::None) {
StoreUp();
if (Stores.IsPlayerInStore()) {
Stores.StoreUp();
} else if (QuestLogIsOpen) {
QuestlogUp();
} else if (HelpFlag) {
Expand All @@ -600,8 +600,8 @@ void PressKey(SDL_Keycode vkey, uint16_t modState)
}
return;
case SDLK_DOWN:
if (stextflag != TalkID::None) {
StoreDown();
if (Stores.IsPlayerInStore()) {
Stores.StoreDown();
} else if (QuestLogIsOpen) {
QuestlogDown();
} else if (HelpFlag) {
Expand All @@ -615,15 +615,15 @@ void PressKey(SDL_Keycode vkey, uint16_t modState)
}
return;
case SDLK_PAGEUP:
if (stextflag != TalkID::None) {
StorePrior();
if (Stores.IsPlayerInStore()) {
Stores.StorePrior();
} else if (ChatLogFlag) {
ChatLogScrollTop();
}
return;
case SDLK_PAGEDOWN:
if (stextflag != TalkID::None) {
StoreNext();
if (Stores.IsPlayerInStore()) {
Stores.StoreNext();
} else if (ChatLogFlag) {
ChatLogScrollBottom();
}
Expand All @@ -643,12 +643,12 @@ void PressKey(SDL_Keycode vkey, uint16_t modState)

void HandleMouseButtonDown(Uint8 button, uint16_t modState)
{
if (stextflag != TalkID::None && (button == SDL_BUTTON_X1
if (Stores.IsPlayerInStore() && (button == SDL_BUTTON_X1
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|| button == 8
#endif
)) {
StoreESC();
Stores.StoreESC();
return;
}

Expand Down Expand Up @@ -752,8 +752,8 @@ 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 (stextflag != TalkID::None) {
StoreUp();
if (Stores.IsPlayerInStore()) {
Stores.StoreUp();
} else if (QuestLogIsOpen) {
QuestlogUp();
} else if (HelpFlag) {
Expand All @@ -766,8 +766,8 @@ void GameEventHandler(const SDL_Event &event, uint16_t modState)
sgOptions.Keymapper.KeyPressed(MouseScrollUpButton);
}
} else if (event.wheel.y < 0) { // down
if (stextflag != TalkID::None) {
StoreDown();
if (Stores.IsPlayerInStore()) {
Stores.StoreDown();
} else if (QuestLogIsOpen) {
QuestlogDown();
} else if (HelpFlag) {
Expand Down Expand Up @@ -1492,7 +1492,7 @@ void HelpKeyPressed()
{
if (HelpFlag) {
HelpFlag = false;
} else if (stextflag != TalkID::None) {
} else if (Stores.IsPlayerInStore()) {
InfoString = StringOrView {};
AddInfoBoxString(_("No help available")); /// BUGFIX: message isn't displayed
AddInfoBoxString(_("while in stores"));
Expand All @@ -1516,7 +1516,7 @@ void HelpKeyPressed()

void InventoryKeyPressed()
{
if (stextflag != TalkID::None)
if (Stores.IsPlayerInStore())
return;
invflag = !invflag;
if (!IsLeftPanelOpen() && CanPanelsCoverView()) {
Expand All @@ -1537,7 +1537,7 @@ void InventoryKeyPressed()

void CharacterSheetKeyPressed()
{
if (stextflag != TalkID::None)
if (Stores.IsPlayerInStore())
return;
if (!IsRightPanelOpen() && CanPanelsCoverView()) {
if (CharFlag) { // We are closing the character sheet
Expand All @@ -1555,7 +1555,7 @@ void CharacterSheetKeyPressed()

void QuestLogKeyPressed()
{
if (stextflag != TalkID::None)
if (Stores.IsPlayerInStore())
return;
if (!QuestLogIsOpen) {
StartQuestlog();
Expand All @@ -1580,7 +1580,7 @@ void QuestLogKeyPressed()

void DisplaySpellsKeyPressed()
{
if (stextflag != TalkID::None)
if (Stores.IsPlayerInStore())
return;
CloseCharPanel();
QuestLogIsOpen = false;
Expand All @@ -1596,7 +1596,7 @@ void DisplaySpellsKeyPressed()

void SpellBookKeyPressed()
{
if (stextflag != TalkID::None)
if (Stores.IsPlayerInStore())
return;
SpellbookFlag = !SpellbookFlag;
if (!IsLeftPanelOpen() && CanPanelsCoverView()) {
Expand Down Expand Up @@ -1761,7 +1761,7 @@ void InitKeymapActions()
SDLK_F3,
[] { gamemenu_load_game(false); },
nullptr,
[&]() { return !gbIsMultiplayer && gbValidSaveFile && stextflag == TalkID::None && IsGameRunning(); });
[&]() { return !gbIsMultiplayer && gbValidSaveFile && !Stores.IsPlayerInStore() && IsGameRunning(); });
#ifndef NOEXIT
sgOptions.Keymapper.AddAction(
"QuitGame",
Expand Down Expand Up @@ -2328,7 +2328,7 @@ void InitPadmapActions()
ControllerButton_NONE,
[] { gamemenu_load_game(false); },
nullptr,
[&]() { return !gbIsMultiplayer && gbValidSaveFile && stextflag == TalkID::None && IsGameRunning(); });
[&]() { return !gbIsMultiplayer && gbValidSaveFile && !Stores.IsPlayerInStore() && IsGameRunning(); });
sgOptions.Padmapper.AddAction(
"Item Highlighting",
N_("Item highlighting"),
Expand Down Expand Up @@ -2778,8 +2778,8 @@ bool PressEscKey()
rv = true;
}

if (stextflag != TalkID::None) {
StoreESC();
if (Stores.IsPlayerInStore()) {
Stores.StoreESC();
rv = true;
}

Expand Down Expand Up @@ -2873,7 +2873,7 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir)
InitInfoBoxGfx();
InitHelp();
}
InitStores();
Stores.InitStores();
InitAutomapOnce();
}
if (!setlevel) {
Expand All @@ -2886,9 +2886,9 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir)
}

if (leveltype == DTYPE_TOWN) {
SetupTownStores();
Stores.SetupTownStores();
} else {
FreeStoreMem();
Stores.FreeStoreMem();
}

if (firstflag || lvldir == ENTRY_LOAD) {
Expand Down
6 changes: 3 additions & 3 deletions Source/engine/render/scrollrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,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 (stextflag == TalkID::None && (itemIndex == pcursitem || AutoMapShowItems)) {
if (!Stores.IsPlayerInStore() && (itemIndex == pcursitem || AutoMapShowItems)) {
ClxDrawOutlineSkipColorZero(out, GetOutlineColor(item, false), position, sprite);
}
ClxDrawLight(out, position, sprite, lightTableIndex);
Expand Down Expand Up @@ -1197,8 +1197,8 @@ void DrawView(const Surface &out, Point startPosition)
DrawMonsterHealthBar(out);
DrawFloatingNumbers(out, startPosition, offset);

if (stextflag != TalkID::None && !qtextflag)
DrawSText(out);
if (Stores.IsPlayerInStore() && !qtextflag)
Stores.DrawSText(out);
if (invflag) {
DrawInv(out);
} else if (SpellbookFlag) {
Expand Down
4 changes: 2 additions & 2 deletions Source/help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void InitHelp()

void DrawHelp(const Surface &out)
{
DrawSTextHelp();
Stores.DrawSTextHelp();
DrawQTextBack(out);

const int lineHeight = LineHeight();
Expand All @@ -210,7 +210,7 @@ void DrawHelp(const Surface &out)
{ .flags = UiFlags::ColorWhitegold | UiFlags::AlignCenter });

const int titleBottom = sy + HeaderHeight();
DrawSLine(out, titleBottom);
Stores.DrawSLine(out, titleBottom);

const int numLines = NumVisibleLines();
const int contentY = titleBottom + DividerLineMarginY() + ContentPaddingY();
Expand Down
2 changes: 1 addition & 1 deletion Source/inv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2007,7 +2007,7 @@ bool UseInvItem(int cii)
return true;
if (pcurs != CURSOR_HAND)
return true;
if (stextflag != TalkID::None)
if (Stores.IsPlayerInStore())
return true;
if (cii < INVITEM_INV_FIRST)
return false;
Expand Down
Loading

0 comments on commit 508bfa3

Please sign in to comment.