Skip to content

Commit

Permalink
add userXX to keybinding menu (#828)
Browse files Browse the repository at this point in the history
* add userXX to keybinding menu

* Update XEH_preStart.sqf

* Update XEH_preStart.sqf

* Don't check inputAction if we have none bound

* check all keys instead of counting them

* Don't check inputAction if we have none bound (#830)

* Don't check inputAction if we have none bound

* check all keys instead of counting them

* constant as macro

* constant as macro

* Invert logic for faster condition checking

0.0001 ms faster!
  • Loading branch information
commy2 authored Dec 16, 2017
1 parent 8278650 commit dcc2aa0
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 1 deletion.
9 changes: 8 additions & 1 deletion addons/events/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ ADDON = true;

if (!hasInterface) exitWith {};

GVAR(skipCheckingUserActions) = true;

// Display Event Handlers
// Pressing "Restart" in the editor starts a completely new mission (preInit etc. are executed). The main display is never deleted though!
// This would cause douplicate display events to be added, because the old ones carry over while the new ones are added again.
Expand All @@ -56,9 +58,10 @@ PREP(keyHandlerUp);
PREP(mouseHandlerDown);
PREP(mouseHandlerUp);
PREP(mouseWheelHandler);
PREP(userKeyHandler);

private _keyHandlers = [];
_keyHandlers resize 0xFF;
_keyHandlers resize 270;

GVAR(keyDownStates) = _keyHandlers apply {[]};
GVAR(keyUpStates) = + GVAR(keyDownStates);
Expand All @@ -83,3 +86,7 @@ GVAR(keyHoldTimers) = call CBA_fnc_createNamespace;
GVAR(shift) = false;
GVAR(control) = false;
GVAR(alt) = false;

private _states = [];
_states resize 20;
GVAR(userKeyStates) = _states apply {false};
8 changes: 8 additions & 0 deletions addons/events/fnc_addKeyHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,12 @@ _hashKeys pushBackUnique _hashKey; // pushBackUnique. Fixes using addKeyHander t

_keyHandlers set [_key, _hashKeys];

if ((_key >= USERACTION_OFFSET) && {_key <= USERACTION_OFFSET + 19}) then {
private _hasUserActionsBound = {count _x > 0} count (GVAR(keyDownStates) select [USERACTION_OFFSET, 20]) > 0;

if (_hasUserActionsBound) then {
GVAR(skipCheckingUserActions) = false;
};
};

_hashKey
2 changes: 2 additions & 0 deletions addons/events/fnc_initDisplayCurator.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ _display displayAddEventHandler ["KeyUp", {call FUNC(keyHandlerUp)}];
_display displayAddEventHandler ["MouseButtonDown", {call FUNC(mouseHandlerDown)}];
_display displayAddEventHandler ["MouseButtonUp", {call FUNC(mouseHandlerUp)}];
_display displayAddEventHandler ["MouseZChanged", {call FUNC(mouseWheelHandler)}];
_display displayAddEventHandler ["MouseMoving", {call FUNC(userKeyHandler)}];
_display displayAddEventHandler ["MouseHolding", {call FUNC(userKeyHandler)}];
2 changes: 2 additions & 0 deletions addons/events/fnc_initDisplayMission.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ _display displayAddEventHandler ["KeyUp", {call FUNC(keyHandlerUp)}];
_display displayAddEventHandler ["MouseButtonDown", {call FUNC(mouseHandlerDown)}];
_display displayAddEventHandler ["MouseButtonUp", {call FUNC(mouseHandlerUp)}];
_display displayAddEventHandler ["MouseZChanged", {call FUNC(mouseWheelHandler)}];
_display displayAddEventHandler ["MouseMoving", {call FUNC(userKeyHandler)}];
_display displayAddEventHandler ["MouseHolding", {call FUNC(userKeyHandler)}];
8 changes: 8 additions & 0 deletions addons/events/fnc_removeKeyHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,12 @@ if (count _keyHandlers > _key) then {
_keyHandlers set [_key, _hashKeys];
};

if ((_key >= USERACTION_OFFSET) && {_key <= USERACTION_OFFSET + 19}) then {
private _hasUserActionsBound = {count _x > 0} count (GVAR(keyDownStates) select [USERACTION_OFFSET, 20]) > 0;

if (!_hasUserActionsBound) then {
GVAR(skipCheckingUserActions) = true;
};
};

nil
30 changes: 30 additions & 0 deletions addons/events/fnc_userKeyHandler.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* ----------------------------------------------------------------------------
Internal Function: CBA_events_fnc_userKeyHandler
Description:
Check state of user keys if enabled
Author:
commy2
---------------------------------------------------------------------------- */
#include "script_component.hpp"

if (GVAR(skipCheckingUserActions)) exitWith {};

params ["_display"];

private _userKeyStates = [
inputAction "User1" > 0.1, inputAction "User2" > 0.1, inputAction "User3" > 0.1, inputAction "User4" > 0.1, inputAction "User5" > 0.1,
inputAction "User6" > 0.1, inputAction "User7" > 0.1, inputAction "User8" > 0.1, inputAction "User9" > 0.1, inputAction "User10" > 0.1,
inputAction "User11" > 0.1, inputAction "User12" > 0.1, inputAction "User13" > 0.1, inputAction "User14" > 0.1, inputAction "User15" > 0.1,
inputAction "User16" > 0.1, inputAction "User17" > 0.1, inputAction "User18" > 0.1, inputAction "User19" > 0.1, inputAction "User20" > 0.1
];

if !(_userKeyStates isEqualTo GVAR(userKeyStates)) then {
{
if !(_x isEqualTo (GVAR(userKeyStates) select _forEachIndex)) then {
GVAR(userKeyStates) set [_forEachIndex, _x];
[_display, USERACTION_OFFSET + _forEachIndex, false, false, false] call ([FUNC(keyHandlerUp), FUNC(keyHandlerDown)] select _x);
};
} forEach _userKeyStates;
};
1 change: 1 addition & 0 deletions addons/events/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@
// key handler system
#define MOUSE_OFFSET 0xF0
#define MOUSE_WHEEL_OFFSET 0xF8 // MOUSE_OFFSET + 8 possible mouse keys
#define USERACTION_OFFSET 0xFA
5 changes: 5 additions & 0 deletions addons/keybinding/XEH_preStart.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ GVAR(keyNamesHash) = [_supportedKeys] call CBA_fnc_hashCreate;
[198, DIK_PAUSE]
];

