diff --git a/addons/atragmx/initKeybinds.sqf b/addons/atragmx/initKeybinds.sqf index 730ec4daed..c2ab01d217 100644 --- a/addons/atragmx/initKeybinds.sqf +++ b/addons/atragmx/initKeybinds.sqf @@ -11,4 +11,26 @@ false }, {false}, -[0, [false, false, false]], false, 0] call CBA_fnc_addKeybind; // (empty default key) \ No newline at end of file +[0, [false, false, false]], false, 0] call CBA_fnc_addKeybind; // (empty default key) + + +//Add deviceKey entry: +private ["_conditonCode", "_toggleCode", "_closeCode"]; +_conditonCode = { + [] call FUNC(can_show); +}; +_toggleCode = { + // Conditions: canInteract + if !([ACE_player, objNull, ["notOnMap", "isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {}; + if (GVAR(active)) exitWith { + closeDialog 0; + }; + // Statement + [] call FUNC(create_dialog); +}; +_closeCode = { + if (GVAR(active)) exitWith { + closeDialog 0; + }; +}; +[(localize LSTRING(Name)), QUOTE(PATHTOF(UI\ATRAG_Icon.paa)), _conditonCode, _toggleCode, _closeCode] call EFUNC(common,deviceKeyRegisterNew); diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index e0e78db11a..e3729a837a 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -314,4 +314,41 @@ if(isMultiplayer && { ACE_time > 0 || isNull player } ) then { ] call FUNC(checkPBOs) }] call FUNC(addEventHandler); +//Device Handler: +GVAR(deviceKeyHandlingArray) = []; +GVAR(deviceKeyCurrentIndex) = -1; + +["ACE3 Equipment", QGVAR(openDevice), (localize "STR_ACE_Common_toggleHandheldDevice"), +{ + [] 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), (localize "STR_ACE_Common_closeHandheldDevice"), +{ + [] call FUNC(deviceKeyFindValidIndex); + if (GVAR(deviceKeyCurrentIndex) == -1) exitWith {false}; + [] call ((GVAR(deviceKeyHandlingArray) select GVAR(deviceKeyCurrentIndex)) select 4); + true +}, +{false}, +[0xC7, [false, true, false]], false] call cba_fnc_addKeybind; //CTRL + Home Key + +["ACE3 Equipment", QGVAR(cycleDevice), (localize "STR_ACE_Common_cycleHandheldDevices"), +{ + [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); + [_displayName, _iconImage] call FUNC(displayTextPicture); + true +}, +{false}, +[0xC7, [true, false, false]], false] call cba_fnc_addKeybind; //SHIFT + Home Key + + GVAR(commonPostInited) = true; diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index d16f4878be..3a26d1e184 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -35,6 +35,8 @@ PREP(currentChannel); PREP(debug); PREP(debugModule); PREP(defineVariable); +PREP(deviceKeyFindValidIndex); +PREP(deviceKeyRegisterNew); PREP(disableAI); PREP(disableUserInput); PREP(displayIcon); diff --git a/addons/common/functions/fnc_deviceKeyFindValidIndex.sqf b/addons/common/functions/fnc_deviceKeyFindValidIndex.sqf new file mode 100644 index 0000000000..a8418cd4cd --- /dev/null +++ b/addons/common/functions/fnc_deviceKeyFindValidIndex.sqf @@ -0,0 +1,45 @@ +/* + * Author: PabstMirror + * Finds next valid index for the device array. + * + * Arguments: + * 0: Offset from currentIndex (use 1 to find next valid after current) or a displayName string or + * + * Return Value: + * The new index (-1 if no valid) + * + * Example: + * [] call ace_common_fnc_deviceKeyFindValidIndex + * ["kestral4500"] call ace_common_fnc_deviceKeyFindValidIndex + * + * Public: No + */ +#include "script_component.hpp" + +DEFAULT_PARAM(0,_searchOffsetOrName,0); + +private ["_validIndex", "_offsetBy", "_realIndex", "_offset"]; + +_validIndex = -1; + +if ((typeName _searchOffsetOrName) == "STRING") then { + { + if ((_x select 0) == _searchOffsetOrName) exitWith { + _validIndex = _forEachIndex; + }; + } forEach GVAR(deviceKeyHandlingArray); +} else { + if ((count GVAR(deviceKeyHandlingArray)) > 0) then { + _baseIndex = if (GVAR(deviceKeyCurrentIndex) == -1) then {0} else {GVAR(deviceKeyCurrentIndex) + _searchOffsetOrName}; + for "_offset" from _baseIndex to ((count GVAR(deviceKeyHandlingArray)) - 1 + _baseIndex) do { + _realIndex = _offset % (count GVAR(deviceKeyHandlingArray)); + if ([] call ((GVAR(deviceKeyHandlingArray) select _realIndex) select 2)) exitWith { + _validIndex = _realIndex; + }; + }; + }; +}; + +GVAR(deviceKeyCurrentIndex) = _validIndex; + +GVAR(deviceKeyCurrentIndex) diff --git a/addons/common/functions/fnc_deviceKeyRegisterNew.sqf b/addons/common/functions/fnc_deviceKeyRegisterNew.sqf new file mode 100644 index 0000000000..88ffa84af7 --- /dev/null +++ b/addons/common/functions/fnc_deviceKeyRegisterNew.sqf @@ -0,0 +1,25 @@ +/* + * Author: PabstMirror + * Finds next valid index for the device array. + * + * Arguments: + * 0: Localized Device Display Name + * 1: Image + * 2: Condtion Code (do they have the device) + * 3: Toggle Code (on home press) + * 4: Close Code (on ctrl-home press) + * + * Return Value: + * Nothing + * + * Example: + * [(localize "STR_ACE_microdagr_itemName"), QUOTE(PATHTOF(images\microDAGR_item.paa)), _conditionCode, _toggleCode, _closeCode] call ace_common_fnc_deviceKeyRegisterNew + * + * Public: No + */ +#include "script_component.hpp" + +PARAMS_5(_displayName,_iconImage,_conditionCode,_toggleCode,_closeCode); + +GVAR(deviceKeyHandlingArray) pushBack [_displayName,_iconImage,_conditionCode,_toggleCode,_closeCode]; +[] call FUNC(deviceKeyFindValidIndex); diff --git a/addons/common/stringtable.xml b/addons/common/stringtable.xml index 0bce1202be..82c709929d 100644 --- a/addons/common/stringtable.xml +++ b/addons/common/stringtable.xml @@ -561,5 +561,14 @@ Fügt einen LSD-Effekt zum synchronisierten Fahrzeug hinzu Přidá LSD efekt pro synchronizované vozidla + + Toggle Handheld Device + + + Close Handheld Device + + + Cycle Handheld Devices + - \ No newline at end of file + diff --git a/addons/kestrel4500/CfgVehicles.hpp b/addons/kestrel4500/CfgVehicles.hpp index 6e2fc1cba5..12b428316f 100644 --- a/addons/kestrel4500/CfgVehicles.hpp +++ b/addons/kestrel4500/CfgVehicles.hpp @@ -11,24 +11,24 @@ class CfgVehicles { priority = 0.1; icon = QUOTE(PATHTOF(UI\Kestrel4500_Icon.paa)); exceptions[] = {"notOnMap"}; - }; - class GVAR(show) { - displayName = CSTRING(ShowKestrel); - condition = QUOTE(call FUNC(canShow) && !GVAR(Overlay)); - statement = QUOTE(call FUNC(displayKestrel)); - showDisabled = 0; - priority = 0.2; - icon = QUOTE(PATHTOF(UI\Kestrel4500_Icon.paa)); - exceptions[] = {"notOnMap", "isNotInside"}; - }; - class GVAR(hide) { - displayName = CSTRING(HideKestrel); - condition = QUOTE(GVAR(Overlay)); - statement = QUOTE(call FUNC(displayKestrel)); - showDisabled = 0; - priority = 0.3; - icon = QUOTE(PATHTOF(UI\Kestrel4500_Icon.paa)); - exceptions[] = {"notOnMap", "isNotInside"}; + class GVAR(show) { + displayName = CSTRING(ShowKestrel); + condition = QUOTE(call FUNC(canShow) && !GVAR(Overlay)); + statement = QUOTE(call FUNC(displayKestrel)); + showDisabled = 0; + priority = 0.2; + icon = QUOTE(PATHTOF(UI\Kestrel4500_Icon.paa)); + exceptions[] = {"notOnMap", "isNotInside"}; + }; + class GVAR(hide) { + displayName = CSTRING(HideKestrel); + condition = QUOTE(GVAR(Overlay)); + statement = QUOTE(call FUNC(displayKestrel)); + showDisabled = 0; + priority = 0.3; + icon = QUOTE(PATHTOF(UI\Kestrel4500_Icon.paa)); + exceptions[] = {"notOnMap", "isNotInside"}; + }; }; }; }; diff --git a/addons/kestrel4500/initKeybinds.sqf b/addons/kestrel4500/initKeybinds.sqf index ab06dc2d2c..2a691bbe4f 100644 --- a/addons/kestrel4500/initKeybinds.sqf +++ b/addons/kestrel4500/initKeybinds.sqf @@ -24,3 +24,36 @@ }, {false}, [0, [true, false, false]], false, 0] call CBA_fnc_addKeybind; // (empty default key) + + +//Add deviceKey entry: +private ["_conditonCode", "_toggleCode", "_closeCode"]; +_conditonCode = { + [] call FUNC(canShow); +}; +_toggleCode = { + // Conditions: canInteract + if !([ACE_player, objNull, []] call EFUNC(common,canInteractWith)) exitWith {}; + + // Statement + if (!GVAR(Overlay)) then { + //If no overlay, show it: + [] call FUNC(displayKestrel); + } else { + //If overlay is up, switch to dialog: + [] call FUNC(createKestrelDialog); + }; +}; +_closeCode = { + // Statement + if (GVAR(Overlay)) then { + //If dispaly is open, close it: + GVAR(Overlay) = false; + }; + if (dialog && {!isNull (uiNamespace getVariable ["Kestrel4500_Display", displayNull])}) then { + //If dialog is open, close it: + GVAR(Kestrel4500) = false; + closeDialog 0; + }; +}; +[(localize LSTRING(Name)), QUOTE(PATHTOF(UI\Kestrel4500.paa)), _conditonCode, _toggleCode, _closeCode] call EFUNC(common,deviceKeyRegisterNew); diff --git a/addons/microdagr/CfgVehicles.hpp b/addons/microdagr/CfgVehicles.hpp index d07903dbc1..d70dcc8c6f 100644 --- a/addons/microdagr/CfgVehicles.hpp +++ b/addons/microdagr/CfgVehicles.hpp @@ -3,34 +3,28 @@ class CfgVehicles { class CAManBase: Man { class ACE_SelfActions { class ACE_Equipment { - class GVAR(show) { - //Opens the mini map - displayName = CSTRING(show); - condition = QUOTE(([DISPLAY_MODE_DISPLAY] call FUNC(canShow)) && {GVAR(currentShowMode) != DISPLAY_MODE_DISPLAY}); - statement = QUOTE([DISPLAY_MODE_DISPLAY] call FUNC(openDisplay)); - showDisabled = 0; - priority = 0.2; - icon = QUOTE(PATHTOF(UI\icon_microDAGR.paa)); - exceptions[] = {"notOnMap", "isNotInside"}; - }; class GVAR(configure) { //Opens the dialog displayName = CSTRING(configure); condition = QUOTE(([DISPLAY_MODE_DIALOG] call FUNC(canShow)) && {GVAR(currentShowMode) != DISPLAY_MODE_DIALOG}); statement = QUOTE([DISPLAY_MODE_DIALOG] call FUNC(openDisplay)); - showDisabled = 0; - priority = 0.1; - icon = QUOTE(PATHTOF(UI\icon_microDAGR.paa)); - exceptions[] = {"notOnMap", "isNotInside"}; - }; - class GVAR(close) { - displayName = CSTRING(closeUnit); - condition = QUOTE(GVAR(currentShowMode) != DISPLAY_MODE_CLOSED); - statement = QUOTE([DISPLAY_MODE_CLOSED] call FUNC(openDisplay)); - showDisabled = 0; - priority = 0.3; icon = QUOTE(PATHTOF(UI\icon_microDAGR.paa)); exceptions[] = {"notOnMap", "isNotInside"}; + class GVAR(show) { + //Opens the mini map + displayName = CSTRING(show); + condition = QUOTE(([DISPLAY_MODE_DISPLAY] call FUNC(canShow)) && {GVAR(currentShowMode) != DISPLAY_MODE_DISPLAY}); + statement = QUOTE([DISPLAY_MODE_DISPLAY] call FUNC(openDisplay)); + icon = QUOTE(PATHTOF(UI\icon_microDAGR.paa)); + exceptions[] = {"notOnMap", "isNotInside"}; + }; + class GVAR(close) { + displayName = CSTRING(closeUnit); + condition = QUOTE(GVAR(currentShowMode) != DISPLAY_MODE_CLOSED); + statement = QUOTE([DISPLAY_MODE_CLOSED] call FUNC(openDisplay)); + icon = QUOTE(PATHTOF(UI\icon_microDAGR.paa)); + exceptions[] = {"notOnMap", "isNotInside"}; + }; }; }; }; diff --git a/addons/microdagr/XEH_clientInit.sqf b/addons/microdagr/XEH_clientInit.sqf index 3b77a6bc33..736403cb5f 100644 --- a/addons/microdagr/XEH_clientInit.sqf +++ b/addons/microdagr/XEH_clientInit.sqf @@ -3,33 +3,21 @@ if (!hasInterface) exitWith {}; -//Add Keybinds: -["ACE3 Equipment", QGVAR(openGPS), (localize LSTRING(toggleUnit)), -{ - // canInteractWith (can use on map) - if !([ACE_player, objNull, ["notOnMap", "isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false}; - // Conditions: specific - if (!("ACE_microDAGR" in (items ace_player))) exitWith {false}; - +//Add deviceKey entry: +private ["_conditonCode", "_toggleCode", "_closeCode"]; +_conditonCode = { + ("ACE_microDAGR" in (items ACE_player)) +}; +_toggleCode = { + if !([ACE_player, objNull, ["notOnMap", "isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {}; [] call FUNC(openDisplay); //toggle display mode - true; -}, -{false}, -[0xC7, [false, false, false]], false] call cba_fnc_addKeybind; //Home Key +}; +_closeCode = { + if (GVAR(currentShowMode) == DISPLAY_MODE_CLOSED) exitWith {}; + [DISPLAY_MODE_CLOSED] call FUNC(openDisplay); +}; +[(localize LSTRING(itemName)), QUOTE(PATHTOF(images\microDAGR_item.paa)), _conditonCode, _toggleCode, _closeCode] call EFUNC(common,deviceKeyRegisterNew); -["ACE3 Equipment", QGVAR(closeGPS), (localize LSTRING(closeUnit)), -{ - // canInteractWith (can use on map) - if !([ACE_player, objNull, ["notOnMap", "isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false}; - // Conditions: specific - if (!("ACE_microDAGR" in (items ace_player))) exitWith {false}; - if (GVAR(currentShowMode) == DISPLAY_MODE_CLOSED) exitWith {false}; - - [DISPLAY_MODE_CLOSED] call FUNC(openDisplay); //close unit - true; -}, -{false}, -[0xC7, [false, true, false]], false] call cba_fnc_addKeybind; //CTRL + Home Key //Add Eventhandler: ["RangerfinderData", {_this call FUNC(recieveRangefinderData)}] call EFUNC(common,addEventHandler);