Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/common/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class CfgFunctions {
PATHTO_FNC(attachToBone);
PATHTO_FNC(binarizeNumber);
PATHTO_FNC(endRadioTransmission);
PATHTO_FNC(hideAction);
};

class Broken {
Expand Down
66 changes: 66 additions & 0 deletions addons/common/fnc_hideAction.sqf

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things:

  • I don't quite understand what the purpose of _forceAdd is. In what scenarios would you use this?
  • Part of current behaviour: Hide an action (action A), then unhide using the function. Hide action A, but using the hideActions command. Now, hide/unhide any other action using the function and action A will be visible again. I don't like that behaviour, it feels very imposing and invasive.
    Proposed behavior: when you add a key to the index hashmap, it will hide the action (or keep it hidden if there was another key present with same action index). If all keys of a specific index are removed (i.e. index hashmap is empty), the index hashmap will be removed from the action hashmap and the action will be shown again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to rework _forceAdd because I also can't think of a good use
but for 2nd point, we have to think about undoing everything that was done

e.g.
Start as playerA
["autoHover", "mySetting", true] call cba // update setting
cba does hideActions true
switch to UAV
["autoHover", "mySetting", false] call cba // update setting
switch back to playerA

  • here we need to undo the hideActions that was originally applied to the player

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[15, "noEngineAction", true] call CBA_fnc_hideAction;  // hides
[15, "noEngineAction", false] call CBA_fnc_hideAction; // shows
[15, "noEngineAction", false, true] call CBA_fnc_hideAction; // shows and then removes from hash

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/johnb432/No-Actions/blob/master/addons/main/functions/fnc_hideAction.sqf

Here's something I cooked up that should address the scenario you described.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#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. <NUMBER>
_key - The key (case-sensitive). <STRING>
_hide - Whether to hide the action. <BOOL>
Comment on lines +10 to +12

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_index - The action index. <NUMBER>
_key - The key (case-sensitive). <STRING>
_hide - Whether to hide the action. <BOOL>
_index - The action index. (Default: 0) <NUMBER>
_key - The key (case-sensitive). <STRING>
_hide - Whether to hide the action. (Default: false) <BOOL>

At 1st was gonna add the default for _key too, but realized it's completely pointless to not specify that param, so it's better as a mandatory one; damned SQF requiring a default value to allow type-checking ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it may technically have a default from params
but I don't think it makes sense to list them, at least for _index where the default of 0 won't do anything useful

_forceAdd - Force add (even if hide is false and action is not hidden). (optional, default: false) <BOOL>

Returns:
[hiddenIndices, unhiddenIndices] <ARRAY>

Examples:
(begin example)
[15, "noEngineAction", true] call CBA_fnc_hideAction;
(end)

Author:
PabstMirror
---------------------------------------------------------------------------- */

if (!hasInterface) exitWith { [[], []] };

params [["_index", 0, [0]], ["_key", "", [""]], ["_hide", false, [false]], ["_forceAdd", false, [false]]];

private _addEH = if (isNil QGVAR(hideActionHash)) then {
GVAR(hideActionHash) = createHashMap;
true
} else {
false
};

if (_hide || _forceAdd || {_index in GVAR(hideActionHash)}) then {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't test in any way, but hashmaps are fast and in as well, so an in check might be faster than a lazy eval.

private _actionIndex = GVAR(hideActionHash) getOrDefault [_index, createHashMap, true];
if (_hide) then {
_actionIndex set [_key, true];
} else {
_actionIndex deleteAt _key;
};
};

private _fnc_update = {
private _hideSelected = [];
private _unhideSelected = [];
{
if (count _y == 0) then {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (count _y == 0) then {
if (count _y isEqualTo 0) then {

_unhideSelected pushBack _x;
} else {
_hideSelected pushBack _x;
};
} forEach GVAR(hideActionHash);
hideActions [false, _unhideSelected];
hideActions [true, _hideSelected];
[_hideSelected, _unhideSelected] // final return
};

if (_addEH) then {
// need to update whenever the focusOn changes (player or UAV)
addMissionEventHandler ["PlayerViewChanged", _fnc_update];
};
call _fnc_update
2 changes: 1 addition & 1 deletion addons/main/script_mod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 :)
Expand Down
Loading