InventoryView.unbind()
This commit is contained in:
parent
a8aa0550c9
commit
fa57a898d7
@ -16,6 +16,7 @@
|
||||
#include "../content/Content.h"
|
||||
#include "../items/ItemDef.h"
|
||||
#include "../items/Inventory.h"
|
||||
#include "../items/Inventories.h"
|
||||
#include "../maths/voxmaths.h"
|
||||
#include "../objects/Player.h"
|
||||
#include "../voxels/Block.h"
|
||||
@ -337,6 +338,12 @@ void InventoryView::bind(
|
||||
}
|
||||
}
|
||||
|
||||
void InventoryView::unbind() {
|
||||
if (inventory->isVirtual()) {
|
||||
frontend->getLevel()->inventories->remove(inventory->getId());
|
||||
}
|
||||
}
|
||||
|
||||
void InventoryView::setSelected(int index) {
|
||||
for (int i = 0; i < int(slots.size()); i++) {
|
||||
auto slot = slots[i];
|
||||
|
||||
@ -113,6 +113,8 @@ public:
|
||||
LevelFrontend* frontend,
|
||||
InventoryInteraction* interaction
|
||||
);
|
||||
|
||||
void unbind();
|
||||
|
||||
std::shared_ptr<SlotView> addSlot(SlotLayout layout);
|
||||
|
||||
|
||||
@ -409,20 +409,11 @@ void Hud::openPermanent(UiDocument* doc) {
|
||||
}
|
||||
|
||||
void Hud::closeInventory() {
|
||||
auto level = frontend->getLevel();
|
||||
|
||||
inventoryOpen = false;
|
||||
ItemStack& grabbed = interaction->getGrabbedItem();
|
||||
grabbed.clear();
|
||||
inventoryView = nullptr;
|
||||
if (blockUI) {
|
||||
auto blockinv = blockUI->getInventory();
|
||||
// todo: do it automatically
|
||||
if (blockinv->isVirtual()) {
|
||||
level->inventories->remove(blockinv->getId());
|
||||
}
|
||||
blockUI = nullptr;
|
||||
}
|
||||
blockUI = nullptr;
|
||||
secondUI = nullptr;
|
||||
}
|
||||
|
||||
@ -458,6 +449,9 @@ void Hud::remove(HudElement& element) {
|
||||
inventory = invview->getInventory().get();
|
||||
}
|
||||
scripting::on_ui_close(document, inventory);
|
||||
if (invview) {
|
||||
invview->unbind();
|
||||
}
|
||||
}
|
||||
gui->remove(element.getNode());
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user