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 - Conditional on sorts #7889

Merged
merged 4 commits into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions addons/arsenal/ACE_Arsenal_Sorts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class GVAR(sorts) {
displayName = "";
tabs[] = {{}, {}};
statement = "";
condition = "true";
};

class ACE_alphabetically: sortBase {
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions addons/arsenal/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions addons/arsenal/functions/fnc_addSort.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -35,7 +36,8 @@ params [
["_tabs", [[], []], [[]], 2],
["_class", "", [""]],
["_displayName", "", [""]],
["_statement", {}, [{}]]
["_statement", {}, [{}]],
["_condition", {true}, [{}]]
];

_tabs params [
Expand All @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion addons/arsenal/functions/fnc_compileSorts.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions addons/arsenal/functions/fnc_fillSort.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
14 changes: 10 additions & 4 deletions addons/arsenal/functions/fnc_sortPanel.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
};
Expand Down
19 changes: 19 additions & 0 deletions addons/arsenal/functions/fnc_sortStatement_amount.sqf
Original file line number Diff line number Diff line change
@@ -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