Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
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 ;
18 protected ref SizeToChild m_LegendResizer;
19
21 protected ImageWidget m_Images;
23 protected ImageWidget m_GPSMarkerArrow;
26 protected ImageWidget m_ToolsCompassArrow;
33 protected CanvasWidget m_ToolsScaleCellSizeCanvas;
34 protected ItemMap m_Map;
35 protected Widget m_ToolbarPanel;
36 //int m_MarkerCount;
37
39
40 void ~MapMenu()
41 {
42 if (g_Game && g_Game.GetMission())
43 {
44 g_Game.GetMission().GetOnInputPresetChanged().Remove(OnInputPresetChanged);
45 g_Game.GetMission().GetOnInputDeviceChanged().Remove(OnInputDeviceChanged);
46 }
47 }
48
49 override Widget Init()
50 {
51 layoutRoot = g_Game.GetWorkspace().CreateWidgets("gui/layouts/day_z_map.layout");
52 m_Hud = IngameHud.Cast(g_Game.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");
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;
84
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 = g_Game.ConfigGetVector(string.Format("CfgWorlds %1 centerPosition", g_Game.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
107
108 if (player)
109 {
110 m_MapNavigationBehaviour = player.GetMapNavigationBehaviour();
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 {
124 {
126 m_MapWidgetInstance.SetMapPos(m_MapNavigationBehaviour.GetPositionReal());
127 }
128 }
129
130 if (m_HasCompass)
131 {
135 {
137 }
138 }
139
141 if ((!m_HasGPS && !m_HasCompass) || !CfgGameplayHandler.GetMapDisplayNavigationInfo())
142 {
144 }
145 }
146 }
147
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);
161
162 g_Game.GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
163 g_Game.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);
223
224 PlayerBase player = PlayerBase.Cast(g_Game.GetPlayer());
225
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()));
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
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);
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
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
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
353 {
355 {
356 g_Game.GetMission().RemoveActiveInputExcludes({"map"});
357 }
358 else
359 {
360 g_Game.GetMission().RemoveActiveInputExcludes({"loopedactions"});
361 }
362
363 g_Game.GetMission().RemoveActiveInputRestriction(EInputRestrictors.MAP);
364 }
365
366 Close();
367 }
368
369 protected void SetCompassUIVisibility(bool pState)
370 {
372 {
373 m_ToolsCompassArrow.Show(pState);
374 }
375
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 {
393 {
394 m_GPSMarkerArrow.Show(pState);
395 }
396 }
397
398 protected void SetUpperLegendVisibility(bool pState)
399 {
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;
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
482 {
483 bool toolbarShow = false;
484 #ifdef PLATFORM_CONSOLE
485 toolbarShow = !g_Game.GetInput().IsEnabledMouseAndKeyboard() || g_Game.GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER;
486 #endif
487
488 m_ToolbarPanel.Show(toolbarShow);
490 }
491
492 protected void ShiftMapToolsContainer()
493 {
494 if (m_ToolbarPanel.IsVisible())
495 {
496 float sizeX,sizeY;
497 m_ToolbarPanel.GetScreenSize(sizeX,sizeY);
499 }
500 else
502 }
503}
static bool GetMapDisplayNavigationInfo()
static bool GetMapIgnoreMapOwnership()
static bool GetMapIgnoreNavItemsOwnership()
static bool GetMapDisplayPlayerPosition()
static const float ICON_SCALE_TOOLBAR
Definition inpututils.c:15
static string GetRichtextButtonIconFromInputAction(notnull UAInput pInput, string pLocalizedDescription, int pInputDeviceType=EUAINPUT_DEVICE_CONTROLLER, float pScale=ICON_SCALE_NORMAL, bool pVertical=false)
Definition inpututils.c:167
string GetMarkerText()
int GetMarkerColor()
int GetMarkerIcon()
vector GetMarkerPos()
static string GetMarkerTypeFromID(int id)
Definition enmath.c:7
proto native UAInput GetInputByID(int iID)
returns list of all bindable (i.e. visible) inputs from the active group ('core' by default)
proto native bool LocalPress()
Xbox menu.
Definition dayzgame.c:64
CanvasWidget m_ToolsScaleCellSizeCanvas
Definition mapmenu.c:33
void OnInputPresetChanged()
ref IngameHud m_Hud
Definition mapmenu.c:15
void CloseMapMenu()
Definition mapmenu.c:332
const int SCALE_RULER_NUM_SEGMENTS
Definition mapmenu.c:5
TextWidget m_ToolsScaleCellSizeText
Definition mapmenu.c:32
void UpdateControlsElementVisibility()
override void Update(float timeslice)
Definition mapmenu.c:219
Widget m_MapToolsContainer
Definition mapmenu.c:20
ImageWidget m_ToolsCompassArrow
Definition mapmenu.c:26
void ~MapMenu()
Definition mapmenu.c:40
void ShiftMapToolsContainer()
Definition mapmenu.c:492
ref MapWidget m_MapWidgetInstance
Definition mapmenu.c:17
void SetUpperLegendVisibility(bool pState)
Definition mapmenu.c:398
Widget m_ToolbarPanel
override void LoadMapMarkers()
Definition mapmenu.c:322
override void OnShow()
Definition mapmenu.c:177
TextWidget m_ToolsGPSElevationText
Definition mapmenu.c:29
ref MapHandler m_MapMenuHandler
Definition mapmenu.c:16
ref MapNavigationBehaviour m_MapNavigationBehaviour
Definition mapmenu.c:38
ref SizeToChild m_LegendResizer
Definition mapmenu.c:18
float m_ToolScaleCellSizeCanvasWidth
Definition mapmenu.c:12
bool m_IsOpenning
Definition mapmenu.c:10
ImageWidget m_Images
Definition mapmenu.c:21
void SetCompassUIVisibility(bool pState)
Definition mapmenu.c:369
const int SCALE_RULER_LINE_WIDTH
Definition mapmenu.c:4
void ProcessDistanceAndUnits(float num, out float dist, out string units)
Definition mapmenu.c:440
void RemoveMarker()
Definition mapmenu.c:317
override bool OnKeyPress(Widget w, int x, int y, int key)
Definition mapmenu.c:199
void SetGPSDirectionVisibility(bool pState)
Definition mapmenu.c:390
const string COORD_FORMAT
Definition mapmenu.c:3
void AddMarker(vector pos, int color, int icon=0)
Definition mapmenu.c:310
override void InitMapItem(EntityAI item)
Definition mapmenu.c:168
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
float m_ToolsContainerPos0[2]
Definition mapmenu.c:13
bool m_WasChanged
Definition mapmenu.c:7
override Widget Init()
Definition mapmenu.c:49
TextWidget m_ToolsCompassAzimuth
Definition mapmenu.c:27
TextWidget m_ToolsGPSXText
Definition mapmenu.c:30
void UpdateControlsElements()
TextWidget m_ToolsScaleContourText
Definition mapmenu.c:28
Widget m_UpperLegendContainer
Definition mapmenu.c:24
Widget m_ToolsCompassBase
Definition mapmenu.c:25
TextWidget m_ToolsGPSYText
Definition mapmenu.c:31
void SetGPSMarkerVisibility(bool pState)
Definition mapmenu.c:382
override bool OnClick(Widget w, int x, int y, int button)
Definition mapmenu.c:185
void RenderScaleRuler()
Definition mapmenu.c:411
ImageWidget m_GPSMarkerArrow
Definition mapmenu.c:23
ItemMap m_Map
Definition mapmenu.c:34
Widget m_GPSMarker
Definition mapmenu.c:22
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZGame g_Game
Definition dayzgame.c:3942
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto float Round(float f)
Returns mathematical round of value.
static proto float Ceil(float f)
Returns ceil of value.
static proto float Floor(float f)
Returns floor of value.
static proto string Format(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
Gets n-th character from string.
const int IDC_CANCEL
Definition constants.c:136
Icon x
Icon y
EInputDeviceType
Definition input.c:3
void Close()
void MapNavigationBehaviour(PlayerBase pPlayer, EMapNavigationType pNavigationType=EMapNavigationType.BASIC)
proto native UAInputAPI GetUApi()