Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AttachManualCameraComponent.c
Go to the documentation of this file.
1
2
4[BaseContainerProps(), SCR_BaseManualCameraComponentTitle()]
6{
7 [Attribute(defvalue: "0")]
8 protected bool m_bRotateWithTarget;
9
10 [Attribute(string.Format("%1", EAttachManualCameraType.INPUT), UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EAttachManualCameraType))]
11 private EAttachManualCameraType m_AttachType;
12
13 [Attribute(params: "layout")]
14 private ResourceName m_Layout;
15
16 protected IEntity m_Target;
17 protected SCR_AttachEntity m_AttachHelper;
18 protected bool m_bAttachChanged;
19 private Widget m_Widget;
21
22 //------------------------------------------------------------------------------------------------
26 bool AttachTo(IEntity target)
27 {
28 //--- No target, already attached target or inactive target - ignore
29 if (!target || target == m_Target || !SCR_Enum.HasFlag(target.GetFlags(), EntityFlags.TRACEABLE))
30 return false;
31
33 if (!camera)
34 return false;
35
36 Physics targetPhysics = target.GetPhysics();
37 //--- A target is static if is not kinematic and not dynamic (eg: tree)
38 if (targetPhysics && !targetPhysics.IsKinematic() && !targetPhysics.IsDynamic())
39 return false;
40
41 //--- Already attached - detach first
43 Detach();
44
45 m_Target = target;
46
47 //--- Create helper entity and attach camera to it, so it moves in its local coordinate space
48 //--- Don't attach on target itself, because we only want to move, not rotate camera with it
49 EntitySpawnParams spawnParams = new EntitySpawnParams;
50 spawnParams.Transform[3] = m_Target.CoordToParent(vector.Zero);
51 m_AttachHelper = SCR_AttachEntity.Cast(GetGame().SpawnEntity(SCR_AttachEntity, camera.GetWorld(), spawnParams));
52 m_AttachHelper.AttachTo(m_Target);
53 m_AttachHelper.RotateWithTarget(m_bRotateWithTarget);
54 m_AttachHelper.EOnPostFrame(m_AttachHelper, 0);
56
57 m_bAttachChanged = true;
58
59 m_OnAttachChange.Invoke(true, m_Target);
60
61 //Print("Attached to " + target.ToString(), LogLevel.DEBUG);
62
63 return true;
64 }
65
66 //------------------------------------------------------------------------------------------------
68 void Detach()
69 {
70 if (!m_AttachHelper)
71 return;
72
74 if (!camera)
75 return;
76
77 m_OnAttachChange.Invoke(false, m_Target);
78
79 m_Target = null;
80
81 //--- Detach and delete the attach helper
82 camera.Detach();
83 delete m_AttachHelper;
84
85 m_bAttachChanged = true;
86
87 //Print("Detach", LogLevel.DEBUG);
88 }
89
90 //------------------------------------------------------------------------------------------------
97
98 //------------------------------------------------------------------------------------------------
100 {
101 if (m_Target)
102 {
103 data.m_aValues = {m_AttachType};
104 data.m_Target = m_Target;
105 }
106 }
107
108 //------------------------------------------------------------------------------------------------
110 {
111 if (data.m_Target && m_AttachType == data.m_aValues[0] && m_AttachType != EAttachManualCameraType.PLAYER)
112 AttachTo(data.m_Target);
113 }
114
115 //------------------------------------------------------------------------------------------------
117 {
118 //--- Target deleted, detach
119 if (m_AttachHelper && !m_Target)
120 Detach();
121
122 if (!param.isManualInputEnabled)
123 {
124 if (m_Widget)
125 m_Widget.SetVisible(false);
126
127 return;
128 }
129
130 //--- Change attachment on input
131 switch (m_AttachType)
132 {
133 case EAttachManualCameraType.INPUT:
134 {
135 if (param.isManualInputEnabled && GetInputManager().GetActionTriggered("ManualCameraAttach"))
136 {
137 param.GetCursorWorldPos(); //--- Update entity under cursor
138 if (!AttachTo(param.target))
139 Detach();
140 }
141 break;
142 }
143
144 case EAttachManualCameraType.PLAYER:
145 {
146 if (!m_AttachHelper)
148
149 break;
150 }
151
152 case EAttachManualCameraType.ENTITY:
153 {
154 if (!m_AttachHelper)
156
157 break;
158 }
159 }
160
161 //--- Convert camera coordinates to local space
163 {
164 m_bAttachChanged = false;
165
167 if (camera)
168 {
169 camera.GetLocalTransform(param.transform);
170 camera.GetLocalTransform(param.transformOriginal);
171 param.isDirty = true;
172 }
173
174 if (m_Widget)
175 m_Widget.SetVisible(m_Target != null);
176 }
177
178 //--- Update GUI
179 if (m_Widget && m_Target)
180 {
181 m_Widget.SetVisible(true);
182 vector screenPos = m_Widget.GetWorkspace().ProjWorldToScreen(m_AttachHelper.GetOrigin(), param.world);
183 if (screenPos[2] > 0)
184 FrameSlot.SetPos(m_Widget, screenPos[0], screenPos[1]);
185 }
186 }
187
188 //------------------------------------------------------------------------------------------------
189 override bool EOnCameraInit()
190 {
191 m_Widget = GetCameraEntity().CreateCameraWidget(m_Layout, false);
192 return true;
193 }
194
195 //------------------------------------------------------------------------------------------------
196 override void EOnCameraExit()
197 {
198 if (m_Widget)
199 m_Widget.RemoveFromHierarchy();
200
201 delete m_AttachHelper;
202 }
203}
204
205class SCR_AttachEntityClass : GenericEntityClass
206{
207}
208
209class SCR_AttachEntity : GenericEntity
210{
212 private bool m_bRotateWithTarget;
213
214 //------------------------------------------------------------------------------------------------
217 void RotateWithTarget(bool rotate)
218 {
219 m_bRotateWithTarget = rotate;
220 }
221
222 //------------------------------------------------------------------------------------------------
225 void AttachTo(IEntity target)
226 {
227 m_Target = target;
228 SetEventMask(EntityEvent.POSTFRAME);
229 SetFlags(EntityFlags.ACTIVE);
230 }
231
232 //------------------------------------------------------------------------------------------------
233 override void EOnPostFrame(IEntity owner, float timeSlice)
234 {
235 if (!m_Target)
236 return;
237
238 if (m_bRotateWithTarget)
239 {
240 vector transform[4];
241 m_Target.GetWorldTransform(transform);
242 SetWorldTransform(transform);
243 }
244 else
245 {
246 SetOrigin(m_Target.GetWorldTransformAxis(3));
247 }
248 }
249}
250
251enum EAttachManualCameraType
252{
253 NONE,
254 INPUT,
255 PLAYER,
256 ENTITY
257}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
class SCR_AIPolar m_Target
IEntity SpawnEntity(ResourceName entityResourceName, notnull IEntity slotOwner)
Get all prefabs that have the spawner data
enum EVehicleType IEntity
proto external EntityFlags GetFlags()
proto external EntityEvent SetEventMask(EntityEvent e)
proto external void SetOrigin(vector orig)
proto external Physics GetPhysics()
void EOnPostFrame(IEntity owner, float timeSlice)
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
proto external bool SetWorldTransform(vector mat[4])
See IEntity::SetTransform. Returns false, if there is no change in transformation.
override void EOnCameraFrame(SCR_ManualCameraParam param)
override void EOnCameraSave(SCR_ManualCameraComponentSave data)
override void EOnCameraLoad(SCR_ManualCameraComponentSave data)
void Detach()
Detach camera from its parent entity.
Parent class from which all SCR_ManualCamera components inherit.
Widget CreateCameraWidget(ResourceName layout, bool isVisible=true)
void AttachTo(IEntity parent)
void Detach()
Detach camera from its parent entity.
Parameter for carrying information between individual camera components.
IEntity target
Entity under cursor.
BaseWorld world
World in which the camera exists.
static IEntity GetLocalMainEntity()
void EntitySpawnParams()
Definition gameLib.c:130
@ NONE
When Shape is created and not initialized yet.
Definition ShapeType.c:15
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134