// manually add user action keys
for "_i" from 0 to 19 do {
[GVAR(keyNamesHash), str (USER_1 + _i), actionName format ["User%1", _i + 1]] call CBA_fnc_hashSet;
};

GVAR(forbiddenKeys) = [
DIK_XBOX_LEFT_TRIGGER,
DIK_XBOX_RIGHT_TRIGGER,
Expand Down
23 changes: 23 additions & 0 deletions addons/keybinding/fnc_gui_editKey.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,29 @@ private _specialKeys = [
[true, true, true]
];

_specialKeys append [
[USER_1, [false, false, false]],
[USER_2, [false, false, false]],
[USER_3, [false, false, false]],
[USER_4, [false, false, false]],
[USER_5, [false, false, false]],
[USER_6, [false, false, false]],
[USER_7, [false, false, false]],
[USER_8, [false, false, false]],
[USER_9, [false, false, false]],
[USER_10, [false, false, false]],
[USER_11, [false, false, false]],
[USER_12, [false, false, false]],
[USER_13, [false, false, false]],
[USER_14, [false, false, false]],
[USER_15, [false, false, false]],
[USER_16, [false, false, false]],
[USER_17, [false, false, false]],
[USER_18, [false, false, false]],
[USER_19, [false, false, false]],
[USER_20, [false, false, false]]
];

{
_ctrlSpecialKeyList lbSetData [_ctrlSpecialKeyList lbAdd (_x call CBA_fnc_localizeKey), str _x];
} forEach _specialKeys;
Expand Down
21 changes: 21 additions & 0 deletions addons/keybinding/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,27 @@
#define DIK_XBOX_RIGHT_THUMB_X_LEFT 327702
#define DIK_XBOX_RIGHT_THUMB_Y_DOWN 327703

#define USER_1 0xFA
#define USER_2 0xFB
#define USER_3 0xFC
#define USER_4 0xFD
#define USER_5 0xFE
#define USER_6 0xFF
#define USER_7 0x100
#define USER_8 0x101
#define USER_9 0x102
#define USER_10 0x103
#define USER_11 0x104
#define USER_12 0x105
#define USER_13 0x106
#define USER_14 0x107
#define USER_15 0x108
#define USER_16 0x109
#define USER_17 0x10A
#define USER_18 0x10B
#define USER_19 0x10C
#define USER_20 0x10D

#define NAMESPACE_NULL objNull
#define HASH_NULL ([] call CBA_fnc_hashCreate)
#define KEYBIND_NULL [0, [false, false, false]]

0 comments on commit dcc2aa0

Please sign in to comment.