Skip to content

Commit

Permalink
Merge pull request #1118 from acemod/multipleDevices
Browse files Browse the repository at this point in the history
Multiple Devices
  • Loading branch information
PabstMirror committed Jun 13, 2015
2 parents e7347be + 6ab8b12 commit b2d6961
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 66 deletions.
24 changes: 23 additions & 1 deletion addons/atragmx/initKeybinds.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,26 @@
false
},
{false},
[0, [false, false, false]], false, 0] call CBA_fnc_addKeybind; // (empty default key)
[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);
37 changes: 37 additions & 0 deletions addons/common/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 2 additions & 0 deletions addons/common/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ PREP(currentChannel);
PREP(debug);
PREP(debugModule);
PREP(defineVariable);
PREP(deviceKeyFindValidIndex);
PREP(deviceKeyRegisterNew);
PREP(disableAI);
PREP(disableUserInput);
PREP(displayIcon);
Expand Down
45 changes: 45 additions & 0 deletions addons/common/functions/fnc_deviceKeyFindValidIndex.sqf
Original file line number Diff line number Diff line change
@@ -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 <STRING>or<NUMBER><OPTIONAL>
*
* Return Value:
* The new index (-1 if no valid) <NUMBER>
*
* 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)
25 changes: 25 additions & 0 deletions addons/common/functions/fnc_deviceKeyRegisterNew.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Author: PabstMirror
* Finds next valid index for the device array.
*
* Arguments:
* 0: Localized Device Display Name <STRING>
* 1: Image <STRING>
* 2: Condtion Code (do they have the device) <CODE>
* 3: Toggle Code (on home press) <CODE>
* 4: Close Code (on ctrl-home press) <CODE>
*
* 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);
11 changes: 10 additions & 1 deletion addons/common/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -561,5 +561,14 @@
<German>Fügt einen LSD-Effekt zum synchronisierten Fahrzeug hinzu</German>
<Czech>Přidá LSD efekt pro synchronizované vozidla</Czech>
</Key>
<Key ID="STR_ACE_Common_toggleHandheldDevice">
<English>Toggle Handheld Device</English>
</Key>
<Key ID="STR_ACE_Common_closeHandheldDevice">
<English>Close Handheld Device</English>
</Key>
<Key ID="STR_ACE_Common_cycleHandheldDevices">
<English>Cycle Handheld Devices</English>
</Key>
</Package>
</Project>
</Project>
36 changes: 18 additions & 18 deletions addons/kestrel4500/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
};
};
};
};
Expand Down
33 changes: 33 additions & 0 deletions addons/kestrel4500/initKeybinds.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
36 changes: 15 additions & 21 deletions addons/microdagr/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
};
};
};
};
Expand Down
38 changes: 13 additions & 25 deletions addons/microdagr/XEH_clientInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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

["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};
};
_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);

[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);
Expand Down

0 comments on commit b2d6961

Please sign in to comment.