diff --git a/addons/arsenal/ACE_Arsenal_Sorts.hpp b/addons/arsenal/ACE_Arsenal_Sorts.hpp index 6d5125d7ff..ecdd1e68b2 100644 --- a/addons/arsenal/ACE_Arsenal_Sorts.hpp +++ b/addons/arsenal/ACE_Arsenal_Sorts.hpp @@ -4,6 +4,7 @@ class GVAR(sorts) { displayName = ""; tabs[] = {{}, {}}; statement = ""; + condition = "true"; }; class ACE_alphabetically: sortBase { @@ -27,6 +28,14 @@ class GVAR(sorts) { statement = QUOTE(_this call FUNC(sortStatement_mass)); }; + class ACE_amount: sortBase { + scope = 2; + displayName = CSTRING(sortByAmountText); + tabs[] = {{}, {0,1,2,3,4,5,6,7}}; + statement = QUOTE(_this call FUNC(sortStatement_amount)); + condition = QUOTE(_this select 0); // Only show for containers + }; + class ACE_load: sortBase { scope = 2; displayName = CSTRING(sortByLoadText); diff --git a/addons/arsenal/XEH_PREP.hpp b/addons/arsenal/XEH_PREP.hpp index 209f882738..18128f8cc9 100644 --- a/addons/arsenal/XEH_PREP.hpp +++ b/addons/arsenal/XEH_PREP.hpp @@ -64,6 +64,7 @@ PREP(scanConfig); PREP(showItem); PREP(sortPanel); PREP(sortStatement_accuracy); +PREP(sortStatement_amount); PREP(sortStatement_magCount); PREP(sortStatement_mass); PREP(sortStatement_mod); diff --git a/addons/arsenal/functions/fnc_addSort.sqf b/addons/arsenal/functions/fnc_addSort.sqf index 6faa2ba51c..5ef5a8fc90 100644 --- a/addons/arsenal/functions/fnc_addSort.sqf +++ b/addons/arsenal/functions/fnc_addSort.sqf @@ -10,12 +10,13 @@ * 1: Sort Class (a unique string for each algorithm) * 2: Display Name * 3: Algorithm + * 4: Condition (Optional) * * Return Value: * 0: Array of IDs (ARRAY of STRINGS) * * Example: - * [[[0, 1]], "fireRateSort", "Sort by fire rate", { + * [[[0, 1], []], "fireRateSort", "Sort by fire rate", { * params ["_itemCfg"]; * private _fireModes = getArray (_itemCfg >> "modes"); * private _fireRate = []; @@ -35,7 +36,8 @@ params [ ["_tabs", [[], []], [[]], 2], ["_class", "", [""]], ["_displayName", "", [""]], - ["_statement", {}, [{}]] + ["_statement", {}, [{}]], + ["_condition", {true}, [{}]] ]; _tabs params [ @@ -57,7 +59,7 @@ private _fnc_addToTabs = { } forEach _tabsToAddTo; }; -_finalArray = ["", _displayName, _statement]; +_finalArray = ["", _displayName, _statement, _condition]; if !(_leftTabs isEqualTo []) then { [GVAR(sortListLeftPanel), _leftTabs, "L", 0] call _fnc_addToTabs; diff --git a/addons/arsenal/functions/fnc_compileSorts.sqf b/addons/arsenal/functions/fnc_compileSorts.sqf index 423bec30b3..e810f64a9b 100644 --- a/addons/arsenal/functions/fnc_compileSorts.sqf +++ b/addons/arsenal/functions/fnc_compileSorts.sqf @@ -64,13 +64,18 @@ private _configEntries = "(getNumber (_x >> 'scope')) == 2" configClasses (confi private _class = configName _x; private _displayName = getText (_x >> "displayName"); private _statement = getText (_x >> "statement"); + private _condition = getText (_x >> "condition"); (getArray (_x >> "tabs")) params ["_leftTabsList", "_rightTabsList"]; if (_statement != "") then { _statement = compile _statement; }; - _finalArray = ["", _displayName, _statement]; + if (_condition != "") then { + _condition = compile _condition; + }; + + _finalArray = ["", _displayName, _statement, _condition]; if !(_leftTabsList isEqualTo []) then { [_sortListLeftPanel, _leftTabsList, "L"] call _fnc_addToTabs; diff --git a/addons/arsenal/functions/fnc_fillSort.sqf b/addons/arsenal/functions/fnc_fillSort.sqf index a6e93a0508..1f27fd879d 100644 --- a/addons/arsenal/functions/fnc_fillSort.sqf +++ b/addons/arsenal/functions/fnc_fillSort.sqf @@ -90,9 +90,13 @@ private _sortIndex = 0; { if (_x isEqualTo []) exitWith {}; - _sortCtrl lbAdd (_x select 1); - if ((_x select 1) isEqualTo _lastSort) then { - _sortIndex = _forEachIndex; + _x params ["_sortName", "_displayName", "", "_condition"] + if ([_right] call _condition) then { + private _index = _sortCtrl lbAdd _displayName; + _sortCtrl lbSetData [_index, _sortName]; + if (_displayName isEqualTo _lastSort) then { + _sortIndex = _index; + }; }; } forEach _sorts; diff --git a/addons/arsenal/functions/fnc_sortPanel.sqf b/addons/arsenal/functions/fnc_sortPanel.sqf index 91d0614c65..e840b11c07 100644 --- a/addons/arsenal/functions/fnc_sortPanel.sqf +++ b/addons/arsenal/functions/fnc_sortPanel.sqf @@ -97,12 +97,13 @@ private _selected = if (_right) then { _panel lbData _curSel }; -private _mode = 0 max lbCurSel _sortControl; -private _statement = _sorts select _mode select 2; +private _sortName = _sortControl lbData (0 max lbCurSel _sortControl); +private _sortConfig = _sorts select (0 max (_sorts findIf {(_x select 0) isEqualTo _sortName})); +private _statement = _sortConfig select 2; missionNamespace setVariable [ [QGVAR(lastSortLeft), QGVAR(lastSortRight)] select _rightSort, - _sorts select _mode select 1 + _sortConfig select 1 ]; private _for = if (_right) then { @@ -117,8 +118,13 @@ _for do { } else { _panel lbData _i }; + private _quantity = if (_right) then { + parseNumber (_panel lnbText [_i, 2]) + } else { + 0 + }; private _itemCfg = _cfgClass >> _item; - private _value = _itemCfg call _statement; + private _value = [_itemCfg, _item, _quantity] call _statement; if (_value isEqualType 0) then { _value = [_value, 8] call CBA_fnc_formatNumber; }; diff --git a/addons/arsenal/functions/fnc_sortStatement_amount.sqf b/addons/arsenal/functions/fnc_sortStatement_amount.sqf new file mode 100644 index 0000000000..f4e4539d99 --- /dev/null +++ b/addons/arsenal/functions/fnc_sortStatement_amount.sqf @@ -0,0 +1,19 @@ +#include "script_component.hpp" +/* + * Author: SynixeBrett + * Statement to sort items by the amount in inventory. + * + * Arguments: + * 0: Item Config + * 1: Item Name + * 2: Quantity + * + * Return Value: + * Sorting Value + * + * Public: No +*/ + +params ["", "", "_quantity"]; + +10000 - _quantity