Interaction - Show all possible modes for an attachment (#8154)

* Interaction - Show all possible modes for an attachement

* Move attach & detach actions under item action

* Remove switching from PIP to regular 2D

* Remove attachment name from attach/detach actions

* Fixed typo in variable name

---------

Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>
This commit is contained in:
PabstMirror 2024-07-27 12:37:33 -05:00 committed by GitHub
parent aa6e5c30ec
commit e3d8f40538
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 124 additions and 61 deletions

View File

@ -1,6 +1,6 @@
#include "..\script_component.hpp" #include "..\script_component.hpp"
/* /*
* Author: mharis001, Dystopian * Author: mharis001, Dystopian, PabstMirror, johnb43
* Returns children actions for weapon attachment switching. * Returns children actions for weapon attachment switching.
* *
* Arguments: * Arguments:
@ -21,48 +21,111 @@ params ["_unit"];
params ["_unit"]; params ["_unit"];
private _currentWeapon = currentWeapon _unit; private _currentWeapon = currentWeapon _unit;
if (_currentWeapon isEqualTo "") exitWith {[]};
private _weaponItems = _unit weaponAccessories _currentWeapon; if (_currentWeapon == "") exitWith {[]};
private _cfgWeapons = configFile >> "CfgWeapons"; private _cfgWeapons = configFile >> "CfgWeapons";
private _actions = []; private _weaponItems = _unit weaponAccessories _currentWeapon;
// "attach" actions // Get current weapon attachments, as well as compatible attachments in inventory
private _items = _unit call EFUNC(common,uniqueItems); private _allAttachments = (+_weaponItems) - [""];
private _compatibleItems = _currentWeapon call CBA_fnc_compatibleItems; _allAttachments append ((_unit call EFUNC(common,uniqueItems)) arrayIntersect (compatibleItems _currentWeapon));
{
(_allAttachments arrayIntersect _allAttachments) apply {
private _config = _cfgWeapons >> _x; 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 _config = _cfgWeapons >> _x;
private _name = format [LLSTRING(weaponAttachmentsDetach), getText (_config >> "displayName")];
private _picture = getText (_config >> "picture"); private _picture = getText (_config >> "picture");
private _action = [ [
_x, _name, _picture, [
LINKFUNC(switchWeaponAttachment), _x,
{true}, _name,
{}, _picture,
[_currentWeapon, "", _x] {},
] call EFUNC(interact_menu,createAction); {true},
_actions pushBack [_action, [], _unit]; {
} forEach _weaponItems; params ["_unit", "", "_args"];
_args params ["_attachment", "_name", "_picture", "_weaponItems", "_currentWeapon"];
_actions 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); }, _unit, QGVAR(weaponAttachmentsActions), 5, QGVAR(clearWeaponAttachmentsActionsCache)] call EFUNC(common,cachedCall);

View File

@ -1247,30 +1247,30 @@
<Korean>전면유리 부수기</Korean> <Korean>전면유리 부수기</Korean>
</Key> </Key>
<Key ID="STR_ACE_Interaction_weaponAttachmentsAttach"> <Key ID="STR_ACE_Interaction_weaponAttachmentsAttach">
<English>Attach %1</English> <English>Attach</English>
<Russian>Установить %1</Russian> <Russian>Установить</Russian>
<Japanese>%1 を取り付け</Japanese> <Japanese>を取り付け</Japanese>
<Spanish>Acoplar %1</Spanish> <Spanish>Acoplar</Spanish>
<French>Fixer %1</French> <French>Fixer</French>
<Polish>Przyczep %1</Polish> <Polish>Przyczep</Polish>
<German>Befestige %1</German> <German>Befestige</German>
<Italian>Attacca %1</Italian> <Italian>Attacca</Italian>
<Chinesesimp>附加 %1</Chinesesimp> <Chinesesimp>附加</Chinesesimp>
<Korean>%1 붙이기</Korean> <Korean>붙이기</Korean>
<Portuguese>Fixar %1</Portuguese> <Portuguese>Fixar</Portuguese>
</Key> </Key>
<Key ID="STR_ACE_Interaction_weaponAttachmentsDetach"> <Key ID="STR_ACE_Interaction_weaponAttachmentsDetach">
<English>Detach %1</English> <English>Detach</English>
<Russian>Снять %1</Russian> <Russian>Снять</Russian>
<Japanese>%1 を外す</Japanese> <Japanese>を外す</Japanese>
<Spanish>Desacoplar %1</Spanish> <Spanish>Desacoplar</Spanish>
<French>Retirer %1</French> <French>Retirer</French>
<Polish>Odczep %1</Polish> <Polish>Odczep</Polish>
<German>Löse %1</German> <German>Löse</German>
<Italian>Stacca %1</Italian> <Italian>Stacca</Italian>
<Chinesesimp>拆卸 %1</Chinesesimp> <Chinesesimp>拆卸</Chinesesimp>
<Korean>%1 떼내기</Korean> <Korean>떼내기</Korean>
<Portuguese>Desfixar %1</Portuguese> <Portuguese>Desfixar</Portuguese>
</Key> </Key>
<Key ID="STR_ACE_Interaction_weaponAttachments_Description"> <Key ID="STR_ACE_Interaction_weaponAttachments_Description">
<English>Enables attach/detach weapon attachment actions for current weapon.</English> <English>Enables attach/detach weapon attachment actions for current weapon.</English>