/// #pkgName FGUI包名
/// #panelName UIPanel名字
/// #UIName = $"{#pkgName}{#panelName}" UIKey名字
/// 该脚本由模板创建
/// created by cb 2024
using FairyGUI;
using FL.Data;
using FL.Network;
using System.Collections.Generic;
using XGame.Database;
using XGame.Framework.UI;
using XGame.Framework.Utils;
namespace FL.FGUI
{
///
/// UI逻辑处理类
///
///
public partial class PlayerAwakePanelCtrl : UIController
{
private bool _bShowPlansName; // 方案名称下拉列表UI是否显示状态
private int _selectPlanIndex; // 当前选中的方案索引
private int _selectImprint; // 当前选中的印记索引
private int _awakeItemId; // 觉醒道具id
private int _awakeCostVal; // 觉醒需要的道具数量
private int _upgradeItemId; // 升级印记道具id
private int _upgradeCostVal;// 升级需要的道具数量
private List _imprintItemList;
private List _runeTableList;
private int[] _runeIdArray; // 印记槽位镶嵌的符文id数组
protected override void OnEnable(object intent)
{
AddUIListenres();
AddEventListner();
InitUI();
ShowUI();
}
protected override void OnDisable()
{
RemoveUIListenres();
RemoveEventListner();
if (_imprintItemList != null)
{
_imprintItemList.Clear();
_imprintItemList = null;
}
if (_runeTableList != null)
{
_runeTableList.Clear();
_runeTableList = null;
}
if (_runeIdArray != null) _runeIdArray = null;
}
#region UI事件
private void AddUIListenres()
{
VM.PlansNameBtn.onClick.Add(OnClickPlansNameBtn);
VM.RenameBtn.onClick.Add(OnClickRenameBtn);
VM.WakeupBtn.onClick.Add(OnClickWakeupBtn);
VM.ResetBtn.onClick.Add(OnClickResetBtn);
VM.ChangeImprintBtn.onClick.Add(OnClickChangeImprintBtn);
VM.BackBtn.onClick.Add(OnClickBackBtn);
VM.UpgradeBtn.onClick.Add(OnClickUpgradeBtn);
VM.TenBtn.onClick.Add(OnClickTenBtn);
}
private void RemoveUIListenres()
{
VM.PlansNameBtn.onClick.Remove(OnClickPlansNameBtn);
VM.RenameBtn.onClick.Remove(OnClickRenameBtn);
VM.WakeupBtn.onClick.Remove(OnClickWakeupBtn);
VM.ResetBtn.onClick.Remove(OnClickResetBtn);
VM.ChangeImprintBtn.onClick.Remove(OnClickChangeImprintBtn);
VM.BackBtn.onClick.Remove(OnClickBackBtn);
VM.UpgradeBtn.onClick.Remove(OnClickUpgradeBtn);
VM.TenBtn.onClick.Remove(OnClickTenBtn);
}
///
/// 显示方案选择列表
///
///
private void OnClickPlansNameBtn(EventContext context)
{
ShowPlansNameNestedItem(!_bShowPlansName);
}
///
/// 修改方案名
///
///
private void OnClickRenameBtn(EventContext context)
{
var param = new RenameParam()
{
title = StringDefine.AwakeRenameTitle,
tipsDesc = StringDefine.AwakeRenameDesc,
limitWordCount = 5,
renameCallback = RenameCallback,
};
Context.UI.OpenAsync(UIKeys.CommonRenamePanel, param);
}
///
/// 随机觉醒按钮
///
///
private void OnClickWakeupBtn(EventContext context)
{
if (!ItemService.Instance.IsEnough(_awakeItemId, _awakeCostVal, true))
return;
PlayerService.Instance.SendToWakeupRune();
}
private void OnClickResetBtn(EventContext context)
{
ConfirmationBoxParam dialogParam = new ConfirmationBoxParam()
{
cnt = StringDefine.resetCurrentPlan,
onPromiseCallback = PlayerService.Instance.SendToResetPlan
};
Context.UI.OpenAsync(UIKeys.CommonConfirmationBox, dialogParam);
}
private void OnClickChangeImprintBtn(EventContext context)
{
Context.UI.OpenAsync(UIKeys.PlayerChangeImprintPanel,_selectImprint);
}
private void OnClickBackBtn(EventContext context)
{
Context.ClosePanel();
}
///
/// 升级1次印记
///
///
private void OnClickUpgradeBtn(EventContext context)
{
if (!ItemService.Instance.IsEnough(_upgradeItemId, _upgradeCostVal, true))
return;
PlayerService.Instance.SendToUpgradeRune(_selectImprint+1,1);
}
///
/// 升级10次印记
///
///
private void OnClickTenBtn(EventContext context)
{
if (!ItemService.Instance.IsEnough(_upgradeItemId, _upgradeCostVal*10, true))
return;
PlayerService.Instance.SendToUpgradeRune(_selectImprint+1, 10);
}
#endregion
private void AddEventListner()
{
EventSingle.Instance.AddListener(EventDefine.UpdataItemData, UpdataItemData);
EventSingle.Instance.AddListener(EventDefine.WakeUpRuneSucess, WakeUpRuneSucess);
EventSingle.Instance.AddListener(EventDefine.UpgradeRuneLvSucess, UpgradeRuneLvSucess);
EventSingle.Instance.AddListener(EventDefine.ChangePlanIndexSucess, ChangePlanIndexSucess);
EventSingle.Instance.AddListener(EventDefine.ResetCurrentPlanSucess,ResetCurrentPlanSucess);
EventSingle.Instance.AddListener(EventDefine.ChangePlanNameSucess, ChangePlanNameSucess);
EventSingle.Instance.AddListener(EventDefine.ChangeRuneTypeSucess, ChangeRuneTypeSucess);
}
private void RemoveEventListner()
{
EventSingle.Instance.RemoveListener(EventDefine.UpdataItemData, UpdataItemData);
EventSingle.Instance.RemoveListener(EventDefine.WakeUpRuneSucess, WakeUpRuneSucess);
EventSingle.Instance.RemoveListener(EventDefine.UpgradeRuneLvSucess, UpgradeRuneLvSucess);
EventSingle.Instance.RemoveListener(EventDefine.ChangePlanIndexSucess, ChangePlanIndexSucess);
EventSingle.Instance.RemoveListener(EventDefine.ResetCurrentPlanSucess,ResetCurrentPlanSucess);
EventSingle.Instance.RemoveListener(EventDefine.ChangePlanNameSucess, ChangePlanNameSucess);
EventSingle.Instance.RemoveListener(EventDefine.ChangeRuneTypeSucess, ChangeRuneTypeSucess);
}
private void InitUI()
{
_selectImprint = 0;
_selectPlanIndex = PlayerData.Instance.CurPlanIndex;
SelectPlanNameItem(_selectPlanIndex);
if (_imprintItemList == null)
{
_imprintItemList = new List
{
VM.ImprintItem1.Ctrl,VM.ImprintItem2.Ctrl,VM.ImprintItem3.Ctrl,
VM.ImprintItem4.Ctrl,VM.ImprintItem5.Ctrl,VM.ImprintItem6.Ctrl,
};
}
if (_runeTableList == null)
{
_runeTableList = new List();
_runeTableList.AddRange(runeTableRepo.GetAll());
_runeTableList.Sort((a, b) =>
{
return a.Id.CompareTo(b.Id);//升序
});
}
if (_runeIdArray == null) _runeIdArray = new int[_runeTableList.Count];
}
private void ShowUI()
{
ShowPlayerSpine("info_job_1001_1_SkeletonData");
ShowImprintUI(true);
ShowAwakeCostUI(1);
}
///
/// 加载主角的spine
///
///
private void ShowPlayerSpine(string spineName)
{
VM.JobSpine.LoadSpine(spineName, "stand", true);
}
private void ShowImprintUI(bool bInit = false)
{
RunePlan runePlanData = PlayerData.Instance.RunePlanMap[_selectPlanIndex];
bool bAllLock = true;
bool bMaxLv = true;
bool bWaitAwake = false;
int index = 0;
foreach (var rune in runePlanData.slot)
{
_runeIdArray[index] = rune.runeId;
index++;
if (bAllLock && rune.runeId > 0)
{
bAllLock = false;
}
if (!bWaitAwake && rune.runeId == 0)
{
bWaitAwake = true;
}
if (bMaxLv)
{
if (rune.runeId == 0)
bMaxLv = false;
else
{
var runeLvInfo = rune_levelTableRepo.Get(rune.runeId);
if (runeLvInfo != null)
{
var nextLvInfo = rune_expTableRepo.Get(runeLvInfo.Level + 1);
if (nextLvInfo != null)
{
bMaxLv = false;
}
}
}
}
}
VM.LockCtrl.selectedIndex = bAllLock ? 1 : 0;
VM.AwakeCtrl.selectedIndex = bMaxLv ? 2 : (bWaitAwake ? 0 : 1);
if (bInit && _runeIdArray[_selectImprint] == 0)
{
for (int i = 0; i < _runeIdArray.Length; i++)
{
if (_runeIdArray[i] > 0)
{
_selectImprint = i;
break;
}
}
}
ShowImprintRuneUI();
}
///
/// 显示印记镶嵌的符文UI
///
private void ShowImprintRuneUI()
{
for (int i = 0; i < _runeIdArray.Length; i++)
{
if (_imprintItemList[i] != null)
{
_imprintItemList[i].ShowUI(i,_runeIdArray[i], OnclcickImprintItem);
}
}
OnclcickImprintItem(_selectImprint);
}
///
/// 觉醒印记消耗
///
///
private void ShowAwakeCostUI(int index)
{
var info = _runeTableList[index];
if (info != null)
{
_awakeItemId = info.LevelUpCost[0];
_awakeCostVal = info.LevelUpCost[1];
VM.AwakeCostItem.Ctrl.ShowCostUI(_awakeItemId, _awakeCostVal, 0);
}
}
///
/// 升级印记消耗
///
///
private void ShowUpgradeCostUI(int runeId)
{
var runeLvInfo = rune_levelTableRepo.Get(runeId);
if (runeLvInfo == null) return;
var runeExpInfo = rune_expTableRepo.Get(runeLvInfo.Level);
if (runeExpInfo?.Cost?.Length > 1)
{
_upgradeItemId = runeExpInfo.Cost[0];
_upgradeCostVal = runeExpInfo.Cost[1];
RunePlan runePlanData = PlayerData.Instance.RunePlanMap[_selectPlanIndex];
// allPoint - 当前方案的subPoint) + 玩家的道具
int upgradePoint = PlayerData.Instance.AllPoint - runePlanData.subPoint + (int)ItemData.Instance.GetItemNum(_upgradeItemId);
VM.UpgradeCostItem.Ctrl.ShowCostUI(_upgradeItemId, _upgradeCostVal, upgradePoint);
VM.TenCostItem.Ctrl.ShowCostUI(_upgradeItemId, _upgradeCostVal*10, upgradePoint);
}
}
///
/// 点击印记项
///
///
private void OnclcickImprintItem(int imprintIndex)
{
_selectImprint = imprintIndex;
ShowImprintItemUI(imprintIndex);
for (int i = 0; i < _imprintItemList.Count; i++)
{
_imprintItemList[i].ShowSelectUI(i == imprintIndex);
}
}
///
/// 获取某个槽位上的符文id
///
///
private int GetRuneId(int index)
{
RunePlan runePlanData = PlayerData.Instance.RunePlanMap[_selectPlanIndex];
foreach (var item in runePlanData.slot)
{
if (item.id == index)
{
return item.runeId;
}
}
return 0;
}
///
/// 显示点击的印记项信息
///
///
private void ShowImprintItemUI(int index)
{
int runeId = GetRuneId(index+1);
bool bShowChangeImprintBtn = true;
int lvCtrlIndex = 0;
if (runeId == 0)
{
// 展示信息 槽位id * 10000 + 符文类型 * 1000
runeId = (index+1) * 10000 + 1001;
bShowChangeImprintBtn = false;
}
else
{
var runeLevelInfo = rune_levelTableRepo.Get(runeId);
if (runeLevelInfo == null)
lvCtrlIndex = 2;
else
{
var runeExpInfo = rune_expTableRepo.Get(runeLevelInfo.Level +1);
lvCtrlIndex = runeExpInfo == null ? 2 : 1;
}
}
var imprintInfo = _runeTableList[index];
if (imprintInfo != null)
{
int runeType = (runeId - (index+1) * 10000) / 1000 - 1;
VM.ImprintNameLabel.text = imprintInfo.Name[runeType];
if (bShowChangeImprintBtn && imprintInfo.Handoff.Length == 1) bShowChangeImprintBtn = false;
}
ShowRuneAttrUI(runeId);
ShowUpgradeCostUI(runeId);
VM.ChangeImprintBtn.visible = bShowChangeImprintBtn;
VM.LevelCtrl.selectedIndex = lvCtrlIndex;
}
private void ShowRuneAttrUI(int runeId)
{
var runeInfo = rune_levelTableRepo.Get(runeId);
if (runeInfo != null)
{
var sb = StringBuilderUtils.Acquire();
for (int i = 0; i < runeInfo.Value_plus.Length; i+=2)
{
var attributeInfo = AttrDescTableRepo.Get(runeInfo.Value_plus[i]);
if (attributeInfo != null)
{
sb.Append(attributeInfo.ShowName);
sb.Append("[color=#1EF369]+");
sb.Append(attributeInfo.Num_type == 1 ? TableUtils.ToRealDouble(runeInfo.Value_plus[i+1]).ToString("F3") + "%" :
(attributeInfo.Id == (int)EAttributeType.AtkSpeed ? TableUtils.ToRealDouble(runeInfo.Value_plus[i + 1]).ToString("F1") : runeInfo.Value_plus[i + 1].ToString()));
sb.Append("[/color]");
}
}
VM.ImprintDescLabel.text = sb.ToString();
StringBuilderUtils.Release(sb);
}
}
///
/// 道具变化
///
///
///
private void UpdataItemData(int eventId, object args)
{
int runeId = GetRuneId(_selectImprint+1);
var itemDataList = args as List;
if (itemDataList?.Count > 0)
{
for (int i = 0; i < itemDataList.Count; i++)
{
if (itemDataList[i].count > 0)
{
if (itemDataList[i].id == _awakeItemId)
{
ShowAwakeCostUI(1);
}
if (runeId > 0 && itemDataList[i].id == _upgradeItemId)
{
ShowUpgradeCostUI(runeId);
}
}
}
}
}
///
/// 成功激活印记(镶嵌符文)
///
///
///
private void WakeUpRuneSucess(int eventId, object args)
{
ShowImprintUI();
}
///
/// 成功提升印记(符文)等级
///
///
///
private void UpgradeRuneLvSucess(int eventId, object args)
{
ShowImprintUI();
}
///
/// 切换符文方案
///
///
///
private void ChangePlanIndexSucess(int eventId, object args)
{
_selectImprint = PlayerData.Instance.CurPlanIndex;
ShowImprintUI();
}
///
/// 成功重置当前方案
///
///
///
private void ResetCurrentPlanSucess(int eventId, object args)
{
ShowImprintUI();
}
///
/// 成功更换印记类型
///
///
///
private void ChangeRuneTypeSucess(int eventId, object args)
{
ShowImprintItemUI(_selectImprint);
}
///
/// 成功修改符文方案名字
///
///
///
private void ChangePlanNameSucess(int eventId, object args)
{
SelectPlanNameItem(_selectPlanIndex);
}
///
/// 修改方案名
///
/// 要修改的名称
/// 确定修改
private void RenameCallback(string changeName, bool bChange)
{
if (bChange)
{
PlayerService.Instance.SendToAlterPlanName(changeName,_selectPlanIndex);
}
}
///
/// 显示印记方案列表UI
///
///
private void ShowPlansNameNestedItem(bool bShow)
{
_bShowPlansName = bShow;
VM.PlansNameBtn.GetController("ComboBoxCtrl").selectedIndex = bShow ? 1 : 0;
if (bShow)
{
VM.PlansNameNestedItem.Enable(null);
VM.PlansNameNestedItem.Ctrl.ShowUI(SelectPlanNameItem);
}
else
{
VM.PlansNameNestedItem.Disable();
}
}
///
/// 选择(符文升级)方案
///
///
private void SelectPlanNameItem(int index)
{
if (index > 0 && PlayerData.Instance.RunePlanNamesArray.Count > 0)
{
VM.PlansNameBtn.title = PlayerData.Instance.RunePlanNamesArray[index-1];
}
ShowPlansNameNestedItem(false);
}
}
}