Replace selection dialog with interact children

This commit is contained in:
PabstMirror 2015-03-27 00:02:54 -05:00
parent efe57461b5
commit d03e474075
9 changed files with 92 additions and 100 deletions

View File

@ -4,9 +4,9 @@
class ACE_MainActions { \ class ACE_MainActions { \
class GVAR(AttachVehicle) { \ class GVAR(AttachVehicle) { \
displayName = "$STR_ACE_Attach_AttachDetach"; \ displayName = "$STR_ACE_Attach_AttachDetach"; \
condition = QUOTE(([ARR_2(_player, _target)] call FUNC(canAttach))); \ condition = QUOTE(_this call FUNC(canAttach)); \
statement = QUOTE( [ARR_2(_player, _target)] call FUNC(openAttachUI);); \ insertChildren = QUOTE(_this call FUNC(getChildrenAttachActions)); \
exceptions[] = {}; \ exceptions[] = {"isNotDragging"}; \
showDisabled = 0; \ showDisabled = 0; \
priority = 0; \ priority = 0; \
icon = PATHTOF(UI\attach_ca.paa); \ icon = PATHTOF(UI\attach_ca.paa); \
@ -14,9 +14,9 @@
}; \ }; \
class GVAR(DetachVehicle) { \ class GVAR(DetachVehicle) { \
displayName = "$STR_ACE_Attach_Detach"; \ displayName = "$STR_ACE_Attach_Detach"; \
condition = QUOTE(([ARR_2(_player, _target)] call FUNC(canDetach))); \ condition = QUOTE(_this call FUNC(canDetach)); \
statement = QUOTE( [ARR_2(_player, _target)] call FUNC(detach) ); \ statement = QUOTE(_this call FUNC(detach) ); \
exceptions[] = {}; \ exceptions[] = {"isNotDragging"}; \
showDisabled = 0; \ showDisabled = 0; \
priority = 0; \ priority = 0; \
icon = PATHTOF(UI\detach_ca.paa); \ icon = PATHTOF(UI\detach_ca.paa); \
@ -55,18 +55,18 @@ class CfgVehicles {
class ACE_Equipment { class ACE_Equipment {
class GVAR(Attach) { class GVAR(Attach) {
displayName = "$STR_ACE_Attach_AttachDetach"; displayName = "$STR_ACE_Attach_AttachDetach";
condition = QUOTE(([ARR_2(_player, _player)] call FUNC(canAttach))); condition = QUOTE(_this call FUNC(canAttach));
statement = QUOTE( [ARR_2(_player, _player)] call FUNC(openAttachUI); ); insertChildren = QUOTE(_this call FUNC(getChildrenAttachActions));
exceptions[] = {"isNotDragging"}; exceptions[] = {"isNotDragging"};
showDisabled = 0; showDisabled = 0;
priority = 5; priority = 5;
icon = PATHTOF(UI\attach_ca.paa); icon = PATHTOF(UI\attach_ca.paa);
hotkey = "T"; // hotkey = "T";
}; };
class GVAR(Detach) { class GVAR(Detach) {
displayName = "$STR_ACE_Attach_Detach"; displayName = "$STR_ACE_Attach_Detach";
condition = QUOTE(([ARR_2(_player, _player)] call FUNC(canDetach))); condition = QUOTE(_this call FUNC(canDetach));
statement = QUOTE( [ARR_2(_player, _player)] call FUNC(detach) ); statement = QUOTE(_this call FUNC(detach));
exceptions[] = {"isNotDragging"}; exceptions[] = {"isNotDragging"};
showDisabled = 0; showDisabled = 0;
priority = 5; priority = 5;

View File

@ -6,6 +6,7 @@ PREP(attach);
PREP(canAttach); PREP(canAttach);
PREP(canDetach); PREP(canDetach);
PREP(detach); PREP(detach);
PREP(getChildrenAttachActions);
PREP(openAttachUI); PREP(openAttachUI);
PREP(placeApprove); PREP(placeApprove);
PREP(placeCancel); PREP(placeCancel);

View File

@ -3,9 +3,9 @@
* Attach an item to the unit * Attach an item to the unit
* *
* Arguments: * Arguments:
* 0: unit doing the attach (player) <OBJECT> * 0: vehicle that it will be attached to (player or vehicle) <OBJECT>
* 1: vehicle that it will be attached to (player or vehicle) <OBJECT> * 1: unit doing the attach (player) <OBJECT>
* 2: Name of the attachable item <STRING> * 2: Array containing a string of the attachable item <ARRAY>
* *
* Return Value: * Return Value:
* Nothing * Nothing
@ -17,12 +17,14 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_3(_unit,_attachToVehicle,_itemName); PARAMS_3(_attachToVehicle,_unit,_args);
private ["_item", "_itemVehClass", "_onAtachText", "_selfAttachPosition"];
_itemName = [_args, 0, ""] call CBA_fnc_defaultParam;
//Sanity Check (_unit has item in inventory, not over attach limit) //Sanity Check (_unit has item in inventory, not over attach limit)
if !([_unit, _attachToVehicle, _itemName] call FUNC(canAttach)) exitWith {ERROR("Tried to attach, but check failed");}; if ((_itemName == "") || {!(_this call FUNC(canAttach))}) exitWith {ERROR("Tried to attach, but check failed");};
private ["_itemVehClass", "_onAtachText", "_selfAttachPosition"];
_itemVehClass = ""; _itemVehClass = "";
_onAtachText = ""; _onAtachText = "";

View File

@ -3,9 +3,9 @@
* Check if a unit can attach a specific item. * Check if a unit can attach a specific item.
* *
* Arguments: * Arguments:
* 0: unit doing the attach (player) <OBJECT> * 0: vehicle that it will be attached to (player or vehicle) <OBJECT>
* 1: vehicle that it will be attached to (player or vehicle) <OBJECT> * 1: unit doing the attach (player) <OBJECT>
* 2: Name of the attachable item <STRING><OPTIONAL> * 2: Array empty or containing a string of the attachable item <ARRAY>
* *
* Return Value: * Return Value:
* Boolean <BOOL> * Boolean <BOOL>
@ -17,12 +17,16 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_2(_unit,_attachToVehicle); PARAMS_3(_attachToVehicle,_player,_args);
DEFAULT_PARAM(2,_item,"");
private ["_attachLimit", "_attachedObjects"]; private ["_itemName", "_attachLimit", "_attachedObjects"];
_attachLimit = [10, 1] select (_unit == _attachToVehicle); _itemName = [_args, 0, ""] call CBA_fnc_defaultParam;
_attachLimit = [6, 1] select (_player == _attachToVehicle);
_attachedObjects = _attachToVehicle getVariable [QGVAR(Objects), []]; _attachedObjects = _attachToVehicle getVariable [QGVAR(Objects), []];
canStand _unit && {alive _attachToVehicle} && {count _attachedObjects < _attachLimit} && {_item in (itemsWithMagazines _unit + [""])} _ret = (canStand _player) && {alive _attachToVehicle} && {(count _attachedObjects) < _attachLimit} && {_itemName in ((itemsWithMagazines _player) + [""])};
systemChat format ["[%1] Checking = %2", _itemName, _ret ];
x = _this;
_ret

View File

@ -3,8 +3,8 @@
* Check if a unit has an item attached and if it can remove that item. * Check if a unit has an item attached and if it can remove that item.
* *
* Arguments: * Arguments:
* 0: unit doing the detaching (player) <STRING> * 0: vehicle that it will be detached from (player or vehicle) <OBJECT>
* 1: vehicle that it will be detached from (player or vehicle) <OBJECT> * 1: unit doing the detaching (player) <OBJECT>
* *
* Return Value: * Return Value:
* Boolean <BOOL> * Boolean <BOOL>
@ -16,7 +16,7 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_2(_unit,_attachToVehicle); PARAMS_2(_attachToVehicle,_unit);
private ["_attachedObjects", "_inRange"]; private ["_attachedObjects", "_inRange"];

View File

@ -3,20 +3,20 @@
* Detach an item from a unit * Detach an item from a unit
* *
* Arguments: * Arguments:
* 0: unit doing the attaching (player) <STRING> * 0: vehicle that it will be detached from (player or vehicle) <OBJECT>
* 1: vehicle that it will be detached from (player or vehicle) <OBJECT> * 1: unit doing the detaching (player) <OBJECT>
* *
* Return Value: * Return Value:
* Nothing * Nothing
* *
* Example: * Example:
* Nothing * [car, bob] call ace_attach_fnc_detach
* *
* Public: No * Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_2(_unit,_attachToVehicle); PARAMS_2(_attachToVehicle,_unit);
private ["_attachedObjects", "_attachedItems"]; private ["_attachedObjects", "_attachedItems"];

View File

@ -0,0 +1,51 @@
/*
* Author: Garth de Wet (LH), PabstMirror
* Show the ammo counts for a static weapon.
* Called from "insertChildren" on interact_menu
*
* Argument:
* 0: Target <OBJECT>
* 1: Player <OBJECT>
*
* Return value:
* ChildActiosn<ARRAY>
*
* Example:
* [player, player] call ace_attach_fnc_getChildrenAttachActions
*
* Public: No
*/
#include "script_component.hpp"
PARAMS_2(_target,_player);
_listed = [];
_actions = [];
{
if !(_x in _listed) then {
_listed pushBack _x;
_item = ConfigFile >> "CfgMagazines" >> _x;
if (getNumber (_item >> "ACE_Attachable") == 1) then {
_displayName = getText(_item >> "displayName");
_picture = getText(_item >> "picture");
_action = [_x, _displayName, _picture, {_this call FUNC(attach)}, {_this call FUNC(canAttach)}, {}, [_x]] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _target];
};
};
} forEach (magazines _player);
{
if !(_x in _listed) then {
_listed pushBack _x;
_item = ConfigFile >> "CfgWeapons" >> _x;
if (getNumber (_item >> "ACE_Attachable") == 1) then {
_displayName = getText(_item >> "displayName");
_picture = getText(_item >> "picture");
_action = [_x, _displayName, _picture, {_this call FUNC(attach)}, {_this call FUNC(canAttach)}, {}, _x] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _target];
};
};
} forEach (items _player);
_actions

View File

@ -1,66 +0,0 @@
/*
* Author: Garth de Wet (LH)
* Opens the UI for attaching objects.
*
* Arguments:
* 0: unit <STRING>
* 1: target <OBJECT>
*
* Return Value:
* Nothing
*
* Example:
* Nothing
*
* Public: No
*/
#include "script_component.hpp"
private ["_actions", "_attachables", "_item"];
PARAMS_2(_unit,_target);
GVAR(attachTarget) = _target;
_listed = [];
_attachables = magazines _unit;
_actions = [localize "STR_ACE_Attach_AttachDetach", localize "STR_ACE_Attach_Attach"] call EFUNC(interaction,prepareSelectMenu);
{
if !(_x in _listed) then {
_item = ConfigFile >> "CfgMagazines" >> _x;
if (getNumber (_item >> "ACE_Attachable") == 1) then {
_actions = [
_actions,
getText(_item >> "displayName"),
getText(_item >> "picture"),
_x
] call EFUNC(interaction,addSelectableItem);
};
_listed pushBack _x;
};
} forEach _attachables;
_attachables = items _unit;
{
if !(_x in _listed) then {
_item = ConfigFile >> "CfgWeapons" >> _x;
if (getNumber (_item >> "ACE_Attachable") == 1) then {
_actions = [
_actions,
getText(_item >> "displayName"),
getText(_item >> "picture"),
_x
] call EFUNC(interaction,addSelectableItem);
};
_listed pushBack _x;
};
} forEach _attachables;
[
_actions,
{
[ACE_player, GVAR(attachTarget), _this] call FUNC(attach);
call EFUNC(interaction,hideMenu);
},
{
call EFUNC(interaction,hideMenu);
}
] call EFUNC(interaction,openSelectMenu);

View File

@ -92,7 +92,7 @@ _closeInDistance = (_closeInMax + _closeInMin) / 2;
deleteVehicle _setupObject; deleteVehicle _setupObject;
//Checks //Checks
if (((_startDistanceFromCenter - _closeInDistance) < 0.1) || {!([_placer,_attachToVehicle,_itemClassname] call FUNC(canAttach))}) exitWith { if (((_startDistanceFromCenter - _closeInDistance) < 0.1) || {!([_attachToVehicle, _placer, _itemClassname] call FUNC(canAttach))}) exitWith {
TRACE_2("no valid spot found",_closeInDistance,_startDistanceFromCenter); TRACE_2("no valid spot found",_closeInDistance,_startDistanceFromCenter);
[localize "STR_ACE_Attach_Failed"] call EFUNC(common,displayTextStructured); [localize "STR_ACE_Attach_Failed"] call EFUNC(common,displayTextStructured);
}; };