123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- /// #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
- {
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class PartnerMainPanelCtrl : UIController<PartnerMainPanelVM>
- {
- #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<PartnerListItemData>();
- 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<PartnerListItemData>();
- 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();
- }
- }
- /// <summary>
- /// 圣兵待下阵监听事件
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void WaitForDownPartner(int eventId, object args)
- {
- PartnersData.Instance.IsWaitForDownState = (bool)args;
- VM.UpPartner.selectedIndex = PartnersData.Instance.IsWaitForDownState ? 1 : 0;
- }
- }
- }
|