diff --git a/dependencies/kekengine b/dependencies/kekengine index bbee789..638c716 160000 --- a/dependencies/kekengine +++ b/dependencies/kekengine @@ -1 +1 @@ -Subproject commit bbee789593fda91071e2d06a0320c05d12b59649 +Subproject commit 638c7165076a0f43eaeef4fda6d4d2828e2cb292 diff --git a/src/haxxorizer/cpp/elements.cpp b/src/haxxorizer/cpp/elements.cpp index 4ed697a..c43cdf7 100644 --- a/src/haxxorizer/cpp/elements.cpp +++ b/src/haxxorizer/cpp/elements.cpp @@ -26,6 +26,12 @@ ConsoleElement::ConsoleElement(kek::UIValue x, kek::UIValue y, kek::UIValue w, k textFieldElement->cursor->color = kek::Colors::WHITE; textFieldElement->textElement->color = kek::Colors::WHITE; addChild(textFieldElement); + + textFieldElement->onSubmit = kek::SubmitCallback([](std::string text, void *data) { + ConsoleElement *_this = (ConsoleElement *) data; + _this->onCommand(CommandEvent{text}); + }, + this); } ConsoleElement::~ConsoleElement() { diff --git a/src/haxxorizer/cpp/haxxorizer.cpp b/src/haxxorizer/cpp/haxxorizer.cpp index 935e4af..794b2bd 100644 --- a/src/haxxorizer/cpp/haxxorizer.cpp +++ b/src/haxxorizer/cpp/haxxorizer.cpp @@ -41,9 +41,9 @@ void gameLoop(GLFWwindow *window, void *) {} void startGame() { 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; - _console->textElement->setText(_console->textElement->getText() + "\n" + "> " + text); + _console->textElement->setText(_console->textElement->getText() + "\n" + "> " + event.command); _console->textFieldElement->setText(""); UI::focusElement(_console->textFieldElement); }, diff --git a/src/haxxorizer/include/elements.h b/src/haxxorizer/include/elements.h index 4de8015..74a5ae7 100644 --- a/src/haxxorizer/include/elements.h +++ b/src/haxxorizer/include/elements.h @@ -2,6 +2,13 @@ #include "ui.h" #include "uielements.h" +#include "utils.h" + +struct CommandEvent { + std::string command; +}; + +typedef kek::GenericCallable CommandCallback; class ConsoleElement: public kek::RectangleElement { @@ -9,6 +16,8 @@ class ConsoleElement: public kek::RectangleElement { kek::TextElement *textElement; kek::TextFieldElement *textFieldElement; + CommandCallback onCommand; + ConsoleElement(kek::UIValue x, kek::UIValue y, kek::UIValue w, kek::UIValue h); virtual ~ConsoleElement();