From c4919d65e501140ccf2b1f2e7f29b9e9ff79ad20 Mon Sep 17 00:00:00 2001 From: A Man Date: Tue, 17 Aug 2021 19:20:33 +0200 Subject: [PATCH] Add epoch right click actions to Epoch Core The right click menu made by Mudzereli and updated by Salival is part of epoch now. It gets only loaded if the DZE_CLICK_ACTIONS is not empty. --- .../Rightclicks/ui_selectSlot_addon.sqf | 105 ++++++++++++++++++ .../ui_selectSlot_vanilla.sqf} | 52 +++++---- SQF/dayz_code/configVariables.sqf | 19 ++++ SQF/dayz_code/init/compiles.sqf | 7 +- 4 files changed, 155 insertions(+), 28 deletions(-) create mode 100644 SQF/dayz_code/compile/Rightclicks/ui_selectSlot_addon.sqf rename SQF/dayz_code/compile/{ui_selectSlot.sqf => Rightclicks/ui_selectSlot_vanilla.sqf} (62%) diff --git a/SQF/dayz_code/compile/Rightclicks/ui_selectSlot_addon.sqf b/SQF/dayz_code/compile/Rightclicks/ui_selectSlot_addon.sqf new file mode 100644 index 000000000..8cbbd93c7 --- /dev/null +++ b/SQF/dayz_code/compile/Rightclicks/ui_selectSlot_addon.sqf @@ -0,0 +1,105 @@ +disableSerialization; +local _control = _this select 0; +local _button = _this select 1; +local _parent = findDisplay 106; + +if (carryClick) then {carryClick = false;}; + +if (_button == 1) then { + if (animationState player in ["ainjppnemstpsnonwnondnon_rolltofront","amovppnemstpsnonwnondnon_healed"]) exitWith { + //Prevent bypassing unconscious wake up animation with bandage or other right click actions + localize "str_player_actionslimit" call dayz_rollingMessages; + }; + + local _group = _parent displayCtrl 6902; + local _pos = ctrlPosition _group; + local _item = gearSlotData _control; + + if ( //No right click action + (!DZE_SelfTransfuse && {_item in ["ItemBloodbag","wholeBloodBagANEG","wholeBloodBagAPOS","wholeBloodBagBNEG","wholeBloodBagBPOS","wholeBloodBagABNEG","wholeBloodBagABPOS","wholeBloodBagONEG","wholeBloodBagOPOS"]}) + ) exitWith {}; + + if (mouseOverCarry) then { + _item = DayZ_onBack; + carryClick = true; + }; + + _pos set [0,((_this select 2) + 0.46)]; + _pos set [1,((_this select 3) + 0.07)]; + + local _conf = configFile >> "cfgMagazines" >> _item; + if (!isClass _conf) then { + _conf = configFile >> "cfgWeapons" >> _item; + }; + local _name = getText(_conf >> "displayName"); + + local _cfgActions = _conf >> "ItemActions"; + local _numActions = (count _cfgActions); + local _height = 0; + if (!dayz_groupSystem && {_item == "ItemRadio"}) then {_numActions = 1;}; // Used to bypass the group action when not enabled. + + local _i = 0; + //Populate Menu + while {_i <= (_numActions - 1)} do { + local _menu = _parent displayCtrl (1600 + _i); + _menu ctrlShow true; + local _config = (_cfgActions select _i); + local _type = getText (_config >> "text"); + local _script = getText (_config >> "script"); + local _outputOriented = getNumber (_config >> "outputOriented") == 1; + _height = _height + (0.025 * safezoneH); + local _compile = format["_id = '%2' %1;",_script,_item]; + uiNamespace setVariable ['uiControl', _control]; + if (_outputOriented) then { + /* + This flag means that the action is output oriented + the output class will then be transferred to the script + and the type used for the name + */ + local _array = getArray (_config >> "output"); + local _outputClass = _array select 0; + local _outputType = _array select 1; + _name = getText (configFile >> _outputType >> _outputClass >> "displayName"); + _compile = format["_id = ['%2',%3] %1;",_script,_item,_array]; + }; + + _menu ctrlSetText format[_type,_name]; + _menu ctrlSetEventHandler ["ButtonClick",_compile]; + _i = _i + 1; + }; + + local _isKey = ((["ItemKey",_item] call fnc_inString) && (_item != "ItemKeyKit")); + + { + local _classname = _x select 0; + local _text = _x select 1; + local _execute = _x select 2; + local _condition = _x select 3; + + if ((_item == _classname || (_isKey && (_className == "ItemKey"))) && (call compile _condition)) then { + local _menu = _parent displayCtrl (1600 + _numActions); + _menu ctrlShow true; + _height = _height + (0.025 * safezoneH); + uiNamespace setVariable ['uiControl', _control]; + _menu ctrlSetText _text; + if (_isKey && (_className == "ItemKey")) then { + if (count _this > 4) then { + local _option = _x select 4; + _menu ctrlSetEventHandler ["ButtonClick",format ["[%1,%2] %3",str _item,_option,_execute]]; + }; + } else { + _menu ctrlSetEventHandler ["ButtonClick",_execute]; + }; + _numActions = _numActions + 1; + }; + } forEach DZE_CLICK_ACTIONS; + + _pos set [3,_height]; + + //hint format["Obj: %1 \nHeight: %2\nPos: %3",_item,_height,_grpPos]; + + _group ctrlShow true; + ctrlSetFocus _group; + _group ctrlSetPosition _pos; + _group ctrlCommit 0; +}; \ No newline at end of file diff --git a/SQF/dayz_code/compile/ui_selectSlot.sqf b/SQF/dayz_code/compile/Rightclicks/ui_selectSlot_vanilla.sqf similarity index 62% rename from SQF/dayz_code/compile/ui_selectSlot.sqf rename to SQF/dayz_code/compile/Rightclicks/ui_selectSlot_vanilla.sqf index 04740e5bf..e33d457e2 100644 --- a/SQF/dayz_code/compile/ui_selectSlot.sqf +++ b/SQF/dayz_code/compile/Rightclicks/ui_selectSlot_vanilla.sqf @@ -1,8 +1,7 @@ -//private ["_control","_button","_parent","_group","_pos","_item","_conf","_name","_cfgActions","_numActions","_height","_menu","_config","_type","_script","_outputOriented","_compile","_array","_outputClass","_outputType"]; disableSerialization; -_control = _this select 0; -_button = _this select 1; -_parent = findDisplay 106; +local _control = _this select 0; +local _button = _this select 1; +local _parent = findDisplay 106; if (carryClick) then {carryClick = false;}; @@ -12,12 +11,10 @@ if (_button == 1) then { localize "str_player_actionslimit" call dayz_rollingMessages; }; - private ["_conf","_name","_compile","_height","_item"]; - _group = _parent displayCtrl 6902; - - _pos = ctrlPosition _group; - - _item = gearSlotData _control; + local _group = _parent displayCtrl 6902; + local _pos = ctrlPosition _group; + local _item = gearSlotData _control; + if ( //No right click action (!DZE_SelfTransfuse && {_item in ["ItemBloodbag","wholeBloodBagANEG","wholeBloodBagAPOS","wholeBloodBagBNEG","wholeBloodBagBPOS","wholeBloodBagABNEG","wholeBloodBagABPOS","wholeBloodBagONEG","wholeBloodBagOPOS"]}) ) exitWith {}; @@ -30,28 +27,28 @@ if (_button == 1) then { _pos set [0,((_this select 2) + 0.46)]; _pos set [1,((_this select 3) + 0.07)]; - _conf = configFile >> "cfgMagazines" >> _item; + local _conf = configFile >> "cfgMagazines" >> _item; if (!isClass _conf) then { _conf = configFile >> "cfgWeapons" >> _item; }; - _name = getText(_conf >> "displayName"); + local _name = getText(_conf >> "displayName"); - _cfgActions = _conf >> "ItemActions"; - _numActions = (count _cfgActions); - _height = 0; + local _cfgActions = _conf >> "ItemActions"; + local _numActions = (count _cfgActions); + local _height = 0; if (!dayz_groupSystem && {_item == "ItemRadio"}) then {_numActions = 1;}; // Used to bypass the group action when not enabled. + local _i = 0; //Populate Menu - for "_i" from 0 to (_numActions - 1) do - { - _menu = _parent displayCtrl (1600 + _i); + while {_i <= (_numActions - 1)} do { + local _menu = _parent displayCtrl (1600 + _i); _menu ctrlShow true; - _config = (_cfgActions select _i); - _type = getText (_config >> "text"); - _script = getText (_config >> "script"); - _outputOriented = getNumber (_config >> "outputOriented") == 1; + local _config = (_cfgActions select _i); + local _type = getText (_config >> "text"); + local _script = getText (_config >> "script"); + local _outputOriented = getNumber (_config >> "outputOriented") == 1; _height = _height + (0.025 * safezoneH); - _compile = format["_id = '%2' %1;",_script,_item]; + local _compile = format["_id = '%2' %1;",_script,_item]; uiNamespace setVariable ['uiControl', _control]; if (_outputOriented) then { /* @@ -59,15 +56,16 @@ if (_button == 1) then { the output class will then be transferred to the script and the type used for the name */ - _array = getArray (_config >> "output"); - _outputClass = _array select 0; - _outputType = _array select 1; + local _array = getArray (_config >> "output"); + local _outputClass = _array select 0; + local _outputType = _array select 1; _name = getText (configFile >> _outputType >> _outputClass >> "displayName"); _compile = format["_id = ['%2',%3] %1;",_script,_item,_array]; }; _menu ctrlSetText format[_type,_name]; _menu ctrlSetEventHandler ["ButtonClick",_compile]; + _i = _i + 1; }; _pos set [3,_height]; @@ -77,4 +75,4 @@ if (_button == 1) then { ctrlSetFocus _group; _group ctrlSetPosition _pos; _group ctrlCommit 0; -}; +}; \ No newline at end of file diff --git a/SQF/dayz_code/configVariables.sqf b/SQF/dayz_code/configVariables.sqf index bba4f3b6d..553cdbf90 100644 --- a/SQF/dayz_code/configVariables.sqf +++ b/SQF/dayz_code/configVariables.sqf @@ -160,6 +160,25 @@ if (!isDedicated) then { dayz_knifeDulling = false; // Enable knife dulling. Knives need to be sharpened after so many uses. dayz_matchboxCount = false; // Enable match stick count. After five uses matches run out and must be replaced. dayz_waterBottleBreaking = false; // Water bottles have a chance to break when boiling and require duct tape to fix + + /* + DZE_CLICK_ACTIONS + This is where you register your right-click actions + FORMAT -- (no comma after last array entry) + [_classname,_text,_execute,_condition], + PARAMETERS + _classname : the name of the class to click on (example = "ItemBloodbag") + _text : the text for the option that is displayed when right clicking on the item (example = "Self Transfuse") + _execute : compiled code to execute when the option is selected (example = "execVM 'my\scripts\self_transfuse.sqf';") + _condition : compiled code evaluated to determine whether or not the option is displayed (example = {true}) + */ + + DZE_CLICK_ACTIONS = [ + /* ["ItemGPS",localize "STR_CL_CA_SCAN_NEARBY","if(isNil 'CA_GPS_RANGE') then {CA_GPS_RANGE = 1500;};CA_ZOMBIE_COUNT = count ((position player) nearEntities ['zZombie_Base',CA_GPS_RANGE]); CA_MAN_COUNT = count ((position player) nearEntities ['CAManBase',CA_GPS_RANGE]); format[localize 'STR_CL_CA_SCAN',CA_GPS_RANGE,CA_MAN_COUNT - CA_ZOMBIE_COUNT,count ((position player) nearEntities ['zZombie_Base',CA_GPS_RANGE]),count ((position player) nearEntities ['allVehicles',CA_GPS_RANGE]) - CA_MAN_COUNT] call dayz_rollingMessages;","true"], + ["ItemGPS",localize "STR_CL_CA_RANGE_UP","if(isNil 'CA_GPS_RANGE') then {CA_GPS_RANGE = 1500;};CA_GPS_RANGE = (CA_GPS_RANGE + 100) min 2500; format[localize 'STR_CL_CA_RANGE_GPS',CA_GPS_RANGE] call dayz_rollingMessages;","true"], + ["ItemGPS",localize "STR_CL_CA_RANGE_DOWN","if(isNil 'CA_GPS_RANGE') then {CA_GPS_RANGE = 1500;};CA_GPS_RANGE = (CA_GPS_RANGE - 100) max 1000; format[localize 'STR_CL_CA_RANGE_GPS',CA_GPS_RANGE] call dayz_rollingMessages;","true"] + */ + ]; }; // Both diff --git a/SQF/dayz_code/init/compiles.sqf b/SQF/dayz_code/init/compiles.sqf index cb0135c07..ad0589cd6 100644 --- a/SQF/dayz_code/init/compiles.sqf +++ b/SQF/dayz_code/init/compiles.sqf @@ -112,7 +112,12 @@ if (!isDedicated) then { //ui player_toggleSoundMute = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\player_toggleSoundMute.sqf"; player_toggleStreamerMode = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\player_toggleStreamerMode.sqf"; - player_selectSlot = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\ui_selectSlot.sqf"; + if (!isNil "DZE_CLICK_ACTIONS" && {count DZE_CLICK_ACTIONS > 0}) then { + player_selectSlot = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\Rightclicks\ui_selectSlot_addon.sqf"; + } else { + player_selectSlot = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\Rightclicks\ui_selectSlot_vanilla.sqf"; + DZE_CLICK_ACTIONS = nil; + }; player_selectWeapon = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\player_selectWeapon.sqf"; player_markMap = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\player_markMap.sqf"; player_gearSet = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\player_gearSet.sqf";