diff --git a/src/app/editor/editor.cmake b/src/app/editor/editor.cmake index c54feacc..1ee09936 100644 --- a/src/app/editor/editor.cmake +++ b/src/app/editor/editor.cmake @@ -16,5 +16,6 @@ set( app/editor/utils/gfx_context.cc app/editor/overworld/entity.cc app/editor/system/settings_editor.cc + app/editor/system/command_manager.cc app/editor/system/extension_manager.cc -) \ No newline at end of file +) diff --git a/src/app/editor/editor_manager.cc b/src/app/editor/editor_manager.cc index d1eba76b..f051b563 100644 --- a/src/app/editor/editor_manager.cc +++ b/src/app/editor/editor_manager.cc @@ -242,6 +242,8 @@ void EditorManager::ManageActiveEditors() { void EditorManager::ManageKeyboardShortcuts() { bool ctrl_or_super = (GetIO().KeyCtrl || GetIO().KeySuper); + command_manager_.ShowWhichKey(); + // If CMD + R is pressed, reload the top result of recent files if (IsKeyDown(ImGuiKey_R) && ctrl_or_super) { static RecentFilesManager manager("recent_files.txt"); diff --git a/src/app/editor/editor_manager.h b/src/app/editor/editor_manager.h index 5e5d7cb6..241e7a76 100644 --- a/src/app/editor/editor_manager.h +++ b/src/app/editor/editor_manager.h @@ -17,6 +17,7 @@ #include "app/editor/overworld/overworld_editor.h" #include "app/editor/sprite/sprite_editor.h" #include "app/editor/system/constant_manager.h" +#include "app/editor/system/command_manager.h" #include "app/editor/system/extension_manager.h" #include "app/editor/system/settings_editor.h" #include "app/emu/emulator.h" @@ -99,6 +100,7 @@ class EditorManager : public SharedRom, public core::ExperimentFlags { emu::Emulator emulator_; Project current_project_; + CommandManager command_manager_; ConstantManager constant_manager_; ExtensionManager extension_manager_; yaze_editor_context editor_context_; diff --git a/src/app/editor/system/command_manager.cc b/src/app/editor/system/command_manager.cc new file mode 100644 index 00000000..d7024dfa --- /dev/null +++ b/src/app/editor/system/command_manager.cc @@ -0,0 +1,27 @@ +#include "command_manager.h" + +#include "imgui/imgui.h" + +namespace yaze { +namespace app { +namespace editor { + +// 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. +void CommandManager::ShowWhichKey() { + if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Space))) { + ImGui::OpenPopup("WhichKey"); + } + + if (ImGui::BeginPopup("WhichKey")) { + for (const auto& [shortcut, command] : commands_) { + ImGui::Text("%s: %s", shortcut.c_str(), + command->GetDescription().c_str()); + } + ImGui::EndPopup(); + } +} + +} // namespace editor +} // namespace app +} // namespace yaze diff --git a/src/app/editor/system/command_manager.h b/src/app/editor/system/command_manager.h index c1dcb046..931fb233 100644 --- a/src/app/editor/system/command_manager.h +++ b/src/app/editor/system/command_manager.h @@ -1,6 +1,7 @@ #ifndef YAZE_APP_EDITOR_SYSTEM_COMMAND_MANAGER_H #define YAZE_APP_EDITOR_SYSTEM_COMMAND_MANAGER_H +#include #include #include @@ -16,6 +17,8 @@ class Command { class CommandManager { public: + void ShowWhichKey(); + void RegisterCommand(const std::string& shortcut, Command* command) { commands_[shortcut] = command; } @@ -50,4 +53,6 @@ class CommandManager { } // namespace editor } // namespace app -} // namespace yaze \ No newline at end of file +} // namespace yaze + +#endif // YAZE_APP_EDITOR_SYSTEM_COMMAND_MANAGER_H \ No newline at end of file