19 [
EntityEditorProps(
category:
"GameScripted/Map", description:
"Map entity, handles displaying of map etc", sizeMin:
"-5 -5 -5", sizeMax:
"5 5 5", color:
"255 255 200 0", dynamicBox:
true)]
22 const int FRAME_DELAY = 1;
23 protected int m_iDelayCounter = FRAME_DELAY;
26 protected bool m_bIsOpen;
27 protected bool m_bDoReload;
28 protected bool m_bDoUpdate;
29 protected bool m_bIsDebugMode;
30 protected int m_iMapSizeX;
31 protected int m_iMapSizeY;
32 protected vector m_vVisibleFrameMin;
33 protected vector m_vVisibleFrameMax;
35 protected Widget m_wMapRoot;
36 protected CanvasWidget m_MapWidget;
37 protected WorkspaceWidget m_Workspace;
38 protected ref MapConfiguration m_ActiveMapCfg;
41 protected MapItem m_HoveredMapItem;
44 protected bool m_bIsZoomInterp;
45 protected float m_fZoomPPU = 1;
46 protected float m_fStartPPU;
47 protected float m_fTargetPPU = 1;
48 protected float m_fZoomTimeModif;
49 protected float m_fZoomSlice;
50 protected float m_fMinZoom = 1;
51 protected float m_fMaxZoom;
54 protected bool m_bIsPanInterp;
55 protected int m_iPanX = 0;
56 protected int m_iPanY = 0;
57 protected int m_aStartPan[2];
58 protected int m_aTargetPan[2];
59 protected float m_fPanTimeModif;
60 protected float m_fPanSlice;
63 protected ref array<ref SCR_MapModuleBase> m_aActiveModules = {};
64 protected ref array<ref SCR_MapModuleBase> m_aLoadedModules = {};
65 protected ref array<ref SCR_MapUIBaseComponent> m_aActiveComponents = {};
66 protected ref array<ref SCR_MapUIBaseComponent> m_aLoadedComponents = {};
69 protected static ref ScriptInvokerBase<MapConfigurationInvoker> s_OnMapInit =
new ScriptInvokerBase<MapConfigurationInvoker>();
70 protected static ref ScriptInvokerBase<MapConfigurationInvoker> s_OnMapOpen =
new ScriptInvokerBase<MapConfigurationInvoker>();
71 protected static ref ScriptInvokerBase<MapConfigurationInvoker> s_OnMapClose =
new ScriptInvokerBase<MapConfigurationInvoker>();
72 protected static ref ScriptInvokerBase<ScriptInvokerFloat2Bool> s_OnMapPan =
new ScriptInvokerBase<ScriptInvokerFloat2Bool>;
78 protected static ref ScriptInvokerBase<MapItemInvoker> s_OnSelectionChanged =
new ScriptInvokerBase<MapItemInvoker>();
79 protected static ref ScriptInvokerBase<MapItemInvoker> s_OnHoverItem =
new ScriptInvokerBase<MapItemInvoker>();
80 protected static ref ScriptInvokerBase<MapItemInvoker> s_OnHoverEnd =
new ScriptInvokerBase<MapItemInvoker>();
86 static ScriptInvokerBase<MapConfigurationInvoker> GetOnMapInit() {
return s_OnMapInit; }
88 static ScriptInvokerBase<MapConfigurationInvoker> GetOnMapOpen() {
return s_OnMapOpen; }
90 static ScriptInvokerBase<MapConfigurationInvoker> GetOnMapClose() {
return s_OnMapClose; }
92 static ScriptInvokerBase<ScriptInvokerFloat2Bool> GetOnMapPan() {
return s_OnMapPan; }
100 static ScriptInvokerBase<MapItemInvoker> GetOnSelectionChanged() {
return s_OnSelectionChanged; }
104 static ScriptInvokerBase<MapItemInvoker> GetOnHoverItem() {
return s_OnHoverItem; }
106 static ScriptInvokerBase<MapItemInvoker> GetOnHoverEnd() {
return s_OnHoverEnd; }
110 static SCR_MapEntity GetMapInstance() {
return s_MapInstance; }
114 MapConfiguration GetMapConfig()
116 return m_ActiveMapCfg;
156 float GetTargetZoomPPU()
165 return m_bIsZoomInterp;
170 vector GetCurrentPan()
177 CanvasWidget GetMapWidget()
184 Widget GetMapMenuRoot()
191 void SetMapWidget(Widget mapW)
193 m_MapWidget = CanvasWidget.Cast(mapW);
200 return m_HoveredMapItem;
205 void GetMapVisibleFrame(out vector min, out vector max)
214 float GetCurrentZoom()
223 void GetMapCursorWorldPosition(out
float worldX, out
float worldY)
232 void GetMapCenterWorldPosition(out
float worldX, out
float worldY)
234 float screenX, screenY;
235 m_MapWidget.GetScreenSize(screenX, screenY);
237 ScreenToWorld(screenX/2, screenY/2, worldX, worldY);
248 if ( module.IsInherited(moduleType) )
263 if ( comp.IsInherited(componentType) )
275 void OpenMap(MapConfiguration config)
282 Print(
"SCR_MapEntity: Attempted opening a map while it is already open", LogLevel.WARNING);
286 if (config.MapEntityMode != m_eLastMapMode)
289 m_eLastMapMode = config.MapEntityMode;
290 m_ActiveMapCfg = config;
292 m_wMapRoot = config.RootWidgetRef;
294 SetMapWidget(config.RootWidgetRef.FindAnyWidget(
SCR_MapConstants.MAP_WIDGET_NAME));
304 gameMode.GetOnPlayerDeleted().Insert(OnPlayerDeleted);
309 SetFrame(Vector(0, 0, 0), Vector(0, 0, 0));
313 s_OnMapInit.Invoke(config);
315 PlayerController plc =
GetGame().GetPlayerController();
317 plc.SetCharacterCameraRenderActive(
false);
330 m_iDelayCounter = FRAME_DELAY;
331 auto plc =
GetGame().GetPlayerController();
333 plc.SetCharacterCameraRenderActive(
true);
339 protected void OnMapOpen(MapConfiguration config)
342 m_MapWidget.SetSizeInUnits(Vector(m_iMapSizeX, m_iMapSizeY, 0));
344 AssignViewLayer(
true);
348 ZoomSmooth(m_fZoomPPU, reinitZoom:
true);
353 ActivateModules(config.Modules);
354 ActivateComponents(config.Components);
355 ActivateOtherComponents(config.OtherComponents);
360 s_OnMapOpen.Invoke(config);
370 protected void OnMapClose()
373 s_OnMapClose.Invoke(m_ActiveMapCfg);
379 PlayerController controller =
GetGame().GetPlayerController();
382 ChimeraCharacter
char = ChimeraCharacter.Cast(controller.GetControlledEntity());
389 gameMode.GetOnPlayerDeleted().Remove(OnPlayerDeleted);
412 IEntity mapGadget = gadgetMgr.GetGadgetByType(EGadgetType.MAP);
416 SCR_MapGadgetComponent mapComp = SCR_MapGadgetComponent.Cast(mapGadget.FindComponent(SCR_MapGadgetComponent));
417 mapComp.SetMapMode(
false);
423 protected void OnPlayerDeleted(
int playerId, IEntity player)
428 MenuManager menuManager = g_Game.GetMenuManager();
434 protected void OnUserSettingsChanged()
441 ZoomSmooth(m_fZoomPPU, reinitZoom:
true);
449 protected void OnWindowResized(
int width,
int heigth,
bool windowed)
451 OnUserSettingsChanged();
461 MapConfiguration SetupMapConfig(
EMapEntityMode mapMode, ResourceName configPath, Widget rootWidget)
463 if (mapMode == m_eLastMapMode)
465 m_ActiveMapCfg.RootWidgetRef = rootWidget;
466 return m_ActiveMapCfg;
470 m_aLoadedComponents.Clear();
471 m_aLoadedModules.Clear();
474 Resource container = BaseContainerTools.LoadContainer(configPath);
478 SCR_MapConfig mapConfig =
SCR_MapConfig.Cast( BaseContainerTools.CreateInstanceFromContainer( container.GetResource().ToBaseContainer() ) );
479 MapConfiguration configObject =
new MapConfiguration();
482 configObject.RootWidgetRef = rootWidget;
483 configObject.MapEntityMode = mapConfig.m_iMapMode;
486 configObject.Modules = mapConfig.m_aModules;
487 configObject.Components = mapConfig.m_aUIComponents;
489 if (mapConfig.m_bEnableLegendScale ==
true)
492 if (mapConfig.m_bEnableGrid ==
true)
495 SetupLayersAndProps(configObject, mapConfig);
496 SetupDescriptorTypes(mapConfig.m_DescriptorDefaultsConfig);
505 protected void SetupLayersAndProps(inout MapConfiguration configObject,
SCR_MapConfig mapCfg)
510 Resource containerDefs = BaseContainerTools.LoadContainer(
SCR_MapConstants.CFG_LAYERS_DEFAULT);
511 layersCfg =
SCR_MapLayersBase.Cast( BaseContainerTools.CreateInstanceFromContainer( containerDefs.GetResource().ToBaseContainer() ) );
514 configObject.LayerConfig = layersCfg;
516 if (layersCfg.m_aLayers.IsEmpty())
517 configObject.LayerCount = 0;
519 configObject.LayerCount = layersCfg.m_aLayers.Count();
524 Resource containerDefs = BaseContainerTools.LoadContainer(
SCR_MapConstants.CFG_PROPS_DEFAULT);
525 propsCfg =
SCR_MapPropsBase.Cast( BaseContainerTools.CreateInstanceFromContainer( containerDefs.GetResource().ToBaseContainer() ) );
528 configObject.MapPropsConfig = propsCfg;
531 if (!descriptorViewCfg)
533 Resource containerDefs = BaseContainerTools.LoadContainer(
SCR_MapConstants.CFG_DESCVIEW_DEFAULT);
534 descriptorViewCfg =
SCR_MapDescriptorVisibilityBase.Cast( BaseContainerTools.CreateInstanceFromContainer( containerDefs.GetResource().ToBaseContainer() ) );
537 configObject.DescriptorVisibilityConfig = descriptorViewCfg;
541 if (!descriptorDefaults)
543 Resource containerDefs = BaseContainerTools.LoadContainer(
SCR_MapConstants.CFG_DESCTYPES_DEFAULT);
544 descriptorDefaults =
SCR_MapDescriptorDefaults.Cast( BaseContainerTools.CreateInstanceFromContainer( containerDefs.GetResource().ToBaseContainer() ) );
547 configObject.DescriptorDefsConfig = descriptorDefaults;
556 array<int> imagesetIndices = {};
558 if (!descriptorDefaultsConfig.m_aDescriptorDefaults.IsEmpty())
562 imagesetIndices.Insert(-1);
567 imagesetIndices[descriptorDefs.m_iDescriptorType] = descriptorDefs.m_iImageSetIndex;
580 if (m_iDelayCounter > 0)
582 Print(
"SCR_MapEntity: Attempt to call CenterMap before map init is completed", LogLevel.WARNING);
588 WorldToScreen(GetMapSizeX() / 2, GetMapSizeY() / 2, x, y);
597 SetZoom(m_fMinZoom,
true);
603 void ShowScriptDebug()
605 m_bIsDebugMode = !m_bIsDebugMode;
612 void SetZoom(
float targetPPU,
bool instant =
false)
614 if (m_iDelayCounter > 0)
616 Print(
"SCR_MapEntity: Attempt to call SetZoom before map init is completed", LogLevel.NORMAL);
620 targetPPU = Math.Clamp(targetPPU, m_fMinZoom, m_fMaxZoom);
622 m_fZoomPPU = targetPPU;
623 AssignViewLayer(
false);
624 ZoomChange(targetPPU / m_MapWidget.PixelPerUnit());
627 m_fTargetPPU = m_fZoomPPU;
629 s_OnMapZoom.Invoke(targetPPU);
638 void ZoomSmooth(
float targetPixPerUnit,
float zoomTime = 0.25,
bool zoomToCenter =
true,
bool reinitZoom =
false)
640 if (m_iDelayCounter > 0)
642 Print(
"SCR_MapEntity: Attempt to call ZoomSmooth before map init is completed", LogLevel.NORMAL);
649 targetPixPerUnit = Math.Clamp(targetPixPerUnit, m_fMinZoom, m_fMaxZoom);
650 if (!reinitZoom && targetPixPerUnit == m_fZoomPPU)
653 m_fStartPPU = m_fZoomPPU;
654 m_fTargetPPU = targetPixPerUnit;
655 m_fZoomTimeModif = 1/zoomTime;
657 m_bIsZoomInterp =
true;
659 float screenX, screenY, worldX, worldY, targetScreenX, targetScreenY;
660 m_MapWidget.GetScreenSize(screenX, screenY);
665 GetMapCenterWorldPosition(worldX, worldY);
666 WorldToScreenCustom( worldX, worldY, targetScreenX, targetScreenY, targetPixPerUnit,
false );
667 PanSmooth( targetScreenX, targetScreenY, zoomTime );
675 GetMapCursorWorldPosition(worldX, worldY);
676 WorldToScreenCustom( worldX, worldY, targetScreenX, targetScreenY, targetPixPerUnit,
false );
677 PanSmooth( targetScreenX + diffX, targetScreenY + diffY, zoomTime );
687 void ZoomPanSmooth(
float targetPixPerUnit,
float worldX,
float worldY,
float zoomTime = 0.25)
689 if (m_iDelayCounter > 0)
691 Print(
"SCR_MapEntity: Attempt to call ZoomPanSmooth before map init is completed", LogLevel.NORMAL);
698 if (targetPixPerUnit > m_fMaxZoom)
699 targetPixPerUnit = m_fMaxZoom;
700 else if (targetPixPerUnit < m_fMinZoom)
701 targetPixPerUnit = m_fMinZoom;
703 m_fStartPPU = m_fZoomPPU;
704 m_fTargetPPU = targetPixPerUnit;
705 m_fZoomTimeModif = 1/zoomTime;
707 m_bIsZoomInterp =
true;
709 float screenX, screenY, targetScreenX, targetScreenY;
710 m_MapWidget.GetScreenSize(screenX, screenY);
712 WorldToScreenCustom( worldX, worldY, targetScreenX, targetScreenY, targetPixPerUnit,
false );
713 PanSmooth( targetScreenX, targetScreenY, zoomTime );
722 void SetPan(
float x,
float y,
bool isPanEnd =
true,
bool center =
true)
724 if (m_iDelayCounter > 0)
726 Print(
"SCR_MapEntity: Attempt to call SetPan before map init is completed", LogLevel.NORMAL);
730 bool adjustedPan =
false;
733 if (!FitPanBounds(x, y, center))
745 s_OnMapPan.Invoke(m_iPanX, m_iPanY, adjustedPan);
754 if (m_iDelayCounter > 0)
756 Print(
"SCR_MapEntity: Attempt to call Pan before map init is completed", LogLevel.NORMAL);
773 panX = m_iPanX + diffX;
774 panY = m_iPanY + diffY;
781 panX = m_iPanX + panValue;
787 panY = m_iPanY + panValue;
791 SetPan(panX, panY,
false,
false);
792 s_OnMapPanEnd.Invoke(panX, panY);
800 void PanSmooth(
float panX,
float panY,
float panTime = 0.25)
802 if (m_iDelayCounter > 0)
804 Print(
"SCR_MapEntity: Attempt to call PanSmooth before map init is completed", LogLevel.NORMAL);
808 float screenWidth, screenHeight;
809 m_MapWidget.GetScreenSize(screenWidth, screenHeight);
815 m_aStartPan = {
m_Workspace.DPIUnscale(screenWidth/2) - m_iPanX,
m_Workspace.DPIUnscale(screenHeight/2) - m_iPanY };
817 m_fPanTimeModif = 1/panTime;
819 m_bIsPanInterp =
true;
825 void InvokeOnSelect(vector selectionPos)
827 s_OnSelection.Invoke(selectionPos);
835 item.SetHighlighted(
true);
838 s_OnSelectionChanged.Invoke(item);
846 item.SetHovering(
true);
847 m_HoveredMapItem = item;
849 s_OnHoverItem.Invoke(item);
854 void ClearSelection()
859 s_OnSelectionChanged.Invoke(
null);
868 s_OnHoverEnd.Invoke(m_HoveredMapItem);
869 m_HoveredMapItem =
null;
881 void WorldToScreen(
float worldX,
float worldY, out
int screenPosX, out
int screenPosY,
bool withPan =
false)
883 worldY = m_iMapSizeY - worldY;
887 screenPosX = (worldX * m_fZoomPPU) +
m_Workspace.DPIScale(m_iPanX);
888 screenPosY = (worldY * m_fZoomPPU) +
m_Workspace.DPIScale(m_iPanY);
892 screenPosX = worldX * m_fZoomPPU;
893 screenPosY = worldY * m_fZoomPPU;
905 void WorldToScreenCustom(
float worldX,
float worldY, out
int screenPosX, out
int screenPosY,
float targetPPU,
bool withPan =
false)
907 worldY = m_iMapSizeY - worldY;
911 screenPosX = (worldX * targetPPU) +
m_Workspace.DPIScale(m_iPanX);
912 screenPosY = (worldY * targetPPU) +
m_Workspace.DPIScale(m_iPanY);
916 screenPosX = worldX * targetPPU;
917 screenPosY = worldY * targetPPU;
927 void ScreenToWorld(
int screenPosX,
int screenPosY, out
float worldX, out
float worldY)
929 worldX = (screenPosX -
m_Workspace.DPIScale(m_iPanX)) / m_fZoomPPU;
930 worldY = (screenPosY -
m_Workspace.DPIScale(m_iPanY)) / m_fZoomPPU;
931 worldY = m_iMapSizeY - worldY;
940 void ScreenToWorldNoFlip(
int screenPosX,
int screenPosY, out
float worldX, out
float worldY)
942 worldX = (screenPosX -
m_Workspace.DPIScale(m_iPanX)) / m_fZoomPPU;
943 worldY = (screenPosY -
m_Workspace.DPIScale(m_iPanY)) / m_fZoomPPU;
955 static string GetGridLabel(vector pos,
int resMin = 2,
int resMax = 4,
string delimiter =
" ")
958 GetGridPos(pos, gridX, gridZ, resMin, resMax);
959 return gridX.ToString() + delimiter + gridZ.ToString();
969 static void GetGridPos(vector pos, out
int gridX, out
int gridZ,
int resMin = 2,
int resMax = 4)
975 for (
int i = resMax; i >= resMin; i--)
977 int mod = Math.Pow(10, i);
978 int modX = posX - posX % mod;
979 int modZ = posZ - posZ % mod;
980 gridX = gridX * 10 + (modX / mod);
981 gridZ = gridZ * 10 + (modZ / mod);
994 protected bool FitPanBounds(inout
float panX, inout
float panY,
bool center)
996 float windowWidth, windowHeight;
997 m_MapWidget.GetScreenSize(windowWidth, windowHeight);
1000 windowHeight =
m_Workspace.DPIUnscale(windowHeight);
1005 panX = windowWidth/2 - panX;
1006 panY = windowHeight/2 - panY;
1009 int width = m_iMapSizeX * m_fZoomPPU;
1010 int height = m_iMapSizeY * m_fZoomPPU;
1013 int minCoordX = windowWidth/2 -
m_Workspace.DPIUnscale(width);
1014 int minCoordY = windowHeight/2 -
m_Workspace.DPIUnscale(height);
1015 int maxCoordX = windowWidth/2;
1016 int maxCoordY = windowHeight/2;
1024 bool adjusted =
false;
1027 if (panX < minCoordX)
1033 if (panX > maxCoordX)
1039 if (panY < minCoordY)
1045 if (panY > maxCoordY)
1060 bool UpdateZoomBounds()
1062 float screenWidth, screenHeight;
1063 m_MapWidget.GetScreenSize(screenWidth, screenHeight);
1065 float maxUnitsPerScreen = screenHeight / m_MapWidget.PixelPerUnit();
1066 m_fMinZoom = (maxUnitsPerScreen / m_iMapSizeY) * m_MapWidget.PixelPerUnit();
1074 protected void AssignViewLayer(
bool isInit)
1080 for (
int layerID = 0; layerID < count; layerID++ )
1082 if ( GetCurrentZoom() >=
GetLayer(layerID).GetCeiling() )
1087 s_OnLayerChanged.Invoke(layerID);
1099 protected void InitLayers(MapConfiguration mapConfig)
1103 int layerCount = mapConfig.LayerCount;
1109 for (
int i = 0; i < layerCount; i++)
1115 layerConfig.m_aLayers[i].SetLayerProps(layer);
1120 propsCfg.SetDefaults(layer);
1124 InitDescriptors(i, layer, layerConfig.m_aLayers[i], mapConfig);
1137 map<int, int> descriptorVisibility =
new map<int, int>;
1142 if (descConfig.m_iViewLayer >= layerID + 1)
1143 descriptorVisibility.Set(descConfig.m_iDescriptorType, layerID);
1149 if ( descriptorVisibility.Get(descriptorType.m_iDescriptorType) >= layerID )
1154 if (descriptorType.m_bUseFactionColors)
1158 props = layer.GetPropsFor(factionDefaults.m_iFaction, descriptorType.m_iDescriptorType);
1161 descriptorType.SetDefaults(props);
1162 factionDefaults.SetColors(props);
1168 props = layer.GetPropsFor(EFactionMapID.UNKNOWN, descriptorType.m_iDescriptorType);
1171 descriptorType.SetDefaults(props);
1172 descriptorType.SetColors(props);
1182 if (descriptorType.m_bUseFactionColors)
1186 props = layer.GetPropsFor(factionDefaults.m_iFaction, descriptorType.m_iDescriptorType);
1188 props.SetVisible(
false);
1193 props = layer.GetPropsFor(EFactionMapID.UNKNOWN, descriptorType.m_iDescriptorType);
1195 props.SetVisible(
false);
1205 protected void ActivateModules( array<ref SCR_MapModuleBase> modules )
1207 if (modules.IsEmpty())
1210 array<SCR_MapModuleBase> modulesToInit =
new array<SCR_MapModuleBase>();
1217 if (module.IsConfigDisabled())
1220 m_aLoadedModules.Insert(module);
1221 modulesToInit.Insert(module);
1222 m_aActiveModules.Insert(module);
1223 module.SetActive(
true);
1228 int count = m_aLoadedModules.Count();
1229 for (
int i = 0; i < count; i++)
1231 if (!m_aLoadedModules[i].
IsInherited(module.Type()))
1235 if (m_aActiveModules.Find(m_aLoadedModules[i]) == -1)
1237 m_aActiveModules.Insert(m_aLoadedModules[i]);
1238 m_aLoadedModules[i].SetActive(
true);
1254 protected void ActivateComponents( array<ref SCR_MapUIBaseComponent> components )
1256 if (components.IsEmpty())
1259 array<SCR_MapUIBaseComponent> componentsToInit =
new array<SCR_MapUIBaseComponent>();
1266 if (component.IsConfigDisabled())
1269 m_aLoadedComponents.Insert(component);
1270 componentsToInit.Insert(component);
1271 m_aActiveComponents.Insert(component);
1272 component.SetActive(
true);
1277 int count = m_aLoadedComponents.Count();
1278 for (
int i = 0; i < count; i++)
1280 if (!m_aLoadedComponents[i].
IsInherited(component.Type()))
1284 if (m_aActiveComponents.Find(m_aLoadedComponents[i]) == -1)
1286 m_aActiveComponents.Insert(m_aLoadedComponents[i]);
1287 m_aLoadedComponents[i].SetActive(
true);
1322 m_aActiveModules.RemoveItem(module);
1323 m_aLoadedModules.RemoveItem(module);
1330 m_aActiveComponents.RemoveItem(component);
1331 m_aLoadedComponents.RemoveItem(component);
1336 protected void Cleanup()
1341 component.SetActive(
false,
true);
1343 m_aActiveComponents.Clear();
1347 module.SetActive(
false,
true);
1349 m_aActiveModules.Clear();
1351 m_bIsDebugMode =
false;
1358 void UpdateViewPort()
1360 float screenWidth, screenHeight;
1361 m_MapWidget.GetScreenSize(screenWidth, screenHeight);
1363 float minCoordX, minCoordY, maxCoordX, maxCoordY;
1365 ScreenToWorld(screenWidth, 0, maxCoordX, maxCoordY);
1366 ScreenToWorld(0, screenHeight, minCoordX, minCoordY);
1376 protected void PanUpdate(
float timeSlice)
1378 m_fPanSlice -= timeSlice * m_fPanTimeModif;
1381 if (m_fPanSlice <= 0)
1383 m_bIsPanInterp =
false;
1384 SetPan(m_aTargetPan[0], m_aTargetPan[1]);
1385 s_OnMapPanEnd.Invoke(m_aTargetPan[0], m_aTargetPan[1]);
1389 int panX = Math.Lerp(m_aStartPan[0], m_aTargetPan[0], 1 - m_fPanSlice);
1390 int panY = Math.Lerp(m_aStartPan[1], m_aTargetPan[1], 1 - m_fPanSlice);
1391 SetPan(panX, panY,
false);
1398 protected void ZoomUpdate(
float timeSlice)
1400 m_fZoomSlice -= timeSlice * m_fZoomTimeModif;
1403 if (m_fZoomSlice <= 0)
1405 SetZoom(m_fTargetPPU);
1406 s_OnMapZoomEnd.Invoke(m_fTargetPPU);
1407 m_bIsZoomInterp =
false;
1411 float zoom = Math.Lerp(m_fStartPPU, m_fTargetPPU, 1 - m_fZoomSlice);
1418 protected void UpdateDebug()
1423 ScreenToWorld(x, y, wX, wY);
1425 vector pan = GetCurrentPan();
1426 array<MapItem> outItems = {};
1429 DbgUI.Begin(
"Map debug");
1430 string dbg1 =
"CURSOR SCREEN POS: x: %1 y: %2";
1431 DbgUI.Text(
string.Format( dbg1, x, y ) );
1432 string dbg2 =
"CURSOR WORLD POS: x: %1 y: %2";
1433 DbgUI.Text(
string.Format( dbg2, wX, wY ) );
1434 string dbg3 =
"PAN OFFSET: x: %1 y: %2 ";
1435 DbgUI.Text(
string.Format( dbg3, pan[0], pan[1] ) );
1436 string dbg4 =
"ZOOM: min: %1 max: %2 | pixPerUnit: %3";
1437 DbgUI.Text(
string.Format( dbg4, GetMinZoom(), GetMaxZoom(), GetCurrentZoom() ) );
1438 string dbg5 =
"LAYER: current: %1 | pixPerUnit ceiling: %2";
1440 string dbg6 =
"MODULES: loaded: %1 | active: %2 | list: %3 ";
1441 DbgUI.Text(
string.Format( dbg6, m_aLoadedModules.Count(), m_aActiveModules.Count(), m_aActiveModules ) );
1442 string dbg7 =
"COMPONENTS: loaded: %1 | active: %2 | list: %3 ";
1443 DbgUI.Text(
string.Format( dbg7, m_aLoadedComponents.Count(), m_aActiveComponents.Count(), m_aActiveComponents ) );
1444 string dbg8 =
"MAPITEMS: selected: %1 | hovered: %2 ";
1445 DbgUI.Text(
string.Format( dbg8, outItems, m_HoveredMapItem ) );
1452 protected void UpdateMap(
float timeSlice)
1457 module.Update(timeSlice);
1463 component.Update(timeSlice);
1467 if (m_bIsZoomInterp)
1468 ZoomUpdate(timeSlice);
1471 PanUpdate(timeSlice);
1474 #ifndef DISABLE_GADGETS
1476 override void EOnFrame(IEntity owner,
float timeSlice)
1481 if (m_iDelayCounter >= 0)
1483 if (m_iDelayCounter == 0)
1486 OnMapOpen(m_ActiveMapCfg);
1495 UpdateMap(timeSlice);
1505 override void EOnInit(IEntity owner)
1508 m_iMapSizeX =
Size()[0];
1509 m_iMapSizeY =
Size()[2];
1511 if (m_iMapSizeX == 0 || m_iMapSizeY == 0)
1513 Print(
"SCR_MapEntity: Cannot get the size from terrain. Using default.", LogLevel.WARNING);
1520 world.RegisterEntityToBeUpdatedWhileGameIsPaused(
this);
1526 SetEventMask(EntityEvent.INIT | EntityEvent.FRAME);
1528 s_MapInstance =
this;
1530 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_UI_MAP_DEBUG_OPTIONS,
"",
"Enable map debug menu",
"UI");
1532 GetGame().OnUserSettingsChangedInvoker().Insert(OnUserSettingsChanged);
1533 GetGame().OnWindowResizeInvoker().Insert(OnWindowResized);
1544 world.UnregisterEntityToBeUpdatedWhileGameIsPaused(
this);
1546 s_OnMapInit.Clear();
1547 s_OnMapOpen.Clear();
1548 s_OnMapClose.Clear();
1550 s_OnMapPanEnd.Clear();
1551 s_OnMapZoom.Clear();
1552 s_OnMapZoomEnd.Clear();
1553 s_OnSelectionChanged.Clear();
1554 s_OnSelection.Clear();
1555 s_OnHoverItem.Clear();
1556 s_OnHoverEnd.Clear();
1557 s_OnLayerChanged.Clear();
1561 s_MapInstance =
null;