change vehicle flag actions to use class inheritance instead of object

This commit is contained in:
2024-02-08 12:01:51 -08:00
parent 3217ec487d
commit 7268d8fd50

View File

@@ -16,94 +16,86 @@ private _flagCategoryCfgs = (_vehicleFlagsCfg >> "FlagCategories") call BIS_fnc_
private _parentClass = _x; private _parentClass = _x;
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// add CBA class event handler to add actions to vehicles after they are initialized // create the root action
// all classes that inherit from the base classes will also have this applied
// an exclusion function is present for manually excluding specific classes
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
[_parentClass, "InitPost", { private _rootActionID = QGVAR(SetVehicleFlagAction);
private _flagRootAction = [
_rootActionID, // id
"Set Vehicle Flag", // displayed title
"\A3\ui_f\data\map\markers\flags\nato_ca.paa", // flag icon
{true}, // statement
{
params ["_target", "_player", "_params"];
// _params params ["_parentActionID", "_flagCategories"];
// check if vehicle is excluded
private _excluded = [typeOf _target] call FUNC(isClassExcluded);
if (_excluded || !alive _target) exitWith {false};
true;
}, // condition
{
////////////////////////////////////////////////////////////////////////
// create the flag category actions (with nested flag actions)
////////////////////////////////////////////////////////////////////////
params ["_target", "_player", "_params"];
_params params ["_rootActionID"];
//////////////////////////////////////////////////////////////////////// private _vehicleFlagsCfg = call FUNC(getVehicleFlagsCfg);
// create the root action if (isNull _vehicleFlagsCfg) exitWith {[]};
//////////////////////////////////////////////////////////////////////// private _flagCategoryCfgs = (_vehicleFlagsCfg >> "FlagCategories") call BIS_fnc_returnChildren;
private _rootActionID = "SetVehicleFlag";
private _flagRootAction = [
_rootActionID, // id
"Set Vehicle Flag", // displayed title
"\A3\ui_f\data\map\markers\flags\nato_ca.paa", // flag icon
{true}, // statement
{
params ["_target", "_player", "_params"];
// _params params ["_parentActionID", "_flagCategories"];
// check if vehicle is excluded // return category child actions with individual flag actions nested as children
private _excluded = [typeOf _target] call FUNC(isClassExcluded); [_rootActionID, _flagCategoryCfgs] call FUNC(getActionsFlagCategories);
if (_excluded || !alive _target) exitWith {false};
true; }, // child code
}, // condition [_rootActionID], // params
{ nil, // position
//////////////////////////////////////////////////////////////////////// 4, // distance
// create the flag category actions (with nested flag actions) [false, false, false, false, false], // other params
//////////////////////////////////////////////////////////////////////// nil // modifier function code
params ["_target", "_player", "_params"]; ] call ace_interact_menu_fnc_createAction;
_params params ["_rootActionID"];
private _vehicleFlagsCfg = call FUNC(getVehicleFlagsCfg); ////////////////////////////////////////////////////////////////////////
if (isNull _vehicleFlagsCfg) exitWith {[]}; // add root action to add flags
private _flagCategoryCfgs = (_vehicleFlagsCfg >> "FlagCategories") call BIS_fnc_returnChildren; ////////////////////////////////////////////////////////////////////////
[
_parentClass, // parent classname
0, // action 0 or self-action 1
["ACE_MainActions"], // parent
_flagRootAction, // action
true // apply to child classes
] call ace_interact_menu_fnc_addActionToClass;
// return category child actions with individual flag actions nested as children ////////////////////////////////////////////////////////////////////////
[_rootActionID, _flagCategoryCfgs] call FUNC(getActionsFlagCategories); // add action to remove flag under the root action
////////////////////////////////////////////////////////////////////////
// create action
private _removeFlagAction = [
_rootActionID + "_removeflag", // id
"Remove Flag", // displayed title
"\A3\ui_f\data\map\markers\flags\nato_ca.paa", // flag icon
{
params ["_target", "_player", "_params"];
_target forceFlagTexture "";
}, // statement
{
params ["_target", "_player", "_params"];
alive _target && getForcedFlagTexture _target != "";
}, // condition
nil // child code
] call ace_interact_menu_fnc_createAction;
}, // child code // add the action to the vehicle
[_rootActionID], // params // in this class event handler, this#0 will be the vehicle
nil, // position [
4, // distance _parentClass, // parent classname
[false, false, false, false, false], // other params 0, // action 0 or self-action 1
nil // modifier function code ["ACE_MainActions", _rootActionID], // parent
] call ace_interact_menu_fnc_createAction; _removeFlagAction, // action
true // apply to child classes
] call ace_interact_menu_fnc_addActionToClass;
////////////////////////////////////////////////////////////////////////
// add root action to add flags
////////////////////////////////////////////////////////////////////////
[
(_this select 0), // object
0, // action 0 or self-action 1
["ACE_MainActions"], // parent
_flagRootAction // action
] call ace_interact_menu_fnc_addActionToObject;
////////////////////////////////////////////////////////////////////////
// add action to remove flag under the root action
////////////////////////////////////////////////////////////////////////
// create action
private _removeFlagAction = [
_rootActionID + "_removeflag", // id
"Remove Flag", // displayed title
"\A3\ui_f\data\map\markers\flags\nato_ca.paa", // flag icon
{
params ["_target", "_player", "_params"];
_target forceFlagTexture "";
}, // statement
{
params ["_target", "_player", "_params"];
alive _target && getForcedFlagTexture _target != "";
}, // condition
nil // child code
] call ace_interact_menu_fnc_createAction;
// add the action to the vehicle
// in this class event handler, this#0 will be the vehicle
[
(_this select 0), // object
0, // action 0 or self-action 1
["ACE_MainActions", _rootActionID], // parent
_removeFlagAction // action
] call ace_interact_menu_fnc_addActionToObject;
}, true, [], true] call CBA_fnc_addClassEventHandler;
} forEach _baseClassesToApplyActionsFor; } forEach _baseClassesToApplyActionsFor;
nil; nil;