hud.show_overlay fix
This commit is contained in:
+25
-9
@@ -295,15 +295,7 @@ void Hud::update(bool visible) {
|
|||||||
void Hud::openInventory() {
|
void Hud::openInventory() {
|
||||||
auto level = frontend->getLevel();
|
auto level = frontend->getLevel();
|
||||||
auto content = level->content;
|
auto content = level->content;
|
||||||
exchangeSlotInv = level->inventories->createVirtual(1);
|
showExchangeSlot();
|
||||||
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);
|
|
||||||
|
|
||||||
inventoryOpen = true;
|
inventoryOpen = true;
|
||||||
auto inventory = player->getInventory();
|
auto inventory = player->getInventory();
|
||||||
@@ -345,6 +337,21 @@ void Hud::openInventory(
|
|||||||
add(HudElement(hud_element_mode::inventory_bound, doc, blockUI, false));
|
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) {
|
void Hud::showOverlay(UiDocument* doc, bool playerInventory) {
|
||||||
if (isInventoryOpen()) {
|
if (isInventoryOpen()) {
|
||||||
closeInventory();
|
closeInventory();
|
||||||
@@ -353,6 +360,7 @@ void Hud::showOverlay(UiDocument* doc, bool playerInventory) {
|
|||||||
if (playerInventory) {
|
if (playerInventory) {
|
||||||
openInventory();
|
openInventory();
|
||||||
} else {
|
} else {
|
||||||
|
showExchangeSlot();
|
||||||
inventoryOpen = true;
|
inventoryOpen = true;
|
||||||
}
|
}
|
||||||
add(HudElement(hud_element_mode::inventory_bound, doc, secondUI, false));
|
add(HudElement(hud_element_mode::inventory_bound, doc, secondUI, false));
|
||||||
@@ -377,6 +385,14 @@ void Hud::closeInventory() {
|
|||||||
inventoryView = nullptr;
|
inventoryView = nullptr;
|
||||||
blockUI = nullptr;
|
blockUI = nullptr;
|
||||||
secondUI = nullptr;
|
secondUI = nullptr;
|
||||||
|
|
||||||
|
for (auto& element : elements) {
|
||||||
|
if (element.isInventoryBound()) {
|
||||||
|
element.setRemoved();
|
||||||
|
onRemove(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hud::add(HudElement element) {
|
void Hud::add(HudElement element) {
|
||||||
|
|||||||
@@ -55,6 +55,10 @@ public:
|
|||||||
UiDocument* getDocument() const;
|
UiDocument* getDocument() const;
|
||||||
std::shared_ptr<gui::UINode> getNode() const;
|
std::shared_ptr<gui::UINode> getNode() const;
|
||||||
|
|
||||||
|
bool isInventoryBound() const {
|
||||||
|
return mode == hud_element_mode::inventory_bound;
|
||||||
|
}
|
||||||
|
|
||||||
void setRemoved() {
|
void setRemoved() {
|
||||||
removed = true;
|
removed = true;
|
||||||
}
|
}
|
||||||
@@ -112,6 +116,8 @@ class Hud : public util::ObjectsKeeper {
|
|||||||
void updateElementsPosition(const Viewport& viewport);
|
void updateElementsPosition(const Viewport& viewport);
|
||||||
void updateHotbarControl();
|
void updateHotbarControl();
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
|
void showExchangeSlot();
|
||||||
public:
|
public:
|
||||||
Hud(Engine* engine, LevelFrontend* frontend, Player* player);
|
Hud(Engine* engine, LevelFrontend* frontend, Player* player);
|
||||||
~Hud();
|
~Hud();
|
||||||
|
|||||||
Reference in New Issue
Block a user