diff --git a/externals/cage b/externals/cage index f034fb6..71fb52e 160000 --- a/externals/cage +++ b/externals/cage @@ -1 +1 @@ -Subproject commit f034fb64b11e33e6e446720db489f27c8d9eca13 +Subproject commit 71fb52e6c7f4caef47216c181a22063208aff52e diff --git a/sources/camera.cpp b/sources/camera.cpp index 262a341..f7c4760 100644 --- a/sources/camera.cpp +++ b/sources/camera.cpp @@ -57,9 +57,8 @@ namespace Entity *camera; Holder manualCamera; AutoCamera autoCamera; - EventListener keyPressListener; - void keyPress(InputKey in) + void keyPress(input::KeyPress in) { if (in.key == 32) { @@ -82,6 +81,8 @@ namespace } } + EventListener keyPressListener = engineEvents().listen(inputFilter(keyPress)); + const auto engineInitListener = controlThread().initialize.listen( []() { @@ -110,8 +111,6 @@ namespace manualCamera->freeMove = true; manualCamera->mouseButton = MouseButtonsFlags::Left; manualCamera->movementSpeed = 3; - keyPressListener.attach(engineWindow()->events); - keyPressListener.bind(inputListener(&keyPress)); }, -200); diff --git a/sources/gui.cpp b/sources/gui.cpp index 0cb0434..ff74c98 100644 --- a/sources/gui.cpp +++ b/sources/gui.cpp @@ -30,13 +30,12 @@ namespace EventListener guiListener; - void guiEvent(InputGuiWidget in) + void guiEvent(input::GuiValue in) { - uint32 index = in.widget - 20; - if (index < sizeof(propertyValues) / sizeof(propertyValues[0])) + const uint32 index = in.entity->name() - 20; + if (index < array_size(propertyValues)) { - Entity *e = engineGuiEntities()->get(in.widget); - GuiInputComponent &input = e->value(); + GuiInputComponent &input = in.entity->value(); if (input.valid) *propertyValues[index] = toFloat(input.value); } @@ -48,7 +47,7 @@ namespace Holder g = newGuiBuilder(engineGuiEntities()); guiListener.attach(engineGuiManager()->widgetEvent); - guiListener.bind(inputListener(&guiEvent)); + guiListener.bind(inputFilter(guiEvent)); auto _1 = g->alignment(Vec2()); auto _2 = g->spoiler().text("Ships"); diff --git a/sources/main.cpp b/sources/main.cpp index eef938d..e98a1c3 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -13,14 +13,6 @@ using namespace cage; -namespace -{ - void windowClose(InputWindow) - { - engineStop(); - } -} - int main(int argc, const char *args[]) { try @@ -34,7 +26,7 @@ int main(int argc, const char *args[]) controlThread().updatePeriod(1000000 / 30); engineAssets()->add(HashString("ants/ants.pack")); - const auto closeListener = engineWindow()->events.listen(inputListener([](auto) { engineStop(); })); + const auto closeListener = engineWindow()->events.listen(inputFilter([](input::WindowClose) { engineStop(); })); engineWindow()->title("space-ants"); {