151 lines
4.4 KiB
C#
151 lines
4.4 KiB
C#
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<AUIDialog>();
|
|
}
|
|
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<RectTransform>();
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set hint/tooltip text that will be displayed when the skill icon is clicked.
|
|
/// This is typically the skill description with requirements.
|
|
/// </summary>
|
|
/// <param name="hint">The hint text to display</param>
|
|
public void SetHint(string hint)
|
|
{
|
|
m_hintText = hint ?? string.Empty;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the stored hint/tooltip text.
|
|
/// </summary>
|
|
/// <returns>The hint text or empty string if none set</returns>
|
|
public string GetHint()
|
|
{
|
|
return m_hintText;
|
|
}
|
|
}
|
|
public struct OpenSkillUIEvent
|
|
{
|
|
|
|
}
|
|
}
|