/// <summary> /// Restores the default values. /// </summary> /// <param name="tooltip">The <see cref="ITooltip"/>.</param> public void RestoreDefaults(ITooltip tooltip) { FontColor = tooltip.FontColor; BackgroundColor = tooltip.BackgroundColor; Border = tooltip.Border; Timeout = tooltip.Timeout; RefreshRate = 0; }
public TooltipData(ITooltip tooltip) { Stopwatch timer = new Stopwatch(); string sockets = string.Empty, quality = "Unknown"; timer.Start(); DPS = tooltip.ParseDPS(); Name = tooltip.ParseItemName(); Type = tooltip.ParseItemType(out quality); Meta = tooltip.ParseMeta(); Affixes = tooltip.ParseAffixes(out sockets); Quality = quality; SocketBonuses = sockets; timer.Stop(); TimeTaken = timer.ElapsedMilliseconds; }
IEnumerator AnimateHide(ITooltip tooltip, TooltipUI tooltipUI) { var target = GetTooltipTarget(tooltip); var startTime = Time.realtimeSinceStartup; while (Time.realtimeSinceStartup - startTime < k_TransitionDuration) { if (!target) { break; } UpdateVisuals(tooltip, tooltipUI, target, 1 - (Time.realtimeSinceStartup - startTime) / k_TransitionDuration); yield return(null); } ObjectUtils.Destroy(tooltipUI.gameObject); }
public void HideTooltip(ITooltip tooltip, bool persistent = false) { TooltipData tooltipData; if (m_Tooltips.TryGetValue(tooltip, out tooltipData)) { if (!persistent && tooltipData.persistent) { return; } m_Tooltips.Remove(tooltip); if (m_ModuleParent.activeInHierarchy && tooltipData.tooltipUI) { EditorMonoBehaviour.instance.StartCoroutine(AnimateHide(tooltip, tooltipData)); } } }
public void Created(Actor self) { tooltip = self.TraitsImplementing <ITooltip>().FirstOrDefault(); health = self.TraitOrDefault <Health>(); frozenStates = new PlayerDictionary <FrozenState>(self.World, (player, playerIndex) => { var frozenActor = new FrozenActor(self, footprint, player.Shroud, startsRevealed); if (startsRevealed) { UpdateFrozenActor(self, frozenActor, playerIndex); } player.PlayerActor.Trait <FrozenActorLayer>().Add(frozenActor); return(new FrozenState(frozenActor) { IsVisible = startsRevealed }); }); }
public void HideTooltip(ITooltip tooltip, bool persistent = false) { TooltipData tooltipData; if (m_Tooltips.TryGetValue(tooltip, out tooltipData)) { if (!persistent && tooltipData.persistent) { return; } m_Tooltips.Remove(tooltip); if (tooltipData.tooltipUI) { StartCoroutine(AnimateHide(tooltip, tooltipData)); } } }
internal EditorTooltip(ITooltip item) { InitializeComponent(); Loaded += (s, e) => { ItemName.Content = PrettifyName(item); ItemName.SetResourceReference(TextBlock.ForegroundProperty, EnvironmentColors.SystemMenuTextBrushKey); string description = item.Description; if (!item.IsSupported) { description += $"\r\n\r\n{EditorConfig.Resources.Text.NotSupportedByVS}"; } Description.Text = description; Description.SetResourceReference(TextBlock.ForegroundProperty, EnvironmentColors.SystemMenuTextBrushKey); Glyph.Source = item.Moniker.ToBitmap(_iconSize); }; }
private void Update() { TooltipTitle.text = string.Empty; TooltipDescription.text = string.Empty; TooltipFooter.text = string.Empty; foreach (ITooltipUpdater updater in _updaters) { ITooltip tooltip = updater.GetTooltip(); if (tooltip != null) { TooltipTitle.text = tooltip.Title; TooltipDescription.text = tooltip.Description; TooltipFooter.text = tooltip.Footnote; break; } } TooltipTransform.gameObject.SetActive(!string.IsNullOrEmpty(TooltipTitle.text)); TooltipDescription.gameObject.SetActive(!string.IsNullOrEmpty(TooltipDescription.text)); TooltipFooter.gameObject.SetActive(!string.IsNullOrEmpty(TooltipFooter.text)); Vector2 flip = new Vector2(); Vector2 pos = MousePosition.ScreenPosition; Rect rect = TooltipTransform.rect; if (pos.x + rect.width > Screen.width) { flip.x = -rect.width + Offset.x * -2; } if (pos.y - rect.height < 0f) { flip.y = rect.height + Offset.y * 2; } TooltipTransform.position = pos + Offset + flip; }
private void OnTriggerExit(Collider other) { var hoverable = other.GetComponent <IHoverable>(); if (hoverable != null) { hoverable.Unhover(this); } var grabables = other.GetComponents <IGrabable>(); foreach (var grabable in grabables) { intersectingGrababales.Remove(grabable); } var activatable = other.GetComponent <IActivateable>(); if (activatable != null) { intersectingActivatables.Remove(activatable); if (pressedActivatableReleases.ContainsKey(activatable)) { var unpress = pressedActivatableReleases[activatable]; unpress(); pressedActivatableReleases.Remove(activatable); } } var tt = other.GetComponent <ITooltip>(); if (tt == tooltip) { tooltip = null; tooltipDisplay.enabled = false; } }
public ITooltip GetTooltip() { GraphicRaycaster raycaster = UIController.Instance.GraphicRaycaster; EventSystem eventSystem = UIController.Instance.EventSystem; PointerEventData data = new PointerEventData(eventSystem); data.position = Mouse.current.position.ReadValue(); List <RaycastResult> results = new List <RaycastResult>(); raycaster.Raycast(data, results); foreach (RaycastResult result in results) { ITooltip tooltip = result.gameObject.GetComponent <ITooltip>(); if (tooltip != null) { return(tooltip); } } return(null); }
private Completion4 CreateCompletion(ITooltip item, Category category = Category.None, string iconAutomation = null) { IEnumerable<CompletionIcon2> icon = null; string automationText = iconAutomation; string text = item.Name; if (int.TryParse(item.Name, out int integer)) text = "<integer>"; if (!item.IsSupported) { icon = new[] { new CompletionIcon2(KnownMonikers.IntellisenseWarning, "warning", "") }; } if (category != Category.None) { automationText = category.ToString(); } var completion = new Completion4(text, item.Name, item.Description, item.Moniker, automationText, icon); completion.Properties.AddProperty("item", item); return completion; }
void CreateFaceButtons() { var types = new HashSet <Type>(); types.UnionWith(menuTools); types.UnionWith(menuWorkspaces); types.UnionWith(settingsMenuProviders.Keys.Select(provider => provider.Key)); types.UnionWith(settingsMenuItemProviders.Keys.Select(provider => provider.Key)); if (Application.isPlaying) { types.RemoveWhere(type => type.GetCustomAttributes(true).OfType <EditorOnlyWorkspaceAttribute>().Any()); } foreach (var type in types) { var customMenuAttribute = (MainMenuItemAttribute)type.GetCustomAttributes(typeof(MainMenuItemAttribute), false).FirstOrDefault(); if (customMenuAttribute != null && !customMenuAttribute.shown) { continue; } var isTool = typeof(ITool).IsAssignableFrom(type) && menuTools.Contains(type); var isWorkspace = typeof(Workspace).IsAssignableFrom(type); var isSettingsProvider = typeof(ISettingsMenuProvider).IsAssignableFrom(type); var isSettingsItemProvider = typeof(ISettingsMenuItemProvider).IsAssignableFrom(type); ITooltip tooltip = null; MainMenuUI.ButtonData buttonData = null; var selectedType = type; // Local variable for closure if (customMenuAttribute != null && customMenuAttribute.shown) { tooltip = customMenuAttribute.tooltip; buttonData = new MainMenuUI.ButtonData(customMenuAttribute.name) { sectionName = customMenuAttribute.sectionName, description = customMenuAttribute.description }; } if (isTool) { if (buttonData == null) { buttonData = new MainMenuUI.ButtonData(type.Name); } var mainMenuButton = CreateFaceButton(buttonData, tooltip, () => { if (targetRayOrigin) { this.SelectTool(targetRayOrigin, selectedType, hideMenu: typeof(IInstantiateMenuUI).IsAssignableFrom(selectedType)); UpdateToolButtons(); } }); m_ToolButtons[type] = mainMenuButton; // Assign Tools Menu button preview properties if (mainMenuButton != null) { mainMenuButton.toolType = selectedType; } m_ToolsSpatialMenuElements.Add(new SpatialMenu.SpatialMenuElementContainer(buttonData.name, buttonData.description, node => { this.SelectTool(this.RequestRayOriginFromNode(node), selectedType, hideMenu: typeof(IInstantiateMenuUI).IsAssignableFrom(selectedType)); })); UpdateToolButtons(); } if (isWorkspace) { // For workspaces that haven't specified a custom attribute, do some menu categorization automatically if (buttonData == null) { buttonData = new MainMenuUI.ButtonData(type.Name) { sectionName = "Workspaces" } } ; CreateFaceButton(buttonData, tooltip, () => { this.CreateWorkspace(selectedType); }); m_WorkspaceSpatialMenuElements.Add(new SpatialMenu.SpatialMenuElementContainer(buttonData.name, buttonData.description, node => this.CreateWorkspace(selectedType))); } if (isSettingsProvider) { foreach (var providerPair in settingsMenuProviders) { var kvp = providerPair.Key; if (kvp.Key == type && (kvp.Value == null || kvp.Value == rayOrigin)) { AddSettingsMenu(providerPair.Value, buttonData, tooltip); } } } if (isSettingsItemProvider) { foreach (var providerPair in settingsMenuItemProviders) { var kvp = providerPair.Key; if (kvp.Key == type && (kvp.Value == null || kvp.Value == rayOrigin)) { AddSettingsMenuItem(providerPair.Value); } } } } } MainMenuButton CreateFaceButton(MainMenuUI.ButtonData buttonData, ITooltip tooltip, Action buttonClickCallback) { var mainMenuButton = m_MainMenuUI.CreateFaceButton(buttonData); if (mainMenuButton == null) { return(null); } var button = mainMenuButton.button; button.onClick.RemoveAllListeners(); button.onClick.AddListener(() => { if (m_MenuHideFlags == 0) { buttonClickCallback(); } }); mainMenuButton.hovered += OnButtonHovered; mainMenuButton.clicked += OnButtonClicked; mainMenuButton.tooltip = tooltip; return(mainMenuButton); } void UpdateToolButtons() { foreach (var kvp in m_ToolButtons) { kvp.Value.selected = this.IsToolActive(targetRayOrigin, kvp.Key); } } void OnButtonClicked(Transform rayOrigin) { this.Pulse(this.RequestNodeFromRayOrigin(rayOrigin), m_ButtonClickPulse); this.ClearToolMenuButtonPreview(); } void OnButtonHovered(Transform rayOrigin, Type buttonType, string buttonDescription) { this.Pulse(this.RequestNodeFromRayOrigin(rayOrigin), m_ButtonHoverPulse); // Pass the pointer which is over us, so this information can supply context (e.g. selecting a tool for a different hand) // Enable preview-mode on a Tools Menu button; Display on the opposite proxy device by evaluating the entering RayOrigin // Disable any existing previews being displayed in ToolsMenus this.ClearToolMenuButtonPreview(); if (buttonType != null && rayOrigin != null) { this.PreviewInToolMenuButton(rayOrigin, buttonType, buttonDescription); } } void OnToggleHovered(Transform rayOrigin) { this.Pulse(this.RequestNodeFromRayOrigin(rayOrigin), m_ButtonHoverPulse); } void SendVisibilityPulse() { this.Pulse(node, m_MenuHideFlags == 0 ? m_HidePulse : m_ShowPulse); }
void UpdateVisuals(ITooltip tooltip, TooltipUI tooltipUI, Transform target, float lerp) { var tooltipTransform = tooltipUI.transform; lerp = MathUtilsExt.SmoothInOutLerpFloat(lerp); // shape the lerp for better presentation var tooltipText = tooltipUI.text; if (tooltipText) { tooltipText.text = tooltip.tooltipText; tooltipText.color = Color.Lerp(Color.clear, Color.white, lerp); } var viewerScale = this.GetViewerScale(); tooltipTransform.localScale = m_TooltipScale * lerp * viewerScale; TooltipData toolTipData; m_Tooltips.TryGetValue(tooltip, out toolTipData); var highlightMaterial = toolTipData != null ? toolTipData.customHighlightMaterial : m_HighlightMaterial; tooltipUI.highlight.material = highlightMaterial; m_TooltipBackgroundMaterial.SetColor("_Color", Color.Lerp(UnityBrandColorScheme.darker, m_OriginalBackgroundColor, lerp)); var placement = tooltip as ITooltipPlacement; // Adjust for alignment var offset = Vector3.zero; if (placement != null) { switch (placement.tooltipAlignment) { case TextAlignment.Right: offset = Vector3.left; break; case TextAlignment.Left: offset = Vector3.right; break; } } var rectTransform = tooltipUI.GetComponent <RectTransform>(); var rect = rectTransform.rect; var halfWidth = rect.width * 0.5f; var halfHeight = rect.height * 0.5f; if (placement != null) { offset *= halfWidth * rectTransform.lossyScale.x; } else { offset = Vector3.back * k_Offset * this.GetViewerScale(); } MathUtilsExt.SetTransformOffset(target, tooltipTransform, offset * lerp, Quaternion.identity); if (placement != null) { var source = placement.tooltipSource; var toSource = tooltipTransform.InverseTransformPoint(source.position); // Position spheres: one at source, one on the closest edge of the tooltip var spheres = tooltipUI.spheres; spheres[0].position = source.position; var attachedSphere = spheres[1]; var boxSlope = halfHeight / halfWidth; var toSourceSlope = Mathf.Abs(toSource.y / toSource.x); halfHeight *= Mathf.Sign(toSource.y); halfWidth *= Mathf.Sign(toSource.x); attachedSphere.localPosition = toSourceSlope > boxSlope ? new Vector3(0, halfHeight) : new Vector3(halfWidth, 0); // Align dotted line var attachedSpherePosition = attachedSphere.position; toSource = source.position - attachedSpherePosition; var midPoint = attachedSpherePosition + toSource * 0.5f; var dottedLine = tooltipUI.dottedLine; var length = toSource.magnitude; var uvRect = dottedLine.uvRect; var worldScale = 1 / viewerScale; uvRect.width = length * k_UVScale * worldScale; uvRect.xMin += k_UVScrollSpeed * Time.deltaTime; dottedLine.uvRect = uvRect; var dottedLineTransform = dottedLine.transform.parent.GetComponent <RectTransform>(); dottedLineTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, length / tooltipTransform.lossyScale.x); dottedLineTransform.position = midPoint; dottedLineTransform.rotation = Quaternion.LookRotation(toSource, -tooltipTransform.forward); } }
void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { Amiga.UI.SceneSettings sceneSettings = GameManager.Instance.CurrentSceneSettings; sceneSettings.HideTopPanel(); } if (GameManager.Instance.GameState != GameManager.State.Dungeon) { //return; } if (eventSystem == null) { eventSystem = FindObjectOfType <EventSystem>(); } PointerEventData pointer = new PointerEventData(eventSystem); pointer.position = Input.mousePosition; List <RaycastResult> raycastResults = new List <RaycastResult>(); eventSystem.RaycastAll(pointer, raycastResults); if (GameManager.Instance.CurrentSceneSettings == null) { return; } if (!(GameManager.Instance.CurrentSceneSettings is Amiga.UI.Dungeon.DungeonDisplay)) { //return; } //Amiga.UI.Dungeon.InventoryMenu inventoryMenu = ((Amiga.UI.Dungeon.DungeonDisplay)GameManager.Instance.CurrentSceneSettings).inventoryPanel; if (Input.GetMouseButton(0)) { if (Input.GetMouseButtonDown(1)) { RotateGrabbedItem(); } } foreach (var result in raycastResults) { if (result.gameObject.GetComponent <ITooltip>() != null) { ITooltip tooltippable = result.gameObject.GetComponent <ITooltip>(); UISlot.TooltipData tooltipData = tooltippable.GetTooltip(); tooltip.gameObject.SetActive(tooltipData.show); if (tooltipData.show) { tooltip.transform.Find("Description").GetComponent <Text>().text = "<b>" + tooltipData.title + "</b>\n"; tooltip.transform.Find("Description").GetComponent <Text>().text += tooltipData.content; tooltip.transform.Find("Image Holder").Find("Image").GetComponent <Image>().sprite = tooltipData.image; } break; } else { tooltip.gameObject.SetActive(false); } } bool itstrue = false; foreach (var result in raycastResults) { if (Input.GetMouseButtonDown(0)) { if (result.gameObject.GetComponent <UISlot>() != null) { UISlot grabbable = result.gameObject.GetComponent <UISlot>(); GrabItem(grabbable); } } if (Input.GetMouseButtonUp(0)) { if (result.gameObject.GetComponent <DroppableArea>() != null) { DroppableArea placeable = result.gameObject.GetComponent <DroppableArea>(); PlaceItem(placeable); } } /* * if (result.gameObject.GetComponent<UISlot>() != null) * { * UISlot slot = result.gameObject.GetComponent<UISlot>(); * * if (slot is EquipmentSlot) * { * //Amiga.UI.Dungeon.EquipmentSlot dSlot = slot as Amiga.UI.Dungeon.EquipmentSlot; * * //dSlot.Highlight(true); * * /* * if (Input.GetMouseButtonDown(0)) * { * inventoryMenu.GrabItem(dSlot); * } * * if (Input.GetMouseButtonUp(0)) * { * inventoryMenu.PlaceItem(dSlot); * } *//* * } * else if(slot is Amiga.UI.Inventory.InventorySlot) * { * Amiga.UI.Inventory.InventorySlot iSlot = slot as Amiga.UI.Inventory.InventorySlot; * * inventoryMenu.HighlightInventory(iSlot); * * itstrue = true; * * /* * if (Input.GetMouseButtonDown(0)) * { * inventoryMenu.GrabItem(iSlot); * } * * if (Input.GetMouseButtonUp(0)) * { * inventoryMenu.PlaceItem(iSlot); * } *//* * * break; * } * }*/ } if (Input.GetMouseButtonUp(0)) { ReleaseItem(); } /* * if (itstrue == false) * { * if(GameManager.Instance.CurrentSceneSettings != null && GameManager.Instance.CurrentSceneSettings is Amiga.UI.Dungeon.DungeonDisplay) * { * inventoryMenu.UnhighlightAll(); * } * } */ }
void ITooltipMgr.UnsetTooltip() { this.currentTip = null; this.tipOutput.text = this.defaultValue; }
void ITooltipMgr.SetTooltip(ITooltip tip) { this.currentTip = tip; this.tipOutput.text = tip.Tip; }
/// <summary> /// Hide the given Tooltip /// </summary> /// <param name="tooltip">The tooltip to hide</param> /// <param name="persistent">Whether to hide the tooltip if it was shown with the persistent argument set to true</param> public static void HideTooltip(this ISetTooltipVisibility obj, ITooltip tooltip, bool persistent = false) { hideTooltip(tooltip, persistent); }
public void onOpened(TextController controller) { m_boss = controller.Boss; m_autoComplete = m_boss.Get<IAutoComplete>(); setTypingAttributes(CurrentStyles.DefaultAttributes); setAutomaticTextReplacementEnabled(false); if (m_boss.Has<ITooltip>()) { m_tooltip = m_boss.Get<ITooltip>(); m_timer = new System.Threading.Timer((object state) => { NSApplication.sharedApplication().BeginInvoke(this.DoShowTooltip); }); } }
public void ShowTooltip(ITooltip tooltip, bool persistent = false, float duration = 0f, ITooltipPlacement placement = null, Action becameVisible = null) { if (!IsValidTooltip(tooltip)) { return; } TooltipData data; if (m_Tooltips.TryGetValue(tooltip, out data)) { // Compare the targets to see if they changed var currentTarget = data.GetTooltipTarget(tooltip); var currentPlacement = data.placement; data.persistent |= persistent; data.placement = placement ?? tooltip as ITooltipPlacement; // Set the text to new text var tooltipUI = data.tooltipUI; if (tooltipUI) { tooltipUI.Show(tooltip.tooltipText, data.placement.tooltipAlignment); var newTarget = data.GetTooltipTarget(tooltip); if (currentTarget != newTarget) { // Get the different between the 'old' tooltip position and 'new' tooltip position, even taking alignment into account var transitionLerp = 1.0f - Mathf.Clamp01((Time.time - data.transitionTime) / k_ChangeTransitionDuration); var currentPosition = currentTarget.TransformPoint(GetTooltipOffset(tooltipUI, currentPlacement, data.transitionOffset * transitionLerp)); var newPosition = newTarget.TransformPoint(GetTooltipOffset(tooltipUI, data.placement, Vector3.zero)); // Store it as an additional offset that we'll quickly lerp from data.transitionOffset = newTarget.InverseTransformVector(currentPosition - newPosition); data.transitionTime = Time.time; } if (duration > 0) { data.duration = duration; data.lastModifiedTime = Time.time; } } return; } // Negative durations only affect existing tooltips if (duration < 0) { return; } var tooltipData = GetTooltipData(); tooltipData.startTime = Time.time; tooltipData.lastModifiedTime = Time.time; tooltipData.persistent = persistent; tooltipData.duration = duration; tooltipData.becameVisible = becameVisible; tooltipData.placement = placement ?? tooltip as ITooltipPlacement; tooltipData.orientationWeight = 0.0f; tooltipData.transitionOffset = Vector3.zero; tooltipData.transitionTime = 0.0f; m_Tooltips[tooltip] = tooltipData; }
public static void TooltipUpdate(ITooltip tooltip) { TooltipUpdated.Send(tooltip, tooltip.GetTooltipText()); }
/// <summary> /// Hide the given Tooltip /// </summary> /// <param name="user">The functionality user</param> /// <param name="tooltip">The tooltip to hide</param> /// <param name="persistent">Whether to hide the tooltip if it was shown with the persistent argument set to true</param> public static void HideTooltip(this IUsesSetTooltipVisibility user, ITooltip tooltip, bool persistent = false) { #if !FI_AUTOFILL user.provider.HideTooltip(tooltip, persistent); #endif }
void AddSettingsMenu(ISettingsMenuProvider provider, MainMenuUI.ButtonData buttonData, ITooltip tooltip) { buttonData.sectionName = k_SettingsMenuSectionName; var button = CreateFaceButton(buttonData, tooltip, () => { var instance = m_MainMenuUI.AddSubmenu(k_SettingsMenuSectionName, provider.settingsMenuPrefab); m_SettingsMenus[provider] = instance; provider.settingsMenuInstance = instance; AddToggleHaptics(instance); }); button.hovered += OnButtonHovered; button.clicked += OnButtonClicked; }
void Start() { parentTooltip = GetComponentInParent <ITooltip>(); }
void AddSettingsMenu(ISettingsMenuProvider provider, MainMenuUI.ButtonData buttonData, ITooltip tooltip) { buttonData.sectionName = k_SettingsMenuSectionName; CreateFaceButton(buttonData, tooltip, () => { var instance = m_MainMenuUI.AddSubmenu(k_SettingsMenuSectionName, provider.settingsMenuPrefab); m_SettingsMenus[provider] = instance; provider.settingsMenuInstance = instance; }); }
/// <summary> /// Show the given Tooltip /// </summary> /// <param name="tooltip">The tooltip to show</param> public static void ShowTooltip(this ISetTooltipVisibility obj, ITooltip tooltip) { showTooltip(tooltip); }
void UpdateVisuals(ITooltip tooltip, TooltipUI tooltipUI, Transform target, float lerp) { var tooltipTransform = tooltipUI.transform; var tooltipText = tooltipUI.text; if (tooltipText) { tooltipText.text = tooltip.tooltipText; } var viewerScale = getViewerScale(); tooltipTransform.localScale = m_TooltipScale * lerp * viewerScale; var placement = tooltip as ITooltipPlacement; // Adjust for alignment var offset = Vector3.zero; if (placement != null) { switch (placement.tooltipAlignment) { case TextAlignment.Right: offset = Vector3.left; break; case TextAlignment.Left: offset = Vector3.right; break; } } var rectTransform = tooltipUI.GetComponent <RectTransform>(); var rect = rectTransform.rect; var halfWidth = rect.width * 0.5f; var halfHeight = rect.height * 0.5f; if (placement != null) { offset *= halfWidth * rectTransform.lossyScale.x; } else { offset = Vector3.back * k_Offset; } MathUtilsExt.SetTransformOffset(target, tooltipTransform, offset * lerp, Quaternion.identity); if (placement != null) { var source = placement.tooltipSource; var toSource = tooltipTransform.InverseTransformPoint(source.position); // Position spheres: one at source, one on the closest edge of the tooltip var spheres = tooltipUI.spheres; spheres[0].position = source.position; var attachedSphere = spheres[1]; var boxSlope = halfHeight / halfWidth; var toSourceSlope = Mathf.Abs(toSource.y / toSource.x); halfHeight *= Mathf.Sign(toSource.y); halfWidth *= Mathf.Sign(toSource.x); attachedSphere.localPosition = toSourceSlope > boxSlope ? new Vector3(0, halfHeight) : new Vector3(halfWidth, 0); // Align dotted line var attachedSpherePosition = attachedSphere.position; toSource = source.position - attachedSpherePosition; var midPoint = attachedSpherePosition + toSource * 0.5f; var dottedLine = tooltipUI.dottedLine; var length = toSource.magnitude; var uvRect = dottedLine.uvRect; var worldScale = 1 / viewerScale; uvRect.width = length * k_UVScale * worldScale; uvRect.xMin += k_UVScrollSpeed * Time.unscaledDeltaTime; dottedLine.uvRect = uvRect; var dottedLineTransform = dottedLine.transform.parent.GetComponent <RectTransform>(); dottedLineTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, length / tooltipTransform.lossyScale.x); dottedLineTransform.position = midPoint; dottedLineTransform.rotation = Quaternion.LookRotation(toSource, -tooltipTransform.forward); } }
/// <summary> /// Hide the given Tooltip /// </summary> /// <param name="tooltip">The tooltip to hide</param> public static void HideTooltip(this ISetTooltipVisibility obj, ITooltip tooltip) { hideTooltip(tooltip); }
void UpdateVisuals(ITooltip tooltip, TooltipData tooltipData, float lerp) { var target = tooltipData.GetTooltipTarget(tooltip); var tooltipUI = tooltipData.tooltipUI; var placement = tooltipData.placement; var orientationWeight = tooltipData.orientationWeight; var tooltipTransform = tooltipUI.transform; lerp = MathUtilsExt.SmoothInOutLerpFloat(lerp); // shape the lerp for better presentation var transitionLerp = MathUtilsExt.SmoothInOutLerpFloat(1.0f - Mathf.Clamp01((Time.time - tooltipData.transitionTime) / k_ChangeTransitionDuration)); var viewerScale = this.GetViewerScale(); tooltipTransform.localScale = m_TooltipScale * lerp * viewerScale; // Adjust for alignment var offset = GetTooltipOffset(tooltipUI, placement, tooltipData.transitionOffset * transitionLerp); // The rectTransform expansion is handled in the Tooltip dynamically, based on alignment & text length var rotationOffset = Quaternion.identity; var camTransform = CameraUtils.GetMainCamera().transform; if (Vector3.Dot(camTransform.forward, target.forward) < 0) { rotationOffset *= k_FlipYRotation; } if (Vector3.Dot(camTransform.up, target.up) + orientationWeight < 0) { rotationOffset *= k_FlipZRotation; tooltipData.orientationWeight = -k_TextOrientationWeight; } else { tooltipData.orientationWeight = k_TextOrientationWeight; } MathUtilsExt.SetTransformOffset(target, tooltipTransform, offset * lerp, rotationOffset); if (placement != null) { //TODO: Figure out why rect gives us different height/width than GetWorldCorners tooltipUI.rectTransform.GetWorldCorners(k_Corners); var bottomLeft = k_Corners[0]; var halfWidth = (bottomLeft - k_Corners[2]).magnitude * 0.5f; var halfHeight = (bottomLeft - k_Corners[1]).magnitude * 0.5f; var source = placement.tooltipSource; var toSource = tooltipTransform.InverseTransformPoint(source.position); // Position spheres: one at source, one on the closest edge of the tooltip var spheres = tooltipUI.spheres; spheres[0].position = source.position; var attachedSphere = spheres[1]; var boxSlope = halfHeight / halfWidth; var toSourceSlope = Mathf.Abs(toSource.y / toSource.x); var parentScale = attachedSphere.parent.lossyScale; halfHeight *= Mathf.Sign(toSource.y) / parentScale.x; halfWidth *= Mathf.Sign(toSource.x) / parentScale.y; attachedSphere.localPosition = toSourceSlope > boxSlope ? new Vector3(0, halfHeight) : new Vector3(halfWidth, 0); // Align dotted line var attachedSpherePosition = attachedSphere.position; toSource = source.position - attachedSpherePosition; var midPoint = attachedSpherePosition + toSource * 0.5f; var dottedLine = tooltipUI.dottedLine; var length = toSource.magnitude; var uvRect = dottedLine.uvRect; var worldScale = 1 / viewerScale; uvRect.width = length * k_UVScale * worldScale; uvRect.xMin += k_UVScrollSpeed * Time.deltaTime; dottedLine.uvRect = uvRect; var dottedLineTransform = dottedLine.transform.parent.GetComponent <RectTransform>(); dottedLineTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, length / tooltipTransform.lossyScale.x); dottedLineTransform.position = midPoint; dottedLineTransform.rotation = Quaternion.LookRotation(toSource, -tooltipTransform.forward); } }
/// <summary> /// Show a Tooltip. Calling ShowTooltip on an ITooltip that was just shown will update its placement and timing /// </summary> /// <param name="tooltip">The tooltip to show</param> /// <param name="persistent">Whether the tooltip should stay visible regardless of raycasts</param> /// <param name="duration">If the tooltip is shown persistently, and duration is less than 0, hide after the /// duration, in seconds. If duration greater than 0, placement is updated but timing is not affected. If /// duration is exactly 0, tooltip stays visible until explicitly hidden</param> /// <param name="placement">(Optional) The ITooltipPlacement object used to place the tooltip. If no placement /// is specified, we assume the ITooltip is a component and use its own Transform</param> /// <param name="becameVisible">(Optional) Called as soon as the tooltip becomes visible</param> public static void ShowTooltip(this ISetTooltipVisibility obj, ITooltip tooltip, bool persistent = false, float duration = 0f, ITooltipPlacement placement = null, Action becameVisible = null) { showTooltip(tooltip, persistent, duration, placement, becameVisible); }
static bool IsValidTooltip(ITooltip tooltip) { return(!string.IsNullOrEmpty(tooltip.tooltipText)); }
public void Init(ITooltip <T> tooltip) { _toolTip = tooltip; }