5 protected static const float INERTIA_THRESHOLD = 0.001;
8 protected ref array<ref SCR_TooltipEditorEntry> m_Tooltips;
10 [
Attribute(defvalue:
"0.1",
desc:
"How long (s) it will take before the tooltips appear.")]
11 protected float m_fDelay;
13 [
Attribute(defvalue:
"10",
desc:
"How fast is the fade-in effect")]
14 protected float m_fFadeInSpeed;
16 [
Attribute(defvalue:
"0.03",
desc:
"Inertia strength. Larger values mean more inertia.")]
17 private float m_fInertiaStrength;
19 [
Attribute(
"1",
desc:
"When enabled, changes in entity hover state will refresh tooltips.")]
20 protected bool m_bTrackHoverState;
22 protected InputManager m_InputManager;
29 protected Managed m_InfoInstance;
30 protected bool m_bTooltipShown;
42 if (info && info ==
m_Info)
48 foreach (SCR_TooltipEditorEntry tooltipEntry:
m_Tooltips)
50 if (tooltipEntry.GetTooltipType() ==
type)
52 ResourceName
layout = tooltipEntry.GetTooltipLayout();
56 FrameSlot.SetOffsets(tooltipWidget, 0, 0, 0, 0);
57 FrameSlot.SetSizeToContent(tooltipWidget,
true);
65 GetGame().GetCallqueue().CallLater(PlayAnimation,
m_fDelay * 1000,
false);
69 tooltipWidget.RemoveFromHierarchy();
75 Print(
string.Format(
"SCR_BaseTooltipEditorUIComponent not found in tooltip '%1'",
layout), LogLevel.WARNING);
81 Print(
string.Format(
"Layout for tooltip of type '%1' not defined!",
typename.EnumToString(
EEditorTooltip,
type)), LogLevel.WARNING);
101 if (info && info !=
m_Info)
106 m_Tooltip.GetWidget().RemoveFromHierarchy();
108 GetGame().GetCallqueue().Remove(PlayAnimation);
122 if (m_InfoInstance && instance == m_InfoInstance)
123 SetInfo(info,
type, instance)
127 protected void PlayAnimation()
136 protected void ResetAnimation()
138 AnimateWidget.StopAnimation(
m_TooltipArea.GetWidget(), WidgetAnimationOpacity);
157 protected void OnHover(
EEditableEntityState state, set<SCR_EditableEntityComponent> entitiesInsert, set<SCR_EditableEntityComponent> entitiesRemove)
166 if (entitiesRemove && !entitiesRemove.IsEmpty())
170 if (entitiesInsert && !entitiesInsert.IsEmpty())
172 ShowEntityTooltip(entitiesInsert[0]);
177 protected void OnInputDeviceIsGamepad(
bool isGamepad)
191 protected void OnRadialMenuToggle(IEntity owner,
bool isOpened)
203 ShowEntityTooltip(hoverFilter.GetFirstEntity());
208 protected void OnContextMenuToggle(
bool isOpened)
216 protected void OnMenuUpdate(
float tDelta)
227 WorkspaceWidget workspace = widget.GetWorkspace();
230 int offsetTop, offsetRight, offsetBottom, offsetLeft;
231 int screenW = workspace.GetWidth();
232 int screenH = workspace.GetHeight();
233 screenW = workspace.DPIUnscale(screenW);
234 screenH = workspace.DPIUnscale(screenH);
236 m_TooltipArea.GetOffsets(offsetTop, offsetRight, offsetBottom, offsetLeft);
240 vector cursorPos =
m_Cursor.GetCursorPos();
247 WidgetManager.GetMousePos(mouseX, mouseY);
248 posX = workspace.DPIUnscale(mouseX);
249 posY = workspace.DPIUnscale(mouseY);
252 float tooltipX, tooltipY, tooltipW, tooltipH;
255 vector tooltipPos = FrameSlot.GetPos(widget);
256 tooltipX = tooltipPos[0];
257 tooltipY = tooltipPos[1];
260 widget.GetScreenSize(tooltipW, tooltipH);
261 tooltipW = workspace.DPIUnscale(tooltipW);
262 tooltipH = workspace.DPIUnscale(tooltipH);
265 if (posX > screenW - tooltipW - offsetRight)
266 posX -= tooltipW + offsetLeft;
270 if (posY > screenH - tooltipH - offsetBottom)
271 posY -= tooltipH + offsetTop;
273 posY += offsetBottom;
275 if (vector.DistanceSq(Vector(tooltipX, tooltipY, 0), Vector(posX, posY, 0)) < INERTIA_THRESHOLD)
279 if (m_bTooltipShown && tDelta != 0)
281 float progress = Math.Min(tDelta * m_fInertiaStrength, 1);
282 posX = Math.Lerp(tooltipX, posX, progress);
283 posY = Math.Lerp(tooltipY, posY, progress);
286 FrameSlot.SetPos(widget, posX, posY);
290 protected void OnMenuFocusLost()
296 override void HandlerAttachedScripted(Widget w)
302 GetGame().OnInputDeviceIsGamepadInvoker().Insert(OnInputDeviceIsGamepad);
307 menu.GetOnMenuUpdate().Insert(OnMenuUpdate);
308 menu.GetOnMenuFocusLost().Insert(OnMenuFocusLost);
321 m_ContextMenu.GetOnContextMenuToggle().Insert(OnContextMenuToggle);
329 if (m_bTrackHoverState)
333 hoverFilter.GetOnChanged().Insert(OnHover);
340 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_EDITOR_GUI_TOOLTIP_DEBUG,
"",
"Show debug in tooltips",
"Editor GUI");
344 override void HandlerDeattached(Widget w)
347 GetGame().OnInputDeviceIsGamepadInvoker().Remove(OnInputDeviceIsGamepad);
352 menu.GetOnMenuUpdate().Remove(OnMenuUpdate);
353 menu.GetOnMenuFocusLost().Remove(OnMenuFocusLost);
359 if (m_bTrackHoverState)
363 hoverFilter.GetOnChanged().Remove(OnHover);
367 m_ContextMenu.GetOnContextMenuToggle().Remove(OnContextMenuToggle);
374 class SCR_TooltipEditorEntry
380 protected ResourceName m_TooltipLayout;
386 return m_TooltipType;
391 ResourceName GetTooltipLayout()
393 return m_TooltipLayout;