using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; using Sirenix.OdinInspector; using KairoEngine.Core; using KairoEngine.UI.Tooltips; namespace KairoEngine.UI.ActivityMessages { public class ActivityMessageUi : MonoBehaviour { public TextMeshProUGUI textUi; public Image iconImage; public TooltipTrigger tooltipTrigger; public Image buttonImage; public ActivityMessage message; public bool autoHide = true; public float hideTimer = 5f; private float hideCounter = 0f; public bool fadeIn = true; public bool fadeOut = true; public bool hideOnClick = true; public float fadeTimer = 0.5f; private float fadeCounter = 0f; private bool isFading = false; private bool hasFadedIn = false; private ActivityMessageController controller; // private void Update() // { // if (fadeIn && !hasFadedIn) // { // fadeCounter += Time.deltaTime; // Color color = textUi.color; // color.a = fadeCounter / fadeTimer; // textUi.color = color; // buttonImage.color = color; // if (fadeCounter >= fadeTimer) // { // fadeCounter = 0f; // hasFadedIn = true; // } // } // if (autoHide && hasFadedIn || fadeIn == false) // { // hideCounter += Time.deltaTime; // if(hideCounter >= hideTimer) // { // hideCounter = 0f; // isFading = true; // } // } // if (fadeOut && isFading) // { // fadeCounter += Time.deltaTime; // Color color = textUi.color; // color.a = 1f - (fadeCounter / fadeTimer); // textUi.color = color; // buttonImage.color = color; // if (fadeCounter >= fadeTimer) // { // fadeCounter = 0f; // if(controller != null) // { // //controller.messages.Remove(message); // controller.activeMessages.Remove(this); // } // Destroy(this.gameObject); // } // } // } public void OnClick() { if(message.action != null) message.action(); if(hideOnClick) { //isFading = true; Remove(); } } public void Setup(ActivityMessageController controller, ActivityMessage newMessage) { this.controller = controller; message = newMessage; textUi.text = message.text; hideTimer = message.time; autoHide = !message.sticky; hideOnClick = message.hideOnClick; if(iconImage != null && message.icon != null) { iconImage.sprite = message.icon; iconImage.gameObject.SetActive(true); } else if(iconImage != null && message.icon == null) iconImage.gameObject.SetActive(false); if(!message.sticky) { Timer.ExecuteRealTime(message.time * 1000, () => { Remove(); }); } if(tooltipTrigger != null && message.tooltipBody != "") { tooltipTrigger.header = message.tooltipHeader; tooltipTrigger.content = message.tooltipBody; tooltipTrigger.tooltipType = message.tooltipType; } else if (tooltipTrigger != null && message.tooltipBody == "") { tooltipTrigger.enabled = false; } } public void Remove() { controller.RemoveActivityMessageFromList(message); if(this == null) return; UiAnimator uiAnimator = gameObject.GetComponent(); if(uiAnimator != null) { uiAnimator.Disable(); Timer.ExecuteRealTime(uiAnimator.animationTime * 1000, () => { if(this != null) Destroy(this.gameObject); }); } else if(this != null) Destroy(this.gameObject); } } }