Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MapLocator.c
Go to the documentation of this file.
1 class SCR_MapLocatorClass : GenericEntityClass
2 {
3 };
4 
6 {
7  [Attribute("{2229B9CC8917D3A3}UI/layouts/Map/MapLocationHint.layout", params: "et class=layout")]
8  protected ResourceName m_sUIHintLayout;
9  protected Widget m_wUIHintLayout;
10 
11  [Attribute("MapLocationHint_Text")]
12  protected string m_sMapLocationHintWidgetName1;
13  [Attribute("MapLocationHint_Text2")]
14  protected string m_sMapLocationHintWidgetName2;
15 
16  protected TextWidget m_wUIHintText;
17  protected TextWidget m_wUIHintText2;
18 
19  [Attribute()]
20  protected ref SCR_MapLocationQuadHint m_WorldDirections;
21 
22  protected int m_iGridSizeX;
23  protected int m_iGridSizeY;
24 
25  protected const float angleA = 0.775;
26  protected const float angleB = 0.325;
27 
28  //------------------------------------------------------------------------------------------------
29  override void EOnInit(IEntity owner)
30  {
31  if (!GetGame().InPlayMode() || !m_WorldDirections)
32  return;
33  SCR_MapEntity.GetOnMapOpen().Insert(ShowMapHint);
34  SCR_MapEntity.GetOnMapClose().Insert(HideMapHint);
35 
36  vector mins,maxs;
37  GetGame().GetWorldEntity().GetWorldBounds(mins, maxs);
38 
39  m_iGridSizeX = maxs[0]/3;
40  m_iGridSizeY = maxs[2]/3;
41  }
42 
43  protected void ShowMapHint(MapConfiguration config)
44  {
45  //--- ToDo: Don't hardcode conditions, let the map config define whether to show location hint or not
46  if (SCR_DeployMenuMain.GetDeployMenu())
47  return;
48  m_wUIHintLayout = GetGame().GetWorkspace().CreateWidgets(m_sUIHintLayout);
49  if (!m_wUIHintLayout)
50  return;
51  m_wUIHintText = TextWidget.Cast(m_wUIHintLayout.FindAnyWidget(m_sMapLocationHintWidgetName1));
52  m_wUIHintText2= TextWidget.Cast(m_wUIHintLayout.FindAnyWidget(m_sMapLocationHintWidgetName2));
53  CalculateClosestLocation();
54  GetGame().GetCallqueue().CallLater(CalculateClosestLocation,10000,true);
55  }
56 
57  protected void HideMapHint(MapConfiguration config)
58  {
59  if (m_wUIHintLayout)
60  m_wUIHintLayout.RemoveFromHierarchy();
61  m_wUIHintLayout = null;
62  m_wUIHintText = null;
63  m_wUIHintText2 = null;
64  GetGame().GetCallqueue().Remove(CalculateClosestLocation);
65  }
66 
67  protected void CalculateClosestLocation()
68  {
70  if (!core)
71  return;
72  ChimeraCharacter player = ChimeraCharacter.Cast(SCR_PlayerController.GetLocalControlledEntity());
73  if (!player)
74  {
75  if (m_wUIHintLayout)
76  {
77  m_wUIHintLayout.RemoveFromHierarchy();
78  m_wUIHintLayout = null;
79  }
80  return;
81  }
82  vector posPlayer = player.GetOrigin();
83 
84  SCR_EditableEntityComponent nearest = core.FindNearestEntity(posPlayer, EEditableEntityType.COMMENT, EEditableEntityFlag.LOCAL);
85  if (!nearest)
86  return;
87  GenericEntity nearestLocation = nearest.GetOwner();
88  SCR_MapDescriptorComponent mapDescr = SCR_MapDescriptorComponent.Cast(nearestLocation.FindComponent(SCR_MapDescriptorComponent));
89  string closestLocationName;
90  if (!mapDescr)
91  return;
92  MapItem item = mapDescr.Item();
93  closestLocationName = item.GetDisplayName();
94 
95  vector lastLocationPos = nearestLocation.GetOrigin();
96  float lastDistance = vector.DistanceSqXZ(lastLocationPos, posPlayer);
97 
98  LocalizedString closeLocationAzimuth;
99  vector result = posPlayer - lastLocationPos;
100  result.Normalize();
101 
102  float angle1 = vector.DotXZ(result,vector.Forward);
103  float angle2 = vector.DotXZ(result,vector.Right);
104 
105  if (angle2 > 0)
106  {
107  if (angle1 >= angleA)
108  closeLocationAzimuth = "#AR-MapLocationHint_DirectionNorth";
109  if (angle1 < angleA && angle1 >= angleB )
110  closeLocationAzimuth = "#AR-MapLocationHint_DirectionNorthEast";
111  if (angle1 < angleB && angle1 >=-angleB)
112  closeLocationAzimuth = "#AR-MapLocationHint_DirectionEast";
113  if (angle1 < -angleB && angle1 >=-angleA)
114  closeLocationAzimuth = "#AR-MapLocationHint_DirectionSouthEast";
115  if (angle1 < -angleA)
116  closeLocationAzimuth = "#AR-MapLocationHint_DirectionSouth";
117  }
118  else
119  {
120  if (angle1 >= angleA)
121  closeLocationAzimuth = "#AR-MapLocationHint_DirectionNorth";
122  if (angle1 < angleA && angle1 >= angleB )
123  closeLocationAzimuth = "#AR-MapLocationHint_DirectionNorthWest";
124  if (angle1 < angleB && angle1 >=-angleB)
125  closeLocationAzimuth = "#AR-MapLocationHint_DirectionWest";
126  if (angle1 < -angleB && angle1 >=-angleA)
127  closeLocationAzimuth = "#AR-MapLocationHint_DirectionSouthWest";
128  if (angle1 < -angleA)
129  closeLocationAzimuth = "#AR-MapLocationHint_DirectionSouth";
130  };
131 
132  int playerGridPositionX = posPlayer[0]/m_iGridSizeX;
133  int playerGridPositionY = posPlayer[2]/m_iGridSizeY;
134 
135  int playerGridID = GetGridIndex(playerGridPositionX,playerGridPositionY);
136  m_wUIHintText.SetTextFormat(m_WorldDirections.GetPlayerPositionHint(), m_WorldDirections.GetQuadHint(playerGridID));
137  if (lastDistance < 40000)
138  m_wUIHintText2.SetTextFormat("#AR-MapLocationHint_PlayerPositionNear", closestLocationName);
139  else
140  {
141  m_wUIHintText2.SetVisible(!closestLocationName.IsEmpty());
142  m_wUIHintText2.SetTextFormat(closeLocationAzimuth, closestLocationName);
143  }
144  }
145 
146  protected int GetGridIndex(int x, int y)
147  {
148  return 3*y + x;
149  }
150 
151  //------------------------------------------------------------------------------------------------
152  void SCR_MapLocator(IEntitySource src, IEntity parent)
153  {
154  SetEventMask(EntityEvent.INIT);
155  }
156 };
157 
158 //------------------------------------------------------------------------------------------------
159 [BaseContainerProps(configRoot: true)]
161 {
162  [Attribute("#AR-MapLocationHint_PlayerPositionIslandName")]
163  protected LocalizedString m_sPlayerPositionHint;
164 
165  [Attribute(desc: "Description of given quad. Order: SW, S, SE, W, C, E, NW, N, NE", params: "MaxSize=9")]
166  protected ref array<LocalizedString> m_aQuadHints;
167 
168  //------------------------------------------------------------------------------------------------
169  LocalizedString GetPlayerPositionHint()
170  {
171  return m_sPlayerPositionHint;
172  }
173 
174  LocalizedString GetQuadHint(int index)
175  {
176  if (!m_aQuadHints.IsIndexValid(index))
177  return LocalizedString.Empty;
178 
179  return m_aQuadHints[index];
180  }
181 };
EEditableEntityFlag
EEditableEntityFlag
Unique flags of the entity.
Definition: EEditableEntityFlag.c:5
SCR_EditableEntityCore
Definition: SCR_EditableEntityCore.c:10
SCR_PlayerController
Definition: SCR_PlayerController.c:31
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
SCR_MapLocatorClass
Definition: SCR_MapLocator.c:1
Attribute
typedef Attribute
Post-process effect of scripted camera.
MapItem
Definition: MapItem.c:12
EEditableEntityType
EEditableEntityType
Defines type of SCR_EditableEntityComponent. Assigned automatically based on IEntity inheritance.
Definition: EEditableEntityType.c:5
SCR_MapLocationQuadHint
Definition: SCR_MapLocator.c:160
SCR_MapEntity
Map entity.
Definition: SCR_MapEntity.c:20
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_MapLocator
Definition: SCR_MapLocator.c:5
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
LocalizedString
Definition: LocalizedString.c:21
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468