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