Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_MapLocator.c
Go to the documentation of this file.
1class SCR_MapLocatorClass : GenericEntityClass
2{
3};
4
6{
7 [Attribute("{2229B9CC8917D3A3}UI/layouts/Map/MapLocationHint.layout", params: "et class=layout")]
10
11 [Attribute("MapLocationHint_Text")]
13 [Attribute("MapLocationHint_Text2")]
15
18
19 [Attribute()]
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;
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;
54 GetGame().GetCallqueue().CallLater(CalculateClosestLocation,10000,true);
55 }
56
57 protected void HideMapHint(MapConfiguration config)
58 {
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;
73 if (!player)
74 {
76 {
77 m_wUIHintLayout.RemoveFromHierarchy();
78 m_wUIHintLayout = null;
79 }
80 return;
81 }
82 vector posPlayer = player.GetOrigin();
83
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 //------------------------------------------------------------------------------------------------
153 {
155 }
156};
157
158//------------------------------------------------------------------------------------------------
159[BaseContainerProps(configRoot: true)]
161{
162 [Attribute("#AR-MapLocationHint_PlayerPositionIslandName")]
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 //------------------------------------------------------------------------------------------------
173
175 {
176 if (!m_aQuadHints.IsIndexValid(index))
177 return LocalizedString.Empty;
178
179 return m_aQuadHints[index];
180 }
181};
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void IEntity(IEntitySource src, IEntity parent)
protected script Constructor
proto external EntityEvent SetEventMask(EntityEvent e)
proto external Managed FindComponent(typename typeName)
proto external vector GetOrigin()
SCR_EditableEntityComponent FindNearestEntity(vector pos, EEditableEntityType type, EEditableEntityFlag flags=0, bool onlyDirect=true)
static ScriptInvokerBase< MapConfigurationInvoker > GetOnMapClose()
Get on map close invoker.
static ScriptInvokerBase< MapConfigurationInvoker > GetOnMapOpen()
Get on map open invoker.
LocalizedString GetPlayerPositionHint()
LocalizedString GetQuadHint(int index)
LocalizedString m_sPlayerPositionHint
ref array< LocalizedString > m_aQuadHints
Widget m_wUIHintLayout
const float angleA
string m_sMapLocationHintWidgetName2
override void EOnInit(IEntity owner)
TextWidget m_wUIHintText2
void SCR_MapLocator(IEntitySource src, IEntity parent)
int GetGridIndex(int x, int y)
ref SCR_MapLocationQuadHint m_WorldDirections
string m_sMapLocationHintWidgetName1
const float angleB
void HideMapHint(MapConfiguration config)
void ShowMapHint(MapConfiguration config)
ResourceName m_sUIHintLayout
TextWidget m_wUIHintText
void CalculateClosestLocation()
static IEntity GetLocalControlledEntity()
EEditableEntityType
Defines type of SCR_EditableEntityComponent. Assigned automatically based on IEntity inheritance.
EEditableEntityFlag
Unique flags of the entity.
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14