Files
MissionTemplate/functions/vehicleFlags/fn_initVehicleFlags.sqf
2024-02-03 20:59:51 -08:00

113 lines
4.3 KiB
Plaintext

if (!hasInterface) exitWith {};
private _vehicleFlagsCfg = call milsim_vehicleFlags_fnc_getVehicleFlagsCfg;
if (!isClass _vehicleFlagsCfg) exitWith {
["WARNING: Vehicle Flags: Vehicle Flags config not found. Vehicle Flags will not be available."] call BIS_fnc_error;
};
// get texture pbo class
private _texturePboName = getText(_vehicleFlagsCfg >> "texturePBOName");
if (_texturePboName == "") exitWith {
["WARNING: Vehicle Flags: Texture PBO definition is missing or a blank string! Vehicle Flags will not be available."] call BIS_fnc_error;
};
if (!isClass (configFile >> "CfgPatches" >> _texturePboName)) exitWith {
[
"WARNING: Vehicle Flags: Texture PBO not found (%1). Vehicle Flags will not be available.",
_texturePboName
] call BIS_fnc_error;
};
private _baseClassesToApplyActionsFor =
(_vehicleFlagsCfg >> "baseClassesToApplyActionsFor") call BIS_fnc_getCfgDataArray;
private _flagCategoryCfgs = (_vehicleFlagsCfg >> "FlagCategories") call BIS_fnc_returnChildren;
{ // forEach _baseClassesToApplyActionsFor
private _parentClass = _x;
////////////////////////////////////////////////////////////////////////
// add CBA class event handler to add actions to vehicles after they are initialized
// 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", {
////////////////////////////////////////////////////////////////////////
// create the root action
////////////////////////////////////////////////////////////////////////
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
private _excluded = [typeOf _target] call milsim_vehicleFlags_fnc_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", "_flagCategoryCfgs"];
// return category child actions with individual flag actions nested as children
[_rootActionID, _flagCategoryCfgs] call milsim_vehicleFlags_fnc_getActionsFlagCategories;
}, // child code
[_rootActionID, _flagCategoryCfgs], // params
nil, // position
4, // distance
[false, false, false, false, false], // other params
nil // modifier function code
] call ace_interact_menu_fnc_createAction;
////////////////////////////////////////////////////////////////////////
// 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 = [
_flagRootAction + "_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", _flagActionID], // parent
_removeFlagAction // action
] call ace_interact_menu_fnc_addActionToObject;
}, true, [], true] call CBA_fnc_addClassEventHandler;
} forEach _baseClassesToApplyActionsFor;
nil;