minor refactor + Block.uiLayout
This commit is contained in:
@@ -173,6 +173,7 @@ void ContentLoader::loadBlock(Block& def, std::string name, fs::path file) {
|
|||||||
root->num("draw-group", def.drawGroup);
|
root->num("draw-group", def.drawGroup);
|
||||||
root->str("picking-item", def.pickingItem);
|
root->str("picking-item", def.pickingItem);
|
||||||
root->str("script-name", def.scriptName);
|
root->str("script-name", def.scriptName);
|
||||||
|
root->str("ui-layout", def.uiLayout);
|
||||||
root->num("inventory-size", def.inventorySize);
|
root->num("inventory-size", def.inventorySize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
#include "../maths/voxmaths.h"
|
#include "../maths/voxmaths.h"
|
||||||
#include "../objects/Player.h"
|
#include "../objects/Player.h"
|
||||||
#include "../voxels/Block.h"
|
#include "../voxels/Block.h"
|
||||||
#include "../frontend/gui/panels.h"
|
#include "../frontend/gui/containers.h"
|
||||||
#include "../frontend/gui/controls.h"
|
#include "../frontend/gui/controls.h"
|
||||||
#include "../util/stringutil.h"
|
#include "../util/stringutil.h"
|
||||||
#include "../world/Level.h"
|
#include "../world/Level.h"
|
||||||
@@ -416,10 +416,6 @@ static void readSlotsGrid(InventoryView* view, gui::UiXmlReader& reader, xml::xm
|
|||||||
}
|
}
|
||||||
layout.padding = padding;
|
layout.padding = padding;
|
||||||
|
|
||||||
glm::vec2 size (
|
|
||||||
cols * slotSize + (cols - 1) * interval + padding * 2,
|
|
||||||
rows * slotSize + (rows - 1) * interval + padding * 2
|
|
||||||
);
|
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
for (int row = 0; row < rows; row++) {
|
for (int row = 0; row < rows; row++) {
|
||||||
for (int col = 0; col < cols; col++, idx++) {
|
for (int col = 0; col < cols; col++, idx++) {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include "../frontend/gui/UINode.h"
|
#include "../frontend/gui/UINode.h"
|
||||||
#include "../frontend/gui/panels.h"
|
#include "../frontend/gui/containers.h"
|
||||||
#include "../frontend/gui/controls.h"
|
#include "../frontend/gui/controls.h"
|
||||||
#include "../items/ItemStack.h"
|
#include "../items/ItemStack.h"
|
||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "gui/UINode.h"
|
#include "gui/UINode.h"
|
||||||
#include "gui/panels.h"
|
#include "gui/containers.h"
|
||||||
#include "InventoryView.h"
|
#include "InventoryView.h"
|
||||||
#include "../logic/scripting/scripting.h"
|
#include "../logic/scripting/scripting.h"
|
||||||
#include "../files/files.h"
|
#include "../files/files.h"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "GUI.h"
|
#include "GUI.h"
|
||||||
#include "UINode.h"
|
#include "UINode.h"
|
||||||
#include "panels.h"
|
#include "containers.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ namespace gui {
|
|||||||
class Container;
|
class Container;
|
||||||
class PagesControl;
|
class PagesControl;
|
||||||
|
|
||||||
|
/** The main UI controller */
|
||||||
class GUI {
|
class GUI {
|
||||||
std::shared_ptr<Container> container;
|
std::shared_ptr<Container> container;
|
||||||
std::shared_ptr<UINode> hover = nullptr;
|
std::shared_ptr<UINode> hover = nullptr;
|
||||||
@@ -81,4 +82,4 @@ namespace gui {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // FRONTEND_GUI_GUI_H_
|
#endif // FRONTEND_GUI_GUI_H_
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ namespace gui {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class UINode {
|
class UINode {
|
||||||
|
/**
|
||||||
|
* element identifier used for direct access in UiDocument
|
||||||
|
*/
|
||||||
std::string id = "";
|
std::string id = "";
|
||||||
protected:
|
protected:
|
||||||
glm::vec2 coord;
|
glm::vec2 coord;
|
||||||
@@ -44,6 +47,9 @@ namespace gui {
|
|||||||
UINode(glm::vec2 coord, glm::vec2 size);
|
UINode(glm::vec2 coord, glm::vec2 size);
|
||||||
public:
|
public:
|
||||||
virtual ~UINode();
|
virtual ~UINode();
|
||||||
|
/** Called every frame for all visible elements
|
||||||
|
* @param delta delta time
|
||||||
|
*/
|
||||||
virtual void act(float delta) {};
|
virtual void act(float delta) {};
|
||||||
virtual void draw(const GfxContext* pctx, Assets* assets) = 0;
|
virtual void draw(const GfxContext* pctx, Assets* assets) = 0;
|
||||||
|
|
||||||
@@ -59,11 +65,11 @@ namespace gui {
|
|||||||
virtual void setParent(UINode* node);
|
virtual void setParent(UINode* node);
|
||||||
UINode* getParent() const;
|
UINode* getParent() const;
|
||||||
|
|
||||||
/* Set element color (doesn't affect inner elements).
|
/** Set element color (doesn't affect inner elements).
|
||||||
Also replaces hover color to avoid adding extra properties. */
|
Also replaces hover color to avoid adding extra properties. */
|
||||||
virtual void setColor(glm::vec4 newColor);
|
virtual void setColor(glm::vec4 newColor);
|
||||||
|
|
||||||
/* Get element color */
|
/** Get element color (float R,G,B,A in range [0.0, 1.0])*/
|
||||||
glm::vec4 getColor() const;
|
glm::vec4 getColor() const;
|
||||||
|
|
||||||
virtual void setHoverColor(glm::vec4 newColor);
|
virtual void setHoverColor(glm::vec4 newColor);
|
||||||
@@ -72,6 +78,8 @@ namespace gui {
|
|||||||
virtual void setMargin(glm::vec4 margin);
|
virtual void setMargin(glm::vec4 margin);
|
||||||
glm::vec4 getMargin() const;
|
glm::vec4 getMargin() const;
|
||||||
|
|
||||||
|
/** Influences container elements sort order
|
||||||
|
Doesn't work in Panel */
|
||||||
virtual void setZIndex(int idx);
|
virtual void setZIndex(int idx);
|
||||||
int getZIndex() const;
|
int getZIndex() const;
|
||||||
|
|
||||||
@@ -86,20 +94,20 @@ namespace gui {
|
|||||||
void defocus();
|
void defocus();
|
||||||
bool isFocused() const;
|
bool isFocused() const;
|
||||||
|
|
||||||
/* Check if elements catches all user input when focused */
|
/** Check if element catches all user input when focused */
|
||||||
virtual bool isFocuskeeper() const {return false;}
|
virtual bool isFocuskeeper() const {return false;}
|
||||||
|
|
||||||
virtual void typed(unsigned int codepoint) {};
|
virtual void typed(unsigned int codepoint) {};
|
||||||
virtual void keyPressed(int key) {};
|
virtual void keyPressed(int key) {};
|
||||||
|
|
||||||
/* Check if screen position is inside of the element
|
/** Check if screen position is inside of the element
|
||||||
@param pos screen position */
|
* @param pos screen position */
|
||||||
virtual bool isInside(glm::vec2 pos);
|
virtual bool isInside(glm::vec2 pos);
|
||||||
|
|
||||||
/* Get element under the cursor.
|
/** Get element under the cursor.
|
||||||
@param pos cursor screen position
|
* @param pos cursor screen position
|
||||||
@param self shared pointer to element
|
* @param self shared pointer to element
|
||||||
@return self, sub-element or nullptr if element is not interractive */
|
* @return self, sub-element or nullptr if element is not interractive */
|
||||||
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self);
|
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self);
|
||||||
|
|
||||||
/* Check if element is opaque for cursor */
|
/* Check if element is opaque for cursor */
|
||||||
@@ -120,6 +128,7 @@ namespace gui {
|
|||||||
virtual void setSize(glm::vec2 size);
|
virtual void setSize(glm::vec2 size);
|
||||||
virtual glm::vec2 getMinSize() const;
|
virtual glm::vec2 getMinSize() const;
|
||||||
virtual void setMinSize(glm::vec2 size);
|
virtual void setMinSize(glm::vec2 size);
|
||||||
|
/* Called in containers when new element added */
|
||||||
virtual void refresh() {};
|
virtual void refresh() {};
|
||||||
virtual void lock();
|
virtual void lock();
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "panels.h"
|
#include "containers.h"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -301,3 +301,4 @@ void PagesControl::reset() {
|
|||||||
current = Page{nullptr};
|
current = Page{nullptr};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef FRONTEND_GUI_PANELS_H_
|
#ifndef FRONTEND_GUI_CONTAINERS_H_
|
||||||
#define FRONTEND_GUI_PANELS_H_
|
#define FRONTEND_GUI_CONTAINERS_H_
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -109,4 +109,4 @@ namespace gui {
|
|||||||
Page& getCurrent();
|
Page& getCurrent();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // FRONTEND_GUI_PANELS_H_
|
#endif // FRONTEND_GUI_CONTAINERS_H_
|
||||||
@@ -335,15 +335,15 @@ std::shared_ptr<UINode> TextBox::getAt(glm::vec2 pos, std::shared_ptr<UINode> se
|
|||||||
return UINode::getAt(pos, self);
|
return UINode::getAt(pos, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextBox::textSupplier(wstringsupplier supplier) {
|
void TextBox::setTextSupplier(wstringsupplier supplier) {
|
||||||
this->supplier = supplier;
|
this->supplier = supplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextBox::textConsumer(wstringconsumer consumer) {
|
void TextBox::setTextConsumer(wstringconsumer consumer) {
|
||||||
this->consumer = consumer;
|
this->consumer = consumer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextBox::textValidator(wstringchecker validator) {
|
void TextBox::setTextValidator(wstringchecker validator) {
|
||||||
this->validator = validator;
|
this->validator = validator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
#include "GUI.h"
|
#include "GUI.h"
|
||||||
#include "UINode.h"
|
#include "UINode.h"
|
||||||
#include "panels.h"
|
#include "containers.h"
|
||||||
#include "../../window/input.h"
|
#include "../../window/input.h"
|
||||||
#include "../../delegates.h"
|
#include "../../delegates.h"
|
||||||
|
|
||||||
@@ -111,11 +111,13 @@ namespace gui {
|
|||||||
virtual void drawBackground(const GfxContext* pctx, Assets* assets) override;
|
virtual void drawBackground(const GfxContext* pctx, Assets* assets) override;
|
||||||
virtual void typed(unsigned int codepoint) override;
|
virtual void typed(unsigned int codepoint) override;
|
||||||
virtual void keyPressed(int key) override;
|
virtual void keyPressed(int key) override;
|
||||||
virtual void textSupplier(wstringsupplier supplier);
|
virtual void setTextSupplier(wstringsupplier supplier);
|
||||||
virtual void textConsumer(wstringconsumer consumer);
|
virtual void setTextConsumer(wstringconsumer consumer);
|
||||||
virtual void textValidator(wstringchecker validator);
|
virtual void setTextValidator(wstringchecker validator);
|
||||||
virtual bool isFocuskeeper() const override {return true;}
|
virtual bool isFocuskeeper() const override {return true;}
|
||||||
|
/* Get TextBox content text or placeholder if empty */
|
||||||
virtual std::wstring getText() const;
|
virtual std::wstring getText() const;
|
||||||
|
/* Set TextBox content text */
|
||||||
virtual void setText(std::wstring value);
|
virtual void setText(std::wstring value);
|
||||||
virtual bool validate();
|
virtual bool validate();
|
||||||
virtual void setValid(bool valid);
|
virtual void setValid(bool valid);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "gui_util.h"
|
#include "gui_util.h"
|
||||||
#include "controls.h"
|
#include "controls.h"
|
||||||
#include "panels.h"
|
#include "containers.h"
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <charconv>
|
#include <charconv>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include "panels.h"
|
#include "containers.h"
|
||||||
#include "controls.h"
|
#include "controls.h"
|
||||||
|
|
||||||
#include "../../assets/AssetsLoader.h"
|
#include "../../assets/AssetsLoader.h"
|
||||||
@@ -173,7 +173,7 @@ static std::shared_ptr<UINode> readTextBox(UiXmlReader& reader, xml::xmlelement
|
|||||||
element->attr("consumer").getText(),
|
element->attr("consumer").getText(),
|
||||||
reader.getFilename()+".lua"
|
reader.getFilename()+".lua"
|
||||||
);
|
);
|
||||||
textbox->textConsumer(consumer);
|
textbox->setTextConsumer(consumer);
|
||||||
}
|
}
|
||||||
return textbox;
|
return textbox;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
#include "../physics/Hitbox.h"
|
#include "../physics/Hitbox.h"
|
||||||
#include "../maths/voxmaths.h"
|
#include "../maths/voxmaths.h"
|
||||||
#include "gui/controls.h"
|
#include "gui/controls.h"
|
||||||
#include "gui/panels.h"
|
#include "gui/containers.h"
|
||||||
#include "gui/UINode.h"
|
#include "gui/UINode.h"
|
||||||
#include "gui/GUI.h"
|
#include "gui/GUI.h"
|
||||||
#include "ContentGfxCache.h"
|
#include "ContentGfxCache.h"
|
||||||
@@ -147,11 +147,11 @@ std::shared_ptr<UINode> Hud::createDebugPanel(Engine* engine) {
|
|||||||
|
|
||||||
// Coord input
|
// Coord input
|
||||||
auto box = std::make_shared<TextBox>(L"");
|
auto box = std::make_shared<TextBox>(L"");
|
||||||
box->textSupplier([=]() {
|
box->setTextSupplier([=]() {
|
||||||
Hitbox* hitbox = level->player->hitbox.get();
|
Hitbox* hitbox = level->player->hitbox.get();
|
||||||
return util::to_wstring(hitbox->position[ax], 2);
|
return util::to_wstring(hitbox->position[ax], 2);
|
||||||
});
|
});
|
||||||
box->textConsumer([=](std::wstring text) {
|
box->setTextConsumer([=](std::wstring text) {
|
||||||
try {
|
try {
|
||||||
glm::vec3 position = level->player->hitbox->position;
|
glm::vec3 position = level->player->hitbox->position;
|
||||||
position[ax] = std::stoi(text);
|
position[ax] = std::stoi(text);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include "gui/GUI.h"
|
#include "gui/GUI.h"
|
||||||
#include "gui/panels.h"
|
#include "gui/containers.h"
|
||||||
#include "gui/controls.h"
|
#include "gui/controls.h"
|
||||||
#include "screens.h"
|
#include "screens.h"
|
||||||
|
|
||||||
@@ -401,7 +401,7 @@ void create_new_world_panel(Engine* engine) {
|
|||||||
|
|
||||||
panel->add(std::make_shared<Label>(langs::get(L"Name", L"world")));
|
panel->add(std::make_shared<Label>(langs::get(L"Name", L"world")));
|
||||||
auto nameInput = std::make_shared<TextBox>(L"New World", vec4(6.0f));
|
auto nameInput = std::make_shared<TextBox>(L"New World", vec4(6.0f));
|
||||||
nameInput->textValidator([=](const std::wstring& text) {
|
nameInput->setTextValidator([=](const std::wstring& text) {
|
||||||
EnginePaths* paths = engine->getPaths();
|
EnginePaths* paths = engine->getPaths();
|
||||||
std::string textutf8 = util::wstr2str_utf8(text);
|
std::string textutf8 = util::wstr2str_utf8(text);
|
||||||
return util::is_valid_filename(text) &&
|
return util::is_valid_filename(text) &&
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
#include "ContentGfxCache.h"
|
#include "ContentGfxCache.h"
|
||||||
#include "LevelFrontend.h"
|
#include "LevelFrontend.h"
|
||||||
#include "gui/GUI.h"
|
#include "gui/GUI.h"
|
||||||
#include "gui/panels.h"
|
#include "gui/containers.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
|
|
||||||
#include "../content/Content.h"
|
#include "../content/Content.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user