mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Merge pull request #1739 from acemod/virtualAttachObject
Virtual attach object
This commit is contained in:
commit
7da258111d
30
addons/attach/GUI_VirtualAmmo.hpp
Normal file
30
addons/attach/GUI_VirtualAmmo.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
class RscTitles {
|
||||
class GVAR(virtualAmmo) {
|
||||
idd = -1;
|
||||
movingEnable = 1;
|
||||
duration = 9999999;
|
||||
fadein = 0;
|
||||
fadeout = 0;
|
||||
onLoad = "uiNamespace setVariable ['ACE_attach_virtualAmmoDisplay', (_this select 0)];";
|
||||
class controls {};
|
||||
class objects {
|
||||
class TheObject {
|
||||
idc = 800851;
|
||||
type = 82;
|
||||
model = "\a3\weapons_f\Ammo\Handgrenade.p3d";
|
||||
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;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
@ -16,3 +16,4 @@ class CfgPatches {
|
||||
#include "CfgMagazines.hpp"
|
||||
#include "CfgVehicles.hpp"
|
||||
#include "CfgWeapons.hpp"
|
||||
#include "GUI_VirtualAmmo.hpp"
|
||||
|
@ -17,7 +17,7 @@
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_itemClassname", "_itemVehClass", "_onAtachText", "_selfAttachPosition", "_attachedItem", "_tempObject", "_actionID"];
|
||||
private ["_itemClassname", "_itemVehClass", "_onAtachText", "_selfAttachPosition", "_attachedItem", "_tempObject", "_actionID", "_model"];
|
||||
|
||||
PARAMS_3(_attachToVehicle,_unit,_args);
|
||||
_itemClassname = [_args, 0, ""] call CBA_fnc_defaultParam;
|
||||
@ -47,26 +47,43 @@ if (_unit == _attachToVehicle) then { //Self Attachment
|
||||
_attachToVehicle setVariable [QGVAR(Objects), [_attachedItem], true];
|
||||
_attachToVehicle setVariable [QGVAR(ItemNames), [_itemClassname], true];
|
||||
} else {
|
||||
GVAR(placeAction) = -1;
|
||||
|
||||
_tempObject = _itemVehClass createVehicleLocal [0,0,-10000];
|
||||
_tempObject enableSimulationGlobal false;
|
||||
GVAR(placeAction) = PLACE_WAITING;
|
||||
|
||||
[_unit, QGVAR(vehAttach), true] call EFUNC(common,setForceWalkStatus);
|
||||
|
||||
//MenuBack isn't working for now (localize "STR_ACE_Attach_CancelAction")
|
||||
[{[localize LSTRING(PlaceAction), ""] call EFUNC(interaction,showMouseHint)}, []] call EFUNC(common,execNextFrame);
|
||||
_unit setVariable [QGVAR(placeActionEH), [_unit, "DefaultAction", {true}, {GVAR(placeAction) = 1;}] call EFUNC(common,AddActionEventHandler)];
|
||||
// _unit setVariable [QGVAR(cancelActionEH), [_unit, "MenuBack", {true}, {GVAR(placeAction) = 0;}] call EFUNC(common,AddActionEventHandler)];
|
||||
_unit setVariable [QGVAR(placeActionEH), [_unit, "DefaultAction", {true}, {GVAR(placeAction) = PLACE_APPROVE;}] call EFUNC(common,AddActionEventHandler)];
|
||||
|
||||
_actionID = _unit addAction [format ["<t color='#FF0000'>%1</t>", localize LSTRING(CancelAction)], {GVAR(placeAction) = 0}];
|
||||
_actionID = _unit addAction [format ["<t color='#FF0000'>%1</t>", localize LSTRING(CancelAction)], {GVAR(placeAction) = PLACE_CANCEL}];
|
||||
|
||||
//Display to show virtual object:
|
||||
private [];
|
||||
_model = getText (configFile >> "CfgAmmo" >> _itemVehClass >> "model");
|
||||
if (_model == "") then {
|
||||
_model = getText (configFile >> "CfgVehicles" >> _itemVehClass >> "model");
|
||||
};
|
||||
//"\A3\Weapons_F\empty.p3d" is fine, but ctrlSetModel ""; - will crash game!
|
||||
if (_model == "") exitWith {ERROR("No Model");};
|
||||
(QGVAR(virtualAmmo) call BIS_fnc_rscLayer) cutRsc [QGVAR(virtualAmmo), "PLAIN", 0, false];
|
||||
((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlSetModel _model;
|
||||
|
||||
[{
|
||||
private "_startingPosition";
|
||||
PARAMS_2(_args,_pfID);
|
||||
EXPLODE_7_PVT(_args,_unit,_attachToVehicle,_itemClassname,_itemVehClass,_tempObject,_onAtachText,_actionID);
|
||||
private["_angle", "_dir", "_screenPos", "_realDistance", "_up", "_virtualPos", "_virtualPosASL", "_lineInterection"];
|
||||
|
||||
if ((GVAR(placeAction) != -1) ||
|
||||
PARAMS_2(_args,_pfID);
|
||||
EXPLODE_6_PVT(_args,_unit,_attachToVehicle,_itemClassname,_itemVehClass,_onAtachText,_actionID);
|
||||
|
||||
_virtualPosASL = (eyePos _unit) vectorAdd (positionCameraToWorld [0,0,0.6]) 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);
|
||||
_lineInterection = lineIntersects [eyePos ACE_player, _virtualPosASL, ACE_player];
|
||||
|
||||
//Don't allow placing in a bad position:
|
||||
if (_lineInterection && {GVAR(placeAction) == PLACE_APPROVE}) then {GVAR(placeAction) = PLACE_WAITING;};
|
||||
|
||||
if ((GVAR(placeAction) != PLACE_WAITING) ||
|
||||
{_unit != ACE_player} ||
|
||||
{!([_unit, _attachToVehicle, []] call EFUNC(common,canInteractWith))} ||
|
||||
{!([_attachToVehicle, _unit, _itemClassname] call FUNC(canAttach))}) then {
|
||||
@ -75,16 +92,31 @@ if (_unit == _attachToVehicle) then { //Self Attachment
|
||||
[_unit, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus);
|
||||
[] call EFUNC(interaction,hideMouseHint);
|
||||
[_unit, "DefaultAction", (_unit getVariable [QGVAR(placeActionEH), -1])] call EFUNC(common,removeActionEventHandler);
|
||||
//[_unit, "MenuBack", (_unit getVariable [QGVAR(cancelActionEH), -1])] call EFUNC(common,removeActionEventHandler);
|
||||
_unit removeAction _actionID;
|
||||
|
||||
if (GVAR(placeAction) == 1) then {
|
||||
_startingPosition = _tempObject modelToWorldVisual [0,0,0];
|
||||
[_unit, _attachToVehicle, _itemClassname, _itemVehClass, _onAtachText, _startingPosition] call FUNC(placeApprove);
|
||||
(QGVAR(virtualAmmo) call BIS_fnc_rscLayer) cutText ["", "PLAIN"];
|
||||
|
||||
if (GVAR(placeAction) == PLACE_APPROVE) then {
|
||||
[_unit, _attachToVehicle, _itemClassname, _itemVehClass, _onAtachText, _virtualPos] call FUNC(placeApprove);
|
||||
};
|
||||
deleteVehicle _tempObject;
|
||||
} else {
|
||||
_tempObject setPosATL ((ASLtoATL eyePos _unit) vectorAdd (positionCameraToWorld [0,0,1] vectorDiff positionCameraToWorld [0,0,0]));;
|
||||
//Show the virtual object:
|
||||
if (_lineInterection) 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);
|
||||
_up = [0, cos _angle, sin _angle];
|
||||
((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlSetModelDirAndUp [[1,0,0], _up];
|
||||
};
|
||||
};
|
||||
}, 0, [_unit, _attachToVehicle, _itemClassname, _itemVehClass, _tempObject, _onAtachText, _actionID]] call CBA_fnc_addPerFrameHandler;
|
||||
}, 0, [_unit, _attachToVehicle, _itemClassname, _itemVehClass, _onAtachText, _actionID]] call CBA_fnc_addPerFrameHandler;
|
||||
};
|
||||
|
@ -25,7 +25,7 @@
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_startingOffset", "_startDistanceFromCenter", "_closeInUnitVector", "_closeInMax", "_closeInMin", "_setupObject", "_closeInDistance", "_endPosTestOffset", "_endPosTest", "_doesIntersect", "_startingPosShifted", "_startASL", "_endPosShifted", "_endASL", "_attachedObject", "_currentObjects", "_currentItemNames"];
|
||||
private ["_startingOffset", "_startDistanceFromCenter", "_closeInUnitVector", "_closeInMax", "_closeInMin", "_closeInDistance", "_endPosTestOffset", "_endPosTest", "_doesIntersect", "_startingPosShifted", "_startASL", "_endPosShifted", "_endASL", "_attachedObject", "_currentObjects", "_currentItemNames"];
|
||||
|
||||
PARAMS_6(_unit,_attachToVehicle,_itemClassname,_itemVehClass,_onAtachText,_startingPosition);
|
||||
|
||||
@ -37,9 +37,6 @@ _closeInUnitVector = vectorNormalized (_startingOffset vectorFromTo [0,0,0]);
|
||||
_closeInMax = _startDistanceFromCenter;
|
||||
_closeInMin = 0;
|
||||
|
||||
//Delete Local Placement Object
|
||||
deleteVehicle _setupObject;
|
||||
|
||||
while {(_closeInMax - _closeInMin) > 0.01} do {
|
||||
_closeInDistance = (_closeInMax + _closeInMin) / 2;
|
||||
// systemChat format ["Trying %1 from %2 start %3", _closeInDistance, [_closeInMax, _closeInMin], _startDistanceFromCenter];
|
||||
|
@ -9,4 +9,8 @@
|
||||
#define DEBUG_SETTINGS DEBUG_SETTINGS_ATTACH
|
||||
#endif
|
||||
|
||||
#include "\z\ace\addons\main\script_macros.hpp"
|
||||
#include "\z\ace\addons\main\script_macros.hpp"
|
||||
|
||||
#define PLACE_WAITING -1
|
||||
#define PLACE_CANCEL 0
|
||||
#define PLACE_APPROVE 1
|
||||
|
Loading…
Reference in New Issue
Block a user