Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MapRTWBaseUI.c
Go to the documentation of this file.
2 class ToolSize
3 {
4  [Attribute("", UIWidgets.EditBox, desc: "X size")]
5  int m_iSizeX;
6 
7  [Attribute("", UIWidgets.EditBox, desc: "Y size")]
8  int m_iSizeY;
9 }
10 
13 {
14  [Attribute("", UIWidgets.Object, desc: "Array of x*y sizes in unscaled pix")]
15  protected ref array<ref ToolSize> m_aSizesArray;
16 
17  protected static const string BASE_WORLD_TYPE = "ChimeraWorld";
18  protected static const float CAMERA_VERTICAL_FOV = 43;
19 
20  // configuration
21  protected string WIDGET_NAME;
22  protected string RT_WIDGET_NAME;
23  protected string WORLD_RESOURCE = "{88ABCDC0EEC969DF}Prefabs/World/PreviewWorld/MapCompassWorld.et";
24  protected string WORLD_NAME;
25  protected vector m_vPrefabPos;
26  protected vector m_vCameraPos;
27  protected vector m_vCameraAngle;
28 
29  protected bool m_bIsVisible; // visibility flag
30  protected bool m_bWantedVisible; // holds wanted visibility state after close
31  protected bool m_bIsDragged = false; // widget is being dragged
32  protected int m_iCurrentSizeIndex; // current id of m_SizesArray
33  protected int m_iSizesCount; // count of m_SizesArray
34  protected float m_fPosX, m_fPosY; // widget position
35 
36  protected EGadgetType m_eGadgetType;
38  protected ref SharedItemRef m_RTWorld;
39  protected SCR_MapToolEntry m_ToolMenuEntry; // tool menu entry
40 
41  // Widgets
42  protected Widget m_wFrame; // parent frame
43  protected RenderTargetWidget m_wRenderTarget; // RenderTargetWidget
44 
45  //------------------------------------------------------------------------------------------------
47  protected void SetWidgetNames()
48  {
49  WIDGET_NAME = "";
50  RT_WIDGET_NAME = "";
51  WORLD_NAME = "MapUIWorld";
52  }
53 
54  //------------------------------------------------------------------------------------------------
56  protected void InitPositionVectors()
57  {
58  m_vPrefabPos = "0 0 0";
59  m_vCameraPos = "0 0.3 0";
60  m_vCameraAngle = "0 -90 0";
61  }
62 
63  //------------------------------------------------------------------------------------------------
66  protected string GetPrefabResource()
67  {
68  return string.Empty;
69  }
70 
71  //------------------------------------------------------------------------------------------------
75  {
76  IEntity gadget;
77 
78  SCR_GadgetManagerComponent gadgetManager = SCR_GadgetManagerComponent.GetGadgetManager(SCR_PlayerController.GetLocalControlledEntity());
79  if (gadgetManager)
80  gadget = gadgetManager.GetGadgetByType(m_eGadgetType);
81 
82  return gadget;
83  }
84 
85  //------------------------------------------------------------------------------------------------
87  protected void ToggleVisible()
88  {
89  if (!m_bIsVisible)
90  SetVisible(true);
91  else
92  {
93  SetVisible(false);
94  }
95  }
96 
97  //------------------------------------------------------------------------------------------------
100  protected void SetVisible(bool visible)
101  {
102  if (!m_wFrame)
103  return;
104 
105  if (visible)
106  {
107  // RTW preview world
108  if (!SetupRTWorld())
109  return;
110 
111  if (!SpawnPrefab())
112  return;
113 
114  m_bIsVisible = true;
115  m_wFrame.SetEnabled(true);
116  ScriptCallQueue queue = GetGame().GetCallqueue();
117  if (queue)
118  queue.CallLater(SetFrameVisible, 0, 0); // delayed by frame so the positioning can be initialised
119 
120  FrameSlot.SetPos(m_wFrame, m_fPosX, m_fPosY);
121  }
122  else
123  {
124  m_bIsVisible = false;
125  m_wFrame.SetEnabled(false);
126  m_wFrame.SetVisible(false);
127 
128  delete m_RTEntity; // proc anims do not work without this not being refreshed atm
129  }
130 
131  if (m_ToolMenuEntry)
132  m_ToolMenuEntry.SetActive(visible);
133  }
134 
135  //------------------------------------------------------------------------------------------------
138  {
139  m_wFrame.SetVisible(true);
140  }
141 
142  //------------------------------------------------------------------------------------------------
145  protected bool SetupRTWorld()
146  {
147  // create new empty base world
148  if (!m_RTWorld || !m_RTWorld.IsValid())
149  {
150  m_RTWorld = BaseWorld.CreateWorld(BASE_WORLD_TYPE, WORLD_NAME);
151  if (!m_RTWorld)
152  return false;
153  World previewRTWorld = m_RTWorld.GetRef();
154  previewRTWorld.ReloadSystems();
155  }
156 
157  BaseWorld previewWorld = m_RTWorld.GetRef();
158  if (!previewWorld)
159  return false;
160 
161  m_wRenderTarget.SetWorld( previewWorld, 0 );
162 
163  // spawn preview GenericWorldEntity
164  Resource rsc = Resource.Load(WORLD_RESOURCE);
165  if (rsc.IsValid())
166  GetGame().SpawnEntityPrefabLocal(rsc, previewWorld);
167 
168  // default cam settings
169  previewWorld.SetCameraType(0, CameraType.PERSPECTIVE);
170  previewWorld.SetCameraNearPlane(0, 0.001);
171  previewWorld.SetCameraFarPlane(0, 50);
172  previewWorld.SetCameraVerticalFOV(0, CAMERA_VERTICAL_FOV);
173 
174  return true;
175  }
176 
177  //------------------------------------------------------------------------------------------------
180  protected bool SpawnPrefab()
181  {
182  string rscStr = GetPrefabResource();
183  if (rscStr == string.Empty)
184  return false;
185 
186  Resource rscItem = Resource.Load(rscStr);
187  if (rscItem.IsValid())
188  {
189  BaseWorld world = m_RTWorld.GetRef();
190  if (!world)
191  return false;
192 
193  if (!m_RTEntity)
194  {
195  m_RTEntity = GenericEntity.Cast( GetGame().SpawnEntityPrefabLocal(rscItem, world) );
196  if (!m_RTEntity)
197  return false;
198 
200 
201  m_RTEntity.SetOrigin(m_vPrefabPos);
202  m_RTEntity.SetFixedLOD(0);
203 
204  BaseWorld previewWorld = m_RTWorld.GetRef();
205  if (!previewWorld)
206  return false;
207 
208  previewWorld.SetCamera(0, m_vCameraPos, m_vCameraAngle);
209 
210  SetSize();
211  }
212  }
213 
214  return true;
215  }
216 
217  //------------------------------------------------------------------------------------------------
220  protected void SetSize(bool nextSize = false)
221  {
222  if (nextSize)
223  {
226  else
227  m_iCurrentSizeIndex = 0;
228  }
229 
230  FrameSlot.SetSize(m_wFrame, m_aSizesArray[m_iCurrentSizeIndex].m_iSizeX, m_aSizesArray[m_iCurrentSizeIndex].m_iSizeY);
231  }
232 
233  //------------------------------------------------------------------------------------------------
236  protected void OnDragWidget(Widget widget)
237  {
238  if (widget == m_wFrame)
239  m_bIsDragged = true;
240  else
241  m_bIsDragged = false;
242  }
243 
244  //------------------------------------------------------------------------------------------------
246  protected void OnActivateTool(Widget widget)
247  {
248  if (widget != m_wFrame)
249  return;
250 
251  SetSize(true);
252  }
253 
254  //------------------------------------------------------------------------------------------------
255  // OVERRIDES
256  //------------------------------------------------------------------------------------------------
257 
258  //------------------------------------------------------------------------------------------------
259  override void OnMapOpen(MapConfiguration config)
260  {
261  super.OnMapOpen(config);
262 
263  SetWidgetNames();
264 
265  // refresh widgets
266  m_wFrame = m_RootWidget.FindAnyWidget(WIDGET_NAME);
267  m_wRenderTarget = RenderTargetWidget.Cast(m_RootWidget.FindAnyWidget(RT_WIDGET_NAME));
268  m_iSizesCount = m_aSizesArray.Count();
269 
270  if ( SCR_MapToolInteractionUI.Cast(m_MapEntity.GetMapUIComponent(SCR_MapToolInteractionUI)) ) // if dragging available, add callback
271  {
272  SCR_MapToolInteractionUI.GetOnDragWidgetInvoker().Insert(OnDragWidget);
273  SCR_MapToolInteractionUI.GetOnActivateToolInvoker().Insert(OnActivateTool);
274  }
275 
276  SetVisible(m_bWantedVisible); // restore last visible state
277 
278  if (m_ToolMenuEntry)
279  {
280  if (FindRelatedGadget())
281  m_ToolMenuEntry.SetEnabled(true);
282  else
283  m_ToolMenuEntry.SetEnabled(false);
284  }
285  }
286 
287  //------------------------------------------------------------------------------------------------
288  override void OnMapClose(MapConfiguration config)
289  {
290  m_bWantedVisible = m_bIsVisible; // visibility state
291  SetVisible(false);
292 
293  delete m_RTEntity;
294 
295  super.OnMapClose(config);
296  }
297 
298  //------------------------------------------------------------------------------------------------
299  // constructor
301  {
302  m_bHookToRoot = true;
303  }
304 }
ToggleVisible
protected void ToggleVisible()
Visibility toggle.
Definition: SCR_MapRTWBaseUI.c:87
m_MapEntity
protected SCR_MapEntity m_MapEntity
Definition: SCR_MapGadgetComponent.c:14
m_RootWidget
protected Widget m_RootWidget
Definition: SCR_BinocularsComponent.c:10
SetVisible
protected void SetVisible(bool visible)
Definition: SCR_MapRTWBaseUI.c:100
OnDragWidget
protected void OnDragWidget(Widget widget)
Definition: SCR_MapRTWBaseUI.c:236
SCR_PlayerController
Definition: SCR_PlayerController.c:31
OnActivateTool
protected void OnActivateTool(Widget widget)
SCR_MapToolInteractionUI event.
Definition: SCR_MapRTWBaseUI.c:246
WIDGET_NAME
protected string WIDGET_NAME
Definition: SCR_MapRTWBaseUI.c:21
SCR_MapRTWBaseUI
void SCR_MapRTWBaseUI()
Definition: SCR_MapRTWBaseUI.c:300
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SpawnPrefab
protected bool SpawnPrefab()
Definition: SCR_MapRTWBaseUI.c:180
InitPositionVectors
protected void InitPositionVectors()
Initialise RT camera and prefab positon.
Definition: SCR_MapRTWBaseUI.c:56
SCR_GadgetManagerComponent
Definition: SCR_GadgetManagerComponent.c:138
FindRelatedGadget
IEntity FindRelatedGadget()
Definition: SCR_MapRTWBaseUI.c:74
GetPrefabResource
protected string GetPrefabResource()
Definition: SCR_MapRTWBaseUI.c:66
OnMapClose
override void OnMapClose(MapConfiguration config)
Definition: SCR_MapRTWBaseUI.c:288
OnMapOpen
override void OnMapOpen(MapConfiguration config)
Definition: SCR_MapRTWBaseUI.c:259
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_iSizesCount
protected int m_iSizesCount
Definition: SCR_MapRTWBaseUI.c:33
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
SCR_MapToolEntry
Map tool menu entry data class.
Definition: SCR_MapToolMenuUI.c:2
m_fPosX
protected float m_fPosX
Definition: SCR_MapRTWBaseUI.c:34
m_vCameraPos
protected vector m_vCameraPos
Definition: SCR_MapRTWBaseUI.c:26
SetSize
protected void SetSize(bool nextSize=false)
Definition: SCR_MapRTWBaseUI.c:220
m_RTWorld
protected ref SharedItemRef m_RTWorld
Definition: SCR_MapRTWBaseUI.c:38
m_iSizeY
int m_iSizeY
Definition: SCR_MapRTWBaseUI.c:6
SetupRTWorld
protected bool SetupRTWorld()
Definition: SCR_MapRTWBaseUI.c:145
SetFrameVisible
void SetFrameVisible()
TODO Frame is now set through script here instead of directly in callqueue to avoid leak.
Definition: SCR_MapRTWBaseUI.c:137
m_bIsDragged
protected bool m_bIsDragged
Definition: SCR_MapRTWBaseUI.c:31
RT_WIDGET_NAME
protected string RT_WIDGET_NAME
Definition: SCR_MapRTWBaseUI.c:22
m_vPrefabPos
protected vector m_vPrefabPos
Definition: SCR_MapRTWBaseUI.c:25
m_ToolMenuEntry
protected SCR_MapToolEntry m_ToolMenuEntry
Definition: SCR_MapRTWBaseUI.c:39
m_RTEntity
protected GenericEntity m_RTEntity
Definition: SCR_MapRTWBaseUI.c:37
m_wRenderTarget
protected RenderTargetWidget m_wRenderTarget
Definition: SCR_MapRTWBaseUI.c:43
SetWidgetNames
protected void SetWidgetNames()
Set widget names.
Definition: SCR_MapRTWBaseUI.c:47
m_bWantedVisible
protected bool m_bWantedVisible
Definition: SCR_MapRTWBaseUI.c:30
m_vCameraAngle
protected vector m_vCameraAngle
Definition: SCR_MapRTWBaseUI.c:27
m_iSizeX
int m_iSizeX
Definition: SCR_MapRTWBaseUI.c:3
WORLD_NAME
protected string WORLD_NAME
Definition: SCR_MapRTWBaseUI.c:24
WORLD_RESOURCE
protected string WORLD_RESOURCE
Definition: SCR_MapRTWBaseUI.c:23
Attribute
class ToolSize Attribute("", UIWidgets.Object, desc:"Array of x*y sizes in unscaled pix")] protected ref array< ref ToolSize > m_aSizesArray
Base map UI component for map tools which are using RenderTargetWidget to display.
m_bIsVisible
protected bool m_bIsVisible
Definition: SCR_MapRTWBaseUI.c:29
m_fPosY
protected float m_fPosY
Definition: SCR_MapRTWBaseUI.c:34
ToolSize
Definition: SCR_MapRTWBaseUI.c:2
SCR_MapUIBaseComponent
Definition: SCR_MapUIBaseComponent.c:3
m_eGadgetType
protected EGadgetType m_eGadgetType
Definition: SCR_MapRTWBaseUI.c:36
m_wFrame
protected Widget m_wFrame
Definition: SCR_MapRTWBaseUI.c:42
m_iCurrentSizeIndex
protected int m_iCurrentSizeIndex
Definition: SCR_MapRTWBaseUI.c:32
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