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