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

Arsenal - Add Sorting Algorithms #7719

Merged
merged 18 commits into from
Aug 18, 2020
43 changes: 43 additions & 0 deletions addons/arsenal/ACE_Arsenal_Sorts.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class GVAR(sorts) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the scope entry and as a result the sortBase class necessary? I think its reasonable to have all sorting algorithms defined here be public.

Also, fix spaces after commas in this file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to add properties in the future this class would be useful, it also keeps it inline with the rest of arsenal

class sortBase {
scope = 1;
displayName = "";
tabs[] = {{}, {}};
statement = "";
};

class ACE_alphabetically: sortBase {
scope = 2;
displayName = "$STR_a3_rscdisplayarsenal_sort_alphabet";
tabs[] = {{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14}, {0,1,2,3,4,5,6,7}};
statement = QUOTE({});
};

class ACE_mod: sortBase {
scope = 2;
displayName = "$STR_a3_rscdisplayarsenal_sort_mod";
tabs[] = {{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14}, {0,1,2,3,4,5,6,7}};
statement = QUOTE(_this call FUNC(sortStatement_mod));
};

class ACE_mass: sortBase {
scope = 2;
displayName = "Sort by weight";
tabs[] = {{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14}, {}};
statement = QUOTE(_this call FUNC(sortStatement_mass));
};

class ACE_load: sortBase {
scope = 2;
displayName = "Sort by load";
tabs[] = {{3,4,5}, {}};
statement = QUOTE(getContainerMaxLoad configName _this);
};

class ACE_rateOfFire: sortBase {
scope = 2;
displayName = "Sort by rate of fire";
tabs[] = {{0,1,2}, {}};
statement = QUOTE(_this call FUNC(sortStatement_rateOfFire));
};
};
6 changes: 6 additions & 0 deletions addons/arsenal/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
PREP(addDefaultLoadout);
PREP(addListBoxItem);
PREP(addSort);
PREP(addStat);
PREP(addVirtualItems);
PREP(attributeAddCompatible);
Expand All @@ -26,10 +27,12 @@ PREP(buttonLoadoutsShare);
PREP(buttonStats);
PREP(buttonStatsPage);
PREP(clearSearchbar);
PREP(compileSorts);
PREP(compileStats);
PREP(fillLeftPanel);
PREP(fillLoadoutsList);
PREP(fillRightPanel);
PREP(fillSort);
PREP(handleLoadoutsSearchbar);
PREP(handleMouse);
PREP(handleScrollWheel);
Expand Down Expand Up @@ -59,6 +62,9 @@ PREP(removeVirtualItems);
PREP(scanConfig);
PREP(showItem);
PREP(sortPanel);
PREP(sortStatement_mass);
PREP(sortStatement_rateOfFire);
PREP(sortStatement_mod);
PREP(statBarStatement_accuracy);
PREP(statBarStatement_default);
PREP(statBarStatement_impact);
Expand Down
3 changes: 1 addition & 2 deletions addons/arsenal/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ PREP_RECOMPILE_START;
PREP_RECOMPILE_END;

// Arsenal
GVAR(modList) = ["", "curator", "kart", "heli", "mark", "expansion", "expansionpremium"];

[QGVAR(camInverted), "CHECKBOX", localize LSTRING(invertCameraSetting), localize LSTRING(settingCategory), false] call CBA_Settings_fnc_init;
[QGVAR(enableModIcons), "CHECKBOX", [LSTRING(modIconsSetting), LSTRING(modIconsTooltip)], localize LSTRING(settingCategory), true] call CBA_Settings_fnc_init;
[QGVAR(fontHeight), "SLIDER", [LSTRING(fontHeightSetting), LSTRING(fontHeightTooltip)], localize LSTRING(settingCategory), [1, 10, 4.5, 1]] call CBA_Settings_fnc_init;
Expand Down Expand Up @@ -58,6 +56,7 @@ GVAR(modList) = ["", "curator", "kart", "heli", "mark", "expansion", "expansionp
}] call CBA_fnc_addEventHandler;

call FUNC(compileStats);
call FUNC(compileSorts);

[QUOTE(ADDON), {!isNil QGVAR(camera)}] call CBA_fnc_registerFeatureCamera;

Expand Down
3 changes: 2 additions & 1 deletion addons/arsenal/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CfgPatches {
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_common"};
author = ECSTRING(common,ACETeam);
authors[] = {"alganthe", "mharis001"};
authors[] = {"alganthe", "mharis001", "SynixeBrett"};
url = ECSTRING(main,URL);
VERSION_CONFIG;
};
Expand All @@ -19,4 +19,5 @@ class CfgPatches {
#include "Cfg3DEN.hpp"
#include "CfgEventHandlers.hpp"
#include "RscDisplayMain.hpp"
#include "ACE_Arsenal_Sorts.hpp"
#include "ACE_Arsenal_Stats.hpp"
3 changes: 0 additions & 3 deletions addons/arsenal/defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,6 @@
private _dlcName = _this call GETDLC;\
if (_dlcName != "") then {\
_ctrlPanel lbsetpictureright [_lbAdd,(modParams [_dlcName,["logo"]]) param [0,""]];\
_modID = GVAR(modList) find _dlcName;\
if (_modID < 0) then {_modID = GVAR(modList) pushback _dlcName;};\
_ctrlPanel lbsetvalue [_lbAdd,_modID];\
};\
};

