126 lines
3.8 KiB
C#
126 lines
3.8 KiB
C#
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>();
|
|
}
|
|
private void OnEnable()
|
|
{
|
|
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;
|
|
float inflationRate = _dataProviver.Data.BattlePassRecord.InflationRate;
|
|
var slotP = new List<BPTaskSlot>();
|
|
foreach (var task in dailyTasks)
|
|
{
|
|
var slot = Instantiate(go_DTslot, tran_slotParent).GetComponent<BPTaskSlot>();
|
|
slot.SetData(task.Key, true, inflationRate);
|
|
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, inflationRate);
|
|
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
|
|
}
|