Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_EditableEntitySceneSlotUIComponent.c
Go to the documentation of this file.
2 {
3  [Attribute(defvalue: "0")]
4  protected float m_fOffScreenPadding;
5 
6  [Attribute(uiwidget: UIWidgets.ResourceNamePicker, params: "layout")]
7  protected ResourceName m_OffScreenPrefab;
8 
9  protected WorkspaceWidget m_Workspace;
10  protected BaseWorld m_World;
11  protected bool m_bShowOffScreen = false;
12  protected bool m_bIsOffScreen;
13  protected vector m_vCornersPadding[4];
14  protected ImageWidget m_OffScreenWidget;
15  protected bool m_bIsPreview;
16 
17  //------------------------------------------------------------------------------------------------
19  void UpdateShowOffScreen()
20  {
21  bool showOffScreen = false;
22  foreach (SCR_BaseEditableEntityUIComponent component: m_EntityWidgets)
23  {
24  showOffScreen |= component.IsShownOffScreen();
25  }
26 
27  if (showOffScreen != m_bShowOffScreen)
28  {
29  if (showOffScreen)
30  {
31  m_OffScreenWidget = ImageWidget.Cast(m_Workspace.CreateWidgets(m_OffScreenPrefab, m_Widget));
32  if (m_OffScreenWidget)
33  {
34  FrameSlot.SetPos(m_OffScreenWidget, m_fOffScreenPadding * 0.5, m_fOffScreenPadding * 0.5);
35  FrameSlot.SetSize(m_OffScreenWidget, m_fOffScreenPadding * 2, m_fOffScreenPadding * 2);
36  FrameSlot.SetAlignment(m_OffScreenWidget, 0.5, 0.5);
37  m_OffScreenWidget.SetVisible(false);
38  }
39  }
40  else
41  {
42  if (m_OffScreenWidget)
43  {
44  m_OffScreenWidget.RemoveFromHierarchy();
45  m_OffScreenWidget = null;
46  }
47  }
48  }
49 
50  m_bShowOffScreen = showOffScreen;
51  }
52 
53  //------------------------------------------------------------------------------------------------
56  bool IsShownOffScreen()
57  {
58  return m_bShowOffScreen;
59  }
60 
61  //------------------------------------------------------------------------------------------------
64  void SetOffScreenPadding(float padding)
65  {
66  m_fOffScreenPadding = padding;
67  m_vCornersPadding = {
68  Vector(0, m_fOffScreenPadding, 0), //--- A1
69  Vector(1, m_fOffScreenPadding, 0), //--- A2
70  Vector(m_fOffScreenPadding, 0, 0), //--- B1
71  Vector(m_fOffScreenPadding, 1, 0) //--- B2
72  };
73 
74  if (m_OffScreenWidget)
75  FrameSlot.SetSize(m_OffScreenWidget, m_fOffScreenPadding * 2, m_fOffScreenPadding * 2);
76  }
77 
78  //------------------------------------------------------------------------------------------------
81  float GetOffScreenPadding()
82  {
83  return m_fOffScreenPadding;
84  }
85 
86  //------------------------------------------------------------------------------------------------
88  Widget GetOffScreenWidget()
89  {
90  return m_OffScreenWidget;
91  }
92 
93  //------------------------------------------------------------------------------------------------
94  override bool IsPreview()
95  {
96  return m_bIsPreview;
97  }
98 
99  //------------------------------------------------------------------------------------------------
105  vector GetIntersectionPoint(vector A1, vector A2, vector B1, vector B2)
106  {
107  float tmp = (B2[0] - B1[0]) * (A2[1] - A1[1]) - (B2[1] - B1[1]) * (A2[0] - A1[0]);
108  if (tmp == 0)
109  return vector.Zero;
110 
111  float mu = ((A1[0] - B1[0]) * (A2[1] - A1[1]) - (A1[1] - B1[1]) * (A2[0] - A1[0])) / tmp;
112  return {
113  B1[0] + (B2[0] - B1[0]) * mu,
114  B1[1] + (B2[1] - B1[1]) * mu,
115  0
116  };
117  }
118 
119  //------------------------------------------------------------------------------------------------
126  vector ShowOffScreen(vector pos, int screenW, int screenH, vector posCenter)
127  {
128  bool isOffScreenPrev = m_bIsOffScreen;
129  float screenWPadded = screenW - m_fOffScreenPadding;
130  float screenHPadded = screenH - m_fOffScreenPadding;
131  m_bIsOffScreen = pos[2] < 0 || pos[0] < m_fOffScreenPadding || pos[1] < m_fOffScreenPadding || pos[0] > screenWPadded || pos[1] > screenHPadded;
132  if (m_bIsOffScreen)
133  {
134  float intersect = GetIntersectionPoint(posCenter, pos, m_vCornersPadding[0], m_vCornersPadding[1])[0];
135  if (intersect > m_fOffScreenPadding && intersect < screenWPadded)
136  {
137  if (pos[1] < posCenter[1])
138  {
139  pos = { intersect, m_fOffScreenPadding, 0 }; //--- Top
140  if (m_OffScreenWidget)
141  m_OffScreenWidget.SetRotation(0);
142  }
143  else
144  {
145  pos = { screenW - intersect, screenHPadded, 0 }; //--- Bottom
146  if (m_OffScreenWidget)
147  m_OffScreenWidget.SetRotation(180);
148  }
149  }
150  else
151  {
152  intersect = GetIntersectionPoint(posCenter, pos, m_vCornersPadding[2], m_vCornersPadding[3])[1];
153  if (pos[0] < posCenter[0])
154  {
155  pos = { m_fOffScreenPadding, intersect, 0 }; //--- Left
156  if (m_OffScreenWidget)
157  m_OffScreenWidget.SetRotation(270);
158  }
159  else
160  {
161  pos = { screenWPadded, screenH - intersect, 0 }; //--- Right
162  if (m_OffScreenWidget)
163  m_OffScreenWidget.SetRotation(90);
164  }
165  }
166 
167  m_bIsOffScreen = true;
168  }
169 
170  //--- When off-screen presence changed, execute event in all slot widgets
171  if (m_bIsOffScreen != isOffScreenPrev)
172  {
173  foreach (SCR_BaseEditableEntityUIComponent widgetComponent: m_EntityWidgets)
174  {
175  widgetComponent.OnShownOffScreen(m_bIsOffScreen);
176  }
177 
178  if (m_OffScreenWidget)
179  m_OffScreenWidget.SetVisible(m_bIsOffScreen);
180  }
181 
182  FrameSlot.SetPos(m_Widget, pos[0], pos[1]);
183  m_Widget.SetVisible(true);
184  return pos;
185  }
186 
187  //------------------------------------------------------------------------------------------------
188  override vector UpdateSlot(int screenW, int screenH, vector posCenter, vector posCam)
189  {
190  if (m_Entity)
191  {
192  vector posWorld;
193  if (m_Entity.GetPos(posWorld))
194  {
195  vector posScreen = m_Workspace.ProjWorldToScreen(posWorld, m_World);
196 
197  if (m_bShowOffScreen)
198  {
199  //--- Show on screen border when off-screen
200  return ShowOffScreen(posScreen, screenW, screenH, posCenter);
201  }
202  else
203  {
204  //--- On-screen only
205  if (posScreen[2] > 0)
206  {
207  FrameSlot.SetPos(m_Widget, posScreen[0], posScreen[1]);
208  m_Widget.SetZOrder(-vector.Distance(posWorld, posCam)); //--- Don't use DistanceSq, can overflow int
209  m_Widget.SetVisible(true);
210  return posScreen;
211  }
212  }
213  }
214  }
215 
216  m_Widget.SetVisible(false);
217  return vector.Zero;
218  }
219 
220  //------------------------------------------------------------------------------------------------
221  override Widget CreateWidgetForEntity(SCR_EditableEntityComponent entity, SCR_EntitiesEditorUIRule rule, ResourceName layout)
222  {
223  Widget widget = super.CreateWidgetForEntity(entity, rule, layout);
224  UpdateShowOffScreen();
225  return widget;
226  }
227 
228  //------------------------------------------------------------------------------------------------
229  override void DeleteWidget(SCR_EntitiesEditorUIRule rule)
230  {
231  super.DeleteWidget(rule);
232  UpdateShowOffScreen();
233  }
234 
235  //------------------------------------------------------------------------------------------------
236  override void InitSlot(SCR_EditableEntityComponent entity)
237  {
238  m_Workspace = GetGame().GetWorkspace();
239  m_World = entity.GetOwner().GetWorld();
240  m_bIsPreview = entity.HasEntityState(EEditableEntityState.PREVIEW);
241  SetOffScreenPadding(m_fOffScreenPadding);
242 
243  super.InitSlot(entity);
244  }
245 }
EEditableEntityState
EEditableEntityState
Definition: EEditableEntityState.c:37
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_EntitiesEditorUIRule
Definition: SCR_EditableEntityUIRule.c:8
SCR_EditableEntityBaseSlotUIComponent
Definition: SCR_EditableEntityBaseSlotUIComponent.c:6
m_Entity
enum EAITargetInfoCategory m_Entity
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_EditableEntitySceneSlotUIComponent
Definition: SCR_EditableEntitySceneSlotUIComponent.c:1
m_Workspace
protected WorkspaceWidget m_Workspace
Definition: SCR_EntitiesEditorUIComponent.c:13
m_World
protected BaseWorld m_World
Definition: SCR_PreviewEntityEditorUIComponent.c:46
SCR_BaseEditableEntityUIComponent
Definition: SCR_BaseEditableEntityUIComponent.c:8
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
layout
UI layouts HUD CampaignMP CampaignMainHUD layout
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:20
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24