layout test

This commit is contained in:
MihailRis
2024-02-09 10:34:34 +03:00
parent 07adbd04ea
commit 9ad371862c
8 changed files with 41 additions and 14 deletions
+1
View File
@@ -260,6 +260,7 @@ void SlotView::bind(
bound = &stack;
content = frontend->getLevel()->content;
this->frontend = frontend;
this->interaction = interaction;
}
const SlotLayout& SlotView::getLayout() const {
+14 -1
View File
@@ -11,10 +11,23 @@ UiDocument::UiDocument(
std::string namesp,
uidocscript script,
std::shared_ptr<gui::UINode> root
) {
) : namesp(namesp), script(script), root(root) {
collect(map, root);
}
const uinodes_map& UiDocument::getMap() const {
return map;
}
const std::string& UiDocument::getNamespace() const {
return namesp;
}
const std::shared_ptr<gui::UINode> UiDocument::getRoot() const {
return root;
}
void UiDocument::collect(uinodes_map& map, std::shared_ptr<gui::UINode> node) {
const std::string& id = node->getId();
if (!id.empty()) {
+1
View File
@@ -30,6 +30,7 @@ public:
const uinodes_map& getMap() const;
const std::string& getNamespace() const;
const std::shared_ptr<gui::UINode> getRoot() const;
/* Collect map of all uinodes having identifiers */
static void collect(uinodes_map& map, std::shared_ptr<gui::UINode> node);
+18 -9
View File
@@ -31,7 +31,6 @@
#include "../objects/Player.h"
#include "../physics/Hitbox.h"
#include "../maths/voxmaths.h"
#include "../files/files.h"
#include "gui/controls.h"
#include "gui/panels.h"
#include "gui/UINode.h"
@@ -42,6 +41,7 @@
#include "BlocksPreview.h"
#include "InventoryView.h"
#include "LevelFrontend.h"
#include "UiDocument.h"
#include "../engine.h"
#include "../core_defs.h"
#include "../items/ItemDef.h"
@@ -217,15 +217,24 @@ std::shared_ptr<InventoryView> HudRenderer::createInventory() {
auto player = level->player;
auto inventory = player->getInventory();
SlotLayout slotLayout(-1, glm::vec2(), true, false, [=](ItemStack& stack) {
stack.clear();
}, nullptr);
auto layout = assets->getLayout("core:inventory");
if (layout) {
std::cout << "custom layout used" << std::endl;
auto view = std::dynamic_pointer_cast<InventoryView>(layout->getRoot());
view->bind(inventory, frontend, interaction.get());
return view;
} else {
std::cout << "generated layout used" << std::endl;
SlotLayout slotLayout(-1, glm::vec2(), true, false, [=](ItemStack& stack) {
stack.clear();
}, nullptr);
InventoryBuilder builder;
builder.addGrid(10, inventory->size(), glm::vec2(), 4, true, slotLayout);
auto view = builder.build();
view->bind(inventory, frontend, interaction.get());
return view;
InventoryBuilder builder;
builder.addGrid(10, inventory->size(), glm::vec2(), 4, true, slotLayout);
auto view = builder.build();
view->bind(inventory, frontend, interaction.get());
return view;
}
}
HudRenderer::HudRenderer(Engine* engine, LevelFrontend* frontend)