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

Add Weapon Attachments interaction #7706

Merged
merged 12 commits into from
Mar 4, 2021
2 changes: 1 addition & 1 deletion addons/attach/functions/fnc_detach.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 0 additions & 17 deletions addons/attach/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,23 +154,6 @@
<Chinesesimp>已取下萤光棒</Chinesesimp>
<Turkish>Işık Çubuğu Söküldü</Turkish>
</Key>
<Key ID="STR_ACE_Attach_Inventory_Full">
<English>No inventory space</English>
<German>Kein Platz im Inventar</German>
<Spanish>Sin espacio en inventario</Spanish>
<Polish>Brak miejsca w ekwipunku</Polish>
<French>Pas de place dans l'inventaire</French>
<Czech>Nedostatek místa v inventáři</Czech>
<Portuguese>Sem espaço no inventário</Portuguese>
<Italian>Non hai più spazio</Italian>
<Hungarian>Nincs több hely</Hungarian>
<Russian>В инвентаре нет места</Russian>
<Japanese>インベントリに空きがない</Japanese>
<Korean>넣을 공간이 없음</Korean>
<Chinese>無可用空間</Chinese>
<Chinesesimp>无可用空间</Chinesesimp>
<Turkish>Envanter de alan yok</Turkish>
</Key>
<Key ID="STR_ACE_Attach_IrStrobe_Name">
<English>IR Strobe</English>
<German>IR-Stroboskop</German>
Expand Down
17 changes: 0 additions & 17 deletions addons/chemlights/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,6 @@
<Spanish>%1&lt;br/&gt;Preparado</Spanish>
<Turkish>%1&lt;br/&gt; Hazırlandı</Turkish>
</Key>
<Key ID="STR_ACE_Chemlights_Inventory_Full">
<English>No inventory space</English>
<German>Kein Platz im Inventar</German>
<Spanish>Sin espacio en inventario</Spanish>
<Polish>Brak miejsca w ekwipunku</Polish>
<French>Pas de place dans l'inventaire</French>
<Czech>Nedostatek místa v inventáři</Czech>
<Portuguese>Sem espaço no inventário</Portuguese>
<Italian>Nessuno spazio nell'inventario</Italian>
<Hungarian>Nincs több hely</Hungarian>
<Russian>В инвентаре нет места</Russian>
<Japanese>インベントリに空きがありません</Japanese>
<Korean>소지품 공간이 없음</Korean>
<Chinese>已無存放空間</Chinese>
<Chinesesimp>已无存放空间</Chinesesimp>
<Turkish>Envanter de alan yok</Turkish>
</Key>
<Key ID="STR_ACE_Chemlights_Box_DisplayName">
<English>[ACE] Chemlights</English>
<Japanese>[ACE] ケミライト</Japanese>
Expand Down
2 changes: 1 addition & 1 deletion addons/common/functions/fnc_cbaSettings_convertHelper.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand All @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions addons/common/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,23 @@
<Chinesesimp>没有空间可卸载</Chinesesimp>
<Korean>언로드 할 공간이 없습니다.</Korean>
</Key>
<Key ID="STR_ACE_Common_Inventory_Full">
<English>No inventory space</English>
<German>Kein Platz im Inventar</German>
<Spanish>Sin espacio en inventario</Spanish>
<Polish>Brak miejsca w ekwipunku</Polish>
<French>Pas de place dans l'inventaire</French>
<Czech>Nedostatek místa v inventáři</Czech>
<Portuguese>Sem espaço no inventário</Portuguese>
<Italian>Non hai più spazio</Italian>
<Hungarian>Nincs több hely</Hungarian>
<Russian>В инвентаре нет места</Russian>
<Japanese>インベントリに空きがない</Japanese>
<Korean>넣을 공간이 없음</Korean>
<Chinese>無可用空間</Chinese>
<Chinesesimp>无可用空间</Chinesesimp>
<Turkish>Envanter de alan yok</Turkish>
</Key>
<Key ID="STR_ACE_Common_KeybindToggle">
<English>Toggle</English>
<Polish>переключить</Polish>
Expand Down
2 changes: 1 addition & 1 deletion addons/hearing/functions/fnc_removeEarplugs.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 0 additions & 17 deletions addons/hearing/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,6 @@
<Chinese>你沒有耳塞</Chinese>
<Turkish>Kulak Tıkacın Yok</Turkish>
</Key>
<Key ID="STR_ACE_Hearing_Inventory_Full">
<English>No inventory space</English>
<German>Kein Platz im Inventar</German>
<Spanish>Sin espacio en el inventario</Spanish>
<Polish>Brak miejsca w ekwipunku</Polish>
<French>Il n'y a plus de place dans l'inventaire.</French>
<Czech>Není místo v inventáři</Czech>
<Italian>Non hai abbastanza spazio</Italian>
<Portuguese>Não há espaço no inventário</Portuguese>
<Hungarian>Nincs több hely</Hungarian>
<Russian>Нет места в инвентаре</Russian>
<Japanese>インベントリに空きがありません</Japanese>
<Korean>넣을 공간이 없습니다</Korean>
<Chinesesimp>无可用空间</Chinesesimp>
<Chinese>無可用空間</Chinese>
<Turkish>Envanterin de alan yok</Turkish>
</Key>
<Key ID="STR_ACE_Hearing_DisableEarRinging_DisplayName">
<English>Disable ear ringing</English>
<French>Désactiver les bourdonnements</French>
Expand Down
18 changes: 3 additions & 15 deletions addons/interaction/ACE_Settings.hpp
Original file line number Diff line number Diff line change
@@ -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;
};
};
8 changes: 8 additions & 0 deletions addons/interaction/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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'))];);
Dystopian marked this conversation as resolved.
Show resolved Hide resolved
};
};
};
};
Expand Down
4 changes: 4 additions & 0 deletions addons/interaction/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ PREP(pardon);
PREP(canPullOutBody);
PREP(pullOutBody);

