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) {
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);

View File

@ -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) {
}

View File

@ -15,7 +15,7 @@ const short ASSET_LAYOUT = 5;
class ResPaths;
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 {
int tag;

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 {

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()) {

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);

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)