diff --git a/addons/common/CfgFunctions.hpp b/addons/common/CfgFunctions.hpp index fbc16954b..a2b9f7363 100644 --- a/addons/common/CfgFunctions.hpp +++ b/addons/common/CfgFunctions.hpp @@ -156,6 +156,7 @@ class CfgFunctions { PATHTO_FNC(attachToBone); PATHTO_FNC(binarizeNumber); PATHTO_FNC(endRadioTransmission); + PATHTO_FNC(hideAction); }; class Broken { diff --git a/addons/common/fnc_hideAction.sqf b/addons/common/fnc_hideAction.sqf new file mode 100644 index 000000000..4a1b13dd8 --- /dev/null +++ b/addons/common/fnc_hideAction.sqf @@ -0,0 +1,67 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_hideAction + +Description: + Registers or unregisters a hideActions entry for an action index and updates the current hidden state. + See https://community.bistudio.com/wiki/shownAction for CfgAction enums. + +Parameters: + _index - The action index. + _key - The key (case-sensitive). + _hide - Whether to hide the action. + _forceRemove - Force remove if all keys have been removed. (optional, default: false) + This can cause unexpected behavior if the action was hidden on a previous unit and the player switches back to it. + +Returns: + [hiddenIndices, unhiddenIndices] or empty array if no changes were made. + +Examples: + (begin example) + [15, "noEngineAction", true] call CBA_fnc_hideAction; + (end) + +Author: + PabstMirror +---------------------------------------------------------------------------- */ + +if (!hasInterface) exitWith { [] }; + +params [["_index", 0, [0]], ["_key", "", [""]], ["_hide", false, [false]], ["_forceRemove", false, [false]]]; + +private _fnc_update = { + private _hideSelected = []; + private _unhideSelected = []; + { + if (count _y == 0) then { + _unhideSelected pushBack _x; + } else { + _hideSelected pushBack _x; + }; + } forEach GVAR(hideActionHash); + hideActions [false, _unhideSelected]; + hideActions [true, _hideSelected]; + [_hideSelected, _unhideSelected] // final return +}; + +if (isNil QGVAR(hideActionHash)) then { + GVAR(hideActionHash) = createHashMap; + // need to update whenever the focusOn changes (player or UAV) + addMissionEventHandler ["PlayerViewChanged", _fnc_update]; +}; + +if (!_hide && {!(_index in (GVAR(hideActionHash)))}) exitWith { [] }; // index has never been set, just exit +private _actionIndex = GVAR(hideActionHash) getOrDefault [_index, createHashMap, true]; +if (_hide) then { + _actionIndex set [_key, true]; +} else { + _actionIndex deleteAt _key; +}; + +private _return = call _fnc_update; + +if (_forceRemove && {(count _actionIndex) == 0}) then { + GVAR(hideActionHash) deleteAt _index; +}; + +_return diff --git a/addons/main/script_mod.hpp b/addons/main/script_mod.hpp index cb37dca7e..c79f4202a 100644 --- a/addons/main/script_mod.hpp +++ b/addons/main/script_mod.hpp @@ -10,7 +10,7 @@ #define VERSION_AR MAJOR,MINOR,PATCHLVL,BUILD // MINIMAL required version for the Mod. Components can specify others.. -#define REQUIRED_VERSION 2.20 +#define REQUIRED_VERSION 2.22 /* // Defined DEBUG_MODE_NORMAL in a few CBA_fncs to prevent looped logging :)