Explorar o código

Fixed showing multiple tooltips

jamesperet %!s(int64=2) %!d(string=hai) anos
pai
achega
8d42a5ab50

+ 3 - 1
Runtime/ActivityMessages/ActivityMessage.cs

@@ -20,9 +20,10 @@ namespace KairoEngine.UI.ActivityMessages
         [FoldoutGroup("@GetTitle()")] public Action action;
         [FoldoutGroup("@GetTitle()")] public string tooltipHeader;
         [FoldoutGroup("@GetTitle()")] public string tooltipBody;
+        [FoldoutGroup("@GetTitle()")] public string tooltipType;
 
         public ActivityMessage(string text, string id = "", string group = "", string prefab = "", Sprite icon = null, float time = 5f, bool sticky = false, 
-            bool hideOnClick = true, Action action = null, string tooltipHeader = "", string tooltipBody = "")
+            bool hideOnClick = true, Action action = null, string tooltipHeader = "", string tooltipBody = "", string tooltipType = "")
         {
             this.text = text;
             this.id = id;
@@ -35,6 +36,7 @@ namespace KairoEngine.UI.ActivityMessages
             this.action = action;
             this.tooltipHeader = tooltipHeader;
             this.tooltipBody = tooltipBody;
+            this.tooltipType = tooltipType;
         }
 
         public string GetTitle()

+ 4 - 3
Runtime/ActivityMessages/ActivityMessageController.cs

@@ -97,16 +97,16 @@ namespace KairoEngine.UI.ActivityMessages
         }
 
         private void NewFullMessage(string text, string id, string group, string prefab, Sprite icon, float time, bool sticky, bool hideOnClick, 
-            Action action, string tooltipHeader, string tooltipBody)
+            Action action, string tooltipHeader, string tooltipBody, string tooltipType)
         {
-            ActivityMessage message = new ActivityMessage(text, id, group, prefab, icon, time, sticky, hideOnClick, action, tooltipHeader, tooltipBody);
+            ActivityMessage message = new ActivityMessage(text, id, group, prefab, icon, time, sticky, hideOnClick, action, tooltipHeader, tooltipBody, tooltipType);
             int groupIndex = GetGroupIndexByTitle(group);
             int prefabIndex = GetPrefabIndexByTitle(prefab);
             CreateMessage(message, groupIndex, prefabIndex).Setup(this, message);
         }
 
         private void UpdateActivityMessage(string id, string newText, Sprite newSprite, float time, bool sticky, bool hideOnClick, 
-            Action action, string tooltipHeader, string tooltipBody)
+            Action action, string tooltipHeader, string tooltipBody, string tooltipType)
         {
             for (int i = 0; i < activeMessages.Count; i++)
             {
@@ -119,6 +119,7 @@ namespace KairoEngine.UI.ActivityMessages
                     activeMessages[i].message.hideOnClick = hideOnClick;
                     activeMessages[i].message.tooltipHeader = tooltipHeader;
                     activeMessages[i].message.tooltipBody = tooltipBody;
+                    activeMessages[i].message.tooltipType = tooltipType;
                     if(action != null) activeMessages[i].message.action = action;
                     activeMessages[i].Setup(this, activeMessages[i].message);
                     return;

+ 1 - 0
Runtime/ActivityMessages/ActivityMessageUi.cs

@@ -110,6 +110,7 @@ namespace KairoEngine.UI.ActivityMessages
             {
                 tooltipTrigger.header = message.tooltipHeader;
                 tooltipTrigger.content = message.tooltipBody;
+                tooltipTrigger.tooltipType = message.tooltipType;
             }
             else if (tooltipTrigger != null && message.tooltipBody == "")
             {

+ 12 - 8
Runtime/Tooltips/TooltipSystem.cs

@@ -26,27 +26,31 @@ namespace KairoEngine.UI.Tooltips
         public static void Show(string content, string header = "", string tooltipType = "")
         {
             if(!HasInstance()) return;
+            Tooltip currentTooltip = null;
             foreach(KeyValuePair<string, Tooltip> keyValue in instance.tooltipList)
             {
                 string key = keyValue.Key;
-                if(key == tooltipType)
+                if(key == tooltipType || (key == "" && tooltipType == ""))
                 {
-                    instance.tooltip = keyValue.Value;
+                    currentTooltip = keyValue.Value;
                 }
             }
-            if(instance.tooltip != null)
+            foreach(KeyValuePair<string, Tooltip> keyValue in instance.tooltipList) Hide(keyValue.Value);
+            if(currentTooltip != null)
             {
-                instance.tooltip.SetText(content, header);
-                instance.tooltip.gameObject.SetActive(true);
+                currentTooltip.SetText(content, header);
+                currentTooltip.gameObject.SetActive(true);
+                instance.tooltip = currentTooltip;
             }
             else Debug.LogError($"The Tooltip type named \'{tooltipType}\' could not be found.", instance.gameObject);
         }
 
-        public static void Hide()
+        public static void Hide(Tooltip tooltip = null)
         {
             if(!HasInstance()) return;
-            if(instance.tooltip == null) return;
-            instance.tooltip.gameObject.SetActive(false);
+            if(tooltip == null && instance.tooltip == null) return;
+            if(tooltip == null) tooltip = instance.tooltip;
+            tooltip.gameObject.SetActive(false);
             instance.tooltip = null;
         }