Skip to content

Commit

Permalink
Arsenal - Improvements to 3DEN attribute (#6849)
Browse files Browse the repository at this point in the history
* Improvements to arsenal 3DEN attribute

* Better alignment of button

* Remove magazineGroups copy
  • Loading branch information
mharis001 authored and PabstMirror committed Mar 12, 2019
1 parent 2ff614c commit 695416d
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 4 deletions.
41 changes: 38 additions & 3 deletions addons/arsenal/Cfg3DEN.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand All @@ -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};
};
};
};
};
Expand Down
3 changes: 3 additions & 0 deletions addons/arsenal/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions addons/arsenal/defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "×"
Expand Down
75 changes: 75 additions & 0 deletions addons/arsenal/functions/fnc_attributeAddCompatible.sqf
Original file line number Diff line number Diff line change
@@ -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 <CONTROL>
*
* 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);
32 changes: 32 additions & 0 deletions addons/arsenal/functions/fnc_attributeCategory.sqf
Original file line number Diff line number Diff line change
@@ -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 <CONTROL>
* 1: Category <NUMBER>
*
* 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);
49 changes: 49 additions & 0 deletions addons/arsenal/functions/fnc_attributeImport.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "script_component.hpp"
/*
* Author: mharis001
* Handles importing items list from clipboard into 3DEN attribute.
*
* Arguments:
* 0: Attribute controls group <CONTROL>
*
* 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);
6 changes: 5 additions & 1 deletion addons/arsenal/functions/fnc_attributeLoad.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
9 changes: 9 additions & 0 deletions addons/arsenal/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,15 @@
<Italian>Esporta l'attuale lista di elementi come un array, per essere usati negli script</Italian>
<Polish>Eksportuj obecną listę przedmiotów jako tablicę do wykorzystania w skryptach</Polish>
</Key>
<Key ID="STR_ACE_Arsenal_AttributeImport_Tooltip">
<English>Import items list array from clipboard (should be the same format as export)</English>
</Key>
<Key ID="STR_ACE_Arsenal_AttributeAddCompatible_DisplayName">
<English>Add Compatible Items</English>
</Key>
<Key ID="STR_ACE_Arsenal_AttributeAddCompatible_Tooltip">
<English>Will automatically add compatible attachments or magazines (based on selected category) for all weapons in current items list</English>
</Key>
<Key ID="STR_ACE_Arsenal_statTTL">
<English>Time to live</English>
<French>Durée de vie</French>
Expand Down

0 comments on commit 695416d

Please sign in to comment.