ACE3/addons/microdagr/functions/fnc_openDisplay.sqf
mharis001 803d497d8a Improve checking of unit items (#6350)
* Add uniqueItems function

* Optimize dogtag children actions function

* Optimize getDetonators item search

* Store CfgWeapons lookup in getDetonators

* Update items to use new function

* Update items to use new function 2

* More optimization of uniqueItems function

* Update items to use new function 3
2018-09-17 14:03:28 -05:00

98 lines
3.7 KiB
Plaintext

/*
* Author: PabstMirror
* Changes the display mode of the MicroDAGR.
*
* Arguments:
* 0: Display Mode to show the microDAGR in <NUMBER> (default: -1)
*
* Return Value:
* None
*
* Example:
* [1] call ace_microdagr_fnc_openDisplay
*
* Public: No
*/
#include "script_component.hpp"
params [["_newDisplayShowMode", -1, [-1]]];
private _oldShowMode = GVAR(currentShowMode);
if (_newDisplayShowMode == -1) then {
//Toggle mode button:
if (_oldShowMode in [DISPLAY_MODE_DISPLAY, DISPLAY_MODE_HIDDEN]) then {_newDisplayShowMode = DISPLAY_MODE_DIALOG};
if (_oldShowMode in [DISPLAY_MODE_DIALOG, DISPLAY_MODE_CLOSED]) then {_newDisplayShowMode = DISPLAY_MODE_DISPLAY};
};
if ((_newDisplayShowMode == DISPLAY_MODE_DISPLAY) && {!([DISPLAY_MODE_DISPLAY] call FUNC(canShow))}) then {_newDisplayShowMode = DISPLAY_MODE_HIDDEN};
if ((_newDisplayShowMode == DISPLAY_MODE_DIALOG) && {!([DISPLAY_MODE_DIALOG] call FUNC(canShow))}) then {_newDisplayShowMode = DISPLAY_MODE_HIDDEN};
//On first-startup
if (GVAR(currentApplicationPage) == APP_MODE_NULL) then {
GVAR(currentApplicationPage) = APP_MODE_INFODISPLAY;
GVAR(mapPosition) = getPos ACE_player;
};
if (_newDisplayShowMode in [DISPLAY_MODE_CLOSED, DISPLAY_MODE_HIDDEN]) then {
//If Dialog is open, back it up before closing:
if (dialog && {!isNull (uiNamespace getVariable [QGVAR(DialogDisplay), displayNull])}) then {
[-1] call FUNC(saveCurrentAndSetNewMode);
closeDialog 0;
};
//Close the display:
(QGVAR(TheRscTitleDisplay) call BIS_fnc_rscLayer) cutText ["", "PLAIN"];
} else {
if (_newDisplayShowMode == DISPLAY_MODE_DISPLAY) then {
//If Dialog is open, back it up before closing:
if (dialog && {!isNull (uiNamespace getVariable [QGVAR(DialogDisplay), displayNull])}) then {
[-1] call FUNC(saveCurrentAndSetNewMode);
closeDialog 0;
};
//Open the display:
(QGVAR(TheRscTitleDisplay) call BIS_fnc_rscLayer) cutRsc [QGVAR(TheRscTitleDisplay), "PLAIN", 0, true];
} else { //DISPLAY_MODE_DIALOG
//Close the display:
(QGVAR(TheRscTitleDisplay) call BIS_fnc_rscLayer) cutText ["", "PLAIN"];
//Open the dialog:
createDialog QGVAR(TheDialog);
};
};
GVAR(currentShowMode) = _newDisplayShowMode;
//Update display applicaiton if open:
if (GVAR(currentShowMode) in [DISPLAY_MODE_DIALOG, DISPLAY_MODE_DISPLAY]) then {
[] call FUNC(showApplicationPage);
};
if ((_oldShowMode == DISPLAY_MODE_CLOSED) && {GVAR(currentShowMode) != DISPLAY_MODE_CLOSED}) then {
//Start a pfeh to update display and handle hiding display
[{
params ["_args", "_idPFH"];
_args params ["_player"];
if ((isNull ACE_player) || {!alive ACE_player} || {ACE_player != _player} || {!("ACE_microDAGR" in (ACE_player call EFUNC(common,uniqueItems)))} || {GVAR(currentShowMode) == DISPLAY_MODE_CLOSED}) then {
//Close Display if still open:
if (GVAR(currentShowMode) != DISPLAY_MODE_CLOSED) then {
[DISPLAY_MODE_CLOSED] call FUNC(openDisplay);
};
[_idPFH] call CBA_fnc_removePerFrameHandler;
} else {
if (GVAR(currentShowMode) == DISPLAY_MODE_HIDDEN) then {
//If display is hidden, and we can show, then swithc modes:
if ([DISPLAY_MODE_DISPLAY] call FUNC(canShow)) then {
[DISPLAY_MODE_DISPLAY] call FUNC(openDisplay);
};
} else {
if ([GVAR(currentShowMode)] call FUNC(canShow)) then {
[] call FUNC(updateDisplay);
} else {
[DISPLAY_MODE_HIDDEN] call FUNC(openDisplay);
};
};
};
}, 0.1, [ACE_player]] call CBA_fnc_addPerFrameHandler;
};