using BrewMonster.UI; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UI; namespace BrewMonster.Assets.PerfectWorld.Scripts.UI.GamePlay { public class AUIImagePicture : MonoBehaviour { [Header("AUIImagePicture")] [SerializeField] CECShortcut pSC; [SerializeField] Button skillbutton; [SerializeField] protected Image skillImage; [SerializeField] GameObject borderImage; [SerializeField] int cooldownTime; [SerializeField] AUIClockIcon m_ClockCounter; [SerializeField] bool isNotCastSkill; private Color m_color = Color.white; private bool m_bUpdateRenderTarget; private bool m_bForceDynamicRender; private AUIDialog m_pParent; // Hint/tooltip data storage private string m_hintText = string.Empty; private void Awake() { if (skillbutton == null) { Debug.LogError("Skill Button is not assigned in AUIImagePicture"); return; } skillbutton.onClick.RemoveAllListeners(); skillbutton.onClick.AddListener(Execute); m_pParent = GetComponentInParent(); } public void SetDataPtr(CECShortcut pvData, string strName = null) { pSC = pvData; } public void SetInteract(bool isInteract) { if (isInteract) { skillbutton.interactable = true; skillImage.color = Color.white; } else { skillImage.color = Color.gray; skillbutton.interactable = false; } } public CECShortcut GetDataPtr() => pSC; public void Execute() { if (pSC != null ) { if (!isNotCastSkill) { pSC.Execute(); //SetInteract(false); } } else { EventBus.Publish(new OpenSkillUIEvent()); } // Show tooltip if hint exists if (!string.IsNullOrEmpty(m_hintText)) { var uiManager = CECUIManager.Instance; if (uiManager != null) { var rectTransform = GetComponent(); uiManager.ShowSkillTooltip(m_hintText, rectTransform); } } } public void SetImage(Sprite sprite) { if(skillImage == null) { Debug.LogError("Skill Image is not assigned in AUIImagePicture"); return; } skillImage.sprite = sprite; if(borderImage != null) borderImage.SetActive(true); } private IEnumerator CooldownRoutine() { skillbutton.interactable = false; skillImage.color = Color.gray; yield return new WaitForSeconds(cooldownTime); skillImage.color = Color.white; skillbutton.interactable = true; } public AUIClockIcon GetClockIcon() => m_ClockCounter; public void SetColor(Color color) { skillImage.color = color; } private void UpdateRenderTargert() { if (!NeedDynamicRender()) m_pParent.UpdateRenderTarget(); } private bool NeedDynamicRender() { return m_bUpdateRenderTarget || m_bForceDynamicRender; } /// /// Set hint/tooltip text that will be displayed when the skill icon is clicked. /// This is typically the skill description with requirements. /// /// The hint text to display public void SetHint(string hint) { m_hintText = hint ?? string.Empty; } /// /// Get the stored hint/tooltip text. /// /// The hint text or empty string if none set public string GetHint() { return m_hintText; } public void Clear() { // BMLogger.Log("Clear AUIImagePicture with name: " + name) ; pSC = null; this.SetDataPtr(null); borderImage.SetActive(false); m_ClockCounter.SetProgressRange(0, 1); m_ClockCounter.SetProgressPos(1); } } public struct OpenSkillUIEvent { } }