131 lines
3.9 KiB
C#
131 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using EnhancedUI.EnhancedScroller;
|
|
using asap.core;
|
|
using Event1v1Battle.Data;
|
|
using GameCore;
|
|
using TMPro;
|
|
using TimeManager;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Event1v1Battle.Panel.RewardPanel
|
|
{
|
|
/// <summary>
|
|
/// 1v1扇耳光大赛奖励弹窗面板 Event1v1BattleSlapRewardPopupPanel
|
|
/// </summary>
|
|
public class Event1v1BattleSlapRewardPopupPanel : BasePanel,IEnhancedScrollerDelegate
|
|
{
|
|
#region UI Elements
|
|
|
|
private Button _btnClose; // 关闭按钮
|
|
private EnhancedScroller _enhancedScroller;
|
|
private Event1v1BattleSlapRewardCell _cell;
|
|
private TMP_Text _timeText;
|
|
#endregion
|
|
|
|
private Animation _uiAnimation;
|
|
private List<List<ItemData>> _rewards;
|
|
private Event1v1BattleSlapData _data;
|
|
|
|
private void Awake()
|
|
{
|
|
_btnClose = gameObject.FindChildGameObject("btn_close")?.GetComponentInChildren<Button>();
|
|
if (_btnClose != null)
|
|
_btnClose.onClick.AddListener(OnClickClose);
|
|
|
|
_enhancedScroller = GetComponentInChildren<EnhancedScroller>();
|
|
_cell = gameObject.GetComponentInChildren<Event1v1BattleSlapRewardCell>();
|
|
_cell?.gameObject.SetActive(false);
|
|
_timeText=gameObject.FindChildGameObject("text_time")?.GetComponent<TMP_Text>();
|
|
_uiAnimation = GetComponent<Animation>();
|
|
|
|
GContext.container.Resolve<ITimeTickService>()?.SecondTick?.Subscribe(_ => UpdateEventTime()).AddTo(disposables);
|
|
}
|
|
|
|
protected override void OnDestroy()
|
|
{
|
|
base.OnDestroy();
|
|
|
|
if (_btnClose != null)
|
|
_btnClose.onClick.RemoveAllListeners();
|
|
}
|
|
|
|
#region UI Refresh
|
|
private void UpdateEventTime()
|
|
{
|
|
if (_timeText)
|
|
_timeText.text = ConvertTools.ConvertTime2(_data.RemainingTime);
|
|
}
|
|
private void RefreshUI()
|
|
{
|
|
UpdateEventTime();
|
|
_enhancedScroller.Delegate = this;
|
|
_enhancedScroller.ReloadData();
|
|
_enhancedScroller.JumpToDataIndex(_rewards.Count-1);
|
|
}
|
|
#endregion
|
|
|
|
#region Button Actions
|
|
|
|
private void OnClickClose()
|
|
{
|
|
_ = ClosePanel();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Panel Navigation
|
|
|
|
public async Task ClosePanel()
|
|
{
|
|
//if (_uiAnimation != null)
|
|
//_uiAnimation.Play("popup_common_out");
|
|
|
|
await Awaiters.Seconds(0.25f);
|
|
UIManager.Instance.DestroyUI(UITypes.Event1v1BattleSlapRewardPopupPanel);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region public
|
|
|
|
public void SetData(Event1v1BattleSlapData data)
|
|
{
|
|
this._data=data;
|
|
_rewards ??=_data.GetAllStageRewards();
|
|
RefreshUI();
|
|
}
|
|
|
|
#endregion
|
|
#region enhanced scroller
|
|
|
|
public int GetNumberOfCells(EnhancedScroller scroller)
|
|
{
|
|
return _rewards.Count;
|
|
}
|
|
|
|
public float GetCellViewSize(EnhancedScroller scroller, int dataIndex)
|
|
{
|
|
return ((RectTransform)_cell.transform).sizeDelta.y;
|
|
}
|
|
|
|
public EnhancedScrollerCellView GetCellView(EnhancedScroller scroller, int dataIndex, int cellIndex)
|
|
{
|
|
var cell = scroller.GetCellView(_cell);
|
|
if (cell is not Event1v1BattleSlapRewardCell rewardCell) return null;
|
|
cell.gameObject.SetActive(true);
|
|
var index = _rewards.Count - 1 - dataIndex;
|
|
var stageIndex = _data.GetCurrentStageIndex();
|
|
var isCurrent = stageIndex== index;
|
|
var isClaimed = stageIndex>index;
|
|
rewardCell.SetData(_rewards[index], index+1,isCurrent,isClaimed);
|
|
return cell;
|
|
}
|
|
|
|
#endregion enhanced scroller
|
|
}
|
|
}
|