diff --git a/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf b/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf
index c771589904f..2b8fbe43e9d 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,48 +21,111 @@ 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;
- {
- private _config = _cfgWeapons >> _x;
- private _name = format [LLSTRING(weaponAttachmentsAttach), 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};
+ // 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(weaponAttachmentsDetach), getText (_config >> "displayName")];
+ private _name = getText (_config >> "displayName");
private _picture = getText (_config >> "picture");
- private _action = [
- _x, _name, _picture,
- LINKFUNC(switchWeaponAttachment),
- {true},
- {},
- [_currentWeapon, "", _x]
- ] call EFUNC(interact_menu,createAction);
- _actions pushBack [_action, [], _unit];
- } forEach _weaponItems;
-
- _actions
+ [
+ [
+ _x,
+ _name,
+ _picture,
+ {},
+ {true},
+ {
+ params ["_unit", "", "_args"];
+ _args params ["_attachment", "_name", "_picture", "_weaponItems", "_currentWeapon"];
+
+ private _cfgWeapons = configFile >> "CfgWeapons";
+ private _attachmentNotOnGun = !(_attachment in _weaponItems);
+ private _actions = [];
+
+ // "attach" action
+ 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);
+
+ _actions pushBack [
+ [
+ QGVAR(attach_) + _attachment,
+ LLSTRING(weaponAttachmentsAttach),
+ _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 (_attachmentNotOnGun) exitWith {_actions};
+
+ // "detach" action
+ _actions pushBack [
+ [
+ QGVAR(detach_) + _attachment,
+ LLSTRING(weaponAttachmentsDetach),
+ _picture,
+ LINKFUNC(switchWeaponAttachment),
+ {true},
+ {},
+ [_currentWeapon, "", _attachment]
+ ] call EFUNC(interact_menu,createAction),
+ [],
+ _unit
+ ];
+
+ private _CBA_PIPItems = configFile >> "CBA_PIPItems";
+
+ // "switch" action
+ {
+ // Ignore 2D scopes when using a PIP scope (e.g. CUP uses this)
+ if (getText (_CBA_PIPItems >> _x) == _attachment) then {
+ continue;
+ };
+
+ 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
+
+ _actions
+ },
+ [_x, _name, _picture, _weaponItems, _currentWeapon]
+ ] call EFUNC(interact_menu,createAction),
+ [],
+ _unit
+ ]
+ } // return
}, _unit, QGVAR(weaponAttachmentsActions), 5, QGVAR(clearWeaponAttachmentsActionsCache)] call EFUNC(common,cachedCall);
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.