Files
ft/Client/Assets/Scripts/Event1v1Battle/Panel/Event1v1BattleSlapFacePopupPanel.cs
2026-06-29 21:18:33 +08:00

107 lines
3.0 KiB
C#

using System;
using System.Threading.Tasks;
using Activity;
using asap.core;
using Event1v1Battle.Data;
using GameCore;
using TimeManager;
using TMPro;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
namespace Event1v1Battle.Panel
{
/// <summary>
/// Event1v1BattleSlapReviewPopupPanel
/// </summary>
public class Event1v1BattleSlapFacePopupPanel:BasePanel
{
private Button _btnStart; // 开始按钮
private Button _btnClose; // 关闭按钮
private TMP_Text _textEventTime; // 活动剩余时间
#region Manager
private Event1v1BattleSlapManager _manager;
private Event1v1BattleSlapManager Manager => _manager ??= ActivityResolver.Resolve<Event1v1BattleSlapManager>();
private Event1v1BattleSlapData Data => Manager?.LoadData();
#endregion
private Animation _uiAnimation;
private void Awake()
{
// Buttons
_btnStart = gameObject.FindChildGameObject("btn_go")?.GetComponentInChildren<Button>();
if (_btnStart)
_btnStart.onClick.AddListener(OnClickClose);
_btnClose=gameObject.FindChildGameObject("btn_close")?.GetComponentInChildren<Button>();
if (_btnClose)
_btnClose.onClick.AddListener(OnClickClose);
// Text elements
_textEventTime = gameObject.FindChildGameObject("text_time")?.GetComponent<TMP_Text>();
// Animation
_uiAnimation = GetComponent<Animation>();
// Start timer
GContext.container.Resolve<ITimeTickService>()?.SecondTick?.Subscribe(UpdateTimer).AddTo(disposables);
}
protected override void OnDestroy()
{
base.OnDestroy();
if (_btnStart )
_btnStart.onClick.RemoveAllListeners();
if (_btnClose)
_btnClose.onClick.RemoveAllListeners();
}
protected override void Start()
{
// 播放入场动画
if (_uiAnimation )
_uiAnimation.Play("popup_common_show");
UpdateTimer(0);
}
#region UI Refresh
private void UpdateTimer(long _ = 0)
{
if (_textEventTime || Data == null) return;
_textEventTime.text = ConvertTools.ConvertTime2(Data.RemainingTime);
}
#endregion
#region Button Actions
private async void OnClickClose()
{
try
{
await ClosePanel();
}
catch (Exception e)
{
Debug.LogError(e);
}
}
#endregion
#region Panel Navigation
private async Task ClosePanel()
{
if (_uiAnimation )
_uiAnimation.Play("popup_common_out");
await Awaiters.Seconds(0.25f);
UIManager.Instance.DestroyUI(UITypes.Event1v1BattleSlapFacePopupPanel);
}
#endregion
}
}