Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MapMarkerEntity.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 [EntityEditorProps(category: "GameScripted/Markers")]
3 class SCR_MapMarkerEntityClass : GenericEntityClass
4 {
5 };
6 
7 //------------------------------------------------------------------------------------------------
11 {
12  [RplProp(onRplName: "OnUpdateType")]
13  protected SCR_EMapMarkerType m_eType;
14 
15  [RplProp()]
16  protected int m_iConfigID = -1; // config id used when marker of a single type has bigger amount of configuration options
17 
18  [RplProp(condition: RplCondition.NoOwner, onRplName: "OnUpdatePosition")]
19  protected vector m_vPos;
20 
21  [RplProp(onRplName: "OnUpdateVisibility")]
22  protected bool m_bIsGlobalVisible; // is this marker visible based on server main conditions, such as it having assigned target
23 
24  protected bool m_bIsLocalVisible = true; // is this marker visible to the player based on custom local conditions
25  protected int m_iScreenX;
26  protected int m_iScreenY;
27  protected float m_fUpdateDelay = 1;
28  protected float m_fTimeTracker;
29 
30  protected string m_sText;
31  protected ResourceName m_sImageset;
32  protected string m_sIconName;
33  protected SCR_MapMarkerEntryDynamic m_ConfigEntry; // marker entry associated with this marker type
34 
35  protected Widget m_wRoot;
36  protected SCR_MapEntity m_MapEntity;
37  protected SCR_MapMarkerDynamicWComponent m_MarkerWidgetComp;
38 
39  // server side
40  protected IEntity m_Target;
41  protected Faction m_MarkerFaction; // if null, no streaming restrictions are applied
42 
43  //------------------------------------------------------------------------------------------------
44  // RPL EVENTS
45  //------------------------------------------------------------------------------------------------
47  protected void OnUpdateType()
48  {
49  OnUpdateVisibility();
50  }
51 
52  //------------------------------------------------------------------------------------------------
54  protected void OnUpdatePosition()
55  {}
56 
57  //------------------------------------------------------------------------------------------------
59  protected void OnUpdateVisibility()
60  {
61  SCR_MapEntity mapEnt = SCR_MapEntity.GetMapInstance();
62  if (!mapEnt || !mapEnt.IsOpen() || mapEnt.GetMapUIComponent(SCR_MapMarkersUI) == null) // map not open or makers not enabled
63  return;
64 
65  if (!IsVisible() && m_wRoot) // should not be visible
66  OnDelete();
67 
68  if (IsVisible() && !m_wRoot) // should be visible
69  OnCreateMarker();
70  }
71 
72  //------------------------------------------------------------------------------------------------
73  // API CLIENT
74  //------------------------------------------------------------------------------------------------
75  void SetLocalVisible(bool state)
76  {
77  m_bIsLocalVisible = state;
78  OnUpdateVisibility();
79  }
80 
81  //------------------------------------------------------------------------------------------------
82  SCR_EMapMarkerType GetType()
83  {
84  return m_eType;
85  }
86 
87  //------------------------------------------------------------------------------------------------
88  int GetMarkerConfigID()
89  {
90  return m_iConfigID;
91  }
92 
93  //------------------------------------------------------------------------------------------------
94  void SetText(string text)
95  {
96  m_sText = text;
97  }
98 
99  //------------------------------------------------------------------------------------------------
100  string GetText()
101  {
102  return m_sText;
103  }
104 
105  //------------------------------------------------------------------------------------------------
106  void SetImage(string imageset, string icon)
107  {
108  m_sImageset = imageset;
109  m_sIconName = icon;
110  }
111 
112  //------------------------------------------------------------------------------------------------
113  void GetImageResource(out ResourceName imageset, out string imageQuad)
114  {
115  imageset = m_sImageset;
116  imageQuad = m_sIconName;
117  }
118 
119  //------------------------------------------------------------------------------------------------
121  vector GetWorldPos()
122  {
123  return m_vPos;
124  }
125 
126  //------------------------------------------------------------------------------------------------
127  // API SERVER
128  //------------------------------------------------------------------------------------------------
129  void SetType(SCR_EMapMarkerType type, int configID = -1)
130  {
131  m_eType = type;
132  OnUpdateType();
133 
134  if (configID != -1)
135  m_iConfigID = configID;
136 
137  Replication.BumpMe();
138  }
139 
140  //------------------------------------------------------------------------------------------------
141  void SetGlobalVisible(bool state)
142  {
143  m_bIsGlobalVisible = state;
144  OnUpdateVisibility();
145  Replication.BumpMe();
146  }
147 
148  //------------------------------------------------------------------------------------------------
150  IEntity GetTarget()
151  {
152  return m_Target;
153  }
154 
155  //------------------------------------------------------------------------------------------------
157  void SetTarget(IEntity target)
158  {
159  m_Target = target;
160 
161  if (target)
162  SetEventMask(EntityEvent.FRAME);
163  else
164  ClearEventMask(EntityEvent.FRAME);
165  }
166 
167  //------------------------------------------------------------------------------------------------
168  Faction GetFaction()
169  {
170  return m_MarkerFaction;
171  }
172 
173  //------------------------------------------------------------------------------------------------
174  void SetFaction(Faction faction)
175  {
176  SCR_MapMarkerManagerComponent markerMgr = SCR_MapMarkerManagerComponent.GetInstance();
177  if (!markerMgr)
178  return;
179 
180  m_MarkerFaction = faction;
181 
182  markerMgr.SetMarkerStreamRules(this);
183  }
184 
185  //------------------------------------------------------------------------------------------------
186  // EVENTS & OTHERS
187  //------------------------------------------------------------------------------------------------
188  protected bool IsVisible()
189  {
190  return m_bIsGlobalVisible && m_bIsLocalVisible;
191  }
192 
193  //------------------------------------------------------------------------------------------------
195  void OnCreateMarker()
196  {
197  if (!IsVisible())
198  return;
199 
200  if (!m_MapEntity)
201  m_MapEntity = SCR_MapEntity.GetMapInstance();
202 
203  if (!m_ConfigEntry)
204  m_ConfigEntry = SCR_MapMarkerEntryDynamic.Cast(SCR_MapMarkerManagerComponent.GetInstance().GetMarkerConfig().GetMarkerEntryConfigByType(m_eType));
205 
206  if (!m_MapEntity || !m_ConfigEntry)
207  return;
208 
209  Widget mapFrame = m_MapEntity.GetMapMenuRoot().FindAnyWidget(SCR_MapConstants.MAP_FRAME_NAME);
210  if (!mapFrame)
211  return;
212 
213  m_wRoot = GetGame().GetWorkspace().CreateWidgets(m_ConfigEntry.GetMarkerLayout(), mapFrame);
214  if (!m_wRoot)
215  return;
216 
217  m_MarkerWidgetComp = SCR_MapMarkerDynamicWComponent.Cast(m_wRoot.FindHandler(SCR_MapMarkerDynamicWComponent));
218  m_MarkerWidgetComp.SetMarkerEntity(this); // todo needs base class
219  m_ConfigEntry.InitClientSettingsDynamic(this, m_MarkerWidgetComp);
220 
221  SCR_MapEntity.GetOnMapClose().Insert(OnMapClosed);
222  SCR_MapEntity.GetOnLayerChanged().Insert(OnMapLayerChanged);
223  OnMapLayerChanged(m_MapEntity.GetLayerIndex());
224  }
225 
226  //------------------------------------------------------------------------------------------------
227  void OnDelete()
228  {
229  if (m_wRoot)
230  m_wRoot.RemoveFromHierarchy();
231  }
232 
233  //------------------------------------------------------------------------------------------------
234  protected void OnMapClosed(MapConfiguration config)
235  {
236  SCR_MapEntity.GetOnMapClose().Remove(OnMapClosed);
237  SCR_MapEntity.GetOnLayerChanged().Remove(OnMapLayerChanged);
238  }
239 
240  //------------------------------------------------------------------------------------------------
241  protected void OnMapLayerChanged(int layerID)
242  {
243  if (m_MarkerWidgetComp)
244  m_MarkerWidgetComp.SetLayerID(layerID);
245 
246  LayerChangeLogic(layerID);
247  }
248 
249  //------------------------------------------------------------------------------------------------
250  void LayerChangeLogic(int layerID)
251  {
252  if (m_ConfigEntry && m_MarkerWidgetComp)
253  m_ConfigEntry.OnMapLayerChangedDynamic(m_MarkerWidgetComp, layerID);
254  }
255 
256  //------------------------------------------------------------------------------------------------
258  void OnUpdate()
259  {
260  if (!m_wRoot)
261  return;
262 
263  m_MapEntity.WorldToScreen(m_vPos[0], m_vPos[2], m_iScreenX, m_iScreenY, true);
264  FrameSlot.SetPos(m_wRoot, GetGame().GetWorkspace().DPIUnscale(m_iScreenX), GetGame().GetWorkspace().DPIUnscale(m_iScreenY)); // needs unscaled coords
265  }
266 
267  //------------------------------------------------------------------------------------------------
268  // OVERRIDES
269  //------------------------------------------------------------------------------------------------
270  override protected void EOnInit(IEntity owner)
271  {
272  SCR_MapMarkerManagerComponent markerMgr = SCR_MapMarkerManagerComponent.GetInstance();
273  if (!markerMgr)
274  return;
275 
276  markerMgr.RegisterDynamicMarker(this);
277 
278  BaseRplComponent rplComp = BaseRplComponent.Cast(FindComponent(BaseRplComponent));
279  if (rplComp.IsOwner()) // Only authority runs frame update
280  {
281  SetFlags(EntityFlags.ACTIVE, true);
282  SetEventMask(EntityEvent.FRAME);
283  }
284 
285  m_fTimeTracker = m_fUpdateDelay; // tick first update instantly
286  }
287 
288  //------------------------------------------------------------------------------------------------
290  override protected void EOnFrame(IEntity owner, float timeSlice)
291  {
292  if (!m_Target)
293  return;
294 
295  m_fTimeTracker += timeSlice;
296  if (m_fTimeTracker >= m_fUpdateDelay)
297  {
298  m_fTimeTracker = 0;
299  m_vPos = m_Target.GetOrigin();
300  Replication.BumpMe();
301  }
302  }
303 
304  //------------------------------------------------------------------------------------------------
305  void SCR_MapMarkerEntity(IEntitySource src, IEntity parent)
306  {
307  SetEventMask(EntityEvent.INIT);
308  }
309 
310  //------------------------------------------------------------------------------------------------
311  void ~SCR_MapMarkerEntity()
312  {
313  if (SCR_MapEntity.GetMapInstance() && SCR_MapEntity.GetMapInstance().IsOpen())
314  OnDelete();
315 
316  SCR_MapMarkerManagerComponent markerMgr = SCR_MapMarkerManagerComponent.GetInstance();
317  if (markerMgr)
318  markerMgr.UnregisterDynamicMarker(this);
319  }
320 
321 }
m_fUpdateDelay
protected float m_fUpdateDelay
Definition: SCR_MotorExhaustEffectGeneralComponent.c:25
m_MapEntity
protected SCR_MapEntity m_MapEntity
Definition: SCR_MapGadgetComponent.c:14
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
SCR_MapMarkerDynamicWComponent
Attached to root of marker dynamic base layout.
Definition: SCR_MapMarkerDynamicWComponent.c:2
RplProp
SCR_RplTestEntityClass RplProp
Used for handling entity spawning requests for SCR_CatalogEntitySpawnerComponent and inherited classe...
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_Target
class SCR_AIPolar m_Target
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
SCR_MapMarkerEntryDynamic
Marker dynamic entry base.
Definition: SCR_MapMarkerEntryDynamic.c:4
SCR_MapMarkerEntity
Definition: SCR_MapMarkerEntity.c:10
SCR_EMapMarkerType
SCR_EMapMarkerType
Definition: SCR_MapMarkerConfig.c:5
SCR_MapEntity
Map entity.
Definition: SCR_MapEntity.c:20
SCR_MapMarkersUI
Markers UI map component.
Definition: SCR_MapMarkersUI.c:6
SCR_MapMarkerEntityClass
Definition: SCR_MapMarkerEntity.c:3
Faction
Definition: Faction.c:12
m_eType
protected SCR_ECampaignBaseType m_eType
Definition: SCR_CampaignMilitaryBaseComponent.c:59
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
SCR_MapConstants
Definition: SCR_MapConstants.c:2
m_sText
class SCR_BaseEditorAttribute m_sText
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180