hud.show_overlay fix

This commit is contained in:
MihailRis 2024-05-10 08:57:05 +03:00
parent 76f52037b5
commit 92f185ab51
2 changed files with 31 additions and 9 deletions

View File

@ -295,15 +295,7 @@ void Hud::update(bool visible) {
void Hud::openInventory() {
auto level = frontend->getLevel();
auto content = level->content;
exchangeSlotInv = level->inventories->createVirtual(1);
exchangeSlot = std::make_shared<SlotView>(
SlotLayout(-1, glm::vec2(), false, false, nullptr, nullptr, nullptr)
);
exchangeSlot->bind(exchangeSlotInv->getId(), exchangeSlotInv->getSlot(0), content);
exchangeSlot->setColor(glm::vec4());
exchangeSlot->setInteractive(false);
exchangeSlot->setZIndex(1);
gui->store(SlotView::EXCHANGE_SLOT_NAME, exchangeSlot);
showExchangeSlot();
inventoryOpen = true;
auto inventory = player->getInventory();
@ -345,6 +337,21 @@ void Hud::openInventory(
add(HudElement(hud_element_mode::inventory_bound, doc, blockUI, false));
}
void Hud::showExchangeSlot() {
auto level = frontend->getLevel();
auto content = level->content;
exchangeSlotInv = level->inventories->createVirtual(1);
exchangeSlot = std::make_shared<SlotView>(
SlotLayout(-1, glm::vec2(), false, false, nullptr, nullptr, nullptr)
);
exchangeSlot->bind(exchangeSlotInv->getId(), exchangeSlotInv->getSlot(0), content);
exchangeSlot->setColor(glm::vec4());
exchangeSlot->setInteractive(false);
exchangeSlot->setZIndex(1);
gui->store(SlotView::EXCHANGE_SLOT_NAME, exchangeSlot);
}
void Hud::showOverlay(UiDocument* doc, bool playerInventory) {
if (isInventoryOpen()) {
closeInventory();
@ -353,6 +360,7 @@ void Hud::showOverlay(UiDocument* doc, bool playerInventory) {
if (playerInventory) {
openInventory();
} else {
showExchangeSlot();
inventoryOpen = true;
}
add(HudElement(hud_element_mode::inventory_bound, doc, secondUI, false));
@ -377,6 +385,14 @@ void Hud::closeInventory() {
inventoryView = nullptr;
blockUI = nullptr;
secondUI = nullptr;
for (auto& element : elements) {
if (element.isInventoryBound()) {
element.setRemoved();
onRemove(element);
}
}
cleanup();
}
void Hud::add(HudElement element) {

View File

@ -55,6 +55,10 @@ public:
UiDocument* getDocument() const;
std::shared_ptr<gui::UINode> getNode() const;
bool isInventoryBound() const {
return mode == hud_element_mode::inventory_bound;
}
void setRemoved() {
removed = true;
}
@ -112,6 +116,8 @@ class Hud : public util::ObjectsKeeper {
void updateElementsPosition(const Viewport& viewport);
void updateHotbarControl();
void cleanup();
void showExchangeSlot();
public:
Hud(Engine* engine, LevelFrontend* frontend, Player* player);
~Hud();