-
Notifications
You must be signed in to change notification settings - Fork 158
Common - Add setter for hideActions
#1832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
At 1st was gonna add the default for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, it may technically have a default from |
||||||||||||||
| _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 { | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't test in any way, but hashmaps are fast and |
||||||||||||||
| 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 { | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| _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 | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two things:
_forceAddis. In what scenarios would you use this?hideActionscommand. 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.
There was a problem hiding this comment.
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
_forceAddbecause I also can't think of a good usebut for 2nd point, we have to think about undoing everything that was done
e.g.
Start as playerA
["autoHover", "mySetting", true] call cba// update settingcba does
hideActions trueswitch to UAV
["autoHover", "mySetting", false] call cba// update settingswitch back to playerA
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.