Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interaction - Show all possible modes for an attachment #8154

Merged
merged 6 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 102 additions & 39 deletions addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "..\script_component.hpp"
/*
* Author: mharis001, Dystopian
* Author: mharis001, Dystopian, PabstMirror, johnb43
* Returns children actions for weapon attachment switching.
*
* Arguments:
Expand All @@ -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);
44 changes: 22 additions & 22 deletions addons/interaction/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1247,30 +1247,30 @@
<Korean>전면유리 부수기</Korean>
</Key>
<Key ID="STR_ACE_Interaction_weaponAttachmentsAttach">
<English>Attach %1</English>
<Russian>Установить %1</Russian>
<Japanese>%1 を取り付け</Japanese>
<Spanish>Acoplar %1</Spanish>
<French>Fixer %1</French>
<Polish>Przyczep %1</Polish>
<German>Befestige %1</German>
<Italian>Attacca %1</Italian>
<Chinesesimp>附加 %1</Chinesesimp>
<Korean>%1 붙이기</Korean>
<Portuguese>Fixar %1</Portuguese>
<English>Attach</English>
<Russian>Установить</Russian>
<Japanese>を取り付け</Japanese>
<Spanish>Acoplar</Spanish>
<French>Fixer</French>
<Polish>Przyczep</Polish>
<German>Befestige</German>
<Italian>Attacca</Italian>
<Chinesesimp>附加</Chinesesimp>
<Korean>붙이기</Korean>
<Portuguese>Fixar</Portuguese>
</Key>
<Key ID="STR_ACE_Interaction_weaponAttachmentsDetach">
<English>Detach %1</English>
<Russian>Снять %1</Russian>
<Japanese>%1 を外す</Japanese>
<Spanish>Desacoplar %1</Spanish>
<French>Retirer %1</French>
<Polish>Odczep %1</Polish>
<German>Löse %1</German>
<Italian>Stacca %1</Italian>
<Chinesesimp>拆卸 %1</Chinesesimp>
<Korean>%1 떼내기</Korean>
<Portuguese>Desfixar %1</Portuguese>
<English>Detach</English>
<Russian>Снять</Russian>
<Japanese>を外す</Japanese>
<Spanish>Desacoplar</Spanish>
<French>Retirer</French>
<Polish>Odczep</Polish>
<German>Löse</German>
<Italian>Stacca</Italian>
<Chinesesimp>拆卸</Chinesesimp>
<Korean>떼내기</Korean>
<Portuguese>Desfixar</Portuguese>
</Key>
<Key ID="STR_ACE_Interaction_weaponAttachments_Description">
<English>Enables attach/detach weapon attachment actions for current weapon.</English>
Expand Down