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

View File

@ -0,0 +1,3 @@
<inventory color="#00000080">
<slots-grid cols="4" count="40"/>
</inventory>

View File

@ -87,6 +87,9 @@ void Assets::extend(const Assets& assets) {
for (auto entry : assets.atlases) { for (auto entry : assets.atlases) {
atlases[entry.first] = entry.second; atlases[entry.first] = entry.second;
} }
for (auto entry : assets.layouts) {
layouts[entry.first] = entry.second;
}
animations.clear(); animations.clear();
for (auto entry : assets.animations) { for (auto entry : assets.animations) {
animations.emplace_back(entry); animations.emplace_back(entry);

View File

@ -9,9 +9,6 @@
#include "../constants.h" #include "../constants.h"
#include "../files/engine_paths.h" #include "../files/engine_paths.h"
using std::filesystem::path;
using std::unique_ptr;
AssetsLoader::AssetsLoader(Assets* assets, const ResPaths* paths) AssetsLoader::AssetsLoader(Assets* assets, const ResPaths* paths)
: assets(assets), paths(paths) { : assets(assets), paths(paths) {
} }

View File

@ -15,7 +15,7 @@ const short ASSET_LAYOUT = 5;
class ResPaths; class ResPaths;
class Assets; class Assets;
typedef std::function<bool(Assets*, const ResPaths*, const std::string&, const std::string&)> aloader_func; using aloader_func = std::function<bool(Assets*, const ResPaths*, const std::string&, const std::string&)>;
struct aloader_entry { struct aloader_entry {
int tag; int tag;

View File

@ -260,6 +260,7 @@ void SlotView::bind(
bound = &stack; bound = &stack;
content = frontend->getLevel()->content; content = frontend->getLevel()->content;
this->frontend = frontend; this->frontend = frontend;
this->interaction = interaction;
} }
const SlotLayout& SlotView::getLayout() const { const SlotLayout& SlotView::getLayout() const {

View File

@ -11,10 +11,23 @@ UiDocument::UiDocument(
std::string namesp, std::string namesp,
uidocscript script, uidocscript script,
std::shared_ptr<gui::UINode> root std::shared_ptr<gui::UINode> root
) { ) : namesp(namesp), script(script), root(root) {
collect(map, 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) { void UiDocument::collect(uinodes_map& map, std::shared_ptr<gui::UINode> node) {
const std::string& id = node->getId(); const std::string& id = node->getId();
if (!id.empty()) { if (!id.empty()) {

View File

@ -30,6 +30,7 @@ public:
const uinodes_map& getMap() const; const uinodes_map& getMap() const;
const std::string& getNamespace() const; const std::string& getNamespace() const;
const std::shared_ptr<gui::UINode> getRoot() const;
/* Collect map of all uinodes having identifiers */ /* Collect map of all uinodes having identifiers */
static void collect(uinodes_map& map, std::shared_ptr<gui::UINode> node); static void collect(uinodes_map& map, std::shared_ptr<gui::UINode> node);

View File

@ -31,7 +31,6 @@
#include "../objects/Player.h" #include "../objects/Player.h"
#include "../physics/Hitbox.h" #include "../physics/Hitbox.h"
#include "../maths/voxmaths.h" #include "../maths/voxmaths.h"
#include "../files/files.h"
#include "gui/controls.h" #include "gui/controls.h"
#include "gui/panels.h" #include "gui/panels.h"
#include "gui/UINode.h" #include "gui/UINode.h"
@ -42,6 +41,7 @@
#include "BlocksPreview.h" #include "BlocksPreview.h"
#include "InventoryView.h" #include "InventoryView.h"
#include "LevelFrontend.h" #include "LevelFrontend.h"
#include "UiDocument.h"
#include "../engine.h" #include "../engine.h"
#include "../core_defs.h" #include "../core_defs.h"
#include "../items/ItemDef.h" #include "../items/ItemDef.h"
@ -217,6 +217,14 @@ std::shared_ptr<InventoryView> HudRenderer::createInventory() {
auto player = level->player; auto player = level->player;
auto inventory = player->getInventory(); auto inventory = player->getInventory();
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) { SlotLayout slotLayout(-1, glm::vec2(), true, false, [=](ItemStack& stack) {
stack.clear(); stack.clear();
}, nullptr); }, nullptr);
@ -226,6 +234,7 @@ std::shared_ptr<InventoryView> HudRenderer::createInventory() {
auto view = builder.build(); auto view = builder.build();
view->bind(inventory, frontend, interaction.get()); view->bind(inventory, frontend, interaction.get());
return view; return view;
}
} }
HudRenderer::HudRenderer(Engine* engine, LevelFrontend* frontend) HudRenderer::HudRenderer(Engine* engine, LevelFrontend* frontend)