1 [
EntityEditorProps(
category:
"GameScripted/Weapon/Sights/Picture in Picture Sights", description:
"", color:
"0 0 255 255")]
9 [
Attribute(
"{EF091399D840192D}UI/layouts/Sights/PictureInPictureSightsLayout.layout", UIWidgets.ResourceNamePicker,
"The layout used for this PIP component",
params:
"layout")]
10 protected ResourceName m_sLayoutResource;
12 [
Attribute(
"RTTexture0", UIWidgets.EditBox,
"Name of RTTexture widget within provided layout")]
13 protected string m_sRTTextureWidgetName;
15 [
Attribute(
"RenderTarget0", UIWidgets.EditBox,
"Name of RenderTarget widget within provided layout")]
16 protected string m_sRTargetWidgetName;
18 [
Attribute(
"1", UIWidgets.Slider,
"Camera index used for this PIP component",
params:
"0 31 1")]
19 protected int m_iCameraIndex;
21 [
Attribute(
"12.5", UIWidgets.Slider,
"Camera field of view used by this PIP component",
params:
"0 89.9 0.1")]
22 protected float m_fCameraFOV;
24 [
Attribute(
"0.2", UIWidgets.Slider,
"Camera near clipping plane",
params:
"0 1000 0.01")]
25 protected float m_fNearPlane;
27 [
Attribute(
"1500", UIWidgets.Slider,
"Camera field of view used by this PIP component",
params:
"0 5000 1")]
28 protected float m_fFarPlane;
31 [
Attribute(
"1.0", UIWidgets.EditBox,
"Scale of resolution used by the PIP",
params:
"0.1 1 0.1")]
32 protected float m_fResolutionScale;
35 [
Attribute(
"0 0 0", UIWidgets.EditBox,
"Camera offset used for this PIP")]
36 protected vector m_vCameraPoint;
40 protected bool m_bIsEnabled;
43 protected ref Widget m_wRoot;
46 protected IEntity m_pOwner;
49 protected RTTextureWidget m_wRenderTargetTextureWidget;
52 protected RenderTargetWidget m_wRenderTargetWidget;
55 protected ScriptCamera m_PIPCamera;
59 protected override void _WB_AfterWorldUpdate(IEntity owner,
float timeSlice)
61 const float axisLength = 0.1;
63 vector origin = owner.GetOrigin() + m_vCameraPoint;
64 vector right = origin + owner.GetTransformAxis(0) * axisLength;
65 vector up = origin + owner.GetTransformAxis(1) * axisLength;
66 vector fwd = origin + owner.GetTransformAxis(2) * axisLength;
68 ref
auto rightArrow = Shape.CreateArrow(origin, right, 0.01, ARGB(240,255,0,0), ShapeFlags.ONCE);
69 ref
auto upArrow = Shape.CreateArrow(origin, up, 0.01, ARGB(240,0,255,0), ShapeFlags.ONCE);
70 ref
auto fwdArrow = Shape.CreateArrow(origin, fwd, 0.01, ARGB(240,0,0,255), ShapeFlags.ONCE);
75 void SetEnabled(
bool enabled)
88 if (!
m_wRoot || !m_wRenderTargetTextureWidget || !m_wRenderTargetWidget)
89 m_wRoot = CreateUI(m_sLayoutResource, m_sRTTextureWidgetName, m_sRTargetWidgetName, m_wRenderTargetTextureWidget, m_wRenderTargetWidget);
93 Print(
"Could not create PIP layout!");
99 m_PIPCamera = CreateCamera(m_pOwner, m_vCameraPoint, m_iCameraIndex, m_fCameraFOV, m_fNearPlane, m_fFarPlane);
102 BaseWorld baseWorld = m_pOwner.GetWorld();
103 m_wRenderTargetWidget.SetWorld(baseWorld, m_iCameraIndex);
106 m_wRenderTargetWidget.SetResolutionScale(m_fResolutionScale, m_fResolutionScale);
109 m_wRenderTargetTextureWidget.SetGUIWidget(m_pOwner, 0);
126 protected Widget CreateUI(
string layout,
string rtTextureName,
string rtName, out RTTextureWidget RTTexture, out RenderTargetWidget RTWidget)
129 if (
layout ==
string.Empty)
133 Widget root =
GetGame().GetWorkspace().CreateWidgets(
layout);
140 RTTexture = RTTextureWidget.Cast(root.FindAnyWidget(rtTextureName));
141 RTWidget = RenderTargetWidget.Cast(root.FindAnyWidget(rtName));
142 if (!RTTexture || !RTWidget)
144 root.RemoveFromHierarchy();
152 protected void DestroyUI(Widget root)
156 root.RemoveFromHierarchy();
167 protected ScriptCamera CreateCamera(IEntity parent, vector
position,
int cameraIndex,
float fov,
float nearPlane,
float farPlane)
170 BaseWorld baseWorld = parent.GetWorld();
171 ScriptCamera pipCamera = ScriptCamera.Cast(
GetGame().
SpawnEntity(ScriptCamera, baseWorld));
176 Math3D.MatrixIdentity3(mat);
180 pipCamera.SetTransform(mat);
181 pipCamera.Index = cameraIndex;
182 pipCamera.FreeFly =
false;
194 baseWorld.SetCameraVerticalFOV(cameraIndex, m_fCameraFOV);
195 baseWorld.SetCameraFarPlane(cameraIndex, farPlane);
196 baseWorld.SetCameraNearPlane(cameraIndex, nearPlane);
199 parent.AddChild(pipCamera, -1, EAddChildFlags.AUTO_TRANSFORM);
204 protected void DestroyCamera(ScriptCamera camera)
208 IEntity cameraParent = camera.GetParent();
210 cameraParent.RemoveChild(camera);
218 protected void Destroy()
220 DestroyCamera(m_PIPCamera);
225 protected override void OnSightADSActivated()
228 super.OnSightADSActivated();
232 protected override void OnSightADSDeactivated()
235 super.OnSightADSDeactivated();
239 protected override void OnInit(IEntity owner)