From 84f404ae8467c2b118cef92e46503a2e4bb2ce40 Mon Sep 17 00:00:00 2001 From: Nou Date: Sun, 18 Jan 2015 20:08:34 -0800 Subject: [PATCH] Remove debug, added scripted add/remove actions. --- addons/interact_menu/XEH_preInit.sqf | 4 ++ .../interact_menu/functions/fnc_addAction.sqf | 51 +++++++++++++++++++ .../functions/fnc_compileMenu.sqf | 17 ++++--- addons/interact_menu/functions/fnc_probe.sqf | 2 +- .../functions/fnc_removeAction.sqf | 51 +++++++++++++++++++ .../functions/fnc_renderMenu.sqf | 7 ++- 6 files changed, 120 insertions(+), 12 deletions(-) create mode 100644 addons/interact_menu/functions/fnc_addAction.sqf create mode 100644 addons/interact_menu/functions/fnc_removeAction.sqf diff --git a/addons/interact_menu/XEH_preInit.sqf b/addons/interact_menu/XEH_preInit.sqf index 0f86582531..2c6d32d4de 100644 --- a/addons/interact_menu/XEH_preInit.sqf +++ b/addons/interact_menu/XEH_preInit.sqf @@ -12,6 +12,8 @@ PREP(rotateVectLine); PREP(keyDown); PREP(keyUp); PREP(compileMenu); +PREP(addAction); +PREP(removeAction); GVAR(toRender) = []; @@ -46,4 +48,6 @@ GVAR(iconCount) = 0; GVAR(objectActionsHash) = HASH_CREATE; +GVAR(uidCounter) = 0; + ADDON = true; \ No newline at end of file diff --git a/addons/interact_menu/functions/fnc_addAction.sqf b/addons/interact_menu/functions/fnc_addAction.sqf new file mode 100644 index 0000000000..3e07618bf0 --- /dev/null +++ b/addons/interact_menu/functions/fnc_addAction.sqf @@ -0,0 +1,51 @@ +/* + * Author: commy2 + * + * Add an ACE action to an object. Note: This function is NOT global. + * + * Argument: + * 0: Object the action should be assigned to (Object) + * 1: Name of the action shown in the menu (String) + * 2: Icon (String) + * 3: Position (Position or Selection Name) + * 4: Statement (Code) + * 5: Condition (Code) + * 6: Distance (Number) + * + * Return value: + * The entry array, which can be used to remove the entry, or add children entries. + */ +#include "script_component.hpp" + +private ["_object", "_displayName", "_icon", "_position", "_statement", "_condition", "_distance", "_actions", "_entry"]; +_object = _this select 0; +_displayName = _this select 1; +_icon = _this select 2; +_position = _this select 3; +_statement = _this select 4; +_condition = _this select 5; +_distance = _this select 6; + +_actions = []; +if(IS_OBJECT(_object)) then { + _actions = _object getVariable [QUOTE(GVAR(actionData)), []]; +} else { + if(IS_ARRAY(_object)) then { + _actions = _object select 6; + }; +}; + +_entry = [ + _displayName, + _icon, + _position, + _statement, + _condition, + _distance, + [], + GVAR(uidCounter) + ]; +GVAR(uidCounter) = GVAR(uidCounter) + 1; +_actions pushBack _entry; + +_entry; \ No newline at end of file diff --git a/addons/interact_menu/functions/fnc_compileMenu.sqf b/addons/interact_menu/functions/fnc_compileMenu.sqf index 36845eb9ee..d921dfabeb 100644 --- a/addons/interact_menu/functions/fnc_compileMenu.sqf +++ b/addons/interact_menu/functions/fnc_compileMenu.sqf @@ -1,6 +1,6 @@ //fnc_compileMenu.sqf #include "script_component.hpp"; -diag_log text format["COMPILE ACTIONS: %1", _this]; +// diag_log text format["COMPILE ACTIONS: %1", _this]; _object = _this select 0; _objectType = typeOf _object; @@ -55,7 +55,7 @@ _recurseFnc = { _enableInside = getNumber (_entryCfg >> "enableInside"); _condition = compile _condition; - diag_log text format["_condition: %1", _condition]; + // diag_log text format["_condition: %1", _condition]; _children = []; if(isArray (_entryCfg >> "subMenu")) then { _subMenuDef = getArray (_entryCfg >> "subMenu"); @@ -70,9 +70,10 @@ _recurseFnc = { _statement, _condition, _distance, - _children + _children, + GVAR(uidCounter) ]; - + GVAR(uidCounter) = GVAR(uidCounter) + 1; _actions pushBack _entry; }; }; @@ -88,8 +89,10 @@ _actions = [[ { true }, { true }, 5, - _actions -]]; - + _actions, + GVAR(uidCounter) +] +]; +GVAR(uidCounter) = GVAR(uidCounter) + 1; _object setVariable [QUOTE(GVAR(actionData)), _actions]; \ No newline at end of file diff --git a/addons/interact_menu/functions/fnc_probe.sqf b/addons/interact_menu/functions/fnc_probe.sqf index ef4c5787bb..1f178180be 100644 --- a/addons/interact_menu/functions/fnc_probe.sqf +++ b/addons/interact_menu/functions/fnc_probe.sqf @@ -18,7 +18,7 @@ if(!GVAR(keyDown)) then { _target = _actionObject; _player = ACE_player; _active = [_target, ACE_player] call (_actionItem select 4); - player sideChat format["_active: %1 %2", _actionItem select 0, _active]; + // player sideChat format["_active: %1 %2", _actionItem select 0, _active]; if(_active) then { _renderItem = +_actionItem; _renderItem set[4, true]; diff --git a/addons/interact_menu/functions/fnc_removeAction.sqf b/addons/interact_menu/functions/fnc_removeAction.sqf new file mode 100644 index 0000000000..2362cb424f --- /dev/null +++ b/addons/interact_menu/functions/fnc_removeAction.sqf @@ -0,0 +1,51 @@ +/* + * Author: commy2 + * + * Add an ACE action to an object. Note: This function is global. + * + * Argument: + * 0: Object the action should be assigned to (Object) + * 1: Entry to remove (Array or Number) + * + * Return value: + * ID of the action (used to remove it later). + */ + +#include "script_component.hpp" +_object = _this select 0; +_entry = _this select 1; + + + + + +if(!IS_OBJECT(_object)) exitWith {false}; + +_actions = _object getVariable [QUOTE(GVAR(actionData)), []]; +if(IS_ARRAY(_entry)) then { + _entry = _entry select 7; +}; + +_found = false; +_searchFnc = { + private ["_actions", "_entry"]; + _actions = _this select 0; + _entry = _this select 1; + { + if((_x select 7) == _entry) then { + _actions set[_forEachIndex, "aceactiondelete"]; + _actions = _actions - ["aceactiondelete"]; + _found = true; + } else { + if(!_found && {count (_x select 6) > 0}) then { + _childActions = [(_x select 6), _entry] call _searchFnc; + _x set[6, _childActions]; + }; + }; + } forEach _actions; + _actions; +}; +_actions = [_actions, _entry] call _searchFnc; +_object setVariable [QUOTE(GVAR(actionData)), _actions]; + +_found; \ No newline at end of file diff --git a/addons/interact_menu/functions/fnc_renderMenu.sqf b/addons/interact_menu/functions/fnc_renderMenu.sqf index 2ab17e0140..761fe3f5f1 100644 --- a/addons/interact_menu/functions/fnc_renderMenu.sqf +++ b/addons/interact_menu/functions/fnc_renderMenu.sqf @@ -37,14 +37,13 @@ if(_cursorScreenPos distance _pos <= _distance) then { _currentRenderDepth = GVAR(renderDepth); GVAR(renderDepth) = GVAR(renderDepth) + 1; if(_index == (GVAR(menuDepthPath) select (GVAR(renderDepth)-1))) then { - _radialOffset = 0; - { + _radialOffset = 0; + { // if(_index != (GVAR(menuDepthPath) select (GVAR(renderDepth)))) then { this = _object; _target = _object; _player = ACE_player; _active = [_object, ACE_player] call (_x select 4); - diag_log text format["_active: %1: %2", (_x select 0), _active]; if(_active) then { _offset = [GVAR(vecLineMap), (270*(GVAR(renderDepth)%2))-(_radialOffset*45)] call FUNC(rotateVectLine); _newPos = [ @@ -57,7 +56,7 @@ if(_cursorScreenPos distance _pos <= _distance) then { _radialOffset = _radialOffset + 1; }; // }; - } forEach (_actionData select 6); + } forEach (_actionData select 6); }; GVAR(renderDepth) = GVAR(renderDepth) - 1; };