Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
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")]
7  protected ResourceName m_sIconImageset;
8 
9  protected bool m_bIsUnitVisible; // units debug visible
10  protected ref array<MapItem> m_aMapItems = {}; // cached map items
11 
12  protected SCR_MapDescriptorDefaults m_DefaultsCfg;
13 
14  //------------------------------------------------------------------------------------------------
16  protected void ShowUnits()
17  {
18  m_bIsUnitVisible = !m_bIsUnitVisible;
19 
20  if (m_bIsUnitVisible)
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 
83  MapDescriptorProps props;
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  {
134  IEntity player = SCR_PlayerController.GetLocalControlledEntity();
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  {
212  SCR_SelectionMenuCategoryEntry category = radialUI.AddRadialCategory("Debug Options");
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  {
248  if (m_bIsUnitVisible)
249  UpdateUnits();
250  }
251 
252  //------------------------------------------------------------------------------------------------
253  override void OnMapOpen(MapConfiguration config)
254  {
255  super.OnMapOpen(config);
256  m_DefaultsCfg = config.DescriptorDefsConfig;
257 
258  if (m_bIsUnitVisible)
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 }
m_MapEntity
protected SCR_MapEntity m_MapEntity
Definition: SCR_MapGadgetComponent.c:14
SCR_MapDebugUI
Definition: SCR_MapDebugUI.c:1
SCR_PlayerController
Definition: SCR_PlayerController.c:31
SCR_SelectionMenuCategoryEntry
Definition: SCR_SelectionMenuCategory.c:6
SCR_MapDescriptorDefaults
Config for default values set per descriptor type.
Definition: SCR_MapDescriptorDefaults.c:4
SCR_MapRadialUI
2D map radial menu UI
Definition: SCR_MapRadialUI.c:13
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_CharacterControllerComponent
Definition: SCR_CharacterControllerComponent.c:35
SCR_FactionColorDefaults
Configuration of descriptor defaults.
Definition: SCR_MapDescriptorDefaults.c:28
MapDescriptorProps
Definition: MapDescriptorProps.c:12
Attribute
typedef Attribute
Post-process effect of scripted camera.
MapItem
Definition: MapItem.c:12
SCR_MapEntity
Map entity.
Definition: SCR_MapEntity.c:20
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
EMapDescriptorType
EMapDescriptorType
Definition: EMapDescriptorType.c:15
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_SelectionMenuEntry
Definition: SCR_SelectionMenuEntry.c:7
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3
SCR_MapUIBaseComponent
Definition: SCR_MapUIBaseComponent.c:3
PlayerManager
Definition: PlayerManager.c:12
MapLayer
Definition: MapLayer.c:12
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180