ACE3/addons/zeus/functions/fnc_ui_toggleFlashlight.sqf
Josuan Albin 1ba330e853 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
2017-09-21 20:43:35 +02:00

144 lines
3.5 KiB
Plaintext

/*
* 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];