16[
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)]
19 const int FRAME_DELAY = 1;
68 protected static ref ScriptInvokerBase<MapConfigurationInvoker>
s_OnMapInit =
new ScriptInvokerBase<MapConfigurationInvoker>();
69 protected static ref ScriptInvokerBase<MapConfigurationInvoker>
s_OnMapOpen =
new ScriptInvokerBase<MapConfigurationInvoker>();
70 protected static ref ScriptInvokerBase<MapConfigurationInvoker>
s_OnMapOpenComplete =
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>();
236 float screenX, screenY;
250 if ( module.IsInherited(moduleType) )
265 if ( comp.IsInherited(componentType) )
284 Print(
"SCR_MapEntity: Attempted opening a map while it is already open",
LogLevel.WARNING);
317 PlayerController plc =
GetGame().GetPlayerController();
319 plc.SetCharacterCameraRenderActive(
false);
333 auto plc =
GetGame().GetPlayerController();
335 plc.SetCharacterCameraRenderActive(
true);
385 PlayerController controller =
GetGame().GetPlayerController();
422 SCR_MapGadgetComponent mapComp = SCR_MapGadgetComponent.Cast(mapGadget.
FindComponent(SCR_MapGadgetComponent));
423 mapComp.SetMapMode(
false);
490 configObject.RootWidgetRef = rootWidget;
491 configObject.MapEntityMode = mapConfig.m_iMapMode;
494 configObject.Modules = mapConfig.m_aModules;
495 configObject.Components = mapConfig.m_aUIComponents;
497 if (mapConfig.m_bEnableLegendScale ==
true)
500 if (mapConfig.m_bEnableGrid ==
true)
522 configObject.LayerConfig = layersCfg;
524 if (layersCfg.m_aLayers.IsEmpty())
525 configObject.LayerCount = 0;
527 configObject.LayerCount = layersCfg.m_aLayers.Count();
536 configObject.MapPropsConfig = propsCfg;
539 if (!descriptorViewCfg)
545 configObject.DescriptorVisibilityConfig = descriptorViewCfg;
548 if (!descriptorDefaults)
554 configObject.DescriptorDefsConfig = descriptorDefaults;
563 array<int> imagesetIndices = {};
565 if (!descriptorDefaultsConfig.m_aDescriptorDefaults.IsEmpty())
569 imagesetIndices.Insert(-1);
574 imagesetIndices[descriptorDefs.m_iDescriptorType] = descriptorDefs.m_iImageSetIndex;
589 Print(
"SCR_MapEntity: Attempt to call CenterMap before map init is completed",
LogLevel.WARNING);
619 void SetZoom(
float targetPPU,
bool instant =
false)
623 Print(
"SCR_MapEntity: Attempt to call SetZoom before map init is completed",
LogLevel.NORMAL);
645 void ZoomSmooth(
float targetPixPerUnit,
float zoomTime = 0.25,
bool zoomToCenter =
true,
bool reinitZoom =
false)
649 Print(
"SCR_MapEntity: Attempt to call ZoomSmooth before map init is completed",
LogLevel.NORMAL);
657 if (!reinitZoom && targetPixPerUnit ==
m_fZoomPPU)
666 float screenX, screenY, worldX, worldY, targetScreenX, targetScreenY;
673 WorldToScreenCustom( worldX, worldY, targetScreenX, targetScreenY, targetPixPerUnit,
false );
674 PanSmooth( targetScreenX, targetScreenY, zoomTime );
683 WorldToScreenCustom( worldX, worldY, targetScreenX, targetScreenY, targetPixPerUnit,
false );
684 PanSmooth( targetScreenX + diffX, targetScreenY + diffY, zoomTime );
694 void ZoomPanSmooth(
float targetPixPerUnit,
float worldX,
float worldY,
float zoomTime = 0.25)
698 Print(
"SCR_MapEntity: Attempt to call ZoomPanSmooth before map init is completed",
LogLevel.NORMAL);
716 float screenX, screenY, targetScreenX, targetScreenY;
719 WorldToScreenCustom( worldX, worldY, targetScreenX, targetScreenY, targetPixPerUnit,
false );
720 PanSmooth( targetScreenX, targetScreenY, zoomTime );
729 void SetPan(
float x,
float y,
bool isPanEnd =
true,
bool center =
true,
bool updatingPan =
false)
733 Print(
"SCR_MapEntity: Attempt to call SetPan before map init is completed",
LogLevel.NORMAL);
737 bool adjustedPan =
false;
775 Print(
"SCR_MapEntity: Attempt to call Pan before map init is completed",
LogLevel.NORMAL);
810 SetPan(panX, panY,
false,
false);
819 void PanSmooth(
float panX,
float panY,
float panTime = 0.25)
823 Print(
"SCR_MapEntity: Attempt to call PanSmooth before map init is completed",
LogLevel.NORMAL);
827 float screenWidth, screenHeight;
828 m_MapWidget.GetScreenSize(screenWidth, screenHeight);
854 item.SetHighlighted(
true);
864 item.SetHovering(
true);
899 void WorldToScreen(
float worldX,
float worldY, out
int screenPosX, out
int screenPosY,
bool withPan =
false)
923 void WorldToScreenCustom(
float worldX,
float worldY, out
int screenPosX, out
int screenPosY,
float targetPPU,
bool withPan =
false)
945 void ScreenToWorld(
int screenPosX,
int screenPosY, out
float worldX, out
float worldY)
976 GetGridPos(pos, gridX, gridZ, resMin, resMax);
977 return gridX.ToString() + delimiter + gridZ.ToString();
987 static void GetGridPos(
vector pos, out
int gridX, out
int gridZ,
int resMin = 2,
int resMax = 4)
993 for (
int i = resMax; i >= resMin; i--)
995 int mod =
Math.Pow(10, i);
996 int modX = posX - posX % mod;
997 int modZ = posZ - posZ % mod;
998 gridX = gridX * 10 + (modX / mod);
999 gridZ = gridZ * 10 + (modZ / mod);
1012 protected bool FitPanBounds(inout
float panX, inout
float panY,
bool center)
1014 float windowWidth, windowHeight;
1015 m_MapWidget.GetScreenSize(windowWidth, windowHeight);
1017 windowWidth =
m_Workspace.DPIUnscale(windowWidth);
1018 windowHeight =
m_Workspace.DPIUnscale(windowHeight);
1023 panX = windowWidth/2 - panX;
1024 panY = windowHeight/2 - panY;
1031 int minCoordX = windowWidth/2 -
m_Workspace.DPIUnscale(width);
1032 int minCoordY = windowHeight/2 -
m_Workspace.DPIUnscale(height);
1033 int maxCoordX = windowWidth/2;
1034 int maxCoordY = windowHeight/2;
1042 bool adjusted =
false;
1045 if (panX < minCoordX)
1051 if (panX > maxCoordX)
1057 if (panY < minCoordY)
1063 if (panY > maxCoordY)
1080 float screenWidth, screenHeight;
1081 m_MapWidget.GetScreenSize(screenWidth, screenHeight);
1083 float maxUnitsPerScreen = screenHeight /
m_MapWidget.PixelPerUnit();
1098 for (
int layerID = 0; layerID < count; layerID++ )
1121 int layerCount = mapConfig.LayerCount;
1127 for (
int i = 0; i < layerCount; i++)
1133 layerConfig.m_aLayers[i].SetLayerProps(
layer);
1138 propsCfg.SetDefaults(
layer);
1160 if (descConfig.m_iViewLayer >= layerID + 1)
1161 descriptorVisibility.Set(descConfig.m_iDescriptorType, layerID);
1167 if ( descriptorVisibility.Get(descriptorType.m_iDescriptorType) >= layerID )
1172 if (descriptorType.m_bUseFactionColors)
1176 props =
layer.GetPropsFor(factionDefaults.m_iFaction, descriptorType.m_iDescriptorType);
1179 descriptorType.SetDefaults(props);
1180 factionDefaults.SetColors(props);
1186 props =
layer.GetPropsFor(EFactionMapID.UNKNOWN, descriptorType.m_iDescriptorType);
1189 descriptorType.SetDefaults(props);
1190 descriptorType.SetColors(props);
1200 if (descriptorType.m_bUseFactionColors)
1204 props =
layer.GetPropsFor(factionDefaults.m_iFaction, descriptorType.m_iDescriptorType);
1206 props.SetVisible(
false);
1211 props =
layer.GetPropsFor(EFactionMapID.UNKNOWN, descriptorType.m_iDescriptorType);
1213 props.SetVisible(
false);
1225 if (modules.IsEmpty())
1228 array<SCR_MapModuleBase> modulesToInit =
new array<SCR_MapModuleBase>();
1235 if (module.IsConfigDisabled())
1239 modulesToInit.Insert(module);
1241 module.SetActive(true);
1247 for (
int i = 0; i < count; i++)
1274 if (components.IsEmpty())
1277 array<SCR_MapUIBaseComponent> componentsToInit =
new array<SCR_MapUIBaseComponent>();
1284 if (component.IsConfigDisabled())
1288 componentsToInit.Insert(component);
1290 component.SetActive(
true);
1296 for (
int i = 0; i < count; i++)
1359 component.SetActive(
false,
true);
1366 module.SetActive(false, true);
1379 float screenWidth, screenHeight;
1380 m_MapWidget.GetScreenSize(screenWidth, screenHeight);
1382 float minCoordX, minCoordY, maxCoordX, maxCoordY;
1410 SetPan(panX, panY,
false,
true,
true);
1445 array<MapItem> outItems = {};
1448 DbgUI.Begin(
"Map debug");
1449 const string dbg1 =
"CURSOR SCREEN POS: x: %1 y: %2";
1450 DbgUI.Text(
string.Format( dbg1, x, y ) );
1451 const string dbg2 =
"CURSOR WORLD POS: x: %1 y: %2";
1452 DbgUI.Text(
string.Format( dbg2, wX, wY ) );
1453 const string dbg3 =
"PAN OFFSET: x: %1 y: %2 ";
1454 DbgUI.Text(
string.Format( dbg3, pan[0], pan[1] ) );
1455 const string dbg4 =
"ZOOM: min: %1 max: %2 | pixPerUnit: %3";
1457 const string dbg5 =
"LAYER: current: %1 | pixPerUnit ceiling: %2";
1459 const string dbg6 =
"MODULES: loaded: %1 | active: %2 | list: %3 ";
1461 const string dbg7 =
"COMPONENTS: loaded: %1 | active: %2 | list: %3 ";
1463 const string dbg8 =
"MAPITEMS: selected: %1 | hovered: %2 ";
1476 module.Update(timeSlice);
1482 component.Update(timeSlice);
1493#ifndef DISABLE_GADGETS
1535 Print(
"SCR_MapEntity: Cannot get the size from terrain. Using default.",
LogLevel.WARNING);
1542 world.RegisterEntityToBeUpdatedWhileGameIsPaused(
this);
1566 world.UnregisterEntityToBeUpdatedWhileGameIsPaused(
this);
ArmaReforgerScripted GetGame()
SCR_CharacterControllerComponent GetCharacterController()
SCR_BaseGameMode GetGameMode()
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
EMapPanMode
Panning modes.
EMapEntityMode
Mode of the map.
EMapOtherComponents
Map components which are not part of the component system.
func ScriptInvokerFloat2Bool
func MapConfigurationInvoker
ScriptInvokerBase< ScriptInvokerFloatMethod > ScriptInvokerFloat
ScriptInvokerBase< ScriptInvokerIntMethod > ScriptInvokerInt
ScriptInvokerBase< ScriptInvokerVectorMethod > ScriptInvokerVector
ScriptInvokerBase< ScriptInvokerFloat2Method > ScriptInvokerFloat2
proto native external bool IsInherited(typename type)
proto external Managed FindComponent(typename typeName)
Object holding reference to resource. In destructor release the resource.
ScriptInvokerBase< SCR_BaseGameMode_PlayerIdAndEntity > GetOnPlayerDeleted()
ref OnLifeStateChangedInvoker m_OnLifeStateChanged
Configuration of descriptor defaults.
Configuration of visibility in layers per descriptor type.
Configuration of descriptor defaults.
IEntity GetGadgetByType(EGadgetType type)
static SCR_GadgetManagerComponent GetGadgetManager(IEntity entity)
Config for default values set per descriptor type.
Descriptor visibility config root.
void OnUserSettingsChanged()
Game event.
static SCR_MapEntity s_MapInstance
ref array< ref SCR_MapUIBaseComponent > m_aActiveComponents
SCR_MapModuleBase GetMapModule(typename moduleType)
void GetMapCenterWorldPosition(out float worldX, out float worldY)
void Pan(EMapPanMode panMode, float panValue=0)
static ScriptInvokerBase< MapConfigurationInvoker > GetOnMapClose()
Get on map close invoker.
ref array< ref SCR_MapModuleBase > m_aActiveModules
static ref ScriptInvokerBase< MapItemInvoker > s_OnHoverItem
static ref ScriptInvokerBase< ScriptInvokerFloat2Bool > s_OnMapPan
CanvasWidget GetMapWidget()
Get map widget.
ref array< ref SCR_MapUIBaseComponent > m_aLoadedComponents
int GetMapSizeX()
Get map sizeX in meters.
vector m_vVisibleFrameMin
static ref ScriptInvokerInt s_OnLayerChanged
void InvokeOnSelect(vector selectionPos)
float GetMinZoom()
Get minimal zoom.
void SetMapWidget(Widget mapW)
Set map widget.
static ScriptInvokerBase< MapConfigurationInvoker > GetOnMapOpenComplete()
Get on map open complete invoker.
Widget GetMapMenuRoot()
Get map menu root widget.
static void GetGridPos(vector pos, out int gridX, out int gridZ, int resMin=2, int resMax=4)
void SetupLayersAndProps(inout MapConfiguration configObject, SCR_MapConfig mapCfg)
MapConfiguration GetMapConfig()
Get map config.
static ref ScriptInvokerBase< MapItemInvoker > s_OnHoverEnd
void ZoomUpdate(float timeSlice)
MapItem GetHoveredItem()
Get hovered item.
vector GetCurrentPan()
Get current DPIScaled pan offsets.
static ScriptInvokerVector GetOnSelection()
Get on selection invoker.
void ShowScriptDebug()
Show/hide debug info table.
bool IsZooming()
Get whether zoom interpolation is ongoing.
void CloseMap()
Close the map.
void ZoomSmooth(float targetPixPerUnit, float zoomTime=0.25, bool zoomToCenter=true, bool reinitZoom=false)
bool FitPanBounds(inout float panX, inout float panY, bool center)
EMapEntityMode m_eLastMapMode
static ScriptInvokerBase< MapItemInvoker > GetOnHoverItem()
Get on hover item invoker.
static ScriptInvokerInt GetOnLayerChanged()
Get on layer changed invoker.
void SetupDescriptorTypes(SCR_MapDescriptorDefaults descriptorDefaultsConfig)
ref array< ref SCR_MapModuleBase > m_aLoadedModules
void OpenMap(MapConfiguration config)
void GetMapCursorWorldPosition(out float worldX, out float worldY)
void InitDescriptors(int layerID, MapLayer layer, SCR_LayerConfiguration layerConfig, MapConfiguration mapConfig)
void ScreenToWorld(int screenPosX, int screenPosY, out float worldX, out float worldY)
Use scaled screen coords to get canvas world coords, flips the y-axis.
static ScriptInvokerBase< MapItemInvoker > GetOnHoverEnd()
Get on hover end invoker.
static ref ScriptInvokerBase< MapConfigurationInvoker > s_OnMapOpen
SCR_MapUIBaseComponent GetMapUIComponent(typename componentType)
void AssignViewLayer(bool isInit)
Checks whether layer should change based on current zoom.
static ref ScriptInvokerFloat s_OnMapZoom
void WorldToScreen(float worldX, float worldY, out int screenPosX, out int screenPosY, bool withPan=false)
Use canvas world coords to get DPIscaled screen coords, flips the y-axis.
static ref ScriptInvokerBase< MapConfigurationInvoker > s_OnMapClose
void SetPan(float x, float y, bool isPanEnd=true, bool center=true, bool updatingPan=false)
void OnPlayerDeleted(int playerId, IEntity player)
static string GetGridLabel(vector pos, int resMin=2, int resMax=4, string delimiter=" ")
void PanSmooth(float panX, float panY, float panTime=0.25)
static ref ScriptInvokerBase< MapConfigurationInvoker > s_OnMapOpenComplete
ref MapConfiguration m_ActiveMapCfg
override void EOnInit(IEntity owner)
void UpdateMap(float timeSlice)
void OnMapClose()
Map close event.
static ref ScriptInvokerVector s_OnSelection
void DeactivateModule(SCR_MapModuleBase module)
Deactivate module, removing it from loadable list until config is reloaded.
void ActivateModules(array< ref SCR_MapModuleBase > modules)
bool IsOpen()
Check if the map is opened.
void ZoomOut()
Set minimal zoom and center the map.
void OnLifeStateChanged(ECharacterLifeState previousLifeState, ECharacterLifeState newLifeState)
float GetTargetZoomPPU()
Get target zoom in the form of PixelPerUnit value, which is different from current zoom if interpolat...
static ref ScriptInvokerFloat2 s_OnMapPanEnd
static ref ScriptInvokerBase< MapConfigurationInvoker > s_OnMapInit
static ScriptInvokerFloat GetOnMapZoomEnd()
Get on map zoom interpolated end invoker.
void SelectItem(MapItem item)
void InitLayers(MapConfiguration mapConfig)
Initialize layers from config.
void UpdateDebug()
Update map debug table.
void DeactivateComponent(SCR_MapUIBaseComponent component)
Deactivate UI component, removing it from loadable list until config is reloaded.
float GetMaxZoom()
Get maximal zoom.
static ScriptInvokerBase< MapConfigurationInvoker > GetOnMapInit()
Get on map init invoker, caution: called during the first frame of opening the map when widget relate...
vector m_vVisibleFrameMax
static ScriptInvokerBase< MapItemInvoker > GetOnSelectionChanged()
Get on selection changed invoker.
void CenterMap()
Center the map.
void ActivateComponents(array< ref SCR_MapUIBaseComponent > components)
WorkspaceWidget m_Workspace
static ScriptInvokerFloat2 GetOnMapPanEnd()
Get on map pan interpolated end invoker.
void HoverItem(MapItem item)
void ActivateOtherComponents(EMapOtherComponents componentFlags)
void PanUpdate(float timeSlice)
static ScriptInvokerBase< ScriptInvokerFloat2Bool > GetOnMapPan()
Get on map pan invoker.
void OnWindowResized(int width, int height, bool windowed)
Game event.
static ScriptInvokerFloat GetOnMapZoom()
Get on map zoom invoker.
void GetMapVisibleFrame(out vector min, out vector max)
Return visible frame in the form of min and max point, used to ignore update of f....
void OnMapOpen(MapConfiguration config)
void SCR_MapEntity(IEntitySource src, IEntity parent)
static ScriptInvokerBase< MapConfigurationInvoker > GetOnMapOpen()
Get on map open invoker.
void UpdateViewPort()
Updates view port.
void ZoomPanSmooth(float targetPixPerUnit, float worldX, float worldY, float zoomTime=0.25)
void ScreenToWorldNoFlip(int screenPosX, int screenPosY, out float worldX, out float worldY)
Use scaled screen coords to get canvas world coords without flipping the y-axis.
MapConfiguration SetupMapConfig(EMapEntityMode mapMode, ResourceName configPath, Widget rootWidget)
void Cleanup()
Map close cleanup.
void SetZoom(float targetPPU, bool instant=false)
static ref ScriptInvokerBase< MapItemInvoker > s_OnSelectionChanged
static SCR_MapEntity GetMapInstance()
Get map entity instance.
int GetMapSizeY()
Get map sizeY in meters.
void ClearHover()
Clear hover state.
void ClearSelection()
Clear selected items.
override void EOnFrame(IEntity owner, float timeSlice)
static ref ScriptInvokerFloat s_OnMapZoomEnd
void WorldToScreenCustom(float worldX, float worldY, out int screenPosX, out int screenPosY, float targetPPU, bool withPan=false)
Use canvas world coords and defined pixel per unit to get DPIscaled screen coords,...
Game g_Game
Game singleton instance.
SCR_EditableEntityComponent GetControlledEntity()
CameraManagerClass GenericEntityClass CurrentCamera()
Returns the current camera.
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
EntityEvent
Various entity events.
proto external PlayerController GetPlayerController()
proto external void EnableGrid(bool bValue)
Enable/ Disable grid visibility.
proto external void InitializeLayers(int count, int factionSize=4)
Clear layer setup + set new layer count.
proto external vector Size()
Terrain dimensions (x, height = maxElevation-minElevation, z).
proto external int GetSelected(out notnull array< MapItem > outItems)
Get all selected entities.
void EnableLegend(bool bValue)
Enable/ Disable legend.
proto external void PosChange(float x, float y)
Set new pos of map.
proto external void ResetSelected()
Reset all entity selection.
proto external void SetLayer(int index)
Set active layer.
proto external vector Offset()
Starting offset of the map.
proto external int GetLayerIndex()
Returns -1 if no valid index previously set.
proto external void SetImagesetMapping(notnull array< int > values)
Sets corresponding multiple imageset indices for MapDescriptors usage.
proto external void SetFrame(vector start, vector end)
Set frame to visualise (from -> to).
proto external MapLayer GetLayer(int index)
Get layer by Index.
proto external void ZoomChange(float level)
Set new zoom.
proto external int LayerCount()
Get layer count.
proto external void EnableVisualisation(bool bValue)
Enable/ Disable visualisation.
MapEntityClass GenericEntityClass UpdateTexts()
proto external void ResetHighlighted()
Reset all entity highlighted tag.
proto external void ResetHovering()
Reset all entity hovering tag.
proto external int GetPlayerId()
proto native vector Vector(float x, float y, float z)