DayZ 1.24
Loading...
Searching...
No Matches
MapMenu.c
Go to the documentation of this file.
1class 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
13 protected float m_ToolsContainerPos0[2];
14
15 protected ref IngameHud m_Hud ;
19
34 protected ItemMap m_Map;
35 protected Widget m_ToolbarPanel;
36 //int m_MarkerCount;
37
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;
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;
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
119
120 if (m_HasGPS)
121 {
122 SetUpperLegendVisibility(true);
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);
135 SetGPSDirectionVisibility(true);
136 }
137
140 SetUpperLegendVisibility(false);
141 }
142 }
143
144 m_MapMenuHandler = new MapHandler(m_MapWidgetInstance);
145
146 if (m_Hud)
147 {
148 m_Hud.ShowHudUI(false);
149 m_Hud.ShowQuickbarUI(false);
150 }
151 }
152
153 float x, y;
154 m_MapToolsContainer.GetScreenPos(x, y);
155 m_ToolsContainerPos0[0] = x;
156 m_ToolsContainerPos0[1] = y;
157
158 GetGame().GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
159 GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
160
161 return layoutRoot;
162 }
163
164 override void InitMapItem(EntityAI item)
165 {
166 super.InitMapItem(item);
167
168 m_Map = ItemMap.Cast(item);
169 //m_Map.SyncMapMarkers();
170 //m_MarkerCount = m_Map.GetMarkerArray().Count();
171 }
172
173 override void OnShow()
174 {
175 super.OnShow();
176
179 }
180
181 override bool OnClick(Widget w, int x, int y, int button)
182 {
183 super.OnClick(w, x, y, button);
184
185 switch (w.GetUserID())
186 {
187 case IDC_CANCEL:
188 CloseMapMenu();
189 return true;
190 }
191
192 return false;
193 }
194
195 override bool OnKeyPress(Widget w, int x, int y, int key)
196 {
197 super.OnKeyPress(w, x, y, key);
198
199 return false;
200 }
201
202 protected void OnInputPresetChanged()
203 {
204#ifdef PLATFORM_CONSOLE
206#endif
207 }
208
214
215 override void Update(float timeslice)
216 {
217 super.Update(timeslice);
218 m_ToolsScaleCellSizeCanvas.Clear();
219
220 PlayerBase player = PlayerBase.Cast(g_Game.GetPlayer());
221
222 if (m_MapWidgetInstance)
223 {
224 if (m_Images)
225 m_MapWidgetInstance.RemoveChild(m_Images);
226
227 if (player)
228 {
229 m_ToolsScaleContourText.SetText(string.Format("%1 m", m_MapWidgetInstance.GetContourInterval()));
230 RenderScaleRuler();
231 float rulerMaxDistance;
232 string rulerUnits;
233 ProcessDistanceAndUnits(m_MapWidgetInstance.GetCellSize(m_ToolScaleCellSizeCanvasWidth), rulerMaxDistance, rulerUnits);
234 m_ToolsScaleCellSizeText.SetText(string.Format("%1%2", rulerMaxDistance, rulerUnits));
235
236 if (m_MapNavigationBehaviour)
237 {
238 vector mapPos = m_MapWidgetInstance.MapToScreen(m_MapNavigationBehaviour.GetPositionReal());
239 float scale = 1 - m_MapWidgetInstance.GetScale();
240
241 if (m_HasCompass)
242 {
243 vector rot = player.GetYawPitchRoll();
244 float angle = Math.Round(rot[0]);
245 if (angle < 0)
246 angle = 360 + angle;
247
248 m_GPSMarkerArrow.SetRotation(0, 0, angle);
249 m_ToolsCompassArrow.SetRotation(0, 0, angle);
250 m_ToolsCompassAzimuth.SetText(string.Format("%1°", angle));
251 }
252
253 array<int> coords = MapNavigationBehaviour.OrderedPositionNumbersFromGridCoords(player);
255 {
256 m_GPSMarker.SetSize(scale * 100, scale * 100);
257 m_GPSMarkerArrow.SetSize(scale * 100, scale * 100);
258 float sizeX, sizeY;
259 m_GPSMarker.GetSize(sizeX, sizeY);
262 m_GPSMarker.SetPos(mapPos[0] - sizeX / 2, mapPos[1] - sizeY / 2);
263 m_GPSMarkerArrow.SetPos(mapPos[0] - sizeX / 2, mapPos[1] - sizeY / 2);
264
265 if (coords.Count() == m_MapNavigationBehaviour.DISPLAY_GRID_POS_MAX_CHARS_COUNT * 2 && coords[0] >= 0)
266 {
267 m_ToolsGPSXText.SetText(string.Format(COORD_FORMAT, coords[0], coords[1], coords[2]));
268 m_ToolsGPSYText.SetText(string.Format(COORD_FORMAT, coords[3], coords[4], coords[5]));
269 }
270 else
271 {
272 m_ToolsGPSXText.SetText("-.--");
273 m_ToolsGPSYText.SetText("-.--");
274 }
275
276 m_ToolsGPSElevationText.SetText(string.Format("%1m", Math.Round(player.GetPosition()[1])));
277 }
278 else
279 {
280 m_ToolsGPSXText.SetText("-.--");
281 m_ToolsGPSYText.SetText("-.--");
282 m_ToolsGPSElevationText.SetText("----m");
283 }
284 }
285 }
286
288 if (!m_IsOpenning && (GetUApi().GetInputByID(UAUIBack).LocalPress() || isClosedWithShortcut))
289 {
290 if (player)
291 player.SetLastMapInfo(m_MapWidgetInstance.GetScale(), m_MapWidgetInstance.GetMapPos());
292
293 CloseMapMenu();
294 }
295
296 m_IsOpenning = false;
297 }
298 }
299
300 void AddMarker(vector pos, int color, int icon = 0)
301 {
302 m_Map.InsertMarker(pos, "", color, icon);
303 m_MapWidgetInstance.AddUserMark(pos, "", color, MapMarkerTypes.GetMarkerTypeFromID(icon));
304 m_WasChanged = true;
305 }
306
308 {
309 m_WasChanged = true;
310 }
311
312 override void LoadMapMarkers()
313 {
315 for (int i = 0; i < m_Map.GetMarkerArray().Count(); i++)
316 {
317 marker = m_Map.GetMarkerArray().Get(i);
318 m_MapWidgetInstance.AddUserMark(marker.GetMarkerPos(), marker.GetMarkerText(), marker.GetMarkerColor(), MapMarkerTypes.GetMarkerTypeFromID(marker.GetMarkerIcon())/*"\\dz\\gear\\navigation\\data\\map_tree_ca.paa"*/);
319 }
320 }
321
323 {
324 if (m_WasChanged)
325 {
326 m_Map.SyncMapMarkers();
327 m_WasChanged = false;
328 }
329
330 PlayerBase player = PlayerBase.Cast(g_Game.GetPlayer());
331 if (player)
332 {
333 player.SetMapClosingSyncSet(false); //map is closing, server needs to be notified - once
334 }
335
336 if (m_Hud)
337 {
338 m_Hud.ShowHudUI(true);
339 m_Hud.ShowQuickbarUI(true);
340 }
341
343 {
345 {
346 GetGame().GetMission().RemoveActiveInputExcludes({"map"});
347 }
348 else
349 {
350 GetGame().GetMission().RemoveActiveInputExcludes({"loopedactions"});
351 }
352
353 GetGame().GetMission().RemoveActiveInputRestriction(EInputRestrictors.MAP);
354 }
355
356 Close();
357 }
358
359 protected void SetCompassUIVisibility(bool pState)
360 {
361 if (m_ToolsCompassArrow)
362 m_ToolsCompassArrow.Show(pState);
363
364 if (m_ToolsCompassAzimuth)
365 m_ToolsCompassAzimuth.Show(pState);
366 }
367
368 protected void SetGPSMarkerVisibility(bool pState)
369 {
370 if (m_GPSMarker)
371 m_GPSMarker.Show(pState);
372 }
373
375 {
376 if (m_GPSMarkerArrow)
377 m_GPSMarkerArrow.Show(pState);
378 }
379
380 protected void SetUpperLegendVisibility(bool pState)
381 {
382 if (m_UpperLegendContainer)
383 m_UpperLegendContainer.Show(pState);
384
385 if (m_LegendResizer)
386 m_LegendResizer.ResizeParentToChild();
387 }
388
389 protected void RenderScaleRuler()
390 {
391 float sizeYShift = 8;
392 float segmentLength = m_ToolScaleCellSizeCanvasWidth / SCALE_RULER_NUM_SEGMENTS;
393 int lineColor = FadeColors.BLACK;
394
395 for (int i = 1; i <= SCALE_RULER_NUM_SEGMENTS; i++)
396 {
397 lineColor = FadeColors.BLACK;
398 if (i % 2 == 0)
399 lineColor = FadeColors.LIGHT_GREY;
400
401 if (i == 1)
402 m_ToolsScaleCellSizeCanvas.DrawLine(0, sizeYShift, segmentLength, sizeYShift, SCALE_RULER_LINE_WIDTH, lineColor);
403 else if (i == SCALE_RULER_NUM_SEGMENTS)
404 m_ToolsScaleCellSizeCanvas.DrawLine(segmentLength * (SCALE_RULER_NUM_SEGMENTS - 1), sizeYShift, segmentLength * SCALE_RULER_NUM_SEGMENTS, sizeYShift, SCALE_RULER_LINE_WIDTH, lineColor);
405 else
406 m_ToolsScaleCellSizeCanvas.DrawLine(segmentLength * (i - 1), sizeYShift, segmentLength * i, sizeYShift, SCALE_RULER_LINE_WIDTH, lineColor);
407 }
408 }
409
410 protected void ProcessDistanceAndUnits(float num, out float dist, out string units)
411 {
412 if (num >= 901)
413 {
414 num *= 0.001;
415 num = Math.Round(num * 10) * 0.1;
416 dist = num;
417 units = "km";
418 }
419 else if (num >= 100 && num <= 900)
420 {
421 num = Math.Ceil(num * 0.1) * 10;
422 dist = num;
423 units = "m";
424 }
425 else if (num >= 1)
426 {
427 num = Math.Floor(num);
428 dist = num;
429 units = "m";
430 }
431 else
432 {
433 num = Math.Ceil(num * 10);
434 dist = num;
435 units = "cm";
436 }
437 }
438
439 protected void UpdateControlsElements()
440 {
441 RichTextWidget toolbarText = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ContextToolbarText"));
442 string text = string.Empty;
443
444 text += string.Format(" <image set=\"xbox_buttons\" name=\"LS\" scale=\"%1\" /> %2 ", InputUtils.ICON_SCALE_TOOLBAR, "#layout_map_navigate");
445 text += string.Format(" <image set=\"xbox_buttons\" name=\"RS\" scale=\"%1\" /> %2 ", InputUtils.ICON_SCALE_TOOLBAR, "#STR_Controls_Zoom");
447
448 toolbarText.SetText(text);
449 }
450
452 {
453 bool toolbarShow = false;
454#ifdef PLATFORM_CONSOLE
455 toolbarShow = !GetGame().GetInput().IsEnabledMouseAndKeyboard() || GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER;
456#endif
457
458 m_ToolbarPanel.Show(toolbarShow);
459 ShiftMapToolsContainer();
460 }
461
462 protected void ShiftMapToolsContainer()
463 {
464 if (m_ToolbarPanel.IsVisible())
465 {
466 float sizeX, sizeY;
467 m_ToolbarPanel.GetScreenSize(sizeX, sizeY);
468 m_MapToolsContainer.SetScreenPos(m_ToolsContainerPos0[0], m_ToolsContainerPos0[1] - sizeY);
469 }
470 else
471 m_MapToolsContainer.SetScreenPos(m_ToolsContainerPos0[0], m_ToolsContainerPos0[1]);
472 }
473}
void OnInputPresetChanged()
Definition Inventory.c:160
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
Definition Inventory.c:167
DayZGame g_Game
Definition DayZGame.c:3528
Hud m_Hud
Icon x
Icon y
void Close()
void UpdateControlsElementVisibility()
void UpdateControlsElements()
void MapNavigationBehaviour(PlayerBase pPlayer, EMapNavigationType pNavigationType=EMapNavigationType.BASIC)
proto native UAInputAPI GetUApi()
static bool GetMapDisplayPlayerPosition()
static bool GetMapDisplayNavigationInfo()
static bool GetMapIgnoreMapOwnership()
static bool GetMapIgnoreNavItemsOwnership()
void ShowHudUI(bool show)
void ShowQuickbarUI(bool show)
static string GetRichtextButtonIconFromInputAction(notnull UAInput pInput, string pLocalizedDescription, int pInputDeviceType=EUAINPUT_DEVICE_CONTROLLER, float pScale=ICON_SCALE_NORMAL, bool pVertical=false)
Definition InputUtils.c:151
static const float ICON_SCALE_TOOLBAR
Definition InputUtils.c:15
static string GetMarkerTypeFromID(int id)
Definition EnMath.c:7
void UpdateControlsElementVisibility()
Definition MapMenu.c:451
override void OnShow()
Definition MapMenu.c:173
void SetGPSMarkerVisibility(bool pState)
Definition MapMenu.c:368
ImageWidget m_Images
Definition MapMenu.c:21
override void Update(float timeslice)
Definition MapMenu.c:215
override void LoadMapMarkers()
Definition MapMenu.c:312
ref MapWidget m_MapWidgetInstance
Definition MapMenu.c:17
void AddMarker(vector pos, int color, int icon=0)
Definition MapMenu.c:300
Widget m_UpperLegendContainer
Definition MapMenu.c:24
void SetUpperLegendVisibility(bool pState)
Definition MapMenu.c:380
TextWidget m_ToolsGPSElevationText
Definition MapMenu.c:29
TextWidget m_ToolsGPSYText
Definition MapMenu.c:31
ItemMap m_Map
Definition MapMenu.c:34
void CloseMapMenu()
Definition MapMenu.c:322
void RenderScaleRuler()
Definition MapMenu.c:389
override void InitMapItem(EntityAI item)
Definition MapMenu.c:164
TextWidget m_ToolsScaleCellSizeText
Definition MapMenu.c:32
Widget m_ToolsCompassBase
Definition MapMenu.c:25
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
Definition MapMenu.c:209
bool m_IsOpenning
Definition MapMenu.c:10
ImageWidget m_GPSMarkerArrow
Definition MapMenu.c:23
ref IngameHud m_Hud
Definition MapMenu.c:15
CanvasWidget m_ToolsScaleCellSizeCanvas
Definition MapMenu.c:33
override bool OnKeyPress(Widget w, int x, int y, int key)
Definition MapMenu.c:195
void SetCompassUIVisibility(bool pState)
Definition MapMenu.c:359
ref MapHandler m_MapMenuHandler
Definition MapMenu.c:16
void ~MapMenu()
Definition MapMenu.c:40
ref MapNavigationBehaviour m_MapNavigationBehaviour
Definition MapMenu.c:38
TextWidget m_ToolsGPSXText
Definition MapMenu.c:30
float m_ToolScaleCellSizeCanvasWidth
Definition MapMenu.c:12
void SetGPSDirectionVisibility(bool pState)
Definition MapMenu.c:374
void UpdateControlsElements()
Definition MapMenu.c:439
bool m_WasChanged
Definition MapMenu.c:7
ImageWidget m_ToolsCompassArrow
Definition MapMenu.c:26
Widget m_GPSMarker
Definition MapMenu.c:22
void RemoveMarker()
Definition MapMenu.c:307
override Widget Init()
Definition MapMenu.c:49
override bool OnClick(Widget w, int x, int y, int button)
Definition MapMenu.c:181
TextWidget m_ToolsCompassAzimuth
Definition MapMenu.c:27
void ProcessDistanceAndUnits(float num, out float dist, out string units)
Definition MapMenu.c:410
ref SizeToChild m_LegendResizer
Definition MapMenu.c:18
void ShiftMapToolsContainer()
Definition MapMenu.c:462
TextWidget m_ToolsScaleContourText
Definition MapMenu.c:28
Widget m_MapToolsContainer
Definition MapMenu.c:20
void OnInputPresetChanged()
Definition MapMenu.c:202
proto native CGame GetGame()
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto float Floor(float f)
Returns floor of value.
static proto float Round(float f)
Returns mathematical round of value.
static proto float Ceil(float f)
Returns ceil of value.
const int IDC_CANCEL
Definition constants.c:128
EInputDeviceType
Definition input.c:3