Files
back_cantanBuilding/Assets/Scripts/UI/Rod/FishingRodPanel_Ascend.cs
2026-05-26 16:15:54 +08:00

307 lines
10 KiB
C#

using asap.core;
using cfg;
using GameCore;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public partial class FishingRodPanel : BasePanel
{
[Header("升阶")]
public GameObject perks;
public Perk perk_before;
public Button btn_perk_before;
public Perk perk_after;
public Button btn_perk_after;
RodAttributeInfoRoot ascendRodAttribute;
public RodAttributeInfo lvInfo;
List<int> ascend_upIndexList = new List<int>();
Button ascend_btn_upgrade;
Button ascend_btn_upgrade_gray;
GameObject ascend_cost;
GameObject icon_cost_1;
TMP_Text icon_cost_1_num;
TMP_Text icon_cost_2_num;
Image icon_ticket_1;
Image icon_ticket_2;
int perkIndex;
void InitAscendUpPanel()
{
ascendRodAttribute = AscendRoot.Find("level_info/attribute").GetComponent<RodAttributeInfoRoot>();
ascend_btn_upgrade = AscendRoot.Find("btn_all/btn_levelup/btn_green").GetComponent<Button>();
ascend_btn_upgrade_gray = AscendRoot.Find("btn_all/btn_levelup_gray/btn_green").GetComponent<Button>();
ascend_cost = AscendRoot.Find("cost").gameObject;
icon_cost_1 = ascend_cost.transform.Find("icon_cost_1").gameObject;
icon_cost_1_num = ascend_cost.transform.Find("icon_cost_1/text_num").GetComponent<TMP_Text>();
icon_cost_2_num = ascend_cost.transform.Find("icon_cost_2/text_num").GetComponent<TMP_Text>();
icon_ticket_1 = ascend_cost.transform.Find("icon_cost_1/icon_ticket").GetComponent<Image>();
icon_ticket_2 = ascend_cost.transform.Find("icon_cost_2/icon_ticket").GetComponent<Image>();
ascend_btn_upgrade.onClick.AddListener(OnClickAscendUp);
ascend_btn_upgrade_gray.onClick.AddListener(OnClickAscendGray);
var rodBasicStats = _tables.TbRodBasicStats.DataList;
for (int i = 0; i < 3; i++)
{
ascendRodAttribute.rodAttributes[i].icon.sprite = uIService.GetSprite(rodBasicStats[i].Icon);
ascendRodAttribute.rodAttributes[i].text_name.text = LocalizationMgr.GetText(rodBasicStats[i].Title_l10n_key);
int index = i;
Button btn = ascendRodAttribute.rodAttributes[i].btn;
btn.onClick.AddListener(() =>
{
ShowAttributes(index, btn.transform);
});
}
btn_perk_before.onClick.AddListener(() =>
{
ShowPerk(perkIndex, btn_perk_before.transform, 0);
});
btn_perk_after.onClick.AddListener(() =>
{
ShowPerk(perkIndex, btn_perk_after.transform, 1);
});
}
void OpenAscendRoot()
{
InitAscend();
}
void OnClickAscendGray()
{
GContext.Publish(new VibrationData(HapticTypes.Failure));
//提示材料不足
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_66"));
}
void OnClickAscendUp()
{
if (data.isMax)
{
ShowAscendRoot(false);
return;
}
OnClickUpgrade();
ShowFishingRodAscendPopupPanel();
SetAscend();
}
public void OnClickUpgrade()
{
RodAscend _rodAscend = _tables.TbRodAscend.GetOrDefault(data.config.AscendID);
bool isLock = playerFishData.NotRod(data.config.ID);
//消耗材料升级
GContext.Publish(new VibrationData(HapticTypes.Selection));
playerFishData.AscendRod(data.config.ID);
int star = playerFishData.GetRodPiece(data.config.ID);
if (isLock)
{
data.isLock = false;
}
bool isMax = star >= _rodAscend.MaxAscent;
data.star = star;
data.isMax = isMax;
SetLevelStar();
SetPanelData();
//鱼竿权益积分飞入
//PlayUpAni();
}
async void ShowFishingRodAscendPopupPanel()
{
GameObject go = await UIManager.Instance.ShowUI(new UIType("FishingRodAscendPopupPanel"));
if (go != null)
{
var panel = go.GetComponent<FishingRodAscendPopupPanel>();
panel.SetCurData(data, perk_before.bg.sprite);
}
else
{
Debug.LogError("Failed to open FishingRodAscendPopupPanel");
}
}
void InitAscend()
{
ascend_upIndexList.Clear();
RodData rodData = data.config;
curRodAscend = _tables.TbRodAscend.GetOrDefault(rodData.AscendID);
Item item = _tables.TbItem.GetOrDefault(curRodAscend.FragmentID);
icon_ticket_2.sprite = uIService.GetSprite(item.Icon);
RodFragmentExchange rodFragmentExchange = _tables.TbRodFragmentExchange.GetOrDefault(data.config.Quality);
if (rodFragmentExchange != null)
{
item = _tables.TbItem.GetOrDefault(rodFragmentExchange.GeneralFragmentID);
icon_ticket_1.sprite = uIService.GetSprite(item.Icon);
}
SetAscend();
}
void SetEP(int star)
{
int perkIDListCount = curRodAscend.PerkIDList.Count;
var perkUnlockOrder = curRodAscend.PerkUnlockOrder;
int[] lv = playerFishData.GetPerkLevel(perkIDListCount, star, curRodAscend.DefaultPerk, perkUnlockOrder);
//要升下一级箭头提示
perkIndex = -1;
if (star < perkUnlockOrder.Count)
{
perkIndex = perkUnlockOrder[star] - 1;
perks.SetActive(true);
perk_before.SetData(curRodAscend.PerkIDList[perkIndex], lv[perkIndex], config.Quality);
perk_after.SetData(curRodAscend.PerkIDList[perkIndex], lv[perkIndex] + 1, config.Quality);
}
else
{
perks.SetActive(false);
}
}
int ShowCost(int rquiredFragments)
{
RodFragmentExchange rodFragmentExchange = _tables.TbRodFragmentExchange.GetOrDefault(data.config.Quality);
int fragment = GContext.container.Resolve<PlayerFishData>().GetRodPiece(rodFragmentExchange.GeneralFragmentID) / rodFragmentExchange.ExchangeRate;
if (fragment == 0)
{
icon_cost_1.SetActive(false);
return rquiredFragments;
}
int count;
if (fragment >= rquiredFragments)
{
count = rquiredFragments * rodFragmentExchange.ExchangeRate;
}
else
{
count = fragment * rodFragmentExchange.ExchangeRate;
}
icon_cost_1_num.text = $"<color=green>{count}</color>/{count}";
return rquiredFragments - fragment;
}
void SetAscendCost(int star)
{
bool isUp = false;
int fragment = GContext.container.Resolve<PlayerFishData>().GetRodPiece(curRodAscend.FragmentID);
int rquiredFragments = curRodAscend.AscentTransformed[star + 1];
if (fragment < rquiredFragments)
{
icon_cost_1.SetActive(true);
rquiredFragments -= fragment;
rquiredFragments = ShowCost(rquiredFragments);
if (rquiredFragments <= 0)
{
isUp = true;
icon_cost_2_num.text = $"<color=green>{fragment} </color>/{fragment}";
}
else
{
icon_cost_2_num.text = $"<color=red>{fragment}</color>/{fragment + rquiredFragments}";
}
}
else
{
icon_cost_2_num.text = $"<color=green>{fragment} </color>/{rquiredFragments}";
isUp = true;
icon_cost_1.SetActive(false);
}
ascend_btn_upgrade.gameObject.SetActive(isUp);
ascend_btn_upgrade_gray.gameObject.SetActive(!isUp);
}
void SetAscend()
{
RodData rodData = data.config;
int star = GContext.container.Resolve<PlayerFishData>().GetRodPiece(rodData.ID);
ascend_cost.SetActive(!data.isMax);
ascend_upIndexList.Clear();
SetEP(star);
if (!data.isMax)
{
SetAscendCost(star);
var values = GContext.container.Resolve<PlayerFishData>().GetRodAttribute(rodData.ID);
var values2 = GContext.container.Resolve<PlayerFishData>().GetRodAttribute(rodData.ID, starAdd: 1);
for (int i = 0; i < values.Count; i++)
{
RodAttributeInfo rodAttribute = ascendRodAttribute.rodAttributes[i];
var curValue = values[i];
rodAttribute.text_num.text = curValue.ToString();
var nextValue = values2[i];
if (curValue != nextValue)
{
rodAttribute.text_after.text = nextValue.ToString();
rodAttribute.text_after.gameObject.SetActive(true);
rodAttribute.arrow.gameObject.SetActive(true);
ascend_upIndexList.Add(i);
}
else
{
rodAttribute.text_after.gameObject.SetActive(false);
rodAttribute.arrow.gameObject.SetActive(false);
}
}
}
else
{
ascend_btn_upgrade.gameObject.SetActive(true);
ascend_btn_upgrade_gray.gameObject.SetActive(false);
var values = GContext.container.Resolve<PlayerFishData>().GetRodAttribute(rodData.ID);
for (int i = 0; i < values.Count; i++)
{
var curValue = values[i];
RodAttributeInfo rodAttribute = ascendRodAttribute.rodAttributes[i];
rodAttribute.text_num.text = curValue.ToString();
rodAttribute.text_after.gameObject.SetActive(false);
rodAttribute.arrow.gameObject.SetActive(false);
}
}
SetLevelShow(star);
}
void SetLevelShow(int star)
{
RodLevelup rodLevelup = _tables.TbRodLevelup.GetOrDefault(data.config.LevelupID);
List<int> Millestones = rodLevelup.Millestones;
if (star >= Millestones.Count)
{
lvInfo.text_num.text = Millestones[Millestones.Count - 1].ToString();
lvInfo.text_after.gameObject.SetActive(false);
lvInfo.arrow.gameObject.SetActive(false);
}
else if (star == Millestones.Count - 1)
{
lvInfo.text_num.text = Millestones[star].ToString();
lvInfo.text_after.text = rodLevelup.MaxLevel.ToString();
lvInfo.text_after.gameObject.SetActive(true);
lvInfo.arrow.gameObject.SetActive(true);
}
else
{
lvInfo.text_num.text = Millestones[star].ToString();
lvInfo.text_after.text = Millestones[star + 1].ToString();
lvInfo.text_after.gameObject.SetActive(true);
lvInfo.arrow.gameObject.SetActive(true);
}
}
}