147 lines
4.2 KiB
C#
147 lines
4.2 KiB
C#
using BrewMonster;
|
|
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 : AUIImagePictureBase
|
|
{
|
|
[SerializeField] Button skillbutton;
|
|
[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 int _skillID;
|
|
|
|
public int SkillId => _skillID;
|
|
|
|
private AUIDialog m_pParent;
|
|
public override 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>();
|
|
_skillID = int.Parse(this.name.Split('_')[1]);
|
|
}
|
|
|
|
public void SetInteract(bool isInteract)
|
|
{
|
|
if (isInteract)
|
|
{
|
|
skillbutton.interactable = true;
|
|
disPlayImage.color = Color.white;
|
|
}
|
|
else
|
|
{
|
|
disPlayImage.color = Color.gray;
|
|
|
|
skillbutton.interactable = false;
|
|
}
|
|
}
|
|
|
|
public virtual void Execute()
|
|
{
|
|
if (pSC != null )
|
|
{
|
|
if (!isNotCastSkill)
|
|
{
|
|
pSC.Execute();
|
|
//SetInteract(false);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
EventBus.Publish(new OpenAssignSkillUIEvent());
|
|
}
|
|
|
|
// Show tooltip if hint exists
|
|
if (!string.IsNullOrEmpty(m_hintText))
|
|
{
|
|
var uiManager = CECUIManager.Instance;
|
|
if (uiManager != null)
|
|
{
|
|
var rectTransform = GetComponent<RectTransform>();
|
|
// int skillID = int.Parse(this.name.Split('_')[1]);
|
|
uiManager.ShowSkillTooltip(m_hintText, rectTransform, () => EventBus.Publish(new AssignSkillSelectionChangedEvent(_skillID, true)));
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void SetImage(Sprite sprite)
|
|
{
|
|
if(disPlayImage == null)
|
|
{
|
|
Debug.LogError("Skill Image is not assigned in AUIImagePicture");
|
|
return;
|
|
}
|
|
disPlayImage.sprite = sprite;
|
|
disPlayImage.gameObject.SetActive(true);
|
|
if(borderImage != null)
|
|
borderImage.SetActive(true);
|
|
}
|
|
private IEnumerator CooldownRoutine()
|
|
{
|
|
skillbutton.interactable = false;
|
|
disPlayImage.color = Color.gray;
|
|
yield return new WaitForSeconds(cooldownTime);
|
|
disPlayImage.color = Color.white;
|
|
skillbutton.interactable = true;
|
|
}
|
|
public AUIClockIcon GetClockIcon() => m_ClockCounter;
|
|
|
|
private void UpdateRenderTargert()
|
|
{
|
|
if (!NeedDynamicRender())
|
|
m_pParent.UpdateRenderTarget();
|
|
}
|
|
|
|
private bool NeedDynamicRender()
|
|
{
|
|
return m_bUpdateRenderTarget || m_bForceDynamicRender;
|
|
}
|
|
|
|
public override void Clear()
|
|
{
|
|
// BMLogger.Log("Clear AUIImagePicture with name: " + name) ;
|
|
base.Clear();
|
|
if (borderImage != null)
|
|
{
|
|
borderImage.SetActive(false);
|
|
}
|
|
if (m_ClockCounter != null)
|
|
{
|
|
m_ClockCounter.SetProgressRange(0, 1);
|
|
m_ClockCounter.SetProgressPos(1);
|
|
}
|
|
}
|
|
|
|
public void SetSkillId(int skillId)
|
|
{
|
|
_skillID = skillId;
|
|
}
|
|
}
|
|
public struct OpenSkillUIEvent
|
|
{
|
|
}
|
|
public struct OpenAssignSkillUIEvent
|
|
{
|
|
}
|
|
}
|