Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
mapmenu.c
Go to the documentation of this file.
1 class MapMenu extends UIScriptedMenu
2 {
3  protected const string COORD_FORMAT = "%1.%2%3";
4  protected const int SCALE_RULER_LINE_WIDTH = 8;
5  protected const int SCALE_RULER_NUM_SEGMENTS = 10;
6 
7  protected bool m_WasChanged;
8  protected bool m_HasCompass
9  protected bool m_HasGPS
10  protected bool m_IsOpenning;
11 
12  protected float m_ToolScaleCellSizeCanvasWidth;
13  protected float m_ToolsContainerPos0[2];
14 
15  protected ref IngameHud m_Hud ;
16  protected ref MapHandler m_MapMenuHandler;
17  protected ref MapWidget m_MapWidgetInstance;
18  protected ref SizeToChild m_LegendResizer;
19 
20  protected Widget m_MapToolsContainer;
21  protected ImageWidget m_Images;
22  protected Widget m_GPSMarker;
23  protected ImageWidget m_GPSMarkerArrow;
24  protected Widget m_UpperLegendContainer;
25  protected Widget m_ToolsCompassBase;
26  protected ImageWidget m_ToolsCompassArrow;
27  protected TextWidget m_ToolsCompassAzimuth;
28  protected TextWidget m_ToolsScaleContourText;
29  protected TextWidget m_ToolsGPSElevationText;
30  protected TextWidget m_ToolsGPSXText;
31  protected TextWidget m_ToolsGPSYText;
32  protected TextWidget m_ToolsScaleCellSizeText;
33  protected CanvasWidget m_ToolsScaleCellSizeCanvas;
34  protected ItemMap m_Map;
35  protected Widget m_ToolbarPanel;
36  //int m_MarkerCount;
37 
38  protected ref MapNavigationBehaviour m_MapNavigationBehaviour;
39 
40  void ~MapMenu()
41  {
42  if (GetGame() && GetGame().GetMission())
43  {
44  GetGame().GetMission().GetOnInputPresetChanged().Remove(OnInputPresetChanged);
45  GetGame().GetMission().GetOnInputDeviceChanged().Remove(OnInputDeviceChanged);
46  }
47  }
48 
49  override Widget Init()
50  {
51  layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/day_z_map.layout");
52  m_Hud = IngameHud.Cast(GetGame().GetMission().GetHud());
53  m_IsOpenning = true;
54 
55  /*MapWidget m = MapWidget.Cast(layoutRoot.FindAnyWidget("Map"));
56  if (m)
57  {
58  m.AddUserMark("2681 4.7 1751", "Lalal", ARGB(255,255,0,0), "\\dz\\gear\\navigation\\data\\map_tree_ca.paa");
59  m.AddUserMark("2683 4.7 1851", "Lala2", ARGB(255,0,255,0), "\\dz\\gear\\navigation\\data\\map_bunker_ca.paa");
60  m.AddUserMark("2670 4.7 1651", "Lala3", ARGB(255,0,0,255), "\\dz\\gear\\navigation\\data\\map_busstop_ca.paa");
61  }*/
62 
63  m_MapToolsContainer = layoutRoot.FindAnyWidget("Map_Tools_Container");
64  m_MapToolsContainer.GetScript(m_LegendResizer);
65 
66  m_MapWidgetInstance = MapWidget.Cast(layoutRoot.FindAnyWidget("Map"));
67  m_GPSMarker = layoutRoot.FindAnyWidget("GPSMarkerCircle");
68  m_GPSMarkerArrow = ImageWidget.Cast(layoutRoot.FindAnyWidget("GPSMarkerArrow"));
69  m_UpperLegendContainer = layoutRoot.FindAnyWidget("Tools_Extra");
70  layoutRoot.Update();
71  m_ToolsCompassBase = layoutRoot.FindAnyWidget("Tools_Compass_Base");
72  m_ToolsCompassArrow = ImageWidget.Cast(layoutRoot.FindAnyWidget("Tools_Compass_Arrow"));
73  m_ToolsCompassAzimuth = TextWidget.Cast(layoutRoot.FindAnyWidget("Tools_Compass_Azimuth"));
74  m_ToolsGPSXText = TextWidget.Cast(layoutRoot.FindAnyWidget("Tools_GPS_X_Value"));
75  m_ToolsGPSYText = TextWidget.Cast(layoutRoot.FindAnyWidget("Tools_GPS_Y_Value"));
76  m_ToolsGPSElevationText = TextWidget.Cast(layoutRoot.FindAnyWidget("Tools_GPS_Elevation_Value"));
77  m_ToolsScaleContourText = TextWidget.Cast(layoutRoot.FindAnyWidget("Tools_Scale_Contour_Value"));
78  m_ToolsScaleCellSizeText = TextWidget.Cast(layoutRoot.FindAnyWidget("Tools_Scale_CellSize_Value"));
79  m_ToolsScaleCellSizeCanvas = CanvasWidget.Cast(layoutRoot.FindAnyWidget("Tools_Scale_CellSize_Canvas"));
80  m_ToolbarPanel = layoutRoot.FindAnyWidget("toolbar_bg");
81 
82  float canvasHeight = 0;
83  m_ToolsScaleCellSizeCanvas.GetSize(m_ToolScaleCellSizeCanvasWidth, canvasHeight);
84 
85  if (m_MapWidgetInstance)
86  {
87  float scale;
88  vector mapPosition;
89  PlayerBase player = PlayerBase.Cast(g_Game.GetPlayer());
90  if (player && !player.GetLastMapInfo(scale, mapPosition))
91  {
92  vector tempPosition = GetGame().ConfigGetVector(string.Format("CfgWorlds %1 centerPosition", GetGame().GetWorldName()));
93  scale = 0.33;
94  mapPosition = Vector(tempPosition[0], tempPosition[1], tempPosition[2]);
95  }
96 
97  m_MapWidgetInstance.SetScale(scale);
98  m_MapWidgetInstance.SetMapPos(mapPosition);
99 
100  m_HasCompass = false;
101  m_HasGPS = false;
102 
103  SetGPSMarkerVisibility(false);
104  SetGPSDirectionVisibility(false);
105  SetCompassUIVisibility(false);
106  SetUpperLegendVisibility(true);
107 
108  if (player)
109  {
110  m_MapNavigationBehaviour = player.GetMapNavigationBehaviour();
111  if (m_MapNavigationBehaviour)
112  {
113  m_HasGPS = (m_MapNavigationBehaviour.GetNavigationType() & EMapNavigationType.GPS|EMapNavigationType.ALL == 0);
114  m_HasCompass = (m_MapNavigationBehaviour.GetNavigationType() & EMapNavigationType.COMPASS|EMapNavigationType.ALL == 0);
115 
117  m_HasGPS = CfgGameplayHandler.GetMapIgnoreNavItemsOwnership() || m_HasGPS;
118  m_HasCompass = CfgGameplayHandler.GetMapIgnoreNavItemsOwnership() || m_HasCompass;
119 
120  if (m_HasGPS)
121  {
122  SetUpperLegendVisibility(true);
123  if (m_HasGPS && CfgGameplayHandler.GetMapDisplayPlayerPosition())
124  {
125  SetGPSMarkerVisibility(true);
126  m_MapWidgetInstance.SetMapPos(m_MapNavigationBehaviour.GetPositionReal());
127  }
128  }
129 
130  if (m_HasCompass)
131  {
132  SetCompassUIVisibility(true);
133  SetUpperLegendVisibility(true);
134  if (m_HasGPS && CfgGameplayHandler.GetMapDisplayPlayerPosition())
135  {
136  SetGPSDirectionVisibility(true);
137  }
138  }
139 
141  if ((!m_HasGPS && !m_HasCompass) || !CfgGameplayHandler.GetMapDisplayNavigationInfo())
142  {
143  SetUpperLegendVisibility(false);
144  }
145  }
146  }
147 
148  m_MapMenuHandler = new MapHandler(m_MapWidgetInstance);
149 
150  if (m_Hud)
151  {
152  m_Hud.ShowHudUI(false);
153  m_Hud.ShowQuickbarUI(false);
154  }
155  }
156 
157  float x,y;
158  m_MapToolsContainer.GetScreenPos(x,y);
159  m_ToolsContainerPos0[0] = x;
160  m_ToolsContainerPos0[1] = y;
161 
162  GetGame().GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
163  GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
164 
165  return layoutRoot;
166  }
167 
168  override void InitMapItem(EntityAI item)
169  {
170  super.InitMapItem(item);
171 
172  m_Map = ItemMap.Cast(item);
173  //m_Map.SyncMapMarkers();
174  //m_MarkerCount = m_Map.GetMarkerArray().Count();
175  }
176 
177  override void OnShow()
178  {
179  super.OnShow();
180 
183  }
184 
185  override bool OnClick(Widget w, int x, int y, int button)
186  {
187  super.OnClick(w, x, y, button);
188 
189  switch (w.GetUserID())
190  {
191  case IDC_CANCEL:
192  CloseMapMenu();
193  return true;
194  }
195 
196  return false;
197  }
198 
199  override bool OnKeyPress(Widget w, int x, int y, int key)
200  {
201  super.OnKeyPress(w, x, y, key);
202 
203  return false;
204  }
205 
206  protected void OnInputPresetChanged()
207  {
208  #ifdef PLATFORM_CONSOLE
210  #endif
211  }
212 
213  protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
214  {
217  }
218 
219  override void Update(float timeslice)
220  {
221  super.Update(timeslice);
222  m_ToolsScaleCellSizeCanvas.Clear();
223 
224  PlayerBase player = PlayerBase.Cast(g_Game.GetPlayer());
225 
226  if (m_MapWidgetInstance)
227  {
228  if (m_Images)
229  {
230  m_MapWidgetInstance.RemoveChild(m_Images);
231  }
232 
233  if (player)
234  {
235  m_ToolsScaleContourText.SetText(string.Format("%1 m", m_MapWidgetInstance.GetContourInterval()));
236  RenderScaleRuler();
237  float rulerMaxDistance;
238  string rulerUnits;
239  ProcessDistanceAndUnits(m_MapWidgetInstance.GetCellSize(m_ToolScaleCellSizeCanvasWidth), rulerMaxDistance, rulerUnits);
240  m_ToolsScaleCellSizeText.SetText(string.Format("%1%2", rulerMaxDistance, rulerUnits));
241 
242  if (m_MapNavigationBehaviour)
243  {
244  vector mapPos = m_MapWidgetInstance.MapToScreen(m_MapNavigationBehaviour.GetPositionReal());
245  float scale = 1 - m_MapWidgetInstance.GetScale();
246 
247  if (m_HasCompass)
248  {
249  vector rot = player.GetYawPitchRoll();
250  float angle = Math.Round(rot[0]);
251  if (angle < 0)
252  {
253  angle = 360 + angle;
254  }
255 
256  m_GPSMarkerArrow.SetRotation(0, 0, angle);
257  m_ToolsCompassArrow.SetRotation(0, 0, angle);
258  m_ToolsCompassAzimuth.SetText(string.Format("%1°", angle));
259  }
260 
261  array<int> coords = MapNavigationBehaviour.OrderedPositionNumbersFromGridCoords(player);
262  if (m_HasGPS || CfgGameplayHandler.GetMapIgnoreNavItemsOwnership())
263  {
264  m_GPSMarker.SetSize(scale * 100, scale * 100);
265  m_GPSMarkerArrow.SetSize(scale * 100, scale * 100);
266  float sizeX, sizeY;
267  m_GPSMarker.GetSize(sizeX, sizeY);
268  sizeX = Math.Round(sizeX);
269  sizeY = Math.Round(sizeY);
270  m_GPSMarker.SetPos(mapPos[0] - sizeX/2, mapPos[1] - sizeY/2);
271  m_GPSMarkerArrow.SetPos(mapPos[0] - sizeX/2, mapPos[1] - sizeY/2);
272 
273  if (coords.Count() == m_MapNavigationBehaviour.DISPLAY_GRID_POS_MAX_CHARS_COUNT * 2 && coords[0] >= 0)
274  {
275  m_ToolsGPSXText.SetText(string.Format(COORD_FORMAT, coords[0], coords[1], coords[2]));
276  m_ToolsGPSYText.SetText(string.Format(COORD_FORMAT, coords[3], coords[4], coords[5]));
277  }
278  else
279  {
280  m_ToolsGPSXText.SetText("-.--");
281  m_ToolsGPSYText.SetText("-.--");
282  }
283 
284  m_ToolsGPSElevationText.SetText(string.Format("%1m", Math.Round(player.GetPosition()[1])));
285  }
286  else
287  {
288  m_ToolsGPSXText.SetText("-.--");
289  m_ToolsGPSYText.SetText("-.--");
290  m_ToolsGPSElevationText.SetText("----m");
291  }
292  }
293  }
294 
295  bool isClosedWithShortcut = CfgGameplayHandler.GetMapIgnoreMapOwnership() && GetUApi().GetInputByID(UAMapToggle).LocalPress();
296  if (!m_IsOpenning && (GetUApi().GetInputByID(UAUIBack).LocalPress() || isClosedWithShortcut))
297  {
298  if (player)
299  {
300  player.SetLastMapInfo(m_MapWidgetInstance.GetScale(), m_MapWidgetInstance.GetMapPos());
301  }
302 
303  CloseMapMenu();
304  }
305 
306  m_IsOpenning = false;
307  }
308  }
309 
310  void AddMarker(vector pos, int color, int icon = 0)
311  {
312  m_Map.InsertMarker(pos,"",color,icon);
313  m_MapWidgetInstance.AddUserMark(pos, "", color, MapMarkerTypes.GetMarkerTypeFromID(icon));
314  m_WasChanged = true;
315  }
316 
317  void RemoveMarker()
318  {
319  m_WasChanged = true;
320  }
321 
322  override void LoadMapMarkers()
323  {
324  MapMarker marker;
325  for (int i = 0; i < m_Map.GetMarkerArray().Count(); i++)
326  {
327  marker = m_Map.GetMarkerArray().Get(i);
328  m_MapWidgetInstance.AddUserMark(marker.GetMarkerPos(),marker.GetMarkerText(),marker.GetMarkerColor(),MapMarkerTypes.GetMarkerTypeFromID(marker.GetMarkerIcon())/*"\\dz\\gear\\navigation\\data\\map_tree_ca.paa"*/);
329  }
330  }
331 
332  void CloseMapMenu()
333  {
334  if (m_WasChanged)
335  {
336  m_Map.SyncMapMarkers();
337  m_WasChanged = false;
338  }
339 
340  PlayerBase player = PlayerBase.Cast(g_Game.GetPlayer());
341  if (player)
342  {
343  player.SetMapClosingSyncSet(false); //map is closing, server needs to be notified - once
344  }
345 
346  if (m_Hud)
347  {
348  m_Hud.ShowHudUI(true);
349  m_Hud.ShowQuickbarUI(true);
350  }
351 
352  if (CfgGameplayHandler.GetMapIgnoreMapOwnership())
353  {
354  if (!CfgGameplayHandler.GetUse3DMap())
355  {
356  GetGame().GetMission().RemoveActiveInputExcludes({"map"});
357  }
358  else
359  {
360  GetGame().GetMission().RemoveActiveInputExcludes({"loopedactions"});
361  }
362 
363  GetGame().GetMission().RemoveActiveInputRestriction(EInputRestrictors.MAP);
364  }
365 
366  Close();
367  }
368 
369  protected void SetCompassUIVisibility(bool pState)
370  {
371  if (m_ToolsCompassArrow)
372  {
373  m_ToolsCompassArrow.Show(pState);
374  }
375 
376  if (m_ToolsCompassAzimuth)
377  {
378  m_ToolsCompassAzimuth.Show(pState);
379  }
380  }
381 
382  protected void SetGPSMarkerVisibility(bool pState)
383  {
384  if (m_GPSMarker)
385  {
386  m_GPSMarker.Show(pState);
387  }
388  }
389 
390  protected void SetGPSDirectionVisibility(bool pState)
391  {
392  if (m_GPSMarkerArrow)
393  {
394  m_GPSMarkerArrow.Show(pState);
395  }
396  }
397 
398  protected void SetUpperLegendVisibility(bool pState)
399  {
400  if (m_UpperLegendContainer)
401  {
402  m_UpperLegendContainer.Show(pState);
403  }
404 
405  if (m_LegendResizer)
406  {
407  m_LegendResizer.ResizeParentToChild();
408  }
409  }
410 
411  protected void RenderScaleRuler()
412  {
413  float sizeYShift = 8;
414  float segmentLength = m_ToolScaleCellSizeCanvasWidth / SCALE_RULER_NUM_SEGMENTS;
415  int lineColor = FadeColors.BLACK;
416 
417  for (int i = 1; i <= SCALE_RULER_NUM_SEGMENTS; i++)
418  {
419  lineColor = FadeColors.BLACK;
420  if (i % 2 == 0)
421  {
422  lineColor = FadeColors.LIGHT_GREY;
423  }
424 
425  if (i == 1)
426  {
427  m_ToolsScaleCellSizeCanvas.DrawLine(0, sizeYShift, segmentLength, sizeYShift, SCALE_RULER_LINE_WIDTH, lineColor);
428  }
429  else if (i == SCALE_RULER_NUM_SEGMENTS)
430  {
431  m_ToolsScaleCellSizeCanvas.DrawLine(segmentLength * (SCALE_RULER_NUM_SEGMENTS - 1), sizeYShift, segmentLength * SCALE_RULER_NUM_SEGMENTS, sizeYShift, SCALE_RULER_LINE_WIDTH, lineColor);
432  }
433  else
434  {
435  m_ToolsScaleCellSizeCanvas.DrawLine(segmentLength * (i - 1), sizeYShift, segmentLength * i, sizeYShift, SCALE_RULER_LINE_WIDTH, lineColor);
436  }
437  }
438  }
439 
440  protected void ProcessDistanceAndUnits(float num, out float dist, out string units)
441  {
442  if (num >= 901)
443  {
444  num *= 0.001;
445  num = Math.Round(num * 10) * 0.1;
446  dist = num;
447  units = "km";
448  }
449  else if (num >= 100 && num <= 900)
450  {
451  num = Math.Ceil(num * 0.1) * 10;
452  dist = num;
453  units = "m";
454  }
455  else if (num >= 1)
456  {
457  num = Math.Floor(num);
458  dist = num;
459  units = "m";
460  }
461  else
462  {
463  num = Math.Ceil(num * 10);
464  dist = num;
465  units = "cm";
466  }
467  }
468 
469  protected void UpdateControlsElements()
470  {
471  RichTextWidget toolbarText = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ContextToolbarText"));
472  string text = string.Empty;
473 
474  text += string.Format(" <image set=\"xbox_buttons\" name=\"LS\" scale=\"%1\" /> %2 ", InputUtils.ICON_SCALE_TOOLBAR, "#layout_map_navigate");
475  text += string.Format(" <image set=\"xbox_buttons\" name=\"RS\" scale=\"%1\" /> %2 ", InputUtils.ICON_SCALE_TOOLBAR, "#STR_Controls_Zoom");
476  text += string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "#close", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
477 
478  toolbarText.SetText(text);
479  }
480 
481  protected void UpdateControlsElementVisibility()
482  {
483  bool toolbarShow = false;
484  #ifdef PLATFORM_CONSOLE
485  toolbarShow = !GetGame().GetInput().IsEnabledMouseAndKeyboard() || GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER;
486  #endif
487 
488  m_ToolbarPanel.Show(toolbarShow);
489  ShiftMapToolsContainer();
490  }
491 
492  protected void ShiftMapToolsContainer()
493  {
494  if (m_ToolbarPanel.IsVisible())
495  {
496  float sizeX,sizeY;
497  m_ToolbarPanel.GetScreenSize(sizeX,sizeY);
498  m_MapToolsContainer.SetScreenPos(m_ToolsContainerPos0[0],m_ToolsContainerPos0[1] - sizeY);
499  }
500  else
501  m_MapToolsContainer.SetScreenPos(m_ToolsContainerPos0[0],m_ToolsContainerPos0[1]);
502  }
503 }
GetGame
proto native CGame GetGame()
UIScriptedMenu
Definition: dayzgame.c:63
m_Hud
Hud m_Hud
Definition: displaystatus.c:29
InputUtils
Definition: inpututils.c:1
MapWidget
Definition: gameplay.c:321
ItemMap
Definition: chernarusmap_open.c:1
IDC_CANCEL
const int IDC_CANCEL
Definition: constants.c:128
UpdateControlsElements
protected void UpdateControlsElements()
Definition: itemdropwarningmenu.c:92
MapMarkerTypes
Definition: mapmarkersinfo.c:1
Close
void Close()
y
Icon y
MapHandler
Definition: maphandler.c:1
MapNavigationBehaviour
void MapNavigationBehaviour(PlayerBase pPlayer, EMapNavigationType pNavigationType=EMapNavigationType.BASIC)
Definition: mapnavigationbehaviour.c:27
OnInputDeviceChanged
protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
Definition: inventory.c:167
EInputDeviceType
EInputDeviceType
Definition: input.c:2
RichTextWidget
Definition: gameplay.c:315
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
Init
class InventoryGridController extends ScriptedWidgetEventHandler Init
Definition: uihintpanel.c:46
TextWidget
Definition: enwidgets.c:219
UpdateControlsElementVisibility
protected void UpdateControlsElementVisibility()
Definition: itemdropwarningmenu.c:100
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
EMapNavigationType
EMapNavigationType
Definition: mapnavigationbehaviour.c:1
CfgGameplayHandler
Definition: cfggameplayhandler.c:1
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
Update
proto native volatile void Update()
Definition: playersoundmanager.c:125
x
Icon x
MapMarker
Definition: inventoryitem.c:1154
OnInputPresetChanged
protected void OnInputPresetChanged()
Definition: inventory.c:160
OnShow
override void OnShow()
Definition: controlsxbox.c:349
Widget
Definition: enwidgets.c:189
GetUApi
proto native UAInputAPI GetUApi()
OnClick
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
Definition: dayzgame.c:146
Math
Definition: enmath.c:6
Vector
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
EntityAI
Definition: building.c:5
Count
@ Count
Definition: randomgeneratorsyncmanager.c:7