fix: allow closing any bag independently and reset off-screen positions

Remove the forced backpack-open constraint that prevented closing the
backpack while other bags were open. Each bag window is now independently
closable regardless of which others are open.

Add off-screen position reset to individual bag windows (renderBagWindow)
so bags saved at positions outside the current resolution snap back to
their default stack position.
This commit is contained in:
Kelsi 2026-03-23 18:16:23 -07:00
parent b10c8b7aea
commit 5e8d4e76c8

View file

@ -987,11 +987,7 @@ void InventoryScreen::renderSeparateBags(game::Inventory& inventory, uint64_t mo
constexpr int columns = 6;
constexpr float baseWindowW = columns * (slotSize + 4.0f) + 30.0f;
bool anyBagOpen = std::any_of(bagOpen_.begin(), bagOpen_.end(), [](bool b) { return b; });
if (anyBagOpen && !backpackOpen_) {
// Enforce backpack as the bottom-most stack window when any bag is open.
backpackOpen_ = true;
}
// Each bag window is independently closable — no forced backpack constraint.
// Anchor stack to the bag bar (bottom-right), opening upward.
const float bagBarTop = screenH - (42.0f + 12.0f) - 10.0f;
@ -1076,6 +1072,16 @@ void InventoryScreen::renderBagWindow(const char* title, bool& isOpen,
return;
}
// Reset position if the window ended up outside the screen (resolution change)
ImVec2 winPos = ImGui::GetWindowPos();
ImVec2 winSize = ImGui::GetWindowSize();
float scrW = ImGui::GetIO().DisplaySize.x;
float scrH = ImGui::GetIO().DisplaySize.y;
if (winPos.x > scrW || winPos.y > scrH ||
winPos.x + winSize.x < 0 || winPos.y + winSize.y < 0) {
ImGui::SetWindowPos(ImVec2(defaultX, defaultY));
}
// Render item slots in 4-column grid
for (int i = 0; i < numSlots; i++) {
if (i % columns != 0) ImGui::SameLine();