Polyphase Game Engine
Loading...
Searching...
No Matches
EditorHotkeyMap.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4
5#include "EditorAction.h"
6
7#include "document.h"
8
9#include <stdint.h>
10#include <string>
11#include <vector>
12
13// Central registry for editor hotkey bindings.
14//
15// Use IsActionJustTriggered for one-shot actions (menus, toggles, gizmo
16// switches) and IsActionDown for continuous actions (camera movement). Both
17// queries gate themselves on AreEditorHotkeysActive() so they automatically
18// stop firing when Play-In-Editor has captured the cursor in the game window.
19class EditorHotkeyMap
20{
21public:
22
23 static void Create();
24 static void Destroy();
25 static EditorHotkeyMap* Get();
26
27 // ----- Query API used by editor call sites -----
28
29 // True for one frame when the binding's key+modifier combo just edged
30 // down. Returns false during captured PIE so game code owns those keys.
31 bool IsActionJustTriggered(EditorAction action) const;
32
33 // Same as IsActionJustTriggered but uses ImGui's input pipeline
34 // (ImGui::IsKeyPressed + io.KeyCtrl/Shift/Alt) instead of the engine's
35 // INP_* layer. Use this from inside ImGui-window draw code where the
36 // engine input layer can race with ImGui's keyboard handling — for
37 // example panel-scoped Ctrl+C / Ctrl+V hotkeys that should fire when the
38 // window is hovered. Same PIE gate as IsActionJustTriggered.
39 bool IsActionJustTriggeredImGui(EditorAction action) const;
40
41 // True every frame the binding's key+modifier combo is held. Use for
42 // camera movement / continuous tools. Same PIE gate as above.
43 bool IsActionDown(EditorAction action) const;
44
45 // True for one frame when the binding's key just released.
46 bool IsActionJustReleased(EditorAction action) const;
47
48 // ----- Binding management -----
49
50 KeyBinding GetBinding(EditorAction action) const;
51 void SetBinding(EditorAction action, const KeyBinding& binding);
52 void ClearBinding(EditorAction action);
53 void ResetActionToDefault(EditorAction action);
54 void ResetAllToDefaults();
55
56 // Return every action whose binding exactly matches the supplied combo,
57 // optionally excluding one (used to exclude the action being remapped).
58 std::vector<EditorAction> FindConflicts(const KeyBinding& binding,
59 EditorAction excluding = EditorAction::Count) const;
60
61 // Explicit consume helper. Some sites (Ctrl+S, Ctrl+P) need to clear the
62 // key after handling so a follow-up popup or text field doesn't see it as
63 // still-held. Mirrors the existing INP_ClearKey calls in InputManager.cpp.
64 void ConsumeBindingKey(EditorAction action) const;
65
66 // Display string ("Ctrl+Shift+S", "Space+G", or "—" if unbound).
67 static std::string BindingToDisplayString(const KeyBinding& binding);
68
69 // True iff editor hotkeys should be processed this frame. Editor code can
70 // call this directly when it needs to gate something other than a binding
71 // (e.g. mouse-button hotkeys).
72 static bool AreEditorHotkeysActive();
73
74 // ----- Preset management -----
75 //
76 // Presets live as JSON files in
77 // Windows: %APPDATA%/PolyphaseEditor/HotkeyPresets/
78 // Linux: ~/.config/PolyphaseEditor/HotkeyPresets/
79 //
80 // Users share presets by exporting to a chosen file and importing
81 // someone else's file.
82
83 bool SavePreset(const std::string& name);
84 bool LoadPreset(const std::string& name);
85 bool DeletePreset(const std::string& name);
86 std::vector<std::string> GetPresetNames() const;
87 static std::string GetPresetsDirectory();
88
89 bool ExportToFile(const std::string& absPath);
90 bool ImportFromFile(const std::string& absPath);
91
92 // Writes a "Default.json" preset to the presets folder if one doesn't
93 // already exist. Called from Create() during editor startup, before any
94 // user customizations are loaded by the PreferencesManager, so the saved
95 // file always reflects the canonical defaults from the metadata table.
96 // Users can then load "Default" from the dropdown like any other preset,
97 // and the file is regenerated next launch if they delete it.
98 void EnsureDefaultPresetExists();
99 static const char* GetDefaultPresetName() { return "Default"; }
100
101 // ----- Preferences-module serialization -----
102
103 void SerializeToJson(rapidjson::Document& doc) const;
104 void DeserializeFromJson(const rapidjson::Document& doc);
105
106private:
107
108 static EditorHotkeyMap* sInstance;
109
110 EditorHotkeyMap();
111
112 bool MatchesBinding(const KeyBinding& binding) const;
113 void WriteBindingToJson(const KeyBinding& binding,
114 rapidjson::Value& outObj,
115 rapidjson::Document::AllocatorType& alloc) const;
116 bool ReadBindingFromJson(const rapidjson::Value& obj, KeyBinding& outBinding) const;
117
118 KeyBinding mBindings[(int32_t)EditorAction::Count];
119};
120
121#endif
Definition JsonHelpers.h:15
Definition JsonHelpers.h:14
void ExportToFile(NodeGraph &graph, const std::vector< GraphNodeId > &selectedNodeIds, const std::string &filePath)
Definition GraphClipboard.cpp:328
void ImportFromFile(NodeGraph &targetGraph, const std::string &filePath, const glm::vec2 &pastePosition, NodeGraphAsset *ownerAsset)
Definition GraphClipboard.cpp:338