325 lines
9.6 KiB
C#
325 lines
9.6 KiB
C#
using asap.core;
|
|
using Coffee.UIExtensions;
|
|
using DG.Tweening;
|
|
using GameCore;
|
|
using System;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class MapBtnMiniBP : MonoBehaviour, IUIRedPoint
|
|
{
|
|
MiniBattlePassType Type = MiniBattlePassType.Fishcard;
|
|
MiniBattlePassDataModel miniBP;
|
|
public Button btn_questionmark;
|
|
|
|
Button btn;
|
|
Image icon;
|
|
TMP_Text text_time;
|
|
GameObject redpoint;
|
|
GameObject redpoint_big;
|
|
TMP_Text text_redpoint_big;
|
|
TMP_Text text_level;
|
|
Image bar;
|
|
TMP_Text text_num_bar;
|
|
int curExp;
|
|
int curAllExp;
|
|
int curMax = 1;
|
|
float _fillTime = 0.5f;
|
|
public GameObject fx;
|
|
public UIParticleAttractor uIParticleAttractor;
|
|
public CanvasGroup canvasGroup;
|
|
IDisposable timerDisposable;
|
|
private void Awake()
|
|
{
|
|
miniBP = GContext.container.Resolve<MiniBattlePassDataProvider>().GetModel(Type);
|
|
icon = transform.Find("icon").GetComponent<Image>();
|
|
text_time = transform.Find("text_time").GetComponent<TMP_Text>();
|
|
btn = GetComponent<Button>();
|
|
redpoint = transform.Find("redpoint").gameObject;
|
|
redpoint_big = transform.Find("redpoint_big").gameObject;
|
|
text_redpoint_big = redpoint_big.transform.Find("text_redpoint").GetComponent<TMP_Text>();
|
|
text_level = transform.Find("level/text_num").GetComponent<TMP_Text>();
|
|
bar = transform.Find("bg_bar/bar").GetComponent<Image>();
|
|
text_num_bar = transform.Find("bg_bar/text_num").GetComponent<TMP_Text>();
|
|
OnInit();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
btn.onClick.AddListener(OnClickIn);
|
|
}
|
|
|
|
private void OnInit()
|
|
{
|
|
if (timerDisposable != null)
|
|
{
|
|
timerDisposable.Dispose();
|
|
timerDisposable = null;
|
|
}
|
|
if (!miniBP.IsShow())
|
|
{
|
|
gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
gameObject.SetActive(true);
|
|
}
|
|
miniBP.SetOldLevel();
|
|
var progressList = miniBP.ProgressList;
|
|
int nextlv = miniBP.rewardIndex + 1;
|
|
if (nextlv < progressList.Count)
|
|
{
|
|
int startExp = 0;
|
|
if (nextlv > 0)
|
|
{
|
|
startExp = progressList[nextlv - 1];
|
|
}
|
|
curExp = miniBP.Data.Exp - startExp;
|
|
|
|
curMax = progressList[nextlv] - startExp;
|
|
text_num_bar.text = $"{curExp}/{curMax}";
|
|
bar.fillAmount = curExp / (float)curMax;
|
|
text_level.text = nextlv.ToString();
|
|
}
|
|
else
|
|
{
|
|
bar.fillAmount = 1f;
|
|
text_num_bar.text = LocalizationMgr.GetText("UI_FishingRodPanel_Advanced_18");
|
|
text_level.text = miniBP.rewardIndex.ToString();
|
|
}
|
|
|
|
curAllExp = miniBP.Data.Exp;
|
|
ShowTimer();
|
|
}
|
|
private void OnEnable()
|
|
{
|
|
RedPointManager.Instance.AddRedPoint(HomeBtnMiniBP.redKey + Type, this);
|
|
SetRedPointState(RedPointManager.Instance.GetRedPointState(HomeBtnMiniBP.redKey + Type));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 资源飞入
|
|
/// </summary>
|
|
/// <param name="classification"></param>
|
|
/// <returns></returns>
|
|
public async System.Threading.Tasks.Task ParticleAttractor(int showCount)
|
|
{
|
|
ParticleSystem particleSystem = fx.transform.Find("Scale/quan03").GetComponent<ParticleSystem>();
|
|
if (particleSystem != null)
|
|
{
|
|
particleSystem.Clear();
|
|
|
|
var main = particleSystem.main;
|
|
int maxCount = main.maxParticles;
|
|
if (showCount < maxCount)
|
|
{
|
|
int addCount = (int)showCount;
|
|
main.maxParticles = addCount;
|
|
}
|
|
fx.SetActive(true);
|
|
uIParticleAttractor.enabled = true;
|
|
await Awaiters.Seconds(1.8f);
|
|
fx.SetActive(false);
|
|
uIParticleAttractor.enabled = false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 资源飞入之后
|
|
/// </summary>
|
|
public async void PlayUpBar()
|
|
{
|
|
int offset = miniBP.Data.Exp - curAllExp;
|
|
if (offset <= 0)
|
|
{
|
|
return;
|
|
}
|
|
curAllExp = miniBP.Data.Exp;
|
|
canvasGroup.blocksRaycasts = false;
|
|
await ParticleAttractor(offset);
|
|
|
|
int oldLv = miniBP.Data.showIndex;
|
|
int curLv = miniBP.rewardIndex;
|
|
if (curLv > oldLv)
|
|
{
|
|
miniBP.SetOldLevel();
|
|
for (int i = oldLv + 1; i < curLv; i++)
|
|
{
|
|
text_level.text = i.ToString();
|
|
bar.DOFillAmount(1f, _fillTime).OnUpdate(
|
|
() =>
|
|
{
|
|
var curExp = bar.fillAmount * curMax;
|
|
text_num_bar.text = $"{(int)curExp}/{curMax}";
|
|
}
|
|
);
|
|
await Awaiters.Seconds(_fillTime);
|
|
int startExp = 0;
|
|
if (i > 0)
|
|
{
|
|
startExp = miniBP.ProgressList[i - 1];
|
|
}
|
|
curMax = miniBP.ProgressList[i] - startExp;
|
|
text_num_bar.text = $"{0}/{curMax}";
|
|
bar.fillAmount = 0;
|
|
}
|
|
text_level.text = curLv.ToString();
|
|
bar.DOFillAmount(1f, _fillTime).OnUpdate(
|
|
() =>
|
|
{
|
|
var curExp = bar.fillAmount * curMax;
|
|
text_num_bar.text = $"{(int)curExp}/{curMax}";
|
|
}
|
|
).OnComplete(PlayUpBarEnd);
|
|
}
|
|
else if (curLv <= miniBP.ProgressList.Count - 1)
|
|
{
|
|
PlayBar(false);
|
|
}
|
|
else
|
|
{
|
|
canvasGroup.blocksRaycasts = true;
|
|
}
|
|
}
|
|
void PlayUpBarEnd()
|
|
{
|
|
bar.fillAmount = 0f;
|
|
curExp = 0;
|
|
PlayBar(true);
|
|
}
|
|
void PlayBar(bool openPanel)
|
|
{
|
|
var progressList = miniBP.ProgressList;
|
|
int nextlv = miniBP.rewardIndex + 1;
|
|
|
|
if (nextlv < progressList.Count)
|
|
{
|
|
text_num_bar.text = $"{curExp}/{curMax}";
|
|
bar.fillAmount = curExp / (float)curMax;
|
|
text_level.text = nextlv.ToString();
|
|
int startExp = 0;
|
|
if (nextlv > 0)
|
|
{
|
|
startExp = progressList[nextlv - 1];
|
|
}
|
|
curMax = progressList[nextlv] - startExp;
|
|
curExp = miniBP.Data.Exp - startExp;
|
|
if (curExp == 0)
|
|
{
|
|
if (openPanel)
|
|
{
|
|
OnClickIn();
|
|
}
|
|
canvasGroup.blocksRaycasts = true;
|
|
return;
|
|
}
|
|
bar.DOFillAmount(curExp / (float)curMax, _fillTime)
|
|
.OnUpdate(
|
|
() =>
|
|
{
|
|
var curExp = bar.fillAmount * curMax;
|
|
text_num_bar.text = $"{(int)curExp}/{curMax}";
|
|
}
|
|
)
|
|
.OnComplete(
|
|
() =>
|
|
{
|
|
text_num_bar.text = $"{curExp}/{curMax}";
|
|
bar.fillAmount = curExp / (float)curMax;
|
|
if (openPanel)
|
|
{
|
|
OnClickIn();
|
|
}
|
|
canvasGroup.blocksRaycasts = true;
|
|
});
|
|
}
|
|
else
|
|
{
|
|
bar.fillAmount = 1f;
|
|
text_num_bar.text = LocalizationMgr.GetText("UI_FishingRodPanel_Advanced_18");
|
|
text_level.text = miniBP.rewardIndex.ToString();
|
|
if (openPanel)
|
|
{
|
|
OnClickIn();
|
|
}
|
|
canvasGroup.blocksRaycasts = true;
|
|
}
|
|
}
|
|
public void SetRedPointState(bool state)
|
|
{
|
|
if (redpoint_big != null && text_redpoint_big != null)
|
|
{
|
|
if (!state)
|
|
{
|
|
redpoint_big.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
int count = RedPointManager.Instance.GetRedPointCount(HomeBtnMiniBP.redKey + Type);
|
|
if (count > 1)
|
|
{
|
|
redpoint_big.SetActive(true);
|
|
if (count > 99)
|
|
{
|
|
text_redpoint_big.text = "99+";
|
|
}
|
|
else
|
|
{
|
|
text_redpoint_big.text = count.ToString();
|
|
}
|
|
state = false;
|
|
}
|
|
else
|
|
{
|
|
redpoint_big.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
redpoint.SetActive(state);
|
|
}
|
|
|
|
void OnClickIn()
|
|
{
|
|
UIManager.Instance.ShowUILoad(new UIType(miniBP.PanelName));
|
|
}
|
|
|
|
void ShowTimer()
|
|
{
|
|
//剩余时间
|
|
TimeSpan duration = miniBP.endTime - ZZTimeHelper.UtcNow();
|
|
text_time.text = ConvertTools.ConvertTime2(duration);
|
|
timerDisposable = Observable.Interval(TimeSpan.FromSeconds(1)).Subscribe(UpdateTimer);
|
|
}
|
|
private void UpdateTimer(long _ = 0L)
|
|
{
|
|
text_time.text = ConvertTools.ConvertTime2(miniBP.endTime - ZZTimeHelper.UtcNow());
|
|
if (!miniBP.IsShow())
|
|
{
|
|
Refresh();
|
|
}
|
|
}
|
|
protected void Refresh()
|
|
{
|
|
gameObject.SetActive(false);
|
|
GContext.container.Resolve<FishingEventData>().GetEventAndInit(9, 3);
|
|
OnInit();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
RedPointManager.Instance.RemoveRedPoint(HomeBtnMiniBP.redKey + Type);
|
|
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
if (timerDisposable != null)
|
|
{
|
|
timerDisposable.Dispose();
|
|
timerDisposable = null;
|
|
}
|
|
}
|
|
}
|