Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_MapDebugUI.c
Go to the documentation of this file.
2{
3 [Attribute("0", UIWidgets.EditBox, desc: "Adjust rotation for debug unit icons", params: "-180 180")]
4 protected float m_fUnitIconRotation;
5
6 [Attribute("{BCD5479864D1A79A}UI/Textures/Map/topographicIcons/icons_topographic_map.imageset", UIWidgets.ResourceNamePicker, "Imageset source for display icon")]
8
9 protected bool m_bIsUnitVisible; // units debug visible
10 protected ref array<MapItem> m_aMapItems = {}; // cached map items
11
13
14 //------------------------------------------------------------------------------------------------
16 protected void ShowUnits()
17 {
19
21 {
22 SetPropsVisible(true);
23
24 int count = m_MapEntity.GetByType(m_aMapItems, EMapDescriptorType.MDT_UNIT);
25 for (int i = 0; i < count; i++)
26 {
27 MapItem item = m_aMapItems[i];
28 if (!item)
29 continue;
30
31 IEntity ent = item.Entity();
32 if (!ent)
33 {
34 item.Recycle();
35 count--;
36 continue;
37 }
38
40 if (contrComp && contrComp.IsDead())
41 {
42 item.SetVisible(false);
43 continue;
44 }
45
46 string name;
47 array<string> nameParams = {};
48 GetUnitName(ent, name, nameParams);
49 item.SetInfoText(name, nameParams);
50
51 FactionAffiliationComponent factionComp = FactionAffiliationComponent.Cast(ent.FindComponent(FactionAffiliationComponent));
52 if (factionComp && factionComp.GetAffiliatedFaction())
53 {
54 string factionKey = factionComp.GetAffiliatedFaction().GetFactionKey();
55 if (factionKey == "USSR")
56 item.SetFactionIndex(EFactionMapID.EAST);
57 else if (factionKey == "US")
58 item.SetFactionIndex(EFactionMapID.WEST);
59 else if (factionKey == "FIA")
60 item.SetFactionIndex(EFactionMapID.FIA);
61 else
62 item.SetFactionIndex(EFactionMapID.UNKNOWN);
63 }
64 }
65 }
66 else
67 {
68 SetPropsVisible(false);
69 }
70 }
71
72 //------------------------------------------------------------------------------------------------
75 void SetPropsVisible(bool state)
76 {
77 for (int i = 0; i < 6; i++) // TODO unhardcode layers
78 {
79 MapLayer layer = m_MapEntity.GetLayer(i);
80 if (!layer)
81 continue;
82
84 foreach (SCR_FactionColorDefaults factionDefaults : m_DefaultsCfg.m_aFactionColors)
85 {
86 props = layer.GetPropsFor(factionDefaults.m_iFaction, EMapDescriptorType.MDT_UNIT);
87 if (props)
88 {
89 props.SetVisible(state);
90 }
91 }
92 }
93 }
94
95 //------------------------------------------------------------------------------------------------
100 void GetUnitName(IEntity ent, out string name, out notnull array<string> nameParams)
101 {
102 PlayerManager playerMgr = GetGame().GetPlayerManager();
103 if (!playerMgr)
104 return;
105
106 int id = playerMgr.GetPlayerIdFromControlledEntity(ent);
107 if (id != 0)
108 {
109 name = playerMgr.GetPlayerName(id);
110 }
111 else
112 {
113 SCR_CharacterIdentityComponent scrCharIdentity = SCR_CharacterIdentityComponent.Cast(ent.FindComponent(SCR_CharacterIdentityComponent));
114 if (scrCharIdentity)
115 {
116 scrCharIdentity.GetFormattedFullName(name, nameParams);
117 }
118 else
119 {
120 CharacterIdentityComponent charIdentity = CharacterIdentityComponent.Cast(ent.FindComponent(CharacterIdentityComponent));
121 if (charIdentity)
122 name = charIdentity.GetIdentity().GetName();
123 else
124 name = "No identity";
125 }
126
127 }
128 }
129
130 //------------------------------------------------------------------------------------------------
132 protected void PanToPlayer()
133 {
135 if (!player)
136 return;
137
138 float targetScreenX, targetScreenY;
139 vector playerPos = player.GetOrigin();
140 m_MapEntity.WorldToScreen(playerPos[0], playerPos[2], targetScreenX, targetScreenY);
141 m_MapEntity.PanSmooth(targetScreenX, targetScreenY); // zoom to PPU = 1 and pan to player
142 }
143
144 //------------------------------------------------------------------------------------------------
146 protected void ZoomToPPU1()
147 {
148 m_MapEntity.ZoomSmooth(1);
149 }
150
151 //------------------------------------------------------------------------------------------------
153 protected void ZoomLayerUp()
154 {
155 int index = m_MapEntity.GetLayerIndex();
156 MapLayer layer = m_MapEntity.GetLayer(index);
157 if (layer)
158 {
159 if (layer.GetCeiling() <= m_MapEntity.GetMinZoom()) // max layer
160 return;
161
162 m_MapEntity.ZoomSmooth(layer.GetCeiling() - 0.1);
163 }
164 }
165
166 //------------------------------------------------------------------------------------------------
168 protected void ZoomLayerDown()
169 {
170 int index = m_MapEntity.GetLayerIndex();
171 if (index == 0) // min layer
172 return;
173
174 MapLayer layer = m_MapEntity.GetLayer(index-1);
175 if (layer)
176 m_MapEntity.ZoomSmooth(layer.GetCeiling());
177 }
178
179 //------------------------------------------------------------------------------------------------
181 protected void ToggleLight()
182 {
183 SCR_MapLightUI lightUI = SCR_MapLightUI.Cast(SCR_MapEntity.GetMapInstance().GetMapUIComponent(SCR_MapLightUI));
184 if (lightUI)
185 lightUI.ToggleActive();
186 }
187
188 //------------------------------------------------------------------------------------------------
190 protected void UpdateUnits()
191 {
192 IEntity ent;
193 foreach (MapItem item : m_aMapItems)
194 {
195 ent = item.Entity();
196 if (ent)
197 {
198 vector angles = ent.GetAngles();
199 item.SetAngle(angles[1] + m_fUnitIconRotation);
200 }
201 }
202 }
203
204 //------------------------------------------------------------------------------------------------
205 protected void OnRadialMenuOpen()
206 {
207 SCR_MapRadialUI radialUI = SCR_MapRadialUI.Cast(m_MapEntity.GetMapUIComponent(SCR_MapRadialUI));
208
209 bool isDebugOn = DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_UI_MAP_DEBUG_OPTIONS, false);
210 if (isDebugOn)
211 {
213 category.SetIcon(m_sIconImageset, "view-point");
214
215 SCR_SelectionMenuEntry entry = radialUI.AddRadialEntry("Map variables dbg", category);
216 entry.GetOnPerform().Insert(m_MapEntity.ShowScriptDebug);
217 entry.SetIcon(m_sIconImageset, "culvet");
218
219 entry = radialUI.AddRadialEntry("Zoom to 1px == 1m", category);
220 entry.GetOnPerform().Insert(ZoomToPPU1);
221 entry.SetIcon(m_sIconImageset, "single-tree");
222
223 entry = radialUI.AddRadialEntry("Zoom up a layer", category);
224 entry.GetOnPerform().Insert(ZoomLayerUp);
225 entry.SetIcon(m_sIconImageset, "ancient-fortification");
226
227 entry = radialUI.AddRadialEntry("Zoom down a layer", category);
228 entry.GetOnPerform().Insert(ZoomLayerDown);
229 entry.SetIcon(m_sIconImageset, "hospital");
230
231 entry = radialUI.AddRadialEntry("Pan to player", category);
232 entry.GetOnPerform().Insert(PanToPlayer);
233 entry.SetIcon(m_sIconImageset, "hill-marker");
234
235 entry = radialUI.AddRadialEntry("Show units", category);
236 entry.GetOnPerform().Insert(ShowUnits);
237 entry.SetIcon(m_sIconImageset, "crane");
238
239 entry = radialUI.AddRadialEntry("Toggle Light", category);
240 entry.GetOnPerform().Insert(ToggleLight);
241 entry.SetIcon(m_sIconImageset, "smoke-stack");
242 }
243 }
244
245 //------------------------------------------------------------------------------------------------
246 override void Update(float timeSlice)
247 {
249 UpdateUnits();
250 }
251
252 //------------------------------------------------------------------------------------------------
253 override void OnMapOpen(MapConfiguration config)
254 {
255 super.OnMapOpen(config);
256 m_DefaultsCfg = config.DescriptorDefsConfig;
257
259 {
260 m_bIsUnitVisible = false;
261 ShowUnits();
262 }
263 }
264
265 //------------------------------------------------------------------------------------------------
266 override void Init()
267 {
268 SCR_MapRadialUI radialMenu = SCR_MapRadialUI.Cast(m_MapEntity.GetMapUIComponent(SCR_MapRadialUI));
269 if (radialMenu)
270 radialMenu.GetOnMenuInitInvoker().Insert(OnRadialMenuOpen);
271 }
272}
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
ArmaReforgerScripted GetGame()
Definition game.c:1398
LayerPresets layer
ref array< string > angles
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Diagnostic and developer menu system.
Definition DiagMenu.c:18
proto external Managed FindComponent(typename typeName)
proto external vector GetAngles()
Same as GetYawPitchRoll(), but returns rotation vector around X, Y and Z axis.
proto external vector GetOrigin()
Configuration of descriptor defaults.
ref array< MapItem > m_aMapItems
override void OnMapOpen(MapConfiguration config)
SCR_MapDescriptorDefaults m_DefaultsCfg
void ShowUnits()
Show infantry units.
void PanToPlayer()
Context callback.
void ToggleLight()
Toggle map light.
float m_fUnitIconRotation
void ZoomLayerUp()
Zooms to the beginning of higher layer.
override void Update(float timeSlice)
void GetUnitName(IEntity ent, out string name, out notnull array< string > nameParams)
override void Init()
void ZoomToPPU1()
Zooms to current pixel per unit ratio == 1.
void SetPropsVisible(bool state)
ResourceName m_sIconImageset
void UpdateUnits()
Update unit map items.
void ZoomLayerDown()
Zooms to the ceiling of lower layer.
Config for default values set per descriptor type.
SCR_MapUIBaseComponent GetMapUIComponent(typename componentType)
static SCR_MapEntity GetMapInstance()
Get map entity instance.
2D map radial menu UI
ScriptInvokerVoid GetOnMenuInitInvoker()
SCR_SelectionMenuEntry AddRadialEntry(string name, SCR_SelectionMenuCategoryEntry category=null)
SCR_SelectionMenuCategoryEntry AddRadialCategory(string name, SCR_SelectionMenuCategoryEntry parent=null)
static IEntity GetLocalControlledEntity()
ScriptInvoker GetOnPerform()
void SetIcon(ResourceName iconPath, string imageSetName="")
Set icon and invoke change.
SCR_FieldOfViewSettings Attribute
EMapDescriptorType