From 7a30a439c1367fffbd77ee2cdc917a060dd20b10 Mon Sep 17 00:00:00 2001 From: He-Man Date: Tue, 13 Dec 2016 17:11:18 +0100 Subject: [PATCH] Added Filter for TraderMenu --- .../traders/EPOCH_NPCTraderMenuFilter.sqf | 197 +++++++----------- 1 file changed, 76 insertions(+), 121 deletions(-) diff --git a/Sources/epoch_code/compile/traders/EPOCH_NPCTraderMenuFilter.sqf b/Sources/epoch_code/compile/traders/EPOCH_NPCTraderMenuFilter.sqf index bcd45d65..9e67c4ea 100644 --- a/Sources/epoch_code/compile/traders/EPOCH_NPCTraderMenuFilter.sqf +++ b/Sources/epoch_code/compile/traders/EPOCH_NPCTraderMenuFilter.sqf @@ -23,31 +23,33 @@ NOTHING */ disableSerialization; -//[[[cog import generate_private_arrays ]]] -private ["_aiItems","_bpck","_config","_filterArray","_filterItems","_filterMagazines","_filterVehicle","_filterWeapons","_index","_isPlayerFilter","_item","_itemCount","_itemIcon","_itemName","_itemOfferCount","_items","_name","_offerArray","_picture","_qty","_qtys","_sizeOut","_slot","_type","_vehicles","_wpn"]; -//[[[end]]] +private ["_item","_itemCount","_itemOfferCount","_wpn","_bpck","_config","_name","_picture","_type","_vehicles","_sizeOut","_offerArray","_itemName","_itemIcon","_qty","_items","_qtys","_aiItems","_filterArray","_filterMagazines","_filterItems","_filterVehicle","_slot","_isPlayerFilter"]; params ["_control","_index"]; - +_display = (finddisplay -8); +_playerlb = (_display displayCtrl 41500); +_Traderlb = (_display displayCtrl 41503); +_config = 'CfgItemSort' call EPOCH_returnConfig; +_MainCategoriearray = getarray (_config >> "MainCategories" >> "Classes"); +_FilterArray = []; +if (_index != 0) then { + { + _MainCategorie = _x; + if (_index == (_MainCategorie select 0)) then { + _subcategories = _MainCategorie select 2; + { + _SubCategorieItems = getArray (_config >> "SubCatergories" >> _x); + { + _FilterArray pushback (tolower _x); + } foreach _SubCategorieItems; + } forEach _subcategories; + }; + } forEach _MainCategoriearray; +}; if !(isNull EPOCH_lastNPCtradeTarget) then { _slot = EPOCH_lastNPCtradeTarget getVariable["AI_SLOT", -1]; _isPlayerFilter = (ctrlIDC _control == 42100); if (_slot != -1) then { - - _filterArray = [ - [true,true,true,true], // all - // [true,false,false,false], // weapons only - [false,true,false,false], // mags only - [false,false,true,false], // items only - [false,false,false,true] // vehicles only - ]; - - //_filterWeapons = ((_filterArray select _index) select 0); - _filterMagazines = ((_filterArray select _index) select 1); - _filterItems = ((_filterArray select _index) select 2); - _filterVehicle = ((_filterArray select _index) select 3); - if (_isPlayerFilter) then { - _sizeOut = lbSize 41501; _offerArray = []; if (_sizeOut > 0) then { @@ -56,135 +58,88 @@ if !(isNull EPOCH_lastNPCtradeTarget) then { _offerArray pushBack _item; }; }; - lbClear 41500; - - if (_filterMagazines) then { - { - // make sure this exceeds the item count already offered - _item = _x; - _itemCount = {_x == _item} count magazines player; - _itemOfferCount = {_x == _item} count _offerArray; - if (_itemCount > _itemOfferCount) then { - _offerArray pushBack _item; - _index = lbAdd [41500, _x call EPOCH_itemDisplayName]; - lbSetData [41500, _index, _x]; - lbSetPicture [41500, _index, _x call EPOCH_itemPicture]; + _playeritems = ((items player)+(magazines player)); + if (primaryWeapon player != "") then { + _playeritems pushback primaryWeapon player; + }; + if (count backpackItems player == 0 && count backpackmagazines player == 0 && backpack player != "") then { + _playeritems pushback backpack player; + }; + + { + _item = _x; + if !(_item isequalto "") then { + if (_index == 0 || (tolower _item) in _FilterArray) then { + _itemCount = {_x == _item} count ((items player)+(magazines player)+[backpack player]+[primaryweapon player]); + _itemOfferCount = {_x == _item} count _offerArray; + if (_itemCount > _itemOfferCount) then { + _offerArray pushBack _item; + _id = lbAdd [41500, _x call EPOCH_itemDisplayName]; + lbSetData [41500, _id, _x]; + lbSetPicture [41500, _id, _x call EPOCH_itemPicture]; + }; }; - } forEach magazines player; - }; - - /* not used currently - if (_filterWeapons) then { - }; - */ - - if (_filterItems) then { - { - _item = _x; - _itemCount = {_x == _item} count items player; - _itemOfferCount = {_x == _item} count _offerArray; - if (_itemCount > _itemOfferCount) then { - _offerArray pushBack _item; - _index = lbAdd [41500, _x call EPOCH_itemDisplayName]; - lbSetData [41500, _index, _x]; - lbSetPicture [41500, _index, _x call EPOCH_itemPicture]; - }; - } forEach items player; - if (primaryWeapon player != "") then { - _wpn = primaryWeapon player; - _offerArray pushback _wpn; - _index = lbAdd [41500, _wpn call EPOCH_itemDisplayName]; - lbSetData [41500, _index, _wpn]; - lbSetPicture [41500, _index, _wpn call EPOCH_itemPicture]; }; - if (count backpackItems player == 0 && count backpackmagazines player == 0 && backpack player != "") then { - _bpck = Backpack player; - _offerArray pushback _bpck; - _index = lbAdd [41500, _bpck call EPOCH_itemDisplayName]; - lbSetData [41500, _index, _bpck]; - lbSetPicture [41500, _index, _bpck call EPOCH_itemPicture]; - }; - }; - - if (_filterVehicle) then { - _vehicles = player nearEntities [["LandVehicle","Ship","Air","Tank"], 30]; - { - if (local _x) then { - _type = typeOf _x; + } forEach _playeritems; + + _vehicles = player nearEntities [["LandVehicle","Ship","Air","Tank"], 30]; + { + if (local _x) then { + _type = typeOf _x; + if (_index == 0 || (tolower _type) in _FilterArray) then { _itemCount = { typeOf _x == _type } count _vehicles; _itemOfferCount = { _x == _type } count _offerArray; if (_itemCount > _itemOfferCount) then { _offerArray pushBack _type; - _config = configFile >> "CfgVehicles" >> _type; - _name = getText(_config >> "displayName"); _picture = getText(_config >> "picture"); - - _index = lbAdd[41500, _name]; - lbSetData[41500, _index, _type]; - lbSetPicture[41500, _index, _picture]; + _id = lbAdd[41500, _name]; + lbSetData[41500, _id, _type]; + lbSetPicture[41500, _id, _picture]; }; }; - } forEach _vehicles; - }; - - } else { - + }; + } forEach _vehicles; + _control = (_display displayCtrl 41500); + lbsort _control; + } + else { lbClear 41503; - _sizeOut = lbSize 41502; _offerArray = []; if (_sizeOut > 0) then { for "_i" from 0 to (_sizeOut - 1) do { - _item = lbData [41502, _i]; - _offerArray pushBack _item; + _id = lbData [41502, _i]; + _offerArray pushBack _id; }; }; _aiItems = EPOCH_lastNPCtradeTarget getVariable["AI_ITEMS", []]; if ((count _aiItems) == 2) then { _items = _aiItems select 0; _qtys = _aiItems select 1; + _sortarray = []; { - - _item = _x; - _itemName = ""; - _itemIcon = ""; - if ([_item, "CfgVehicles"] call EPOCH_fnc_isAny) then { - if (_filterVehicle) then { - _itemName = getText(configfile >> "CfgVehicles" >> _item >> "DisplayName"); - _itemIcon = getText(configfile >> "CfgVehicles" >> _item >> "picture"); - }; - } else { - if ([_item, "CfgWeapons"] call EPOCH_fnc_isAny) then { - if (_filterItems) then { - _itemName = getText(configfile >> "CfgWeapons" >> _item >> "DisplayName"); - _itemIcon = getText(configfile >> "CfgWeapons" >> _item >> "picture"); - }; - } else { - if ([_item, "CfgMagazines"] call EPOCH_fnc_isAny) then { - if (_filterMagazines) then { - _itemName = getText(configfile >> "CfgMagazines" >> _item >> "DisplayName"); - _itemIcon = getText(configfile >> "CfgMagazines" >> _item >> "picture"); - }; + _sortarray pushback [_x call EPOCH_itemDisplayName,_x,_qtys select _foreachindex]; + } foreach _items; + _sortarray sort true; + + { + _item = _x select 1; + + if !(_item isequalto "") then { + if (_index == 0 || (tolower _item) in _FilterArray) then { + _qty = ((_x select 2) - ({_x == _item} count _offerArray)); + if (_qty > 0) then { + _id = lnbAddRow[41503, ["", str(_qty),_x select 0]]; + lnbSetData [41503, [_id,0], _item]; + lnbSetValue [41503, [_id,0], _qty]; + lnbSetPicture [41503, [_id,0], _item call EPOCH_itemPicture]; }; }; }; - if (_itemName != "") then { - - _qty = ((_qtys select _forEachIndex) - ({_x == _item} count _offerArray)); - if (_qty > 0) then { - - // _offerArray pushBack _item; - _index = lnbAddRow[41503, ["", str(_qty), _itemName]]; - lnbSetData [41503, [_index,0], _item]; - lnbSetValue [41503, [_index,0], _qty]; - lnbSetPicture [41503, [_index,0], _itemIcon]; - }; - }; - - } forEach _items; + } forEach _sortarray; }; }; };