297 lines
8.6 KiB
C#
297 lines
8.6 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 BrewMonster.Network;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BrewMonster.Assets.PerfectWorld.Scripts.UI.GamePlay
|
|
{
|
|
public class AUIImagePicture : AUIImagePictureBase
|
|
{
|
|
public const string DefaultComboIcon = "爱你";
|
|
[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;
|
|
private int _skillGroupIndex = -1;
|
|
private readonly List<int> _skillGroupIndexes = new();
|
|
|
|
public int SkillId => _skillID;
|
|
public int SkillGroupIndex => _skillGroupIndex;
|
|
public IReadOnlyList<int> SkillGroupIndexes => _skillGroupIndexes;
|
|
|
|
private AUIDialog m_pParent;
|
|
|
|
public override void Awake()
|
|
{
|
|
if (skillbutton == null)
|
|
{
|
|
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;
|
|
}
|
|
|
|
if (skillbutton != null)
|
|
{
|
|
skillbutton.interactable = true;
|
|
}
|
|
|
|
disPlayImage.color = Color.white;
|
|
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();
|
|
skillbutton.interactable = true;
|
|
if (disPlayImage != null)
|
|
{
|
|
disPlayImage.color = Color.white;
|
|
}
|
|
_skillGroupIndex = -1;
|
|
_skillGroupIndexes.Clear();
|
|
if (borderImage != null)
|
|
{
|
|
borderImage.SetActive(false);
|
|
}
|
|
if (m_ClockCounter != null)
|
|
{
|
|
m_ClockCounter.ClearSkillGroupBinding();
|
|
m_ClockCounter.SetProgressRange(0, 1);
|
|
m_ClockCounter.SetProgressPos(1);
|
|
}
|
|
}
|
|
|
|
public void SetSkillId(int skillId)
|
|
{
|
|
_skillID = skillId;
|
|
}
|
|
|
|
public void SetSkillGroupIndex(int groupIndex)
|
|
{
|
|
_skillGroupIndex = groupIndex;
|
|
_skillGroupIndexes.Clear();
|
|
if (groupIndex >= 0)
|
|
{
|
|
_skillGroupIndexes.Add(groupIndex);
|
|
}
|
|
if (m_ClockCounter != null)
|
|
{
|
|
m_ClockCounter.BindSkillGroup(groupIndex);
|
|
}
|
|
}
|
|
|
|
public bool SetSkillGroupIcon(int groupIndex, int nIcon)
|
|
{
|
|
return SetSkillGroupIcons(new[] { groupIndex }, groupIndex);
|
|
}
|
|
|
|
public bool SetSkillGroupIcons(IReadOnlyList<int> groupIndexes, int preferredGroupIndex = -1)
|
|
{
|
|
_skillGroupIndexes.Clear();
|
|
if (groupIndexes == null || groupIndexes.Count == 0)
|
|
{
|
|
Clear();
|
|
return false;
|
|
}
|
|
|
|
foreach (int groupIndex in groupIndexes)
|
|
{
|
|
if (groupIndex >= 0 && !_skillGroupIndexes.Contains(groupIndex))
|
|
{
|
|
_skillGroupIndexes.Add(groupIndex);
|
|
}
|
|
}
|
|
|
|
if (_skillGroupIndexes.Count == 0)
|
|
{
|
|
Clear();
|
|
return false;
|
|
}
|
|
|
|
int resolvedGroup = preferredGroupIndex >= 0 && _skillGroupIndexes.Contains(preferredGroupIndex)
|
|
? preferredGroupIndex
|
|
: _skillGroupIndexes[0];
|
|
|
|
if (m_ClockCounter != null)
|
|
{
|
|
m_ClockCounter.BindSkillGroup(resolvedGroup);
|
|
}
|
|
|
|
EC_VIDEO_SETTING? setting = EC_Game.GetConfigs()?.GetVideoSettings();
|
|
if (!setting.HasValue || setting.Value.comboSkill == null)
|
|
{
|
|
Clear();
|
|
return false;
|
|
}
|
|
|
|
var comboSkills = setting.Value.comboSkill;
|
|
|
|
for (int i = 0; i < _skillGroupIndexes.Count; i++)
|
|
{
|
|
int index = _skillGroupIndexes[i];
|
|
if (index < 0 || index >= comboSkills.Length)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (TrySetDefaultSkillGroupIcon())
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
_skillGroupIndex = resolvedGroup;
|
|
Clear();
|
|
return false;
|
|
}
|
|
|
|
private bool TrySetSkillGroupIconByNIcon(int groupIndex, int nIcon)
|
|
{
|
|
_skillGroupIndex = groupIndex;
|
|
if (nIcon <= 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
skillbutton.interactable = true;
|
|
var uiMan = EC_Game.GetGameRun()?.GetUIManager()?.GetInGameUIMan();
|
|
if (uiMan == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// C++ mapping uses nIcon + 1 for skill group icon index.
|
|
string iconName = (nIcon + 1).ToString();
|
|
var icon = uiMan.GetIcon(iconName, EC_GAMEUI_ICONS.ICONS_SKILLGRP);
|
|
if (icon == null)
|
|
{
|
|
iconName = nIcon.ToString();
|
|
icon = uiMan.GetIcon(iconName, EC_GAMEUI_ICONS.ICONS_SKILLGRP);
|
|
}
|
|
if (icon == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
SetImage(icon);
|
|
return true;
|
|
}
|
|
|
|
private bool TrySetDefaultSkillGroupIcon()
|
|
{
|
|
var uiMan = EC_Game.GetGameRun()?.GetUIManager()?.GetInGameUIMan();
|
|
if (uiMan == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var icon = uiMan.GetIcon(DefaultComboIcon, EC_GAMEUI_ICONS.ICONS_SKILLGRP);
|
|
if (icon == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
SetImage(icon);
|
|
return true;
|
|
}
|
|
}
|
|
public struct OpenSkillUIEvent
|
|
{
|
|
}
|
|
public struct OpenAssignSkillUIEvent
|
|
{
|
|
}
|
|
}
|