备份CatanBuilding瘦身独立工程
This commit is contained in:
106
Assets/Scripts/UI/Shop/LackOfResourcePopupPanel.cs
Normal file
106
Assets/Scripts/UI/Shop/LackOfResourcePopupPanel.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using GameCore;
|
||||
using System;
|
||||
using TMPro;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class LackOfResourceCloseEvent
|
||||
{
|
||||
public bool resultToShop;
|
||||
}
|
||||
public class LackOfResourcePopupPanel : MonoBehaviour
|
||||
{
|
||||
Button btn_mask;
|
||||
Button btn_diamond;
|
||||
TMP_Text text_info;
|
||||
GameObject info;
|
||||
PlayerData _playerData;
|
||||
Tables _tables;
|
||||
Timer packTimer;
|
||||
#region Field&&Property
|
||||
[SerializeField]
|
||||
private EnergyShopSlot[] _diamondShopSlots;
|
||||
#endregion
|
||||
protected CompositeDisposable disposables = new CompositeDisposable();
|
||||
private void Awake()
|
||||
{
|
||||
_tables = GContext.container.Resolve<Tables>();
|
||||
_playerData = GContext.container.Resolve<PlayerData>();
|
||||
btn_mask = transform.Find("mask").GetComponent<Button>();
|
||||
text_info = transform.Find("root/bg_info/text_info").GetComponent<TMP_Text>();
|
||||
info = transform.Find("root/bg_info").gameObject;
|
||||
btn_diamond = transform.Find("top_area/resource/icon_diamond").GetComponent<Button>();
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
btn_mask.onClick.AddListener(OnClose);
|
||||
btn_diamond.onClick.AddListener(async () =>
|
||||
{
|
||||
btn_diamond.enabled = false;
|
||||
LackOfResourceCloseEvent lackOfResourceCloseEvent = new LackOfResourceCloseEvent();
|
||||
lackOfResourceCloseEvent.resultToShop = true;
|
||||
GContext.Publish(lackOfResourceCloseEvent);
|
||||
await UIManager.Instance.GetUIAsync(UITypes.FishingShopPanel);
|
||||
UIManager.Instance.DestroyUI(UITypes.LackOfResourcePopupPanel);
|
||||
GContext.Publish(new HideHomePanelEvent());
|
||||
});
|
||||
GContext.OnEvent<LackOfResourceConfirmEvent>().Subscribe(x =>
|
||||
{
|
||||
LackOfResourceCloseEvent lackOfResourceCloseEvent = new LackOfResourceCloseEvent();
|
||||
lackOfResourceCloseEvent.resultToShop = true;
|
||||
GContext.Publish(lackOfResourceCloseEvent);
|
||||
UIManager.Instance.DestroyUI(UITypes.LackOfResourcePopupPanel);
|
||||
}).AddTo(disposables);
|
||||
|
||||
var shopTokens = GContext.container.Resolve<Tables>().TbResourceStore.DataList;
|
||||
EnergyDef energyDef = _tables.TbEnergyDef.DataList[GContext.container.Resolve<PlayerData>().magnification];
|
||||
_diamondShopSlots[0].SetData(shopTokens[0]);
|
||||
for (int i = 1; i < _diamondShopSlots.Length; i++)
|
||||
{
|
||||
_diamondShopSlots[i].gameObject.SetActive(false);
|
||||
}
|
||||
if (_diamondShopSlots.Length >= energyDef.ShopID)
|
||||
{
|
||||
_diamondShopSlots[energyDef.ShopID - 1].gameObject.SetActive(true);
|
||||
_diamondShopSlots[energyDef.ShopID - 1].SetData(GContext.container.Resolve<Tables>().TbResourceStore.GetOrDefault(energyDef.ShopID));
|
||||
}
|
||||
info.SetActive(false);
|
||||
//if (LackOfResourceEvent.type == 4)
|
||||
//{
|
||||
info.SetActive(true);
|
||||
TimeSpan now = _playerData.GetEnergyRecoveryTimeMAndS();
|
||||
packTimer = this.AttachTimer((float)now.TotalSeconds, null,
|
||||
(elapsed) =>
|
||||
{
|
||||
now = _playerData.GetEnergyRecoveryTimeMAndS();
|
||||
int EnergyRecover = _playerData.EnergyRecover;
|
||||
string Time2 = ConvertTools.ConvertTime2(now.Days, now.Hours, now.Minutes, now.Seconds);
|
||||
text_info.text = LocalizationMgr.GetFormatTextValue("UI_LackOfResourcePopupPanel_3", EnergyRecover, Time2);
|
||||
if (now.TotalMilliseconds <= 0 || _playerData.Energy >= _playerData.MaxEnergy)
|
||||
{
|
||||
packTimer?.Cancel();
|
||||
packTimer = null;
|
||||
info.SetActive(false);
|
||||
}
|
||||
}, useRealTime: true);
|
||||
//}
|
||||
|
||||
}
|
||||
void OnClose()
|
||||
{
|
||||
LackOfResourceCloseEvent lackOfResourceCloseEvent = new LackOfResourceCloseEvent();
|
||||
GContext.Publish(lackOfResourceCloseEvent);
|
||||
UIManager.Instance.DestroyUI(UITypes.LackOfResourcePopupPanel);
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
packTimer?.Cancel();
|
||||
packTimer = null;
|
||||
disposables?.Dispose();
|
||||
disposables = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user