/// #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 PartnerSbMainPanelCtrl : UIController
{
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();
}
}
///
/// 圣兵上阵打开事件
///
///
///
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;
///
/// 选择类型,0圣兵,1铭文
///
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();
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
}
}