// Weapon Attachments
PREP(getWeaponAttachmentsActions);
PREP(switchWeaponAttachment);

// interaction with doors
PREP(getDoor);
PREP(getGlassDoor);
Expand Down
6 changes: 6 additions & 0 deletions addons/interaction/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
2 changes: 2 additions & 0 deletions addons/interaction/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
{
Expand Down
68 changes: 68 additions & 0 deletions addons/interaction/functions/fnc_getWeaponAttachmentsActions.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "script_component.hpp"
/*
* Author: mharis001, Dystopian
* Returns children actions for weapon attachment switching.
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* Actions <ARRAY>
*
* Example:
* player call ace_interaction_fnc_getWeaponAttachmentsActions
*
* Public: No
*/

params ["_unit"];

[_unit, {
params ["_unit"];

private _currentWeapon = currentWeapon _unit;
Dystopian marked this conversation as resolved.
Show resolved Hide resolved
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);
59 changes: 59 additions & 0 deletions addons/interaction/functions/fnc_switchWeaponAttachment.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "script_component.hpp"
/*
* Author: mharis001, Dystopian
* Switches weapon attachment.
*
* Arguments:
* 0: Target <OBJECT>
* 1: Player (not used) <OBJECT>
* 2: Action params <ARRAY>
*
* 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;
31 changes: 31 additions & 0 deletions addons/interaction/initSettings.sqf
Original file line number Diff line number Diff line change
@@ -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
Dystopian marked this conversation as resolved.
Show resolved Hide resolved
] call CBA_fnc_addSetting;
12 changes: 12 additions & 0 deletions addons/interaction/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1203,5 +1203,17 @@
<Spanish>Romper parabrisas</Spanish>
<Turkish>Ön camı parçala</Turkish>
</Key>
<Key ID="STR_ACE_Interaction_weaponAttachmentsAttach">
<English>Attach %1</English>
<Russian>Установить %1</Russian>
</Key>
<Key ID="STR_ACE_Interaction_weaponAttachmentsDetach">
<English>Detach %1</English>
<Russian>Снять %1</Russian>
</Key>
<Key ID="STR_ACE_Interaction_weaponAttachments_Description">
<English>Enables attach/detach weapon attachment actions for current weapon.</English>
<Russian>Включает действия Установить/Снять для приспособлений текущего оружия.</Russian>
</Key>
</Package>
</Project>
2 changes: 1 addition & 1 deletion addons/main/script_mod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down