/*
Author: Maxence
Web site: www.the-programmer.com
Discord: https://discord.the-programmer.com
Terms of use:
- This file is forbidden unless you have permission from the author. If you have this file without permission to use it please do not use it and do not share it.
- If you have permission to use this file, you can use it on your server however it is strictly forbidden to share it.
- Out of respect for the author please do not delete this information.
*/
if (life_action_inUse) exitWith {hint localize "STR_NOTF_Action";};
_workbench = cursorObject;
if (isNull _workbench) exitWith {};
_config = missionConfigFile >> "Max_Settings_Craft";
if !((typeOf _workbench) in (getArray (_config >> "all_workbench_classnames"))) exitWith {};
if (dialog) exitWith {};
if !(isNull (_workbench getVariable ["workbench_in_use_by",objNull])) exitWith {hint localize "STR_MISC_VehInvUse";};
createDialog "Maxence_Craft";
disableSerialization;
_workbench setVariable ["workbench_in_use_by",player,true];
_display = findDisplay 6940;
(_display displayCtrl 6949) ctrlSetText format ["%1\main.paa",(getText (_config >> "textures_base_path"))];
if ((getNumber (_config >> "show_only_one_category")) isEqualTo 1) then {
_craftsList = _display displayCtrl 6955;
lbClear _craftsList;
(_display displayCtrl 6941) ctrlShow false;
_categoriesList = _display displayCtrl 6954;
{
_typeConfigPath = _x;
_itemType = configName _typeConfigPath;
_categoryAdded = false;
if (isClass _typeConfigPath) then {
if (_itemType in ["vItem","weapon","magazine","vehicle","backpack","uniform"]) then {
for "_i" from 0 to (count _typeConfigPath)-1 do {
if (_categoryAdded) exitWith {};
_configPath = _typeConfigPath select _i;
if (isClass _configPath) then {
_condition = getText (_configPath >> "condition");
if ([_condition] call theprogrammer_core_fnc_checkCondition) exitWith {
_categoryAdded = true;
_categoriesList lbAdd format ["%1",([(getText (_typeConfigPath >> "category_display_name")),"Max_Settings_Craft","Craft_Localization"] call theprogrammer_core_fnc_localize)];
_categoriesList lbSetData [(lbSize _categoriesList)-1,_itemType];
};
};
};
};
};
} forEach ("true" configClasses (_config >> "crafts"));
_craftsList lbAdd (["STR_SELECT_CATEGORY","Max_Settings_Craft","Craft_Localization"] call theprogrammer_core_fnc_localize);
_craftsList lbSetData [(lbSize _craftsList)-1,"category"];
_craftsList ctrlAddEventHandler ["LBSelChanged",format ["[""%1""] spawn max_craft_fnc_craftLbChanged;",netId (_workbench)]];
} else {
_craftsList = _display displayCtrl 6941;
lbClear _craftsList;
(_display displayCtrl 6954) ctrlShow false;
(_display displayCtrl 6955) ctrlShow false;
{
_fnc_hasAllRequiredItems = {
params [
["_itemType","",[""]],
["_itemClass","",[""]],
["_etabli",objNull,[objNull]]
];
_itemClassConfig = missionConfigFile >> "Max_Settings_Craft" >> "crafts" >> _itemType >> _itemClass;
_hasItems = true;
if !(isClass _itemClassConfig) exitWith {false;};
_data = (_etabli getVariable ["workbench_inventory",[[],0]]) select 0;
{
_hasItem = false;
_index = [(_x select 0),_data] call max_craft_fnc_index;
if !(_index isEqualTo -1) then {
_value = (_data select _index) select 1;
if (_value >= (_x select 1)) then {_hasItem = true;};
};
if !(_hasItem) exitWith {_hasItems = false;};
} forEach (getArray (_itemClassConfig >> "itemsRequired"));
_money = getNumber (_itemClassConfig >> "moneyRequired");
if (_money > 0) then {if (life_cash < _money) then {_hasItems = false;};};
_hasItems;
};
_craftsList = _display displayCtrl 6941;
lbClear _craftsList;
_vehicleInfo = [_itemResult] call life_fnc_fetchVehInfo;
_itemName = _vehicleInfo select 3;
_icon = _vehicleInfo select 2;
};
case "backpack" : {
_itemInfo = [_itemResult] call life_fnc_fetchCfgDetails;
_itemName = _itemInfo select 1;
_icon = _itemInfo select 2;
};
case "uniform" : {
_itemInfo = [_itemResult] call life_fnc_fetchCfgDetails;
_itemName = _itemInfo select 1;
_icon = _itemInfo select 2;
};
default {};
};
if ([_itemType,_itemClass,_workbench] call _fnc_hasAllRequiredItems) then {
_craftsList lbAdd format ["- %1",_itemName];
_craftsList lbSetData [(lbSize _craftsList)-1,str [_itemType,_itemClass]];
if !(_icon isEqualTo "") then {
_craftsList lbSetPicture [(lbSize _craftsList)-1,_icon];
};
};
};
};
};
} else {
if ((_itemClass isEqualTo "category_display_name") && ((count _typeConfigPath) > 1)) then {
if ((lbSize _craftsList) > 0) then {
_craftsList lbAdd "";
_craftsList lbSetData [(lbSize _craftsList)-1,"category"];
};
_craftsList lbAdd format ["%1 :",([(getText (_configPath)),"Max_Settings_Craft","Craft_Localization"] call theprogrammer_core_fnc_localize)];
_craftsList lbSetData [(lbSize _craftsList)-1,"category"];
};
};
};
};
} forEach ("true" configClasses (missionConfigFile >> "Max_Settings_Craft" >> "crafts"));
_craftsList ctrlAddEventHandler ["LBSelChanged",format ["[""%1""] spawn max_craft_fnc_craftLbChanged;",netId (_workbench)]];
};
(_display displayCtrl 6950) buttonSetAction format ["[""%1""] spawn max_craft_fnc_workBenchTakeItem;",netId (_workbench)];
(_display displayCtrl 6951) buttonSetAction format ["[""%1""] spawn max_craft_fnc_workBenchStoreItem;",netId (_workbench)];
(_display displayCtrl 6952) buttonSetAction format ["[""%1""] spawn max_craft_fnc_craftAction;",netId (_workbench)];
(_display displayCtrl 6953) buttonSetAction format ["[""%1""] spawn max_craft_fnc_craftCancel;",netId (_workbench)];
[_workbench] spawn max_craft_fnc_workBenchInventory;
[_workbench] spawn max_craft_fnc_workBenchProgressBar;
waitUntil {(isNull (findDisplay 6940))};
_workbench setVariable ["workbench_in_use_by",objNull,true];