layout test
This commit is contained in:
parent
07adbd04ea
commit
9ad371862c
3
res/layouts/inventory.xml
Normal file
3
res/layouts/inventory.xml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<inventory color="#00000080">
|
||||||
|
<slots-grid cols="4" count="40"/>
|
||||||
|
</inventory>
|
||||||
@ -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);
|
||||||
|
|||||||
@ -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) {
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
@ -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()) {
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user