fix: inventory interaction on "disablePlayerInventory = true"

This commit is contained in:
clasher113 2025-12-28 18:01:02 +02:00
parent a1549983f8
commit dba10805f8
2 changed files with 20 additions and 26 deletions

View file

@ -383,17 +383,18 @@ void Hud::update(bool visible) {
}
/// @brief Show inventory on the screen and turn on inventory mode blocking movement
void Hud::openInventory() {
auto& content = frontend.getLevel().content;
void Hud::openInventory(bool playerInventory) {
showExchangeSlot();
inventoryOpen = true;
auto inventory = player.getInventory();
auto inventoryDocument = assets.get<UiDocument>("core:inventory");
inventoryView = std::dynamic_pointer_cast<InventoryView>(inventoryDocument->getRoot());
inventoryView->bind(inventory, &content);
add(HudElement(HudElementMode::INVENTORY, inventoryDocument, inventoryView, false));
add(HudElement(HudElementMode::INVENTORY, nullptr, exchangeSlot, false));
if (playerInventory) {
auto& content = frontend.getLevel().content;
auto inventory = player.getInventory();
auto inventoryDocument = assets.get<UiDocument>("core:inventory");
inventoryView = std::dynamic_pointer_cast<InventoryView>(inventoryDocument->getRoot());
inventoryView->bind(inventory, &content);
add(HudElement(HudElementMode::INVENTORY, inventoryDocument, inventoryView, false));
}
}
std::shared_ptr<Inventory> Hud::openInventory(
@ -412,11 +413,8 @@ std::shared_ptr<Inventory> Hud::openInventory(
}
secondUI = secondInvView;
if (playerInventory) {
openInventory();
} else {
inventoryOpen = true;
}
openInventory(playerInventory);
if (inv == nullptr) {
inv = level.inventories->createVirtual(secondInvView->getSlotsCount());
}
@ -444,11 +442,9 @@ void Hud::openInventory(
throw std::runtime_error("block UI root element must be 'inventory'");
}
secondUI = blockUI;
if (playerInventory) {
openInventory();
} else {
inventoryOpen = true;
}
openInventory(playerInventory);
if (blockinv == nullptr) {
blockinv = level.inventories->createVirtual(blockUI->getSlotsCount());
}
@ -477,6 +473,7 @@ void Hud::showExchangeSlot() {
exchangeSlot->setInteractive(false);
exchangeSlot->setZIndex(1);
gui.store(SlotView::EXCHANGE_SLOT_NAME, exchangeSlot);
add(HudElement(HudElementMode::INVENTORY, nullptr, exchangeSlot, false));
}
void Hud::showOverlay(
@ -486,12 +483,9 @@ void Hud::showOverlay(
closeInventory();
}
secondUI = doc->getRoot();
if (playerInventory) {
openInventory();
} else {
showExchangeSlot();
inventoryOpen = true;
}
openInventory(playerInventory);
add(HudElement(HudElementMode::INVENTORY, doc, secondUI, false), args);
}

View file

@ -156,7 +156,7 @@ public:
void setPause(bool pause);
/// @brief Show player inventory in inventory-mode
void openInventory();
void openInventory(bool playerInventory = true);
/// @brief Show inventory in inventory-mode
/// @param doc ui layout