minor refactor

This commit is contained in:
MihailRis 2024-03-06 11:30:33 +03:00
parent fa57a898d7
commit 7601bfad3a
2 changed files with 5 additions and 6 deletions

View File

@ -240,7 +240,7 @@ Hud::~Hud() {
// removing all controlled ui
gui->remove(grabbedItemView);
for (auto& element : elements) {
remove(element);
onRemove(element);
}
gui->remove(hotbarView);
gui->remove(darkOverlay);
@ -331,7 +331,7 @@ void Hud::update(bool visible) {
for (auto& element : elements) {
element.update(pause, inventoryOpen, player->debug);
if (element.isRemoved()) {
remove(element);
onRemove(element);
}
}
}
@ -440,7 +440,7 @@ void Hud::add(HudElement element) {
elements.push_back(element);
}
void Hud::remove(HudElement& element) {
void Hud::onRemove(HudElement& element) {
auto document = element.getDocument();
if (document) {
Inventory* inventory = nullptr;
@ -456,12 +456,11 @@ void Hud::remove(HudElement& element) {
gui->remove(element.getNode());
}
// todo: refactor this garbage
void Hud::remove(std::shared_ptr<gui::UINode> node) {
for (auto& element : elements) {
if (element.getNode() == node) {
element.setRemoved();
remove(element);
onRemove(element);
}
}
cleanup();

View File

@ -148,7 +148,7 @@ public:
void openPermanent(UiDocument* doc);
void add(HudElement element);
void remove(HudElement& element);
void onRemove(HudElement& element);
void remove(std::shared_ptr<gui::UINode> node);
Player* getPlayer() const;