diff --git a/res/layouts/inventory.xml b/res/layouts/inventory.xml
new file mode 100644
index 00000000..b5ea903c
--- /dev/null
+++ b/res/layouts/inventory.xml
@@ -0,0 +1,3 @@
+
+
+
diff --git a/src/assets/Assets.cpp b/src/assets/Assets.cpp
index 3d10e1e1..7d34d6a0 100644
--- a/src/assets/Assets.cpp
+++ b/src/assets/Assets.cpp
@@ -87,6 +87,9 @@ void Assets::extend(const Assets& assets) {
for (auto entry : assets.atlases) {
atlases[entry.first] = entry.second;
}
+ for (auto entry : assets.layouts) {
+ layouts[entry.first] = entry.second;
+ }
animations.clear();
for (auto entry : assets.animations) {
animations.emplace_back(entry);
diff --git a/src/assets/AssetsLoader.cpp b/src/assets/AssetsLoader.cpp
index 91b9861a..177f2e9e 100644
--- a/src/assets/AssetsLoader.cpp
+++ b/src/assets/AssetsLoader.cpp
@@ -9,9 +9,6 @@
#include "../constants.h"
#include "../files/engine_paths.h"
-using std::filesystem::path;
-using std::unique_ptr;
-
AssetsLoader::AssetsLoader(Assets* assets, const ResPaths* paths)
: assets(assets), paths(paths) {
}
diff --git a/src/assets/AssetsLoader.h b/src/assets/AssetsLoader.h
index c4a1874d..bce21bdf 100644
--- a/src/assets/AssetsLoader.h
+++ b/src/assets/AssetsLoader.h
@@ -15,7 +15,7 @@ const short ASSET_LAYOUT = 5;
class ResPaths;
class Assets;
-typedef std::function aloader_func;
+using aloader_func = std::function;
struct aloader_entry {
int tag;
diff --git a/src/frontend/InventoryView.cpp b/src/frontend/InventoryView.cpp
index fffa0a7a..1380245b 100644
--- a/src/frontend/InventoryView.cpp
+++ b/src/frontend/InventoryView.cpp
@@ -260,6 +260,7 @@ void SlotView::bind(
bound = &stack;
content = frontend->getLevel()->content;
this->frontend = frontend;
+ this->interaction = interaction;
}
const SlotLayout& SlotView::getLayout() const {
diff --git a/src/frontend/UiDocument.cpp b/src/frontend/UiDocument.cpp
index 7cb5b343..88702084 100644
--- a/src/frontend/UiDocument.cpp
+++ b/src/frontend/UiDocument.cpp
@@ -11,10 +11,23 @@ UiDocument::UiDocument(
std::string namesp,
uidocscript script,
std::shared_ptr 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 UiDocument::getRoot() const {
+ return root;
+}
+
void UiDocument::collect(uinodes_map& map, std::shared_ptr node) {
const std::string& id = node->getId();
if (!id.empty()) {
diff --git a/src/frontend/UiDocument.h b/src/frontend/UiDocument.h
index e724faff..a987ecf3 100644
--- a/src/frontend/UiDocument.h
+++ b/src/frontend/UiDocument.h
@@ -30,6 +30,7 @@ public:
const uinodes_map& getMap() const;
const std::string& getNamespace() const;
+ const std::shared_ptr getRoot() const;
/* Collect map of all uinodes having identifiers */
static void collect(uinodes_map& map, std::shared_ptr node);
diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp
index 0857c277..ef847332 100644
--- a/src/frontend/hud.cpp
+++ b/src/frontend/hud.cpp
@@ -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 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(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)