123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- /// #pkgName FGUI包名
- /// #panelName UIPanel名字
- /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
- /// 该脚本由模板创建
- /// created by cb 2024
- using System.Collections.Generic;
- using System.Runtime.Remoting.Contexts;
- using FairyGUI;
- using FL.Data;
- using XGame.Database;
- using XGame.Framework.Persistence;
- using XGame.Framework.UI;
- namespace FL.FGUI
- {
- public class PartnerSbBagListParam
- {
- /// <summary>
- /// 道具类型,为0则是标题,否则是列表
- /// </summary>
- public int Type;
- public string Title;
- public List<int> SbList;
- }
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class PartnerSbBagPanelCtrl : UIController<PartnerSbBagPanelVM>
- {
- protected override void OnEnable(object intent)
- {
- AddUIListenres();
- InitView();
- VM.OpenSelect.selectedIndex = 1;
- ShowUI();
- }
- protected override void OnDisable()
- {
- RemoveUIListenres();
- }
- #region UI事件
- private void AddUIListenres()
- {
- VM.OnStrongBtn.onClick.Add(OnClickOnStrongBtn);
- VM.SortBtn.onClick.Add(OnClickSortBtn);
- VM.ShangZhenBtn.onClick.Add(OnClickSortTypeBtn);
- VM.PinZhiBtn.onClick.Add(OnClickSortTypeBtn);
- VM.DengJiBtn.onClick.Add(OnClickSortTypeBtn);
- VM.IDBtn.onClick.Add(OnClickSortTypeBtn);
- VM.PanelEvent.Add(OnClickPanel);
- Context.AddListener(EventDefine.PartnerDown, OnUpdateList);
- Context.AddListener(EventDefine.PartnerUp, OnUpdateList);
- Context.AddListener(EventDefine.PartnerUpLevel, OnUpdateList);
- Context.AddListener(EventDefine.PartnerStrongAll, OnUpdateList);
- Context.AddListener(EventDefine.PartnerUpStar, OnUpdateList);
- Context.AddListener(EventDefine.PartnerBinding, OnUpdateList);
- }
- private void RemoveUIListenres()
- {
- VM.OnStrongBtn.onClick.Remove(OnClickOnStrongBtn);
- VM.SortBtn.onClick.Remove(OnClickSortBtn);
- VM.ShangZhenBtn.onClick.Remove(OnClickSortTypeBtn);
- VM.PinZhiBtn.onClick.Remove(OnClickSortTypeBtn);
- VM.DengJiBtn.onClick.Remove(OnClickSortTypeBtn);
- VM.IDBtn.onClick.Remove(OnClickSortTypeBtn);
- VM.PanelEvent.Remove(OnClickPanel);
- Context.RemoveListener(EventDefine.PartnerDown, OnUpdateList);
- Context.RemoveListener(EventDefine.PartnerUp, OnUpdateList);
- Context.RemoveListener(EventDefine.PartnerUpLevel, OnUpdateList);
- Context.RemoveListener(EventDefine.PartnerStrongAll, OnUpdateList);
- Context.RemoveListener(EventDefine.PartnerUpStar, OnUpdateList);
- Context.RemoveListener(EventDefine.PartnerBinding, OnUpdateList);
- }
- private void OnClickPanel()
- {
- if (VM.OpenSelect.selectedIndex == 1)
- return;
- VM.OpenSelect.selectedIndex = 1;
- }
- private void OnClickSortTypeBtn(EventContext context)
- {
- context.StopPropagation();
- if (_curSortType == VM.CurSelect.selectedIndex)
- return;
- _curSortType = VM.CurSelect.selectedIndex;
- Persistence.Write(
- PlayerData.Instance.UID + PersistenceKeys.partner_sort_type,
- _curSortType
- );
- ShowUI();
- }
- private void OnClickOnStrongBtn(EventContext context)
- {
- var list = PartnersData.Instance.PartnerList;
- var canUp = false;
- foreach (var item in list)
- {
- var table = partnerStarUpTableRepo.GetPartnerStarTable(
- item.TableId,
- item.RisingStarLv
- );
- var nextTable = partnerStarUpTableRepo.GetPartnerStarTable(
- item.TableId,
- item.RisingStarLv + 1
- );
- XGame.Framework.Assert.IsNotNull(
- table,
- $"圣兵表升星不存在,id{item.TableId},starlv:{item.RisingStarLv}"
- );
- if (
- nextTable != null
- && ItemService.Instance.IsEnough(table.PetId, table.StarUpCost, false)
- )
- {
- canUp = true;
- break;
- }
- }
- if (canUp)
- PartnersService.Instance.RequestPartnerOneKeyStarUp();
- else
- {
- Context.ShowTips(StringDefine.PartnerCantStarUpAll);
- }
- }
- private void OnClickSortBtn(EventContext context)
- {
- context.StopPropagation();
- VM.OpenSelect.selectedIndex = VM.OpenSelect.selectedIndex > 0 ? 0 : 1;
- }
- private void OnUpdateList(int eventId, object args)
- {
- ShowUI();
- }
- #endregion
- private List<PartnerSbBagListParam> _dataList = new List<PartnerSbBagListParam>();
- private bool _init = false;
- private int _curSortType = 0;
- private void InitView()
- {
- if (_init)
- return;
- _init = true;
- VM.CurSelect.selectedIndex = Persistence.Read(
- PlayerData.Instance.UID + PersistenceKeys.partner_sort_type,
- 0
- );
- VM.List.ListType = EGListType.Virtual;
- }
- private void ShowUI()
- {
- var allSbList = PartnerTableRepo.GetAll();
- var haveList = new List<int>();
- var noHaveList = new List<int>();
- foreach (var sb in allSbList)
- {
- var attr = PartnersData.Instance.GetPartnerAttrByTableId(sb.Id);
- if (attr != null)
- {
- haveList.Add(sb.Id);
- }
- else
- {
- noHaveList.Add(sb.Id);
- }
- }
- haveList.Sort(
- (a, b) =>
- {
- PartnersData.Instance.TryGetPartnerAttrByTableId(a, out var aAttr);
- PartnersData.Instance.TryGetPartnerAttrByTableId(b, out var bAttr);
- switch (VM.CurSelect.selectedIndex)
- {
- case 0:
- if (aAttr.Status != bAttr.Status)
- {
- return bAttr.Status - aAttr.Status;
- }
- break;
- case 1:
- var aTable = PartnerTableRepo.Get(a);
- var bTable = PartnerTableRepo.Get(b);
- if (aTable.Quality != bTable.Quality)
- {
- return bTable.Quality - aTable.Quality;
- }
- break;
- case 2:
- if (bAttr.Level != aAttr.Level)
- {
- return bAttr.Level - aAttr.Level;
- }
- break;
- }
- return a - b;
- }
- );
- noHaveList.Sort(
- (a, b) =>
- {
- switch (VM.CurSelect.selectedIndex)
- {
- case 1:
- var aTable = PartnerTableRepo.Get(a);
- var bTable = PartnerTableRepo.Get(b);
- if (aTable.Quality != bTable.Quality)
- {
- return bTable.Quality - aTable.Quality;
- }
- break;
- }
- return a - b;
- }
- );
- _dataList.Clear();
- _dataList.Add(new PartnerSbBagListParam() { Type = 0, Title = StringDefine.Have });
- var list = new List<int>();
- foreach (var have in haveList)
- {
- list.Add(have);
- if (list.Count >= 5)
- {
- _dataList.Add(new PartnerSbBagListParam() { Type = 1, SbList = list });
- list = new List<int>();
- }
- }
- if (list.Count > 0)
- {
- _dataList.Add(new PartnerSbBagListParam() { Type = 1, SbList = list });
- list = new List<int>();
- }
- _dataList.Add(new PartnerSbBagListParam() { Type = 0, Title = StringDefine.NoHave });
- foreach (var noHave in noHaveList)
- {
- list.Add(noHave);
- if (list.Count >= 5)
- {
- _dataList.Add(new PartnerSbBagListParam() { Type = 1, SbList = list });
- list = new List<int>();
- }
- }
- //var dataList = new List<int>();
- //foreach (var item in allSbList)
- //{
- // dataList.Add(item.Id);
- //}
- //dataList.Sort((a, b) =>
- //{
- // PartnersData.Instance.TryGetPartnerAttrByTableId(a, out var aAttr);
- // PartnersData.Instance.TryGetPartnerAttrByTableId(b, out var bAttr);
- // if (aAttr != null && bAttr != null)
- // {
- // if (aAttr.Status != bAttr.Status)
- // {
- // return bAttr.Status - aAttr.Status;
- // }
- // else if (bAttr.Level != aAttr.Level)
- // {
- // return bAttr.Level - aAttr.Level;
- // }
- // }
- // else if (aAttr == null && bAttr != null)
- // {
- // return 1;
- // }
- // else if (aAttr != null && bAttr == null)
- // {
- // return -1;
- // }
- // return b - a;
- //});
- VM.List.BindDatas(_dataList);
- }
- }
- }
|