From fc82018c49dcf14cfa07c15aef302966498c084c Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 18 Sep 2015 08:23:18 +0200 Subject: [PATCH] more common cleanup --- .../functions/fnc_addActionEventHandler.sqf | 73 ++++++++----------- .../fnc_addActionMenuEventHandler.sqf | 59 ++++++++------- .../fnc_addCanInteractWithCondition.sqf | 24 +++--- .../fnc_addCuratorUnloadEventhandler.sqf | 16 +++- 4 files changed, 83 insertions(+), 89 deletions(-) diff --git a/addons/common/functions/fnc_addActionEventHandler.sqf b/addons/common/functions/fnc_addActionEventHandler.sqf index 29b058487b..d9946207f8 100644 --- a/addons/common/functions/fnc_addActionEventHandler.sqf +++ b/addons/common/functions/fnc_addActionEventHandler.sqf @@ -1,73 +1,64 @@ /* * Author: commy2 - * * Add an addAction event to a unit. Used to handle multiple addAction events. Global arguments, local effects. Does only work for player controlled units. * - * Argument: - * 0: Unit the action should be assigned to (Object) - * 1: Name of the action, e.g. "DefaultAction" (String) - * 2: Condition (Code or String) - * 3: Code to execute (Code or String) + * Arguments: + * 0: Unit the action should be assigned to + * 1: Name of the action, e.g. "DefaultAction" + * 2: Condition + * 3: Code to execute * - * Return value: - * ID of the action (used to remove it later). + * Return Value: + * ID of the action (used to remove it later) */ #include "script_component.hpp" -private ["_unit", "_action", "_condition", "_statement", "_name", "_actionsVar", "_actionID", "_actions", "_id", "_actionIDs"]; -//IGNORE_PRIVATE_WARNING("_count", "_index", "_return", "_target"); - -_unit = _this select 0; -_action = _this select 1; -_condition = _this select 2; -_statement = _this select 3; +params ["_unit", "_action", "_condition", "_statement"]; if (typeName _condition == "STRING") then { - _condition = compile _condition; + _condition = compile _condition; }; if (typeName _statement == "STRING") then { - _statement = compile _statement; + _statement = compile _statement; }; -_name = format ["ACE_Action_%1", _action]; +private ["_name", "_actionsVar"]; +_name = format ["ACE_Action_%1", _action]; _actionsVar = _unit getVariable [_name, [-1, [-1, [], []], objNull]]; if (_unit != _actionsVar select 2) then { // check if the unit is still valid, fixes respawn issues - _actionsVar = [-1, [-1, [], []], objNull]; + _actionsVar = [-1, [-1, [], []], objNull]; }; -_actionID = _actionsVar select 0; -_actions = _actionsVar select 1; +_actionsVar params ["_actionID", "_actionsArray"]; +_actionsArray params ["_id", "_actionIDs", "_actions"]; -_id = (_actions select 0) + 1; -_actionIDs = _actions select 1; -_actions = _actions select 2; +_id = _id + 1; _actionIDs pushBack _id; _actions pushBack [_condition, _statement]; // first action to add, unit needs addAction command if (_actionID == -1) then { - private "_addAction"; + private "_addAction"; + _addAction = call compile format [ + "[ + '', + {if (inputAction '%1' == 0) exitWith {}; {if (_this call (_x select 0)) then {_this call (_x select 1)}} forEach (((_this select 0) getVariable '%2') select 1 select 2)}, + nil, + -1, + false, + true, + '%1', + ""if (_this != ACE_player || {vehicle _this != _target}) exitWith {false}; _actions = (_this getVariable '%2') select 1 select 2; _count = count _actions; _index = 0; _return = false; while {_index < _count && {!_return}} do {_return = [_target, _this] call ((_actions select _index) select 0); _index = _index + 1}; _return"" + ]", + _action, + _name + ]; - _addAction = call compile format [ - "[ - '', - {if (inputAction '%1' == 0) exitWith {}; {if (_this call (_x select 0)) then {_this call (_x select 1)}} forEach (((_this select 0) getVariable '%2') select 1 select 2)}, - nil, - -1, - false, - true, - '%1', - ""if (_this != ACE_player || {vehicle _this != _target}) exitWith {false}; _actions = (_this getVariable '%2') select 1 select 2; _count = count _actions; _index = 0; _return = false; while {_index < _count && {!_return}} do {_return = [_target, _this] call ((_actions select _index) select 0); _index = _index + 1}; _return"" - ]", - _action, - _name - ]; - - _actionID = _unit addAction _addAction; + _actionID = _unit addAction _addAction; }; _unit setVariable [_name, [_actionID, [_id, _actionIDs, _actions], _unit], false]; diff --git a/addons/common/functions/fnc_addActionMenuEventHandler.sqf b/addons/common/functions/fnc_addActionMenuEventHandler.sqf index 268cc18d5a..9c7a63fb86 100644 --- a/addons/common/functions/fnc_addActionMenuEventHandler.sqf +++ b/addons/common/functions/fnc_addActionMenuEventHandler.sqf @@ -1,29 +1,25 @@ /* * Author: commy2 - * * Add an addAction event to a unit. Used to handle multiple addAction events and add a action to the mouse wheel menu. Global arguments, local effects. Does only work for player controlled units. * - * Argument: - * 0: Unit the action should be assigned to (Object) - * 1: Menu title of the action (String) - * 2: Name of the action, e.g. "DefaultAction" (String) - * 3: Condition (Code or String) - * 4: Code to execute by the action (Code or String) - * 5: Condition for the menu action (Code or String) - * 6: Code to execute from the menu (Code or String) - * 7: Priority of the action (Number, optional default: 0) + * Arguments: + * 0: Unit the action should be assigned to + * 1: Menu title of the action + * 2: Name of the action, e.g. "DefaultAction" + * 3: Condition + * 4: Code to execute by the action + * 5: Condition for the menu action + * 6: Code to execute from the menu + * 7: Priority of the action (default: 0) * - * Return value: - * ID of the action (used to remove it later). + * Return Value: + * ID of the action (used to remove it later) + * + * Public: No */ #include "script_component.hpp" -private ["_name", "_actionsVar", "_id", "_actionIDs", "_actions", "_nameVar", "_addAction", "_actionID"]; -//IGNORE_PRIVATE_WARNING("_target"); - -PARAMS_8(_unit,_displayName,_action,_condition,_statement,_condition2,_statement2,_priority); - -if (isNil "_priority") then {_priority = 0}; +params ["_unit", "_displayName", "_action", "_condition", "_statement", "_condition2", "_statement2", ["_priority", 0]]; if (typeName _condition == "STRING") then { _condition = compile _condition; @@ -41,13 +37,16 @@ if (typeName _statement2 == "STRING") then { _statement2 = compile _statement2; }; -_name = format ["ACE_ActionMenu_%1", _action]; +private ["_name", "_actionsVar"]; +_name = format ["ACE_ActionMenu_%1", _action]; _actionsVar = _unit getVariable [_name, [-1, [], []]]; -_id = (_actionsVar select 0) + 1; -_actionIDs = _actionsVar select 1; -_actions = _actionsVar select 2; +_actionsVar params ["_id", "_actionIDs", "_actions"]; + +_id = _id + 1; + +private ["_nameVar", "_addAction", "_actionID"]; _nameVar = format ["%1_ID%2", _name, _id]; missionNamespace setVariable [_nameVar, [_condition, _statement, _condition2, _statement2]]; @@ -56,14 +55,14 @@ _actionIDs pushBack _id; _addAction = call compile format [ "[ - '%2', - {if (inputAction '%1' == 0) then {if (_this call (%3 select 2)) then {_this call (%3 select 3)}} else {_this call (%3 select 1)}}, - nil, - %4, - false, - true, - '%1', - ""if (_this != ACE_player || {vehicle _this != _target}) exitWith {false}; [_target, _this] call (%3 select 0)"" + '%2', + {if (inputAction '%1' == 0) then {if (_this call (%3 select 2)) then {_this call (%3 select 3)}} else {_this call (%3 select 1)}}, + nil, + %4, + false, + true, + '%1', + ""if (_this != ACE_player || {vehicle _this != _target}) exitWith {false}; [_target, _this] call (%3 select 0)"" ]", _action, _displayName, diff --git a/addons/common/functions/fnc_addCanInteractWithCondition.sqf b/addons/common/functions/fnc_addCanInteractWithCondition.sqf index 10ea084858..11213accd6 100644 --- a/addons/common/functions/fnc_addCanInteractWithCondition.sqf +++ b/addons/common/functions/fnc_addCanInteractWithCondition.sqf @@ -1,31 +1,25 @@ /* * Author: commy2 - * * Add a condition that gets checked by ace_common_fnc_canInteractWith. * * Arguments: - * 0: The conditions id. Used to remove later or as exception name. An already existing name overwrites. (String) - * 1: The condition to check. format of "_this" is "[_player, _target]". (Code) + * 0: The conditions id. Used to remove later or as exception name. An already existing name overwrites. + * 1: The condition to check. format of "_this" is "[_player, _target]". * * Return Value: - * Unit can interact? + * None * + * Public: No */ #include "script_component.hpp" -private ["_conditionName", "_conditionFunc"]; -//IGNORE_PRIVATE_WARNING("_player", "_target"); +params ["_conditionName", "_conditionFunc"]; +_conditionName = toLower _conditionName; -_conditionName = toLower (_this select 0); -_conditionFunc = _this select 1; - -private ["_conditions", "_conditionNames", "_conditionFuncs"]; - +private "_conditions"; _conditions = missionNamespace getVariable [QGVAR(InteractionConditions), [[],[]]]; - -_conditionNames = _conditions select 0; -_conditionFuncs = _conditions select 1; +_conditions params ["_conditionNames", "_conditionFuncs"]; private "_index"; _index = _conditionNames find _conditionName; @@ -37,4 +31,4 @@ if (_index == -1) then { _conditionNames set [_index, _conditionName]; _conditionFuncs set [_index, _conditionFunc]; -GVAR(InteractionConditions) = [_conditionNames, _conditionFuncs]; +GVAR(InteractionConditions) = _conditions; diff --git a/addons/common/functions/fnc_addCuratorUnloadEventhandler.sqf b/addons/common/functions/fnc_addCuratorUnloadEventhandler.sqf index 4623bb4ddb..95cce02e41 100644 --- a/addons/common/functions/fnc_addCuratorUnloadEventhandler.sqf +++ b/addons/common/functions/fnc_addCuratorUnloadEventhandler.sqf @@ -1,9 +1,19 @@ -// by commy2 +/* + * Author: commy2 + * + * Arguments: + * Display where the Unload event was added + * + * Return Value: + * None + * + * Public: No + */ #include "script_component.hpp" -private "_dlg"; - disableSerialization; + +private "_dlg"; _dlg = ctrlParent _this; _dlg displayAddEventHandler ["unload", {