/// #pkgName FGUI包名
/// #panelName UIPanel名字
/// #UIName = $"{#pkgName}{#panelName}" UIKey名字
/// 该脚本由模板创建
/// created by cb 2024
using FairyGUI;
using FL.Battle.Components.AI;
using FL.Data;
using System.Collections.Generic;
using UnityEngine.UI;
using XGame.Database;
using XGame.Framework.UI;
namespace FL.FGUI
{
///
/// UI逻辑处理类
///
///
public partial class PlayerChangeImprintPanelCtrl : UIController
{
private int _slotId; // 槽位id
private int _runeType; // 符文类型
private GButton[] _btnsArray;
private runeTable _runeTableInfo;
protected override void OnEnable(object intent)
{
AddUIListenres();
_btnsArray = new GButton[3] {VM.AttackImprintBtn, VM.SkillImprintBtn, VM.PartnerImprintBtn };
ShowUI(int.Parse(intent.ToString()));
}
protected override void OnDisable()
{
RemoveUIListenres();
RemoveUIListenres();
}
#region UI事件
private void AddUIListenres()
{
VM.CancelBtn.onClick.Add(OnClickCancelBtn);
VM.SureBtn.onClick.Add(OnClickSureBtn);
VM.AttackImprintBtn.onClick.Add(OnClickAttackImprintBtn);
VM.SkillImprintBtn.onClick.Add(OnClickSkillImprintBtn);
VM.PartnerImprintBtn.onClick.Add(OnClickPartnerImprintBtn);
}
private void RemoveUIListenres()
{
VM.CancelBtn.onClick.Remove(OnClickCancelBtn);
VM.SureBtn.onClick.Remove(OnClickSureBtn);
VM.AttackImprintBtn.onClick.Remove(OnClickAttackImprintBtn);
VM.SkillImprintBtn.onClick.Remove(OnClickSkillImprintBtn);
VM.PartnerImprintBtn.onClick.Remove(OnClickPartnerImprintBtn);
}
private void OnClickCancelBtn(EventContext context)
{
Context.ClosePanel();
}
private void OnClickSureBtn(EventContext context)
{
PlayerService.Instance.SendToChangeRuneType(PlayerData.Instance.CurPlanIndex, _slotId, _runeType);
Context.ClosePanel();
}
private void OnClickAttackImprintBtn(EventContext context)
{
_runeType = _runeTableInfo.Handoff[0];
ShowSelectUI(0);
}
private void OnClickSkillImprintBtn(EventContext context)
{
_runeType = _runeTableInfo.Handoff[1];
ShowSelectUI(1);
}
private void OnClickPartnerImprintBtn(EventContext context)
{
_runeType = _runeTableInfo.Handoff[2];
ShowSelectUI(2);
}
#endregion
///
/// 显示可选择替换的符文UI
///
///
private void ShowUI(int imprintIndex)
{
_slotId = imprintIndex + 1;
_runeTableInfo = runeTableRepo.Get(_slotId);
if (_runeTableInfo != null)
{
int count = _runeTableInfo.Name.Length;
for (int i = 0; i < _btnsArray.Length; i++)
{
if (i < count)
{
_btnsArray[i].visible = true;
_btnsArray[i].title = _runeTableInfo.Name[i];
}
else
{
_btnsArray[i].visible = false;
}
}
}
OnClickAttackImprintBtn(null);
}
private void ShowSelectUI(int index)
{
for (int i = 0; i < _btnsArray.Length; i++)
{
_btnsArray[i].GetController("SelectCtrl").selectedIndex = i == index ? 1 : 0;
}
}
}
}