Files
MinFt/Client/Assets/Scripts/UI/Advert/AdvertRewardPanel.cs
Liubing\LB 3d8d4d18f3 first commit
先修复一下,错误的场景

删除不必要的钓场资产

修复into场景

update:更新meta文件,修复报错

update:修复资源

修复第一章节建造

修复建造第三章

update:删除多余内容

update:更新README.md

update:还原图标

update:更新README

update:更新配置
2026-04-28 02:17:22 +08:00

168 lines
5.4 KiB
C#

using asap.core;
using cfg;
using game;
using GameCore;
using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class AdvertRewardPanel : MonoBehaviour
{
Tables _tables;
ShopPackManager packM;
Pack pack;
int num;
RewardItemNew[] rewardItems;
//倒计时
GameObject cd;
TMP_Text text_time;
//购买按钮
Button btn_buy;
AdvertButton btn_advert;
PlayerShopData shopData;
Timer timer;
List<ItemData> itemDataGift;
Daily daily;
private void Awake()
{
shopData = GContext.container.Resolve<PlayerShopData>();
_tables = GContext.container.Resolve<Tables>();
rewardItems = transform.Find("reward_panel").GetComponentsInChildren<RewardItemNew>();
cd = transform.Find("reward_panel/cd").gameObject;
text_time = transform.Find("reward_panel/cd/text_time").GetComponent<TMP_Text>();
btn_buy = transform.Find("reward_panel/btn_free/btn_green").GetComponent<Button>();
btn_advert = transform.Find("reward_panel/AdvertBtn").GetComponent<AdvertButton>();
}
private void Start()
{
btn_buy.onClick.AddListener(OnBuySuccess);
btn_advert.SetData(() =>
{
shopData.AddAdvertCount(packM.ID);
//广告成功
OnBuySuccess();
}, AdvertPopupType.Chest);
var id = GContext.container.Resolve<PlayerData>().priceLevel.DailyGiftPackList[0];
packM = shopData.TbPackManagerGetOrDefault(id);
pack = _tables.TbPack.GetOrDefault(packM.PackID[0]);
num = shopData.GetShopPackBuyCount(packM.ID);
SetTimer();
SetRewardItems();
SetBuy();
}
void OnBuySuccess()
{
num += 1;
shopData.AddShopPackDailyBuyCount("DailyGiftDisplay");
shopData.AddShopPackDailyBuyCount(packM.ID, 1);
GContext.Publish(new ShowData(itemDataGift));
GContext.container.Resolve<PlayerItemData>().AddItem(itemDataGift, null);
//ShowGiftNoticePanel();
GContext.Publish(new ShowData());
SetBuy();
shopData.SetAdvRedPoint();
#if AGG
using (var e = GEvent.GameEvent("item_change", gaSend: true))
{
e.AddContent("item_id", GContext.container.Resolve<PlayerData>().priceLevel.DailyGiftDisplay)
.AddContent("state_info", "get")
.AddContent("get_times", shopData.GetShopPackBuyCount("DailyGiftDisplay"))
.AddContent("change_num", 1);
}
#endif
}
void SetTimer()
{
DateTime now = ZZTimeHelper.UtcNow().UtcNowOffset();
daily = packM.TimeDefinition as Daily;
var DailyGiftPackList = GContext.container.Resolve<PlayerData>().priceLevel.DailyGiftPackList;
int id;
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;
num = shopData.GetShopPackBuyCount(localPackM.ID);
break;
}
}
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, ReStart,
(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 ShowGiftNoticePanel()
//{
// int showGiftNoticePanel = PlayerPrefs.GetInt("GiftNoticePanel", 0);
// ISettingService settingService = GContext.container.Resolve<ISettingService>();
// if (showGiftNoticePanel == 0 && !settingService.Notice)
// {
// _ = UIManager.Instance.ShowUI(UITypes.GiftNoticePanel);
// }
//}
void SetRewardItems()
{
//体力膨胀 不膨胀
itemDataGift = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropIdAndType(pack.DropID);
for (int i = 0; i < rewardItems.Length; i++)
{
if (i < itemDataGift.Count)
{
rewardItems[i].SetData(itemDataGift[i], isCanClick: true);
}
else
{
rewardItems[i].gameObject.SetActive(false);
}
}
}
void SetBuy()
{
var adConfig = _tables.TbAdConfig.DataList[0];
bool vipFree = adConfig.VipFree <= GContext.container.Resolve<PlayerData>().vip;
if (vipFree)
{
btn_buy.gameObject.SetActive(num <= 1);
btn_advert.gameObject.SetActive(false);
}
else
{
btn_buy.gameObject.SetActive(num == 0);
btn_advert.gameObject.SetActive(num == 1);
}
cd.gameObject.SetActive(num > 1);
}
void ReStart()
{
timer.Cancel();
timer = null;
shopData.InitShopPackData();
num = 0;
SetBuy();
SetTimer();
}
}