Base Device Handler Framework

Multiple devices share Home/Ctrl-home keys
This commit is contained in:
PabstMirror 2015-05-10 14:59:53 -05:00
parent f103a19920
commit f7ff4a2f36
5 changed files with 76 additions and 2 deletions

View File

@ -249,3 +249,39 @@ if(isMultiplayer && { time > 0 || isNull player } ) then {
};
}, 0, []] call cba_fnc_addPerFrameHandler;
};
//Device Handler:
GVAR(deviceKeyHandlingArray) = [];
GVAR(deviceKeyCurrentIndex) = -1;
["ACE3 Equipment", QGVAR(openDevice), "Open Device", //(localize "STR_ACE_microdagr_toggleUnit"),
{
[] call FUNC(deviceKeyFindValidIndex);
if (GVAR(deviceKeyCurrentIndex) == -1) exitWith {false};
[] call ((GVAR(deviceKeyHandlingArray) select GVAR(deviceKeyCurrentIndex)) select 3);
true;
},
{false},
[0xC7, [false, false, false]], false] call cba_fnc_addKeybind; //Home Key
["ACE3 Equipment", QGVAR(closeDevice), "Close Device", //(localize "STR_ACE_microdagr_toggleUnit"),
{
[] call FUNC(deviceKeyFindValidIndex);
if (GVAR(deviceKeyCurrentIndex) == -1) exitWith {false};
[] call ((GVAR(deviceKeyHandlingArray) select GVAR(deviceKeyCurrentIndex)) select 4);
},
{false},
[0xC7, [false, true, false]], false] call cba_fnc_addKeybind; //CTRL + Home Key
["ACE3 Equipment", QGVAR(cycleDevice), "Cycle Devices", //(localize "STR_ACE_microdagr_toggleUnit"),
{
systemChat "here";
[1] call FUNC(deviceKeyFindValidIndex);
if (GVAR(deviceKeyCurrentIndex) == -1) exitWith {false};
_displayName = ((GVAR(deviceKeyHandlingArray) select GVAR(deviceKeyCurrentIndex)) select 0);
_iconImage = ((GVAR(deviceKeyHandlingArray) select GVAR(deviceKeyCurrentIndex)) select 1);
systemChat str [_displayName, _iconImage];
[_displayName, _iconImage] call FUNC(displayTextPicture);
},
{false},
[0xC7, [true, false, false]], false] call cba_fnc_addKeybind; //SHIFT + Home Key

View File

@ -33,6 +33,8 @@ PREP(currentChannel);
PREP(debug);
PREP(debugModule);
PREP(defineVariable);
PREP(deviceKeyFindValidIndex);
PREP(deviceKeyRegisterNew);
PREP(disableAI);
PREP(disableUserInput);
PREP(displayIcon);

View File

@ -0,0 +1,13 @@
#include "script_component.hpp"
DEFAULT_PARAM(0,_offsetBy,0);
_validIndex = -1;
for "_offset" from _offsetBy to ((count GVAR(deviceKeyHandlingArray)) - 1 + _offsetBy) do {
_realIndex = (GVAR(deviceKeyCurrentIndex) + _offset) % (count GVAR(deviceKeyHandlingArray));
if ([] call ((GVAR(deviceKeyHandlingArray) select _realIndex) select 2)) exitWith {
_validIndex = _realIndex;
};
};
GVAR(deviceKeyCurrentIndex) = _validIndex;

View File

@ -0,0 +1,6 @@
#include "script_component.hpp"
PARAMS_5(_displayName,_iconImage,_conditionCode,_toggleCode,_closeCode);
GVAR(deviceKeyHandlingArray) pushBack [_displayName,_iconImage,_conditionCode,_toggleCode,_closeCode];
[] call FUNC(deviceKeyFindValidIndex);

View File

@ -3,7 +3,24 @@
if (!hasInterface) exitWith {};
//Add Keybinds:
_conditonCode = {
("ACE_microDAGR" in (items ace_player))
};
_toggleCode = {
if !([ACE_player, objNull, ["notOnMap", "isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false};
[] call FUNC(openDisplay); //toggle display mode
true
};
_closeCode = {
if (GVAR(currentShowMode) == DISPLAY_MODE_CLOSED) exitWith {false};
[DISPLAY_MODE_CLOSED] call FUNC(openDisplay);
true
};
["Mdagr", "", _conditonCode, _toggleCode, _closeCode] call EFUNC(common,deviceKeyRegisterNew);
/* //Add Keybinds:
["ACE3 Equipment", QGVAR(openGPS), (localize "STR_ACE_microdagr_toggleUnit"),
{
// canInteractWith (can use on map)
@ -29,7 +46,7 @@ if (!hasInterface) exitWith {};
true;
},
{false},
[0xC7, [false, true, false]], false] call cba_fnc_addKeybind; //CTRL + Home Key
[0xC7, [false, true, false]], false] call cba_fnc_addKeybind; //CTRL + Home Key */
//Add Eventhandler:
["RangerfinderData", {_this call FUNC(recieveRangefinderData)}] call EFUNC(common,addEventHandler);