备份CatanBuilding瘦身独立工程
This commit is contained in:
377
Assets/Scripts/UI/Home/HomeLeftPanel.cs
Normal file
377
Assets/Scripts/UI/Home/HomeLeftPanel.cs
Normal file
@@ -0,0 +1,377 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using game;
|
||||
using GameCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
/// <summary>
|
||||
/// 触发礼包 ???
|
||||
/// </summary>
|
||||
public class HomeLeftPanel : MonoBehaviour
|
||||
{
|
||||
Button but_shop;
|
||||
Button btn_gift1;//新手礼包2
|
||||
Image image_gift1;
|
||||
TMP_Text text_time1;
|
||||
Button btn_gift3;//转盘礼包
|
||||
TMP_Text text_time3;
|
||||
Button btn_gift4;//
|
||||
TMP_Text text_time4;
|
||||
Button btn_gift5;//地图礼包
|
||||
TMP_Text text_time5;
|
||||
Button btn_gift6;//新手礼包1 第一次体力不足
|
||||
TMP_Text text_time6;
|
||||
Button btn_gift8;//体力不足礼包4
|
||||
TMP_Text text_time8;
|
||||
|
||||
Button btn_gift2;//礼包链
|
||||
Image image_gift2;
|
||||
Button btn_debug;
|
||||
public HomePanel homePanel;
|
||||
TMP_Text text_chainGiftPack;
|
||||
Timer chainGiftPackTimer;
|
||||
int triggerPackListCount1 = -1;//新手礼包2
|
||||
int triggerPackListCount6 = -1;//新手礼包1 第一次体力不足
|
||||
int triggerPackListCount8 = -1;//体力不足礼包
|
||||
int triggerPackListCount51 = -1;//转盘礼包
|
||||
int triggerPackListCount52 = -1;//
|
||||
int triggerPackListCount53 = -1;//地图礼包
|
||||
|
||||
int gift1ID;
|
||||
int gift6ID;
|
||||
int gift8ID;
|
||||
int gift51ID;
|
||||
int gift52ID;
|
||||
int gift53ID;
|
||||
public List<TriggerPackBuyData> triggerPackList1;
|
||||
public List<TriggerPackBuyData> triggerPackList6;
|
||||
public List<TriggerPackBuyData> triggerPackList8;
|
||||
public List<TriggerPackBuyData> triggerPackList51;
|
||||
public List<TriggerPackBuyData> triggerPackList52;
|
||||
public List<TriggerPackBuyData> triggerPackList53;
|
||||
protected CompositeDisposable disposables = new CompositeDisposable();
|
||||
IDisposable disRequestSvrTime;
|
||||
TriggerPackData triggerPackData;
|
||||
private void Awake()
|
||||
{
|
||||
but_shop = transform.Find("btn_shop").GetComponent<Button>();
|
||||
btn_gift1 = transform.Find("btn_gift1").GetComponent<Button>();
|
||||
image_gift1 = transform.Find("btn_gift1/icon").GetComponent<Image>();
|
||||
btn_gift2 = transform.Find("btn_gift2").GetComponent<Button>();
|
||||
image_gift2 = transform.Find("btn_gift2/icon").GetComponent<Image>();
|
||||
btn_gift3 = transform.Find("btn_gift3").GetComponent<Button>();
|
||||
btn_gift4 = transform.Find("btn_gift4").GetComponent<Button>();
|
||||
btn_gift5 = transform.Find("btn_gift5").GetComponent<Button>();
|
||||
btn_gift6 = transform.Find("btn_gift6").GetComponent<Button>();
|
||||
btn_gift8 = transform.Find("btn_gift8").GetComponent<Button>();
|
||||
text_chainGiftPack = transform.Find("btn_gift2/text_time").GetComponent<TMP_Text>();
|
||||
text_time1 = transform.Find("btn_gift1/text_time").GetComponent<TMP_Text>();
|
||||
text_time3 = transform.Find("btn_gift3/text_time").GetComponent<TMP_Text>();
|
||||
text_time4 = transform.Find("btn_gift4/text_time").GetComponent<TMP_Text>();
|
||||
text_time5 = transform.Find("btn_gift5/text_time").GetComponent<TMP_Text>();
|
||||
text_time6 = transform.Find("btn_gift6/text_time").GetComponent<TMP_Text>();
|
||||
text_time8 = transform.Find("btn_gift8/text_time").GetComponent<TMP_Text>();
|
||||
btn_debug = transform.Find("btn_debug").GetComponent<Button>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
GContext.OnEvent<TriggerPackEvent>().Subscribe(TriggerPackEvent).AddTo(disposables);
|
||||
|
||||
btn_debug.onClick.AddListener(() => homePanel.OnPushPanelOrScene(UITypes.DeBugPanel));
|
||||
|
||||
but_shop.onClick.AddListener(() =>
|
||||
{
|
||||
homePanel.OnPushPanelOrScene(UITypes.FishingShopPanel);
|
||||
});
|
||||
btn_gift2.onClick.AddListener(() =>
|
||||
{
|
||||
ShowGiftUI(btn_gift2, UITypes.GiftChainCommon_SubmarinePanel);
|
||||
});
|
||||
btn_gift1.onClick.AddListener(() =>
|
||||
{
|
||||
ShowGiftUI(btn_gift1, UITypes.CommerceNoviceGiftPopupPanel);
|
||||
});
|
||||
//转盘券
|
||||
btn_gift3.onClick.AddListener(() =>
|
||||
{
|
||||
ShowGiftUI(btn_gift3, UITypes.GiftPopupPanel_3);
|
||||
});
|
||||
btn_gift4.onClick.AddListener(() =>
|
||||
{
|
||||
ShowGiftUI(btn_gift4, UITypes.GiftPopupPanel_4);
|
||||
});
|
||||
//钓鱼券
|
||||
btn_gift5.onClick.AddListener(() =>
|
||||
{
|
||||
ShowGiftUI(btn_gift5, UITypes.MapPackPanel);
|
||||
});
|
||||
//破冰
|
||||
btn_gift6.onClick.AddListener(() =>
|
||||
{
|
||||
ShowGiftUI(btn_gift6, UITypes.GiftPopupPanel_6);
|
||||
});
|
||||
//体力不足
|
||||
//btn_gift8.onClick.AddListener(() =>
|
||||
//{
|
||||
// ShowGiftUI(btn_gift8, UITypes.GiftPopupPanel_8);
|
||||
//});
|
||||
//开始计时
|
||||
SetTriggerPackTimer();
|
||||
GContext.container.Resolve<PlayerData>().RecoveryEnergy();
|
||||
}
|
||||
async void ShowGiftUI(Button btn, UIType GiftPopupPanel)
|
||||
{
|
||||
// 退出自动钓鱼
|
||||
//homePanel.ExitAutoFishing();
|
||||
btn.enabled = false;
|
||||
await UIManager.Instance.ShowUILoad(GiftPopupPanel);
|
||||
btn.enabled = true;
|
||||
}
|
||||
|
||||
void SystemSwitch()
|
||||
{
|
||||
triggerPackData = GContext.container.Resolve<TriggerPackData>();
|
||||
gift1ID = 0;
|
||||
triggerPackList1 = triggerPackData.GetTriggerPackList(2);
|
||||
triggerPackListCount1 = triggerPackList1.Count;
|
||||
if (triggerPackListCount1 > 0)
|
||||
{
|
||||
triggerPackList1.Sort((a, b) => a.time.CompareTo(b.time));
|
||||
|
||||
TriggerPackBuyData _noticeGift = triggerPackList1[0];
|
||||
gift1ID = _noticeGift.ID;
|
||||
}
|
||||
btn_gift1.gameObject.SetActive(triggerPackListCount1 > 0);
|
||||
|
||||
gift6ID = 0;
|
||||
triggerPackList6 = triggerPackData.GetTriggerPackList(1);
|
||||
triggerPackListCount6 = triggerPackList6.Count;
|
||||
if (triggerPackListCount6 > 0)
|
||||
{
|
||||
triggerPackList6.Sort((a, b) => a.time.CompareTo(b.time));
|
||||
|
||||
gift6ID = triggerPackList6[0].ID;
|
||||
|
||||
}
|
||||
btn_gift6.gameObject.SetActive(triggerPackListCount6 > 0);
|
||||
|
||||
gift8ID = 0;
|
||||
triggerPackList8 = triggerPackData.GetTriggerPackList(4);
|
||||
triggerPackListCount8 = triggerPackList8.Count;
|
||||
if (triggerPackListCount8 > 0)
|
||||
{
|
||||
triggerPackList8.Sort((a, b) => a.time.CompareTo(b.time));
|
||||
|
||||
gift8ID = triggerPackList8[0].ID;
|
||||
|
||||
}
|
||||
btn_gift8.gameObject.SetActive(false);// triggerPackListCount8 > 0);
|
||||
|
||||
|
||||
gift51ID = 0;
|
||||
triggerPackList51 = triggerPackData.GetTriggerPackList(51);
|
||||
triggerPackListCount51 = triggerPackList51.Count;
|
||||
if (triggerPackListCount51 > 0)
|
||||
{
|
||||
triggerPackList51.Sort((a, b) => a.time.CompareTo(b.time));
|
||||
|
||||
gift51ID = triggerPackList51[0].ID;
|
||||
|
||||
}
|
||||
btn_gift3.gameObject.SetActive(triggerPackListCount51 > 0);
|
||||
|
||||
|
||||
gift52ID = 0;
|
||||
triggerPackList52 = triggerPackData.GetTriggerPackList(52);
|
||||
triggerPackListCount52 = triggerPackList52.Count;
|
||||
if (triggerPackListCount52 > 0)
|
||||
{
|
||||
triggerPackList52.Sort((a, b) => a.time.CompareTo(b.time));
|
||||
|
||||
gift52ID = triggerPackList52[0].ID;
|
||||
|
||||
}
|
||||
btn_gift4.gameObject.SetActive(triggerPackListCount52 > 0);
|
||||
|
||||
gift53ID = 0;
|
||||
triggerPackList53 = triggerPackData.GetTriggerPackList(53);
|
||||
triggerPackListCount53 = triggerPackList53.Count;
|
||||
if (triggerPackListCount53 > 0)
|
||||
{
|
||||
triggerPackList53.Sort((a, b) => a.time.CompareTo(b.time));
|
||||
|
||||
gift53ID = triggerPackList53[0].ID;
|
||||
}
|
||||
btn_gift5.gameObject.SetActive(triggerPackListCount53 > 0);
|
||||
|
||||
but_shop.gameObject.SetActive(GContext.container.Resolve<PlayerShopData>().IsShopOpen);
|
||||
btn_gift2.gameObject.SetActive(GContext.container.Resolve<PlayerShopData>().IsOpenChainGiftPack());
|
||||
SetChainGiftPackTimer();
|
||||
}
|
||||
void TriggerPackEvent(TriggerPackEvent triggerPackEvent)
|
||||
{
|
||||
SystemSwitch();
|
||||
PlayerFishData playerFishData = GContext.container.Resolve<PlayerFishData>();
|
||||
|
||||
CurRewardQCount curRewardQCount = new CurRewardQCount();
|
||||
GContext.Publish(curRewardQCount);
|
||||
if (curRewardQCount.count <= 0)
|
||||
{
|
||||
int faceCount = GContext.container.Resolve<IFaceUIService>().GetFaceUICount();
|
||||
if (faceCount == 0)
|
||||
{
|
||||
GContext.container.Resolve<GuideDataCenter>().InspectTriggerGuide("HomePanel");
|
||||
}
|
||||
else
|
||||
{
|
||||
GContext.container.Resolve<IFaceUIService>().ShowFaceUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetChainGiftPackTimer()
|
||||
{
|
||||
if (GContext.container.Resolve<PlayerShopData>().IsOpenChainGiftPack())
|
||||
{
|
||||
if (chainGiftPackTimer == null)
|
||||
{
|
||||
DateTime endTime = GContext.container.Resolve<PlayerShopData>().GetChainEndTime();
|
||||
TimeSpan now = endTime - ZZTimeHelper.UtcNow().UtcNowOffset();
|
||||
double seconds = now.TotalSeconds;
|
||||
chainGiftPackTimer = this.AttachTimer((float)seconds, InitChainGiftPack,
|
||||
(elapsed) =>
|
||||
{
|
||||
now = endTime - ZZTimeHelper.UtcNow().UtcNowOffset();
|
||||
text_chainGiftPack.text = ConvertTools.ConvertTime2(now.Days, now.Hours, now.Minutes, now.Seconds);
|
||||
}, useRealTime: true);
|
||||
btn_gift2.gameObject.SetActive(true);
|
||||
GContext.container.Resolve<IUIService>().SetImageSprite(image_gift2, GContext.container.Resolve<PlayerShopData>().chainPackM.Icon);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
btn_gift2.gameObject.SetActive(false);
|
||||
chainGiftPackTimer?.Cancel();
|
||||
chainGiftPackTimer = null;
|
||||
}
|
||||
}
|
||||
void InitChainGiftPack()
|
||||
{
|
||||
chainGiftPackTimer?.Cancel();
|
||||
chainGiftPackTimer = null;
|
||||
btn_gift2.gameObject.SetActive(false);
|
||||
GContext.container.Resolve<FishingEventData>().GetEventAndInit(3, 10);
|
||||
}
|
||||
private System.Threading.CancellationTokenSource tokenSource;
|
||||
|
||||
void OnApplicationPause(bool is_pause)
|
||||
{
|
||||
if (is_pause)
|
||||
{
|
||||
tokenSource?.Cancel();
|
||||
tokenSource = null;
|
||||
GContext.container.Resolve<PlayerData>().StopRecoveryEnergy();
|
||||
disRequestSvrTime?.Dispose();
|
||||
disRequestSvrTime = GContext.OnEvent<RequestSvrTimeEvent>().Subscribe(RequestSvrTimeEvent);
|
||||
}
|
||||
}
|
||||
void RequestSvrTimeEvent(RequestSvrTimeEvent e)
|
||||
{
|
||||
if (e.Status)
|
||||
{
|
||||
disRequestSvrTime?.Dispose();
|
||||
disRequestSvrTime = null;
|
||||
Debug.Log("RequestSvrTimeEvent AllRefresh");
|
||||
GContext.container.Resolve<PlayerShopData>().InitShopPackData();
|
||||
GContext.container.Resolve<PlayerData>().RecoveryEnergy();
|
||||
SetTriggerPackTimer();
|
||||
}
|
||||
}
|
||||
|
||||
public async void SetTriggerPackTimer()
|
||||
{
|
||||
tokenSource = new System.Threading.CancellationTokenSource();
|
||||
SystemSwitch();
|
||||
DateTime dateTime = ZZTimeHelper.UtcNow().UtcNowOffset();
|
||||
DateTime dateTime1 = dateTime.AddDays(1).Date;
|
||||
try
|
||||
{
|
||||
var token = tokenSource.Token;
|
||||
while (!token.IsCancellationRequested && dateTime.Ticks < dateTime1.Ticks)
|
||||
{
|
||||
UpdateTriggerTimer();
|
||||
await System.Threading.Tasks.Task.Delay(1000);
|
||||
dateTime = dateTime.AddSeconds(1);
|
||||
}
|
||||
if (!token.IsCancellationRequested)
|
||||
{
|
||||
Refresh();
|
||||
SetTriggerPackTimer();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
}
|
||||
}
|
||||
void Refresh()
|
||||
{
|
||||
GContext.container.Resolve<PlayerShopData>().InitShopPackData();
|
||||
GContext.container.Resolve<TriggerPackData>().InitPackData();
|
||||
}
|
||||
public void UpdateTriggerTimer()
|
||||
{
|
||||
var list = GContext.container.Resolve<TriggerPackData>().triggerPackList;
|
||||
int count = list.Count;
|
||||
if (count > 0)
|
||||
{
|
||||
TriggerPackBuyData stateEvent;
|
||||
for (int i = count - 1; i >= 0; i--)
|
||||
{
|
||||
stateEvent = list[i];
|
||||
TimeSpan timeSpan = GContext.container.Resolve<TriggerPackData>().GetCurTriggerPackEndTime(stateEvent);
|
||||
if (timeSpan.TotalSeconds <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (stateEvent.ID == gift1ID)
|
||||
{
|
||||
text_time1.text = ConvertTools.ConvertTime2(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
|
||||
}
|
||||
else if (stateEvent.ID == gift51ID)
|
||||
{
|
||||
text_time3.text = ConvertTools.ConvertTime2(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
|
||||
}
|
||||
else if (stateEvent.ID == gift52ID)
|
||||
{
|
||||
text_time4.text = ConvertTools.ConvertTime2(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
|
||||
}
|
||||
else if (stateEvent.ID == gift53ID)
|
||||
{
|
||||
text_time5.text = ConvertTools.ConvertTime2(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
|
||||
}
|
||||
else if (stateEvent.ID == gift6ID)
|
||||
{
|
||||
text_time6.text = ConvertTools.ConvertTime2(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
|
||||
}
|
||||
else if (stateEvent.ID == gift8ID)
|
||||
{
|
||||
text_time8.text = ConvertTools.ConvertTime2(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
disposables?.Dispose();
|
||||
disposables = null;
|
||||
tokenSource?.Cancel();
|
||||
tokenSource = null;
|
||||
GContext.container?.Resolve<PlayerData>()?.StopRecoveryEnergy();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user