Refactor key mapping logic and streamline shortcut execution in CommandManager and ShortcutManager
This commit is contained in:
@@ -2,73 +2,12 @@
|
|||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
#include "app/gui/input.h"
|
||||||
#include "imgui/imgui.h"
|
#include "imgui/imgui.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace editor {
|
namespace editor {
|
||||||
|
|
||||||
ImGuiKey MapKeyToImGuiKey(char key) {
|
|
||||||
switch (key) {
|
|
||||||
case 'A':
|
|
||||||
return ImGuiKey_A;
|
|
||||||
case 'B':
|
|
||||||
return ImGuiKey_B;
|
|
||||||
case 'C':
|
|
||||||
return ImGuiKey_C;
|
|
||||||
case 'D':
|
|
||||||
return ImGuiKey_D;
|
|
||||||
case 'E':
|
|
||||||
return ImGuiKey_E;
|
|
||||||
case 'F':
|
|
||||||
return ImGuiKey_F;
|
|
||||||
case 'G':
|
|
||||||
return ImGuiKey_G;
|
|
||||||
case 'H':
|
|
||||||
return ImGuiKey_H;
|
|
||||||
case 'I':
|
|
||||||
return ImGuiKey_I;
|
|
||||||
case 'J':
|
|
||||||
return ImGuiKey_J;
|
|
||||||
case 'K':
|
|
||||||
return ImGuiKey_K;
|
|
||||||
case 'L':
|
|
||||||
return ImGuiKey_L;
|
|
||||||
case 'M':
|
|
||||||
return ImGuiKey_M;
|
|
||||||
case 'N':
|
|
||||||
return ImGuiKey_N;
|
|
||||||
case 'O':
|
|
||||||
return ImGuiKey_O;
|
|
||||||
case 'P':
|
|
||||||
return ImGuiKey_P;
|
|
||||||
case 'Q':
|
|
||||||
return ImGuiKey_Q;
|
|
||||||
case 'R':
|
|
||||||
return ImGuiKey_R;
|
|
||||||
case 'S':
|
|
||||||
return ImGuiKey_S;
|
|
||||||
case 'T':
|
|
||||||
return ImGuiKey_T;
|
|
||||||
case 'U':
|
|
||||||
return ImGuiKey_U;
|
|
||||||
case 'V':
|
|
||||||
return ImGuiKey_V;
|
|
||||||
case 'W':
|
|
||||||
return ImGuiKey_W;
|
|
||||||
case 'X':
|
|
||||||
return ImGuiKey_X;
|
|
||||||
case 'Y':
|
|
||||||
return ImGuiKey_Y;
|
|
||||||
case 'Z':
|
|
||||||
return ImGuiKey_Z;
|
|
||||||
case '/':
|
|
||||||
return ImGuiKey_Slash;
|
|
||||||
case '-':
|
|
||||||
return ImGuiKey_Minus;
|
|
||||||
default:
|
|
||||||
return ImGuiKey_COUNT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// When the player presses Space, a popup will appear fixed to the bottom of the
|
// When the player presses Space, a popup will appear fixed to the bottom of the
|
||||||
// ImGui window with a list of the available key commands which can be used.
|
// ImGui window with a list of the available key commands which can be used.
|
||||||
|
|||||||
@@ -10,8 +10,6 @@
|
|||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace editor {
|
namespace editor {
|
||||||
|
|
||||||
ImGuiKey MapKeyToImGuiKey(char key);
|
|
||||||
|
|
||||||
class CommandManager {
|
class CommandManager {
|
||||||
public:
|
public:
|
||||||
CommandManager() = default;
|
CommandManager() = default;
|
||||||
|
|||||||
@@ -140,29 +140,27 @@ std::vector<ImGuiKey> ParseShortcut(const std::string& shortcut) {
|
|||||||
void ExecuteShortcuts(const ShortcutManager& shortcut_manager) {
|
void ExecuteShortcuts(const ShortcutManager& shortcut_manager) {
|
||||||
// Check for keyboard shortcuts using the shortcut manager
|
// Check for keyboard shortcuts using the shortcut manager
|
||||||
for (const auto& shortcut : shortcut_manager.GetShortcuts()) {
|
for (const auto& shortcut : shortcut_manager.GetShortcuts()) {
|
||||||
bool ctrl_pressed = ImGui::GetIO().KeyCtrl;
|
bool keys_pressed = true;
|
||||||
bool alt_pressed = ImGui::GetIO().KeyAlt;
|
|
||||||
bool shift_pressed = ImGui::GetIO().KeyShift;
|
|
||||||
bool super_pressed = ImGui::GetIO().KeySuper;
|
|
||||||
bool keys_pressed = false;
|
|
||||||
// Check for all the keys in the shortcut
|
// Check for all the keys in the shortcut
|
||||||
for (const auto& key : shortcut.second.keys) {
|
for (const auto& key : shortcut.second.keys) {
|
||||||
if (key == ImGuiMod_Ctrl) {
|
if (key == ImGuiMod_Ctrl) {
|
||||||
keys_pressed = ctrl_pressed;
|
keys_pressed &= ImGui::GetIO().KeyCtrl;
|
||||||
} else if (key == ImGuiMod_Alt) {
|
} else if (key == ImGuiMod_Alt) {
|
||||||
keys_pressed = alt_pressed;
|
keys_pressed &= ImGui::GetIO().KeyAlt;
|
||||||
} else if (key == ImGuiMod_Shift) {
|
} else if (key == ImGuiMod_Shift) {
|
||||||
keys_pressed = shift_pressed;
|
keys_pressed &= ImGui::GetIO().KeyShift;
|
||||||
} else if (key == ImGuiMod_Super) {
|
} else if (key == ImGuiMod_Super) {
|
||||||
keys_pressed = super_pressed;
|
keys_pressed &= ImGui::GetIO().KeySuper;
|
||||||
} else {
|
} else {
|
||||||
keys_pressed = ImGui::IsKeyDown(key);
|
keys_pressed &= ImGui::IsKeyDown(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!keys_pressed) {
|
if (!keys_pressed) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (keys_pressed) {
|
||||||
|
shortcut.second.callback();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user