123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569 |
- /// #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 Unity.Jobs;
- using XGame.Database;
- using XGame.Framework.UI;
- using XGame.Framework.Utils;
- namespace FL.FGUI
- {
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class PlayerAwakePanelCtrl : UIController<PlayerAwakePanelVM>
- {
- 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<PlayerImprintItemNestedCtrl> _imprintItemList;
- private List<runeTable> _runeTableList;
- private int[] _runeIdArray; // 印记槽位镶嵌的符文id数组
- protected override void OnEnable(object intent)
- {
- AddUIListenres();
- AddEventListner();
- InitUI();
- ShowUI();
- }
- protected override void OnDisable()
- {
- RemoveUIListenres();
- RemoveEventListner();
- _selectImprint = 0;
- 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);
- }
- /// <summary>
- /// 显示方案选择列表
- /// </summary>
- /// <param name="context"></param>
- private void OnClickPlansNameBtn(EventContext context)
- {
- ShowPlansNameNestedItem(!_bShowPlansName);
- }
- /// <summary>
- /// 修改方案名
- /// </summary>
- /// <param name="context"></param>
- 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);
- }
- /// <summary>
- /// 随机觉醒按钮
- /// </summary>
- /// <param name="context"></param>
- private void OnClickWakeupBtn(EventContext context)
- {
- if (VM.AwakeCtrl.selectedIndex == 1)
- {
- // 前往觉醒
- Context.UI.OpenAsync(UIKeys.PlayerTransferPanel);
- Context.ClosePanel();
- return;
- }
- else if (VM.AwakeCtrl.selectedIndex == 2)
- {
- // 职业预览
- Context.UI.OpenAsync(UIKeys.PlayerJobCareerPreviewPanel);
- Context.ClosePanel();
- return;
- }
- // 随机觉醒槽位(符文)
- 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();
- }
- /// <summary>
- /// 升级1次印记
- /// </summary>
- /// <param name="context"></param>
- private void OnClickUpgradeBtn(EventContext context)
- {
- if (!ItemService.Instance.IsEnough(_upgradeItemId, _upgradeCostVal, true))
- return;
- PlayerService.Instance.SendToUpgradeRune(_selectImprint+1,1);
- }
- /// <summary>
- /// 升级10次印记
- /// </summary>
- /// <param name="context"></param>
- 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<PlayerImprintItemNestedCtrl>
- {
- VM.ImprintItem1.Ctrl,VM.ImprintItem2.Ctrl,VM.ImprintItem3.Ctrl,
- VM.ImprintItem4.Ctrl,VM.ImprintItem5.Ctrl,VM.ImprintItem6.Ctrl,
- };
- }
- if (_runeTableList == null)
- {
- _runeTableList = new List<runeTable>();
- _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);
- }
- /// <summary>
- /// 加载主角的spine
- /// </summary>
- /// <param name="spineName"></param>
- 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 bHighestJob = false; // 已到达觉醒最高阶
- 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;
- }
- }
- VM.LockCtrl.selectedIndex = bAllLock ? 1 : 0;
- if (!bWaitAwake)
- {
- var curJobInfo = careerTableRepo.Get(PlayerData.Instance.JobId);
- if (curJobInfo?.Job_change.Length == 0)
- {
- bHighestJob = true;
- }
- }
- VM.AwakeCtrl.selectedIndex = bWaitAwake ? 0 : (bHighestJob ? 2 : 1);
- if (bInit && _runeIdArray[_selectImprint] == 0)
- {
- for (int i = 0; i < _runeIdArray.Length; i++)
- {
- if (_runeIdArray[i] > 0)
- {
- _selectImprint = i;
- break;
- }
- }
- }
- ShowImprintRuneUI();
- }
- /// <summary>
- /// 显示印记镶嵌的符文UI
- /// </summary>
- private void ShowImprintRuneUI()
- {
- for (int i = 0; i < _runeIdArray.Length; i++)
- {
- if (_imprintItemList[i] != null)
- {
- _imprintItemList[i].ShowUI(i,_runeIdArray[i], OnclcickImprintItem);
- }
- }
- OnclcickImprintItem(_selectImprint);
- }
- /// <summary>
- /// 觉醒印记消耗
- /// </summary>
- /// <param name="index"></param>
- 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);
- }
- }
- /// <summary>
- /// 升级印记消耗
- /// </summary>
- /// <param name="runeId"></param>
- 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);
- }
- }
- /// <summary>
- /// 点击印记项
- /// </summary>
- /// <param name="imprintIndex"></param>
- private void OnclcickImprintItem(int imprintIndex)
- {
- _selectImprint = imprintIndex;
- ShowImprintItemUI(imprintIndex);
- for (int i = 0; i < _imprintItemList.Count; i++)
- {
- _imprintItemList[i].ShowSelectUI(i == imprintIndex);
- }
- }
- /// <summary>
- /// 获取某个槽位上的符文id
- /// </summary>
- /// <param name="index"></param>
- 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;
- }
- /// <summary>
- /// 显示点击的印记项信息
- /// </summary>
- /// <param name="index"></param>
- 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);
- }
- }
- /// <summary>
- /// 道具变化
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void UpdataItemData(int eventId, object args)
- {
- int runeId = GetRuneId(_selectImprint+1);
- var itemDataList = args as List<ActItem>;
- 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);
- }
- }
- }
- }
- }
- /// <summary>
- /// 成功激活印记(镶嵌符文)
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void WakeUpRuneSucess(int eventId, object args)
- {
- ShowImprintUI();
- }
- /// <summary>
- /// 成功提升印记(符文)等级
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void UpgradeRuneLvSucess(int eventId, object args)
- {
- ShowImprintUI();
- }
- /// <summary>
- /// 切换符文方案
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void ChangePlanIndexSucess(int eventId, object args)
- {
- _selectImprint = 0;
- _selectPlanIndex = PlayerData.Instance.CurPlanIndex;
- ShowImprintUI();
- }
- /// <summary>
- /// 成功重置当前方案
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void ResetCurrentPlanSucess(int eventId, object args)
- {
- ShowImprintUI();
- }
- /// <summary>
- /// 成功更换印记类型
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void ChangeRuneTypeSucess(int eventId, object args)
- {
- ShowImprintItemUI(_selectImprint);
- }
- /// <summary>
- /// 成功修改符文方案名字
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void ChangePlanNameSucess(int eventId, object args)
- {
- SelectPlanNameItem(_selectPlanIndex);
- }
- /// <summary>
- /// 修改方案名
- /// </summary>
- /// <param name="rename">要修改的名称</param>
- /// <param name="bChange">确定修改</param>
- private void RenameCallback(string changeName, bool bChange)
- {
- if (bChange)
- {
- PlayerService.Instance.SendToAlterPlanName(changeName,_selectPlanIndex);
- }
- }
- /// <summary>
- /// 显示印记方案列表UI
- /// </summary>
- /// <param name="bShow"></param>
- 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();
- }
- }
- /// <summary>
- /// 选择(符文升级)方案
- /// </summary>
- /// <param name="index"></param>
- private void SelectPlanNameItem(int index)
- {
- if (index > 0 && PlayerData.Instance.RunePlanNamesArray.Count > 0)
- {
- PlayerService.Instance.SendToChangePlanIndex(index);
- VM.PlansNameBtn.title = PlayerData.Instance.RunePlanNamesArray[index-1];
- }
- ShowPlansNameNestedItem(false);
- }
- }
- }
|