214 lines
6.7 KiB
C#
214 lines
6.7 KiB
C#
using asap.core;
|
|
using DG.Tweening;
|
|
using GameCore;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
public struct SUnlockDiamondShopEvent
|
|
{
|
|
}
|
|
public class UITopArea : MonoBehaviour
|
|
{
|
|
public Button bnt_gold;
|
|
public TMP_Text text_gold;
|
|
public ulong curGold = 0;
|
|
public Transform gold_icon;
|
|
private Button btn_menu;
|
|
private Button btn_vip;
|
|
private TMP_Text text_vipLevel;
|
|
protected CompositeDisposable disposables = new CompositeDisposable();
|
|
|
|
#region diamond
|
|
public Button btn_diamond;
|
|
public GameObject go_diamondAdd;
|
|
public int curDiamond;
|
|
public TMP_Text text_diamond;
|
|
#endregion
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
if (curGold == 0)
|
|
{
|
|
curGold = GContext.container.Resolve<PlayerData>().gold;
|
|
}
|
|
btn_menu = transform.Find("resource/btn_menu").GetComponent<Button>();
|
|
btn_vip = transform.Find("resource/vip").GetComponent<Button>();
|
|
text_vipLevel = transform.Find("resource/vip/p_text_num").GetComponent<TMP_Text>();
|
|
text_gold.text = ConvertTools.GetNumberString2(curGold);
|
|
|
|
curDiamond = GContext.container.Resolve<PlayerData>().diamond;
|
|
GContext.OnEvent<SUnlockDiamondShopEvent>().Subscribe(x =>
|
|
{
|
|
if (btn_diamond)
|
|
{
|
|
if (go_diamondAdd)
|
|
{
|
|
go_diamondAdd.SetActive(GContext.container.Resolve<PlayerShopData>().IsShopOpen);
|
|
|
|
}
|
|
btn_diamond.onClick.AddListener(OnClickDiamondAsync);
|
|
}
|
|
}).AddTo(disposables);
|
|
if (text_diamond != null)
|
|
text_diamond.text = ConvertTools.GetNumberString2(curDiamond);
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
if (btn_diamond)
|
|
{
|
|
if (go_diamondAdd)
|
|
{
|
|
go_diamondAdd.SetActive(GContext.container.Resolve<PlayerShopData>().IsShopOpen);
|
|
|
|
}
|
|
btn_diamond.onClick.AddListener(OnClickDiamondAsync);
|
|
}
|
|
|
|
if (bnt_gold)
|
|
{
|
|
bnt_gold.onClick.AddListener(OnClickGoldAsync);
|
|
}
|
|
btn_menu.onClick.AddListener(async () =>
|
|
{
|
|
btn_menu.enabled = false;
|
|
|
|
await UIManager.Instance.ShowUI(UITypes.FishingMorePanel);
|
|
btn_menu.enabled = true;
|
|
});
|
|
|
|
//btn_vip.onClick.AddListener(async () =>
|
|
//{
|
|
// if (GContext.container.Resolve<PlayerData>().vip >= 0 & GContext.container.Resolve<PlayerData>().vip <= 20)
|
|
// {
|
|
// btn_vip.enabled = false;
|
|
// GContext.Publish(new VibrationData(HapticTypes.Success));
|
|
|
|
// await UIManager.Instance.ShowUI(UITypes.VipPopupPanel);
|
|
// btn_vip.enabled = true;
|
|
// }
|
|
// else
|
|
// {
|
|
// Debug.LogError("VIP等级错误");
|
|
// }
|
|
//});
|
|
GContext.OnEvent<ResAddEvent>().Where(x => x.id == 1002).Subscribe(x =>
|
|
{
|
|
GoldAddAnim(x.addCount);
|
|
}).AddTo(disposables);
|
|
GContext.OnEvent<ResAddEvent>().Where(x => x.id == 1005).Subscribe(x =>
|
|
{
|
|
DiamondAddAnim();
|
|
}).AddTo(disposables);
|
|
OnVipChange();
|
|
}
|
|
async void OnClickDiamondAsync()
|
|
{
|
|
if (GContext.container.Resolve<PlayerShopData>().IsShopOpen)
|
|
{
|
|
btn_diamond.enabled = false;
|
|
//GContext.Publish(new VibrationData(HapticTypes.Selection));
|
|
await UIManager.Instance.GetUIAsync(UITypes.FishingShopPanel);
|
|
GContext.Publish(new HideHomePanelEvent());
|
|
btn_diamond.enabled = true;
|
|
}
|
|
// else
|
|
// {
|
|
// ToastPanel.Show(GContext.container.Resolve<FishingEventData>().GetTipforUnlocked(GContext.container.Resolve<PlayerShopData>().shopTipforUnlocked));
|
|
// }
|
|
}
|
|
async void OnClickGoldAsync()
|
|
{
|
|
if (GContext.container.Resolve<PlayerShopData>().IsShopOpen)
|
|
{
|
|
bnt_gold.enabled = false;
|
|
await UIManager.Instance.GetUIAsync(UITypes.FishingShopPanel);
|
|
GContext.Publish(new HideHomePanelEvent());
|
|
bnt_gold.enabled = true;
|
|
}
|
|
else
|
|
{
|
|
ToastPanel.Show(GContext.container.Resolve<FishingEventData>().GetTipforUnlocked(GContext.container.Resolve<PlayerShopData>().shopTipforUnlocked));
|
|
}
|
|
}
|
|
|
|
void OnVipChange()
|
|
{
|
|
//if (GContext.container.Resolve<PlayerShopData>().IsVIPOpen)
|
|
//{
|
|
// btn_vip.gameObject.SetActive(true);
|
|
// text_vipLevel.text = GContext.container.Resolve<PlayerData>().vip.ToString();
|
|
//}
|
|
//else
|
|
{
|
|
btn_vip.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
void GoldAddAnim(int addCount)
|
|
{
|
|
DOTween.Kill("text_gold");
|
|
text_gold.text = ConvertTools.GetNumberString2(curGold);
|
|
|
|
ulong playerGold = GContext.container.Resolve<PlayerData>().gold;
|
|
ulong endGold = playerGold;
|
|
if (addCount > 0)
|
|
{
|
|
var _endGold = curGold + (ulong)addCount;
|
|
if (_endGold < playerGold)
|
|
{
|
|
endGold = _endGold;
|
|
}
|
|
}
|
|
|
|
float progress = 0;
|
|
ulong cur_glod = curGold;
|
|
curGold = endGold;
|
|
if (endGold < cur_glod)
|
|
{
|
|
ulong addGold = cur_glod - endGold;
|
|
DOTween.To(() => progress, x => progress = x, 1, 1f).OnUpdate(() =>
|
|
{
|
|
ulong gold = (ulong)(addGold * progress);
|
|
if (gold > cur_glod)
|
|
{
|
|
gold = cur_glod;
|
|
}
|
|
text_gold.text = ConvertTools.GetNumberString2(cur_glod - gold);
|
|
}).SetId("text_gold");
|
|
}
|
|
else if (endGold > cur_glod)
|
|
{
|
|
ulong addGold = endGold - cur_glod;
|
|
DOTween.To(() => progress, x => progress = x, 1, 1f).OnUpdate(() =>
|
|
{
|
|
text_gold.text = ConvertTools.GetNumberString2(cur_glod + (ulong)(addGold * progress));
|
|
}).SetId("text_gold");
|
|
}
|
|
}
|
|
void DiamondAddAnim()
|
|
{
|
|
DOTween.Kill("text_diamond");
|
|
text_diamond.text = ConvertTools.GetNumberString2(curDiamond);
|
|
var EndDiamond = GContext.container.Resolve<PlayerData>().diamond;
|
|
DOTween.To(() => curDiamond, x => curDiamond = x, EndDiamond, 1f).OnUpdate(() =>
|
|
{
|
|
text_diamond.text = ConvertTools.GetNumberString2(curDiamond);
|
|
}).SetId("text_diamond").OnComplete(() => text_diamond.text = ConvertTools.GetNumberString2(EndDiamond));
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
UIManager.Instance.DestroyUI(UITypes.FishingMorePanel);
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
disposables.Dispose();
|
|
disposables = null;
|
|
}
|
|
|
|
}
|