/// #pkgName FGUI包名
/// #panelName UIPanel名字
/// #UIName = $"{#pkgName}{#panelName}" UIKey名字
/// 该脚本由模板创建
/// created by cb 2024
using FairyGUI;
using FL.Data;
using System.Collections.Generic;
using XGame.Database;
using XGame.Framework.UI;
namespace FL.FGUI
{
///
/// UI逻辑处理类
///
///
public partial class PartnerMainPanelCtrl : UIController
{
#region 属性
private bool _bShowLineupPlanNested;
#endregion
protected override void OnEnable(object intent)
{
_bShowLineupPlanNested = false;
AddUIListenres();
AddEventListenres();
InitView();
RefreshGoneUpPartners();
RefreshAllPartners();
ShowLineupPlanNested();
}
protected override void OnDisable()
{
RemoveUIListenres();
RemoveEventListenres();
}
#region UI事件
private void AddUIListenres()
{
VM.OneKeyUpBtn.onClick.Add(OnClickOneKeyUpBtn);
VM.OneKeyStrongBtn.onClick.Add(OnClickOneKeyStrongBtn);
VM.ChangeBtn.onClick.Add(OnClickChangeBtn);
}
private void RemoveUIListenres()
{
VM.OneKeyUpBtn.onClick.Remove(OnClickOneKeyUpBtn);
VM.OneKeyStrongBtn.onClick.Remove(OnClickOneKeyStrongBtn);
VM.ChangeBtn.onClick.Remove(OnClickChangeBtn);
}
private void OnClickOneKeyUpBtn(EventContext context)
{
XGame.Log.Info("OnClickOneKeyUpBtn.");
}
private void OnClickOneKeyStrongBtn(EventContext context)
{
XGame.Log.Info("OnClickOneKeyStrongBtn.");
}
private void OnClickChangeBtn(EventContext context)
{
EventSingle.Instance.Notify(EventDefine.ShowTips, "方案切换");
_bShowLineupPlanNested = !_bShowLineupPlanNested;
ShowLineupPlanNested();
}
#endregion
#region 事件监听
private void AddEventListenres()
{
EventSingle.Instance.AddListener(EventDefine.PartnerDown, OnPartnerDown);
EventSingle.Instance.AddListener(EventDefine.PartnerUp, OnPartnerUp);
EventSingle.Instance.AddListener(EventDefine.WaitForDownPartner,WaitForDownPartner);
}
private void RemoveEventListenres()
{
EventSingle.Instance.RemoveListener(EventDefine.PartnerDown, OnPartnerDown);
EventSingle.Instance.RemoveListener(EventDefine.PartnerUp, OnPartnerUp);
EventSingle.Instance.RemoveListener(EventDefine.WaitForDownPartner, WaitForDownPartner);
}
private void OnPartnerUp(int eventId, object args)
{
RefreshGoneUpPartners();
RefreshAllPartners();
}
private void OnPartnerDown(int eventId, object args)
{
RefreshGoneUpPartners();
RefreshAllPartners();
}
#endregion
#region 随从列表
private void InitView()
{
VM.GoneUpList.ListType = EGListType.None;
VM.ParentAllList.ListType = EGListType.Virtual;
}
private void RefreshGoneUpPartners()
{
var list = new List();
var curPlan = PartnersData.Instance.CurUsePlan;
for (int i = 0; i < PartnersData.GoneUpLimit; i++)
{
var slot = curPlan.GetSlot(i);
list.Add(new PartnerListItemData() { tableId = slot?.sbId ?? 0, type = PartnerListItemType.Up });
}
VM.GoneUpList.BindDatas(list);
}
private void RefreshAllPartners()
{
var table = PartnerTableRepo.GetAll();
var list = new List();
foreach (var partner in table)
{
list.Add(new PartnerListItemData()
{
tableId = partner.Id,
type = PartnerListItemType.Bag,
});
}
//list.Sort((a,b) =>
//{
// var partnerInfo = PartnersData.Instance.get
//});
//.Sort((a, b) =>
//{
// // 已上阵的排前面
// var result = b.state - a.state;
// if (result != 0)
// return result;
// // id小的排前面
// return a.tableId - b.tableId;
//});
VM.ParentAllList.BindDatas(list);
}
#endregion
private void ShowLineupPlanNested()
{
VM.SwitchPlan.selectedIndex = _bShowLineupPlanNested ? 1 : 0;
if (_bShowLineupPlanNested)
{
VM.LineupPlanNested.Ctrl.ShowUI();
}
}
///
/// 圣兵待下阵监听事件
///
///
///
private void WaitForDownPartner(int eventId, object args)
{
PartnersData.Instance.IsWaitForDownState = (bool)args;
VM.UpPartner.selectedIndex = PartnersData.Instance.IsWaitForDownState ? 1 : 0;
}
}
}