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;
7 protected bool m_WasChanged;
8 protected bool m_HasCompass
9 protected bool m_HasGPS
10 protected bool m_IsOpenning;
12 protected float m_ToolScaleCellSizeCanvasWidth;
13 protected float m_ToolsContainerPos0[2];
15 protected ref IngameHud
m_Hud ;
17 protected ref
MapWidget m_MapWidgetInstance;
18 protected ref SizeToChild m_LegendResizer;
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;
33 protected CanvasWidget m_ToolsScaleCellSizeCanvas;
35 protected Widget m_ToolbarPanel;
51 layoutRoot =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/day_z_map.layout");
63 m_MapToolsContainer = layoutRoot.FindAnyWidget(
"Map_Tools_Container");
64 m_MapToolsContainer.GetScript(m_LegendResizer);
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");
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");
82 float canvasHeight = 0;
83 m_ToolsScaleCellSizeCanvas.GetSize(m_ToolScaleCellSizeCanvasWidth, canvasHeight);
85 if (m_MapWidgetInstance)
90 if (player && !player.GetLastMapInfo(scale, mapPosition))
92 vector tempPosition =
GetGame().ConfigGetVector(
string.Format(
"CfgWorlds %1 centerPosition",
GetGame().GetWorldName()));
94 mapPosition =
Vector(tempPosition[0], tempPosition[1], tempPosition[2]);
97 m_MapWidgetInstance.SetScale(scale);
98 m_MapWidgetInstance.SetMapPos(mapPosition);
100 m_HasCompass =
false;
103 SetGPSMarkerVisibility(
false);
104 SetGPSDirectionVisibility(
false);
105 SetCompassUIVisibility(
false);
106 SetUpperLegendVisibility(
true);
110 m_MapNavigationBehaviour = player.GetMapNavigationBehaviour();
111 if (m_MapNavigationBehaviour)
122 SetUpperLegendVisibility(
true);
125 SetGPSMarkerVisibility(
true);
126 m_MapWidgetInstance.SetMapPos(m_MapNavigationBehaviour.GetPositionReal());
132 SetCompassUIVisibility(
true);
133 SetUpperLegendVisibility(
true);
136 SetGPSDirectionVisibility(
true);
141 if ((!m_HasGPS && !m_HasCompass) || !
CfgGameplayHandler.GetMapDisplayNavigationInfo())
143 SetUpperLegendVisibility(
false);
148 m_MapMenuHandler =
new MapHandler(m_MapWidgetInstance);
152 m_Hud.ShowHudUI(
false);
153 m_Hud.ShowQuickbarUI(
false);
158 m_MapToolsContainer.GetScreenPos(
x,
y);
159 m_ToolsContainerPos0[0] =
x;
160 m_ToolsContainerPos0[1] =
y;
168 override void InitMapItem(
EntityAI item)
170 super.InitMapItem(item);
187 super.OnClick(w,
x,
y, button);
189 switch (w.GetUserID())
199 override bool OnKeyPress(
Widget w,
int x,
int y,
int key)
201 super.OnKeyPress(w,
x,
y, key);
208 #ifdef PLATFORM_CONSOLE
219 override void Update(
float timeslice)
221 super.Update(timeslice);
222 m_ToolsScaleCellSizeCanvas.Clear();
226 if (m_MapWidgetInstance)
230 m_MapWidgetInstance.RemoveChild(m_Images);
235 m_ToolsScaleContourText.SetText(
string.Format(
"%1 m", m_MapWidgetInstance.GetContourInterval()));
237 float rulerMaxDistance;
239 ProcessDistanceAndUnits(m_MapWidgetInstance.GetCellSize(m_ToolScaleCellSizeCanvasWidth), rulerMaxDistance, rulerUnits);
240 m_ToolsScaleCellSizeText.SetText(
string.Format(
"%1%2", rulerMaxDistance, rulerUnits));
242 if (m_MapNavigationBehaviour)
244 vector mapPos = m_MapWidgetInstance.MapToScreen(m_MapNavigationBehaviour.GetPositionReal());
245 float scale = 1 - m_MapWidgetInstance.GetScale();
249 vector rot = player.GetYawPitchRoll();
250 float angle =
Math.Round(rot[0]);
256 m_GPSMarkerArrow.SetRotation(0, 0, angle);
257 m_ToolsCompassArrow.SetRotation(0, 0, angle);
258 m_ToolsCompassAzimuth.SetText(
string.Format(
"%1°", angle));
264 m_GPSMarker.SetSize(scale * 100, scale * 100);
265 m_GPSMarkerArrow.SetSize(scale * 100, scale * 100);
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);
273 if (coords.Count() == m_MapNavigationBehaviour.DISPLAY_GRID_POS_MAX_CHARS_COUNT * 2 && coords[0] >= 0)
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]));
280 m_ToolsGPSXText.SetText(
"-.--");
281 m_ToolsGPSYText.SetText(
"-.--");
284 m_ToolsGPSElevationText.SetText(
string.Format(
"%1m",
Math.Round(player.GetPosition()[1])));
288 m_ToolsGPSXText.SetText(
"-.--");
289 m_ToolsGPSYText.SetText(
"-.--");
290 m_ToolsGPSElevationText.SetText(
"----m");
295 bool isClosedWithShortcut =
CfgGameplayHandler.GetMapIgnoreMapOwnership() &&
GetUApi().GetInputByID(UAMapToggle).LocalPress();
296 if (!m_IsOpenning && (
GetUApi().GetInputByID(UAUIBack).LocalPress() || isClosedWithShortcut))
300 player.SetLastMapInfo(m_MapWidgetInstance.GetScale(), m_MapWidgetInstance.GetMapPos());
306 m_IsOpenning =
false;
310 void AddMarker(
vector pos,
int color,
int icon = 0)
312 m_Map.InsertMarker(pos,
"",color,icon);
313 m_MapWidgetInstance.AddUserMark(pos,
"", color,
MapMarkerTypes.GetMarkerTypeFromID(icon));
322 override void LoadMapMarkers()
325 for (
int i = 0; i < m_Map.GetMarkerArray().
Count(); i++)
327 marker = m_Map.GetMarkerArray().Get(i);
328 m_MapWidgetInstance.AddUserMark(marker.GetMarkerPos(),marker.GetMarkerText(),marker.GetMarkerColor(),
MapMarkerTypes.GetMarkerTypeFromID(marker.GetMarkerIcon()));
336 m_Map.SyncMapMarkers();
337 m_WasChanged =
false;
343 player.SetMapClosingSyncSet(
false);
348 m_Hud.ShowHudUI(
true);
349 m_Hud.ShowQuickbarUI(
true);
356 GetGame().GetMission().RemoveActiveInputExcludes({
"map"});
360 GetGame().GetMission().RemoveActiveInputExcludes({
"loopedactions"});
363 GetGame().GetMission().RemoveActiveInputRestriction(EInputRestrictors.MAP);
369 protected void SetCompassUIVisibility(
bool pState)
371 if (m_ToolsCompassArrow)
373 m_ToolsCompassArrow.Show(pState);
376 if (m_ToolsCompassAzimuth)
378 m_ToolsCompassAzimuth.Show(pState);
382 protected void SetGPSMarkerVisibility(
bool pState)
386 m_GPSMarker.Show(pState);
390 protected void SetGPSDirectionVisibility(
bool pState)
392 if (m_GPSMarkerArrow)
394 m_GPSMarkerArrow.Show(pState);
398 protected void SetUpperLegendVisibility(
bool pState)
400 if (m_UpperLegendContainer)
402 m_UpperLegendContainer.Show(pState);
407 m_LegendResizer.ResizeParentToChild();
411 protected void RenderScaleRuler()
413 float sizeYShift = 8;
414 float segmentLength = m_ToolScaleCellSizeCanvasWidth / SCALE_RULER_NUM_SEGMENTS;
415 int lineColor = FadeColors.BLACK;
417 for (
int i = 1; i <= SCALE_RULER_NUM_SEGMENTS; i++)
419 lineColor = FadeColors.BLACK;
422 lineColor = FadeColors.LIGHT_GREY;
427 m_ToolsScaleCellSizeCanvas.DrawLine(0, sizeYShift, segmentLength, sizeYShift, SCALE_RULER_LINE_WIDTH, lineColor);
429 else if (i == SCALE_RULER_NUM_SEGMENTS)
431 m_ToolsScaleCellSizeCanvas.DrawLine(segmentLength * (SCALE_RULER_NUM_SEGMENTS - 1), sizeYShift, segmentLength * SCALE_RULER_NUM_SEGMENTS, sizeYShift, SCALE_RULER_LINE_WIDTH, lineColor);
435 m_ToolsScaleCellSizeCanvas.DrawLine(segmentLength * (i - 1), sizeYShift, segmentLength * i, sizeYShift, SCALE_RULER_LINE_WIDTH, lineColor);
440 protected void ProcessDistanceAndUnits(
float num, out
float dist, out
string units)
445 num =
Math.Round(num * 10) * 0.1;
449 else if (num >= 100 && num <= 900)
451 num =
Math.Ceil(num * 0.1) * 10;
457 num =
Math.Floor(num);
463 num =
Math.Ceil(num * 10);
472 string text =
string.Empty;
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));
478 toolbarText.SetText(text);
483 bool toolbarShow =
false;
484 #ifdef PLATFORM_CONSOLE
488 m_ToolbarPanel.Show(toolbarShow);
489 ShiftMapToolsContainer();
492 protected void ShiftMapToolsContainer()
494 if (m_ToolbarPanel.IsVisible())
497 m_ToolbarPanel.GetScreenSize(sizeX,sizeY);
498 m_MapToolsContainer.SetScreenPos(m_ToolsContainerPos0[0],m_ToolsContainerPos0[1] - sizeY);
501 m_MapToolsContainer.SetScreenPos(m_ToolsContainerPos0[0],m_ToolsContainerPos0[1]);