159 lines
5.5 KiB
C#
159 lines
5.5 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using GameCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
public class HomeBtnAdvert : EventButtonResource, IUIRedPoint
|
|
{
|
|
public const string redKey = "Home.Advert";
|
|
PlayerShopData shopData;
|
|
Button btn_advert;
|
|
TMP_Text text_time;
|
|
GameObject redpoint;
|
|
GameObject text_task;
|
|
Timer timer;
|
|
bool isOpenAdPack;
|
|
private void Awake()
|
|
{
|
|
shopData = GContext.container.Resolve<PlayerShopData>();
|
|
btn_advert = GetComponent<Button>();
|
|
redpoint = transform.Find("redpoint").gameObject;
|
|
text_time = transform.Find("text_time").GetComponent<TMP_Text>();
|
|
text_task = transform.Find("text_task").gameObject;
|
|
if (GContext.container.Resolve<PlayerData>().lv < GContext.container.Resolve<Tables>().TbGlobalConfig.PreviewUnlockLevel)
|
|
{
|
|
gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
CheckResource(new List<string>() { "AdvertPanel" });
|
|
}
|
|
private void Start()
|
|
{
|
|
btn_advert.onClick.AddListener(OnClickAdvert);
|
|
}
|
|
void OnEnable()
|
|
{
|
|
RedPointManager.Instance.AddRedPoint(redKey, this);
|
|
isOpenAdPack = shopData.IsOpenAdPack();
|
|
// btn_advert.enabled = isOpenAdPack;
|
|
transform.Find("lock").gameObject.SetActive(!isOpenAdPack);
|
|
shopData.SetAdvRedPoint();
|
|
if (!isOpenAdPack)
|
|
{
|
|
text_time.gameObject.SetActive(false);
|
|
text_task.SetActive(false);
|
|
TMP_Text text_level = transform.Find("lock/text_level").GetComponent<TMP_Text>();
|
|
FishingEvent fishingEvent = GContext.container.Resolve<Tables>().TbFishingEvent.Get(11000000);
|
|
text_level.text = LocalizationMgr.GetFormatTextValue("UI_PlayerGradePopupPanel_1", fishingEvent.ConditionList[0].Param[0]);
|
|
}
|
|
//SetRedPointState(RedPointManager.Instance.GetRedPointState(redKey));
|
|
}
|
|
private async void OnClickAdvert()
|
|
{
|
|
isOpenAdPack = shopData.IsOpenAdPack();
|
|
if (!isOpenAdPack)
|
|
{
|
|
GameObject panel = await UIManager.Instance.ShowUILoad(new UIType("FeatureUnlockPreviewPopupPanel"));
|
|
FeatureUnlockPreviewPopupPanel featureUnlockPreviewPopupPanel = panel.GetComponent<FeatureUnlockPreviewPopupPanel>();
|
|
featureUnlockPreviewPopupPanel.InitPanel(3);
|
|
return;
|
|
}
|
|
GameObject go = await UIManager.Instance.ShowUILoad(UITypes.AdvertPanel);
|
|
if (go != null)
|
|
{
|
|
GContext.Publish(new HideHomePanelEvent());
|
|
}
|
|
}
|
|
public void SetRedPointState(bool state)
|
|
{
|
|
if (redpoint == null)
|
|
{
|
|
return;
|
|
}
|
|
redpoint.SetActive(state);
|
|
if (!state && shopData.IsOpenAdPack() && shopData.IsShowVIPAdTimer())
|
|
{
|
|
StartTimer();
|
|
return;
|
|
}
|
|
if (timer != null)
|
|
{
|
|
timer.Cancel();
|
|
timer = null;
|
|
}
|
|
SetState(true);
|
|
}
|
|
void StartTimer()
|
|
{
|
|
DateTime now = ZZTimeHelper.UtcNow().UtcNowOffset();
|
|
var id = GContext.container.Resolve<PlayerData>().priceLevel.DailyGiftPackList[0];
|
|
var packM = shopData.TbPackManagerGetOrDefault(id);
|
|
var pack = GContext.container.Resolve<Tables>().TbPack.GetOrDefault(packM.PackID[0]);
|
|
var daily = packM.TimeDefinition as Daily;
|
|
var DailyGiftPackList = GContext.container.Resolve<PlayerData>().priceLevel.DailyGiftPackList;
|
|
for (int i = 0; i < DailyGiftPackList.Count; i++)
|
|
{
|
|
id = DailyGiftPackList[i];
|
|
ShopPackManager localPackM = shopData.TbPackManagerGetOrDefault(id);
|
|
if (localPackM == null) break;
|
|
daily = localPackM.TimeDefinition as Daily;
|
|
if (TimeSpan.FromSeconds(daily.StartTime) <= now.TimeOfDay && TimeSpan.FromSeconds(daily.EndTime) > now.TimeOfDay)
|
|
{
|
|
packM = localPackM;
|
|
break;
|
|
}
|
|
|
|
}
|
|
if (shopData.GetShopPackBuyCount(packM.ID) < 2)
|
|
{
|
|
SetState(true);
|
|
return;
|
|
}
|
|
SetState(false);
|
|
TimeSpan ts = TimeSpan.FromSeconds(daily.EndTime) - now.TimeOfDay;
|
|
text_time.text = ConvertTools.ConvertTime2(0, ts.Hours, ts.Minutes, ts.Seconds);
|
|
if (timer == null)
|
|
{
|
|
timer = this.AttachTimer((float)ts.TotalSeconds, EndTimer,
|
|
(elapsed) =>
|
|
{
|
|
now = ZZTimeHelper.UtcNow().UtcNowOffset();
|
|
ts = TimeSpan.FromSeconds(daily.EndTime) - now.TimeOfDay;
|
|
text_time.text = ConvertTools.ConvertTime2(0, ts.Hours, ts.Minutes, ts.Seconds);
|
|
}, useRealTime: true);
|
|
}
|
|
}
|
|
void EndTimer()
|
|
{
|
|
SetRedPointState(RedPointManager.Instance.GetRedPointState(redKey));
|
|
}
|
|
void SetState(bool value)
|
|
{
|
|
text_time.gameObject.SetActive(!value);
|
|
text_task.SetActive(value && isOpenAdPack);
|
|
}
|
|
protected override void OnLoadEventResource()
|
|
{
|
|
if (GContext.container.Resolve<PlayerData>().lv >= GContext.container.Resolve<Tables>().TbGlobalConfig.PreviewUnlockLevel)
|
|
{
|
|
gameObject.SetActive(true);
|
|
}
|
|
}
|
|
private void OnDisable()
|
|
{
|
|
RedPointManager.Instance.RemoveRedPoint(redKey);
|
|
}
|
|
protected override void OnDestroy()
|
|
{
|
|
base.OnDestroy();
|
|
if (timer != null)
|
|
{
|
|
timer.Cancel();
|
|
timer = null;
|
|
}
|
|
}
|
|
}
|