test worlds panel with XML + lua
This commit is contained in:
+23
-21
@@ -81,6 +81,28 @@ void GUI::actMouse(float delta) {
|
||||
}
|
||||
}
|
||||
|
||||
void GUI::actFocused() {
|
||||
if (Events::jpressed(keycode::ESCAPE)) {
|
||||
focus->defocus();
|
||||
focus = nullptr;
|
||||
return;
|
||||
}
|
||||
for (auto codepoint : Events::codepoints) {
|
||||
focus->typed(codepoint);
|
||||
}
|
||||
for (auto key : Events::pressedKeys) {
|
||||
focus->keyPressed(key);
|
||||
}
|
||||
|
||||
if (!Events::_cursor_locked) {
|
||||
if (Events::clicked(mousecode::BUTTON_1) &&
|
||||
(Events::jclicked(mousecode::BUTTON_1) || Events::delta.x || Events::delta.y))
|
||||
{
|
||||
focus->mouseMove(this, Events::cursor.x, Events::cursor.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief Processing user input and UI logic
|
||||
/// @param delta delta time
|
||||
void GUI::act(float delta) {
|
||||
@@ -99,27 +121,7 @@ void GUI::act(float delta) {
|
||||
}
|
||||
|
||||
if (focus) {
|
||||
if (Events::jpressed(keycode::ESCAPE)) {
|
||||
focus->defocus();
|
||||
focus = nullptr;
|
||||
} else {
|
||||
for (auto codepoint : Events::codepoints) {
|
||||
focus->typed(codepoint);
|
||||
}
|
||||
for (auto key : Events::pressedKeys) {
|
||||
focus->keyPressed(key);
|
||||
}
|
||||
|
||||
if (!Events::_cursor_locked) {
|
||||
if (Events::clicked(mousecode::BUTTON_1)) {
|
||||
if (Events::jclicked(mousecode::BUTTON_1) ||
|
||||
Events::delta.x || Events::delta.y)
|
||||
{
|
||||
focus->mouseMove(this, Events::cursor.x, Events::cursor.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
actFocused();
|
||||
}
|
||||
if (focus && !focus->isFocused()) {
|
||||
focus = nullptr;
|
||||
|
||||
@@ -63,6 +63,7 @@ namespace gui {
|
||||
std::shared_ptr<Menu> menu;
|
||||
std::queue<runnable> postRunnables;
|
||||
void actMouse(float delta);
|
||||
void actFocused();
|
||||
public:
|
||||
GUI();
|
||||
~GUI();
|
||||
|
||||
@@ -176,6 +176,11 @@ namespace gui {
|
||||
virtual void setMinSize(glm::vec2 size);
|
||||
/* Called in containers when new element added */
|
||||
virtual void refresh() {};
|
||||
virtual void fullRefresh() {
|
||||
if (parent) {
|
||||
parent->fullRefresh();
|
||||
}
|
||||
};
|
||||
virtual void lock();
|
||||
|
||||
virtual vec2supplier getPositionFunc() const;
|
||||
|
||||
@@ -192,10 +192,15 @@ void Panel::cropToContent() {
|
||||
}
|
||||
}
|
||||
|
||||
void Panel::add(std::shared_ptr<UINode> node) {
|
||||
Container::add(node);
|
||||
void Panel::fullRefresh() {
|
||||
refresh();
|
||||
cropToContent();
|
||||
Container::fullRefresh();
|
||||
}
|
||||
|
||||
void Panel::add(std::shared_ptr<UINode> node) {
|
||||
Container::add(node);
|
||||
fullRefresh();
|
||||
}
|
||||
|
||||
void Panel::refresh() {
|
||||
@@ -255,7 +260,7 @@ bool Menu::has(const std::string& name) {
|
||||
}
|
||||
|
||||
void Menu::addPage(std::string name, std::shared_ptr<UINode> panel) {
|
||||
pages[name] = Page{panel};
|
||||
pages[name] = Page{name, panel};
|
||||
}
|
||||
|
||||
void Menu::addSupplier(std::string name, supplier<std::shared_ptr<UINode>> pageSupplier) {
|
||||
@@ -276,13 +281,16 @@ void Menu::setPage(std::string name, bool history) {
|
||||
} else {
|
||||
page = found->second;
|
||||
}
|
||||
setPage(page, history);
|
||||
}
|
||||
|
||||
void Menu::setPage(Page page, bool history) {
|
||||
if (current.panel) {
|
||||
Container::remove(current.panel);
|
||||
}
|
||||
if (history) {
|
||||
pageStack.push(curname);
|
||||
pageStack.push(current);
|
||||
}
|
||||
curname = name;
|
||||
current = page;
|
||||
Container::add(current.panel);
|
||||
setSize(current.panel->getSize());
|
||||
@@ -291,29 +299,24 @@ void Menu::setPage(std::string name, bool history) {
|
||||
void Menu::back() {
|
||||
if (pageStack.empty())
|
||||
return;
|
||||
std::string name = pageStack.top();
|
||||
Page page = pageStack.top();
|
||||
pageStack.pop();
|
||||
setPage(name, false);
|
||||
setPage(page, false);
|
||||
}
|
||||
|
||||
Page& Menu::getCurrent() {
|
||||
return current;
|
||||
}
|
||||
|
||||
const std::string& Menu::getCurrentName() const {
|
||||
return curname;
|
||||
}
|
||||
|
||||
void Menu::clearHistory() {
|
||||
pageStack = std::stack<std::string>();
|
||||
pageStack = std::stack<Page>();
|
||||
}
|
||||
|
||||
void Menu::reset() {
|
||||
clearHistory();
|
||||
if (current.panel) {
|
||||
curname = "";
|
||||
Container::remove(current.panel);
|
||||
current = Page{nullptr};
|
||||
current = Page{"", nullptr};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,6 +76,7 @@ namespace gui {
|
||||
virtual void add(std::shared_ptr<UINode> node) override;
|
||||
|
||||
virtual void refresh() override;
|
||||
virtual void fullRefresh() override;
|
||||
|
||||
virtual void setMaxLength(int value);
|
||||
int getMaxLength() const;
|
||||
@@ -85,6 +86,7 @@ namespace gui {
|
||||
};
|
||||
|
||||
struct Page {
|
||||
std::string name;
|
||||
std::shared_ptr<UINode> panel = nullptr;
|
||||
|
||||
~Page() {
|
||||
@@ -95,9 +97,8 @@ namespace gui {
|
||||
class Menu : public Container {
|
||||
protected:
|
||||
std::unordered_map<std::string, Page> pages;
|
||||
std::stack<std::string> pageStack;
|
||||
std::stack<Page> pageStack;
|
||||
Page current;
|
||||
std::string curname = "";
|
||||
std::unordered_map<std::string, supplier<std::shared_ptr<UINode>>> pageSuppliers;
|
||||
public:
|
||||
Menu();
|
||||
@@ -110,6 +111,7 @@ namespace gui {
|
||||
/// @param name page or page supplier name
|
||||
/// @param history previous page will not be saved in history if false
|
||||
void setPage(std::string name, bool history=true);
|
||||
void setPage(Page page, bool history=true);
|
||||
void addPage(std::string name, std::shared_ptr<UINode> panel);
|
||||
|
||||
/// @brief Add page supplier used if page is not found
|
||||
@@ -128,9 +130,6 @@ namespace gui {
|
||||
|
||||
/// @brief Get current page
|
||||
Page& getCurrent();
|
||||
|
||||
/// @brief Get current page name
|
||||
const std::string& getCurrentName() const;
|
||||
};
|
||||
}
|
||||
#endif // GRAPHICS_UI_ELEMENTS_CONTAINERS_H_
|
||||
|
||||
Reference in New Issue
Block a user