From 69c3d2bb658293710631af795ad657ac7d60d9b8 Mon Sep 17 00:00:00 2001 From: Dystopian Date: Thu, 4 Mar 2021 21:43:11 +0400 Subject: [PATCH] Add Weapon Attachments interaction (#7706) * Add Weapon Attachments interaction * Apply recommended changes * Format addPEH Co-authored-by: mharis001 <34453221+mharis001@users.noreply.github.com> * Remove toLower * Update required CBA version * Rename category to Accessories * Change setting var name * Add setting description * Fix notification size * Optimize with new commands Co-authored-by: mharis001 <34453221+mharis001@users.noreply.github.com> --- addons/attach/functions/fnc_detach.sqf | 2 +- addons/attach/stringtable.xml | 17 ----- addons/chemlights/stringtable.xml | 17 ----- .../fnc_cbaSettings_convertHelper.sqf | 2 +- addons/common/stringtable.xml | 17 +++++ .../hearing/functions/fnc_removeEarplugs.sqf | 2 +- addons/hearing/stringtable.xml | 17 ----- addons/interaction/ACE_Settings.hpp | 18 +---- addons/interaction/CfgVehicles.hpp | 8 +++ addons/interaction/XEH_PREP.hpp | 4 ++ addons/interaction/XEH_postInit.sqf | 6 ++ addons/interaction/XEH_preInit.sqf | 2 + .../fnc_getWeaponAttachmentsActions.sqf | 68 +++++++++++++++++++ .../functions/fnc_switchWeaponAttachment.sqf | 59 ++++++++++++++++ addons/interaction/initSettings.sqf | 31 +++++++++ addons/interaction/stringtable.xml | 12 ++++ addons/main/script_mod.hpp | 2 +- 17 files changed, 214 insertions(+), 70 deletions(-) create mode 100644 addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf create mode 100644 addons/interaction/functions/fnc_switchWeaponAttachment.sqf create mode 100644 addons/interaction/initSettings.sqf diff --git a/addons/attach/functions/fnc_detach.sqf b/addons/attach/functions/fnc_detach.sqf index 38acbc1883..7c68831f36 100644 --- a/addons/attach/functions/fnc_detach.sqf +++ b/addons/attach/functions/fnc_detach.sqf @@ -47,7 +47,7 @@ private _isChemlight = _attachedObject isKindOf "Chemlight_base"; // Exit if can't add the item if (!([_unit, _itemName] call CBA_fnc_canAddItem) && {!_isChemlight}) exitWith { - [localize LSTRING(Inventory_Full)] call EFUNC(common,displayTextStructured); + [LELSTRING(common,Inventory_Full)] call EFUNC(common,displayTextStructured); }; // Add item to inventory (unless it's a chemlight) diff --git a/addons/attach/stringtable.xml b/addons/attach/stringtable.xml index 44af699017..831c4384e4 100644 --- a/addons/attach/stringtable.xml +++ b/addons/attach/stringtable.xml @@ -154,23 +154,6 @@ 已取下萤光棒 Işık Çubuğu Söküldü - - No inventory space - Kein Platz im Inventar - Sin espacio en inventario - Brak miejsca w ekwipunku - Pas de place dans l'inventaire - Nedostatek místa v inventáři - Sem espaço no inventário - Non hai più spazio - Nincs több hely - В инвентаре нет места - インベントリに空きがない - 넣을 공간이 없음 - 無可用空間 - 无可用空间 - Envanter de alan yok - IR Strobe IR-Stroboskop diff --git a/addons/chemlights/stringtable.xml b/addons/chemlights/stringtable.xml index 86deea0380..c1c6c930d8 100644 --- a/addons/chemlights/stringtable.xml +++ b/addons/chemlights/stringtable.xml @@ -49,23 +49,6 @@ %1<br/>Preparado %1<br/> Hazırlandı - - No inventory space - Kein Platz im Inventar - Sin espacio en inventario - Brak miejsca w ekwipunku - Pas de place dans l'inventaire - Nedostatek místa v inventáři - Sem espaço no inventário - Nessuno spazio nell'inventario - Nincs több hely - В инвентаре нет места - インベントリに空きがありません - 소지품 공간이 없음 - 已無存放空間 - 已无存放空间 - Envanter de alan yok - [ACE] Chemlights [ACE] ケミライト diff --git a/addons/common/functions/fnc_cbaSettings_convertHelper.sqf b/addons/common/functions/fnc_cbaSettings_convertHelper.sqf index b2b23eec91..6e7a4456c7 100644 --- a/addons/common/functions/fnc_cbaSettings_convertHelper.sqf +++ b/addons/common/functions/fnc_cbaSettings_convertHelper.sqf @@ -110,7 +110,6 @@ private _settings = configProperties [configFile >> "ACE_Settings", "(isClass _x private _gvarName = _varName select [_addonSearchCount]; - _output pushBack ""; _output pushBack format ["["]; _output pushBack format [" QGVAR(%1), ""%2"",", _gvarName, _cbaSettingType]; _output pushBack format [" [LSTRING(), LSTRING()], // %1, %2", _localizedName, _localizedDescription]; //IGNORE_STRING_WARNING(str_ace_common_); @@ -124,6 +123,7 @@ private _settings = configProperties [configFile >> "ACE_Settings", "(isClass _x }; _output pushBack format [" %1 // Needs mission restart", _warnIfChangedMidMission]; _output pushBack "] call CBA_fnc_addSetting;"; + _output pushBack ""; } forEach _settings; copyToClipboard (_output joinString endl); diff --git a/addons/common/stringtable.xml b/addons/common/stringtable.xml index fb94add8b6..4325f152bf 100644 --- a/addons/common/stringtable.xml +++ b/addons/common/stringtable.xml @@ -1296,6 +1296,23 @@ 没有空间可卸载 언로드 할 공간이 없습니다. + + No inventory space + Kein Platz im Inventar + Sin espacio en inventario + Brak miejsca w ekwipunku + Pas de place dans l'inventaire + Nedostatek místa v inventáři + Sem espaço no inventário + Non hai più spazio + Nincs több hely + В инвентаре нет места + インベントリに空きがない + 넣을 공간이 없음 + 無可用空間 + 无可用空间 + Envanter de alan yok + Toggle переключить diff --git a/addons/hearing/functions/fnc_removeEarplugs.sqf b/addons/hearing/functions/fnc_removeEarplugs.sqf index 55ba422beb..8399a3a84f 100644 --- a/addons/hearing/functions/fnc_removeEarplugs.sqf +++ b/addons/hearing/functions/fnc_removeEarplugs.sqf @@ -21,7 +21,7 @@ params ["_player", ["_displayHint", false, [false]]]; if (!GVAR(EnableCombatDeafness)) exitWith {}; if !([_player, "ACE_EarPlugs"] call CBA_fnc_canAddItem) exitWith { // inventory full - [localize LSTRING(Inventory_Full)] call EFUNC(common,displayTextStructured); + [LELSTRING(common,Inventory_Full)] call EFUNC(common,displayTextStructured); }; // Plugs already in and removing them. diff --git a/addons/hearing/stringtable.xml b/addons/hearing/stringtable.xml index e5a8ca2bab..b67f363b00 100644 --- a/addons/hearing/stringtable.xml +++ b/addons/hearing/stringtable.xml @@ -119,23 +119,6 @@ 你沒有耳塞 Kulak Tıkacın Yok - - No inventory space - Kein Platz im Inventar - Sin espacio en el inventario - Brak miejsca w ekwipunku - Il n'y a plus de place dans l'inventaire. - Není místo v inventáři - Non hai abbastanza spazio - Não há espaço no inventário - Nincs több hely - Нет места в инвентаре - インベントリに空きがありません - 넣을 공간이 없습니다 - 无可用空间 - 無可用空間 - Envanterin de alan yok - Disable ear ringing Désactiver les bourdonnements diff --git a/addons/interaction/ACE_Settings.hpp b/addons/interaction/ACE_Settings.hpp index 3efb745a6b..67497ec23b 100644 --- a/addons/interaction/ACE_Settings.hpp +++ b/addons/interaction/ACE_Settings.hpp @@ -1,24 +1,12 @@ class ACE_Settings { class GVAR(enableTeamManagement) { - category = CSTRING(DisplayName); - displayName = CSTRING(EnableTeamManagement_DisplayName); - description = CSTRING(EnableTeamManagement_Description); - value = 1; - typeName = "BOOL"; + movedToSQF = 1; }; class GVAR(enableMagazinePassing) { - category = CSTRING(DisplayName); - value = 1; - typeName = "BOOL"; - isClientSettable = 1; - displayName = CSTRING(PassMagazineSetting); + movedToSQF = 1; }; class GVAR(disableNegativeRating) { - category = CSTRING(DisplayName); - displayName = CSTRING(DisableNegativeRating_DisplayName); - description = CSTRING(DisableNegativeRating_Description); - value = 0; - typeName = "BOOL"; + movedToSQF = 1; }; }; diff --git a/addons/interaction/CfgVehicles.hpp b/addons/interaction/CfgVehicles.hpp index 3b53bf925c..de80f3e1e1 100644 --- a/addons/interaction/CfgVehicles.hpp +++ b/addons/interaction/CfgVehicles.hpp @@ -312,6 +312,14 @@ class CfgVehicles { statement = ""; showDisabled = 1; icon = ""; // @todo + + class GVAR(weaponAttachments) { + displayName = "$STR_A3_CfgEditorSubcategories_EdSubcat_SideSlot0"; + condition = QGVAR(enableWeaponAttachments); + exceptions[] = {"isNotInside", "isNotSwimming", "isNotSitting"}; + insertChildren = QUOTE(call DFUNC(getWeaponAttachmentsActions)); + modifierFunction = QUOTE(_this select 3 set [ARR_2(2, getText (configFile >> 'CfgWeapons' >> currentWeapon (_this select 0) >> 'picture'))];); + }; }; }; }; diff --git a/addons/interaction/XEH_PREP.hpp b/addons/interaction/XEH_PREP.hpp index a63bfc48f8..8eada17e3d 100644 --- a/addons/interaction/XEH_PREP.hpp +++ b/addons/interaction/XEH_PREP.hpp @@ -33,6 +33,10 @@ PREP(pardon); PREP(canPullOutBody); PREP(pullOutBody); +// Weapon Attachments +PREP(getWeaponAttachmentsActions); +PREP(switchWeaponAttachment); + // interaction with doors PREP(getDoor); PREP(getGlassDoor); diff --git a/addons/interaction/XEH_postInit.sqf b/addons/interaction/XEH_postInit.sqf index 7a9f2b6572..933cead137 100644 --- a/addons/interaction/XEH_postInit.sqf +++ b/addons/interaction/XEH_postInit.sqf @@ -135,3 +135,9 @@ GVAR(isOpeningDoor) = false; }]; }; }] call CBA_fnc_addEventHandler; + +{ + [_x, { + [QGVAR(clearWeaponAttachmentsActionsCache)] call CBA_fnc_localEvent; + }] call CBA_fnc_addPlayerEventHandler; +} forEach ["loadout", "weapon"]; diff --git a/addons/interaction/XEH_preInit.sqf b/addons/interaction/XEH_preInit.sqf index dbc37e2bb6..855d651d55 100644 --- a/addons/interaction/XEH_preInit.sqf +++ b/addons/interaction/XEH_preInit.sqf @@ -6,6 +6,8 @@ PREP_RECOMPILE_START; #include "XEH_PREP.hpp" PREP_RECOMPILE_END; +#include "initSettings.sqf" + DFUNC(repair_Statement) = { // moved from config because of build problems TRACE_1("repair_Statement",_this); { diff --git a/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf b/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf new file mode 100644 index 0000000000..cd0e8f9730 --- /dev/null +++ b/addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf @@ -0,0 +1,68 @@ +#include "script_component.hpp" +/* + * Author: mharis001, Dystopian + * Returns children actions for weapon attachment switching. + * + * Arguments: + * 0: Unit + * + * Return Value: + * Actions + * + * Example: + * player call ace_interaction_fnc_getWeaponAttachmentsActions + * + * Public: No + */ + +params ["_unit"]; + +[_unit, { + params ["_unit"]; + + private _currentWeapon = currentWeapon _unit; + if (_currentWeapon isEqualTo "") exitWith {[]}; + private _weaponItems = _unit weaponAccessories _currentWeapon; + private _cfgWeapons = configFile >> "CfgWeapons"; + private _actions = []; + + // "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}; + + private _config = _cfgWeapons >> _x; + private _name = format [LLSTRING(weaponAttachmentsDetach), 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 +}, _unit, QGVAR(weaponAttachmentsActions), 5, QGVAR(clearWeaponAttachmentsActionsCache)] call EFUNC(common,cachedCall); diff --git a/addons/interaction/functions/fnc_switchWeaponAttachment.sqf b/addons/interaction/functions/fnc_switchWeaponAttachment.sqf new file mode 100644 index 0000000000..4f9a9f2514 --- /dev/null +++ b/addons/interaction/functions/fnc_switchWeaponAttachment.sqf @@ -0,0 +1,59 @@ +#include "script_component.hpp" +/* + * Author: mharis001, Dystopian + * Switches weapon attachment. + * + * Arguments: + * 0: Target + * 1: Player (not used) + * 2: Action params + * + * Return Value: + * None + * + * Example: + * [player, player, [currentWeapon player, "acc_flashlight", ""]] call ace_interaction_fnc_switchWeaponAttachment + * + * Public: No + */ + +params ["_unit", "", "_actionParams"]; +_actionParams params ["_weapon", "_newAttachment", "_oldAttachment"]; +TRACE_3("Switching attachment",_weapon,_newAttachment,_oldAttachment); + +[_unit, "Gear"] call EFUNC(common,doGesture); + +private _addNew = _newAttachment isNotEqualTo ""; +private _removeOld = _oldAttachment isNotEqualTo ""; + +if (_addNew) then { + _unit removeItem _newAttachment; +}; + +if (_removeOld && {!([_unit, _oldAttachment] call CBA_fnc_canAddItem)}) exitWith { + LOG("no space"); + [LELSTRING(common,Inventory_Full)] call EFUNC(common,displayTextStructured); + if (_addNew) then { + _unit addItem _newAttachment; + }; +}; + +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;}; + }; + _unit addItem _oldAttachment; + }, [_unit, _weapon, _oldAttachment], 0.3] call CBA_fnc_waitAndExecute; +}; + +if (!_addNew) exitWith {}; + +[{ + params ["_unit", "_weapon", "_newAttachment"]; + _unit addWeaponItem [_weapon, _newAttachment]; + [[getText (configFile >> "CfgWeapons" >> _newAttachment >> "picture"), 4], true] call CBA_fnc_notify; +}, [_unit, _weapon, _newAttachment], 1] call CBA_fnc_waitAndExecute; diff --git a/addons/interaction/initSettings.sqf b/addons/interaction/initSettings.sqf new file mode 100644 index 0000000000..0500cd5c43 --- /dev/null +++ b/addons/interaction/initSettings.sqf @@ -0,0 +1,31 @@ +[ + QGVAR(enableTeamManagement), "CHECKBOX", + [LSTRING(EnableTeamManagement_DisplayName), LSTRING(EnableTeamManagement_Description)], + format ["ACE %1", LLSTRING(DisplayName)], + true, + true +] call CBA_fnc_addSetting; + +[ + QGVAR(enableMagazinePassing), "CHECKBOX", + LSTRING(PassMagazineSetting), + format ["ACE %1", LLSTRING(DisplayName)], + true +] call CBA_fnc_addSetting; + +[ + QGVAR(disableNegativeRating), "CHECKBOX", + [LSTRING(DisableNegativeRating_DisplayName), LSTRING(DisableNegativeRating_Description)], + format ["ACE %1", LLSTRING(DisplayName)], + false, + true, + {[QGVAR(disableNegativeRating), _this] call EFUNC(common,cbaSettings_settingChanged)}, + true +] call CBA_fnc_addSetting; + +[ + QGVAR(enableWeaponAttachments), "CHECKBOX", + ["str_a3_cfgeditorcategories_edcat_weaponattachments0", LSTRING(weaponAttachments_Description)], + format ["ACE %1", LLSTRING(DisplayName)], + true +] call CBA_fnc_addSetting; diff --git a/addons/interaction/stringtable.xml b/addons/interaction/stringtable.xml index 06c18cbaf0..6d28384798 100644 --- a/addons/interaction/stringtable.xml +++ b/addons/interaction/stringtable.xml @@ -1203,5 +1203,17 @@ Romper parabrisas Ön camı parçala + + Attach %1 + Установить %1 + + + Detach %1 + Снять %1 + + + Enables attach/detach weapon attachment actions for current weapon. + Включает действия Установить/Снять для приспособлений текущего оружия. + diff --git a/addons/main/script_mod.hpp b/addons/main/script_mod.hpp index 36015f36ac..b8e9bcf69c 100644 --- a/addons/main/script_mod.hpp +++ b/addons/main/script_mod.hpp @@ -11,7 +11,7 @@ // MINIMAL required version for the Mod. Components can specify others.. #define REQUIRED_VERSION 2.02 -#define REQUIRED_CBA_VERSION {3,15,0} +#define REQUIRED_CBA_VERSION {3,15,2} #ifdef COMPONENT_BEAUTIFIED #define COMPONENT_NAME QUOTE(ACE3 - COMPONENT_BEAUTIFIED)