/// #pkgName FGUI包名 /// #panelName UIPanel名字 /// #UIName = $"{#pkgName}{#panelName}" UIKey名字 /// 该脚本由模板创建 /// created by cb 2024 using System.Collections.Generic; using FairyGUI; using FL.Data; using XGame.Database; using XGame.Framework.UI; namespace FL.FGUI { /// /// UI逻辑处理类 /// /// public partial class PartnerPartnerBookDetailPanelCtrl : UIController { protected override void OnEnable(object intent) { _curId = (int)intent; AddUIListenres(); InitView(); UpView(); } protected override void OnDisable() { RemoveUIListenres(); } #region UI事件 private void AddUIListenres() { VM.LeftBtn.onClick.Add(OnClickLeftBtn); VM.RightBtn.onClick.Add(OnClickRightBtn); VM.GetBtn.onClick.Add(OnClickGetBtn); Context.AddListener(EventDefine.PartnerJibanRwdGet, OnRwdGet); Context.AddListener(EventDefine.PartnerJibanRwdGetAll, OnRwdGet); } private void RemoveUIListenres() { VM.LeftBtn.onClick.Remove(OnClickLeftBtn); VM.RightBtn.onClick.Remove(OnClickRightBtn); VM.GetBtn.onClick.Remove(OnClickGetBtn); Context.RemoveListener(EventDefine.PartnerJibanRwdGet, OnRwdGet); Context.RemoveListener(EventDefine.PartnerJibanRwdGetAll, OnRwdGet); } private void OnRwdGet(int eventId, object args) { UpdateList(); } private void OnClickLeftBtn(EventContext context) { SelectOffset(-1); } private void OnClickRightBtn(EventContext context) { SelectOffset(1); } private void OnClickGetBtn(EventContext context) { var collectTable = collectTableRepo.Get(_curId); var starLv = 0; foreach (var id in collectTable.Param) { if (PartnersData.Instance.TryGetPartnerAttrByTableId(id, out var attr)) { starLv += attr.RisingStarLv; } } var rwdList = collect_rewardTableRepo.GetCollectRwdList(_curId); var canGet = false; foreach (var item in rwdList) { if ( starLv > item.Unlock && !PartnersData.Instance.GetJibaIsActive(item.CollectId, item.Level) ) { canGet = true; break; } } if (canGet) { PartnersService.Instance.RequestJibanRwdGetAll(_curId); } else { Context.ShowTips(StringDefine.PartnerJiBanNoActivatable); } } #endregion private bool _initView = false; private int _curId; private List _list; private void InitView() { if (_initView) return; _initView = true; VM.List.ListType = EGListType.None; VM.RwdList.ListType = EGListType.Virtual; var tableList = collectTableRepo.GetAllEpiCollectList(); var list = new List(); foreach (var item in tableList) { list.Add(item.Id); } _list = list; } private void UpView() { var table = collectTableRepo.Get(_curId); XGame.Framework.Assert.IsNotNull(table, $"羁绊表不存在,id:{_curId}"); VM.List.BindDatas(table.Param); VM.NameLabel.text = table.Name; UpdateList(); } private void UpdateList() { var list = collect_rewardTableRepo.GetCollectRwdList(_curId); VM.RwdList.BindDatas(list); } private void SelectOffset(int offset) { var index = _list.IndexOf(offset); index += offset; if (index < 0) { index += _list.Count; } else if (index >= _list.Count) { index -= _list.Count; } _curId = _list[index]; UpView(); } } }