Arsenal - Conditional on sorts (#7889)

* Arsenal - conditional on sorts

* fix: zero divisor

* update fnc_addSort

* Update fnc_fillSort.sqf

Co-authored-by: PabstMirror <pabstmirror@gmail.com>
This commit is contained in:
Brett 2020-11-02 12:23:44 -06:00 committed by GitHub
parent 260706cb9f
commit 9226035d59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 57 additions and 11 deletions

View File

@ -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);

View File

@ -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);

View File

@ -10,12 +10,13 @@
* 1: Sort Class (a unique string for each algorithm) <STRING>
* 2: Display Name <STRING>
* 3: Algorithm <CODE>
* 4: Condition (Optional)<CODE>
*
* 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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
};

View File

@ -0,0 +1,19 @@
#include "script_component.hpp"
/*
* Author: SynixeBrett
* Statement to sort items by the amount in inventory.
*
* Arguments:
* 0: Item Config <CONFIG>
* 1: Item Name <STRING>
* 2: Quantity <NUMBER>
*
* Return Value:
* Sorting Value <NUMBER>
*
* Public: No
*/
params ["", "", "_quantity"];
10000 - _quantity