Files
MinFt/Client/Assets/Scripts/UI/Shop/BlackFridayCouponBanner.cs
2026-04-27 12:07:32 +08:00

62 lines
2.2 KiB
C#

using System;
using asap.core;
using cfg;
using GameCore;
using TMPro;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
public class BlackFridayCouponBanner : MonoBehaviour
{
private BlackFridayCouponData _data;
[SerializeField] private TMP_Text textBanner, textTimer;
[SerializeField] private DiamondShopSlot[] slots;
[SerializeField] private Image bgBanner;
private readonly IEventAggregator _eventAggregator = new EventAggregator();
public void Awake()
{
_data = GContext.container.Resolve<PlayerShopData>().CouponData;
if (_data is not { IsActive: true })
{
SetupBlackFriday(false, _eventAggregator);
return;
}
SetupBlackFriday(true, _eventAggregator);
textBanner.text = LocalizationMgr.GetFormatTextValue("UI_GiftPopupPanel_13_5", _data.Multiplier + "%");
textTimer.text = ConvertTools.ConvertTime2(_data.RemainingTime);
ColorUtility.TryParseHtmlString(
GContext.container.Resolve<Tables>().TbEventCoupon[_data.RedirectId].FontColorTime, out var c);
textTimer.color = c;
Observable.Interval(TimeSpan.FromSeconds(1.0f))
.Subscribe(_ => {
textTimer.text = ConvertTools.ConvertTime2(_data.RemainingTime);
if (!_data.IsActive)
SetupBlackFriday(false, _eventAggregator);
}).AddTo(this);
_eventAggregator.GetEvent<EventTerminateBlackFriday>().Subscribe(_ => {
// _data.SetStateBought();
SetupBlackFriday(_data.IsActive, _eventAggregator);
}).AddTo(this);
GContext.container.Resolve<IUIService>().SetImageSprite(bgBanner,
GContext.container.Resolve<Tables>().TbEventCoupon[_data.RedirectId].LabelShop1);
}
private void SetupBlackFriday(bool isOpen, IEventAggregator ea)
{
if (isOpen)
{
gameObject.SetActive(true);
foreach (var slot in slots)
slot.SetUpBlackFriday(true, ea);
}
else
{
foreach (var slot in slots)
slot.SetUpBlackFriday(false, ea);
Destroy(gameObject);
}
}
public class EventTerminateBlackFriday { }
}