Add toggle flashlight and NVG zeus modules (#4556)

* Add toggle flashlight and NVG modules

* Remove excessive spaces in moduleToggleNvg

* Fix indentation and typos to fit review

* Add an option to add gear, fix headers

* Change category to utility

* Add QOL improvement suggested by pabst

* Fix locality issues

* Remove locality check before enableFlashlight targetEvent

* Remove locality check before addWeaponItem targetEvent

* Add a player check in moduleToggleNVG, change modules category

* Add the same QOL in toggleNVG than in toggleFlashlight
This commit is contained in:
Josuan Albin 2017-09-21 20:43:35 +02:00 committed by jonpas
parent a783e6319f
commit 1ba330e853
11 changed files with 583 additions and 1 deletions

View File

@ -123,6 +123,7 @@ if (isServer) then {
[QGVAR(switchMove), {(_this select 0) switchMove (_this select 1)}] call CBA_fnc_addEventHandler;
[QGVAR(setVectorDirAndUp), {(_this select 0) setVectorDirAndUp (_this select 1)}] call CBA_fnc_addEventHandler;
[QGVAR(setVanillaHitPointDamage), {(_this select 0) setHitPointDamage (_this select 1)}] call CBA_fnc_addEventHandler;
[QGVAR(addWeaponItem), {(_this select 0) addWeaponItem [(_this select 1), (_this select 2)]}] call CBA_fnc_addEventHandler;
// Request framework
[QGVAR(requestCallback), FUNC(requestCallback)] call CBA_fnc_addEventHandler;

View File

@ -221,6 +221,18 @@ class CfgVehicles {
function = QFUNC(moduleUnconscious);
icon = QPATHTOF(UI\Icon_Module_Zeus_Unconscious_ca.paa);
};
class GVAR(moduleToggleNvg): GVAR(moduleBase) {
curatorCanAttach = 1;
category = QGVAR(AI);
displayName = CSTRING(moduleToggleNVG_DisplayName);
curatorInfoType = QGVAR(RscToggleNvg);
};
class GVAR(moduleToggleFlashlight): GVAR(moduleBase) {
curatorCanAttach = 1;
category = QGVAR(AI);
displayName = CSTRING(moduleToggleFlashlight_DisplayName);
curatorInfoType = QGVAR(RscToggleFlashlight);
};
class GVAR(AddFullArsenal): GVAR(moduleBase) {
curatorCanAttach = 1;
category = QGVAR(Utility);

View File

@ -24,6 +24,8 @@ PREP(moduleSuppressiveFire);
PREP(moduleSuppressiveFireLocal);
PREP(moduleSurrender);
PREP(moduleTeleportPlayers);
PREP(moduleToggleFlashlight);
PREP(moduleToggleNvg);
PREP(moduleUnconscious);
PREP(moduleZeusSettings);
PREP(showMessage);
@ -37,4 +39,6 @@ PREP(ui_groupSide);
PREP(ui_patrolArea);
PREP(ui_searchArea);
PREP(ui_teleportPlayers);
PREP(ui_toggleFlashlight);
PREP(ui_toggleNvg);
PREP(zeusAttributes);

View File

@ -16,6 +16,10 @@ QGVAR(GlobalSkillAI) addPublicVariableEventHandler FUNC(moduleGlobalSetSkill);
[QGVAR(moduleSearchNearby), CBA_fnc_searchNearby] call CBA_fnc_addEventHandler;
[QGVAR(moduleSearchArea), CBA_fnc_taskSearchArea] call CBA_fnc_addEventHandler;
[QGVAR(suppressiveFire), LINKFUNC(moduleSuppressiveFireLocal)] call CBA_fnc_addEventHandler;
[QGVAR(enableFlashlight), {
params ["_unit", "_mode"];
_unit enableGunLights _mode;
}] call CBA_fnc_addEventHandler;
// Editable object commands must be ran on server, this events are used in the respective module
if (isServer) then {

View File

@ -12,6 +12,9 @@ class CfgPatches {
QGVAR(modulePatrolArea),
QGVAR(moduleSearchArea),
QGVAR(moduleSearchNearby),
QGVAR(moduleTeleportPlayers),
QGVAR(moduleToggleNvg),
QGVAR(moduleToggleFlashlight),
QGVAR(moduleSimulation),
QGVAR(moduleSuppressiveFire),
QGVAR(AddFullArsenal),

View File

@ -0,0 +1,64 @@
/*
* Author: alganthe
* Zeus module function to toggle Flashlights
*
* Arguments:
* 0: Logic object <OBJECT>
* 1: Toggle mode <BOOL>
* 2: Add gear <BOOL>
* 3: Target of the toggle <SCALAR> 0: blufor; 1: opfor; 2: indep; 3: civ; 4: selected group
*
* Return Value:
* None
*
* Example:
* [LOGIC, true, true, 4] call ace_zeus_fnc_moduleToggleFlashlight
*
* Public: No
*/
#include "script_component.hpp"
params ["_logic", "_toggle", "_addGear", "_target"];
private _units = [];
if (_target == 4) then {
_units = units (attachedTo _logic);
} else {
_units = allUnits select {alive _x && {side _x == ([blufor, opfor, independent, civilian] select _target)}},
};
if (_toggle) then {
{
// enableGunLights doesn't work on players
if !(isPlayer _x || {(currentWeapon _x) isEqualTo ""}) then {
private _pointer = (_x weaponAccessories (currentWeapon _x)) select 1;
if (!(_pointer isEqualTo "") && {isNull (configfile >> "CfgWeapons" >> _pointer >> "ItemInfo" >> "Pointer")}) then {
[QGVAR(enableFlashlight), [_x, "forceOn"], _x] call CBA_fnc_targetEvent;
} else {
if (_addGear) then {
// Retrieve compatible items for the pointer slot
private _pointerSlotCompatible = [currentWeapon _x, "pointer"] call CBA_fnc_compatibleItems;
// Get flashlights from the array above and select the first one
private _flashlight = (_pointerSlotCompatible select {isNull (configfile >> "CfgWeapons" >> _x >> "ItemInfo" >> "Pointer")}) select 0;
[QEGVAR(common,addWeaponItem), [_x, (currentWeapon _x), _flashlight], _x] call CBA_fnc_targetEvent;
[QGVAR(enableFlashlight), [_x, "forceOn"], _x] call CBA_fnc_targetEvent;
};
};
};
} foreach _units;
} else {
{
if !(isPlayer _x || {(currentWeapon _x) isEqualTo ""}) then {
[QGVAR(enableFlashlight), [_x, "forceOff"], _x] call CBA_fnc_targetEvent;
};
} foreach _units;
};
deleteVehicle _logic;

View File

@ -0,0 +1,69 @@
/*
* Author: alganthe
* Zeus module function to toggle NVGs
*
* Arguments:
* 0: Logic object <OBJECT>
* 1: Toggle mode <BOOL>
* 2: Target of the toggle <SCALAR> 0: blufor; 1: opfor; 2: indep; 3: civ; 4: selected group
*
* Return Value:
* None
*
* Example:
* [LOGIC, true, 4] call ace_zeus_fnc_moduleToggleNvg
*
* Public: No
*/
#include "script_component.hpp"
params ["_logic", "_toggle", "_target"];
private _units = [];
if (_target == 4) then {
_units = units (attachedTo _logic);
} else {
_units = allUnits select {alive _x && {side _x == ([blufor, opfor, independent, civilian] select _target)}},
};
if (_toggle) then {
{
if (!isplayer _x && {hmd _x isEqualTo ""}) then {
private _cfgArray = getArray (configFile >> 'CfgVehicles' >> typeOf _x >>'linkedItems');
private _nvgClass = _cfgArray select {_x isKindOf ["NVGoggles",(configFile >> "CfgWeapons")]};
private _nvgHelmet =_cfgArray select {count (getArray (configFile >> "CfgWeapons" >> _x >> "subItems")) > 0};
// Can't have more than 1 assigned by default
if (count _nvgClass == 1 || {count _nvgHelmet == 1}) then {
if (count _nvgHelmet == 1) then {
_x addHeadgear (_nvgHelmet select 0);
} else {
_x linkItem (_nvgClass select 0);
};
} else {
_x linkItem "NVGoggles";
};
};
} foreach _units;
} else {
{
if (!isplayer _x) then {
private _cfgArray = getArray (configFile >> 'CfgVehicles' >> typeOf _x >>'linkedItems');
private _nvgHelmet =_cfgArray select {count (getArray (configFile >> "CfgWeapons" >> _x >> "subItems")) > 0};
if (count _nvgHelmet == 1) then {
removeHeadgear _x;
} else {
_x unlinkItem (hmd _x);
};
};
} foreach _units;
};
deleteVehicle _logic;

View File

@ -0,0 +1,126 @@
/*
* Author: alganthe
* Initalises the `Toggle NVGs` zeus module display
*
* Arguments:
* 0: Nvg toggle controls group <CONTROL>
*
* Return Value:
* None
*
* Example:
* onSetFocus = "_this call ace_zeus_fnc_ui_toggleNvg"
*
* Public: No
*/
#include "script_component.hpp"
disableSerialization;
params ["_control"];
//Generic Init:
private _display = ctrlparent _control;
private _ctrlButtonOK = _display displayctrl 1; //IDC_OK
private _logic = GETMVAR(BIS_fnc_initCuratorAttributes_target,objnull);
TRACE_1("logicObject",_logic);
_control ctrlRemoveAllEventHandlers "setFocus";
private _unit = effectiveCommander (attachedTo _logic);
// Handles errors
scopeName "Main";
private _fnc_errorAndClose = {
params ["_msg"];
_display closeDisplay 0;
deleteVehicle _logic;
[_msg] call EFUNC(common,displayTextStructured);
breakOut "Main";
};
if !(isNull _unit) then {
switch (false) do {
case (_unit isKindOf "CAManBase"): {
[LSTRING(OnlyInfantry)] call _fnc_errorAndClose;
};
case (alive _unit): {
[LSTRING(OnlyAlive)] call _fnc_errorAndClose;
};
};
};
//Specific on-load stuff:
private _comboBox = _display displayCtrl 92855;
private _comboBox2 = _display displayCtrl 92856;
{
_comboBox lbSetValue [_comboBox lbAdd (_x select 0), _x select 1];
} forEach [
[localize ELSTRING(common,Disabled), 0],
[localize ELSTRING(common,Enabled), 1]
];
if (isNull _unit) then {
{
_comboBox2 lbSetValue [_comboBox2 lbAdd (_x select 0), _x select 1];
} forEach [
["BLUFOR", 0],
["OPFOR", 1],
["INDEP", 2],
["CIV", 3]
];
} else {
{
_comboBox2 lbSetValue [_comboBox2 lbAdd (_x select 0), _x select 1];
} forEach [
[localize LSTRING(moduleToggleNVG_SelectedGroup), 4],
["BLUFOR", 0],
["OPFOR", 1],
["INDEP", 2],
["CIV", 3]
];
};
private _enabledDefault = false;
if (!isNull _unit) then {
_enabledDefault = !(hmd _unit isEqualTo "");
};
_comboBox lbSetCurSel ([0,1] select _enabledDefault);
_comboBox2 lbSetCurSel 0;
private _fnc_onUnload = {
params ["_display"];
private _logic = GETMVAR(BIS_fnc_initCuratorAttributes_target,objnull);
if (isNull _logic) exitWith {};
};
private _fnc_onConfirm = {
params [["_ctrlButtonOK", controlNull, [controlNull]]];
private _display = ctrlparent _ctrlButtonOK;
if (isNull _display) exitWith {};
private _logic = GETMVAR(BIS_fnc_initCuratorAttributes_target,objnull);
if (isNull _logic) exitWith {};
private _combo1 = _display displayCtrl 92855;
private _combo2 = _display displayCtrl 92856;
private _toggle = _combo1 lbValue (lbCurSel _combo1);
private _target = _combo2 lbValue (lbCurSel _combo2);
private _toggle = [
false,
true
] select (_toggle == 1);
[_logic, _toggle, _target] call FUNC(moduleToggleNvg);
};
_display displayAddEventHandler ["unload", _fnc_onUnload];
_ctrlButtonOK ctrlAddEventHandler ["buttonclick", _fnc_onConfirm];

View File

@ -0,0 +1,143 @@
/*
* Author: alganthe
* Initalises the `Toggle Flashlights` zeus module display
*
* Arguments:
* 0: Flashlight toggle controls group <CONTROL>
*
* Return Value:
* None
*
* Example:
* onSetFocus = "_this call ace_zeus_fnc_ui_toggleFLashlight"
*
* Public: No
*/
#include "script_component.hpp"
disableSerialization;
params ["_control"];
//Generic Init:
private _display = ctrlparent _control;
private _ctrlButtonOK = _display displayctrl 1; //IDC_OK
private _logic = GETMVAR(BIS_fnc_initCuratorAttributes_target,objnull);
TRACE_1("logicObject",_logic);
_control ctrlRemoveAllEventHandlers "setFocus";
private _unit = effectiveCommander (attachedTo _logic);
// Handles errors
scopeName "Main";
private _fnc_errorAndClose = {
params ["_msg"];
_display closeDisplay 0;
deleteVehicle _logic;
[_msg] call EFUNC(common,displayTextStructured);
breakOut "Main";
};
if !(isNull _unit) then {
switch (false) do {
case (_unit isKindOf "CAManBase"): {
[LSTRING(OnlyInfantry)] call _fnc_errorAndClose;
};
case (alive _unit): {
[LSTRING(OnlyAlive)] call _fnc_errorAndClose;
};
};
};
//Specific on-load stuff:
private _comboBox = _display displayCtrl 56218;
private _comboBox2 = _display displayCtrl 56219;
private _comboBox3 = _display displayCtrl 56220;
{
_comboBox lbSetValue [_comboBox lbAdd (_x select 0), _x select 1];
} forEach [
[localize ELSTRING(common,Disabled), 0],
[localize ELSTRING(common,Enabled), 1]
];
if (isNull _unit) then {
{
_comboBox2 lbSetValue [_comboBox2 lbAdd (_x select 0), _x select 1];
} forEach [
["BLUFOR", 0],
["OPFOR", 1],
["INDEP", 2],
["CIV", 3]
];
} else {
{
_comboBox2 lbSetValue [_comboBox2 lbAdd (_x select 0), _x select 1];
} forEach [
[localize LSTRING(moduleToggleNVG_SelectedGroup), 4],
["BLUFOR", 0],
["OPFOR", 1],
["INDEP", 2],
["CIV", 3]
];
};
{
_comboBox3 lbSetValue [_comboBox3 lbAdd (_x select 0), _x select 1];
} foreach [
[localize ELSTRING(common,Disabled), 0],
[localize ELSTRING(common,Enabled), 1]
];
private _enabledDefault = false;
if (!isNull _unit) then {
_enabledDefault = _unit isFlashlightOn (currentWeapon _unit);
};
_comboBox lbSetCurSel ([0,1] select _enabledDefault);
_comboBox2 lbSetCurSel 0;
_comboBox3 lbSetCurSel 0;
private _fnc_onUnload = {
params ["_display"];
private _logic = GETMVAR(BIS_fnc_initCuratorAttributes_target,objnull);
if (isNull _logic) exitWith {};
};
private _fnc_onConfirm = {
params [["_ctrlButtonOK", controlNull, [controlNull]]];
private _display = ctrlparent _ctrlButtonOK;
if (isNull _display) exitWith {};
private _logic = GETMVAR(BIS_fnc_initCuratorAttributes_target,objnull);
if (isNull _logic) exitWith {};
private _combo1 = _display displayCtrl 56218;
private _combo2 = _display displayCtrl 56219;
private _combo3 = _display displayCtrl 56220;
private _toggle = _combo1 lbValue (lbCurSel _combo1);
private _target = _combo2 lbValue (lbCurSel _combo2);
private _gear = _combo3 lbValue (lbCurSel _combo3);
_toggle = [
false,
true
] select (_toggle == 1);
_gear = [
false,
true
] select (_gear == 1);
[_logic, _toggle, _gear, _target] call FUNC(moduleToggleFlashlight);
};
_display displayAddEventHandler ["unload", _fnc_onUnload];
_ctrlButtonOK ctrlAddEventHandler ["buttonclick", _fnc_onConfirm];

View File

@ -1038,5 +1038,41 @@
<Key ID="STR_ACE_Zeus_ModuleLoadIntoCargo_DisplayName">
<English>Load into Cargo</English>
</Key>
<Key ID="STR_ACE_Zeus_moduleToggleNVG_DisplayName">
<English>Toggle NVGs</English>
<French>Basculer JVN</French>
</Key>
<Key ID="STR_ACE_Zeus_moduleToggleNVG_ToggleNvgTitle">
<English>NVG equipment</English>
<French>Equipment de vision nocturne</French>
</Key>
<Key ID="STR_ACE_Zeus_moduleToggleNVG_ToggleNvgTitleTooltip">
<English>Add or remove NVGs from units</English>
<French>Ajouter ou retirer JVN des unités</French>
</Key>
<Key ID="STR_ACE_Zeus_moduleToggleNVG_ToggleNvgSide">
<English>Toggle NVG target</English>
<French>Cible du basculement</French>
</Key>
<Key ID="STR_ACE_Zeus_moduleToggleNVG_SelectedGroup">
<English>Selected group</English>
<French>Groupe sélectionné</French>
</Key>
<Key ID="STR_ACE_Zeus_moduleToggleFlashlight_DisplayName">
<English>Toggle flashlights</English>
<French>Basculer lampes torches</French>
</Key>
<Key ID="STR_ACE_Zeus_moduleToggleFlashlight_ToggleFlashlightSide">
<English>Toggle flashlight target</English>
<French>Cible du basculement</French>
</Key>
<Key ID="STR_ACE_Zeus_moduleToggleFlashlight_ToggleFlashlightTitle">
<English>Flashlight</English>
<French>Lampe torche</French>
</Key>
<Key ID="STR_ACE_Zeus_moduleToggleFlashlight_ToggleFlashlightGear">
<English>Add gear</English>
<French>Ajouter équipement</French>
</Key>
</Package>
</Project>

View File

@ -417,7 +417,6 @@ class GVAR(RscTeleportPlayers): RscDisplayAttributes {
};
};
class GVAR(AttributeCargo): RscControlsGroupNoScrollbars {
onSetFocus = QUOTE(_this call FUNC(ui_attributeCargo));
idc = -1;
@ -473,3 +472,124 @@ class RscDisplayAttributesVehicleEmpty: RscDisplayAttributes {
};
};
};
class GVAR(RscToggleNvg): RscDisplayAttributes {
onLoad = QUOTE([ARR_3('onLoad', _this, QUOTE(QGVAR(RscToggleNvg)))] call FUNC(zeusAttributes));
onUnload = QUOTE([ARR_3('onUnload', _this, QUOTE(QGVAR(RscToggleNvg)))] call FUNC(zeusAttributes));
class Controls: Controls {
class Background: Background {};
class Title: Title {};
class Content: Content {
class Controls {
class ToggleNvg: RscControlsGroupNoScrollbars {
onSetFocus = QUOTE(_this call FUNC(ui_toggleNvg));
idc = 92854;
x = 0;
y = 0;
w = W_PART(26);
h = H_PART(3);
class controls {
class ToggleNvgTitle: Title {
idc = -1;
text = CSTRING(moduleToggleNVG_ToggleNvgTitle);
toolTip = CSTRING(moduleToggleNVG_ToggleNvgTitleTooltip);
x = H_PART(0);
y = H_PART(0);
w = W_PART(7);
};
class ToggleNvgCombo: RscCombo {
idc = 92855;
x = H_PART(6);
y = H_PART(0);
w = W_PART(10.1);
h = H_PART(1);
};
class ToggleNvgSideTitle: Title {
idc = -1;
text = CSTRING(moduleToggleNVG_ToggleNvgSide);
x = H_PART(0);
y = H_PART(1.2);
w = W_PART(7);
};
class ToggleNvgSideCombo: RscCombo {
idc = 92856;
x = H_PART(6);
y = H_PART(1.2);
w = W_PART(10.1);
h = H_PART(1);
};
};
};
};
};
class ButtonOK: ButtonOK {};
class ButtonCancel: ButtonCancel {};
};
};
class GVAR(RscToggleFlashlight): RscDisplayAttributes {
onLoad = QUOTE([ARR_3('onLoad', _this, QUOTE(QGVAR(RscToggleFlashlight)))] call FUNC(zeusAttributes));
onUnload = QUOTE([ARR_3('onUnload', _this, QUOTE(QGVAR(RscToggleFlashlight)))] call FUNC(zeusAttributes));
class Controls: Controls {
class Background: Background {};
class Title: Title {};
class Content: Content {
class Controls {
class ToggleFlashlight: RscControlsGroupNoScrollbars {
onSetFocus = QUOTE(_this call FUNC(ui_toggleFlashlight));
idc = 56217;
x = 0;
y = 0;
w = W_PART(26);
h = H_PART(5);
class controls {
class ToggleFlashlightTitle: Title {
idc = -1;
text = CSTRING(moduleToggleFlashlight_ToggleFlashlightTitle);
x = H_PART(0);
y = H_PART(0);
w = W_PART(7);
};
class ToggleFlashlightCombo: RscCombo {
idc = 56218;
x = H_PART(6);
y = H_PART(0);
w = W_PART(10.1);
h = H_PART(1);
};
class ToggleFlashlightSideTitle: Title {
idc = -1;
text = CSTRING(moduleToggleFlashlight_ToggleFlashlightSide);
x = H_PART(0);
y = H_PART(1.2);
w = W_PART(7);
};
class ToggleFlashlightSideCombo: RscCombo {
idc = 56219;
x = H_PART(6);
y = H_PART(1.2);
w = W_PART(10.1);
h = H_PART(1);
};
class ToggleFlashlightGearTitle: Title {
idc = -1;
text = CSTRING(moduleToggleFlashlight_ToggleFlashlightGear);
x = H_PART(0);
y = H_PART(2.4);
w = W_PART(7);
};
class ToggleFlashlightGearCombo: RscCombo {
idc = 56220;
x = H_PART(6);
y = H_PART(2.4);
w = W_PART(10.1);
h = H_PART(1);
};
};
};
};
};
class ButtonOK: ButtonOK {};
class ButtonCancel: ButtonCancel {};
};
};