123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469 |
- /// #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
- {
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class PartnerSbMainPanelCtrl : UIController<PartnerSbMainPanelVM>
- {
- protected override void OnEnable(object intent)
- {
- AddUIListenres();
- InitView();
- ShowUI();
- }
- protected override void OnDisable()
- {
- RemoveUIListenres();
- clearUpMode();
- }
- #region UI事件
- private void AddUIListenres()
- {
- VM.ReplaceBtn.onClick.Add(OnClickReplaceBtn);
- VM.StrengthBtn.onClick.Add(OnClickStrengthBtn);
- VM.OneUpBtn.onClick.Add(OnClickOneUpBtn);
- VM.RecommendBtn.onClick.Add(OnClickRecommendBtn);
- //VM.BagBtn.onClick.Add(OnClickBagBtn);
- VM.SbBagBtn.onClick.Add(OnClickSbBagBtn);
- VM.MwBagBtn.onClick.Add(OnClickMwBagBtn);
- VM.ConfirmBtn.onClick.Add(OnClickConfirmBtn);
- VM.CancelBtn.onClick.Add(OnClickCancelBtn);
- Context.AddListener(EventDefine.PartnerFinishUpMode, OnFinishUpMode);
- Context.AddListener(EventDefine.PartnerOpenUpMode, OnOpenUpMode);
- Context.AddListener(EventDefine.PartnerMainSbSelect, OnSelectSb);
- Context.AddListener(EventDefine.PartnerUpLevel, OnUpLevel);
- Context.AddListener(EventDefine.PartnerUpStar, OnUpStar);
- Context.AddListener(EventDefine.PartnerDown, OnSbUp);
- Context.AddListener(EventDefine.PartnerUp, OnSbUp);
- Context.AddListener(EventDefine.PartnerWearAll, OnSbUp);
- Context.AddListener(EventDefine.PartnerBinding, OnSbUp);
- Context.AddListener(EventDefine.PartnerMainMwSelect, OnSelectMw);
- Context.AddListener(EventDefine.EpigraphOpenUpMode, OnOpenUpMode);
- Context.AddListener(EventDefine.EpigraphFinishUpMode, OnFinishUpMode);
- Context.AddListener(EventDefine.EpigraphWearAll, OnSbUp);
- }
- private void RemoveUIListenres()
- {
- VM.ReplaceBtn.onClick.Remove(OnClickReplaceBtn);
- VM.StrengthBtn.onClick.Remove(OnClickStrengthBtn);
- VM.OneUpBtn.onClick.Remove(OnClickOneUpBtn);
- VM.RecommendBtn.onClick.Remove(OnClickRecommendBtn);
- //VM.BagBtn.onClick.Remove(OnClickBagBtn);
- VM.SbBagBtn.onClick.Remove(OnClickSbBagBtn);
- VM.MwBagBtn.onClick.Remove(OnClickMwBagBtn);
- VM.ConfirmBtn.onClick.Remove(OnClickConfirmBtn);
- VM.CancelBtn.onClick.Remove(OnClickCancelBtn);
- Context.RemoveListener(EventDefine.PartnerFinishUpMode, OnFinishUpMode);
- Context.RemoveListener(EventDefine.PartnerOpenUpMode, OnOpenUpMode);
- Context.RemoveListener(EventDefine.PartnerMainSbSelect, OnSelectSb);
- Context.RemoveListener(EventDefine.PartnerUpLevel, OnUpLevel);
- Context.RemoveListener(EventDefine.PartnerUpStar, OnUpStar);
- Context.RemoveListener(EventDefine.PartnerDown, OnSbUp);
- Context.RemoveListener(EventDefine.PartnerUp, OnSbUp);
- Context.RemoveListener(EventDefine.PartnerWearAll, OnSbUp);
- Context.RemoveListener(EventDefine.PartnerBinding, OnSbUp);
- Context.RemoveListener(EventDefine.PartnerMainMwSelect, OnSelectMw);
- Context.RemoveListener(EventDefine.EpigraphOpenUpMode, OnOpenUpMode);
- Context.RemoveListener(EventDefine.EpigraphFinishUpMode, OnFinishUpMode);
- Context.RemoveListener(EventDefine.EpigraphWearAll, OnSbUp);
- }
- private void OnClickMwBagBtn()
- {
- Context.UI.OpenAsync(UIKeys.PartnerSbBagPanel, 1);
- }
- private void OnClickSbBagBtn()
- {
- Context.UI.OpenAsync(UIKeys.PartnerSbBagPanel, 0);
- }
- private void OnSelectMw(int eventId, object args)
- {
- var pos = (int)args;
- if (PartnersData.Instance.UpModeSelect > 0)
- {
- if (_selectType == 0 && pos == _curSelectPos)
- return;
- _selectType = 0;
- _curSelectPos = pos;
- RefreshGoneUpPartners(false);
- UpdateDetail();
- }
- else if (EpigraphData.Instance.UpModeSelect > 0)
- {
- if (_selectType == 1 && pos == _curSelectPos)
- return;
- var sbId = PartnersData.Instance.UpSbMap.GetValueOrDefault(_curSelectPos, 0);
- if (sbId == 0)
- {
- Context.ShowTips(EStringDefine.PartnerCurSlotNoSbTips);
- return;
- }
- _selectType = 1;
- _curSelectPos = pos;
- RefreshGoneUpPartners(false);
- UpdateDetail();
- }
- else
- {
- var sbId = PartnersData.Instance.UpSbMap.GetValueOrDefault(pos, 0);
- var sbData = PartnersData.Instance.GetPartnerAttrByTableId(sbId);
- var mwId = sbData?.EpigraphId ?? 0;
- if (mwId == 0)
- {
- Context.UI.OpenAsync(UIKeys.PartnerMwUpPanel, sbId);
- }
- _selectType = 1;
- _curSelectPos = pos;
- RefreshGoneUpPartners(false);
- UpdateDetail();
- }
- }
- private void OnSelectSb(int eventId, object args)
- {
- var pos = (int)args;
- if (PartnersData.Instance.UpModeSelect > 0)
- {
- if (_selectType == 0 && pos == _curSelectPos)
- return;
- _selectType = 0;
- _curSelectPos = pos;
- RefreshGoneUpPartners(false);
- UpdateDetail();
- }
- else if (EpigraphData.Instance.UpModeSelect > 0)
- {
- if (_selectType == 1 && pos == _curSelectPos)
- return;
- var sbId = PartnersData.Instance.UpSbMap.GetValueOrDefault(_curSelectPos, 0);
- if (sbId == 0)
- {
- Context.ShowTips(EStringDefine.PartnerCurSlotNoSbTips);
- return;
- }
- _selectType = 1;
- _curSelectPos = pos;
- RefreshGoneUpPartners(false);
- UpdateDetail();
- }
- else
- {
- var sbId = PartnersData.Instance.UpSbMap.GetValueOrDefault(pos, 0);
- if (sbId == 0)
- {
- Context.UI.OpenAsync(UIKeys.PartnerSbUpPanel, pos);
- }
- if (_selectType == 0 && pos == _curSelectPos)
- return;
- _selectType = 0;
- _curSelectPos = pos;
- RefreshGoneUpPartners(false);
- UpdateDetail();
- }
- }
- private void OnSbUp(int eventId, object args)
- {
- RefreshGoneUpPartners(false);
- UpdateDetail();
- }
- private void OnUpLevel(int eventId, object args)
- {
- RefreshGoneUpPartners(false);
- UpdateDetail();
- }
- private void OnUpStar(int eventId, object args)
- {
- RefreshGoneUpPartners(false);
- UpdateDetail();
- }
- private void OnClickReplaceBtn(EventContext context)
- {
- if (_selectType == 0)
- {
- Context.UI.OpenAsync(UIKeys.PartnerSbReplacePanel, _curSelectPos);
- }
- else
- {
- Context.UI.OpenAsync(UIKeys.PartnerMwReplacePanel, _curSelectPos);
- }
- }
- private void OnClickStrengthBtn(EventContext context)
- {
- var sbId = PartnersData.Instance.UpSbMap.GetValueOrDefault(_curSelectPos, 0);
- if (sbId <= 0)
- {
- Context.ShowTips(EStringDefine.PartnerEmptyTips);
- return;
- }
- if (_selectType == 0)
- {
- Context.UI.OpenAsync(UIKeys.PartnerSbStrengthPanel, sbId);
- }
- else
- {
- var sbData = PartnersData.Instance.GetPartnerAttrByTableId(sbId);
- Context.UI.OpenAsync(UIKeys.PartnerMwStrengthPanel, sbData.EpigraphId);
- }
- }
- private void OnClickOneUpBtn(EventContext context)
- {
- if (_selectType == 0)
- {
- PartnersService.Instance.RequestPartnerOneKeyUp();
- }
- else
- {
- EpigraphService.Instance.RequestEpiWearAll();
- }
- }
- private void OnClickRecommendBtn(EventContext context)
- {
- Context.UI.OpenAsync(UIKeys.PartnerSbRecommendPanel);
- }
- private void OnClickConfirmBtn(EventContext context)
- {
- if (PartnersData.Instance.UpModeSelect > 0)
- {
- PartnersService.Instance.RequestPartnerUpNew(
- _curSelectPos,
- PartnersData.Instance.UpModeSelect
- );
- }
- else if (EpigraphData.Instance.UpModeSelect > 0)
- {
- var sbId = PartnersData.Instance.UpSbMap.GetValueOrDefault(_curSelectPos, 0);
- if (sbId == 0)
- {
- Context.ShowTips(EStringDefine.PartnerCurSlotNoSbTips);
- return;
- }
- EpigraphService.Instance.RequestEpiInset(sbId, EpigraphData.Instance.UpModeSelect);
- }
- }
- private void OnClickCancelBtn(EventContext context)
- {
- if (PartnersData.Instance.UpModeSelect > 0)
- {
- PartnersService.Instance.FinishUpPartnerMode();
- }
- else if (EpigraphData.Instance.UpModeSelect > 0)
- {
- EpigraphService.Instance.FinishUpMode();
- }
- }
- /// <summary>
- /// 圣兵上阵打开事件
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void OnOpenUpMode(int eventId, object args)
- {
- ShowUpMode();
- }
- private void OnFinishUpMode(int eventId, object args)
- {
- ShowUpMode();
- }
- #endregion
- #region 属性
- private bool _initView = false;
- private int _curSelectPos = 0;
- /// <summary>
- /// 选择类型,0圣兵,1铭文
- /// </summary>
- private int _selectType = 0;
- #endregion
- #region 页面
- private void clearUpMode()
- {
- EpigraphData.Instance.UpModeSelect = 0;
- PartnersData.Instance.UpModeSelect = 0;
- }
- private void InitView()
- {
- if (_initView)
- return;
- _initView = true;
- VM.SbList.ListType = EGListType.None;
- }
- private void ShowUI()
- {
- ShowUpMode();
- RefreshGoneUpPartners(true);
- UpdateDetail();
- UpdateAttr();
- }
- private void ShowUpMode()
- {
- if (PartnersData.Instance.UpModeSelect > 0)
- {
- VM.UpPartner.selectedIndex = 1;
- if (_selectType != 0)
- {
- _selectType = 0;
- RefreshGoneUpPartners(false);
- UpdateDetail();
- }
- }
- else if (EpigraphData.Instance.UpModeSelect > 0)
- {
- VM.UpPartner.selectedIndex = 1;
- if (_selectType != 1)
- {
- _selectType = 1;
- var sbId = PartnersData.Instance.UpSbMap.GetValueOrDefault(_curSelectPos, 0);
- if (sbId == 0)
- {
- RefreshGoneUpPartners(true);
- }
- else
- {
- RefreshGoneUpPartners(false);
- }
- UpdateDetail();
- }
- }
- else
- {
- VM.UpPartner.selectedIndex = 0;
- }
- }
- private void RefreshGoneUpPartners(bool chooseFirstSb)
- {
- if (chooseFirstSb)
- {
- _selectType = 0;
- SelectFirst();
- }
- else if (_selectType == 1)
- {
- var sbId = PartnersData.Instance.UpSbMap.GetValueOrDefault(_curSelectPos, 0);
- if (sbId == 0)
- {
- _selectType = 0;
- SelectFirst();
- }
- }
- var list = new List<PartnerSbUpListItemParam>();
- for (int i = 0; i < PartnersData.GoneUpLimit; i++)
- {
- var data = new PartnerSbUpListItemParam()
- {
- PosId = i,
- CurSelectPos = _curSelectPos,
- SelectType = _selectType,
- };
- list.Add(data);
- }
- VM.SbList.BindDatas(list);
- }
- private void SelectFirst()
- {
- _curSelectPos = 0;
- for (int i = 0; i < PartnersData.GoneUpLimit; i++)
- {
- var sbId = PartnersData.Instance.UpSbMap.GetValueOrDefault(i, 0);
- if (sbId > 0)
- {
- _curSelectPos = i;
- break;
- }
- }
- }
- private void UpdateDetail()
- {
- var sbId = PartnersData.Instance.UpSbMap.GetValueOrDefault(_curSelectPos, 0);
- VM.Page.selectedIndex = _selectType;
- if (_selectType > 0)
- {
- VM.SbDetailNested.Disable();
- VM.MwDetailNested.Enable(null);
- //选择铭文
- var sbData = PartnersData.Instance.GetPartnerAttrByTableId(sbId);
- var mwId = sbData?.EpigraphId ?? 0;
- VM.MwDetailNested.Ctrl.ShowUI(mwId);
- if (mwId > 0)
- {
- VM.IsEmpty.selectedIndex = 0;
- }
- else
- {
- VM.IsEmpty.selectedIndex = 1;
- }
- }
- else
- {
- VM.MwDetailNested.Disable();
- VM.SbDetailNested.Enable(null);
- //选择圣兵
- VM.SbDetailNested.Ctrl.ShowUI(sbId);
- if (sbId == 0)
- {
- VM.IsEmpty.selectedIndex = 1;
- }
- else
- {
- VM.IsEmpty.selectedIndex = 0;
- }
- }
- var gObj = VM.SbList.GetChildAt(_curSelectPos);
- var localPos = gObj.position + VM.SbList.position;
- localPos.x += gObj.width / 2;
- VM.DownArr.x = localPos.x;
- VM.ChangeArr.position = VM.DownArr.position;
- }
- private void UpdateAttr()
- {
- var sbList = PartnersData.Instance.PartnerList;
- int val = 0;
- foreach (var sb in sbList)
- {
- var table = PartnerTableRepo.Get(sb.TableId);
- XGame.Framework.Assert.IsNotNull(table, $"圣兵表不存在,id:{sb.TableId}");
- val += table.Own_attr[1];
- }
- VM.AttrLabel.SetVar("val", (val / 100).ToString()).FlushVars();
- }
- #endregion
- }
- }
|