Browse Source

Add helpers to change stash pages (#4287)

pull/4300/head
Andrew James 4 years ago committed by GitHub
parent
commit
028c5945b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      Source/diablo.cpp
  2. 7
      Source/loadsave.cpp
  3. 4
      Source/miniwin/misc_msg.cpp
  4. 32
      Source/qol/stash.cpp
  5. 3
      Source/qol/stash.h

4
Source/diablo.cpp

@ -510,7 +510,7 @@ void PressKey(int vkey)
} else if (AutomapActive) {
AutomapUp();
} else if (IsStashOpen) {
Stash.SetPage(Stash.GetPage() - 1);
Stash.PreviousPage();
}
} else if (vkey == DVL_VK_DOWN) {
if (stextflag != STORE_NONE) {
@ -524,7 +524,7 @@ void PressKey(int vkey)
} else if (AutomapActive) {
AutomapDown();
} else if (IsStashOpen) {
Stash.SetPage(Stash.GetPage() + 1);
Stash.NextPage();
}
} else if (vkey == DVL_VK_PRIOR) {
if (stextflag != STORE_NONE) {

7
Source/loadsave.cpp

@ -1809,6 +1809,8 @@ void LoadStash()
for (unsigned i = 0; i < itemCount; i++) {
LoadItemData(file, Stash.stashList[i]);
}
Stash.SetPage(file.NextLE<uint32_t>());
}
void RemoveEmptyInventory(Player &player)
@ -2055,7 +2057,8 @@ void SaveStash()
+ sizeof(uint32_t)
+ (sizeof(uint32_t) + 10 * 10 * sizeof(uint16_t)) * Stash.stashGrids.size()
+ sizeof(uint32_t)
+ itemSize * Stash.stashList.size());
+ itemSize * Stash.stashList.size()
+ sizeof(uint32_t));
file.WriteLE<uint8_t>(StashVersion);
@ -2077,6 +2080,8 @@ void SaveStash()
for (const Item &item : Stash.stashList) {
SaveItem(file, item);
}
file.WriteLE<uint32_t>(static_cast<uint32_t>(Stash.GetPage()));
}
void SaveGameData()

4
Source/miniwin/misc_msg.cpp

@ -320,13 +320,13 @@ void ProcessGamepadEvents(GameAction &action)
break;
case GameActionType_USE_HEALTH_POTION:
if (IsStashOpen)
Stash.SetPage(Stash.GetPage() - 1);
Stash.PreviousPage();
else
UseBeltItem(BLT_HEALING);
break;
case GameActionType_USE_MANA_POTION:
if (IsStashOpen)
Stash.SetPage(Stash.GetPage() + 1);
Stash.NextPage();
else
UseBeltItem(BLT_MANA);
break;

32
Source/qol/stash.cpp

@ -29,6 +29,7 @@ int WithdrawGoldValue;
namespace {
constexpr unsigned CountStashPages = 50;
constexpr unsigned LastStashPage = CountStashPages - 1;
int InitialWithdrawGoldValue;
@ -293,19 +294,19 @@ void CheckStashButtonRelease(Point mousePosition)
if (stashButton.Contains(mousePosition)) {
switch (StashButtonPressed) {
case 0:
Stash.SetPage(Stash.GetPage() - 10);
Stash.PreviousPage(10);
break;
case 1:
Stash.SetPage(Stash.GetPage() - 1);
Stash.PreviousPage();
break;
case 2:
StartGoldWithdraw();
break;
case 3:
Stash.SetPage(Stash.GetPage() + 1);
Stash.NextPage();
break;
case 4:
Stash.SetPage(Stash.GetPage() + 10);
Stash.NextPage(10);
break;
}
}
@ -534,7 +535,28 @@ void StashStruct::RemoveStashItem(uint16_t iv)
void StashStruct::SetPage(unsigned newPage)
{
page = std::min(newPage, CountStashPages - 1);
page = std::min(newPage, LastStashPage);
dirty = true;
}
void StashStruct::NextPage(unsigned offset)
{
if (page <= LastStashPage) {
page += std::min(offset, LastStashPage - page);
} else {
page = LastStashPage;
}
dirty = true;
}
void StashStruct::PreviousPage(unsigned offset)
{
if (page <= LastStashPage) {
page -= std::min(offset, page);
} else {
page = LastStashPage;
}
dirty = true;
}
void StashStruct::RefreshItemStatFlags()

3
Source/qol/stash.h

@ -28,6 +28,9 @@ public:
}
void SetPage(unsigned newPage);
void NextPage(unsigned offset = 1);
void PreviousPage(unsigned offset = 1);
/** @brief Updates _iStatFlag for all stash items. */
void RefreshItemStatFlags();

Loading…
Cancel
Save