Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MapMarkerBase.c
Go to the documentation of this file.
4 {
5  protected const int SERIALIZED_BYTES = 34; // total amount of serialized bytes without custom string
6 
7  // synchronized
8  protected SCR_EMapMarkerType m_eType; // config type
9  protected int m_iMarkerID = -1; // network ID, -1 means the marker is not set as synchronized
10  protected int m_iConfigID = -1; // config id used when marker of a single type has bigger amount of configuration options
11  protected int m_iMarkerOwnerID = -1; // owner playerID, -1 is dedicated server
12  protected int m_iFlags;
13  protected int m_iPosWorldX;
14  protected int m_iPosWorldY;
15  protected int m_iFactionFlags; // flags determining which factions are able to see the marker, 0 means no restrictions
16  protected int m_iColorEntry; // placed marker color entry id
17  protected int m_iIconEntry; // placed marker icon entry id
18  protected int m_iRotation;
19  protected string m_sCustomText;
20 
21  // server only
22  protected bool m_bIsServerSideDisabled; // in hosted server scenario, opposing faction markers have to be properly managed but still disabled from showing up
23 
24  // rest
25  protected bool m_bTestVisibleFrame = true; // only run update based on presence in visible frame
26  protected bool m_bIsUpdateDisabled; // is update currently disbled
27  protected bool m_bIsDragged; // currently being dragged
28  protected int m_iScreenX; // cached screen position X
29  protected int m_iScreenY; // cached screen position Y
30  protected SCR_MapMarkerEntryConfig m_ConfigEntry; // marker entry associated with this marker type
31  protected SCR_MapEntity m_MapEntity;
32  protected Widget m_wRoot;
33  protected SCR_MapMarkerWidgetComponent m_MarkerWidgetComp;
34  protected ref Color m_Color;
35 
36  //------------------------------------------------------------------------------------------------
37  Widget GetRootWidget()
38  {
39  return m_wRoot;
40  }
41 
42  //------------------------------------------------------------------------------------------------
43  SCR_EMapMarkerType GetType()
44  {
45  return m_eType;
46  }
47 
48  //------------------------------------------------------------------------------------------------
49  void SetType(SCR_EMapMarkerType type)
50  {
51  m_eType = type;
52  }
53 
54  //------------------------------------------------------------------------------------------------
55  int GetMarkerID()
56  {
57  return m_iMarkerID;
58  }
59 
60  //------------------------------------------------------------------------------------------------
61  void SetMarkerID(int id)
62  {
63  m_iMarkerID = id;
64  }
65 
66  //------------------------------------------------------------------------------------------------
67  int GetMarkerConfigID()
68  {
69  return m_iConfigID;
70  }
71 
72  //------------------------------------------------------------------------------------------------
73  void SetMarkerConfigID(int id)
74  {
75  m_iConfigID = id;
76  }
77 
78  //------------------------------------------------------------------------------------------------
79  int GetMarkerOwnerID()
80  {
81  return m_iMarkerOwnerID;
82  }
83 
84  //------------------------------------------------------------------------------------------------
85  void SetMarkerOwnerID(int playerID)
86  {
87  m_iMarkerOwnerID = playerID;
88  }
89 
90  //------------------------------------------------------------------------------------------------
91  int GetFlags()
92  {
93  return m_iFlags;
94  }
95 
96  //------------------------------------------------------------------------------------------------
97  void SetFlags(int flags)
98  {
99  m_iFlags = flags;
100  }
101 
102  //------------------------------------------------------------------------------------------------
104  int GetMarkerFactionFlags()
105  {
106  return m_iFactionFlags;
107  }
108 
109  //------------------------------------------------------------------------------------------------
111  void AddMarkerFactionFlags(int flags)
112  {
113  if (flags < 0) // invalid id
114  return;
115 
116  int flag = Math.Pow(2, flags);
117 
118  m_iFactionFlags |= flag;
119  }
120 
121  //------------------------------------------------------------------------------------------------
123  void SetMarkerFactionFlags(int flags)
124  {
125  m_iFactionFlags = flags;
126  }
127 
128  //------------------------------------------------------------------------------------------------
130  bool IsFaction(int factionID)
131  {
132  int flag = Math.Pow(2, factionID);
133 
134  return (m_iFactionFlags & flag);
135  }
136 
137  //------------------------------------------------------------------------------------------------
138  void GetWorldPos(out int pos[2])
139  {
140  pos[0] = m_iPosWorldX;
141  pos[1] = m_iPosWorldY;
142  }
143 
144  //------------------------------------------------------------------------------------------------
145  void SetWorldPos(int posX, int posY)
146  {
147  m_iPosWorldX = posX;
148  m_iPosWorldY = posY;
149  }
150 
151  //------------------------------------------------------------------------------------------------
152  int GetRotation()
153  {
154  return m_iRotation;
155  }
156 
157  //------------------------------------------------------------------------------------------------
158  void SetRotation(int angle)
159  {
160  m_iRotation = angle;
161  }
162 
163  //------------------------------------------------------------------------------------------------
164  int GetColorEntry()
165  {
166  return m_iColorEntry;
167  }
168 
169  //------------------------------------------------------------------------------------------------
170  int GetIconEntry()
171  {
172  return m_iIconEntry;
173  }
174 
175  //------------------------------------------------------------------------------------------------
176  void SetColorEntry(int colorEntry)
177  {
178  m_iColorEntry = colorEntry;
179  }
180 
181  //------------------------------------------------------------------------------------------------
182  void SetIconEntry(int iconEntry)
183  {
184  m_iIconEntry = iconEntry;
185  }
186 
187  //------------------------------------------------------------------------------------------------
188  string GetCustomText()
189  {
190  return m_sCustomText;
191  }
192 
193  //------------------------------------------------------------------------------------------------
194  void SetCustomText(string text)
195  {
196  m_sCustomText = text;
197  }
198 
199  //------------------------------------------------------------------------------------------------
201  void SetServerDisabled(bool state)
202  {
203  m_bIsServerSideDisabled = state;
204  }
205 
206  //------------------------------------------------------------------------------------------------
208  void SetUpdateDisabled(bool state)
209  {
210  m_bIsUpdateDisabled = state;
211 
212  if (m_wRoot)
213  m_wRoot.SetVisible(!state);
214  }
215 
216  //------------------------------------------------------------------------------------------------
218  void SetVisible(bool state)
219  {
220  if (m_wRoot)
221  m_wRoot.SetVisible(state);
222  }
223 
224  //------------------------------------------------------------------------------------------------
226  void SetDragged(bool state)
227  {
228  m_bIsDragged = state;
229  }
230 
231  //------------------------------------------------------------------------------------------------
233  bool TestVisibleFrame(vector visibleMin, vector visibleMax)
234  {
235  if( m_iPosWorldX < visibleMin[0]
236  || m_iPosWorldX > visibleMax[0]
237  || m_iPosWorldY < visibleMin[2]
238  || m_iPosWorldY > visibleMax[2])
239  {
240  return false;
241  }
242  else
243  {
244  SetUpdateDisabled(false);
245  return true;
246  }
247  }
248 
249  //------------------------------------------------------------------------------------------------
251  void OnCreateMarker()
252  {
253  if (m_bIsServerSideDisabled)
254  return;
255 
256  m_MapEntity = SCR_MapEntity.GetMapInstance();
257  if (!m_MapEntity)
258  return;
259 
260  Widget mapRoot = m_MapEntity.GetMapMenuRoot();
261  if (!mapRoot)
262  return;
263 
264  Widget mapFrame = mapRoot.FindAnyWidget(SCR_MapConstants.MAP_FRAME_NAME);
265  if (!mapFrame)
266  return;
267 
268  m_ConfigEntry = SCR_MapMarkerManagerComponent.GetInstance().GetMarkerConfig().GetMarkerEntryConfigByType(m_eType);
269  if (!m_ConfigEntry)
270  return;
271 
272  m_wRoot = GetGame().GetWorkspace().CreateWidgets(m_ConfigEntry.GetMarkerLayout(), mapFrame);
273  if (!m_wRoot)
274  return;
275 
276  m_MarkerWidgetComp = SCR_MapMarkerWidgetComponent.Cast(m_wRoot.FindHandler(SCR_MapMarkerWidgetComponent));
277  m_MarkerWidgetComp.SetMarkerObject(this);
278  m_ConfigEntry.InitClientSettings(this, m_MarkerWidgetComp);
279  m_MarkerWidgetComp.SetRotation(m_iRotation);
280 
281  SCR_MapEntity.GetOnMapClose().Insert(OnMapClosed);
282  SCR_MapEntity.GetOnLayerChanged().Insert(OnMapLayerChanged);
283  OnMapLayerChanged(m_MapEntity.GetLayerIndex());
284  }
285 
286  //------------------------------------------------------------------------------------------------
287  void OnDelete()
288  {
289  if (m_wRoot)
290  m_wRoot.RemoveFromHierarchy();
291  }
292 
293  //------------------------------------------------------------------------------------------------
294  protected void OnMapClosed(MapConfiguration config)
295  {
296  SCR_MapEntity.GetOnMapClose().Remove(OnMapClosed);
297  SCR_MapEntity.GetOnLayerChanged().Remove(OnMapLayerChanged);
298  }
299 
300  //------------------------------------------------------------------------------------------------
301  protected void OnMapLayerChanged(int layerID)
302  {
303  if (m_MarkerWidgetComp)
304  m_MarkerWidgetComp.SetLayerID(layerID);
305 
306  LayerChangeLogic(layerID);
307  }
308 
309  //------------------------------------------------------------------------------------------------
310  void LayerChangeLogic(int layerID)
311  {
312  if (m_ConfigEntry && m_MarkerWidgetComp)
313  m_ConfigEntry.OnMapLayerChanged(m_MarkerWidgetComp, layerID);
314  }
315 
316  //------------------------------------------------------------------------------------------------
318  bool OnUpdate(vector visibleMin = vector.Zero, vector visibleMax = vector.Zero)
319  {
320  if (m_bIsServerSideDisabled || m_bIsDragged)
321  return true;
322 
323  if (m_bTestVisibleFrame)
324  {
325  if ((m_iPosWorldX < visibleMin[0]) || (m_iPosWorldX > visibleMax[0]) || (m_iPosWorldY < visibleMin[2]) || (m_iPosWorldY > visibleMax[2]))
326  {
327  SetUpdateDisabled(true);
328  return false;
329  }
330  }
331 
332  m_MapEntity.WorldToScreen(m_iPosWorldX, m_iPosWorldY, m_iScreenX, m_iScreenY, true);
333  FrameSlot.SetPos(m_wRoot, GetGame().GetWorkspace().DPIUnscale(m_iScreenX), GetGame().GetWorkspace().DPIUnscale(m_iScreenY)); // needs unscaled coords
334 
335  return true;
336  }
337 
338  //------------------------------------------------------------------------------------------------
339  static bool Extract(SCR_MapMarkerBase instance, ScriptCtx ctx, SSnapSerializerBase snapshot)
340  {
341  snapshot.SerializeInt(instance.m_iPosWorldX);
342  snapshot.SerializeInt(instance.m_iPosWorldY);
343  snapshot.SerializeInt(instance.m_iMarkerID);
344  snapshot.SerializeInt(instance.m_iMarkerOwnerID);
345  snapshot.SerializeInt(instance.m_iFlags);
346  snapshot.SerializeInt(instance.m_iConfigID);
347  snapshot.SerializeInt(instance.m_iFactionFlags);
348  snapshot.SerializeBytes(instance.m_iRotation, 2);
349  snapshot.SerializeBytes(instance.m_eType, 1);
350  snapshot.SerializeBytes(instance.m_iColorEntry, 1);
351  snapshot.SerializeBytes(instance.m_iIconEntry, 2);
352  snapshot.SerializeString(instance.m_sCustomText);
353  return true;
354  }
355 
356  //------------------------------------------------------------------------------------------------
357  static bool Inject(SSnapSerializerBase snapshot, ScriptCtx ctx, SCR_MapMarkerBase instance)
358  {
359  snapshot.SerializeInt(instance.m_iPosWorldX);
360  snapshot.SerializeInt(instance.m_iPosWorldY);
361  snapshot.SerializeInt(instance.m_iMarkerID);
362  snapshot.SerializeInt(instance.m_iMarkerOwnerID);
363  snapshot.SerializeInt(instance.m_iFlags);
364  snapshot.SerializeInt(instance.m_iConfigID);
365  snapshot.SerializeInt(instance.m_iFactionFlags);
366  snapshot.SerializeBytes(instance.m_iRotation, 2);
367  snapshot.SerializeBytes(instance.m_eType, 1);
368  snapshot.SerializeBytes(instance.m_iColorEntry, 1);
369  snapshot.SerializeBytes(instance.m_iIconEntry, 2);
370  snapshot.SerializeString(instance.m_sCustomText);
371  return true;
372  }
373 
374  //------------------------------------------------------------------------------------------------
375  static void Encode(SSnapSerializerBase snapshot, ScriptCtx ctx, ScriptBitSerializer packet)
376  {
377  snapshot.Serialize(packet, SERIALIZED_BYTES);
378  snapshot.EncodeString(packet);
379  }
380 
381  //------------------------------------------------------------------------------------------------
382  static bool Decode(ScriptBitSerializer packet, ScriptCtx ctx, SSnapSerializerBase snapshot)
383  {
384  snapshot.Serialize(packet, SERIALIZED_BYTES);
385  snapshot.DecodeString(packet);
386  return true;
387  }
388 
389  //------------------------------------------------------------------------------------------------
390  static bool SnapCompare(SSnapSerializerBase lhs, SSnapSerializerBase rhs , ScriptCtx ctx)
391  {
392  return lhs.CompareSnapshots(rhs, SERIALIZED_BYTES) // m_iPosWorldX(4) + m_iPosWorldY(4) + m_iMarkerID(4) + m_iMarkerOwnerID(4) + m_iFlags(4) + m_iConfigID(4) + m_iFactionFlags(4) + m_iRotation(2) + m_eType(1) + m_iColorEntry(1) + m_iIconEntry(2)
393  && lhs.CompareStringSnapshots(rhs); // m_sCustomText
394  }
395 
396  //------------------------------------------------------------------------------------------------
397  static bool PropCompare(SCR_MapMarkerBase instance, SSnapSerializerBase snapshot, ScriptCtx ctx)
398  {
399  return snapshot.CompareInt(instance.m_iPosWorldX)
400  && snapshot.CompareInt(instance.m_iPosWorldY)
401  && snapshot.CompareInt(instance.m_iMarkerID)
402  && snapshot.CompareInt(instance.m_iMarkerOwnerID)
403  && snapshot.CompareInt(instance.m_iFlags)
404  && snapshot.CompareInt(instance.m_iConfigID)
405  && snapshot.CompareInt(instance.m_iFactionFlags)
406  && snapshot.Compare(instance.m_iRotation, 2)
407  && snapshot.Compare(instance.m_eType, 1)
408  && snapshot.Compare(instance.m_iColorEntry, 1)
409  && snapshot.Compare(instance.m_iIconEntry, 2)
410  && snapshot.CompareString(instance.m_sCustomText);
411  }
412 };
m_MapEntity
protected SCR_MapEntity m_MapEntity
Definition: SCR_MapGadgetComponent.c:14
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_MapMarkerBase
Definition: SCR_MapMarkerBase.c:3
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_MapMarkerEntryConfig
Base entry config.
Definition: SCR_MapMarkerConfig.c:50
m_bIsDragged
protected bool m_bIsDragged
Definition: SCR_MapRTWBaseUI.c:31
SCR_EMapMarkerType
SCR_EMapMarkerType
Definition: SCR_MapMarkerConfig.c:5
SCR_MapEntity
Map entity.
Definition: SCR_MapEntity.c:20
m_eType
protected SCR_ECampaignBaseType m_eType
Definition: SCR_CampaignMilitaryBaseComponent.c:59
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
SCR_MapMarkerWidgetComponent
Definition: SCR_MapMarkerWidgetComponent.c:3
SCR_MapConstants
Definition: SCR_MapConstants.c:2