// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2021-05-02
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
//
//
// ***********************************************************************
namespace G.UI
{
using TMPro;
using UnityEngine;
using UnityEngine.UI;
///
///
///
partial class BonusLevelBox
{
#region Field
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
[KUIFlag]
TextMeshProUGUI _tmpRemainCount;
[KUIFlag]
TextMeshProUGUI _tmpRemainTimer;
[KUIFlag]
Button _btnClose;
[KUIFlag]
Button _btnBack;
[KUIFlag]
Button _btnChallenge;
[KUIFlag]
TextMeshProUGUI _tmpChallenge;
[KUIFlag]
Button _btnTips;
[KUIFlag]
TextMeshProUGUI _tmpTitle;
[KUIFlag]
Button _btnUp;
[KUIFlag]
GameObject __goUpCost;
[KUIFlag]
KUIList __listRewards;
[KUIFlag]
KUIList __listStar;
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
private CostWidget _upCostWidget;
private int _currentStar = 0;
#endregion
#region Method
///
///
///
public void InitView()
{
SetViewData();
_btnClose.onClick.AddListener(this.OnBackBtnClick);
_btnBack.onClick.AddListener(this.OnBackBtnClick);
_btnChallenge.onClick.AddListener(this.OnChallengeBtnClick);
_btnTips.onClick.AddListener(this.OnTipsBtnClick);
_btnUp.onClick.AddListener(this.OnUpBtnClick);
_upCostWidget = __goUpCost.AddComponent();
__listRewards.AddTemplate(true);
__listStar.AddTemplate(true);
}
///
///
///
public void RefreshView()
{
var amount = TimeProxy.Instance.GetTimeInfo2(TimeProxy.奖励关);
_tmpRemainCount.text = $"本日可挑战次数:{amount.remain}/{amount.max}";
RefreshRewards();
}
void RefreshRewards()
{
if (this.data is ActivityInfo activity)
{
_tmpTitle.text = activity.name;
var subInfos = activity.subInfos;
if (subInfos != null)
{
if (_currentStar >= subInfos.Length)
_currentStar = subInfos.Length - 1;
var subInfo = activity.subInfos[_currentStar];
__listStar.Clear();
for (int i = 0; i < subInfos.Length; i++)
{
__listStar.GetItem().SetGray(i > _currentStar);
}
__listRewards.Clear();
if (subInfo.rewardInfos != null)
for (int i = 0; i < subInfo.rewardInfos.Length; i++)
{
__listRewards.GetItem().SetItem(subInfo.rewardInfos[i]);
}
_upCostWidget.SetAndCheckPrice(1, 5000 + 5000 * _currentStar);
}
}
}
private void OnBackBtnClick()
{
CloseWindow(this);
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
private void OnChallengeBtnClick()
{
if (this.data is ActivityInfo activity)
{
var args = activity.item.typeArgs;
if (args != null && args.Length > 0)
LevelProxy.Instance.StartSpecial(args[0]);
}
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
private void OnTipsBtnClick()
{
MessageBox.ShowMessage(KLocalization.GetLocalString(61), KLocalization.GetLocalString(62));
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
private void OnUpBtnClick()
{
var rnd = Random.value;
if (rnd < 0.1f)
{
_currentStar += 2;
}
else if (rnd < 0.6f)
{
_currentStar += 1;
}
RefreshRewards();
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
#endregion
}
}