Merge pull request #1986 from acemod/addMainAction

Always make sure ACE_MainActions exists
This commit is contained in:
PabstMirror 2015-08-14 19:48:04 -05:00
commit 253fb6e66a
6 changed files with 45 additions and 11 deletions

View File

@ -4,6 +4,7 @@ ADDON = false;
PREP(addActionToClass);
PREP(addActionToObject);
PREP(addMainAction);
PREP(compileMenu);
PREP(compileMenuSelfAction);
PREP(compileMenuZeus);

View File

@ -37,8 +37,15 @@ if((count _actionTrees) == 0) then {
missionNamespace setVariable [_varName, _actionTrees];
};
if (_parentPath isEqualTo ["ACE_MainActions"]) then {
[_objectType, _typeNum] call FUNC(addMainAction);
};
_parentNode = [_actionTrees, _parentPath] call FUNC(findActionNode);
if (isNil {_parentNode}) exitWith {};
if (isNil {_parentNode}) exitWith {
ERROR("Failed to add action");
diag_log text format ["action (%1) to parent %2 on object %3 [%4]", (_action select 0), _parentPath, _objectType, _typeNum];
};
// Add action node as children of the correct node of action tree
(_parentNode select 1) pushBack [_action,[]];

View File

@ -30,6 +30,10 @@ if((count _actionList) == 0) then {
_object setVariable [_varName, _actionList];
};
if (_parentPath isEqualTo ["ACE_MainActions"]) then {
[(typeOf _object), _typeNum] call FUNC(addMainAction);
};
// Add action and parent path to the list of object actions
_actionList pushBack [_action, +_parentPath];

View File

@ -0,0 +1,31 @@
/*
* Author: Jonpas, PabstMirror
* Makes sure there is a ACE_MainActions on the object type
*
* Argument:
* 0: Object classname <STRING>
* 1: Type of action, 0 for actions, 1 for self-actions <NUMBER>
*
* Return value:
* None
*
* Example:
* ["Table", 0] call ace_interact_menu_fnc_addMainAction;
*
* Public: No
*/
#include "script_component.hpp"
params ["_objectType", "_typeNum"];
private["_actionTrees", "_mainAction", "_parentNode", "_varName"];
_varName = format [[QGVAR(Act_%1), QGVAR(SelfAct_%1)] select _typeNum, _objectType];
_actionTrees = missionNamespace getVariable [_varName, []];
_parentNode = [_actionTrees, ["ACE_MainActions"]] call FUNC(findActionNode);
if (isNil {_parentNode}) then {
TRACE_2("No Main Action on object", _objectType, _typeNum);
_mainAction = ["ACE_MainActions", localize ELSTRING(interaction,MainAction), "", {}, {true}] call FUNC(createAction);
[_objectType, _typeNum, [], _mainAction] call EFUNC(interact_menu,addActionToClass);
};

View File

@ -8,7 +8,7 @@
* 1: Path <ARRAY>
*
* Return value:
* Action node <ARRAY>.
* Action node <ARRAY> or <NIL> if not found
*
* Example:
* [_actionTree, ["ACE_TapShoulderRight","VulcanPinchAction"]] call ace_interact_menu_fnc_findActionNode;

View File

@ -62,15 +62,6 @@ if !(["ace_interact_menu"] call EFUNC(common,isModLoaded)) then {
// Add interactions if automatic transitions are disabled, else setup automatic transitions
if (_duration == 0) then {
{
// Add MainAction if one does not already exist
_actionsObject = _x getVariable [QEGVAR(interact_menu,actions), []];
_actionsClass = missionNamespace getVariable [format [QEGVAR(interact_menu,Act_%1), typeOf _x], []];
if (count _actionsObject == 0 && {count _actionsClass == 0}) then {
_mainAction = ["ACE_MainActions", localize ELSTRING(interaction,MainAction), "", {}, {true}] call EFUNC(interact_menu,createAction);
[_x, 0, [], _mainAction] call EFUNC(interact_menu,addActionToObject);
TRACE_2("Adding ACE_MainActions",_actionsObject,_actionsClass);
};
// Add Slides sub-action and populate with images
_slidesAction = [QGVAR(Slides), localize LSTRING(Interaction), "", {}, {true}, {(_this select 2) call FUNC(addSlideActions)}, [_objects,_images,_names,_x,_currentSlideshow], [0,0,0], 2] call EFUNC(interact_menu,createAction);
[_x, 0, ["ACE_MainActions"], _slidesAction] call EFUNC(interact_menu,addActionToObject);