Skip to content
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

Always make sure ACE_MainActions exists #1986

Merged
merged 3 commits into from
Aug 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/interact_menu/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ADDON = false;

PREP(addActionToClass);
PREP(addActionToObject);
PREP(addMainAction);
PREP(compileMenu);
PREP(compileMenuSelfAction);
PREP(compileMenuZeus);
Expand Down
9 changes: 8 additions & 1 deletion addons/interact_menu/functions/fnc_addActionToClass.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,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,[]];
Expand Down
4 changes: 4 additions & 0 deletions addons/interact_menu/functions/fnc_addActionToObject.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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];

Expand Down
31 changes: 31 additions & 0 deletions addons/interact_menu/functions/fnc_addMainAction.sqf
Original file line number Diff line number Diff line change
@@ -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);
};
2 changes: 1 addition & 1 deletion addons/interact_menu/functions/fnc_findActionNode.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 0 additions & 9 deletions addons/slideshow/functions/fnc_createSlideshow.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down