From a71732cf59bd2e0ed8de707be7d853707cbddf9d Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sun, 7 Mar 2021 14:03:33 -0600 Subject: [PATCH 1/5] Interaction - Show all possible modes for an attachement --- .../fnc_getWeaponAttachmentsActions.sqf | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf b/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf index cd0e8f9730c..7ddb4d4523b 100644 --- a/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf +++ b/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf @@ -49,8 +49,30 @@ params ["_unit"]; // "detach" actions { if (_x isEqualTo "") then {continue}; + private _originalAttachment = _x; - private _config = _cfgWeapons >> _x; + private _switchableAttachments = [_originalAttachment] call CBA_fnc_switchableAttachments; + private _convertToActions = []; + { + if (_x == _originalAttachment) then {continue}; + private _config = _cfgWeapons >> _x; + private _modeName = getText (_config >> "MRT_SwitchItemHintText"); + if (_modeName == "") then { _modeName = getText (_config >> "displayName"); }; + private _name = format ["%1: %2", localize "str_sensortype_switch", _modeName]; + private _picture = getText (_config >> "picture"); + + private _action = [ + _x, _name, _picture, + LINKFUNC(switchWeaponAttachment), + {true}, + {}, + [_currentWeapon, _x, ""] + ] call EFUNC(interact_menu,createAction); + _convertToActions pushBack [_action, [], _unit]; + } forEach _switchableAttachments; + + + private _config = _cfgWeapons >> _originalAttachment; private _name = format [LLSTRING(weaponAttachmentsDetach), getText (_config >> "displayName")]; private _picture = getText (_config >> "picture"); @@ -59,9 +81,9 @@ params ["_unit"]; LINKFUNC(switchWeaponAttachment), {true}, {}, - [_currentWeapon, "", _x] + [_currentWeapon, "", _originalAttachment] ] call EFUNC(interact_menu,createAction); - _actions pushBack [_action, [], _unit]; + _actions pushBack [_action, _convertToActions, _unit]; } forEach _weaponItems; _actions From fe7c2a88c1b1e44881075824f18b5e91bdeba48b Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Sat, 20 Jul 2024 15:24:24 +0200 Subject: [PATCH 2/5] Move attach & detach actions under item action --- .../fnc_getWeaponAttachmentsActions.sqf | 152 +++++++++++------- 1 file changed, 93 insertions(+), 59 deletions(-) diff --git a/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf b/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf index b434d47a093..01a37203f8c 100644 --- a/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf +++ b/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf @@ -1,6 +1,6 @@ #include "..\script_component.hpp" /* - * Author: mharis001, Dystopian + * Author: mharis001, Dystopian, PabstMirror, johnb43 * Returns children actions for weapon attachment switching. * * Arguments: @@ -21,70 +21,104 @@ params ["_unit"]; params ["_unit"]; private _currentWeapon = currentWeapon _unit; - if (_currentWeapon isEqualTo "") exitWith {[]}; - private _weaponItems = _unit weaponAccessories _currentWeapon; + + if (_currentWeapon == "") exitWith {[]}; + private _cfgWeapons = configFile >> "CfgWeapons"; - private _actions = []; + private _weaponItems = _unit weaponAccessories _currentWeapon; - // "attach" actions - private _items = _unit call EFUNC(common,uniqueItems); - private _compatibleItems = _currentWeapon call CBA_fnc_compatibleItems; - { + // Get current weapon attachments, as well as compatible attachments in inventory + private _allAttachments = (+_weaponItems) - [""]; + _allAttachments append ((_unit call EFUNC(common,uniqueItems)) arrayIntersect (compatibleItems _currentWeapon)); + + (_allAttachments arrayIntersect _allAttachments) apply { private _config = _cfgWeapons >> _x; - private _name = format [LLSTRING(weaponAttachmentsAttach), getText (_config >> "displayName")]; + private _name = getText (_config >> "displayName"); private _picture = getText (_config >> "picture"); - private _type = getNumber (_config >> "itemInfo" >> "type"); - private _oldAttachment = _weaponItems select ([TYPE_MUZZLE, TYPE_FLASHLIGHT, TYPE_OPTICS, TYPE_BIPOD] find _type); - - private _action = [ - _x, _name, _picture, - LINKFUNC(switchWeaponAttachment), - {true}, - {}, - [_currentWeapon, _x, _oldAttachment] - ] call EFUNC(interact_menu,createAction); - _actions pushBack [_action, [], _unit]; - } forEach ((_items arrayIntersect _compatibleItems) - _weaponItems); - - // "detach" actions - { - if (_x isEqualTo "") then {continue}; - private _originalAttachment = _x; - - private _switchableAttachments = [_originalAttachment] call CBA_fnc_switchableAttachments; - private _convertToActions = []; - { - if (_x == _originalAttachment) then {continue}; - private _config = _cfgWeapons >> _x; - private _modeName = getText (_config >> "MRT_SwitchItemHintText"); - if (_modeName == "") then { _modeName = getText (_config >> "displayName"); }; - private _name = format ["%1: %2", localize "str_sensortype_switch", _modeName]; - private _picture = getText (_config >> "picture"); - - private _action = [ - _x, _name, _picture, - LINKFUNC(switchWeaponAttachment), - {true}, + + [ + [ + _x, + _name, + _picture, {}, - [_currentWeapon, _x, ""] - ] call EFUNC(interact_menu,createAction); - _convertToActions pushBack [_action, [], _unit]; - } forEach _switchableAttachments; + {true}, + { + params ["_unit", "", "_args"]; + _args params ["_attachment", "_name", "_picture", "_weaponItems", "_currentWeapon"]; + private _cfgWeapons = configFile >> "CfgWeapons"; + private _attachementNotOnGun = !(_attachment in _weaponItems); + private _actions = []; - private _config = _cfgWeapons >> _originalAttachment; - private _name = format [LLSTRING(weaponAttachmentsDetach), getText (_config >> "displayName")]; - private _picture = getText (_config >> "picture"); + // "attach" action + if (_attachementNotOnGun && {[_unit, _attachment] call EFUNC(common,hasItem)}) then { + private _type = getNumber (_cfgWeapons >> _attachment >> "itemInfo" >> "type"); + private _currentAttachment = _weaponItems select ([TYPE_MUZZLE, TYPE_FLASHLIGHT, TYPE_OPTICS, TYPE_BIPOD] find _type); + + _actions pushBack [ + [ + QGVAR(attach_) + _attachment, + format [LLSTRING(weaponAttachmentsAttach), _name], + _picture, + LINKFUNC(switchWeaponAttachment), + {true}, + {}, + [_currentWeapon, _attachment, _currentAttachment] + ] call EFUNC(interact_menu,createAction), + [], + _unit + ]; + }; + + // Don't show interaction with attachments that aren't on the current weapon + if (_attachementNotOnGun) exitWith {_actions}; + + // "detach" action + _actions pushBack [ + [ + QGVAR(detach_) + _attachment, + format [LLSTRING(weaponAttachmentsDetach), _name], + _picture, + LINKFUNC(switchWeaponAttachment), + {true}, + {}, + [_currentWeapon, "", _attachment] + ] call EFUNC(interact_menu,createAction), + [], + _unit + ]; + + // "switch" action + { + private _config = _cfgWeapons >> _x; + private _modeName = getText (_config >> "MRT_SwitchItemHintText"); + + if (_modeName == "") then { + _modeName = getText (_config >> "displayName"); + }; + + _actions pushBack [ + [ + QGVAR(switch_) + _x, + format ["%1: %2", localize "str_sensortype_switch", _modeName], + getText (_config >> "picture"), + LINKFUNC(switchWeaponAttachment), + {true}, + {}, + [_currentWeapon, _x, ""] + ] call EFUNC(interact_menu,createAction), + [], + _unit + ]; + } forEach ((_attachment call CBA_fnc_switchableAttachments) - [_attachment]); // Don't allow switching to current mode - private _action = [ - _x, _name, _picture, - LINKFUNC(switchWeaponAttachment), - {true}, - {}, - [_currentWeapon, "", _originalAttachment] - ] call EFUNC(interact_menu,createAction); - _actions pushBack [_action, _convertToActions, _unit]; - } forEach _weaponItems; - - _actions + _actions + }, + [_x, _name, _picture, _weaponItems, _currentWeapon] + ] call EFUNC(interact_menu,createAction), + [], + _unit + ] + } // return }, _unit, QGVAR(weaponAttachmentsActions), 5, QGVAR(clearWeaponAttachmentsActionsCache)] call EFUNC(common,cachedCall); From dfca327d6a269495370ff38eda173e24647cbdfa Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Sat, 20 Jul 2024 15:43:41 +0200 Subject: [PATCH 3/5] Remove switching from PIP to regular 2D --- .../functions/fnc_getWeaponAttachmentsActions.sqf | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf b/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf index 01a37203f8c..16f6c600fe8 100644 --- a/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf +++ b/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf @@ -89,8 +89,14 @@ params ["_unit"]; _unit ]; + private _CBA_PIPItems = configFile >> "CBA_PIPItems"; + // "switch" action { + if (getText (_CBA_PIPItems >> _x) == _attachment) then { + continue; + }; + private _config = _cfgWeapons >> _x; private _modeName = getText (_config >> "MRT_SwitchItemHintText"); From edea6ee73aa30e48074a2de180cf831a0b6952fa Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Mon, 22 Jul 2024 08:36:49 +0200 Subject: [PATCH 4/5] Remove attachment name from attach/detach actions --- .../fnc_getWeaponAttachmentsActions.sqf | 5 ++- addons/interaction/stringtable.xml | 44 +++++++++---------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf b/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf index 16f6c600fe8..69c319637e2 100644 --- a/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf +++ b/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf @@ -59,7 +59,7 @@ params ["_unit"]; _actions pushBack [ [ QGVAR(attach_) + _attachment, - format [LLSTRING(weaponAttachmentsAttach), _name], + LLSTRING(weaponAttachmentsAttach), _picture, LINKFUNC(switchWeaponAttachment), {true}, @@ -78,7 +78,7 @@ params ["_unit"]; _actions pushBack [ [ QGVAR(detach_) + _attachment, - format [LLSTRING(weaponAttachmentsDetach), _name], + LLSTRING(weaponAttachmentsDetach), _picture, LINKFUNC(switchWeaponAttachment), {true}, @@ -93,6 +93,7 @@ params ["_unit"]; // "switch" action { + // Ignore 2D scopes when using a PIP scope (e.g. CUP uses this) if (getText (_CBA_PIPItems >> _x) == _attachment) then { continue; }; diff --git a/addons/interaction/stringtable.xml b/addons/interaction/stringtable.xml index 38c86f5f99b..5b79a69e69b 100644 --- a/addons/interaction/stringtable.xml +++ b/addons/interaction/stringtable.xml @@ -1247,30 +1247,30 @@ 전면유리 부수기 - Attach %1 - Установить %1 - %1 を取り付け - Acoplar %1 - Fixer %1 - Przyczep %1 - Befestige %1 - Attacca %1 - 附加 %1 - %1 붙이기 - Fixar %1 + Attach + Установить + を取り付け + Acoplar + Fixer + Przyczep + Befestige + Attacca + 附加 + 붙이기 + Fixar - Detach %1 - Снять %1 - %1 を外す - Desacoplar %1 - Retirer %1 - Odczep %1 - Löse %1 - Stacca %1 - 拆卸 %1 - %1 떼내기 - Desfixar %1 + Detach + Снять + を外す + Desacoplar + Retirer + Odczep + Löse + Stacca + 拆卸 + 떼내기 + Desfixar Enables attach/detach weapon attachment actions for current weapon. From 6fd5035a7070c4e2ce9792d3400bd430431d4392 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Sat, 27 Jul 2024 19:27:35 +0200 Subject: [PATCH 5/5] Fixed typo in variable name --- .../functions/fnc_getWeaponAttachmentsActions.sqf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf b/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf index 69c319637e2..2b8fbe43e9d 100644 --- a/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf +++ b/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf @@ -48,11 +48,11 @@ params ["_unit"]; _args params ["_attachment", "_name", "_picture", "_weaponItems", "_currentWeapon"]; private _cfgWeapons = configFile >> "CfgWeapons"; - private _attachementNotOnGun = !(_attachment in _weaponItems); + private _attachmentNotOnGun = !(_attachment in _weaponItems); private _actions = []; // "attach" action - if (_attachementNotOnGun && {[_unit, _attachment] call EFUNC(common,hasItem)}) then { + if (_attachmentNotOnGun && {[_unit, _attachment] call EFUNC(common,hasItem)}) then { private _type = getNumber (_cfgWeapons >> _attachment >> "itemInfo" >> "type"); private _currentAttachment = _weaponItems select ([TYPE_MUZZLE, TYPE_FLASHLIGHT, TYPE_OPTICS, TYPE_BIPOD] find _type); @@ -72,7 +72,7 @@ params ["_unit"]; }; // Don't show interaction with attachments that aren't on the current weapon - if (_attachementNotOnGun) exitWith {_actions}; + if (_attachmentNotOnGun) exitWith {_actions}; // "detach" action _actions pushBack [