From be68948629a6cd6f397db217627a4d908b1f7ca0 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Thu, 25 Jul 2024 11:10:39 +0200 Subject: [PATCH 1/6] Improve swtichWeaponAttachment --- .../functions/fnc_switchWeaponAttachment.sqf | 54 ++++++++++++++----- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/addons/interaction/functions/fnc_switchWeaponAttachment.sqf b/addons/interaction/functions/fnc_switchWeaponAttachment.sqf index aaefb3315ed..258dd697210 100644 --- a/addons/interaction/functions/fnc_switchWeaponAttachment.sqf +++ b/addons/interaction/functions/fnc_switchWeaponAttachment.sqf @@ -4,8 +4,8 @@ * Switches weapon attachment. * * Arguments: - * 0: Target - * 1: Player (not used) + * 0: Target (not used) + * 1: Player * 2: Action params * * Return Value: @@ -17,11 +17,19 @@ * Public: No */ -params ["_unit", "", "_actionParams"]; +params ["", "_unit", "_actionParams"]; _actionParams params ["_weapon", "_newAttachment", "_oldAttachment"]; TRACE_3("Switching attachment",_weapon,_newAttachment,_oldAttachment); -[_unit, "Gear"] call EFUNC(common,doGesture); +private _currWeaponType = switch (_weapon) do { + case (""): {-1}; + case (primaryWeapon _unit): {0}; + case (handgunWeapon _unit): {1}; + case (secondaryWeapon _unit): {2}; + default {-1}; +}; + +if (_currWeaponType == -1) exitWith {}; private _addNew = _newAttachment isNotEqualTo ""; private _removeOld = _oldAttachment isNotEqualTo ""; @@ -38,22 +46,42 @@ if (_removeOld && {!([_unit, _oldAttachment] call CBA_fnc_canAddItem)}) exitWith }; }; +[_unit, "Gear"] call EFUNC(common,doGesture); + if (_removeOld) then { [{ - params ["_unit", "_weapon", "_oldAttachment"]; - switch (_weapon) do { - case (primaryWeapon _unit): {_unit removePrimaryWeaponItem _oldAttachment;}; - case (handgunWeapon _unit): {_unit removeHandgunItem _oldAttachment;}; - default {_unit removeSecondaryWeaponItem _oldAttachment;}; + params ["_unit", "_oldAttachment", "", "_currWeaponType"]; + + switch (_currWeaponType) do { + case 0: {_unit removePrimaryWeaponItem _oldAttachment}; + case 1: {_unit removeHandgunItem _oldAttachment}; + case 2: {_unit removeSecondaryWeaponItem _oldAttachment}; + default {}; }; + _unit addItem _oldAttachment; - }, [_unit, _weapon, _oldAttachment], 0.3] call CBA_fnc_waitAndExecute; + + // If adding a new item, let that code handle raising EH + // Delete addNew from array, to be able to pass _this to EH + if (_this deleteAt 4) exitWith {}; + + ["CBA_attachmentSwitched", _this] call CBA_fnc_localEvent; + }, [_unit, _oldAttachment, _newAttachment, _currWeaponType, _addNew], 0.3] call CBA_fnc_waitAndExecute; }; if (!_addNew) exitWith {}; [{ - params ["_unit", "_weapon", "_newAttachment"]; - _unit addWeaponItem [_weapon, _newAttachment]; + params ["_unit", "", "_newAttachment"]; + + // Delete weapon from array, to be able to pass _this to EH + _unit addWeaponItem [_this deleteAt 4, _newAttachment]; + [[getText (configFile >> "CfgWeapons" >> _newAttachment >> "picture"), 4], true] call CBA_fnc_notify; -}, [_unit, _weapon, _newAttachment], 1] call CBA_fnc_waitAndExecute; + + if (_unit == ACE_player) then { + playSound "click"; + }; + + ["CBA_attachmentSwitched", _this] call CBA_fnc_localEvent; +}, [_unit, _oldAttachment, _newAttachment, _currWeaponType, _weapon], 1] call CBA_fnc_waitAndExecute; From b1f6b7b106d89560b1a9e2ed8c9326e3bafcde31 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Thu, 8 Aug 2024 21:18:28 -0500 Subject: [PATCH 2/6] change interact_SWA to use common_SAM (#10176) * change interact_SWA to use common_SAM * Directly call * exit on bad arg * Update fnc_switchAttachmentMode.sqf * Minor optimisations * Cleanup leftover code, use unit instead of target --------- Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com> --- .../functions/fnc_switchAttachmentMode.sqf | 36 ++++++++++++------- .../fnc_getWeaponAttachmentsActions.sqf | 10 ++++-- .../functions/fnc_switchWeaponAttachment.sqf | 33 ++++++----------- 3 files changed, 42 insertions(+), 37 deletions(-) diff --git a/addons/common/functions/fnc_switchAttachmentMode.sqf b/addons/common/functions/fnc_switchAttachmentMode.sqf index aae742db8a3..f721428a531 100644 --- a/addons/common/functions/fnc_switchAttachmentMode.sqf +++ b/addons/common/functions/fnc_switchAttachmentMode.sqf @@ -2,26 +2,31 @@ /* * Author: PabstMirror * Switch attachment from one mode to another - based on CBA_accessory_fnc_switchAttachment + * ToDo: Port this to CBA? * * Arguments: * 0: Unit - * 1: From - * 2: To + * 1: Weapon (String or CBA-Weapon-Index (not ace's getWeaponIndex)) + * 2: From + * 3: To * * Return Value: * None * * Example: - * [player, "ACE_DBAL_A3_Green_VP", "ACE_DBAL_A3_Green"] call ace_common_fnc_switchAttachmentMode + * [player, 0, "ACE_DBAL_A3_Green_VP", "ACE_DBAL_A3_Green"] call ace_common_fnc_switchAttachmentMode * * Public: No */ - -params ["_unit", "_currItem", "_switchItem"]; -TRACE_3("switchAttachmentMode",_unit,_currItem,_switchItem); -switch (currentWeapon _unit) do { - case (""): {}; +params ["_unit", "_weapon", "_currItem", "_switchItem"]; +TRACE_4("switchAttachmentMode",_unit,_weapon,_currItem,_switchItem); + +if (_weapon isEqualTo "") exitWith {}; + +private _exit = _unit != ACE_player; +switch (_weapon) do { + case 0; case (primaryWeapon _unit): { private _currWeaponType = 0; _unit removePrimaryWeaponItem _currItem; @@ -31,6 +36,7 @@ switch (currentWeapon _unit) do { ["CBA_attachmentSwitched", _this] call CBA_fnc_localEvent; }, [_unit, _currItem, _switchItem, _currWeaponType]] call CBA_fnc_execNextFrame; }; + case 1; case (handgunWeapon _unit): { private _currWeaponType = 1; _unit removeHandgunItem _currItem; @@ -40,6 +46,7 @@ switch (currentWeapon _unit) do { ["CBA_attachmentSwitched", _this] call CBA_fnc_localEvent; }, [_unit, _currItem, _switchItem, _currWeaponType]] call CBA_fnc_execNextFrame; }; + case 2; case (secondaryWeapon _unit): { private _currWeaponType = 2; _unit removeSecondaryWeaponItem _currItem; @@ -49,13 +56,18 @@ switch (currentWeapon _unit) do { ["CBA_attachmentSwitched", _this] call CBA_fnc_localEvent; }, [_unit, _currItem, _switchItem, _currWeaponType]] call CBA_fnc_execNextFrame; }; + default { + ERROR_1("bad weapon - %1",_this); + _exit = true; + }; }; +if (_exit) exitWith {}; // Don't notify if the unit isn't the local player or if an invalid weapon was passed + private _configSwitchItem = configfile >> "CfgWeapons" >> _switchItem; private _switchItemHintText = getText (_configSwitchItem >> "MRT_SwitchItemHintText"); private _switchItemHintImage = getText (_configSwitchItem >> "picture"); -if (_switchItemHintText isNotEqualTo "") then { + +playSound "click"; +if (_switchItemHintText != "") then { [[_switchItemHintImage, 2.0], [_switchItemHintText], true] call CBA_fnc_notify; }; -if (_unit == ACE_player) then { - playSound "click"; -}; diff --git a/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf b/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf index 2b8fbe43e9d..e91a027068c 100644 --- a/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf +++ b/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf @@ -44,7 +44,7 @@ params ["_unit"]; {}, {true}, { - params ["_unit", "", "_args"]; + params ["", "_unit", "_args"]; _args params ["_attachment", "_name", "_picture", "_weaponItems", "_currentWeapon"]; private _cfgWeapons = configFile >> "CfgWeapons"; @@ -110,10 +110,14 @@ params ["_unit"]; QGVAR(switch_) + _x, format ["%1: %2", localize "str_sensortype_switch", _modeName], getText (_config >> "picture"), - LINKFUNC(switchWeaponAttachment), + { + params ["", "_unit", "_actionParams"]; + _actionParams params ["_weapon", "_newAttachment", "_oldAttachment"]; + [_unit, _weapon, _oldAttachment, _newAttachment] call EFUNC(common,switchAttachmentMode); + }, {true}, {}, - [_currentWeapon, _x, ""] + [_currentWeapon, _x, _attachment] ] call EFUNC(interact_menu,createAction), [], _unit diff --git a/addons/interaction/functions/fnc_switchWeaponAttachment.sqf b/addons/interaction/functions/fnc_switchWeaponAttachment.sqf index 258dd697210..caa756ca189 100644 --- a/addons/interaction/functions/fnc_switchWeaponAttachment.sqf +++ b/addons/interaction/functions/fnc_switchWeaponAttachment.sqf @@ -7,6 +7,9 @@ * 0: Target (not used) * 1: Player * 2: Action params + * - 0: Weapon + * - 1: New Attachment + * - 2: Old Attachment * * Return Value: * None @@ -21,13 +24,7 @@ params ["", "_unit", "_actionParams"]; _actionParams params ["_weapon", "_newAttachment", "_oldAttachment"]; TRACE_3("Switching attachment",_weapon,_newAttachment,_oldAttachment); -private _currWeaponType = switch (_weapon) do { - case (""): {-1}; - case (primaryWeapon _unit): {0}; - case (handgunWeapon _unit): {1}; - case (secondaryWeapon _unit): {2}; - default {-1}; -}; +private _currWeaponType = [_unit, _weapon] call EFUNC(common,getWeaponIndex); if (_currWeaponType == -1) exitWith {}; @@ -50,38 +47,30 @@ if (_removeOld && {!([_unit, _oldAttachment] call CBA_fnc_canAddItem)}) exitWith if (_removeOld) then { [{ - params ["_unit", "_oldAttachment", "", "_currWeaponType"]; + params ["_unit", "_oldAttachment", "_currWeaponType"]; switch (_currWeaponType) do { case 0: {_unit removePrimaryWeaponItem _oldAttachment}; - case 1: {_unit removeHandgunItem _oldAttachment}; - case 2: {_unit removeSecondaryWeaponItem _oldAttachment}; + case 1: {_unit removeSecondaryWeaponItem _oldAttachment}; + case 2: {_unit removeHandgunItem _oldAttachment}; default {}; }; _unit addItem _oldAttachment; - - // If adding a new item, let that code handle raising EH - // Delete addNew from array, to be able to pass _this to EH - if (_this deleteAt 4) exitWith {}; - - ["CBA_attachmentSwitched", _this] call CBA_fnc_localEvent; - }, [_unit, _oldAttachment, _newAttachment, _currWeaponType, _addNew], 0.3] call CBA_fnc_waitAndExecute; + }, [_unit, _oldAttachment, _currWeaponType], 0.3] call CBA_fnc_waitAndExecute; }; if (!_addNew) exitWith {}; [{ - params ["_unit", "", "_newAttachment"]; + params ["_unit", "_newAttachment", "_weapon"]; // Delete weapon from array, to be able to pass _this to EH - _unit addWeaponItem [_this deleteAt 4, _newAttachment]; + _unit addWeaponItem [_weapon, _newAttachment]; [[getText (configFile >> "CfgWeapons" >> _newAttachment >> "picture"), 4], true] call CBA_fnc_notify; if (_unit == ACE_player) then { playSound "click"; }; - - ["CBA_attachmentSwitched", _this] call CBA_fnc_localEvent; -}, [_unit, _oldAttachment, _newAttachment, _currWeaponType, _weapon], 1] call CBA_fnc_waitAndExecute; +}, [_unit, _newAttachment, _weapon], 1] call CBA_fnc_waitAndExecute; From f4d567028617398b3c3842f1b57d4ad635951139 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Thu, 8 Aug 2024 21:20:43 -0500 Subject: [PATCH 3/6] Update addons/interaction/functions/fnc_switchWeaponAttachment.sqf --- addons/interaction/functions/fnc_switchWeaponAttachment.sqf | 1 - 1 file changed, 1 deletion(-) diff --git a/addons/interaction/functions/fnc_switchWeaponAttachment.sqf b/addons/interaction/functions/fnc_switchWeaponAttachment.sqf index caa756ca189..bddafa49335 100644 --- a/addons/interaction/functions/fnc_switchWeaponAttachment.sqf +++ b/addons/interaction/functions/fnc_switchWeaponAttachment.sqf @@ -65,7 +65,6 @@ if (!_addNew) exitWith {}; [{ params ["_unit", "_newAttachment", "_weapon"]; - // Delete weapon from array, to be able to pass _this to EH _unit addWeaponItem [_weapon, _newAttachment]; [[getText (configFile >> "CfgWeapons" >> _newAttachment >> "picture"), 4], true] call CBA_fnc_notify; From 8854b668aaff7842d2aaeaadeea4c0ff54e88d17 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Fri, 9 Aug 2024 22:34:30 +0200 Subject: [PATCH 4/6] Revert some unnecessary changes --- .../functions/fnc_switchWeaponAttachment.sqf | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/addons/interaction/functions/fnc_switchWeaponAttachment.sqf b/addons/interaction/functions/fnc_switchWeaponAttachment.sqf index bddafa49335..3aecc9f6bb3 100644 --- a/addons/interaction/functions/fnc_switchWeaponAttachment.sqf +++ b/addons/interaction/functions/fnc_switchWeaponAttachment.sqf @@ -47,7 +47,7 @@ if (_removeOld && {!([_unit, _oldAttachment] call CBA_fnc_canAddItem)}) exitWith if (_removeOld) then { [{ - params ["_unit", "_oldAttachment", "_currWeaponType"]; + params ["_unit", "_weapon", "_oldAttachment"]; switch (_currWeaponType) do { case 0: {_unit removePrimaryWeaponItem _oldAttachment}; @@ -57,19 +57,19 @@ if (_removeOld) then { }; _unit addItem _oldAttachment; - }, [_unit, _oldAttachment, _currWeaponType], 0.3] call CBA_fnc_waitAndExecute; + }, [_unit, _weapon, _oldAttachment], 0.3] call CBA_fnc_waitAndExecute; }; if (!_addNew) exitWith {}; [{ - params ["_unit", "_newAttachment", "_weapon"]; + params ["_unit", "_weapon", "_newAttachment"]; _unit addWeaponItem [_weapon, _newAttachment]; + if (_unit != ACE_player) exitWith {}; + [[getText (configFile >> "CfgWeapons" >> _newAttachment >> "picture"), 4], true] call CBA_fnc_notify; - if (_unit == ACE_player) then { - playSound "click"; - }; -}, [_unit, _newAttachment, _weapon], 1] call CBA_fnc_waitAndExecute; + playSound "click"; +}, [_unit, _weapon, _newAttachment], 1] call CBA_fnc_waitAndExecute; From bf10a64f3c83ef13e1fefa33d11d4bf0a1c351b9 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Fri, 9 Aug 2024 22:37:20 +0200 Subject: [PATCH 5/6] Remove sound, as it was part of the CBA attachment switching & pass missing parameter --- addons/interaction/functions/fnc_switchWeaponAttachment.sqf | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/addons/interaction/functions/fnc_switchWeaponAttachment.sqf b/addons/interaction/functions/fnc_switchWeaponAttachment.sqf index 3aecc9f6bb3..a41f12fb6d7 100644 --- a/addons/interaction/functions/fnc_switchWeaponAttachment.sqf +++ b/addons/interaction/functions/fnc_switchWeaponAttachment.sqf @@ -47,7 +47,7 @@ if (_removeOld && {!([_unit, _oldAttachment] call CBA_fnc_canAddItem)}) exitWith if (_removeOld) then { [{ - params ["_unit", "_weapon", "_oldAttachment"]; + params ["_unit", "_currWeaponType", "_oldAttachment"]; switch (_currWeaponType) do { case 0: {_unit removePrimaryWeaponItem _oldAttachment}; @@ -57,7 +57,7 @@ if (_removeOld) then { }; _unit addItem _oldAttachment; - }, [_unit, _weapon, _oldAttachment], 0.3] call CBA_fnc_waitAndExecute; + }, [_unit, _currWeaponType, _oldAttachment], 0.3] call CBA_fnc_waitAndExecute; }; if (!_addNew) exitWith {}; @@ -70,6 +70,4 @@ if (!_addNew) exitWith {}; if (_unit != ACE_player) exitWith {}; [[getText (configFile >> "CfgWeapons" >> _newAttachment >> "picture"), 4], true] call CBA_fnc_notify; - - playSound "click"; }, [_unit, _weapon, _newAttachment], 1] call CBA_fnc_waitAndExecute; From cf3b55c907174e01596d0e11f76160b51f4bb7b7 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Fri, 9 Aug 2024 23:00:24 +0200 Subject: [PATCH 6/6] Add sound back, to indicate new attachment --- addons/interaction/functions/fnc_switchWeaponAttachment.sqf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/interaction/functions/fnc_switchWeaponAttachment.sqf b/addons/interaction/functions/fnc_switchWeaponAttachment.sqf index a41f12fb6d7..6fede349624 100644 --- a/addons/interaction/functions/fnc_switchWeaponAttachment.sqf +++ b/addons/interaction/functions/fnc_switchWeaponAttachment.sqf @@ -70,4 +70,6 @@ if (!_addNew) exitWith {}; if (_unit != ACE_player) exitWith {}; [[getText (configFile >> "CfgWeapons" >> _newAttachment >> "picture"), 4], true] call CBA_fnc_notify; + + playSound "click"; }, [_unit, _weapon, _newAttachment], 1] call CBA_fnc_waitAndExecute;