Expand Down
8 changes: 2 additions & 6 deletions addons/arsenal/functions/fnc_addListBoxItem.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private _cacheNamespace = _ctrlPanel; //For better readability.

private _cachedItemInfo = _cacheNamespace getVariable [_configCategory+_className, []];

//_cachedItemInfo == [_displayName, _itemPicture, _modPicture, _modID]
//_cachedItemInfo == [_displayName, _itemPicture, _modPicture]
if (_cachedItemInfo isEqualTo []) then {//Not in cache. So get info and put into cache.

private _configPath = configFile >> _configCategory >> _className;
Expand All @@ -41,22 +41,18 @@ if (_cachedItemInfo isEqualTo []) then {//Not in cache. So get info and put into

if (_dlcName != "") then {
_cachedItemInfo set [2, (modParams [_dlcName,["logo"]]) param [0,""]];//mod picture
_modID = GVAR(modList) find _dlcName;
if (_modID < 0) then {_modID = GVAR(modList) pushback _dlcName;};//We keep a ordered list of all mods for sorting later.
_cachedItemInfo set [3, _modID];//mod ID
} else {
_cachedItemInfo set [2, ""];//mod picture
_cachedItemInfo set [3, 0];//mod ID
};
_cacheNamespace setVariable [_configCategory+_className, _cachedItemInfo];
};

_cachedItemInfo params ["_displayName", "_itemPicture", "_modPicture", "_modID"];
_cachedItemInfo params ["_displayName", "_itemPicture", "_modPicture"];

private _lbAdd = _ctrlPanel lbAdd _displayName;

_ctrlPanel lbSetData [_lbAdd, _className];
_ctrlPanel lbSetPicture [_lbAdd, _itemPicture];
_ctrlPanel lbSetPictureRight [_lbAdd,["",_modPicture] select (GVAR(enableModIcons))];
_ctrlPanel lbSetValue [_lbAdd,_modID];
_ctrlPanel lbSetTooltip [_lbAdd, format ["%1\n%2", _displayName, _className]];
70 changes: 70 additions & 0 deletions addons/arsenal/functions/fnc_addSort.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "script_component.hpp"
/*
* Author: SynixeBrett
* Add a custom sorting method.
*
* Arguments:
* 1: Tabs to add the stat to (ARRAY of ARRAYS)
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
* 1.1 Left tab indexes (ARRAY of NUMBERS)
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
* 1.2 Right tab indexes (ARRAY of NUMBERS)
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
* 2: Sort class (STRING) (A unique string for each algorithm)
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
* 3: Display name (STRING)
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
* 4: Algorithm (CODE)
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
*
* Return Value:
* 0: Array of IDs (ARRAY of STRINGS)
*
* Example:
* [[[0, 1]], "fireRateSort", "Sort by fire rate", {
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
params ["_itemCfg"];
private _fireModes = getArray (_itemCfg >> "modes");
private _fireRate = [];

{
_fireRate pushBackUnique (getNumber (_itemCfg >> _x >> "reloadTime"));
} foreach _fireModes;

_fireRate sort true;
_fireRate param [0, 0]
}] call ACE_arsenal_fnc_addSort;
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
*
* Public: Yes
*/
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved

params [
["_tabs", [[], []], [[]], 2],
["_class", "", [""]],
["_displayName", "", [""]],
["_statement", {}, [{}]]
];

_tabs params [
["_leftTabs", [], [[]]],
["_rightTabs", [], [[]]]
];

call FUNC(compileSorts);

private _returnArray = [];

private _fnc_addToTabs = {
params ["_tabsList", "_tabsToAddTo", "_sideString"];
{
private _arrayToSave = +_finalArray;
_arrayToSave set [0, ([_class, _sideString, [str _x, format ["0%1", _x]] select (_x < 10)] joinString "")];
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
_returnArray pushBack (_arrayToSave select 0);
(_tabsList select _x) pushBack _arrayToSave;
} foreach _tabsToAddTo;
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
};

_finalArray = ["", _displayName, _statement];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing private.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as the existing arsenal code, it should be fixed in both places in a follow up PR


if (count _leftTabs > 0) then {
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
[GVAR(sortListLeftPanel), _leftTabs, "L", 0] call _fnc_addToTabs;
};

if (count _rightTabs > 0) then {
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
[GVAR(sortListRightPanel), _rightTabs, "R", 1] call _fnc_addToTabs;
};

_returnArray
4 changes: 2 additions & 2 deletions addons/arsenal/functions/fnc_addStat.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* Arguments:
* 0: Tabs to add the stat to (ARRAY of ARRAYS)
* 0.1: Left tab indexes (ARRAY of NUMBERS)
* 0.1 Left tab indexes (ARRAY of NUMBERS)
* 0.2 Right tab indexes (ARRAY of NUMBERS)
* 1: Stat class (STRING) (A unique string for each stat)
* 2: Config entries to pass (ARRAY of STRINGS)
Expand All @@ -14,7 +14,7 @@
* 4.1 Show bar (BOOL)
* 4.2 Show text (BOOL)
* 5: Array of statements (ARRAY of ARRAYS)
* 5.1: Bar code (CODE)
* 5.1 Bar code (CODE)
* 5.2 Text code (CODE)
* 5.3 Condition code (CODE)
* 6: Priority (NUMBER) (Optional)
Expand Down
82 changes: 82 additions & 0 deletions addons/arsenal/functions/fnc_compileSorts.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include "script_component.hpp"
/*
* Author: SynixeBrett
* Create the internal stats arrays when needed for the first time
*
* Arguments:
* None
*
* Return Value:
* None
*
* Public: No
*/

if (!isNil QGVAR(sortListLeftPanel)) exitWith {};

private _fnc_addToTabs = {
params ["_tabsList", "_tabsToAddTo", "_sideString"];
{
private _arrayToSave = +_finalArray;
_arrayToSave set [0, ([_class, _sideString, [str _x, format ["0%1", _x]] select (_x < 10)] joinString "")];
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
(_tabsList select _x) pushBack _arrayToSave;
} foreach _tabsToAddTo;
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
};

private _sortListLeftPanel = [
[], // Primary 0
[], // Handgun 1
[], // Launcher 2
[], // Uniform 3
[], // Vests 4
[], // Backpacks 5
[], // Headgear 6
[], // Goggles 7
[], // NVGs 8
[], // Binoculars 9
[], // Map 10
[], // GPS 11
[], // Radio 12
[], // Compass 13
[] // Watch 14
];

private _sortListRightPanel = [
[], // Optics 0
[], // Side accs 1
[], // Muzzle 2
[], // Bipod 3
[], // Mag 4
[], // Throw 5
[], // Put 6
[] // Misc 7
];

//------------------------- Config handling
private _configEntries = "(getNumber (_x >> 'scope')) == 2" configClasses (configFile >> QGVAR(sorts));

{
private _finalArray = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary, can just add the private to L70?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how stats did it, if we change it here it should be changed in stats too


private _class = configName _x;
private _displayName = getText (_x >> "displayName");
private _statement = getText (_x >> "statement");
(getArray (_x >> "tabs")) params ["_leftTabsList", "_rightTabsList"];

if (_statement != "") then {
_statement = compile _statement;
};

_finalArray = ["", _displayName, _statement];

if (count _leftTabsList > 0) then {
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
[_sortListLeftPanel, _leftTabsList, "L"] call _fnc_addToTabs;
};

if (count _rightTabsList > 0) then {
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
[_sortListRightPanel, _rightTabsList, "R"] call _fnc_addToTabs;
};
} foreach _configEntries;

missionNamespace setVariable [QGVAR(sortListLeftPanel), _sortListLeftPanel];
missionNamespace setVariable [QGVAR(sortListRightPanel), _sortListRightPanel];
9 changes: 6 additions & 3 deletions addons/arsenal/functions/fnc_fillLeftPanel.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ _ctrlPanel ctrlCommit FADE_DELAY;

_ctrlPanel lbSetCurSel -1;

// Fill sort options
[_display, _control] call FUNC(fillSort);

// Handle icons and filling
switch true do {
case (_ctrlIDC in [IDC_buttonPrimaryWeapon, IDC_buttonHandgun, IDC_buttonSecondaryWeapon]) : {
Expand Down Expand Up @@ -138,8 +141,8 @@ switch true do {
{
{
if (
getnumber (_x >> "disabled") == 0 &&
{getText (_x >> "head") != ""} &&
getnumber (_x >> "disabled") == 0 &&
{getText (_x >> "head") != ""} &&
{configName _x != "Default"}
) then {
private _configName = configName _x;
Expand All @@ -162,7 +165,7 @@ switch true do {
{
["CfgUnitInsignia", configName _x, _ctrlPanel, "texture"] call FUNC(addListBoxItem);
} foreach ("true" configClasses (configFile >> "CfgUnitInsignia"));

{
private _displayName = getText (_x >> "displayName");
private _className = configName _x;
Expand Down
Loading