diff --git a/Assets/PerfectWorld/Scripts/UI/CDlgSkillTooltip.cs b/Assets/PerfectWorld/Scripts/UI/CDlgSkillTooltip.cs new file mode 100644 index 0000000000..811fcf7280 --- /dev/null +++ b/Assets/PerfectWorld/Scripts/UI/CDlgSkillTooltip.cs @@ -0,0 +1,162 @@ +// Filename: CDlgSkillTooltip.cs +// Creator: BrewMonster +// Date: 2024 +// Purpose: Tooltip dialog for displaying skill information when clicking skill icons + +using BrewMonster.Scripts.UI; +using BrewMonster.UI; +using UnityEngine; +using UnityEngine.UI; + +namespace BrewMonster +{ + /// + /// Tooltip dialog that displays skill information (description, requirements, etc.) + /// when clicking on skill icons. Uses EC_UIUtility for smart positioning. + /// + public class CDlgSkillTooltip : AUIDialog + { + [Header("Tooltip Components")] + [SerializeField] private GameObject panelRoot; + [SerializeField] private EC_UIUtility.TextOutlet descriptionText; + [SerializeField] private Button closeButton; + + [Header("Positioning Settings")] + [SerializeField] private Vector2 panelOffset = new Vector2(20f, 0f); + [SerializeField] private bool autoHideOnClick = true; + [SerializeField] private float autoHideDelay = 0f; // 0 = no auto-hide + + private RectTransform sourceButton; + private float showTime; + + public override void Awake() + { + base.Awake(); + + if (closeButton != null) + { + closeButton.onClick.RemoveAllListeners(); + closeButton.onClick.AddListener(HideTooltip); + } + + // Hide by default + if (panelRoot != null) + { + panelRoot.SetActive(false); + } + } + + private void Update() + { + // Auto-hide after delay if enabled + if (autoHideDelay > 0f && panelRoot != null && panelRoot.activeSelf) + { + if (Time.time - showTime >= autoHideDelay) + { + HideTooltip(); + } + } + + // Click anywhere to hide if enabled + if (autoHideOnClick && panelRoot != null && panelRoot.activeSelf) + { + if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) + { + // Check if click is outside the tooltip + if (!RectTransformUtility.RectangleContainsScreenPoint( + panelRoot.transform as RectTransform, + Input.mousePosition, + null)) + { + HideTooltip(); + } + } + } + } + + /// + /// Show the tooltip with skill information near the clicked button. + /// + /// The skill description and information to display + /// The button RectTransform to position near + public void ShowTooltip(string hintText, RectTransform buttonRect) + { + if (string.IsNullOrEmpty(hintText)) + { + Debug.LogWarning("[CDlgSkillTooltip] ShowTooltip called with empty hint text"); + return; + } + + // Set description text + if (descriptionText != null) + { + // Text is already formatted by the caller + descriptionText.Set(hintText); + } + else + { + Debug.LogWarning("[CDlgSkillTooltip] descriptionText is not assigned"); + } + + sourceButton = buttonRect; + showTime = Time.time; + + // Position near button using utility + if (panelRoot != null && buttonRect != null) + { + var panelRect = panelRoot.transform as RectTransform; + if (panelRect != null) + { + // Show first so we can get accurate size for positioning + EC_UIUtility.ShowPanel(panelRoot, true); + + // Position using the utility function + EC_UIUtility.PositionPanelNearButton(panelRect, buttonRect, panelOffset); + } + else + { + Debug.LogWarning("[CDlgSkillTooltip] panelRoot does not have a RectTransform component"); + EC_UIUtility.ShowPanel(panelRoot, true); + } + } + else + { + if (panelRoot == null) + { + Debug.LogError("[CDlgSkillTooltip] panelRoot is not assigned"); + } + if (buttonRect == null) + { + Debug.LogWarning("[CDlgSkillTooltip] buttonRect is null, showing tooltip at default position"); + if (panelRoot != null) + { + EC_UIUtility.ShowPanel(panelRoot, true); + } + } + } + } + + /// + /// Hide the tooltip. + /// + public void HideTooltip() + { + EC_UIUtility.ShowPanel(panelRoot, false); + sourceButton = null; + } + + /// + /// Check if the tooltip is currently visible. + /// + /// True if tooltip is visible + public bool IsVisible() + { + return panelRoot != null && panelRoot.activeSelf; + } + + private void OnDisable() + { + HideTooltip(); + } + } +} diff --git a/Assets/PerfectWorld/Scripts/UI/CDlgSkillTooltip.cs.meta b/Assets/PerfectWorld/Scripts/UI/CDlgSkillTooltip.cs.meta new file mode 100644 index 0000000000..6d7daaf18a --- /dev/null +++ b/Assets/PerfectWorld/Scripts/UI/CDlgSkillTooltip.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: fefd244df5c9aee4186f9fe768b19a82 \ No newline at end of file diff --git a/Assets/PerfectWorld/Scripts/UI/Dialogs/CDlgSkillSubOther.cs b/Assets/PerfectWorld/Scripts/UI/Dialogs/CDlgSkillSubOther.cs index eb60b4192b..17ebfb9e2b 100644 --- a/Assets/PerfectWorld/Scripts/UI/Dialogs/CDlgSkillSubOther.cs +++ b/Assets/PerfectWorld/Scripts/UI/Dialogs/CDlgSkillSubOther.cs @@ -158,7 +158,7 @@ namespace BrewMonster.UI // Update combo skill icons - called from DlgSkill public void UpdateComboSkill() { - /*CECConfigs configs = EC_Game.GetConfigs(); + CECConfigs configs = EC_Game.GetConfigs(); if (configs == null) return; @@ -195,7 +195,7 @@ namespace BrewMonster.UI // pImage->SetHint(""); } } - }*/ + } } // Update fixed skill display