/// #pkgName FGUI包名
/// #panelName UIPanel名字
/// #UIName = $"{#pkgName}{#panelName}" UIKey名字
/// 该脚本由模板创建
/// created by cb 2024
using System.Collections.Generic;
using FairyGUI;
using FL.Data;
using XGame;
using XGame.Database;
using XGame.Framework.UI;
namespace FL.FGUI
{
///
/// UI逻辑处理类
///
///
public partial class PartnerEpiMainPanelCtrl : UIController
{
private bool _initialized = false;
private bool _showPlanSwitch = false;
//private Controller _switchBtnCtrl;
protected override void OnEnable(object intent)
{
AddUIListenres();
AddEventListenres();
InitList();
UpView();
}
protected override void OnDisable()
{
RemoveUIListenres();
RemoveEventListenres();
ClearView();
}
#region UI事件
private void AddUIListenres()
{
VM.OneUpBtn.onClick.Add(OnClickOneUpBtn);
VM.OneStrongBtn.onClick.Add(OnClickOneStrongBtn);
//VM.ChangeBtn.onClick.Add(OnClickChangeBtn);
VM.MaskBtn.onClick.Add(OnClickMaskBtn);
}
private void RemoveUIListenres()
{
VM.OneUpBtn.onClick.Remove(OnClickOneUpBtn);
VM.OneStrongBtn.onClick.Remove(OnClickOneStrongBtn);
//VM.ChangeBtn.onClick.Remove(OnClickChangeBtn);
VM.MaskBtn.onClick.Remove(OnClickMaskBtn);
}
//private void OnClickChangeBtn(EventContext context)
//{
// _showPlanSwitch = !_showPlanSwitch;
// if (EpigraphData.Instance.UpModeSelect > 0)
// {
// EpigraphService.Instance.FinishUpMode();
// }
// ShowPlanNested();
// RefreshBagEpigraph();
//}
private void OnClickMaskBtn(EventContext context)
{
EpigraphService.Instance.FinishUpMode();
}
#region 事件监听
private void AddEventListenres()
{
Context.AddListener(EventDefine.PartnerUp, OnUpdateAll);
Context.AddListener(EventDefine.PartnerDown, OnUpdateAll);
Context.AddListener(EventDefine.PartnerBinding, OnUpdateAll);
Context.AddListener(EventDefine.PartnerStrongAll, OnUpdateAll);
Context.AddListener(EventDefine.PartnerUpLevel, OnUpdateAll);
Context.AddListener(EventDefine.PartnerUpStar, OnUpdateAll);
Context.AddListener(EventDefine.PartnerWearAll, OnUpdateAll);
Context.AddListener(EventDefine.EpigraphWearAll, OnUpdateAll);
Context.AddListener(EventDefine.EpigraphStrongAll, OnUpdateAll);
Context.AddListener(EventDefine.EpigraphFinishUpMode, OnFinishUpMode);
Context.AddListener(EventDefine.EpigraphOpenUpMode, OnOpenUpMode);
Context.AddListener(EventDefine.EpigraphUpModeSelect, OnEpiUpSelect);
}
private void RemoveEventListenres()
{
Context.RemoveListener(EventDefine.PartnerUp, OnUpdateAll);
Context.RemoveListener(EventDefine.PartnerDown, OnUpdateAll);
Context.RemoveListener(EventDefine.PartnerBinding, OnUpdateAll);
Context.RemoveListener(EventDefine.PartnerStrongAll, OnUpdateAll);
Context.RemoveListener(EventDefine.PartnerUpLevel, OnUpdateAll);
Context.RemoveListener(EventDefine.PartnerUpStar, OnUpdateAll);
Context.RemoveListener(EventDefine.PartnerWearAll, OnUpdateAll);
Context.RemoveListener(EventDefine.EpigraphWearAll, OnUpdateAll);
Context.RemoveListener(EventDefine.EpigraphStrongAll, OnUpdateAll);
Context.RemoveListener(EventDefine.EpigraphFinishUpMode, OnFinishUpMode);
Context.RemoveListener(EventDefine.EpigraphOpenUpMode, OnOpenUpMode);
Context.RemoveListener(EventDefine.EpigraphUpModeSelect, OnEpiUpSelect);
}
#endregion
private void OnClickOneUpBtn(EventContext context)
{
EpigraphService.Instance.RequestEpiWearAll();
}
private void OnClickOneStrongBtn(EventContext context)
{
var list = EpigraphData.Instance.EpiList;
var canUp = false;
foreach (var epigraph in list)
{
var lvTable = epigraphUpTableRepo.GetEpiragphUp(epigraph.TableId, epigraph.StarLv);
if (lvTable == null)
{
Log.Error($"铭文升星表不存在id:{epigraph.TableId},starLv:{epigraph.StarLv}");
}
if (ItemService.Instance.IsEnough(epigraph.TableId, lvTable.LevelUpCost, false))
{
canUp = true;
break;
}
}
if (canUp)
{
EpigraphService.Instance.RequestEpiStrongAll();
}
else
{
Context.ShowTips(StringDefine.EpigraphCantStarUpAll);
}
}
#endregion
#region 事件
private void OnEpiUpSelect(int eventId, object args)
{
var sbId = (int)args;
if (sbId == 0)
{
Context.ShowTips(StringDefine.PartnerCurSlotNoSbTips);
EpigraphService.Instance.FinishUpMode();
return;
}
if (EpigraphData.Instance.UpModeSelect > 0)
{
EpigraphService.Instance.RequestEpiInset(sbId, EpigraphData.Instance.UpModeSelect);
}
}
private void OnReName(int eventId, object args)
{
//UpdatePlanName();
}
private void OnUpdateAll(int eventId, object args)
{
RefreshBagEpigraph();
RefreshGoneUpPartners();
}
private void OnPlanChange(int eventId, object args)
{
//UpdatePlanName();
RefreshBagEpigraph();
RefreshGoneUpPartners();
}
private void OnEpiUpdate(int eventId, object args)
{
RefreshBagEpigraph();
RefreshGoneUpPartners();
}
///
/// 铭文上阵打开事件
///
///
///
private void OnOpenUpMode(int eventId, object args)
{
if (_showPlanSwitch)
{
//ShowPlanNested();
RefreshBagEpigraph();
}
ShowUpMode();
}
private void OnFinishUpMode(int eventId, object args)
{
ShowUpMode();
}
#endregion
private void InitList()
{
if (_initialized)
return;
VM.UpList.ListType = EGListType.None;
VM.BagList.ListType = EGListType.Virtual;
//_switchBtnCtrl = VM.ChangeBtn.GetController("arr");
_initialized = true;
}
private void UpView()
{
RefreshBagEpigraph();
RefreshGoneUpPartners();
//UpdatePlanName();
//ShowPlanNested();
ShowUpMode();
}
private void RefreshGoneUpPartners()
{
var list = new List();
for (int i = 0; i < PartnersData.GoneUpLimit; i++)
{
list.Add(i);
}
VM.UpList.BindDatas(list);
}
//private void UpdatePlanName()
//{
// //VM.PlanLabel.text = plan.Name;
//}
private void RefreshBagEpigraph()
{
if (VM.State.selectedIndex == 1)
return;
var list = EpigraphTableRepo.GetAll();
VM.BagList.BindDatas(list);
ShowOwnerAttr();
}
//private void ShowPlanNested()
//{
// VM.State.selectedIndex = _showPlanSwitch ? 1 : 0;
// //_switchBtnCtrl.selectedIndex = _showPlanSwitch ? 1 : 0;
// if (_showPlanSwitch)
// {
// VM.PlanNested.Enable(null);
// VM.PlanNested.Ctrl.ShowUI();
// }
// else
// {
// VM.PlanNested.Disable();
// }
//}
private void ShowUpMode()
{
if (PartnersData.Instance.UpModeSelect > 0)
{
VM.SelectMode.selectedIndex = 1;
}
else if (EpigraphData.Instance.UpModeSelect > 0)
{
VM.SelectMode.selectedIndex = 1;
}
else
{
VM.SelectMode.selectedIndex = 0;
}
}
private void ClearView()
{
EpigraphService.Instance.FinishUpMode();
PartnersService.Instance.FinishUpPartnerMode();
_showPlanSwitch = false;
}
public void ShowOwnerAttr()
{
var list = EpigraphData.Instance.EpiList;
//var map = new Dictionary();
var val = 0;
foreach (var epigraph in list)
{
var starTable = epigraphUpTableRepo.GetEpiragphUp(
epigraph.TableId,
epigraph.StarLv
);
if (starTable == null)
{
Log.Error($"铭文升星表不存在id:{epigraph.TableId},starLv:{epigraph.StarLv}");
continue;
}
var attrsArray = starTable.LvOwnAttr;
if (attrsArray?.Length > 0)
{
//for (int i = 0; i < attrsArray.Length; i += 2)
//{
// if (map.TryGetValue(attrsArray[i], out var attr))
// {
// map.Remove(attrsArray[i]);
// map.Add(attrsArray[i], attr + attrsArray[i + 1]);
// }
// else
// {
// map.Add(attrsArray[i], attrsArray[i + 1]);
// }
//}
val += attrsArray[1];
}
}
VM.AttrLabel.SetVar("val", (val / 100).ToString()).FlushVars();
//if (map.Count > 0)
//{
// var desc = StringBuilderUtils.Acquire();
// int index = 0;
// foreach (var pair in map)
// {
// if (index > 0)
// {
// desc.Append(",");
// index++;
// }
// GetAttributeDesc(pair.Key, pair.Value, ref desc);
// }
// VM.AttrLabel.text = desc.ToString();
// VM.HaveLabel.visible = true;
// VM.AttrLabel.visible = true;
//}
//else
//{
// VM.HaveLabel.visible = false;
// VM.AttrLabel.visible = false;
//}
}
//private void GetAttributeDesc(int attrType, int attrValue, ref StringBuilder desc)
//{
// var attributeInfo = AttrDescTableRepo.Get(attrType);
// string valStr = attrValue > 0 ? TableUtils.ToRealDouble(attrValue).ToString("F2") : "0";
// desc.Append(attributeInfo?.ShowName);
// desc.Append(valStr);
// desc.Append("%");
//}
}
}