Dayz Explorer 1.29.162510
Loading...
Searching...
No Matches
input.c
Go to the documentation of this file.
1
8
9//-----------------------------------------------------------------------------
10class Input
11{
12 // input locking
13
20 proto native void ChangeGameFocus(int add, int input_device = -1);
21
27 proto native void ResetGameFocus(int input_device = -1);
28
34 proto native bool HasGameFocus(int input_device = -1);
35
36 // actions
37 proto native int GetActionGroupsCount();
38 proto native int GetActionGroupSize(int group_index);
39 proto int GetActionGroupName(int group_index, out string name);
40 proto int GetActionDesc(int action_index, out string desc);
41
42 // getting action state
50 proto native float LocalValue_ID(int action, bool check_focus = true);
51 proto native float LocalValue(string action, bool check_focus = true);
52
61 proto native bool LocalPress_ID(int action, bool check_focus = true);
62 proto native bool LocalPress(string action, bool check_focus = true);
63
71 proto native bool LocalRelease_ID(int action, bool check_focus = true);
72 proto native bool LocalRelease(string action, bool check_focus = true);
73
81 proto native bool LocalHold_ID(int action, bool check_focus = true);
82 proto native bool LocalHold(string action, bool check_focus = true);
83
91 proto native bool LocalDbl_ID(int action, bool check_focus = true);
92 proto native bool LocalDbl(string action, bool check_focus = true);
93
101 proto native void DisableKey(int key);
102
104 proto native void EnableMouseAndKeyboard(bool enable);
106 proto native bool IsEnabledMouseAndKeyboard();
107
109 proto native void EnableGamepad(bool enable);
111 // NOTE: not actually supported, just keeping naming consistent.
112 // Required as we need to disable gamepad on windows when in the server browser to prevent
113 // the client from freezing on gamepad queries while refreshing the server list .
114 proto native bool IsEnabledGamepad();
119 proto native bool IsEnabledMouseAndKeyboardEvenOnServer();
120
125 proto native bool IsMouseConnected();
126 proto native bool IsKeyboardConnected();
127
129 proto native int GetCurrentProfile();
130 // gets currently selected profile keys for action
131 proto native void GetCurrentProfileActionKeys(int action_index, out TIntArray keys);
133 proto int GetProfileName(int profile_index, out string name);
135 proto native int GetProfilesCount();
137 proto native int SetProfile(int index);
138
139
140 // devices - joystick only!
141 proto native int GetDevicesCount();
142 proto int GetDeviceName(int device_index, out string name);
143 proto native int IsDeviceXInput(int device_index);
144 proto native int IsDeviceEnabled(int device_index);
145 proto native void SetDeviceEnabled(int device_index, bool enabled);
146
148 proto bool GetGamepadThumbDirection(GamepadButton thumbButton, out float angle, out float value);
149
151 proto native void ResetActiveGamepad();
152 proto native void SelectActiveGamepad(int gamepad);
153 proto native void GetGamepadList(out array<int> gamepads);
154 proto void GetGamepadUser(int gamepad, out BiosUser user);
159 proto native void IdentifyGamepad(GamepadButton button);
161 proto native bool IsActiveGamepadSelected();
162
164 bool IsAnyInputDeviceActive()
165 {
166 return IsActiveGamepadSelected() || IsMouseConnected() || IsKeyboardConnected();
167 }
168
173 bool AreAllAllowedInputDevicesActive(out array<int> unavailableDeviceList = null)
174 {
175 bool passed = true;
176 bool gamepad = IsActiveGamepadSelected();
177 bool mouse = IsMouseConnected();
178 bool keyboard = IsKeyboardConnected();
179 bool MnKEnabled;
180
181 if (g_Game.GetGameState() != DayZGameState.IN_GAME)
182 {
183 MnKEnabled = IsEnabledMouseAndKeyboard();
184 }
185 else if (g_Game.GetGameState() != DayZGameState.MAIN_MENU)
186 {
187 MnKEnabled = IsEnabledMouseAndKeyboardEvenOnServer();
188 }
189 else
190 {
191 return true;
192 }
193
194 if (!MnKEnabled)
195 {
196 if (!gamepad)
197 {
198 passed = false;
199 FillUnavailableDeviceArray(EUAINPUT_DEVICE_CONTROLLER,unavailableDeviceList);
200 }
201 }
202 else
203 {
204 if (!gamepad)
205 {
206 if (!mouse)
207 {
208 passed = false;
209 FillUnavailableDeviceArray(EUAINPUT_DEVICE_MOUSE,unavailableDeviceList);
210 }
211 if (!keyboard)
212 {
213 passed = false;
214 FillUnavailableDeviceArray(EUAINPUT_DEVICE_KEYBOARD,unavailableDeviceList);
215 }
216
217 if (!passed)
218 {
219 FillUnavailableDeviceArray(EUAINPUT_DEVICE_CONTROLLER,unavailableDeviceList);
220 }
221 }
222 }
223 return passed;
224 }
225
226 void FillUnavailableDeviceArray(int device, inout array<int> filler)
227 {
228 if (filler)
229 {
230 filler.Insert(device);
231 }
232 }
233
235 void UpdateConnectedInputDeviceList()
236 {
237 g_Game.GetConnectedInputDeviceList().Clear();
238
239 if (IsActiveGamepadSelected())
240 g_Game.GetConnectedInputDeviceList().Insert(EUAINPUT_DEVICE_CONTROLLER);
241 if (IsMouseConnected())
242 g_Game.GetConnectedInputDeviceList().Insert(EUAINPUT_DEVICE_MOUSE);
243 if (IsKeyboardConnected())
244 g_Game.GetConnectedInputDeviceList().Insert(EUAINPUT_DEVICE_KEYBOARD);
245 }
246
251 proto native EInputDeviceType GetCurrentInputDevice();
252
258 proto native GamepadButton GetEnterButton();
259
261 void OnGamepadConnected(int gamepad)
262 {
263 if (!g_Game)
264 return;
265
266 #ifdef PLATFORM_PS4
267 BiosUser user;
268 GetGamepadUser( gamepad, user );
269 if (user && user == g_Game.GetUserManager().GetSelectedUser())
270 {
271 SelectActiveGamepad(gamepad);
272 Mission mission = g_Game.GetMission();
273 if (mission)
274 mission.GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_CONTROLLER); //only for PS, xbox handles it on identification
275 }
276 #endif
277
278 #ifdef PLATFORM_XBOX
279 if (gamepad == g_Game.GetPreviousGamepad())
280 {
281 SelectActiveGamepad(g_Game.GetPreviousGamepad());
282 Mission mission = g_Game.GetMission();
283 if (mission)
284 mission.GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_CONTROLLER); //only for PS, xbox handles it on identification
285 }
286 #endif
287 }
288
290 void OnGamepadDisconnected(int gamepad)
291 {
292 if (!g_Game)
293 return;
294
295 if (IsInactiveGamepadOrUserSelected(gamepad))
296 {
297 UpdateConnectedInputDeviceList();
298
299 if (!g_Game.IsLoading())
300 {
301 DayZLoadState state = g_Game.GetLoadState();
302 if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT)
303 {
304 Mission mission = g_Game.GetMission();
305 if (mission)
306 mission.GetOnInputDeviceDisconnected().Invoke(EUAINPUT_DEVICE_CONTROLLER);
307 }
308 }
309 }
310 }
311
313 void OnGamepadIdentification(int gamepad)
314 {
315 if (!g_Game)
316 return;
317
318 if (gamepad > -1)
319 {
320 DayZLoadState state = g_Game.GetLoadState();
321
322 UpdateConnectedInputDeviceList();
323 SelectActiveGamepad(gamepad);
324 g_Game.SelectUser(gamepad);
325 g_Game.SetPreviousGamepad(gamepad);
326 Mission mission = g_Game.GetMission();
327 if (state == DayZLoadState.MAIN_MENU_START || state == DayZLoadState.MAIN_MENU_USER_SELECT)
328 {
329 if (mission)
330 mission.Reset();
331 }
332
333 if (mission && mission.GetOnInputDeviceConnected())
334 mission.GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_CONTROLLER);
335 }
336 }
337
338 int GetUserGamepad( BiosUser user )
339 {
340 array<int> gamepads = new array<int>;
341 GetGamepadList( gamepads );
342 for( int i = 0; i < gamepads.Count(); i++ )
343 {
344 BiosUser user2;
345 GetGamepadUser( gamepads[i], user2 );
346 if( user == user2 )
347 return gamepads[i];
348 }
349 return -1;
350 }
351
352 bool IsInactiveGamepadOrUserSelected( int gamepad = -1 )
353 {
354 if (!g_Game)
355 return false;
356
357 #ifdef PLATFORM_CONSOLE
358 if (!g_Game.GetUserManager())
359 return false;
360 #ifdef PLATFORM_XBOX
361 return !IsActiveGamepadSelected();
362 #endif
363 #ifdef PLATFORM_PS4
364 BiosUser user;
365 GetGamepadUser( gamepad, user );
366 return (user == g_Game.GetUserManager().GetSelectedUser());
367 #endif
368 #endif
369 return false;
370 }
371
374 void OnMouseConnected()
375 {
376 if (!g_Game)
377 return;
378
379 UpdateConnectedInputDeviceList();
380 if (!g_Game.IsLoading() && g_Game.GetMission())
381 {
382 DayZLoadState state = g_Game.GetLoadState();
383 if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT)
384 {
385 g_Game.GetMission().GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_MOUSE);
386 }
387 }
388 }
389
392 void OnMouseDisconnected()
393 {
394 if (!g_Game)
395 return;
396
397 UpdateConnectedInputDeviceList();
398 if (!g_Game.IsLoading() && g_Game.GetMission())
399 {
400 DayZLoadState state = g_Game.GetLoadState();
401 if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT)
402 {
403 g_Game.GetMission().GetOnInputDeviceDisconnected().Invoke(EUAINPUT_DEVICE_MOUSE);
404 }
405 }
406 }
407
410 void OnKeyboardConnected()
411 {
412 if (!g_Game)
413 return;
414
415 UpdateConnectedInputDeviceList();
416 if (!g_Game.IsLoading() && g_Game.GetMission())
417 {
418 DayZLoadState state = g_Game.GetLoadState();
419 if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT)
420 {
421 g_Game.GetMission().GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_KEYBOARD);
422 }
423 }
424 }
425
428 void OnKeyboardDisconnected()
429 {
430 if (!g_Game)
431 return;
432
433 UpdateConnectedInputDeviceList();
434 if (!g_Game.IsLoading() && g_Game.GetMission())
435 {
436 DayZLoadState state = g_Game.GetLoadState();
437 if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT)
438 {
439 g_Game.GetMission().GetOnInputDeviceDisconnected().Invoke(EUAINPUT_DEVICE_KEYBOARD);
440 }
441 }
442 }
443
445 void OnLastInputDeviceChanged(EInputDeviceType inputDevice)
446 {
447 if (!g_Game)
448 return;
449
450 if (g_Game.GetMission())
451 {
452 g_Game.GetMission().GetOnInputDeviceChanged().Invoke(inputDevice);
453 }
454 }
455};
456
@ UNKNOWN
24 - Any other error. Can be returned from any call.
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
Definition input.c:11
Mission class.
Definition gameplay.c:686
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZGame g_Game
Definition dayzgame.c:3942
Mission mission
array< int > TIntArray
Definition enscript.c:714
GamepadButton
Definition ensystem.c:341
proto string GetProfileName()
EInputDeviceType
Definition input.c:3
@ MOUSE_AND_KEYBOARD
Definition input.c:5
@ CONTROLLER
Definition radialmenu.c:4