4 protected float m_fOffScreenPadding;
7 protected ResourceName m_OffScreenPrefab;
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;
19 void UpdateShowOffScreen()
21 bool showOffScreen =
false;
24 showOffScreen |= component.IsShownOffScreen();
27 if (showOffScreen != m_bShowOffScreen)
31 m_OffScreenWidget = ImageWidget.Cast(
m_Workspace.CreateWidgets(m_OffScreenPrefab, m_Widget));
32 if (m_OffScreenWidget)
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);
42 if (m_OffScreenWidget)
44 m_OffScreenWidget.RemoveFromHierarchy();
45 m_OffScreenWidget =
null;
50 m_bShowOffScreen = showOffScreen;
56 bool IsShownOffScreen()
58 return m_bShowOffScreen;
64 void SetOffScreenPadding(
float padding)
66 m_fOffScreenPadding = padding;
68 Vector(0, m_fOffScreenPadding, 0),
69 Vector(1, m_fOffScreenPadding, 0),
70 Vector(m_fOffScreenPadding, 0, 0),
71 Vector(m_fOffScreenPadding, 1, 0)
74 if (m_OffScreenWidget)
75 FrameSlot.SetSize(m_OffScreenWidget, m_fOffScreenPadding * 2, m_fOffScreenPadding * 2);
81 float GetOffScreenPadding()
83 return m_fOffScreenPadding;
88 Widget GetOffScreenWidget()
90 return m_OffScreenWidget;
94 override bool IsPreview()
105 vector GetIntersectionPoint(vector A1, vector A2, vector B1, vector B2)
107 float tmp = (B2[0] - B1[0]) * (A2[1] - A1[1]) - (B2[1] - B1[1]) * (A2[0] - A1[0]);
111 float mu = ((A1[0] - B1[0]) * (A2[1] - A1[1]) - (A1[1] - B1[1]) * (A2[0] - A1[0])) / tmp;
113 B1[0] + (B2[0] - B1[0]) * mu,
114 B1[1] + (B2[1] - B1[1]) * mu,
126 vector ShowOffScreen(vector pos,
int screenW,
int screenH, vector posCenter)
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;
134 float intersect = GetIntersectionPoint(posCenter, pos, m_vCornersPadding[0], m_vCornersPadding[1])[0];
135 if (intersect > m_fOffScreenPadding && intersect < screenWPadded)
137 if (pos[1] < posCenter[1])
139 pos = { intersect, m_fOffScreenPadding, 0 };
140 if (m_OffScreenWidget)
141 m_OffScreenWidget.SetRotation(0);
145 pos = { screenW - intersect, screenHPadded, 0 };
146 if (m_OffScreenWidget)
147 m_OffScreenWidget.SetRotation(180);
152 intersect = GetIntersectionPoint(posCenter, pos, m_vCornersPadding[2], m_vCornersPadding[3])[1];
153 if (pos[0] < posCenter[0])
155 pos = { m_fOffScreenPadding, intersect, 0 };
156 if (m_OffScreenWidget)
157 m_OffScreenWidget.SetRotation(270);
161 pos = { screenWPadded, screenH - intersect, 0 };
162 if (m_OffScreenWidget)
163 m_OffScreenWidget.SetRotation(90);
167 m_bIsOffScreen =
true;
171 if (m_bIsOffScreen != isOffScreenPrev)
175 widgetComponent.OnShownOffScreen(m_bIsOffScreen);
178 if (m_OffScreenWidget)
179 m_OffScreenWidget.SetVisible(m_bIsOffScreen);
182 FrameSlot.SetPos(m_Widget, pos[0], pos[1]);
183 m_Widget.SetVisible(
true);
188 override vector UpdateSlot(
int screenW,
int screenH, vector posCenter, vector posCam)
197 if (m_bShowOffScreen)
200 return ShowOffScreen(posScreen, screenW, screenH, posCenter);
205 if (posScreen[2] > 0)
207 FrameSlot.SetPos(m_Widget, posScreen[0], posScreen[1]);
208 m_Widget.SetZOrder(-vector.Distance(posWorld, posCam));
209 m_Widget.SetVisible(
true);
216 m_Widget.SetVisible(
false);
223 Widget widget = super.CreateWidgetForEntity(entity, rule,
layout);
224 UpdateShowOffScreen();
231 super.DeleteWidget(rule);
232 UpdateShowOffScreen();
239 m_World = entity.GetOwner().GetWorld();
241 SetOffScreenPadding(m_fOffScreenPadding);
243 super.InitSlot(entity);