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

89 lines
3.0 KiB
C#

using System.Collections.Generic;
using asap.core;
using cfg;
using GameCore;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class FishingRodRewardPopupPanel : MonoBehaviour
{
Button btn_close;
Button btn_mask;
private TMP_Text textLevel;
private TMP_Text text_bar;
private Image image_bar;
private List<RodLevelupStats> dataList;
GameObject change;
TMP_Text text_num_before;
TMP_Text text_num_after;
GameObject max;
TMP_Text text_num_max;
private void Awake()
{
btn_close = transform.Find("btn_close").GetComponent<Button>();
btn_mask = transform.Find("mask").GetComponent<Button>();
textLevel = transform.Find("root/bg_level/text_level").GetComponent<TMP_Text>();
text_bar = transform.Find("root/bg_bar/text_bar").GetComponent<TMP_Text>();
image_bar = transform.Find("root/bg_bar/bar").GetComponent<Image>();
change = transform.Find("root/enhace/change").gameObject;
text_num_before = transform.Find("root/enhace/change/text_num_before").GetComponent<TMP_Text>();
text_num_after = transform.Find("root/enhace/change/text_num_after").GetComponent<TMP_Text>();
max = transform.Find("root/enhace/max").gameObject;
text_num_max = transform.Find("root/enhace/max/text_num_max").GetComponent<TMP_Text>();
dataList = GContext.container.Resolve<Tables>().TbRodLevelupStats.DataList;
}
private void Start()
{
btn_close.onClick.AddListener(() => { UIManager.Instance.HideUI(UITypes.FishingRodRewardPopupPanel); });
btn_mask.onClick.AddListener(() => { UIManager.Instance.HideUI(UITypes.FishingRodRewardPopupPanel); });
}
void SetScore()
{
int allScore = GContext.container.Resolve<PlayerFishData>().GetRodAllScore();
int count = dataList.Count;
var data = dataList[^1];
int level = count;
float PointBonus = 0;
for (int i = 0; i < count; i++)
{
if (allScore < dataList[i].Count)
{
data = dataList[i];
level = i;
break;
}
PointBonus += dataList[i].PointBonus;
}
text_num_before.text = PointBonus.ToPercentageString();
change.gameObject.SetActive(level != count);
max.gameObject.SetActive(level == count);
textLevel.text = level.ToString();
if (level == count)
{
text_bar.text = $"{data.Count}/{data.Count}";
image_bar.fillAmount = 1;
text_num_max.text = PointBonus.ToPercentageString();
}
else
{
text_bar.text = $"{allScore}/{data.Count}";
image_bar.fillAmount = (float)allScore / data.Count;
text_num_after.text = (PointBonus + data.PointBonus).ToPercentageString();
}
}
private void OnEnable()
{
SetScore();
GContext.Publish(new OnEventTriggerGuide(GetType().Name));
}
private void OnDisable()
{
GContext.Publish(new OnEventTriggerGuide(GetType().Name));
}
}