Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MapRulerUI.c
Go to the documentation of this file.
2 {
3  [Attribute(defvalue: "1994", uiwidget: UIWidgets.EditBox, desc: "pix, exact length of the ruler within the provided image, default base length being 1km in world space")]
4  float m_fRulerLength;
5 
6  [Attribute("RulerFrame", UIWidgets.EditBox, desc: "Root frame widget name")]
7  string m_sRootWidgetName;
8 
9  [Attribute("RulerImage", UIWidgets.EditBox, desc: "Ruler image widget name")]
10  string m_sImageWidgetName;
11 
12  [Attribute("ruler", UIWidgets.EditBox, desc: "Toolmenu imageset quad name")]
13  string m_sToolMenuIconName;
14 
15  [Attribute("", UIWidgets.Object, desc: "Array of sizes, multiplicator values of default base ruler length of 1km")]
16  protected ref array<ref int> m_aSizesArray;
17 
18  protected bool m_bIsVisible;
19  protected bool m_bWantedVisible;
20  protected bool m_bIsDragged;
21  protected bool m_bIsZooming;
22  protected int m_iCurrentSizeIndex; // current id of m_SizesArray
23  protected int m_iSizesCount; // count of m_SizesArray
24  protected float m_fPosX, m_fPosY; // widget position in scaled screen coords
25  protected float m_fWorldX, m_fWorldY; // widget world pos
26  protected float m_fAngle; // cached angle for map reopen
27  protected float m_fBaseImageSize[2]; // for calculation of ruler scaling
28  protected float m_fSizeCoef; // ruler size coefficient based on image size and ruler length
29  protected vector m_vMapPan;
30  protected SCR_MapToolEntry m_ToolMenuEntry;
31 
32  // Widgets
33  protected Widget m_wFrame;
34  protected ImageWidget m_wImage;
35  protected WorkspaceWidget m_wWorkspace;
36 
37  //------------------------------------------------------------------------------------------------
39  protected void ToggleVisible()
40  {
41  if (!m_bIsVisible)
42  SetVisible(true);
43  else
44  SetVisible(false);
45  }
46 
47  //------------------------------------------------------------------------------------------------
51  protected void SetVisible(bool visible, bool saveState = false)
52  {
53  m_bIsVisible = visible;
54  m_wFrame.SetEnabled(visible);
55  m_wFrame.SetVisible(visible);
56 
57  if (visible)
58  {
59  float zoomVal = m_MapEntity.GetCurrentZoom();
60  m_fSizeCoef = 1000 / (m_fRulerLength / m_fBaseImageSize[0]); // (ruler real length%) / 1000 pix(meters)
61  float sizeVal = m_wWorkspace.DPIUnscale(zoomVal * m_fSizeCoef);
62  SetSize(sizeVal, sizeVal);
63 
64  if (m_fPosX == 0 && m_fPosY == 0)
65  {
66  float sizeX, sizeY;
67  m_MapEntity.GetMapWidget().GetScreenSize(sizeX, sizeY);
68  m_fPosX = sizeX * 0.5;
69  m_fPosY = sizeY * 0.5;
70 
71  m_MapEntity.ScreenToWorld(m_fPosX, m_fPosY, m_fWorldX, m_fWorldY);
72  }
73 
74  FrameSlot.SetPos(m_wFrame, m_wWorkspace.DPIUnscale(m_fPosX), m_wWorkspace.DPIUnscale(m_fPosY));
75  m_wImage.SetRotation(m_fAngle);
76  m_vMapPan = m_MapEntity.GetCurrentPan();
77 
78  m_MapEntity.GetOnMapZoom().Insert(OnMapZoom); // zoom for scaling
79  m_MapEntity.GetOnMapPan().Insert(OnMapPan); // pan for scaling
80  }
81  else
82  {
83  if (saveState) // save angle
84  {
85  m_fAngle = m_wImage.GetRotation();
86  }
87  else
88  {
89  m_fAngle = 0;
90  m_fPosX = 0;
91  m_fPosY = 0;
92  }
93 
94  m_MapEntity.GetOnMapZoom().Remove(OnMapZoom); // zoom for scaling
95  m_MapEntity.GetOnMapPan().Remove(OnMapPan); // zoom for scaling
96  }
97 
98  if (m_ToolMenuEntry)
99  m_ToolMenuEntry.SetActive(visible);
100  }
101 
102  //------------------------------------------------------------------------------------------------
107  protected void SetSize(float x, float y, bool nextSize = false)
108  {
109  if (nextSize)
110  {
113  else
114  m_iCurrentSizeIndex = 0;
115  }
116 
117  m_wImage.SetSize(x * m_aSizesArray[m_iCurrentSizeIndex], y * m_aSizesArray[m_iCurrentSizeIndex]);
118 
119  }
120 
121  //------------------------------------------------------------------------------------------------
123  protected void OnMapZoom(float zoomVal)
124  {
125  float sizeVal = m_wWorkspace.DPIUnscale(zoomVal * m_fSizeCoef);
126  SetSize(sizeVal, sizeVal);
127  m_bIsZooming = true;
128  }
129 
130  //------------------------------------------------------------------------------------------------
132  protected void OnMapPan(float x, float y, bool adjustedPan)
133  {
134  if (m_bIsZooming)
135  {
136  m_bIsZooming = false;
137 
138  float screenX, screenY, screenSX, screenSY;
139  m_MapEntity.WorldToScreen( m_fWorldX, m_fWorldY, screenX, screenY, true );
140 
141  m_fPosX = screenX;
142  m_fPosY = screenY;
143  }
144  else
145  {
146  m_fPosX -= m_vMapPan[0] - m_wWorkspace.DPIScale(x);
147  m_fPosY -= m_vMapPan[1] - m_wWorkspace.DPIScale(y);
148  }
149 
150  FrameSlot.SetPos(m_wFrame, m_wWorkspace.DPIUnscale(m_fPosX), m_wWorkspace.DPIUnscale(m_fPosY));
151  m_vMapPan = m_MapEntity.GetCurrentPan();
152  }
153 
154  //------------------------------------------------------------------------------------------------
156  protected void OnDragWidget(Widget widget)
157  {
158  if (widget == m_wFrame)
159  m_bIsDragged = true;
160  else
161  m_bIsDragged = false;
162  }
163 
164  //------------------------------------------------------------------------------------------------
166  protected void OnActivateTool(Widget widget)
167  {
168  if (widget != m_wFrame)
169  return;
170 
171  float zoomVal = m_MapEntity.GetCurrentZoom();
172  float sizeVal = m_wWorkspace.DPIUnscale(zoomVal * m_fSizeCoef);
173 
174  if (m_MapEntity.GetMapSizeX() < m_fSizeCoef * m_aSizesArray[m_iCurrentSizeIndex]) // ruler size is bigger than the map, skip to start of the size array
175  {
177  SetSize(sizeVal, sizeVal);
178  }
179  else
180  {
181  SetSize(sizeVal, sizeVal, true);
182  }
183  }
184 
185  //------------------------------------------------------------------------------------------------
186  protected void OnInputQuickBind(float value, EActionTrigger reason)
187  {
188  ToggleVisible();
189  }
190 
191  //------------------------------------------------------------------------------------------------
192  override void OnMapOpen(MapConfiguration config)
193  {
194  super.OnMapOpen(config);
195 
196  // refresh widgets
197  m_wFrame = m_RootWidget.FindAnyWidget(m_sRootWidgetName);
198  m_wImage = ImageWidget.Cast(m_RootWidget.FindAnyWidget(m_sImageWidgetName));
199 
200  int x, y;
201  m_wImage.GetImageSize(0, x, y);
202  m_fBaseImageSize[0] = x;
203  m_fBaseImageSize[1] = y;
204 
205  m_iSizesCount = m_aSizesArray.Count();
206 
207  if ( SCR_MapToolInteractionUI.Cast(m_MapEntity.GetMapUIComponent(SCR_MapToolInteractionUI)) ) // if dragging available, add callback
208  {
209  SCR_MapToolInteractionUI.GetOnDragWidgetInvoker().Insert(OnDragWidget);
210  SCR_MapToolInteractionUI.GetOnActivateToolInvoker().Insert(OnActivateTool);
211  }
212 
213  SetVisible(m_bWantedVisible); // restore last visible state
214  OnMapZoom(m_MapEntity.GetCurrentZoom());
215  }
216 
217  //------------------------------------------------------------------------------------------------
218  override void OnMapClose(MapConfiguration config)
219  {
220  m_bWantedVisible = m_bIsVisible; // visibility state
221  SetVisible(false, true);
222 
223  super.OnMapClose(config);
224  }
225 
226  //------------------------------------------------------------------------------------------------
227  override void Init()
228  {
229  m_fPosX = 0;
230  m_fPosY = 0;
231  m_wWorkspace = GetGame().GetWorkspace();
232 
233  SCR_MapToolMenuUI toolMenu = SCR_MapToolMenuUI.Cast(m_MapEntity.GetMapUIComponent(SCR_MapToolMenuUI));
234  if (toolMenu)
235  {
236  m_ToolMenuEntry = toolMenu.RegisterToolMenuEntry(SCR_MapToolMenuUI.s_sToolMenuIcons, m_sToolMenuIconName, 10); // add to menu
237  m_ToolMenuEntry.m_OnClick.Insert(ToggleVisible);
238  m_ToolMenuEntry.SetEnabled(true);
239 
240  GetGame().GetInputManager().AddActionListener("MapToolProtractor", EActionTrigger.DOWN, OnInputQuickBind);
241  }
242  }
243 
244  //------------------------------------------------------------------------------------------------
245  override void Update(float timeSlice)
246  {
247  if (m_bIsVisible && m_bIsDragged)
248  {
249  // save position for map reopen
250  float sizeX, sizeY;
251  m_wFrame.GetScreenPos(m_fPosX, m_fPosY);
252  m_wFrame.GetScreenSize(sizeX, sizeY);
253  m_fPosX = m_fPosX + sizeX * 0.5;
254  m_fPosY = m_fPosY + sizeY * 0.5;
255 
256  m_MapEntity.ScreenToWorld(m_fPosX, m_fPosY, m_fWorldX, m_fWorldY);
257  }
258  }
259 
260  //------------------------------------------------------------------------------------------------
261  // constructor
262  void SCR_MapRulerUI()
263  {
264  m_bHookToRoot = true;
265  }
266 }
m_MapEntity
protected SCR_MapEntity m_MapEntity
Definition: SCR_MapGadgetComponent.c:14
m_RootWidget
protected Widget m_RootWidget
Definition: SCR_BinocularsComponent.c:10
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_ToolMenuEntry
protected SCR_MapToolEntry m_ToolMenuEntry
Definition: SCR_MapDrawingUI.c:182
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_iSizesCount
protected int m_iSizesCount
Definition: SCR_MapRTWBaseUI.c:33
SCR_MapToolEntry
Map tool menu entry data class.
Definition: SCR_MapToolMenuUI.c:2
m_fPosX
protected float m_fPosX
Definition: SCR_MapRTWBaseUI.c:34
m_bIsDragged
protected bool m_bIsDragged
Definition: SCR_MapRTWBaseUI.c:31
SCR_MapRulerUI
Definition: SCR_MapRulerUI.c:1
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_sImageWidgetName
protected string m_sImageWidgetName
Definition: SCR_EntityTooltipEditorUIComponent.c:3
m_bWantedVisible
protected bool m_bWantedVisible
Definition: SCR_MapRTWBaseUI.c:30
m_wImage
protected ImageWidget m_wImage
Definition: SCR_BackendImageComponent.c:248
m_bIsVisible
protected bool m_bIsVisible
Definition: SCR_MapRTWBaseUI.c:29
m_fPosY
protected float m_fPosY
Definition: SCR_MapRTWBaseUI.c:34
SCR_MapUIBaseComponent
Definition: SCR_MapUIBaseComponent.c:3
m_fAngle
float m_fAngle
Definition: SCR_AIGroupTargetCluster.c:36
SCR_MapToolMenuUI
void SCR_MapToolMenuUI()
Definition: SCR_MapToolMenuUI.c:389
m_wFrame
protected Widget m_wFrame
Definition: SCR_MapRTWBaseUI.c:42
m_wWorkspace
private WorkspaceWidget m_wWorkspace
Definition: SCR_CursorEditorUIComponent.c:17
m_iCurrentSizeIndex
protected int m_iCurrentSizeIndex
Definition: SCR_MapRTWBaseUI.c:32