From e535ccfffa06f1af6f4d383d12be1179e2eb3eb0 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 5 Oct 2018 22:01:38 -0400 Subject: [PATCH] Add key handling to 3DEN attribute --- addons/arsenal/Cfg3DEN.hpp | 4 +- addons/arsenal/Display3DEN.hpp | 34 ++++++++++++++++ addons/arsenal/XEH_PREP.hpp | 1 + addons/arsenal/config.cpp | 1 + .../functions/fnc_attributeAddItems.sqf | 2 +- .../functions/fnc_attributeKeyDown.sqf | 39 +++++++++++++++++++ .../arsenal/functions/fnc_attributeLoad.sqf | 5 +++ addons/arsenal/ui/RscCommon.hpp | 35 ----------------- 8 files changed, 84 insertions(+), 37 deletions(-) create mode 100644 addons/arsenal/Display3DEN.hpp create mode 100644 addons/arsenal/functions/fnc_attributeKeyDown.sqf diff --git a/addons/arsenal/Cfg3DEN.hpp b/addons/arsenal/Cfg3DEN.hpp index ceb3cee9263..8e79b726b44 100644 --- a/addons/arsenal/Cfg3DEN.hpp +++ b/addons/arsenal/Cfg3DEN.hpp @@ -8,7 +8,7 @@ class Cfg3DEN { class GVAR(DefaultLoadoutsListAttribute) { property = QGVAR(DefaultLoadoutsListAttribute); value = 0; - expression = QUOTE(if (!is3DEN) then {GVAR(defaultLoadoutsList) = _value};); + expression = QUOTE(if (!is3DEN) then {GVAR(defaultLoadoutsList) = _value}); defaultValue = "[]"; validate = "none"; wikiType = "[[Array]]"; @@ -102,6 +102,8 @@ class Cfg3DEN { idcLeft = IDC_ATTRIBUTE_LIST_LEFT; idcRight = IDC_ATTRIBUTE_LIST_RIGHT; onLBDblClick = QUOTE(_this call FUNC(attributeDblClick)); + onSetFocus = QUOTE(SETUVAR(QGVAR(attributeFocus),ctrlParentControlsGroup (_this select 0))); + onKillFocus = QUOTE(SETUVAR(QGVAR(attributeFocus),nil)); x = QUOTE(5 * ATTRIBUTE_W); y = QUOTE(35.83 * ATTRIBUTE_H); w = QUOTE(125 * ATTRIBUTE_W); diff --git a/addons/arsenal/Display3DEN.hpp b/addons/arsenal/Display3DEN.hpp new file mode 100644 index 00000000000..0a693a2189a --- /dev/null +++ b/addons/arsenal/Display3DEN.hpp @@ -0,0 +1,34 @@ +class Display3DEN { + class ContextMenu: ctrlMenu { + class Items { + class Arsenal { + items[]= {"aceArsenal", "virtualArsenal"}; + }; + class virtualArsenal { + text = "BI Virtual Arsenal"; + action = QUOTE(['arsenal'] call bis_fnc_3DENEntityMenu); + value = 0; + data = "Arsenal"; + opensNewWindow = 1; + }; + class aceArsenal: virtualArsenal { + text = "ACE Arsenal"; + action = QUOTE(call FUNC(open3DEN)); + }; + }; + }; + class Controls { + class MenuStrip: ctrlMenuStrip { + class Items { + class Tools { + items[] += {"ACE_arsenal_portVALoadouts"}; + }; + class ACE_arsenal_portVALoadouts { + text = CSTRING(portLoadoutsText); + picture = QPATHTOEF(common,data\logo_ace3_ca.paa); + action = "call ace_arsenal_fnc_portVALoadouts;"; + }; + }; + }; + }; +}; diff --git a/addons/arsenal/XEH_PREP.hpp b/addons/arsenal/XEH_PREP.hpp index 233abc56f8d..81ed8f216ce 100644 --- a/addons/arsenal/XEH_PREP.hpp +++ b/addons/arsenal/XEH_PREP.hpp @@ -6,6 +6,7 @@ PREP(attributeAddItems); PREP(attributeClear); PREP(attributeDblClick); PREP(attributeInit); +PREP(attributeKeyDown); PREP(attributeLoad); PREP(attributeMode); PREP(attributeSelect); diff --git a/addons/arsenal/config.cpp b/addons/arsenal/config.cpp index 32bc41d254d..6eb4c895ce4 100644 --- a/addons/arsenal/config.cpp +++ b/addons/arsenal/config.cpp @@ -15,6 +15,7 @@ class CfgPatches { }; #include "ui\RscAttributes.hpp" +#include "Display3DEN.hpp" #include "Cfg3DEN.hpp" #include "CfgEventHandlers.hpp" #include "RscDisplayMain.hpp" diff --git a/addons/arsenal/functions/fnc_attributeAddItems.sqf b/addons/arsenal/functions/fnc_attributeAddItems.sqf index edc62ea6ede..12611bbdeb8 100644 --- a/addons/arsenal/functions/fnc_attributeAddItems.sqf +++ b/addons/arsenal/functions/fnc_attributeAddItems.sqf @@ -11,7 +11,7 @@ * None * * Example: - * [CONTROL, 0] call ace_arsenal_fnc_attributeAddItems + * [CONTROL] call ace_arsenal_fnc_attributeAddItems * * Public: No */ diff --git a/addons/arsenal/functions/fnc_attributeKeyDown.sqf b/addons/arsenal/functions/fnc_attributeKeyDown.sqf new file mode 100644 index 00000000000..300ab9f6c5e --- /dev/null +++ b/addons/arsenal/functions/fnc_attributeKeyDown.sqf @@ -0,0 +1,39 @@ +#include "script_component.hpp" +#include "\a3\ui_f\hpp\defineDIKCodes.inc" +/* + * Author: mharis001 + * Handles keyboard input for the 3DEN attribute. + * + * Arguments: + * 0: Display + * 1: Key code + * + * Return Value: + * Handled + * + * Example: + * [DISPLAY, 0] call ace_arsenal_fnc_attributeKeyDown + * + * Public: No + */ + +params ["_display", "_keyCode"]; +TRACE_2("Attribute key down",_display,_keyCode); + +// Exit if attribute is not in focus +private _controlsGroup = uiNamespace getVariable QGVAR(attributeFocus); +if (isNil "_controlsGroup") exitWith {false}; + +switch (_keyCode) do { + case DIK_LEFT; + case DIK_NUMPADMINUS: { + [_controlsGroup, false] call FUNC(attributeSelect); + true + }; + case DIK_RIGHT; + case DIK_NUMPADPLUS: { + [_controlsGroup, true] call FUNC(attributeSelect); + true + }; + default {false}; +}; diff --git a/addons/arsenal/functions/fnc_attributeLoad.sqf b/addons/arsenal/functions/fnc_attributeLoad.sqf index b2b3f13b1e8..439ec2ff365 100644 --- a/addons/arsenal/functions/fnc_attributeLoad.sqf +++ b/addons/arsenal/functions/fnc_attributeLoad.sqf @@ -23,6 +23,11 @@ TRACE_1("Initializing 3DEN attribute",_value); // Store working attribute value uiNamespace setVariable [QGVAR(attributeValue), _value]; +// Add keyDown EH to display +// Does not work properly when added to controls group +private _display = ctrlParent _controlsGroup; +_display displayAddEventHandler ["KeyDown", {call FUNC(attributeKeyDown)}]; + // Handle selected mode if (_value select 1 > 0) then { (_controlsGroup controlsGroupCtrl IDC_ATTRIBUTE_MODE) lbSetCurSel 1; diff --git a/addons/arsenal/ui/RscCommon.hpp b/addons/arsenal/ui/RscCommon.hpp index 1d580c679e4..f74326bcfb7 100644 --- a/addons/arsenal/ui/RscCommon.hpp +++ b/addons/arsenal/ui/RscCommon.hpp @@ -266,38 +266,3 @@ class ctrlMapEmpty; class ctrlMapMain; class ctrlListNBox; class ctrlCheckboxToolbar; - -class Display3DEN { - class ContextMenu :ctrlMenu { - class Items { - class Arsenal { - items[]= {"aceArsenal", "virtualArsenal"}; - }; - class virtualArsenal { - text = "BI Virtual Arsenal"; - action= QUOTE(['arsenal'] call bis_fnc_3DENEntityMenu); - value=0; - data="Arsenal"; - opensNewWindow=1; - }; - class aceArsenal: virtualArsenal { - text = "ACE Arsenal"; - action= QUOTE(call FUNC(open3DEN)); - }; - }; - }; - class Controls { - class MenuStrip: ctrlMenuStrip { - class Items { - class Tools { - items[] += {"ACE_arsenal_portVALoadouts"}; - }; - class ACE_arsenal_portVALoadouts { - text = CSTRING(portLoadoutsText); - picture = QPATHTOEF(common,data\logo_ace3_ca.paa); - action = "call ace_arsenal_fnc_portVALoadouts;"; - }; - }; - }; - }; -};