Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_MapDrawingUI.c
Go to the documentation of this file.
2class MapLine
4 protected static const ref Color BUTTON_RED = Color.FromSRGBA(197, 75, 75, 255);
6 bool m_bIsLineDrawn; // if line is drawn when closing the map, redraw it on reopen
7 protected bool m_bIsInFocus;
8 protected float m_fStartPointX, m_fStartPointY;
9 protected float m_fEndPointX, m_fEndPointY;
10 protected Widget m_wLine;
15 protected SCR_MapDrawingUI m_OwnerComponent;
16
17 //------------------------------------------------------------------------------------------------
21 void CreateLine(notnull Widget rootW, bool drawStart = false)
22 {
23 Widget mapFrame = m_MapEntity.GetMapMenuRoot().FindAnyWidget(SCR_MapConstants.MAP_FRAME_NAME);
24 if (!mapFrame)
25 return;
26
27 if (drawStart)
28 m_MapEntity.GetMapCursorWorldPosition(m_fStartPointX, m_fStartPointY);
29 else
30 m_bIsLineDrawn = true;
31
32 m_wLine = GetGame().GetWorkspace().CreateWidgets("{E8850FCD9219C411}UI/layouts/Map/MapDrawLine.layout", mapFrame);
33 m_wLineImage = ImageWidget.Cast(m_wLine.FindAnyWidget("DrawLineImage"));
34
35 Widget deleteButtonFrame = GetGame().GetWorkspace().CreateWidgets("{F486FAEEA00A5218}UI/layouts/Map/MapLineDeleteButton.layout", mapFrame);
36 if (!deleteButtonFrame)
37 return;
38
39 m_wDeleteButton = ButtonWidget.Cast(deleteButtonFrame.FindAnyWidget("DelButton"));
40 if (!m_wDeleteButton)
41 return;
42
44 m_DeleteButtonComp.m_OnClicked.Insert(OnButtonClick);
45 m_DeleteButtonComp.m_OnFocus.Insert(OnButtonFocus);
46 m_DeleteButtonComp.m_OnFocusLost.Insert(OnButtonFocusLost);
47 m_DeleteButtonComp.m_OnMouseEnter.Insert(OnMouseEnter);
48 m_DeleteButtonComp.m_OnMouseLeave.Insert(OnMouseLeave);
49 m_DeleteButtonComp.GetImageWidget().SetColor(BUTTON_RED);
50
51 m_OwnerComponent.m_iLinesDrawn++;
52 m_OwnerComponent.UpdateLineCount();
53 }
54
55 //------------------------------------------------------------------------------------------------
56 protected void OnButtonClick()
57 {
58 if (m_OwnerComponent.m_bIsLineBeingDrawn)
59 return;
60
61 if (m_OwnerComponent.IsUsingGamepad() && !m_bIsInFocus)
62 return;
63
64 DestroyLine(false);
65 m_OwnerComponent.m_bActivationThrottle = true;
66 }
67
68 //------------------------------------------------------------------------------------------------
69 protected void OnButtonFocus()
70 {
71 if (m_OwnerComponent.m_bIsLineBeingDrawn)
72 return;
73
74 if (m_OwnerComponent.IsUsingGamepad())
75 {
76 m_bIsInFocus = false;
77 array<Widget> tracedW = SCR_MapCursorModule.GetMapWidgetsUnderCursor();
78 foreach (Widget w : tracedW)
79 {
80 if (w == m_wDeleteButton)
81 {
82 m_bIsInFocus = true;
83 break;
84 }
85 }
86
87 if (!m_bIsInFocus)
88 return;
89 }
90
91 m_DeleteButtonComp.GetImageWidget().SetColor(Color.FromInt(UIColors.CONTRAST_COLOR.PackToInt()));
92 }
93
94 //------------------------------------------------------------------------------------------------
95 protected void OnButtonFocusLost(Widget w)
96 {
97 m_bIsInFocus = false;
98 m_DeleteButtonComp.GetImageWidget().SetColor(BUTTON_RED);
99 }
100
101 //------------------------------------------------------------------------------------------------
102 protected void OnMouseEnter(Widget w)
103 {
104 GetGame().GetWorkspace().SetFocusedWidget(w);
106 }
107
108 //------------------------------------------------------------------------------------------------
109 protected void OnMouseLeave(Widget w)
110 {
111 GetGame().GetWorkspace().SetFocusedWidget(null);
114
115 //------------------------------------------------------------------------------------------------
117 void SetButtonVisible(bool target)
118 {
119 m_wDeleteButton.SetEnabled(target);
120 m_wDeleteButton.SetVisible(target);
121 }
123 //------------------------------------------------------------------------------------------------
126 void DestroyLine(bool cacheDrawn = false)
127 {
128 if (m_wLine)
129 m_wLine.RemoveFromHierarchy();
130
131 if (m_wDeleteButton)
132 m_wDeleteButton.RemoveFromHierarchy();
133
134 if (!cacheDrawn)
135 m_bIsLineDrawn = false;
136
137 m_OwnerComponent.m_iLinesDrawn--;
138 m_OwnerComponent.UpdateLineCount();
139 }
141 //------------------------------------------------------------------------------------------------
144 void UpdateLine(bool updateEndPos)
145 {
146 if (!m_wLine) // can happen due to callater used for update
147 return;
148
149 WorkspaceWidget workspace = GetGame().GetWorkspace();
150 if (!workspace)
151 return;
152
153 if (updateEndPos)
154 m_MapEntity.GetMapCursorWorldPosition(m_fEndPointX, m_fEndPointY);
155
156 int screenX, screenY, endX, endY;
157
158 m_MapEntity.WorldToScreen(m_fStartPointX, m_fStartPointY, screenX, screenY, true);
159 m_MapEntity.WorldToScreen(m_fEndPointX, m_fEndPointY, endX, endY, true);
160
161 vector lineVector = vector.Zero;
162 lineVector[0] = m_fStartPointX - m_fEndPointX;
163 lineVector[1] = m_fStartPointY - m_fEndPointY;
164
165 vector angles = lineVector.VectorToAngles();
166 if (angles[0] == 90)
167 angles[1] = 180 - angles[1]; // reverse angles when passing vertical axis
168 else if (angles[0] == 0)
169 angles[1] = 180 + angles[1]; // fix for case for when line is vertically straight
170
171 m_wLineImage.SetRotation(angles[1]);
172
173 lineVector = lineVector * m_MapEntity.GetCurrentZoom();
174
175 float length = workspace.DPIUnscale(lineVector.Length());
176
177 m_wLineImage.SetSize(length, 50);
178
179 FrameSlot.SetPos(m_wLine, workspace.DPIUnscale(screenX), workspace.DPIUnscale(screenY)); // needs unscaled coords
180
181 lineVector[0] = workspace.DPIUnscale((screenX + endX) * 0.5);
182 lineVector[1] = workspace.DPIUnscale((screenY + endY) * 0.5);
183 FrameSlot.SetPos(m_wDeleteButton, lineVector[0], lineVector[1]); //del button
184
185 }
186
187 //------------------------------------------------------------------------------------------------
188 // constructor
191 void MapLine(SCR_MapEntity mapEnt, SCR_MapDrawingUI ownerComp)
192 {
193 m_MapEntity = mapEnt;
194 m_OwnerComponent = ownerComp;
195 }
196}
197
199class SCR_MapDrawingUI : SCR_MapUIBaseComponent
200{
201 [Attribute("editor", UIWidgets.EditBox, desc: "Toolmenu imageset quad name")]
202 protected string m_sToolMenuIconName;
203
204 [Attribute("9", UIWidgets.EditBox, desc: "Max line count")]
205 protected int m_iLineCount;
206
207 bool m_bActivationThrottle; // onclick will be called same frame draw mode activates/ delete button is clicked, this bool is used to ignore it
208 protected bool m_bIsDrawModeActive;
210 int m_iLinesDrawn; // count of currently drawn lines
211 protected int m_iLineID; // active line id
212
214
215 protected SCR_MapCursorModule m_CursorModule;
217 protected ref array<ref MapLine> m_aLines = new array <ref MapLine>();
218
219 //------------------------------------------------------------------------------------------------
221 {
222 if (!m_CursorModule)
223 return false;
224
225 SCR_MapCursorInfo cursorInfo = m_CursorModule.GetCursorInfo();
226 if (!cursorInfo)
227 return false;
228
229 return cursorInfo && cursorInfo.isGamepad;
230 }
231
232 //------------------------------------------------------------------------------------------------
234 protected void ToggleDrawMode()
235 {
237 SetDrawMode(true);
238 else
239 SetDrawMode(false);
240 }
241
242 //------------------------------------------------------------------------------------------------
246 protected void SetDrawMode(bool state, bool cacheDrawn = false)
247 {
248 if (state)
249 {
250 if (!m_CursorModule.HandleDraw(true)) // draw restricted, return here
251 return;
252
253 GetGame().GetInputManager().AddActionListener("MapSelect", EActionTrigger.UP, OnMapClick);
255
256 for (int i; i < m_iLineCount; i++)
257 {
259 m_aLines[i].SetButtonVisible(true);
260 }
261 }
262 else
263 {
264 GetGame().GetInputManager().RemoveActionListener("MapSelect", EActionTrigger.UP, OnMapClick);
265 GetGame().GetInputManager().RemoveActionListener("MapContextualMenu", EActionTrigger.UP, OnMapModifierClick);
266
267 m_CursorModule.HandleDraw(false); // in case drawing was in progress
268
269 for (int i; i < m_iLineCount; i++)
270 {
271 if (m_bIsLineBeingDrawn && i == m_iLineID) // if drawing in progress, dont cache
272 {
273 m_aLines[i].DestroyLine(false);
274 m_bIsLineBeingDrawn = false;
275 m_iLineID = -1;
276 }
277 else if (cacheDrawn) // map is closing, cache drawn lines and destroy
278 {
279 m_aLines[i].DestroyLine(true);
280 }
281 else if (m_aLines[i].m_bIsLineDrawn)
282 {
283 m_aLines[i].SetButtonVisible(false); // only draw mode disabled
284 }
285 }
286 }
287
288 m_bIsDrawModeActive = state;
289 m_ToolMenuEntry.SetActive(state);
290 m_ToolMenuEntry.m_ButtonComp.SetTextVisible(state);
292 }
293
294 //------------------------------------------------------------------------------------------------
297 {
298 m_ToolMenuEntry.m_ButtonComp.SetText(m_iLinesDrawn.ToString() + "/" + m_iLineCount.ToString());
299 }
300
301 //------------------------------------------------------------------------------------------------
302 protected void OnMapClick(float value, EActionTrigger reason)
303 {
305 {
306 m_bActivationThrottle = false;
307 return;
308 }
309
310 EMapEntityMode mode = m_MapEntity.GetMapConfig().MapEntityMode;
311
312 if (mode == EMapEntityMode.SPAWNSCREEN)
313 {
314 SetDrawMode(false);
315 return;
316 }
317
318 if (m_bIsLineBeingDrawn) // state 2, line drawing in progress
319 {
320 m_bIsLineBeingDrawn = false;
321 m_aLines[m_iLineID].m_bIsLineDrawn = true;
322 m_iLineID = -1;
323
324 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_MAP_GADGET_MARKER_DRAW_STOP);
325 GetGame().GetInputManager().RemoveActionListener("MapContextualMenu", EActionTrigger.UP, OnMapModifierClick);
326
327 return;
328 }
329
331 return;
332
333 if (m_CursorModule.GetCursorState() & SCR_MapCursorModule.STATE_DRAW_RESTRICTED) // draw restricted, return here
334 return;
335
336 for (int i; i < m_iLineCount; i++) // state 1, start drawing line
337 {
338 if (!m_aLines[i].m_bIsLineDrawn)
339 {
340 m_aLines[i].CreateLine(m_wDrawingContainer, true);
341 m_bIsLineBeingDrawn = true;
342 m_iLineID = i;
343 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_MAP_GADGET_MARKER_DRAW_START);
344 GetGame().GetInputManager().AddActionListener("MapContextualMenu", EActionTrigger.UP, OnMapModifierClick);
345
346 return;
347 }
348
349 }
350 }
351
352 //------------------------------------------------------------------------------------------------
356 protected void OnMapModifierClick(float value, EActionTrigger reason)
357 {
358 GetGame().GetInputManager().RemoveActionListener("MapContextualMenu", EActionTrigger.UP, OnMapModifierClick);
359 if (!m_bIsLineBeingDrawn || m_iLineID < 0)
360 return;
361
362 m_bIsLineBeingDrawn = false;
363 m_aLines[m_iLineID].DestroyLine();
364 m_iLineID = -1;
365 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_MAP_GADGET_MARKER_DRAW_STOP);
366 }
367
368 //------------------------------------------------------------------------------------------------
373 protected void OnMapPan(float x, float y, bool adjustedPan)
374 {
375 for (int i; i < m_iLineCount; i++)
376 {
377 if (m_aLines[i].m_bIsLineDrawn)
378 m_aLines[i].UpdateLine(false);
379 }
380 }
381
382 //------------------------------------------------------------------------------------------------
386 protected void OnMapPanEnd(float x, float y)
387 {
388 for (int i; i < m_iLineCount; i++)
389 {
390 if (m_aLines[i].m_bIsLineDrawn)
391 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
392 }
393 }
394
395 //------------------------------------------------------------------------------------------------
398 protected void OnEntryToggled(SCR_MapToolEntry entry)
399 {
400 if (m_bIsDrawModeActive && entry != m_ToolMenuEntry)
401 SetDrawMode(false);
402 }
403
404 //------------------------------------------------------------------------------------------------
405 protected void OnInputQuickBind(float value, EActionTrigger reason)
406 {
407 if (!GetGame().GetInputManager().IsUsingMouseAndKeyboard() && IsToolMenuFocused())
408 return;
410 }
411
412 //------------------------------------------------------------------------------------------------
413 override void OnMapOpen(MapConfiguration config)
414 {
415 super.OnMapOpen(config);
416
417 m_wDrawingContainer = FrameWidget.Cast(config.RootWidgetRef.FindAnyWidget(SCR_MapConstants.DRAWING_CONTAINER_WIDGET_NAME));
418
419 m_iLinesDrawn = 0;
420
421 ScriptCallQueue callQueue = GetGame().GetCallqueue();
422 for (int i; i < m_iLineCount; i++)
423 {
425 {
426 m_aLines[i].CreateLine(m_wDrawingContainer);
427 callQueue.CallLater(m_aLines[i].UpdateLine, 0, false, false);
428 m_aLines[i].SetButtonVisible(false);
429 }
430 }
431
432 m_MapEntity.GetOnMapPan().Insert(OnMapPan); // pan for scaling
433 m_MapEntity.GetOnMapPanEnd().Insert(OnMapPanEnd);
435
436 m_CursorModule = SCR_MapCursorModule.Cast(m_MapEntity.GetMapModule(SCR_MapCursorModule));
437 }
438
439 //------------------------------------------------------------------------------------------------
440 override void OnMapClose(MapConfiguration config)
441 {
442 m_MapEntity.GetOnMapPan().Remove(OnMapPan);
443 m_MapEntity.GetOnMapPanEnd().Remove(OnMapPanEnd);
445
446 SetDrawMode(false, true);
447 m_bIsLineBeingDrawn = false;
448
449 super.OnMapClose(config);
450 }
451
452 //------------------------------------------------------------------------------------------------
453 override void Update(float timeSlice)
454 {
456 m_aLines[m_iLineID].UpdateLine(true);
457 }
458
459 //------------------------------------------------------------------------------------------------
460 override void Init()
461 {
462 SCR_MapToolMenuUI toolMenu = SCR_MapToolMenuUI.Cast(m_MapEntity.GetMapUIComponent(SCR_MapToolMenuUI));
463 if (toolMenu)
464 {
465 m_ToolMenuEntry = toolMenu.RegisterToolMenuEntry(SCR_MapToolMenuUI.s_sToolMenuIcons, m_sToolMenuIconName, 13, m_bIsExclusive); // add to menu
466 m_ToolMenuEntry.m_OnClick.Insert(ToggleDrawMode);
467 m_ToolMenuEntry.SetEnabled(true);
468
469 GetGame().GetInputManager().AddActionListener("MapToolPencil", EActionTrigger.DOWN, OnInputQuickBind);
470 }
471
472 for (int i; i < m_iLineCount; i++)
473 {
474 MapLine line = new MapLine(m_MapEntity, this);
475 m_aLines.Insert(line);
476 }
477 }
478}
ArmaReforgerScripted GetGame()
Definition game.c:1398
ref array< string > angles
InputManager GetInputManager()
EMapEntityMode
Mode of the map.
void OnEntryToggled(SCR_MapToolEntry entry)
SCR_MapToolEntry m_ToolMenuEntry
bool m_bIsLineDrawn
Widget m_wDrawingContainer
void OnMapModifierClick(float value, EActionTrigger reason)
bool IsUsingGamepad()
int m_iLinesDrawn
void ToggleDrawMode()
Toggle draw mode.
SCR_MapCursorModule m_CursorModule
int m_iLineCount
SCR_ButtonImageComponent m_DeleteButtonComp
void UpdateLine(bool updateEndPos)
void MapLine(SCR_MapEntity mapEnt, SCR_MapDrawingUI ownerComp)
int m_iLineID
ref array< ref MapLine > m_aLines
bool m_bIsLineBeingDrawn
SCR_MapDrawingUI m_OwnerComponent
bool m_bIsDrawModeActive
bool m_bActivationThrottle
void OnInputQuickBind(float value, EActionTrigger reason)
void OnMapClick(float value, EActionTrigger reason)
void UpdateLineCount()
void OnMapPan(float x, float y, bool adjustedPan)
void OnMapPanEnd(float x, float y)
void SetDrawMode(bool state, bool cacheDrawn=false)
SCR_MapEntity m_MapEntity
void SCR_MapToolMenuUI()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition Color.c:13
Map line.
ButtonWidget m_wDeleteButton
bool m_bIsLineDrawn
float m_fStartPointX
void MapLine(SCR_MapEntity mapEnt, SCR_MapDrawingUI ownerComp)
void OnButtonFocus()
void UpdateLine(bool updateEndPos)
void OnMouseLeave(Widget w)
static const ref Color BUTTON_RED
SCR_MapEntity m_MapEntity
float m_fEndPointY
SCR_MapDrawingUI m_OwnerComponent
ImageWidget m_wLineImage
Widget m_wLine
bool m_bIsInFocus
void OnButtonFocusLost(Widget w)
void DestroyLine(bool cacheDrawn=false)
float m_fStartPointY
void OnButtonClick()
void CreateLine(notnull Widget rootW, bool drawStart=false)
float m_fEndPointX
SCR_ButtonImageComponent m_DeleteButtonComp
void SetButtonVisible(bool target)
void OnMouseEnter(Widget w)
Map tool menu entry data class.
static ScriptInvoker GetOnEntryToggledInvoker()
void OnMapOpen(MapConfiguration config)
void OnMapClose(MapConfiguration config)
void Init()
Init method for cases where all modules and components should be loaded already so constructor cannot...
ScriptCallQueue Class provide "lazy" calls - when we don't want to execute function immediately but l...
Definition tools.c:53
SCR_FieldOfViewSettings Attribute
EActionTrigger