Update KekEngine, Update ConsoleElement

This commit is contained in:
MrLetsplay 2023-10-20 22:19:35 +02:00
parent 639d2ce889
commit 98e01b7e9a
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
4 changed files with 18 additions and 3 deletions

@ -1 +1 @@
Subproject commit bbee789593fda91071e2d06a0320c05d12b59649 Subproject commit 638c7165076a0f43eaeef4fda6d4d2828e2cb292

View File

@ -26,6 +26,12 @@ ConsoleElement::ConsoleElement(kek::UIValue x, kek::UIValue y, kek::UIValue w, k
textFieldElement->cursor->color = kek::Colors::WHITE; textFieldElement->cursor->color = kek::Colors::WHITE;
textFieldElement->textElement->color = kek::Colors::WHITE; textFieldElement->textElement->color = kek::Colors::WHITE;
addChild(textFieldElement); addChild(textFieldElement);
textFieldElement->onSubmit = kek::SubmitCallback([](std::string text, void *data) {
ConsoleElement *_this = (ConsoleElement *) data;
_this->onCommand(CommandEvent{text});
},
this);
} }
ConsoleElement::~ConsoleElement() { ConsoleElement::~ConsoleElement() {

View File

@ -41,9 +41,9 @@ void gameLoop(GLFWwindow *window, void *) {}
void startGame() { void startGame() {
ConsoleElement *console = new ConsoleElement(uiPx(10), uiPx(10), uiSw(1) - uiPx(20), uiSh(1) - uiPx(20)); ConsoleElement *console = new ConsoleElement(uiPx(10), uiPx(10), uiSw(1) - uiPx(20), uiSh(1) - uiPx(20));
console->textFieldElement->onSubmit = SubmitCallback([](std::string text, void *data) { console->onCommand = CommandCallback([](CommandEvent event, void *data) {
ConsoleElement *_console = (ConsoleElement *) data; ConsoleElement *_console = (ConsoleElement *) data;
_console->textElement->setText(_console->textElement->getText() + "\n" + "> " + text); _console->textElement->setText(_console->textElement->getText() + "\n" + "> " + event.command);
_console->textFieldElement->setText(""); _console->textFieldElement->setText("");
UI::focusElement(_console->textFieldElement); UI::focusElement(_console->textFieldElement);
}, },

View File

@ -2,6 +2,13 @@
#include "ui.h" #include "ui.h"
#include "uielements.h" #include "uielements.h"
#include "utils.h"
struct CommandEvent {
std::string command;
};
typedef kek::GenericCallable<CommandEvent> CommandCallback;
class ConsoleElement: public kek::RectangleElement { class ConsoleElement: public kek::RectangleElement {
@ -9,6 +16,8 @@ class ConsoleElement: public kek::RectangleElement {
kek::TextElement *textElement; kek::TextElement *textElement;
kek::TextFieldElement *textFieldElement; kek::TextFieldElement *textFieldElement;
CommandCallback onCommand;
ConsoleElement(kek::UIValue x, kek::UIValue y, kek::UIValue w, kek::UIValue h); ConsoleElement(kek::UIValue x, kek::UIValue y, kek::UIValue w, kek::UIValue h);
virtual ~ConsoleElement(); virtual ~ConsoleElement();