From 6ddf42b618fcea8949c3721edcd84757f7c04296 Mon Sep 17 00:00:00 2001 From: A Man Date: Mon, 27 Apr 2020 18:12:19 +0200 Subject: [PATCH] Update handleGear --- .../Configs/RscDisplay/RscDisplayGear.hpp | 20 +- SQF/dayz_code/actions/player_addtoBack.sqf | 16 +- SQF/dayz_code/actions/player_switchWeapon.sqf | 20 +- SQF/dayz_code/init/compiles.sqf | 2 + SQF/dayz_code/system/handleGear.sqf | 549 ++---------------- SQF/dayz_code/system/handleGearFunctions.sqf | 398 +++++++++++++ 6 files changed, 480 insertions(+), 525 deletions(-) create mode 100644 SQF/dayz_code/system/handleGearFunctions.sqf diff --git a/SQF/dayz_code/Configs/RscDisplay/RscDisplayGear.hpp b/SQF/dayz_code/Configs/RscDisplay/RscDisplayGear.hpp index c296fad8f..13d46be60 100644 --- a/SQF/dayz_code/Configs/RscDisplay/RscDisplayGear.hpp +++ b/SQF/dayz_code/Configs/RscDisplay/RscDisplayGear.hpp @@ -4,7 +4,7 @@ class RscDisplayGear enableDisplay = 1; movingEnable = 0; - onLoad = "_this call fn_gearMenuChecks; false call dz_fn_meleeMagazines; dayz_gearThread = cursorTarget spawn object_monitorGear; call gear_ui_init; call ui_gear_sound; if (isNil 'IGUI_GEAR_activeFilter') then {IGUI_GEAR_activeFilter = 0}; [_this, 'onLoad'] execVM '\z\addons\dayz_code\system\handleGear.sqf'"; + onLoad = "_this call fn_gearMenuChecks; false call dz_fn_meleeMagazines; dayz_gearThread = cursorTarget spawn object_monitorGear; call gear_ui_init; call ui_gear_sound; if (isNil 'IGUI_GEAR_activeFilter') then {IGUI_GEAR_activeFilter = 0}; [_this, 'onLoad'] spawn fn_handleGear;"; onUnload = "true call dz_fn_meleeMagazines; terminate dayz_gearThread; call player_selectWeapon; call player_forceSave;"; onMouseMoving = "[] call gear_ui_hide;"; onMouseHolding = "[] call gear_ui_hide;"; @@ -313,8 +313,8 @@ class RscDisplayGear idc = 146; x = -2; style = 2048; - onSetFocus = "[_this,'onFocus'] execVM '\z\addons\dayz_code\system\handleGear.sqf'"; - onButtonClick = "false call dz_fn_meleeMagazines; [_this,'onLBListSelChanged'] execVM '\z\addons\dayz_code\system\handleGear.sqf'"; + onSetFocus = "[_this,'onFocus'] spawn fn_handleGear;"; + onButtonClick = "false call dz_fn_meleeMagazines; [_this,'onLBListSelChanged'] spawn fn_handleGear;"; text = "<"; }; @@ -331,9 +331,9 @@ class RscDisplayGear colorSelectBackground[] = {0.28,0.25,0.18,0.4}; colorSelectBackground2[] = {0.28,0.25,0.18,0.4}; shadow = 0; - onLBSelChanged = "[_this,'onLBSelChanged'] execVM '\z\addons\dayz_code\system\handleGear.sqf'"; - onLBListSelChanged = "[_this,'onLBListSelChanged'] execVM '\z\addons\dayz_code\system\handleGear.sqf'"; - onKillFocus = "[_this,'onKillFocus'] execVM '\z\addons\dayz_code\system\handleGear.sqf'"; + onLBSelChanged = "[_this,'onLBSelChanged'] spawn fn_handleGear;"; + onLBListSelChanged = "[_this,'onLBListSelChanged'] spawn fn_handleGear;"; + onKillFocus = "[_this,'onKillFocus'] spawn fn_handleGear;"; x = 0; y = 0; //w = 0.46; @@ -348,8 +348,8 @@ class RscDisplayGear { idc = 147; x = -2; - onSetFocus = "[_this,""onFocus""] execVM '\z\addons\dayz_code\system\handleGear.sqf'"; - onButtonClick = "false call dz_fn_meleeMagazines; [_this,""onLBListSelChanged""] execVM '\z\addons\dayz_code\system\handleGear.sqf'"; + onSetFocus = "[_this,""onFocus""] spawn fn_handleGear;"; + onButtonClick = "false call dz_fn_meleeMagazines; [_this,""onLBListSelChanged""] spawn fn_handleGear;"; text = ">"; }; }; @@ -514,7 +514,7 @@ class RscDisplayGear h = 0.174; colorBackground[] = {0.27,0.34,0.47,0.2}; colorBackgroundSelected[] = {0.27,0.34,0.47,0.8}; - onMouseButtonDblClick = "if (!(ctrlShown ((findDisplay 106) displayCtrl 158)) && ((gearSlotData (_this select 0)) isKindOf 'Bag_Base_EP1')) then { [player,'open_backpack',0,false,5] call dayz_zombieSpeak; };"; + onMouseButtonDblClick = "if (!(ctrlShown ((findDisplay 106) displayCtrl 158)) && {(gearSlotData (_this select 0)) isKindOf 'Bag_Base_EP1'}) then { [player,'open_backpack',0,false,5] call dayz_zombieSpeak; };"; }; class CA_Gear_slot_carry : CA_Gear_slot_primary @@ -524,7 +524,7 @@ class RscDisplayGear y = 0.364; w = 0.309; h = 0.174; - onMouseEnter = "if ((DayZ_onBack != """") && (dayz_onBack in MeleeWeapons)) then {mouseOverCarry = true;} else {mouseOverCarry = false;};"; + onMouseEnter = "if ((DayZ_onBack != """") && {dayz_onBack in MeleeWeapons}) then {mouseOverCarry = true;} else {mouseOverCarry = false;};"; onMouseExit = "mouseOverCarry = false;"; colorActive[] = {1,1,1,1}; colorBackground[] = {0.74,0.74,0.74,0.2}; // has no effect diff --git a/SQF/dayz_code/actions/player_addtoBack.sqf b/SQF/dayz_code/actions/player_addtoBack.sqf index d85b48d4d..066288672 100644 --- a/SQF/dayz_code/actions/player_addtoBack.sqf +++ b/SQF/dayz_code/actions/player_addtoBack.sqf @@ -16,14 +16,14 @@ call gear_ui_init; if (_item in ["ItemHatchet","ItemCrowbar","ItemMachete","ItemFishingPole","ItemSledge"]) then { //free primary slot for new melee (remember item to add after) - switch (_item) do { - case "ItemHatchet": {player removeWeapon "ItemHatchet"; dayz_onBack = "MeleeHatchet";}; - case "ItemCrowbar": {player removeWeapon "ItemCrowbar"; dayz_onBack = "MeleeCrowbar";}; - case "ItemMachete": {player removeWeapon "ItemMachete"; dayz_onBack = "MeleeMachete";}; - case "ItemFishingPole": {player removeWeapon "ItemFishingPole"; dayz_onBack = "MeleeFishingPole";}; - case "ItemSledge": {player removeWeapon "ItemSledge"; dayz_onBack = "MeleeSledge";}; + call { + if (_item == "ItemHatchet") exitwith {player removeWeapon "ItemHatchet"; dayz_onBack = "MeleeHatchet";}; + if (_item == "ItemCrowbar") exitwith {player removeWeapon "ItemCrowbar"; dayz_onBack = "MeleeCrowbar";}; + if (_item == "ItemMachete") exitwith {player removeWeapon "ItemMachete"; dayz_onBack = "MeleeMachete";}; + if (_item == "ItemFishingPole") exitwith {player removeWeapon "ItemFishingPole"; dayz_onBack = "MeleeFishingPole";}; + if (_item == "ItemSledge") exitwith {player removeWeapon "ItemSledge"; dayz_onBack = "MeleeSledge";}; }; disableSerialization; - [[(findDisplay 106)],"onLBSelChanged"] execVM "\z\addons\dayz_code\system\handleGear.sqf"; //update back + [[(findDisplay 106)],"onLBSelChanged"] spawn fn_handleGear; //update back -}; \ No newline at end of file +}; diff --git a/SQF/dayz_code/actions/player_switchWeapon.sqf b/SQF/dayz_code/actions/player_switchWeapon.sqf index f1c89e90c..83abe06bf 100644 --- a/SQF/dayz_code/actions/player_switchWeapon.sqf +++ b/SQF/dayz_code/actions/player_switchWeapon.sqf @@ -19,18 +19,18 @@ dz_fn_switchWeapon = { if Player_IsInVehicle exitWith {}; if Player_IsOnLadder() exitWith {}; if (dayz_autoRun) then {call dayz_autoRunOff;}; - + private ["_current","_secondary","_option"]; - + _option = _this; _current = currentWeapon player; - + call { if (_option == 0) exitWith { // Instantly switch primary and carry, also update gear if (IS_PRIMARY(_current)) then {true call dz_fn_switchWeapon_swap;} else {false call dz_fn_switchWeapon_swap;}; - [[(findDisplay 106)],"onLBSelChanged"] execVM "\z\addons\dayz_code\system\handleGear.sqf"; + [[(findDisplay 106)],"onLBSelChanged"] spawn fn_handleGear; }; - + if (_option == 1) exitWith { //Switch primary and carry if (dayz_quickSwitch) then { true call dz_fn_switchWeapon_swap; @@ -38,7 +38,7 @@ dz_fn_switchWeapon = { call dz_fn_switchWeapon_swapSecure; }; }; - + if (_option == 2) exitWith { // Switch to rifle if (_current == "" || {_current == "Throw"}) exitWith { // No current weapon switch FIND_RIFLE do { @@ -76,7 +76,7 @@ dz_fn_switchWeapon = { }; }; }; - + if (_option == 3) exitWith { //Switch to pistol if (IS_PRIMARY(_current)) then { //If current weapon is primary _secondary = Player_GetSidearm(); @@ -150,7 +150,7 @@ dz_fn_switchWeapon_swap = { } else { dayz_onBack = [primaryWeapon player,player removeWeapon primaryWeapon player,player addWeapon dayz_onBack] select 0; }; - + if (_this) then { player selectWeapon primaryWeapon player; if (IS_MELEE(primaryWeapon player)) then { @@ -169,10 +169,10 @@ dz_fn_switchWeapon_swapSecure = { _str = toString [_array select 5,_array select 6,_array select 7]; _anim = format["AmovP%1MstpSrasWrflDnon_AmovP%1MstpSrasWpstDnon",_str]; player playMoveNow _anim; - + //Add AnimDone event handler to wait until current weapon is put away dz_switchWeapon_handler = player addEventHandler ["AnimDone", { - + true call dz_fn_switchWeapon_swap; player removeEventHandler ["AnimDone", dz_switchWeapon_handler]; dz_switchWeapon_handler = nil; diff --git a/SQF/dayz_code/init/compiles.sqf b/SQF/dayz_code/init/compiles.sqf index febd0c424..9a09528e4 100644 --- a/SQF/dayz_code/init/compiles.sqf +++ b/SQF/dayz_code/init/compiles.sqf @@ -16,6 +16,8 @@ if (!isDedicated) then { call compile preprocessFileLineNumbers "\z\addons\dayz_code\util\compile.sqf"; call compile preprocessFileLineNumbers "\z\addons\dayz_code\loot\init.sqf"; + call compile preprocessFileLineNumbers "\z\addons\dayz_code\system\handleGearFunctions.sqf"; + fn_handleGear = compile preprocessFileLineNumbers "\z\addons\dayz_code\system\handleGear.sqf"; actionMonitor = compile preprocessFileLineNumbers "\z\addons\dayz_code\actions\pickupActions\actionMonitor.sqf"; object_pickup = compile preprocessFileLineNumbers "\z\addons\dayz_code\actions\pickupActions\object_pickup.sqf"; diff --git a/SQF/dayz_code/system/handleGear.sqf b/SQF/dayz_code/system/handleGear.sqf index 14f045992..33854337e 100644 --- a/SQF/dayz_code/system/handleGear.sqf +++ b/SQF/dayz_code/system/handleGear.sqf @@ -4,9 +4,8 @@ */ disableSerialization; -private ["_control","_display","_temp","_event","_data","_x","_stopTheKey","_keyLeft","_i","_index","_size","_indices","_lbcontrol"]; -private ["_key","_keyRight","_keyTop","_keyBottom","_secondColumn","_activateControl","_output","_doFilter"]; -private ["_event","_data","_display","_control","_primaryWeaponControl","_IDCsArray","_lbIDC","_lbColumn","_sum"]; +private ["_doFilter","_filterSets","_event","_data","_display","_control","_IDCsArray","_output"]; + /* IGUI_GEAR_filterPrimaryWeapon = (_activeFilter select 0); IGUI_GEAR_filterSecondaryWeapon = (_activeFilter select 1); @@ -17,8 +16,7 @@ IGUI_GEAR_filterPistols = (_activeFilter select 5); IGUI_GEAR_filterPistolAmmo = (_activeFilter select 6); */ -_doFilter = false; - +/* _filterSets = [ //Primary Weapon, Secondary weapon, Ammo, Binocular, Inventory, Pistols, Pistols Ammo [false,false,false,false,false,false,false], @@ -27,82 +25,7 @@ _filterSets = [ [true,true,true,false,false,true,true], // all but pistol, pistols ammo [true,true,true,true,true,true,true] ]; - -_icons = [ - "\ca\ui\data\igui_buyUnit_filter_1_ca.paa", - "\ca\ui\data\igui_buyUnit_filter_2_ca.paa", - "\ca\ui\data\igui_buyUnit_filter_3_ca.paa", - "\ca\ui\data\igui_buyUnit_filter_4_ca.paa", - "\ca\ui\data\igui_buyUnit_filter_5_ca.paa" -]; - -_event = _this select 1; -_data = _this select 0; -//diag_log [diag_ticktime, __FILE__, _this]; -_display = nil; - - -/*-------------------------------------------*/ -if (typeName(_data select 0) == "DISPLAY") then { - _display = (_data select 0); -}; - -if (typeName(_data select 0) == "CONTROL") then { - _control = (_data select 0); - _display = ctrlParent _control; -}; - - -/*-------------------------------------------*/ -_lbSelectedItem = { - private ["_index","_selectedItem","_n"]; - _lbcontrol = _display displayctrl _lbIDC; - _index = lbCurSel _lbcontrol; - _selectedItem = ""; - _n = 0; - - while {(_selectedItem == "")&&(_n<6)} do { - _selectedItem = _lbcontrol lnbData [_index,1]; - uisleep 0.001; - _n = _n + 1; - }; - - _selectedItem -}; - -_arrowsEnable = { - private ["_index"]; - - _lbcontrol = _display displayctrl _lbIDC; - - _controlLeftArrow = _display displayctrl 147; - _controlRightArrow = _display displayctrl 146; - _index = lbCurSel _lbcontrol; - _selectedItemCountLeft = _lbcontrol lnbText [_index,0]; - _selectedItemCountRight = _lbcontrol lnbText [_index,2]; -}; - - -_isWeapon = { - private ["_item","_return"]; - _item = _this select 0; - _return = (str(configfile >> "cfgWeapons" >> _item) != ""); - _return -}; - -_isMagazine = { - private ["_item","_return"]; - _item = _this select 0; - _return = (str(configfile >> "cfgMagazines" >> _item) != ""); - _return -}; - -_isBackpack = { - private ["_item","_return"]; - _item = _this select 0; - _return = (str(configfile >> "cfgVehicles" >> _item) != ""); - _return -}; +*/ _IDCsArray = [ [107], @@ -128,396 +51,55 @@ _IDCsArray = [ [107], [107] ]; -/* -_showAllIDCs = { - private ["_slotArray","_j","_i"]; - for [{_i=0},{_i-1 ) then { - _itemSlot = _display displayctrl (_slotArray select _j); - //_itemSlot ctrlSetFade 0.0; - //_itemSlot ctrlCommit 0.3; - } else { - _itemSlot = _display displayctrl (_slotArray select _j); - //_itemSlot ctrlSetFade 0.5; - //_itemSlot ctrlCommit 0.3; - }; - }; - }; - - /* - for [{_i=0},{_i> "cfgWeapons" >> _item >> "type"); - }; - - if ([_item] call _isMagazine) then { - _return = getNumber(configfile >> "cfgMagazines" >> _item >> "type"); - }; - - _return -}; - -_highlightIDCs = { - _hlIDCs = _this select 0; -/* - for [{_i=0},{_i=0}, {_i = _i - 1} ] do - { - _valResult = _val mod _n; - - if (_valResult != _val) then { - _bitArray set [_i, 1]; - }; - - _n = _n / 2; - _val = _valResult; - }; - - _bitArray -}; - -_highlightGearSlots ={ - //[] call _showAllIDCs; - _selectedItem = [] call _lbSelectedItem; - _selectedItemSlot = [_selectedItem] call _itemSlot; - _selectedItemSlotFlags = [_selectedItemSlot] call _returnBitArray; - _selectedItemSlotIDCs = [_selectedItemSlotFlags] call _returnSlotIDCs; - [_selectedItemSlotIDCs] call _higlightIDCs; -}; -/* -_weaponsLBSetFocus = { - _lbcontrol = _display displayctrl _lbIDC; - //Temporary disabled to prevent bug news:hov5k4$f6f$1@new-server.localdomain - //ctrlSetFocus _lbcontrol; -};*/ - -_setFilterIcon = { - _ctrlIcon = _display displayctrl 148; - _ctrlIcon ctrlSetText (_icons select IGUI_GEAR_activeFilter); -}; - -_keyActions = { - _keyLeft = [203,327700,327686]; - _keyRight = [205,327696,327687]; - _keyTop = [200,327697,327684]; - _keyBottom = [208,327701,327685]; - _key = _data select 1; - - if ((_keyLeft find _key)>=0) then { - _control = _display displayctrl 146; - ctrlActivate _control; - _output = true; - }; - - if ((_keyRight find _key)>=0) then { - _control = _display displayctrl 147; - ctrlActivate _control; - _output = true; - }; -/* - if((_keyTop find _key)>=0)then { - - }; - - if((_keyBottom find _key)>=0)then { - - };*/ -}; - -//_bitArray = [0,0,0,0,0 ,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; -/* -#define WeaponNoSlot 0 // dummy weapons -#define WeaponSlotPrimary 1 // primary weapons -#define WeaponSlotSecondary 4 // secondary weapons -#define WeaponSlotHandGun 2 // HandGun -#define WeaponSlotHandGunItem 16 // HandGun magazines -#define WeaponSlotItem 256 // items -#define WeaponSlotBinocular 4096 // binocular -#define WeaponHardMounted 65536 -#define WeaponSlotInventory 131072 // inventory items -*/ - -_setFilterGlobals = { - _activeFilter = _this; - IGUI_GEAR_filterPrimaryWeapon = (_activeFilter select 0); - IGUI_GEAR_filterSecondaryWeapon = (_activeFilter select 1); - IGUI_GEAR_filterAmmo = (_activeFilter select 2); - IGUI_GEAR_filterBinocular = (_activeFilter select 3); - IGUI_GEAR_filterInventory = (_activeFilter select 4); - IGUI_GEAR_filterPistols = (_activeFilter select 5); - IGUI_GEAR_filterPistolAmmo = (_activeFilter select 6); -}; - -//1201 -_highlightFilterIcons = { - for [{_i=0},{_i<6}, {_i = _i + 1} ] do { - _control = _display displayctrl (1200 + _i); - _control ctrlSetTextColor [0.6000,0.8392,0.4706,1.0]; - }; - - _control = _display displayctrl (1200 + _this); - _control ctrlSetTextColor [1,1,1,1]; -}; - -_matchesFilter = { - private ["_itemValue","_itemBitArray"]; - _output = false; - - _itemValue = _this select 0; - _itemBitArray = [_itemValue] call _returnBitArray; - - if (_itemValue == 1 && IGUI_GEAR_filterPrimaryWeapon) then { - _output = true; - }; - - if (_itemValue == 5 && IGUI_GEAR_filterPrimaryWeapon) then { - _output = true; - }; - - if (_itemValue == 4 && IGUI_GEAR_filterSecondaryWeapon) then { - _output = true; - }; - - if (_itemValue == 2 && IGUI_GEAR_filterPistols) then { - _output = true; - }; - - if (_itemValue == 16 && IGUI_GEAR_filterPistolAmmo) then { - _output = true; - }; - - if (_itemValue == 131072 && IGUI_GEAR_filterInventory) then { - _output = true; - }; - - if (_itemValue == 512 && IGUI_GEAR_filterAmmo) then { - _output = true; - }; - - if (_itemValue == 256 && IGUI_GEAR_filterAmmo) then { - _output = true; - }; - - if (_itemValue == 4096 && IGUI_GEAR_filterBinocular) then { - _output = true; - }; - - _output -}; - -_filterItems = { - private ["_n","_itemType"]; - _deleteIndexes = []; - _lbcontrol = _display displayctrl _lbIDC; - _n = (lnbSize _lbcontrol) select 0; - _j = 0; - - for [{_i=_n},{_i>=0}, {_i = _i - 1} ] do { - _item = _lbcontrol lnbData [_i,1]; - _itemType = [_item] call _itemSlot; - - if ([_itemType] call _matchesFilter) then { - _j = _j + 1; - _deleteIndexes set [(_j-1), _i]; - }; - }; - - LB_CTRL = _lbcontrol; - - { - _lbcontrol lnbDeleteRow _x; - } count _deleteIndexes; -}; - -_itemPicture = { - private ["_item"]; - _item = _this select 0; - _return = ""; - - if ([_item] call _isWeapon) then { - _return = getText(configfile >> "cfgWeapons" >> _item >> "picture"); - }; - - if ([_item] call _isMagazine) then { - _return = getText(configfile >> "cfgMagazines" >> _item >> "picture"); - }; - - _return -}; - -_itemDescription = { -private ["_inputItem","_return"]; - _inputItem = _this select 0; - _return = ""; - - if ([_inputItem] call _isWeapon) then { - _name = getText(configfile >> "cfgWeapons" >> _inputItem >> "descriptionShort"); - _return = (_name); - }; - - if ([_inputItem] call _isMagazine) then { - _name = getText(configfile >> "cfgMagazines" >> _inputItem >> "descriptionShort"); - _return = (_name); - }; - - if ([_inputItem] call _isBackpack) then { - _name = getText(configfile >> "cfgVehicles" >> _inputItem >> "descriptionShort"); - _return = ( _name); - }; - - _return -}; - -_itemName = { - private ["_item"]; - _item = _this select 0; - _return = ""; - - if ([_item] call _isWeapon) then { - _name = getText(configfile >> "cfgWeapons" >> _item >> "displayName"); - _return = ( _name); - }; - - if ([_item] call _isMagazine) then { - _name = getText(configfile >> "cfgMagazines" >> _item >> "displayName"); - _return = ( _name); - }; - - if ([_item] call _isBackpack) then { - _name = getText(configfile >> "cfgVehicles" >> _item >> "displayName"); - _return = ( _name); - }; - - _return -}; - -_displayItemIcon = { - private ["_selectedItem","_itemPicturePath"]; - _selectedItem = [] call _lbSelectedItem; - _itemPicturePath = [_selectedItem] call _itemPicture; - _pictureControl = _display displayctrl 1104; - _pictureControl ctrlSetText _itemPicturePath; -}; - -_displayItemDescription = { - private ["_descriptionControl","_selectedItemDescription","_selectedItemN"]; - _selectedItemN = [] call _lbSelectedItem; - _selectedItemDescription = [_selectedItemN] call _itemDescription; - _descriptionControl = _display displayctrl 1106; - _descriptionControl ctrlSetStructuredText parseText(_selectedItemDescription); -}; - -_displayItemName = { - private ["_nameControl","_itemDescription"]; - _selectedItem = [] call _lbSelectedItem; - _itemName = [_selectedItem] call _itemName; - _nameControl = _display displayctrl 1101; - _nameControl ctrlSetText _itemName; -}; - -_updateOnBack = { - private ["_onBackCtrl"]; - _onBackCtrl = _display displayCtrl 1209; - - if (dayz_onBack != "") then { - _onBackCtrl ctrlSetText ([dayz_onBack] call _itemPicture); - } else { - _onBackCtrl ctrlSetText ""; - }; -}; +_data = _this select 0; +_event = _this select 1; +_display = nil; _output = true; -_lbIDC = 105; +//_doFilter = false; -switch _event do { - case "initDialog": { - //[] call _showAllIDCs; +//diag_log [diag_ticktime, __FILE__, _this]; + +/*-------------------------------------------*/ +if (typeName(_data select 0) == "DISPLAY") then { + _display = (_data select 0); +}; + +if (typeName(_data select 0) == "CONTROL") then { + _control = (_data select 0); + _display = ctrlParent _control; +}; + + +/*-------------------------------------------*/ + +call { + if (_event == "onLoad") exitwith { + _display call HG_arrowsEnable; + _display call HG_displayItemIcon; + _display call HG_displayItemName; + _display call HG_displayItemDescription; }; - case "onLoad": { - //[] call _weaponsLBSetFocus; - [] call _arrowsEnable; - [] call _displayItemIcon; - [] call _displayItemName; - [] call _displayItemDescription; - //[] call _showAllIDCs; - //[] call _arrowsEnable; - //[] call _highlightGearSlots; + if (_event == "onKeyDown") exitwith { + _output = [_display,_data,_output] call HG_keyActions; }; + if (_event == "onLBSelChanged") exitwith { + _display call HG_updateOnBack; + _display call HG_displayItemIcon; + _display call HG_displayItemName; + _display call HG_displayItemDescription; + [_display,_IDCsArray] call HG_highlightGearSlots; + }; + + // Following checks removed, Epoch Mod no longer use this. + /* //used for buyUnits - case "filter": { + if (_event == "filter") exitwith { IGUI_GEAR_activeFilter = IGUI_GEAR_activeFilter + 1; - if (IGUI_GEAR_activeFilter > ((count _filterSets)-1 )) then { + if (IGUI_GEAR_activeFilter > ((count _filterSets) - 1 )) then { IGUI_GEAR_activeFilter = 0; }; @@ -525,56 +107,29 @@ switch _event do { }; //changing IGUI_GEAR_activeFilter, but not filter picture (used for buyGear) - case "filterNotSet": { + if (_event == "filterNotSet") exitwith { IGUI_GEAR_activeFilter = IGUI_GEAR_activeFilter + 1; - if (IGUI_GEAR_activeFilter > ((count _filterSets)-1 )) then { + if (IGUI_GEAR_activeFilter > ((count _filterSets) - 1 )) then { IGUI_GEAR_activeFilter = 0; }; - - //_doFilter = true; }; - case "filter_left": { + if (_event == "filter_left") exitwith { IGUI_GEAR_activeFilter = IGUI_GEAR_activeFilter - 1; if (IGUI_GEAR_activeFilter < 0) then { - IGUI_GEAR_activeFilter = ((count _filterSets)-1 ); + IGUI_GEAR_activeFilter = ((count _filterSets) - 1 ); }; _doFilter = true; - }; - - case "onFocus": { - //[] call _weaponsLBSetFocus; - //[] call _arrowsEnable; - }; - - case "onKeyDown": { - [] call _keyActions; - }; - - case "onLBSelChanged": { - [] call _updateOnBack; - [] call _displayItemIcon; - [] call _displayItemName; - [] call _displayItemDescription; - //[] call _arrowsEnable; - [] call _highlightGearSlots; - }; - - case "onKillFocus": { - //[] call _weaponsLBSetFocus; - }; - - default {}; + };*/ }; -/* Filter removed, moving to engine */ -if _doFilter then { - (_filterSets select IGUI_GEAR_activeFilter) call _setFilterGlobals; - //[] call _filterItems; - //[] call _setFilterIcon; +/* Filter removed, moving to engine +if (_doFilter) then { + (_filterSets select IGUI_GEAR_activeFilter) call HG_setFilterGlobals; }; +*/ _output diff --git a/SQF/dayz_code/system/handleGearFunctions.sqf b/SQF/dayz_code/system/handleGearFunctions.sqf new file mode 100644 index 000000000..47c6a07b7 --- /dev/null +++ b/SQF/dayz_code/system/handleGearFunctions.sqf @@ -0,0 +1,398 @@ +HG_lbSelectedItem = { + private ["_display","_index","_selectedItem","_n","_lbcontrol"]; + + _display = _this; + _lbcontrol = _display displayctrl 105; + _index = lbCurSel _lbcontrol; + _selectedItem = ""; + _n = 0; + + while {(_selectedItem == "") && (_n < 6)} do { + _selectedItem = _lbcontrol lnbData [_index,1]; + uisleep 0.001; + _n = _n + 1; + }; + + _selectedItem +}; + +HG_arrowsEnable = { + private ["_display", "_lbcontrol", "_index"]; + + _display = _this; + _lbcontrol = _display displayctrl 105; + _index = lbCurSel _lbcontrol; + _lbcontrol lnbText [_index,0]; + _lbcontrol lnbText [_index,2]; +}; + +HG_isWeapon = { + private ["_item","_return"]; + + _item = _this; + _return = (str(configfile >> "cfgWeapons" >> _item) != ""); + _return +}; + +HG_isMagazine = { + private ["_item","_return"]; + + _item = _this; + _return = (str(configfile >> "cfgMagazines" >> _item) != ""); + _return +}; + +HG_isBackpack = { + private ["_item","_return"]; + + _item = _this; + _return = (str(configfile >> "cfgVehicles" >> _item) != ""); + _return +}; + +HG_higlightIDCs = { + private ["_display","_IDCsArray","_slotArray","_j","_i","_selectedItemSlotIDCs"]; + + _display = _this select 0; + _IDCsArray = _this select 1; + _selectedItemSlotIDCs = _this select 2; + + for "_i" from 0 to (count(_IDCsArray)-1) do { + _slotArray = _IDCsArray select _i; + + for "_j" from 0 to (count(_slotArray)-1) do { + if (_selectedItemSlotIDCs find (_slotArray select _j)>-1 ) then { + _display displayctrl (_slotArray select _j); + } else { + _display displayctrl (_slotArray select _j); + }; + }; + }; +}; + +HG_returnSlotIDCs = { + private ["_flags", "_IDCsArray", "_outputArray", "_sum", "_i"]; + + _flags = _this select 0; + _IDCsArray = _this select 1; + + _outputArray = []; + _sum = 0; + + for "_i" from 0 to (count(_IDCsArray)-1) do { + _sum = _sum + (_flags select _i); + if ((_flags select _i) == 1) then { + _outputArray set [count _outputArray, (_IDCsArray select _i)]; + }; + }; + + if (_sum == 0) then { + _outputArray = (_IDCsArray select 2); + }; + + _outputArray +}; + +HG_itemSlot = { + private ["_item", "_return"]; + + _item = _this; + _return = 0; + + if (_item call HG_isWeapon) then { + _return = getNumber(configfile >> "cfgWeapons" >> _item >> "type"); + }; + + if (_item call HG_isMagazine) then { + _return = getNumber(configfile >> "cfgMagazines" >> _item >> "type"); + }; + + _return +}; + +HG_returnBitArray = { + private ["_i","_bitArray","_valResult","_val","_n","_i"]; + + _val = _this; + _bitArray = [0,0,0,0,0 ,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; + _n = 524288; + _i = 19; + + //for [{_i = 19},{_i >= 0}, {_i = _i - 1} ] do + while {_i >= 0} do { + _valResult = _val mod _n; + + if (_valResult != _val) then { + _bitArray set [_i, 1]; + }; + + _n = _n / 2; + _val = _valResult; + _i = _i - 1; + }; + + _bitArray +}; + +HG_highlightGearSlots = { + private ["_display", "_IDCsArray", "_selectedItem", "_selectedItemSlot", "_selectedItemSlotFlags", "_selectedItemSlotIDCs"]; + + _display = _this select 0; + _IDCsArray = _this select 1; + + _selectedItem = _display call HG_lbSelectedItem; + _selectedItemSlot = _selectedItem call HG_itemSlot; + _selectedItemSlotFlags = _selectedItemSlot call HG_returnBitArray; + _selectedItemSlotIDCs = [_selectedItemSlotFlags,_IDCsArray] call HG_returnSlotIDCs; + [_display,_IDCsArray,_selectedItemSlotIDCs] call HG_higlightIDCs; +}; + +HG_keyActions = { + private ["_display", "_data", "_keyLeft", "_keyRight", "_key", "_control", "_output"]; + + _display = _this select 0; + _data = _this select 1; + _output = _this select 2; + + _keyLeft = [203,327700,327686]; + _keyRight = [205,327696,327687]; + _key = _data select 1; + + if ((_keyLeft find _key) >= 0) then { + _control = _display displayctrl 146; + ctrlActivate _control; + _output = true; + }; + + if ((_keyRight find _key) >= 0) then { + _control = _display displayctrl 147; + ctrlActivate _control; + _output = true; + }; + _output +}; + +HG_itemPicture = { + private ["_item","_return"]; + + _item = _this; + _return = ""; + + if (_item call HG_isWeapon) then { + _return = getText(configfile >> "cfgWeapons" >> _item >> "picture"); + }; + + if (_item call HG_isMagazine) then { + _return = getText(configfile >> "cfgMagazines" >> _item >> "picture"); + }; + + _return +}; + +HG_itemDescription = { + private ["_inputItem","_return","_name"]; + + _inputItem = _this; + _return = ""; + + if (_inputItem call HG_isWeapon) then { + _name = getText(configfile >> "cfgWeapons" >> _inputItem >> "descriptionShort"); + _return = (_name); + }; + + if (_inputItem call HG_isMagazine) then { + _name = getText(configfile >> "cfgMagazines" >> _inputItem >> "descriptionShort"); + _return = (_name); + }; + + if (_inputItem call HG_isBackpack) then { + _name = getText(configfile >> "cfgVehicles" >> _inputItem >> "descriptionShort"); + _return = ( _name); + }; + + _return +}; + +HG_itemName = { + private ["_item","_return","_name"]; + + _item = _this; + _return = ""; + + if (_item call HG_isWeapon) then { + _name = getText(configfile >> "cfgWeapons" >> _item >> "displayName"); + _return = ( _name); + }; + + if (_item call HG_isMagazine) then { + _name = getText(configfile >> "cfgMagazines" >> _item >> "displayName"); + _return = ( _name); + }; + + if (_item call HG_isBackpack) then { + _name = getText(configfile >> "cfgVehicles" >> _item >> "displayName"); + _return = ( _name); + }; + + _return +}; + +HG_displayItemIcon = { + private ["_display","_selectedItem","_itemPicturePath","_pictureControl"]; + + _display = _this; + _selectedItem = _display call HG_lbSelectedItem; + _itemPicturePath = _selectedItem call HG_itemPicture; + _pictureControl = _display displayctrl 1104; + _pictureControl ctrlSetText _itemPicturePath; +}; + +HG_displayItemDescription = { + private ["_display","_descriptionControl","_selectedItemDescription","_selectedItemN"]; + + _display = _this; + _selectedItemN = _display call HG_lbSelectedItem; + _selectedItemDescription = _selectedItemN call HG_itemDescription; + _descriptionControl = _display displayctrl 1106; + _descriptionControl ctrlSetStructuredText parseText(_selectedItemDescription); +}; + +HG_displayItemName = { + private ["_display", "_selectedItem", "_itemName", "_nameControl"]; + + _display = _this; + _selectedItem = _display call HG_lbSelectedItem; + _itemName = _selectedItem call HG_itemName; + _nameControl = _display displayctrl 1101; + _nameControl ctrlSetText _itemName; +}; + +HG_updateOnBack = { + private ["_display","_onBackCtrl"]; + + _display = _this; + _onBackCtrl = _display displayCtrl 1209; + + if (dayz_onBack != "") then { + _onBackCtrl ctrlSetText (dayz_onBack call HG_itemPicture); + } else { + _onBackCtrl ctrlSetText ""; + }; +}; + +//_bitArray = [0,0,0,0,0 ,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; +/* +#define WeaponNoSlot 0 // dummy weapons +#define WeaponSlotPrimary 1 // primary weapons +#define WeaponSlotSecondary 4 // secondary weapons +#define WeaponSlotHandGun 2 // HandGun +#define WeaponSlotHandGunItem 16 // HandGun magazines +#define WeaponSlotItem 256 // items +#define WeaponSlotBinocular 4096 // binocular +#define WeaponHardMounted 65536 +#define WeaponSlotInventory 131072 // inventory items +*/ + +//Not used at the moment +/* +HG_setFilterGlobals = { + private "_activeFilter"; + + _activeFilter = _this; + IGUI_GEAR_filterPrimaryWeapon = (_activeFilter select 0); + IGUI_GEAR_filterSecondaryWeapon = (_activeFilter select 1); + IGUI_GEAR_filterAmmo = (_activeFilter select 2); + IGUI_GEAR_filterBinocular = (_activeFilter select 3); + IGUI_GEAR_filterInventory = (_activeFilter select 4); + IGUI_GEAR_filterPistols = (_activeFilter select 5); + IGUI_GEAR_filterPistolAmmo = (_activeFilter select 6); +}; + +//1201 +HG_highlightFilterIcons = { + private ["_i", "_control", "_display"]; + + _display = _this; + + for "_i" from 0 to 5 do { + _control = _display displayctrl (1200 + _i); + _control ctrlSetTextColor [0.6000,0.8392,0.4706,1.0]; + }; + + _control = _display displayctrl (1200 + _this); + _control ctrlSetTextColor [1,1,1,1]; +}; + +HG_matchesFilter = { + private ["_itemValue","_output"]; + + _itemValue = _this; + _output = false; + + if (_itemValue == 1 && {IGUI_GEAR_filterPrimaryWeapon}) then { + _output = true; + }; + + if (_itemValue == 5 && {IGUI_GEAR_filterPrimaryWeapon}) then { + _output = true; + }; + + if (_itemValue == 4 && {IGUI_GEAR_filterSecondaryWeapon}) then { + _output = true; + }; + + if (_itemValue == 2 && {IGUI_GEAR_filterPistols}) then { + _output = true; + }; + + if (_itemValue == 16 && {IGUI_GEAR_filterPistolAmmo}) then { + _output = true; + }; + + if (_itemValue == 131072 && {IGUI_GEAR_filterInventory}) then { + _output = true; + }; + + if (_itemValue == 512 && {IGUI_GEAR_filterAmmo}) then { + _output = true; + }; + + if (_itemValue == 256 && {IGUI_GEAR_filterAmmo}) then { + _output = true; + }; + + if (_itemValue == 4096 && {IGUI_GEAR_filterBinocular}) then { + _output = true; + }; + + _output +}; + +HG_filterItems = { + private ["_display", "_deleteIndexes", "_lbcontrol", "_n", "_j", "_i", "_item", "_itemType"]; + + _display = _this; + _deleteIndexes = []; + _lbcontrol = _display displayctrl 105; + _n = (lnbSize _lbcontrol) select 0; + _j = 0; + _i = _n; + + while {_i >= 0} do { + _item = _lbcontrol lnbData [_i,1]; + _itemType = _item call HG_itemSlot; + + if (_itemType call HG_matchesFilter) then { + _j = _j + 1; + _deleteIndexes set [(_j-1), _i]; + }; + _i = _i - 1; + }; + + LB_CTRL = _lbcontrol; + + { + _lbcontrol lnbDeleteRow _x; + } count _deleteIndexes; +}; +*/