From 695416dfe774580df62995728fe932ef05091a97 Mon Sep 17 00:00:00 2001 From: mharis001 <34453221+mharis001@users.noreply.github.com> Date: Tue, 12 Mar 2019 12:26:40 -0400 Subject: [PATCH] Arsenal - Improvements to 3DEN attribute (#6849) * Improvements to arsenal 3DEN attribute * Better alignment of button * Remove magazineGroups copy --- addons/arsenal/Cfg3DEN.hpp | 41 +++++++++- addons/arsenal/XEH_PREP.hpp | 3 + addons/arsenal/defines.hpp | 2 + .../functions/fnc_attributeAddCompatible.sqf | 75 +++++++++++++++++++ .../functions/fnc_attributeCategory.sqf | 32 ++++++++ .../arsenal/functions/fnc_attributeImport.sqf | 49 ++++++++++++ .../arsenal/functions/fnc_attributeLoad.sqf | 6 +- addons/arsenal/stringtable.xml | 9 +++ 8 files changed, 213 insertions(+), 4 deletions(-) create mode 100644 addons/arsenal/functions/fnc_attributeAddCompatible.sqf create mode 100644 addons/arsenal/functions/fnc_attributeCategory.sqf create mode 100644 addons/arsenal/functions/fnc_attributeImport.sqf diff --git a/addons/arsenal/Cfg3DEN.hpp b/addons/arsenal/Cfg3DEN.hpp index 8e79b726b4..8b40f77bfe 100644 --- a/addons/arsenal/Cfg3DEN.hpp +++ b/addons/arsenal/Cfg3DEN.hpp @@ -55,7 +55,7 @@ class Cfg3DEN { }; class Category: ctrlToolboxPictureKeepAspect { idc = IDC_ATTRIBUTE_CATEGORY; - onToolBoxSelChanged = QUOTE([ctrlParentControlsGroup (_this select 0)] call FUNC(attributeAddItems)); + onToolBoxSelChanged = QUOTE([ARR_2(ctrlParentControlsGroup (_this select 0), _this select 1)] call FUNC(attributeCategory)); x = QUOTE(5 * ATTRIBUTE_W); y = QUOTE(15 * ATTRIBUTE_H); w = QUOTE(125 * ATTRIBUTE_W); @@ -129,7 +129,14 @@ class Cfg3DEN { }; class SearchButton: ctrlButtonPicture { idc = IDC_ATTRIBUTE_SEARCH_BUTTON; - onButtonClick = QUOTE(((ctrlParentControlsGroup (_this select 0)) controlsGroupCtrl IDC_ATTRIBUTE_SEARCHBAR) ctrlSetText ''; [ctrlParentControlsGroup (_this select 0)] call FUNC(attributeAddItems)); + onButtonClick = QUOTE( \ + params ['_searchButton']; \ + private _controlsGroup = ctrlParentControlsGroup _searchButton; \ + private _searchBar = _controlsGroup controlsGroupCtrl IDC_ATTRIBUTE_SEARCHBAR; \ + _searchBar ctrlSetText ''; \ + ctrlSetFocus _searchBar; \ + [_controlsGroup] call FUNC(attributeAddItems); \ + ); text = "\a3\Ui_f\data\GUI\RscCommon\RscButtonSearch\search_start_ca.paa"; x = QUOTE(5 * ATTRIBUTE_W); y = QUOTE(101.83 * ATTRIBUTE_H); @@ -140,9 +147,16 @@ class Cfg3DEN { class SearchBar: ctrlEdit { idc = IDC_ATTRIBUTE_SEARCHBAR; onKeyUp = QUOTE([ctrlParentControlsGroup (_this select 0)] call FUNC(attributeAddItems)); + onMouseButtonClick = QUOTE( \ + params [ARR_2('_searchBar','_button')]; \ + if (_button != 1) exitWith {}; \ + _searchBar ctrlSetText ''; \ + ctrlSetFocus _searchBar; \ + [ctrlParentControlsGroup _searchBar] call FUNC(attributeAddItems); \ + ); x = QUOTE(11 * ATTRIBUTE_W); y = QUOTE(101.83 * ATTRIBUTE_H); - w = QUOTE(55 * ATTRIBUTE_W); + w = QUOTE(40 * ATTRIBUTE_W); h = QUOTE(5 * ATTRIBUTE_H); }; class ClearButton: ctrlButton { @@ -162,6 +176,27 @@ class Cfg3DEN { tooltip = CSTRING(AttributeExport_Tooltip); x = QUOTE(79 * ATTRIBUTE_W); }; + class ImportButton: ClearButton { + idc = IDC_ATTRIBUTE_IMPORT_BUTTON; + onButtonClick = QUOTE([ctrlParentControlsGroup (_this select 0)] call FUNC(attributeImport)); + text = CSTRING(buttonImportText); + tooltip = CSTRING(AttributeImport_Tooltip); + x = QUOTE(53 * ATTRIBUTE_W); + }; + class AddCompatible: ctrlButton { + idc = IDC_ATTRIBUTE_ADD_COMPATIBLE; + style = ST_CENTER; + onButtonClick = QUOTE([ctrlParentControlsGroup (_this select 0)] call FUNC(attributeAddCompatible)); + text = CSTRING(AttributeAddCompatible_DisplayName); + tooltip = CSTRING(AttributeAddCompatible_Tooltip); + font = "RobotoCondensedLight"; + x = QUOTE(98.75 * ATTRIBUTE_W); + y = QUOTE(10.5 * ATTRIBUTE_H); + w = QUOTE(31.25 * ATTRIBUTE_W); + h = QUOTE(4 * ATTRIBUTE_H); + sizeEx = QUOTE(4 * ATTRIBUTE_H); + colorBackground[] = {0, 0, 0, 0.5}; + }; }; }; }; diff --git a/addons/arsenal/XEH_PREP.hpp b/addons/arsenal/XEH_PREP.hpp index 3e64d3654e..656fc5b1d5 100644 --- a/addons/arsenal/XEH_PREP.hpp +++ b/addons/arsenal/XEH_PREP.hpp @@ -2,9 +2,12 @@ PREP(addDefaultLoadout); PREP(addListBoxItem); PREP(addStat); PREP(addVirtualItems); +PREP(attributeAddCompatible); PREP(attributeAddItems); +PREP(attributeCategory); PREP(attributeClear); PREP(attributeDblClick); +PREP(attributeImport); PREP(attributeInit); PREP(attributeKeyDown); PREP(attributeLoad); diff --git a/addons/arsenal/defines.hpp b/addons/arsenal/defines.hpp index 9210ed9b2e..35d2edc461 100644 --- a/addons/arsenal/defines.hpp +++ b/addons/arsenal/defines.hpp @@ -162,6 +162,8 @@ #define IDC_ATTRIBUTE_SEARCHBAR 8106 #define IDC_ATTRIBUTE_CLEAR_BUTTON 8107 #define IDC_ATTRIBUTE_EXPORT_BUTTON 8108 +#define IDC_ATTRIBUTE_IMPORT_BUTTON 8109 +#define IDC_ATTRIBUTE_ADD_COMPATIBLE 8110 #define SYMBOL_ITEM_NONE "−" #define SYMBOL_ITEM_REMOVE "×" diff --git a/addons/arsenal/functions/fnc_attributeAddCompatible.sqf b/addons/arsenal/functions/fnc_attributeAddCompatible.sqf new file mode 100644 index 0000000000..4f84f9624c --- /dev/null +++ b/addons/arsenal/functions/fnc_attributeAddCompatible.sqf @@ -0,0 +1,75 @@ +#include "script_component.hpp" +#include "..\defines.hpp" +/* + * Author: mharis001 + * Adds compatible attachments or magazines for all weapons in 3DEN attribute. + * + * Arguments: + * 0: Attribute controls group + * + * Return Value: + * None + * + * Example: + * [CONTROL] call ace_arsenal_fnc_attributeAddCompatible + * + * Public: No + */ + +params ["_controlsGroup"]; + +private _category = lbCurSel (_controlsGroup controlsGroupCtrl IDC_ATTRIBUTE_CATEGORY); + +// Exit if selected category is not attachments or magazines +if !(_category in [4, 5, 6, 7, 8]) exitWith {}; + +private _configItems = +(uiNamespace getVariable [QGVAR(configItems), []]); +private _attributeValue = uiNamespace getVariable [QGVAR(attributeValue), [[], 0]]; +_attributeValue params ["_attributeItems"]; + +// Get list of all weapons in attribute items +(_configItems select 0) params ["_primaryWeapons", "_secondaryWeapons", "_handgunWeapons"]; +private _attributeWeapons = _attributeItems select {_x in _primaryWeapons || {_x in _secondaryWeapons} || {_x in _handgunWeapons}}; + +// Add compatible attachments or magazines to attribute +private _cfgWeapons = configFile >> "CfgWeapons"; +private _itemsToAdd = []; + +if (_category == 8) then { + private _magazineGroups = uiNamespace getVariable QGVAR(magazineGroups); + private _cfgMagazines = configFile >> "CfgMagazines"; + + { + private _weaponConfig = _cfgWeapons >> _x; + + { + private _muzzleConfig = if (_x == "this") then {_weaponConfig} else {_weaponConfig >> _x}; + + // Only add existent magazines and ensure correct classname case + private _magazines = getArray (_muzzleConfig >> "magazines") select {isClass (_cfgMagazines >> _x)}; + _magazines = _magazines apply {configName (_cfgMagazines >> _x)}; + _itemsToAdd append _magazines; + + { + _itemsToAdd append ([_magazineGroups, toLower _x] call CBA_fnc_hashGet); + } forEach getArray (_muzzleConfig >> "magazineWell"); + } forEach getArray (_weaponConfig >> "muzzles"); + } forEach _attributeWeapons; +} else { + private _attachmentCategory = _category - 4; + private _filter = ["optic", "pointer", "muzzle", "bipod"] select _attachmentCategory; + + { + _itemsToAdd append ([_x, _filter] call CBA_fnc_compatibleItems); + } forEach _attributeWeapons; + + // Only add items with scope of 2 and ensure correct classname case + _itemsToAdd = _itemsToAdd select {getNumber (_cfgWeapons >> _x >> "scope") == 2}; + _itemsToAdd = _itemsToAdd apply {configName (_cfgWeapons >> _x)}; +}; + +_attributeItems append _itemsToAdd; +_attributeValue set [0, _attributeItems arrayIntersect _attributeItems]; + +// Refresh the list for new items +[_controlsGroup] call FUNC(attributeAddItems); diff --git a/addons/arsenal/functions/fnc_attributeCategory.sqf b/addons/arsenal/functions/fnc_attributeCategory.sqf new file mode 100644 index 0000000000..e0c0468f8a --- /dev/null +++ b/addons/arsenal/functions/fnc_attributeCategory.sqf @@ -0,0 +1,32 @@ +#include "script_component.hpp" +#include "..\defines.hpp" +/* + * Author: mharis001 + * Handles changing the category in 3DEN attribute. + * + * Arguments: + * 0: Attribute controls group + * 1: Category + * + * Return Value: + * None + * + * Example: + * [CONTROL, 0] call ace_arsenal_fnc_attributeCategory + * + * Public: No + */ + +params ["_controlsGroup", "_category"]; + +// Store selected category +uiNamespace setVariable [QGVAR(attributeCategory), _category]; + +// Show add compatible items button when category is attachments or magazines +private _compatibleButton = _controlsGroup controlsGroupCtrl IDC_ATTRIBUTE_ADD_COMPATIBLE; +private _enable = _category in [4, 5, 6, 7, 8]; +_compatibleButton ctrlEnable _enable; +_compatibleButton ctrlShow _enable; + +// Refresh the list for selected category +[_controlsGroup] call FUNC(attributeAddItems); diff --git a/addons/arsenal/functions/fnc_attributeImport.sqf b/addons/arsenal/functions/fnc_attributeImport.sqf new file mode 100644 index 0000000000..ec56df4b56 --- /dev/null +++ b/addons/arsenal/functions/fnc_attributeImport.sqf @@ -0,0 +1,49 @@ +#include "script_component.hpp" +/* + * Author: mharis001 + * Handles importing items list from clipboard into 3DEN attribute. + * + * Arguments: + * 0: Attribute controls group + * + * Return Value: + * None + * + * Example: + * [CONTROL] call ace_arsenal_fnc_attributeImport + * + * Public: No + */ + +params ["_controlsGroup"]; + +private _importList = call compile copyFromClipboard; + +// Verify import list is in correct format +if (isNil "_importList" || {!(_importList isEqualType [])} || {!(_importList isEqualTypeAll "")}) exitWith { + playSound ["3DEN_notificationWarning", true]; +}; + +// Ensure imported items are in scanned config array and classname case is correct +private _configItems = +(uiNamespace getVariable [QGVAR(configItems), []]); +private _configItemsFlat = _configItems select [2, 16]; +_configItemsFlat append (_configItems select 0); +_configItemsFlat append (_configItems select 1); + +private _filteredList = []; + +{ + private _item = _x; + { + private _index = _x findIf {_x == _item}; + if (_index > -1) then { + _filteredList pushBackUnique (_x select _index); + }; + } forEach _configItemsFlat; +} forEach _importList; + +private _attributeValue = uiNamespace getVariable [QGVAR(attributeValue), [[], 0]]; +_attributeValue set [0, _filteredList]; + +// Refresh the list for new items +[_controlsGroup] call FUNC(attributeAddItems); diff --git a/addons/arsenal/functions/fnc_attributeLoad.sqf b/addons/arsenal/functions/fnc_attributeLoad.sqf index 439ec2ff36..355d5e113a 100644 --- a/addons/arsenal/functions/fnc_attributeLoad.sqf +++ b/addons/arsenal/functions/fnc_attributeLoad.sqf @@ -34,4 +34,8 @@ if (_value select 1 > 0) then { (_controlsGroup controlsGroupCtrl IDC_ATTRIBUTE_LIST_RIGHT) ctrlSetText SYMBOL_ITEM_REMOVE; }; -[_controlsGroup] call FUNC(attributeAddItems); +// Trigger category selection for last selected category to populate list +private _category = uiNamespace getVariable [QGVAR(attributeCategory), 0]; +(_controlsGroup controlsGroupCtrl IDC_ATTRIBUTE_CATEGORY) lbSetCurSel _category; + +[_controlsGroup, _category] call FUNC(attributeCategory); diff --git a/addons/arsenal/stringtable.xml b/addons/arsenal/stringtable.xml index 564770cb58..617d467fce 100644 --- a/addons/arsenal/stringtable.xml +++ b/addons/arsenal/stringtable.xml @@ -866,6 +866,15 @@ Esporta l'attuale lista di elementi come un array, per essere usati negli script Eksportuj obecną listę przedmiotów jako tablicę do wykorzystania w skryptach + + Import items list array from clipboard (should be the same format as export) + + + Add Compatible Items + + + Will automatically add compatible attachments or magazines (based on selected category) for all weapons in current items list + Time to live Durée de vie