Skip to content

Commit

Permalink
remake keybinding ui and add mouse support (#638)
Browse files Browse the repository at this point in the history
* remake rebinding ui for mouse support

* remember last selected addon in keybinding ui
  • Loading branch information
commy2 authored May 17, 2017
1 parent f390cbe commit 648db8c
Show file tree
Hide file tree
Showing 28 changed files with 779 additions and 1,125 deletions.
6 changes: 3 additions & 3 deletions addons/help/XEH_postClientInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ if (!isNil QGVAR(keys)) then {
0 spawn {
private _text = GVAR(keys);

private _activeMods = allVariables EGVAR(keybinding,activeMods);
private _activeMods = allVariables EGVAR(keybinding,addons);
_activeMods sort true;

{
(EGVAR(keybinding,activeMods) getVariable _x) params ["_addonName", "_addonActions"];
(EGVAR(keybinding,addons) getVariable _x) params ["_addonName", "_addonActions"];

_text = _text + format ["%1:<br/>", _addonName];

{
(EGVAR(keybinding,activeBinds) getVariable (_addonName + "$" + _x)) params ["_displayName", "", "_registryKeybinds"];
(EGVAR(keybinding,actions) getVariable (_addonName + "$" + _x)) params ["_displayName", "", "_registryKeybinds"];

private _keyName = (_registryKeybinds select {_x select 0 > DIK_ESCAPE} apply {_x call CBA_fnc_localizeKey}) joinString " ";

Expand Down
2 changes: 1 addition & 1 deletion addons/keybinding/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class Extended_PreInit_EventHandlers {

class Extended_DisplayLoad_EventHandlers {
class RscDisplayConfigure {
ADDON = QUOTE(_this call (uiNamespace getVariable 'FUNC(configureDisplayLoad)'));
ADDON = QUOTE(_this call (uiNamespace getVariable 'FUNC(initDisplayConfigure)'));
};
};
6 changes: 6 additions & 0 deletions addons/keybinding/XEH_PREP.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

PREP(initDisplayConfigure);

PREP(gui_configure);
PREP(gui_update);
PREP(gui_editKey);
36 changes: 5 additions & 31 deletions addons/keybinding/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ SCRIPT(XEH_preInit);

if (!hasInterface) exitWith {};

#include "XEH_PREP.sqf"

ADDON = false;

// Load DIK to string conversion table.
Expand All @@ -13,41 +15,13 @@ with uiNamespace do {
GVAR(keyNames) = uiNamespace getVariable QGVAR(keyNames);
GVAR(forbiddenKeys) = uiNamespace getVariable QGVAR(forbiddenKeys);

// Prepare GUI functions and variables.
PREP_SUB(gui,onButtonClick_configure);
PREP_SUB(gui,onButtonClick_delete);
PREP_SUB(gui,onButtonClick_default);
PREP_SUB(gui,onButtonClick_cancel);
PREP_SUB(gui,onComboChanged);
PREP_SUB(gui,onKeyDown);
PREP_SUB(gui,onKeyUp);
//PREP_SUB(gui,onKeyDownNextGen);
//PREP_SUB(gui,onKeyUpNextGen);
PREP_SUB(gui,onLBDblClick);
PREP_SUB(gui,updateGUI);

GVAR(input) = [];
GVAR(frameNoKeyPress) = diag_frameNo;
GVAR(modifiers) = [];
GVAR(firstKey) = [];
GVAR(secondKey) = [];
GVAR(thirdKey) = [];
GVAR(waitingForInput) = false;
GVAR(defaultKeybinds) = [[],[]];

if (isNil QGVAR(activeMods)) then {
GVAR(activeMods) = [] call CBA_fnc_createNamespace;
GVAR(activeBinds) = [] call CBA_fnc_createNamespace;
if (isNil QGVAR(addons)) then {
GVAR(addons) = [] call CBA_fnc_createNamespace;
GVAR(actions) = [] call CBA_fnc_createNamespace;
};

if (isNil QGVAR(modPrettyNames)) then {
GVAR(modPrettyNames) = [] call CBA_fnc_createNamespace;
};

// Counter for indexing added key handlers.
GVAR(ehCounter) = 512;

/////////////////////////////////////////////////////////////////////////////////

// Announce initialization complete
ADDON = true;
26 changes: 15 additions & 11 deletions addons/keybinding/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "script_component.hpp"

PREP(configureDisplayLoad);
if (!hasInterface) exitWith {};

#include "XEH_PREP.sqf"

private _supportedKeys = [
DIK_ESCAPE,
Expand Down Expand Up @@ -176,16 +178,18 @@ GVAR(keyNamesHash) = [_supportedKeys] call CBA_fnc_hashCreate;
{
[GVAR(keyNamesHash), str (_x select 0), parseSimpleArray format ["[%1]", keyName (_x select 1)] select 0] call CBA_fnc_hashSet;
} forEach [
[0xF0, 0x10000],
[0xF1, 0x10081],
[0xF2, 0x10002],
[0xF3, 0x10003],
[0xF4, 0x10004],
[0xF5, 0x10005],
[0xF6, 0x10006],
[0xF7, 0x10007],
[0xF8, 0x100004],
[0xF9, 0x100005]
[0xF0, 0x10000], // LMB
[0xF1, 0x10081], // RMB
[0xF2, 0x10002], // MMB
[0xF3, 0x10003], // Mouse #4
[0xF4, 0x10004], // Mouse #5
[0xF5, 0x10005], // Mouse #6
[0xF6, 0x10006], // Mouse #7
[0xF7, 0x10007], // Mouse #8
[0xF8, 0x100004], // Mouse wheel up
[0xF9, 0x100005], // Mouse wheel down
[84, DIK_SYSRQ],
[198, DIK_PAUSE]
];

GVAR(forbiddenKeys) = [
Expand Down
2 changes: 1 addition & 1 deletion addons/keybinding/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ class CfgPatches {
#include "CfgEventHandlers.hpp"
#include "CfgFunctions.hpp"

#include "gui\gui.hpp"
#include "gui.hpp"
41 changes: 23 additions & 18 deletions addons/keybinding/fnc_addKeybind.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ if (canSuspend) exitWith {

params [
["_addon", "", [""]],
["_action", "", [""]],
["_addonAction", "", [""]],
["_title", "", ["", []]],
["_downCode", {}, [{}]],
["_upCode", {}, [{}]],
["_defaultKeybind", KEYBIND_NULL, [KEYBIND_NULL]],
["_holdKey", true, [false]],
["_holdKey", false, [false]],
["_holdDelay", 0, [0]],
["_overwrite", false, [false]]
];

_title params [["_displayName", _action, [""]], ["_tooltip", "", [""]]];
_action = toLower _action;
_title params [["_displayName", _addonAction, [""]], ["_tooltip", "", [""]]];
private _action = toLower format ["%1$%2", _addon, _addonAction];

// support old format
if (_defaultKeybind isEqualTypeParams [0, false, false, false]) then {
Expand All @@ -92,6 +92,8 @@ if (_defaultKeybind isEqualTypeParams [0, false, false, false]) then {
_defaultKeybind params [["_defaultKey", 0, [0]], ["_defaultModifiers", [], [[]]]];
_defaultModifiers params [["_defaultShift", false, [false]], ["_defaultControl", false, [false]], ["_defaultAlt", false, [false]]];

_defaultKey = _defaultKey max 0;

if (_defaultKey in [DIK_LSHIFT, DIK_RSHIFT]) then {
_defaultShift = true;
};
Expand All @@ -114,43 +116,46 @@ if (isNil "_registry") then {
profileNamespace setVariable [QGVAR(registry_v3), _registry];
};

private _registryKeybinds = [_registry, _action] call CBA_fnc_hashGet;
private _keybinds = [_registry, _action] call CBA_fnc_hashGet;

// action doesn't exist in registry yet, create it and store default keybinding
if (isNil "_registryKeybinds" || {_overwrite}) then {
_registryKeybinds = [_keybind];
[_registry, _action, _registryKeybinds] call CBA_fnc_hashSet;
if (isNil "_keybinds" || {_overwrite}) then {
_keybinds = [_keybind];
[_registry, _action, _keybinds] call CBA_fnc_hashSet;
};

// filter out null binds
_keybinds = _keybinds select {_x select 0 > DIK_ESCAPE};

// make list of active mods and keybinds for gui
if (isNil QGVAR(activeMods)) then {
GVAR(activeMods) = [] call CBA_fnc_createNamespace;
GVAR(activeBinds) = [] call CBA_fnc_createNamespace;
if (isNil QGVAR(addons)) then {
GVAR(addons) = [] call CBA_fnc_createNamespace;
GVAR(actions) = [] call CBA_fnc_createNamespace;
};

private _addonInfo = GVAR(activeMods) getVariable _addon;
private _addonInfo = GVAR(addons) getVariable _addon;

if (isNil "_addonInfo") then {
_addonInfo = [_addon, []];
GVAR(activeMods) setVariable [_addon, _addonInfo];
GVAR(addons) setVariable [_addon, _addonInfo];
};

(_addonInfo select 1) pushBackUnique toLower _action;
(_addonInfo select 1) pushBackUnique toLower _addonAction;

GVAR(activeBinds) setVariable [_addon + "$" + _action, [_displayName, _tooltip, _registryKeybinds, _defaultKeybind]];
GVAR(actions) setVariable [_action, [_displayName, _tooltip, _keybinds, _defaultKeybind, _downCode, _upCode, _holdKey, _holdDelay]];

// add this action to all keybinds
{
_keybind = _x;

if !(_downCode isEqualTo {}) then {
[_keybind select 0, _keybind select 1, _downCode, "keyDown", format ["%1$%2$down", _addon, _action], _holdKey, _holdDelay] call CBA_fnc_addKeyHandler;
[_keybind select 0, _keybind select 1, _downCode, "keyDown", format ["%1_down_%2", _action, _forEachIndex], _holdKey, _holdDelay] call CBA_fnc_addKeyHandler;
};

if !(_upCode isEqualTo {}) then {
[_keybind select 0, _keybind select 1, _upCode, "keyUp", format ["%1$%2$up", _addon, _action]] call CBA_fnc_addKeyHandler;
[_keybind select 0, _keybind select 1, _upCode, "keyUp", format ["%1_up_%2", _action, _forEachIndex]] call CBA_fnc_addKeyHandler;
};
} forEach _registryKeybinds;
} forEach _keybinds;

// Emit an event that a key has been registered.
[QGVAR(registerKeybind), _this] call CBA_fnc_localEvent;
Expand Down
55 changes: 0 additions & 55 deletions addons/keybinding/fnc_configureDisplayLoad.sqf

This file was deleted.

68 changes: 68 additions & 0 deletions addons/keybinding/fnc_gui_configure.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "script_component.hpp"

// get button
params ["_control"];

// get dialog
private _display = ctrlParent _control;

_ctrlKeyboardGroup = _display displayCtrl 2300;
_ctrlMouseGroup = _display displayCtrl 2301;
_ctrlKeyboardButton = _display displayCtrl 2400;
_ctrlMouseButton = _display displayCtrl 2401;
_ctrlControllerButton = _display displayCtrl 106;
_ctrlPresetButton = _display displayCtrl 114;
_ctrlDefaultButton = _display displayCtrl 101;

_ctrlKeyboardButtonFake = _display displayCtrl IDC_BTN_KEYBOARD_FAKE;
_ctrlAddonsGroup = _display displayCtrl IDC_ADDONS_GROUP;
_ctrlToggleButton = _display displayCtrl IDC_BTN_CONFIGURE_ADDONS;

// Toggle displayed groups and buttons.
if !(ctrlShown _ctrlAddonsGroup) then {
//--- disable and hide default menu
_ctrlKeyboardGroup ctrlEnable false;
_ctrlKeyboardGroup ctrlShow false;
_ctrlMouseGroup ctrlEnable false;
_ctrlMouseGroup ctrlShow false;
_ctrlKeyboardButton ctrlEnable false;
_ctrlKeyboardButton ctrlShow false;
_ctrlMouseButton ctrlEnable false;
_ctrlMouseButton ctrlShow false;
_ctrlControllerButton ctrlEnable false;
_ctrlControllerButton ctrlShow false;
_ctrlPresetButton ctrlEnable false;
_ctrlPresetButton ctrlShow false;
_ctrlDefaultButton ctrlEnable false;
_ctrlDefaultButton ctrlShow false;

//--- show and enable custom buttons
_ctrlKeyboardButtonFake ctrlEnable true;
_ctrlKeyboardButtonFake ctrlShow true;
_ctrlAddonsGroup ctrlEnable true;
_ctrlAddonsGroup ctrlShow true;

//--- change button text
_ctrlToggleButton ctrlSetText localize LSTRING(configureBase);
} else {
//--- enable and show default menu
_ctrlKeyboardGroup ctrlEnable true;
_ctrlKeyboardGroup ctrlShow true;
_ctrlKeyboardButton ctrlEnable true;
_ctrlKeyboardButton ctrlShow true;
_ctrlMouseButton ctrlEnable true;
_ctrlMouseButton ctrlShow true;
_ctrlControllerButton ctrlEnable true;
_ctrlControllerButton ctrlShow true;
_ctrlPresetButton ctrlEnable true;
_ctrlPresetButton ctrlShow true;

//--- hide and disable custom buttons
_ctrlKeyboardButtonFake ctrlEnable false;
_ctrlKeyboardButtonFake ctrlShow false;
_ctrlAddonsGroup ctrlEnable false;
_ctrlAddonsGroup ctrlShow false;

//--- change button text
_ctrlToggleButton ctrlSetText localize LSTRING(configureAddons);
};
Loading

0 comments on commit 648db8c

Please sign in to comment.