Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MapDrawingUI.c
Go to the documentation of this file.
1 class MapLine
3 {
4  protected static const ref Color BUTTON_RED = Color.FromSRGBA(197, 75, 75, 255);
5 
6  bool m_bIsLineDrawn; // if line is drawn when closing the map, redraw it on reopen
7  bool m_bIsDrawMode;
8  float m_fStartPointX, m_fStartPointY;
9  float m_fEndPointX, m_fEndPointY;
10  Widget m_wRootW;
11  Widget m_wLine;
12  ImageWidget m_wLineImage;
13  Widget m_wDeleteButton;
14  SCR_ButtonImageComponent m_DeleteButtonComp;
15  SCR_MapEntity m_MapEntity;
16  SCR_MapDrawingUI m_OwnerComponent;
17 
18  //------------------------------------------------------------------------------------------------
22  void CreateLine(notnull Widget rootW, bool drawStart = false)
23  {
24  m_wRootW = rootW;
25 
26  Widget mapFrame = m_MapEntity.GetMapMenuRoot().FindAnyWidget(SCR_MapConstants.MAP_FRAME_NAME);
27  if (!mapFrame)
28  return;
29 
30  if (drawStart)
31  m_MapEntity.GetMapCursorWorldPosition(m_fStartPointX, m_fStartPointY);
32  else
33  m_bIsLineDrawn = true;
34 
35  m_wLine = GetGame().GetWorkspace().CreateWidgets("{E8850FCD9219C411}UI/layouts/Map/MapDrawLine.layout", mapFrame);
36  m_wLineImage = ImageWidget.Cast(m_wLine.FindAnyWidget("DrawLineImage"));
37 
38  m_wDeleteButton = GetGame().GetWorkspace().CreateWidgets("{F486FAEEA00A5218}UI/layouts/Map/MapLineDeleteButton.layout", mapFrame);
39  m_DeleteButtonComp = SCR_ButtonImageComponent.Cast(m_wDeleteButton.FindAnyWidget("DelButton").FindHandler(SCR_ButtonImageComponent));
40  m_DeleteButtonComp.m_OnClicked.Insert(OnButtonClick);
41  m_DeleteButtonComp.m_OnFocus.Insert(OnButtonFocus);
42  m_DeleteButtonComp.m_OnFocusLost.Insert(OnButtonFocusLost);
43  m_DeleteButtonComp.m_OnMouseEnter.Insert(OnMouseEnter);
44  m_DeleteButtonComp.m_OnMouseLeave.Insert(OnMouseLeave);
45  m_DeleteButtonComp.GetImageWidget().SetColor(BUTTON_RED);
46 
47  m_OwnerComponent.m_iLinesDrawn++;
48  m_OwnerComponent.UpdateLineCount();
49  }
50 
51  //------------------------------------------------------------------------------------------------
52  protected void OnButtonClick()
53  {
54  if (m_OwnerComponent.m_bIsLineBeingDrawn)
55  return;
56 
57  DestroyLine(false);
58  m_OwnerComponent.m_bActivationThrottle = true;
59  }
60 
61  //------------------------------------------------------------------------------------------------
62  protected void OnButtonFocus()
63  {
64  m_DeleteButtonComp.GetImageWidget().SetColor(Color.FromInt(UIColors.CONTRAST_COLOR.PackToInt()));
65  }
66 
67  //------------------------------------------------------------------------------------------------
68  protected void OnButtonFocusLost(Widget w)
69  {
70  m_DeleteButtonComp.GetImageWidget().SetColor(BUTTON_RED);
71  }
72 
73  //------------------------------------------------------------------------------------------------
74  protected void OnMouseEnter(Widget w)
75  {
76  GetGame().GetWorkspace().SetFocusedWidget(w);
77  }
78 
79  //------------------------------------------------------------------------------------------------
80  protected void OnMouseLeave(Widget w)
81  {
82  GetGame().GetWorkspace().SetFocusedWidget(null);
83  }
84 
85  //------------------------------------------------------------------------------------------------
87  void SetButtonVisible(bool target)
88  {
89  m_wDeleteButton.SetEnabled(target);
90  m_wDeleteButton.SetVisible(target);
91  }
92 
93  //------------------------------------------------------------------------------------------------
96  void DestroyLine(bool cacheDrawn = false)
97  {
98  if (m_wLine)
99  m_wLine.RemoveFromHierarchy();
100 
101  if (m_wDeleteButton)
102  m_wDeleteButton.RemoveFromHierarchy();
103 
104  if (!cacheDrawn)
105  m_bIsLineDrawn = false;
106 
107  m_OwnerComponent.m_iLinesDrawn--;
108  m_OwnerComponent.UpdateLineCount();
109  }
110 
111  //------------------------------------------------------------------------------------------------
114  void UpdateLine(bool updateEndPos)
115  {
116  if (!m_wLine) // can happen due to callater used for update
117  return;
118 
119  if (updateEndPos)
120  m_MapEntity.GetMapCursorWorldPosition(m_fEndPointX, m_fEndPointY);
121 
122  int screenX, screenY, endX, endY;
123 
124  m_MapEntity.WorldToScreen(m_fStartPointX, m_fStartPointY, screenX, screenY, true);
125  m_MapEntity.WorldToScreen(m_fEndPointX, m_fEndPointY, endX, endY, true);
126 
127  vector lineVector = vector.Zero;
128  lineVector[0] = m_fStartPointX - m_fEndPointX;
129  lineVector[1] = m_fStartPointY - m_fEndPointY;
130 
131  vector angles = lineVector.VectorToAngles();
132  if (angles[0] == 90)
133  angles[1] = 180 - angles[1]; // reverse angles when passing vertical axis
134  else if (angles[0] == 0)
135  angles[1] = 180 + angles[1]; // fix for case for when line is vertically straight
136 
137  m_wLineImage.SetRotation(angles[1]);
138 
139  lineVector = m_MapEntity.GetMapWidget().SizeToPixels(lineVector);
140  m_wLineImage.SetSize( GetGame().GetWorkspace().DPIUnscale(lineVector.Length()), 50);
141 
142  FrameSlot.SetPos(m_wLine, GetGame().GetWorkspace().DPIUnscale(screenX), GetGame().GetWorkspace().DPIUnscale(screenY)); // needs unscaled coords
143 
144  lineVector = {
145  GetGame().GetWorkspace().DPIUnscale((screenX + endX) * 0.5),
146  GetGame().GetWorkspace().DPIUnscale((screenY + endY) * 0.5),
147  0
148  };
149  FrameSlot.SetPos(m_wDeleteButton, lineVector[0], lineVector[1]); //del button
150 
151  }
152 
153  //------------------------------------------------------------------------------------------------
154  // constructor
157  void MapLine(SCR_MapEntity mapEnt, SCR_MapDrawingUI ownerComp)
158  {
159  m_MapEntity = mapEnt;
160  m_OwnerComponent = ownerComp;
161  }
162 }
163 
165 class SCR_MapDrawingUI : SCR_MapUIBaseComponent
166 {
167  [Attribute("editor", UIWidgets.EditBox, desc: "Toolmenu imageset quad name")]
168  string m_sToolMenuIconName;
169 
170  [Attribute("9", UIWidgets.EditBox, desc: "Max line count")]
172 
173  bool m_bActivationThrottle; // onclick will be called same frame draw mode activates/ delete button is clicked, this bool is used to ignore it
176  int m_iLinesDrawn; // count of currently drawn lines
177  protected int m_iLineID; // active line id
178 
179  protected Widget m_wDrawingContainer;
180 
183  protected ref array<ref MapLine> m_aLines = new array <ref MapLine>();
184 
185  protected const string m_aDrawableElements[1] = {"RulerFrame"}; // widgets we are allow to draw over
186 
187  //------------------------------------------------------------------------------------------------
189  protected void ToggleDrawMode()
190  {
191  if (!m_bIsDrawModeActive)
192  SetDrawMode(true);
193  else
194  SetDrawMode(false);
195  }
196 
197  //------------------------------------------------------------------------------------------------
201  protected void SetDrawMode(bool state, bool cacheDrawn = false)
202  {
203  m_bIsDrawModeActive = state;
204 
205  if (state)
206  {
207  GetGame().GetInputManager().AddActionListener("MapSelect", EActionTrigger.UP, OnMapClick);
208  m_bActivationThrottle = true;
209 
210  for (int i; i < m_iLineCount; i++)
211  {
212  if (m_aLines[i].m_bIsLineDrawn)
213  m_aLines[i].SetButtonVisible(true);
214  }
215  }
216  else
217  {
218  GetGame().GetInputManager().RemoveActionListener("MapSelect", EActionTrigger.UP, OnMapClick);
219 
220  m_CursorModule.HandleDraw(false); // in case drawing was in progress
221 
222  for (int i; i < m_iLineCount; i++)
223  {
224  if (m_bIsLineBeingDrawn && i == m_iLineID) // if drawing in progress, dont cache
225  {
226  m_aLines[i].DestroyLine(false);
227  m_bIsLineBeingDrawn = false;
228  m_iLineID = -1;
229  }
230  else if (cacheDrawn) // map is closing, cache drawn lines and destroy
231  {
232  m_aLines[i].DestroyLine(true);
233  }
234  else if (m_aLines[i].m_bIsLineDrawn)
235  {
236  m_aLines[i].SetButtonVisible(false); // only draw mode disabled
237  }
238  }
239  }
240 
241  m_ToolMenuEntry.SetActive(state);
242  m_ToolMenuEntry.m_ButtonComp.SetTextVisible(state);
243  UpdateLineCount();
244  }
245 
246  //------------------------------------------------------------------------------------------------
249  {
250  m_ToolMenuEntry.m_ButtonComp.SetText(m_iLinesDrawn.ToString() + "/" + m_iLineCount.ToString());
251  }
252 
253  //------------------------------------------------------------------------------------------------
254  protected void OnMapClick(float value, EActionTrigger reason)
255  {
257  {
258  m_bActivationThrottle = false;
259  return;
260  }
261 
262  array<Widget> tracedW = SCR_MapCursorModule.GetMapWidgetsUnderCursor(); // check if the line isnt being drawn over buttons or other elements
263  EMapEntityMode mode = m_MapEntity.GetMapConfig().MapEntityMode;
264 
265  bool allowed = true;
266  int expectedCount;
267 
268  if (mode == EMapEntityMode.SPAWNSCREEN)
269  expectedCount = 1;
270  else
271  expectedCount = 0;
272 
273  if (tracedW.Count() != expectedCount)
274  {
275  allowed = false;
276  foreach(string widgetName : m_aDrawableElements)
277  {
278  if (tracedW.IsIndexValid(0) && tracedW[0].GetName() == widgetName)
279  {
280  allowed = true;
281  break;
282  }
283  }
284  }
285 
286  if (!allowed)
287  {
288  SetDrawMode(false);
289  return;
290  }
291 
292  if (m_bIsLineBeingDrawn) // state 2, line drawing in progress
293  {
294  m_bIsLineBeingDrawn = false;
295  m_aLines[m_iLineID].m_bIsLineDrawn = true;
296  m_iLineID = -1;
297 
298  m_CursorModule.HandleDraw(false);
299  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_MAP_GADGET_MARKER_DRAW_STOP);
300 
301  return;
302  }
303 
305  return;
306 
307  if (!m_CursorModule.HandleDraw(true)) // draw restricted, return here
308  return;
309 
310  for (int i; i < m_iLineCount; i++) // state 1, start drawing line
311  {
312  if (!m_aLines[i].m_bIsLineDrawn)
313  {
314  m_aLines[i].CreateLine(m_wDrawingContainer, true);
315  m_bIsLineBeingDrawn = true;
316  m_iLineID = i;
317  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_MAP_GADGET_MARKER_DRAW_START);
318 
319  return;
320  }
321 
322  }
323  }
324 
325  //------------------------------------------------------------------------------------------------
330  protected void OnMapPan(float x, float y, bool adjustedPan)
331  {
332  for (int i; i < m_iLineCount; i++)
333  {
334  if (m_aLines[i].m_bIsLineDrawn)
335  m_aLines[i].UpdateLine(false);
336  }
337  }
338 
339  //------------------------------------------------------------------------------------------------
343  protected void OnMapPanEnd(float x, float y)
344  {
345  for (int i; i < m_iLineCount; i++)
346  {
347  if (m_aLines[i].m_bIsLineDrawn)
348  GetGame().GetCallqueue().CallLater(m_aLines[i].UpdateLine, 0, false, false); // needs to be delayed by a frame as it cant always update the size after zoom correctly within the same frame
349  }
350  }
351 
352  //------------------------------------------------------------------------------------------------
355  protected void OnEntryToggled(SCR_MapToolEntry entry)
356  {
357  if (m_bIsDrawModeActive && entry != m_ToolMenuEntry)
358  SetDrawMode(false);
359  }
360 
361  //------------------------------------------------------------------------------------------------
362  protected void OnInputQuickBind(float value, EActionTrigger reason)
363  {
364  ToggleDrawMode();
365  }
366 
367  //------------------------------------------------------------------------------------------------
368  override void OnMapOpen(MapConfiguration config)
369  {
370  super.OnMapOpen(config);
371 
372  m_wDrawingContainer = FrameWidget.Cast(config.RootWidgetRef.FindAnyWidget(SCR_MapConstants.DRAWING_CONTAINER_WIDGET_NAME));
373 
374  m_iLinesDrawn = 0;
375 
376  ScriptCallQueue callQueue = GetGame().GetCallqueue();
377  for (int i; i < m_iLineCount; i++)
378  {
379  if (m_aLines[i].m_bIsLineDrawn)
380  {
381  m_aLines[i].CreateLine(m_wDrawingContainer);
382  callQueue.CallLater(m_aLines[i].UpdateLine, 0, false, false);
383  m_aLines[i].SetButtonVisible(false);
384  }
385  }
386 
387  m_MapEntity.GetOnMapPan().Insert(OnMapPan); // pan for scaling
388  m_MapEntity.GetOnMapPanEnd().Insert(OnMapPanEnd);
389  SCR_MapToolEntry.GetOnEntryToggledInvoker().Insert(OnEntryToggled);
390 
392  }
393 
394  //------------------------------------------------------------------------------------------------
395  override void OnMapClose(MapConfiguration config)
396  {
397  m_MapEntity.GetOnMapPan().Remove(OnMapPan);
398  m_MapEntity.GetOnMapPanEnd().Remove(OnMapPanEnd);
399  SCR_MapToolEntry.GetOnEntryToggledInvoker().Remove(OnEntryToggled);
400 
401  SetDrawMode(false, true);
402  m_bIsLineBeingDrawn = false;
403 
404  super.OnMapClose(config);
405  }
406 
407  //------------------------------------------------------------------------------------------------
408  override void Update(float timeSlice)
409  {
411  m_aLines[m_iLineID].UpdateLine(true);
412  }
413 
414  //------------------------------------------------------------------------------------------------
415  override void Init()
416  {
417  SCR_MapToolMenuUI toolMenu = SCR_MapToolMenuUI.Cast(m_MapEntity.GetMapUIComponent(SCR_MapToolMenuUI));
418  if (toolMenu)
419  {
420  m_ToolMenuEntry = toolMenu.RegisterToolMenuEntry(SCR_MapToolMenuUI.s_sToolMenuIcons, m_sToolMenuIconName, 13); // add to menu
421  m_ToolMenuEntry.m_OnClick.Insert(ToggleDrawMode);
422  m_ToolMenuEntry.SetEnabled(true);
423 
424  GetGame().GetInputManager().AddActionListener("MapToolPencil", EActionTrigger.DOWN, OnInputQuickBind);
425  }
426 
427  for (int i; i < m_iLineCount; i++)
428  {
429  MapLine line = new MapLine(m_MapEntity, this);
430  m_aLines.Insert(line);
431  }
432  }
433 }
OnMapClick
protected void OnMapClick(float value, EActionTrigger reason)
Definition: SCR_MapDrawingUI.c:254
m_MapEntity
protected SCR_MapEntity m_MapEntity
Definition: SCR_MapGadgetComponent.c:14
m_aDrawableElements
const protected string m_aDrawableElements[1]
Definition: SCR_MapDrawingUI.c:185
OnMapOpen
override void OnMapOpen(MapConfiguration config)
Definition: SCR_MapDrawingUI.c:368
OnMapPan
protected void OnMapPan(float x, float y, bool adjustedPan)
Definition: SCR_MapDrawingUI.c:330
SCR_UISoundEntity
Definition: SCR_UISoundEntity.c:7
m_wLineImage
ImageWidget m_wLineImage
Definition: SCR_MapDrawingUI.c:10
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
ToggleDrawMode
protected void ToggleDrawMode()
Toggle draw mode.
Definition: SCR_MapDrawingUI.c:189
OnMapPanEnd
protected void OnMapPanEnd(float x, float y)
Definition: SCR_MapDrawingUI.c:343
m_ToolMenuEntry
protected SCR_MapToolEntry m_ToolMenuEntry
Definition: SCR_MapDrawingUI.c:182
Update
override void Update(float timeSlice)
Definition: SCR_MapDrawingUI.c:408
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
m_fStartPointX
float m_fStartPointX
Definition: SCR_MapDrawingUI.c:6
m_fEndPointX
float m_fEndPointX
Definition: SCR_MapDrawingUI.c:7
m_fEndPointY
float m_fEndPointY
Definition: SCR_MapDrawingUI.c:7
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SetDrawMode
protected void SetDrawMode(bool state, bool cacheDrawn=false)
Definition: SCR_MapDrawingUI.c:201
SCR_MapToolEntry
Map tool menu entry data class.
Definition: SCR_MapToolMenuUI.c:2
m_DeleteButtonComp
SCR_ButtonImageComponent m_DeleteButtonComp
Definition: SCR_MapDrawingUI.c:12
m_CursorModule
protected SCR_MapCursorModule m_CursorModule
Definition: SCR_MapDrawingUI.c:181
m_bIsLineDrawn
bool m_bIsLineDrawn
Definition: SCR_MapDrawingUI.c:4
m_wRootW
Widget m_wRootW
Definition: SCR_MapDrawingUI.c:8
SCR_MapCursorModule
Map cursor behavior and mode setup.
Definition: SCR_MapCursorModule.c:39
m_OwnerComponent
SCR_MapDrawingUI m_OwnerComponent
Definition: SCR_MapDrawingUI.c:14
UpdateLineCount
void UpdateLineCount()
Definition: SCR_MapDrawingUI.c:248
m_fStartPointY
float m_fStartPointY
Definition: SCR_MapDrawingUI.c:6
m_bActivationThrottle
bool m_bActivationThrottle
Definition: SCR_MapDrawingUI.c:173
m_wDrawingContainer
protected Widget m_wDrawingContainer
Definition: SCR_MapDrawingUI.c:179
UIColors
Definition: Constants.c:16
m_aLines
protected ref array< ref MapLine > m_aLines
Definition: SCR_MapDrawingUI.c:183
m_iLineID
protected int m_iLineID
Definition: SCR_MapDrawingUI.c:177
Attribute
class MapLine Attribute("editor", UIWidgets.EditBox, desc:"Toolmenu imageset quad name")] string m_sToolMenuIconName
Temporary drawing substitute so the protractor can be utilized properly.
m_iLinesDrawn
int m_iLinesDrawn
Definition: SCR_MapDrawingUI.c:176
SCR_MapEntity
Map entity.
Definition: SCR_MapEntity.c:20
Init
override void Init()
initialization
Definition: SCR_MapDrawingUI.c:415
m_wLine
Widget m_wLine
Definition: SCR_MapDrawingUI.c:9
OnInputQuickBind
protected void OnInputQuickBind(float value, EActionTrigger reason)
Definition: SCR_MapDrawingUI.c:362
OnMapClose
override void OnMapClose(MapConfiguration config)
Definition: SCR_MapDrawingUI.c:395
m_bIsLineBeingDrawn
bool m_bIsLineBeingDrawn
Definition: SCR_MapDrawingUI.c:175
m_wDeleteButton
Widget m_wDeleteButton
Definition: SCR_MapDrawingUI.c:11
MapLine
Map line.
Definition: SCR_MapDrawingUI.c:2
m_MapEntity
SCR_MapEntity m_MapEntity
Definition: SCR_MapDrawingUI.c:13
SCR_MapConstants
Definition: SCR_MapConstants.c:2
EMapEntityMode
EMapEntityMode
Mode of the map.
Definition: SCR_MapConstants.c:28
MapLine
void MapLine(SCR_MapEntity mapEnt, SCR_MapDrawingUI ownerComp)
Definition: SCR_MapDrawingUI.c:155
SCR_ButtonImageComponent
Definition: SCR_ButtonImageComponent.c:2
SCR_MapUIBaseComponent
Definition: SCR_MapUIBaseComponent.c:3
OnEntryToggled
protected void OnEntryToggled(SCR_MapToolEntry entry)
Definition: SCR_MapDrawingUI.c:355
UpdateLine
void UpdateLine(bool updateEndPos)
Definition: SCR_MapDrawingUI.c:112
SCR_MapToolMenuUI
void SCR_MapToolMenuUI()
Definition: SCR_MapToolMenuUI.c:389
m_bIsDrawModeActive
bool m_bIsDrawModeActive
Definition: SCR_MapDrawingUI.c:174
m_iLineCount
int m_iLineCount
Definition: SCR_MapDrawingUI.c:171