123 lines
4.4 KiB
C#
123 lines
4.4 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using GameCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class EventFishingduelShopPopupPanel : MonoBehaviour
|
|
{
|
|
Button btn_close;
|
|
Button btn_mask;
|
|
TMP_Text text_time;
|
|
GameObject item;
|
|
GameObject item_special_bait1;
|
|
GameObject item_special_bait2;
|
|
GameObject item_special_money1;
|
|
GameObject item_special_money2;
|
|
GameObject item_special_skin;
|
|
Tables tables;
|
|
FishingEventData fishingEventData;
|
|
Timer timer;
|
|
List<GameObject> pvpStoreItems = new List<GameObject>();
|
|
DateTime endTime;
|
|
|
|
private void Awake()
|
|
{
|
|
tables = GContext.container.Resolve<Tables>();
|
|
fishingEventData = GContext.container.Resolve<FishingEventData>();
|
|
btn_mask = transform.Find("mask").GetComponent<Button>();
|
|
btn_close = transform.Find("btn_close").GetComponent<Button>();
|
|
text_time = transform.Find("root/text_time").GetComponent<TMP_Text>();
|
|
item = transform.Find("root/ScrollView/Viewport/Content/Item").gameObject;
|
|
|
|
item_special_bait1 = transform.Find("root/ScrollView/Viewport/Content/item_special_bait1").gameObject;
|
|
item_special_bait2 = transform.Find("root/ScrollView/Viewport/Content/item_special_bait2").gameObject;
|
|
item_special_money1 = transform.Find("root/ScrollView/Viewport/Content/item_special_money1").gameObject;
|
|
item_special_money2 = transform.Find("root/ScrollView/Viewport/Content/item_special_money2").gameObject;
|
|
item_special_skin = transform.Find("root/ScrollView/Viewport/Content/item_special_skin").gameObject;
|
|
item.SetActive(false);
|
|
SetData();
|
|
}
|
|
void SetData()
|
|
{
|
|
for (int i = 0; i < pvpStoreItems.Count; i++)
|
|
{
|
|
Destroy(pvpStoreItems[i]);
|
|
}
|
|
pvpStoreItems.Clear();
|
|
endTime = fishingEventData.SetPVPShopTime();
|
|
Transform content = transform.Find("root/ScrollView/Viewport/Content");
|
|
List<PvpStore> pvpStores = tables.TbPvpStore.DataList;
|
|
pvpStores.Sort((a, b) => a.CellId.CompareTo(b.CellId));
|
|
for (int i = 0; i < pvpStores.Count; i++)
|
|
{
|
|
GameObject go;
|
|
PvpStore pvpStore = pvpStores[i];
|
|
switch (pvpStore.SpecialRoot)
|
|
{
|
|
case "item_special_bait1":
|
|
go = Instantiate(item_special_bait1, content);
|
|
break;
|
|
case "item_special_bait2":
|
|
go = Instantiate(item_special_bait2, content);
|
|
break;
|
|
case "item_special_money1":
|
|
go = Instantiate(item_special_money1, content);
|
|
break;
|
|
case "item_special_money2":
|
|
go = Instantiate(item_special_money2, content);
|
|
break;
|
|
case "item_special_skin":
|
|
go = Instantiate(item_special_skin, content);
|
|
break;
|
|
default:
|
|
go = Instantiate(item, content);
|
|
break;
|
|
}
|
|
go.SetActive(true);
|
|
pvpStoreItems.Add(go);
|
|
PvpStoreItem pvpStoreItem = go.GetComponent<PvpStoreItem>();
|
|
pvpStoreItem.Init(pvpStore, fishingEventData.IsBuyPVPItem(pvpStore.Id));
|
|
}
|
|
SetTimer();
|
|
}
|
|
private void Start()
|
|
{
|
|
btn_mask.onClick.AddListener(OnClickClose);
|
|
btn_close.onClick.AddListener(OnClickClose);
|
|
}
|
|
void OnClickClose()
|
|
{
|
|
UIManager.Instance.DestroyUI(UITypes.EventFishingduelShopPopupPanel);
|
|
}
|
|
void SetTimer()
|
|
{
|
|
TimeSpan now = endTime - ZZTimeHelper.UtcNow().UtcNowOffset();
|
|
text_time.text = LocalizationMgr.GetFormatTextValue("UI_COMMON_refresh",
|
|
ConvertTools.ConvertTime2(now.Days, now.Hours, now.Minutes, now.Seconds));
|
|
double seconds = now.TotalSeconds;
|
|
timer = this.AttachTimer((float)seconds, Refresh,
|
|
(elapsed) =>
|
|
{
|
|
now = endTime - ZZTimeHelper.UtcNow().UtcNowOffset();
|
|
text_time.text = LocalizationMgr.GetFormatTextValue("UI_COMMON_refresh",
|
|
ConvertTools.ConvertTime2(now.Days, now.Hours, now.Minutes, now.Seconds));
|
|
}, useRealTime: true);
|
|
}
|
|
|
|
void Refresh()
|
|
{
|
|
timer?.Cancel();
|
|
timer = null;
|
|
SetData();
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
timer?.Cancel();
|
|
timer = null;
|
|
}
|
|
}
|