diff --git a/addons/explosives/GUI_VirtualAmmo.hpp b/addons/explosives/GUI_VirtualAmmo.hpp new file mode 100644 index 0000000000..96e5b452ee --- /dev/null +++ b/addons/explosives/GUI_VirtualAmmo.hpp @@ -0,0 +1,30 @@ +class RscTitles { + class GVAR(virtualAmmo) { + idd = -1; + movingEnable = 1; + duration = 9999999; + fadein = 0; + fadeout = 0; + onLoad = "uiNamespace setVariable ['ACE_explosives_virtualAmmoDisplay', (_this select 0)];"; + class controls {}; + class objects { + class TheObject { + idc = 800851; + type = 82; + model = "\a3\weapons_f\Ammo\Handgrenade.p3d"; //dummy value, cannot be "" !!! + scale = 1; + direction[] = {0, 0, 1}; + up[] = {0, 1, 0}; + x = 0.5; + y = 0.5; + z = 1; + xBack = 0.5; + yBack = 0.5; + zBack = 0.5; + inBack = 0; + enableZoom = 0; + zoomDuration = 1; + }; + }; + }; +}; diff --git a/addons/explosives/config.cpp b/addons/explosives/config.cpp index 873c4e0dc3..99544213d3 100644 --- a/addons/explosives/config.cpp +++ b/addons/explosives/config.cpp @@ -12,6 +12,8 @@ class CfgPatches { }; }; +#include "ACE_Settings.hpp" + #include "CfgEventHandlers.hpp" #include "CfgAmmo.hpp" @@ -21,6 +23,7 @@ class CfgPatches { #include "ACE_Triggers.hpp" #include "ExplosivesUI.hpp" +#include "GUI_VirtualAmmo.hpp" class CfgActions { class None; @@ -39,5 +42,3 @@ class CfgMineTriggers { mineTriggerRange = 1; }; }; - -#include "ACE_Settings.hpp" diff --git a/addons/explosives/functions/fnc_addExplosiveActions.sqf b/addons/explosives/functions/fnc_addExplosiveActions.sqf index 214b41602c..005163f2db 100644 --- a/addons/explosives/functions/fnc_addExplosiveActions.sqf +++ b/addons/explosives/functions/fnc_addExplosiveActions.sqf @@ -43,10 +43,10 @@ _children = []; format ["Explosive_%1", _forEachIndex], format [_name + " (%1)", _itemCount select _foreachIndex], getText(_x >> "picture"), - {(_this select 2) call FUNC(setupExplosive);}, + {_this call FUNC(setupExplosive);}, {true}, {}, - [_unit, configName _x] + (configName _x) ] call EFUNC(interact_menu,createAction), [], _unit diff --git a/addons/explosives/functions/fnc_handleScrollWheel.sqf b/addons/explosives/functions/fnc_handleScrollWheel.sqf index 3bef53e196..3f0552bfd2 100644 --- a/addons/explosives/functions/fnc_handleScrollWheel.sqf +++ b/addons/explosives/functions/fnc_handleScrollWheel.sqf @@ -14,9 +14,9 @@ * Public: No */ #include "script_component.hpp" -if (isNull(GVAR(Setup)) || {ACE_Modifier == 0} || !GVAR(pfeh_running)) exitWith {false}; -_this = _this * 5; -GVAR(Setup) setDir ((getDir GVAR(Setup)) + _this); -GVAR(TweakedAngle) = GVAR(TweakedAngle) + _this; + +if ((!GVAR(pfeh_running)) || {ACE_Modifier == 0}) exitWith {false}; + +GVAR(TweakedAngle) = ((GVAR(TweakedAngle) + 5 * _this) + 360) % 360; true diff --git a/addons/explosives/functions/fnc_setupExplosive.sqf b/addons/explosives/functions/fnc_setupExplosive.sqf index 566ab9c281..14b2b52844 100644 --- a/addons/explosives/functions/fnc_setupExplosive.sqf +++ b/addons/explosives/functions/fnc_setupExplosive.sqf @@ -3,8 +3,9 @@ * Starts the setup process for the passed explosive. Player only. * * Arguments: - * 0: Unit - * 1: Classname of explosive to place. (CfgMagazine class) + * 0: Vehicle + * 1: Player Unit + * 2: Classname of explosive to place. (CfgMagazine class) * * Return Value: * None @@ -15,6 +16,120 @@ * Public: Yes */ #include "script_component.hpp" + +PARAMS_3(_vehicle,_player,_magClassname); + +[_player, "ACE_Explosives", true] call EFUNC(common,setForceWalkStatus); +GVAR(TweakedAngle) = 0; + +//Get setup object vehicle and model: +_setupObjectClass = getText(ConfigFile >> "CfgMagazines" >> _magClassname >> "ACE_SetupObject"); +if (!isClass (configFile >> "CfgVehicles" >> _setupObjectClass)) exitWith {ERROR("Bad Vehicle");}; +_p3dModel = getText (configFile >> "CfgVehicles" >> _setupObjectClass >> "model"); +if (_p3dModel == "") exitWith {ERROR("No Model");}; //"" - will crash game! + +[localize LSTRING(PlaceAction), localize LSTRING(CancelAction), localize LSTRING(ScrollAction)] call EFUNC(interaction,showMouseHint); +_player setVariable [QGVAR(placeActionEH), [_player, "DefaultAction", {true}, {GVAR(placeAction) = PLACE_APPROVE;}] call EFUNC(common,AddActionEventHandler)]; +_player setVariable [QGVAR(cancelActionEH), [_player, "zoomtemp", {true}, {GVAR(placeAction) = PLACE_CANCEL;}] call EFUNC(common,AddActionEventHandler)]; + + +//Display to show virtual object: +(QGVAR(virtualAmmo) call BIS_fnc_rscLayer) cutRsc [QGVAR(virtualAmmo), "PLAIN", 0, false]; +((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlSetModel _p3dModel; + +GVAR(pfeh_running) = true; +GVAR(placeAction) = PLACE_WAITING; + + +[{ + private["_angle", "_dir", "_screenPos", "_realDistance", "_up", "_virtualPos", "_virtualPosASL", "_badPosition"]; + + PARAMS_2(_args,_pfID); + EXPLODE_3_PVT(_args,_unit,_magClassname,_setupObjectClass); + + _virtualPosASL = (eyePos _unit) vectorAdd (positionCameraToWorld [0,0,1]) vectorDiff (positionCameraToWorld [0,0,0]); + if (cameraView == "EXTERNAL") then { + _virtualPosASL = _virtualPosASL vectorAdd ((positionCameraToWorld [0.3,0,0]) vectorDiff (positionCameraToWorld [0,0,0])); + }; + _virtualPos = _virtualPosASL call EFUNC(common,ASLToPosition); + _intersectsWith = lineIntersectsWith [eyePos ACE_player, _virtualPosASL, ACE_player]; + + hintSilent format ["IntersectsWith %1", _intersectsWith]; + + _badPosition = (count _intersectsWith) > 0; + + //Don't allow placing in a bad position: + if (_badPosition && {GVAR(placeAction) == PLACE_APPROVE}) then {GVAR(placeAction) = PLACE_WAITING;}; + + //Cancel on RMB, For some reason this works (when held) but AddActionEventHandler doesn't + if ((inputAction "zoomTemp") > 0) then {GVAR(placeAction) = PLACE_CANCEL;}; + + if ((GVAR(placeAction) != PLACE_WAITING) || + {_unit != ACE_player} || + {(inputAction "optics") > 0}) then { + + [_pfID] call CBA_fnc_removePerFrameHandler; + GVAR(pfeh_running) = false; + + [_unit, "ACE_Explosives", false] call EFUNC(common,setForceWalkStatus); + [] call EFUNC(interaction,hideMouseHint); + [_unit, "DefaultAction", (_unit getVariable [QGVAR(placeActionEH), -1])] call EFUNC(common,removeActionEventHandler); + [_unit, "zoomtemp", (_unit getVariable [QGVAR(cancelActionEH), -1])] call EFUNC(common,removeActionEventHandler); + + (QGVAR(virtualAmmo) call BIS_fnc_rscLayer) cutText ["", "PLAIN"]; + + if (GVAR(placeAction) == PLACE_APPROVE) then { + systemChat "place"; + _dir = (positionCameraToWorld [0,0,0]) vectorFromTo (positionCameraToWorld [0,0,1]); + _angle = ((_dir select 0) atan2 (_dir select 1)) - GVAR(TweakedAngle) - 180; + + systemChat format ["Pos %1, Cam %2, Ang %3", _virtualPosASL, ((_dir select 0) atan2 (_dir select 1)), _angle]; + + _realObject = _setupObjectClass createVehicle _virtualPos; + _realObject setPosAsl _virtualPosASL; + _realObject setDir _angle; + // [_unit, _attachToVehicle, _itemClassname, _itemVehClass, _onAtachText, _virtualPos] call FUNC(placeApprove); + }; + } else { + // systemChat format ["A Running %1 - %2", time, _badPosition]; + //Show the virtual object: + if (_badPosition) then { + ((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlShow false; + } else { + ((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlShow true; + _screenPos = worldToScreen _virtualPos; + if (_screenPos isEqualTo []) exitWith { + ((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlShow false; + }; + _realDistance = (_virtualPos distance (positionCameraToWorld [0,0,0])) / ((call CBA_fnc_getFov) select 1); + _screenPos = [(_screenPos select 0), _realDistance, (_screenPos select 1)]; + ((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlSetPosition _screenPos; + _dir = (positionCameraToWorld [0,0,1]) vectorFromTo (positionCameraToWorld [0,0,0]); + _angle = asin (_dir select 2) + 90; + + _modelUp = [0, (cos _angle), (sin _angle)]; + _modelDir = [cos GVAR(TweakedAngle), sin GVAR(TweakedAngle), 0] vectorCrossProduct _modelUp; + + // systemChat format ["Running %1", [_modelDir, _modelUp]]; + ((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlSetModelDirAndUp [_modelDir, _modelUp]; + }; + }; +}, 0, [_player, _magClassname, _setupObjectClass]] call CBA_fnc_addPerFrameHandler; + + + + + + + + + + + + +/* + + closeDialog 0; EXPLODE_2_PVT(_this,_unit,_class); GVAR(placer) = _unit; @@ -24,8 +139,8 @@ GVAR(Setup) = createVehicle [getText(ConfigFile >> "CfgMagazines" >> _class >> " GVAR(Setup) enableSimulationGlobal false; GVAR(Setup) setVariable [QGVAR(class), _class, true]; -[_unit, "ACE_Explosives", true] call EFUNC(common,setForceWalkStatus); -GVAR(TweakedAngle) = 180; + + [QGVAR(Placement),"OnEachFrame", { private ["_player", "_pos"]; @@ -41,9 +156,4 @@ GVAR(TweakedAngle) = 180; }; }] call CALLSTACK(BIS_fnc_addStackedEventHandler); -[localize LSTRING(PlaceAction), localize LSTRING(CancelAction), - localize LSTRING(ScrollAction)] call EFUNC(interaction,showMouseHint); -_unit setVariable [QGVAR(Place), [_unit, "DefaultAction", - {GVAR(pfeh_running) AND !isNull (GVAR(Setup))}, {call FUNC(place_Approve);}] call EFUNC(common,AddActionEventHandler)]; -_unit setVariable [QGVAR(Cancel), [_unit, "zoomtemp", - {GVAR(pfeh_running) AND !isNull (GVAR(Setup))}, {call FUNC(place_Cancel);}] call EFUNC(common,AddActionEventHandler)]; + */ diff --git a/addons/explosives/script_component.hpp b/addons/explosives/script_component.hpp index 5ff12b8ba3..057f0aa086 100644 --- a/addons/explosives/script_component.hpp +++ b/addons/explosives/script_component.hpp @@ -12,3 +12,7 @@ #endif #include "\z\ace\addons\main\script_macros.hpp" + +#define PLACE_WAITING -1 +#define PLACE_CANCEL 0 +#define PLACE_APPROVE 1 \ No newline at end of file