diff --git a/sources/include/cage-core/events.h b/sources/include/cage-core/events.h index ddb42f51..0d11bd84 100644 --- a/sources/include/cage-core/events.h +++ b/sources/include/cage-core/events.h @@ -63,7 +63,7 @@ namespace cage } } - CAGE_FORCE_INLINE void clear() { del.b.clear(); } + CAGE_FORCE_INLINE void unbind() { del.b.clear(); } CAGE_FORCE_INLINE void attach(EventDispatcher &dispatcher, sint32 order = 0) { privat::EventLinker::attach(&dispatcher, order); } @@ -87,7 +87,7 @@ namespace cage { Delegate b; Delegate v; - CAGE_FORCE_INLINE Del() : b(){}; + CAGE_FORCE_INLINE Del() : b() {}; } del; bool vd = false; diff --git a/sources/include/cage-engine/keybinds.h b/sources/include/cage-engine/keybinds.h index 4c43d589..c435ffac 100644 --- a/sources/include/cage-engine/keybinds.h +++ b/sources/include/cage-engine/keybinds.h @@ -59,7 +59,7 @@ namespace cage sint32 displayOrder = 0; ModifiersFlags requiredFlags = ModifiersFlags::None; ModifiersFlags forbiddenFlags = ModifiersFlags::Super; - KeybindDevicesFlags devices = KeybindDevicesFlags::Keyboard | KeybindDevicesFlags::Mouse | KeybindDevicesFlags::Wheel; + KeybindDevicesFlags devices = KeybindDevicesFlags::Keyboard | KeybindDevicesFlags::Mouse; KeybindModesFlags modes = KeybindModesFlags::Press; }; diff --git a/sources/libengine/keybinds.cpp b/sources/libengine/keybinds.cpp index 0588d99d..eeb45c35 100644 --- a/sources/libengine/keybinds.cpp +++ b/sources/libengine/keybinds.cpp @@ -14,7 +14,11 @@ namespace cage { namespace { - std::vector global; + std::vector &global() + { + static std::vector g; + return g; + } CAGE_FORCE_INLINE String finishName(String s) { @@ -40,7 +44,7 @@ namespace cage CAGE_FORCE_INLINE KeybindModesFlags matchImpl(input::privat::BaseKey k, KeybindModesFlags activation) const { - if (k.key == key && checkFlags(k.mods)) + if (k.key == key && (checkFlags(k.mods) || activation == KeybindModesFlags::Release)) return activation; return KeybindModesFlags::None; } @@ -64,7 +68,7 @@ namespace cage CAGE_FORCE_INLINE KeybindModesFlags matchImpl(input::privat::BaseMouse k, KeybindModesFlags activation) const { - if (any(k.buttons & button) && checkFlags(k.mods)) + if (any(k.buttons & button) && (checkFlags(k.mods) || activation == KeybindModesFlags::Release)) return activation; return KeybindModesFlags::None; } @@ -94,7 +98,7 @@ namespace cage return KeybindModesFlags::None; } - CAGE_FORCE_INLINE String value() const { return finishName(Stringizer() + getModifiersNames(requiredFlags) + " Scroll"); } + CAGE_FORCE_INLINE String value() const { return finishName(Stringizer() + getModifiersNames(requiredFlags) + " WHEEL"); } }; using Matcher = std::variant; @@ -201,14 +205,14 @@ namespace cage CAGE_ASSERT(any(config.modes)); reset(); // make matchers from the defaults this->event = event; - global.push_back(this); + global().push_back(this); } ~KeybindImpl() { - auto it = std::find(global.begin(), global.end(), this); - if (it != global.end()) - global.erase(it); + auto it = std::find(global().begin(), global().end(), this); + if (it != global().end()) + global().erase(it); } bool process(const GenericInput &input) const @@ -234,7 +238,11 @@ namespace cage if (any(r & config.modes)) { if (event) - return event(input); + { + const bool p = event(input); + if (none(r & KeybindModesFlags::Release)) // release always propagates + return p; + } return false; } } @@ -285,7 +293,7 @@ namespace cage void cancel() { - assignmentListener.clear(); + assignmentListener.unbind(); assigningIndex = m; makeGui(); } @@ -380,7 +388,7 @@ namespace cage [](const auto &mt) -> String { if constexpr (std::is_same_v, std::monostate>) - return "-----"; + return ""; else return mt.value(); }, @@ -459,7 +467,7 @@ namespace cage Keybind *findKeybind(const String &id) { - for (KeybindImpl *it : global) + for (KeybindImpl *it : global()) { if (it->config.id == id) return it; @@ -470,9 +478,9 @@ namespace cage void keybindsRegisterListeners(EventDispatcher &dispatcher) { assignmentListener.attach(dispatcher, -328655984); - for (KeybindImpl *it : global) + for (KeybindImpl *it : global()) { - it->listener.clear(); + it->listener.unbind(); it->listener.bind([it](const GenericInput &in) { return it->process(in); }); it->listener.attach(dispatcher, it->config.eventOrder); } @@ -481,7 +489,7 @@ namespace cage void keybindsDispatchTick() { GenericInput g = input::Tick(); - for (KeybindImpl *it : global) + for (KeybindImpl *it : global()) it->process(g); } @@ -495,13 +503,19 @@ namespace cage void keybindsGuiTable(GuiBuilder *g, const String &filterPrefix) { - std::sort(global.begin(), global.end(), [](const KeybindImpl *a, const KeybindImpl *b) -> bool { return std::pair{ a->config.displayOrder, a->config.id } < std::pair{ b->config.displayOrder, b->config.id }; }); + std::vector tmp; + tmp.reserve(global().size()); + for (KeybindImpl *k : global()) + { + if (isPattern(k->config.id, filterPrefix, "", "")) + tmp.push_back(k); + } + std::sort(tmp.begin(), tmp.end(), [](const KeybindImpl *a, const KeybindImpl *b) -> bool { return std::tuple{ a->config.displayOrder, textsGet(a->textId), a->config.id } < std::tuple{ b->config.displayOrder, textsGet(b->textId), b->config.id }; }); + auto _ = g->verticalTable(2); - for (KeybindImpl *k : global) + for (KeybindImpl *k : tmp) { - if (!isPattern(k->config.id, filterPrefix, "", "")) - continue; - g->label().text(k->textId, k->config.id); + g->label().update([k](Entity *e) { e->value().color = k->active ? Vec3(0.5, 0.9, 1) : Vec3::Nan(); }).text(k->textId, k->config.id); keybindsGuiWidget(g, k); } } diff --git a/sources/libengine/window/window.cpp b/sources/libengine/window/window.cpp index 5837db52..5942d351 100644 --- a/sources/libengine/window/window.cpp +++ b/sources/libengine/window/window.cpp @@ -820,6 +820,8 @@ namespace cage { switch (key) { + case GLFW_KEY_SPACE: + return "_____"; case GLFW_KEY_ESCAPE: return "ESC"; case GLFW_KEY_ENTER: @@ -827,11 +829,11 @@ namespace cage case GLFW_KEY_TAB: return "TAB"; case GLFW_KEY_BACKSPACE: - return "BACKSPACE"; + return "BACK"; case GLFW_KEY_INSERT: - return "INSERT"; + return "INS"; case GLFW_KEY_DELETE: - return "DELETE"; + return "DEL"; case GLFW_KEY_RIGHT: return "RIGHT"; case GLFW_KEY_LEFT: @@ -841,21 +843,21 @@ namespace cage case GLFW_KEY_UP: return "UP"; case GLFW_KEY_PAGE_UP: - return "PAGE_UP"; + return "PGUP"; case GLFW_KEY_PAGE_DOWN: - return "PAGE_DOWN"; + return "PGDN"; case GLFW_KEY_HOME: return "HOME"; case GLFW_KEY_END: return "END"; case GLFW_KEY_CAPS_LOCK: - return "CAPS_LOCK"; + return "CAPS"; case GLFW_KEY_SCROLL_LOCK: - return "SCROLL_LOCK"; + return "SCROLL"; case GLFW_KEY_NUM_LOCK: - return "NUM_LOCK"; + return "NUM"; case GLFW_KEY_PRINT_SCREEN: - return "PRINT_SCREEN"; + return "PRTSC"; case GLFW_KEY_PAUSE: return "PAUSE"; case GLFW_KEY_F1: @@ -882,8 +884,34 @@ namespace cage return "F11"; case GLFW_KEY_F12: return "F12"; + case GLFW_KEY_F13: + return "F13"; + case GLFW_KEY_F14: + return "F14"; + case GLFW_KEY_F15: + return "F15"; + case GLFW_KEY_F16: + return "F16"; + case GLFW_KEY_F17: + return "F17"; + case GLFW_KEY_F18: + return "F18"; + case GLFW_KEY_F19: + return "F19"; + case GLFW_KEY_F20: + return "F20"; + case GLFW_KEY_F21: + return "F21"; + case GLFW_KEY_F22: + return "F22"; + case GLFW_KEY_F23: + return "F23"; + case GLFW_KEY_F24: + return "F24"; + case GLFW_KEY_F25: + return "F25"; case GLFW_KEY_KP_ENTER: - return "ENTER2"; + return "ENT"; } const auto s = glfwGetKeyName(key, 0); return s ? toUpper(detail::StringBase<27>(s)) : "???"; diff --git a/sources/test-core/events.cpp b/sources/test-core/events.cpp index 60d22893..69487bdc 100644 --- a/sources/test-core/events.cpp +++ b/sources/test-core/events.cpp @@ -53,7 +53,7 @@ void testEvents() CAGE_TEST(n == 1); l1.detach(); l1.attach(d); - l1.clear(); + l1.unbind(); } {