备份CatanBuilding瘦身独立工程
This commit is contained in:
125
Assets/Scripts/UI/BattlePass/BattleTaskPanel.cs
Normal file
125
Assets/Scripts/UI/BattlePass/BattleTaskPanel.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
using asap.core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
|
||||
public class BattleTaskPanel : BasePanel
|
||||
{
|
||||
#region Fields
|
||||
[SerializeField]
|
||||
TMP_Text
|
||||
txt_weeklyTaskTiemr,
|
||||
txt_dailyTaskTimer;
|
||||
|
||||
[SerializeField]
|
||||
GameObject
|
||||
go_WTslot,
|
||||
go_DTslot;
|
||||
|
||||
[SerializeField]
|
||||
Transform
|
||||
tran_WTbanner,
|
||||
tran_slotParent;
|
||||
#endregion
|
||||
|
||||
BattlePassDataProvider _dataProviver;
|
||||
|
||||
|
||||
#region Func
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_dataProviver = GContext.container.Resolve<BattlePassDataProvider>();
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
go_DTslot.SetActive(false);
|
||||
go_WTslot.SetActive(false);
|
||||
_dataProviver.CheckIfRefreshDailyTask();
|
||||
_dataProviver.CheckIfRefreshWeekTask();
|
||||
RefreshView();
|
||||
}
|
||||
|
||||
private void SetDTTimer(TimeSpan duration)
|
||||
{
|
||||
txt_dailyTaskTimer.text = ConvertTools.ConvertTime2(duration);
|
||||
var timer = Observable.Interval(TimeSpan.FromSeconds(1))
|
||||
.TakeWhile(seconds => seconds <= duration.TotalSeconds)
|
||||
.Subscribe(seconds =>
|
||||
txt_dailyTaskTimer.text = ConvertTools.ConvertTime2(duration.Subtract(TimeSpan.FromSeconds(seconds)))
|
||||
, () => { _dataProviver.Data.RefreshDaiyTask(); RefreshView(); })
|
||||
.AddTo(disposables)
|
||||
;
|
||||
}
|
||||
|
||||
private void SetWTTimer(TimeSpan duration)
|
||||
{
|
||||
txt_weeklyTaskTiemr.text = ConvertTools.ConvertTime2(duration);
|
||||
var timer = Observable.Interval(TimeSpan.FromSeconds(1))
|
||||
.TakeWhile(seconds => seconds <= duration.TotalSeconds)
|
||||
.Subscribe(seconds =>
|
||||
txt_weeklyTaskTiemr.text = ConvertTools.ConvertTime2(duration.Subtract(TimeSpan.FromSeconds(seconds)))
|
||||
, () => { _dataProviver.Data.RefreshWeeklyTask(); RefreshView(); })
|
||||
.AddTo(disposables)
|
||||
;
|
||||
}
|
||||
|
||||
private void RefreshView()
|
||||
{
|
||||
SetDTTimer(_dataProviver.GetDailyTaskDuration());
|
||||
SetWTTimer(_dataProviver.GetWeeklyTaskDuration());
|
||||
var taskSlot = tran_slotParent.GetComponentsInChildren<BPTaskSlot>();
|
||||
foreach (var slot in taskSlot)
|
||||
{
|
||||
if (slot.gameObject != go_DTslot && slot.gameObject != go_WTslot)
|
||||
{
|
||||
Destroy(slot.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
var dailyTasks = _dataProviver.Data.BattleTask.dic_dailyTasks;
|
||||
var weeklyTasks = _dataProviver.Data.BattleTask.dic_weeklyTasks;
|
||||
var slotP = new List<BPTaskSlot>();
|
||||
foreach (var task in dailyTasks)
|
||||
{
|
||||
var slot = Instantiate(go_DTslot, tran_slotParent).GetComponent<BPTaskSlot>();
|
||||
slot.SetData(task.Key, true);
|
||||
slotP.Add(slot);
|
||||
}
|
||||
|
||||
slotP.Sort();
|
||||
foreach (var slot in slotP)
|
||||
{
|
||||
slot.transform.SetAsLastSibling();
|
||||
}
|
||||
tran_WTbanner.SetAsLastSibling();
|
||||
|
||||
slotP.Clear();
|
||||
|
||||
foreach (var task in weeklyTasks)
|
||||
{
|
||||
var slot = Instantiate(go_WTslot, tran_slotParent).GetComponent<BPTaskSlot>();
|
||||
slot.SetData(task.Key, false);
|
||||
slotP.Add(slot);
|
||||
}
|
||||
|
||||
slotP.Sort();
|
||||
foreach (var slot in slotP)
|
||||
{
|
||||
slot.transform.SetAsLastSibling();
|
||||
}
|
||||
}
|
||||
public void Open()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
public void Close()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user