DayZ 1.24
Loading...
Searching...
No Matches
PluginKeyBinding.c
Go to the documentation of this file.
1
7const int MB_EVENT_PRESS = 0;
8const int MB_EVENT_CLICK = 1;
9const int MB_EVENT_RELEASE = 2;
11const int MB_EVENT_DRAG = 4;
14class PluginKeyBinding extends PluginBase
15{
16 static PluginKeyBinding instance;
17
18 // System Public Events
20 {
21 if (instance == null)
22 instance = this;
23 }
24
25 //============================================
26 // OnInit
27 //============================================
28 override void OnInit()
29 {
30 super.OnInit();
31
32 m_KeyBindings = new array<ref KeyBinding>;
33 m_MouseBindings = new array<ref MouseBinding>;
34 m_MouseButtons = new array<ref MouseButtonInfo>;
35 m_MouseButtons.Insert(new MouseButtonInfo(MouseState.LEFT));
36 m_MouseButtons.Insert(new MouseButtonInfo(MouseState.RIGHT));
37 m_MouseButtons.Insert(new MouseButtonInfo(MouseState.MIDDLE));
38 GetGame().GetUpdateQueue(CALL_CATEGORY_SYSTEM).Insert(this.OnFrame);
39
41 //Keyboard Binds |UI_ID |Key1 |Key2 |Callback Plugin |Callback Function |Info Shrtcut |Info Description
42 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
43 // |constants.h |constants.h |constants.h |only plugin name |only function | |
44 // |MENU_*** |KeyCode.KC_*** |KeyCode.KC_*** | |in plugin | |
45 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
46#ifdef DEVELOPER
47 RegisterKeyBind(MENU_ANY, KeyCode.KC_LCONTROL, KeyCode.KC_F1, "PluginDeveloper", "ToggleHelpScreen", "[LCTRL]+[F1]", "Show/Hide help screen");
48 RegisterKeyBind(MENU_ANY, KeyCode.KC_LCONTROL, KeyCode.KC_F2, "PluginDeveloper", "ResetGUI", "[LCTRL]+[F2]", "Resets shown UI for testing purposes");
49 RegisterKeyBind(MENU_NONE | MENU_SCRIPTCONSOLE, KeyCode.KC_LCONTROL, KeyCode.KC_GRAVE, "PluginDeveloper", "ToggleScriptConsole", "[LCTRL]+[~]", "Show/Hide this script console");
50 RegisterKeyBind(MENU_NONE | MENU_SCRIPTCONSOLE, KeyCode.KC_RCONTROL, KeyCode.KC_GRAVE, "PluginDeveloper", "ToggleScriptConsole", "[RCTRL]+[~]", "Show/Hide this script console");
51 RegisterKeyBind(MENU_NONE | MENU_SCENE_EDITOR, KeyCode.KC_LCONTROL, KeyCode.KC_TAB, "PluginSceneManager", "EditorToggle", "[LCTRL]+[TAB]", "Show/Hide Scripted Scene Editor");
52 RegisterKeyBind(MENU_NONE | MENU_SCENE_EDITOR, KeyCode.KC_RCONTROL, KeyCode.KC_TAB, "PluginSceneManager", "EditorToggle", "[RCTRL]+[TAB]", "Show/Hide Scripted Scene Editor");
53 RegisterKeyBind(MENU_NONE, KeyCode.KC_LCONTROL, KeyCode.KC_V, "PluginDeveloper", "SpawnFromClipboard", "[Right Shift]", "Spawn item from clipboard");
54#endif
55
56#ifdef DIAG_DEVELOPER
57 RegisterKeyBind(MENU_NONE, KeyCode.KC_INSERT, -1, "PluginDeveloper", "TeleportAtCursor", "[Insert]", "Teleport player to cursor position");
58 RegisterKeyBind(MENU_NONE, KeyCode.KC_HOME, -1, "PluginDeveloper", "ToggleFreeCamera", "[Home]", "Toggle free camera and teleport player to its position");
59 RegisterKeyBind(MENU_NONE, KeyCode.KC_DIVIDE, -1, "PluginDeveloper", "ToggleFreeCameraBackPos", "[Divide numeric]", "Toggle free camera, no player teleport");
60 RegisterKeyBind(MENU_NONE, KeyCode.KC_LCONTROL, KeyCode.KC_NUMPAD9, "PluginDeveloperSync", "ToggleFocus", "[LCtrl]+[NUMPAD9]", "Toggle game focus");
61#endif
62
63#ifdef DEVELOPER
64 RegisterKeyBind(MENU_NONE, KeyCode.KC_LCONTROL, KeyCode.KC_Z, "PluginDeveloper", "SetDeveloperItemClient", "Starts watching the item", "Sets the target as Watched item for debug purposes");
65 RegisterKeyBind(MENU_SCRIPTCONSOLE, KeyCode.KC_PRIOR, -1, "PluginDeveloper", "ScriptHistoryBack", "[Page Up]", "Debug Console => Script history back");
66 RegisterKeyBind(MENU_SCRIPTCONSOLE, KeyCode.KC_NEXT, -1, "PluginDeveloper", "ScriptHistoryNext", "[Page Down]", "Debug Console => Script history next");
67 RegisterKeyBind(MENU_SCENE_EDITOR, KeyCode.KC_DELETE, -1, "PluginSceneManager", "DeleteSelectedObject", "[Delete]", "Scene Editor => Delete current selected object");
68 RegisterKeyBind(MENU_SCENE_EDITOR, KeyCode.KC_LCONTROL, KeyCode.KC_S, "PluginSceneManager", "SceneSave", "[LCtrl]+[S]", "Scene Editor => Save Current Scene");
69 RegisterKeyBind(MENU_SCENE_EDITOR, KeyCode.KC_LCONTROL, KeyCode.KC_D, "PluginSceneManager", "SelectedObjectDuplicate", "[LCtrl]+[D]", "Scene Editor => Duplicate current selected object");
70 RegisterKeyBind(MENU_SCENE_EDITOR, KeyCode.KC_LCONTROL, KeyCode.KC_F, "PluginSceneManager", "SelectedObjectFocus", "[LCtrl]+[F]", "Scene Editor => Focus camera on selected object");
71 RegisterKeyBind(MENU_SCENE_EDITOR, KeyCode.KC_LCONTROL, KeyCode.KC_E, "PluginSceneManager", "RulerToggle", "[LCtrl]+[E]", "Scene Editor => Enable/Disable addition of ruler points");
72 RegisterKeyBind(MENU_NONE, KeyCode.KC_LCONTROL, KeyCode.KC_PRIOR, "PluginRecipesManager", "CallbackGenerateCache", "[LCtrl]+[BACKSPACE]", "PluginRecipesManager => Generate recipe cache and save it to file");
73 RegisterKeyBind(MENU_ANY, KeyCode.KC_LCONTROL, KeyCode.KC_DECIMAL, "PluginItemDiagnostic", "ToggleDebugWindowEvent", "[LCtrl]+[DECIMAL]", "Close the Item Debug window");
74 RegisterKeyBind(MENU_ANY, KeyCode.KC_LCONTROL, KeyCode.KC_NUMPAD0, "PluginDayzPlayerDebug", "ToggleDebugWindowEvent", "[LCtrl]+[NUMPAD0]", "Open/Close Player debug window");
75 RegisterKeyBind(MENU_ANY, KeyCode.KC_LCONTROL, KeyCode.KC_DECIMAL, "PluginDayzPlayerDebug", "ToggleDebugWindowEventP", "[LCtrl]+[DECIMAL]", "Open/Close Player debug window");
76 RegisterKeyBind(MENU_ANY, KeyCode.KC_LCONTROL, KeyCode.KC_I, "PluginDayZInfectedDebug", "ToggleDebugWindowEvent", "[LCtrl]+[NUMPAD1]", "Open/Close Infected debug window");
77 RegisterKeyBind(MENU_ANY, KeyCode.KC_LCONTROL, KeyCode.KC_O, "PluginDayZInfectedDebug", "PossesInfected", "[LCtrl]+[NUMPAD1]", "Open/Close Infected debug window");
78 RegisterKeyBind(MENU_NONE, KeyCode.KC_LCONTROL, KeyCode.KC_SCROLL, "PluginNutritionDumper", "CheckInit", "[LCtrl]+[SCROLL LOCK]", "Enable Door Ruler");
79 RegisterKeyBind(MENU_NONE, KeyCode.KC_LCONTROL, KeyCode.KC_RBRACKET, "PluginCharPlacement", "CheckInit", "[LCtrl]+[)]", "Enable CharPlacer");
80
81 RegisterKeyBind(MENU_NONE | MENU_CAMERA_TOOLS, KeyCode.KC_LCONTROL, KeyCode.KC_K, "PluginCameraTools", "ToggleCameraTools", "[LCtrl]+[K]", "Toggle Camera Recording Tools");
82 RegisterKeyBind(MENU_CAMERA_TOOLS, KeyCode.KC_LCONTROL, KeyCode.KC_S, "PluginCameraTools", "Save", "[X]", "Recording Tools => Start Recording Camera Path");
83 RegisterKeyBind(MENU_CAMERA_TOOLS, KeyCode.KC_P, -1, "PluginCameraTools", "PlayPause", "[C]", "Recording Tools => Stop Recording Camera Path");
84 RegisterKeyBind(MENU_CAMERA_TOOLS, KeyCode.KC_LCONTROL, KeyCode.KC_Q, "PluginCameraTools", "AddKeyframe", "[C]", "Recording Tools => Add Camera Point");
85 RegisterKeyBind(MENU_CAMERA_TOOLS, KeyCode.KC_LCONTROL, KeyCode.KC_E, "PluginCameraTools", "DeleteKeyframe", "[V]", "Recording Tools => Play Camera Line");
86
87 //--------------------------------------------------------------------------------------------------------------------------------------------------------------
90 // Mouses Binds |UI_ID |Mouse Button |Mouse Event |Callback Plugin |Callback Function |Info Shrtcut |Info Description
91 //----------------------------------------------------------------------------------------------------------------------------------------------------------------
92 // |constants.h |MouseState.LEFT |MB_EVENT_CLICK |only plugin name |only function | |
93 // |MENU_*** |MouseState.RIGHT |MB_EVENT_DOUBLECLICK | |in plugin | |
94 // |MouseState.MIDDLE |MB_EVENT_DRAG | | | |
95 // | |MB_EVENT_RELEASE | | | |
96 //--------------------------------------------------------------------------------------------------------------------------------------------------------------
97 RegisterMouseBind(MENU_SCENE_EDITOR, MouseState.LEFT, MB_EVENT_CLICK, "PluginSceneManager", "Event_OnClick", "[LMB] Click", "Mission Editor => Select object in scene");
98 RegisterMouseBind(MENU_SCENE_EDITOR, MouseState.LEFT, MB_EVENT_DOUBLECLICK, "PluginSceneManager", "Event_OnDoubleClick", "[LMB] Double Click", "Mission Editor => Craete new object in scene");
99 RegisterMouseBind(MENU_SCENE_EDITOR, MouseState.LEFT, MB_EVENT_DRAG, "PluginSceneManager", "Event_OnDrag", "[LMB] Hold", "Mission Editor => Moving with selected object");
100 RegisterMouseBind(MENU_SCENE_EDITOR, MouseState.MIDDLE, MB_EVENT_CLICK, "PluginSceneManager", "Event_OnClickMiddle", "[MMB] Click", "Mission Editor => Link clicked object with selected object");
101 RegisterMouseBind(MENU_SCENE_EDITOR, MouseState.RIGHT, MB_EVENT_PRESS, "PluginSceneManager", "FreeCameraControlEnable", "[RMB] Hold", "Mission Editor => Enable camera movement");
102 RegisterMouseBind(MENU_SCENE_EDITOR, MouseState.RIGHT, MB_EVENT_RELEASE, "PluginSceneManager", "FreeCameraControlDisable", "[RMB] Release", "Mission Editor => Disable camera movement");
103 RegisterMouseBind(MENU_NONE, MouseState.LEFT, MB_EVENT_CLICK, "PluginDayZCreatureAIDebug", "Event_OnClick", "[LMB] Click", "DayZCreature graph debug => Capture entity during capture mode");
104 RegisterMouseBind(MENU_CAMERA_TOOLS, MouseState.RIGHT, MB_EVENT_RELEASE, "PluginCameraTools", "CursorShow", "[LMB] Click", "DayZCreature graph debug => Capture entity during capture mode");
105 // TO DO: (Boris V.) Remove the following commented-out mouse binds when weapon particles can be implemented properly. Also remove the events they call.
106 //RegisterMouseBind( MENU_NONE ,MouseState.LEFT ,MB_EVENT_PRESS ,"PluginDeveloper" ,"MuzzleParticleTestStart" ,"[LMB] Hold" ,"Debug particle");
107 //RegisterMouseBind( MENU_NONE ,MouseState.LEFT ,MB_EVENT_RELEASE ,"PluginDeveloper" ,"MuzzleParticleTestEnd" ,"[LMB] Release" ,"Debug particle2");
108#endif
109 //--------------------------------------------------------------------------------------------------------------------------------------------------------------
111 }
112
113 //==========================================
114 // OnInit (System Event)
115 //==========================================
116 override void OnDestroy()
117 {
118 GetGame().GetUpdateQueue(CALL_CATEGORY_SYSTEM).Remove(this.OnFrame);
119 }
120
121 //============================================
122 // OnKeyPress
123 //============================================
124 void OnKeyPress(int key)
125 {
126 //Print("OnKeyPress "+ key );
127
128 for (int i = 0; i < m_KeyBindings.Count(); ++i)
129 {
130 KeyBinding key_binding = m_KeyBindings.Get(i);
131
132 if (!IsCurrentUIPageValid(key_binding.GetUIMenuID()))
133 continue;
134
135 bool key1_match = false;
136 bool key2_match = false;
137
138 if (key_binding.GetKey1() > -1)
139 {
140 if (IsKeyPressed(key_binding.GetKey1()))
141 {
142 // Key1 is down
143 key1_match = true;
144 }
145 }
146 else
147 {
148 // Key1 is not set
149 key1_match = true;
150 }
151
152 if (key_binding.GetKey2() > -1)
153 {
154 if (IsKeyPressed(key_binding.GetKey2()))
155 {
156 // Key2 is down
157 key2_match = true;
158 }
159 }
160 else
161 {
162 // Key2 is not set
163 key2_match = true;
164 }
165
166 if (key1_match && key2_match)
167 {
168 //Log( "Call Method -> key press: " + itoa(key) + " " + key_binding.GetInfoDescription() );
169
170 PluginBase m = GetPlugin(key_binding.GetCallbackTarget().ToType());
171 GetGame().GameScript.CallFunction(m, key_binding.GetCallbackFunction(), NULL, 0);
172
173 break;
174 }
175 }
176 }
177
178 //============================================
179 // OnKeyRelease
180 //============================================
182 {
183 }
184
185 //============================================
186 // OnMouseButtonPress
187 //============================================
189 {
190 MouseButtonInfo button_info = GetMouseButtonInfo(button);
191 if (button_info == NULL) return;
192 button_info.Press();
193
194 //Log("****************************");
195 //Log(" MB_EVENT_PRESS");
196
197 OnMouse(MB_EVENT_PRESS, button);
198 }
199
200 //============================================
201 // OnMouseButtonRelease
202 //============================================
204 {
205 MouseButtonInfo button_info = GetMouseButtonInfo(button);
206 if (button_info == NULL) return;
207 int time_curr = GetGame().GetTime();
208 int time_last_press = button_info.GetTimeLastPress();
209 int time_last_release = button_info.GetTimeLastRelease();
212
213 if (time_delta_relase < DOUBLE_CLICK_TIME)
214 {
215 //Log(" DOUBLE_CLICK_TIME ");
216
218 }
219 else if (time_delta_press < CLICK_TIME)
220 {
221 //Log(" MB_EVENT_CLICK ");
222
223 OnMouse(MB_EVENT_CLICK, button);
224 }
225
226 //Log(" MB_EVENT_RELEASE");
227
228 OnMouse(MB_EVENT_RELEASE, button);
229
230 button_info.Release();
231 }
232
233 //============================================
234 // OnFrame
235 //============================================
236 void OnFrame()
237 {
238 for (int i = 0; i < m_MouseButtons.Count(); ++i)
239 {
240 MouseButtonInfo info = m_MouseButtons.Get(i);
241
242 if (info.IsButtonDown())
243 {
244 int time_curr = GetGame().GetTime();
245 int time_hold = info.GetTimeLastPress() + HOLD_CLICK_TIME_MIN;
246
247 if (time_hold < time_curr)
248 {
249 //Log("MB_EVENT_DRAG");
250
251 OnMouse(MB_EVENT_DRAG, info.GetButtonID());
252 }
253 }
254 }
255 }
256
257 //--------------------------------------------
258 // GetKeyBindings
259 //--------------------------------------------
261 {
262 return m_KeyBindings;
263 }
264
265 //--------------------------------------------
266 // GetMouseBindings
267 //--------------------------------------------
269 {
270 return m_MouseBindings;
271 }
272
273 protected const int CLICK_TIME = 200; //ms
274 protected const int DOUBLE_CLICK_TIME = 300; //ms
275 protected const int HOLD_CLICK_TIME_MIN = 300; //ms
276
280
281 //--------------------------------------------
282 // RegisterKeyBind
283 //--------------------------------------------
284 protected void RegisterKeyBind(int ui_id, int key_code1, int key_code2, string plugin_name, string fnc_name, string info_shortcut, string info_description)
285 {
287 }
288
289 //--------------------------------------------
290 // RegisterMouseBind
291 //--------------------------------------------
292 protected void RegisterMouseBind(int ui_id, int mouse_button, int mouse_event, string plugin_name, string fnc_name, string info_shortcut, string info_description)
293 {
295 }
296
297 //--------------------------------------------
298 // IsCurrentUIPageValid
299 //--------------------------------------------
301 {
303
304 if (GetGame().GetUIManager().GetMenu())
305 ui_page_current = GetGame().GetUIManager().GetMenu().GetID();
306
308 {
309 if (CheckMask(ui_page_request, MENU_NONE) || !CheckMask(ui_page_request, MENU_ANY))
310 return false;
311 }
312
313 return true;
314 }
315
317 {
319 return true;
320
321 return false;
322 }
323
324 //--------------------------------------------
325 // OnMouse
326 //--------------------------------------------
327 protected void OnMouse(int event_id, int button)
328 {
329 for (int i = 0; i < m_MouseBindings.Count(); ++i)
330 {
331 MouseBinding mouse_binding = m_MouseBindings.Get(i);
332
333 if (mouse_binding.GetButtonID() == button && mouse_binding.GetMouseEvent() == event_id)
334 {
335 if (IsCurrentUIPageValid(mouse_binding.GetUIMenuID()))
336 {
337 PluginBase m = GetPlugin(mouse_binding.GetCallbackTarget().ToType());
338 GetGame().GameScript.CallFunction(m, mouse_binding.GetCallbackFunction(), NULL, 0);
339 }
340 }
341 }
342 }
343
344 //--------------------------------------------
345 // OnMouse
346 //--------------------------------------------
348 {
349 for (int i = 0; i < m_MouseButtons.Count(); ++i)
350 {
351 MouseButtonInfo info = m_MouseButtons.Get(i);
352
353 if (info.GetButtonID() == button)
354 return info;
355 }
356 return NULL;
357 }
358
359 //--------------------------------------------
360 // IsKeyPressed
361 //--------------------------------------------
362 protected bool IsKeyPressed(int key)
363 {
364 return (KeyState(key) == 1);
365 }
366}
PluginBase GetPlugin(typename plugin_type)
bool CheckMask(int source_mask, int target_mask)
ref array< ref MouseButtonInfo > m_MouseButtons
override void OnInit()
ref array< ref KeyBinding > m_KeyBindings
void OnMouse(int event_id, int button)
void OnKeyPress(int key)
void PluginKeyBinding()
void OnMouseButtonPress(int button)
MouseButtonInfo GetMouseButtonInfo(int button)
void RegisterKeyBind(int ui_id, int key_code1, int key_code2, string plugin_name, string fnc_name, string info_shortcut, string info_description)
override void OnDestroy()
void OnMouseButtonRelease(int button)
bool IsCurrentUIPageValid(int ui_page_request)
ref array< ref MouseBinding > m_MouseBindings
array< ref KeyBinding > GetKeyBindings()
void RegisterMouseBind(int ui_id, int mouse_button, int mouse_event, string plugin_name, string fnc_name, string info_shortcut, string info_description)
static PluginKeyBinding instance
void OnKeyRelease(int key)
array< ref MouseBinding > GetMouseBindings()
bool IsKeyPressed(int key)
proto native CGame GetGame()
KeyCode
Definition EnSystem.c:157
proto native int KeyState(KeyCode key)
const int MENU_NONE
Definition constants.c:161
const int MENU_SCRIPTCONSOLE
Definition constants.c:175
const int MENU_CAMERA_TOOLS
Definition constants.c:191
const int MENU_SCENE_EDITOR
Definition constants.c:167
const int MENU_ANY
Definition constants.c:160
const int MB_EVENT_DRAG
const int MB_EVENT_RELEASE
const int MB_EVENT_CLICK
const int MB_EVENT_DOUBLECLICK
const int MB_EVENT_PRESS
MouseState
Definition EnSystem.c:311
const int CALL_CATEGORY_SYSTEM
Definition tools.c:8