备份CatanBuilding瘦身独立工程
This commit is contained in:
61
Assets/Scripts/UI/Shop/BlackFridayCouponBanner.cs
Normal file
61
Assets/Scripts/UI/Shop/BlackFridayCouponBanner.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
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 { }
|
||||
}
|
||||
Reference in New Issue
Block a user