195 lines
4.6 KiB
C#
195 lines
4.6 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2020-12-07
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "ShopPanel.KeyBoxWidget" company="Kunpo"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace G.UI
|
|
{
|
|
partial class ShopPanel
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class KeyBoxWidget : KUIWidget
|
|
{
|
|
#region Field
|
|
|
|
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpName;
|
|
[KUIFlag]
|
|
KUIImage _imgIcon;
|
|
[KUIFlag]
|
|
Button _btnGet;
|
|
[KUIFlag]
|
|
GameObject __goPrice;
|
|
[KUIFlag]
|
|
GameObject __goFree;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpGet;
|
|
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
|
|
private CostWidget _costWidget;
|
|
private AdCostWidget _adCostWidget;
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
public override void Refresh()
|
|
{
|
|
if (this.data is ShopProxy.KeyBox keyBox)
|
|
{
|
|
var boxInfo = BoxProxy.Instance.GetBoxInfo(keyBox.itemId);
|
|
if (boxInfo != null)
|
|
{
|
|
_tmpName.text = boxInfo.item.name;
|
|
_imgIcon.ShowSprite(Mathf.Max(0, boxInfo.item.quality - 1));
|
|
|
|
var costInfo = boxInfo.item.priceInfo;
|
|
if (costInfo.id > 0 && MoneyProxy.Instance.CheckMoney(costInfo))
|
|
{
|
|
int cur = MoneyProxy.Instance.GetMoney(costInfo.id);
|
|
SetKey(costInfo.id, cur, costInfo.count);
|
|
}
|
|
else
|
|
{
|
|
var count = keyBox.freeCount;
|
|
if (count.x > 0)
|
|
{
|
|
SetFree(count.x, count.y);
|
|
}
|
|
else if (keyBox.recoverSecond > 0)
|
|
{
|
|
var seconds = keyBox.remainSecond;
|
|
SetTime(seconds);
|
|
}
|
|
else
|
|
{
|
|
int cur = MoneyProxy.Instance.GetMoney(costInfo.id);
|
|
SetKey(costInfo.id, cur, costInfo.count);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void SetKey(int id, int cur, int max)
|
|
{
|
|
_tmpGet.text = "";
|
|
__goPrice.SetActive(true);
|
|
__goFree.SetActive(false);
|
|
_costWidget.SetPrice(id, cur, max);
|
|
}
|
|
|
|
private void SetFree(int cur, int max)
|
|
{
|
|
_tmpGet.text = "";
|
|
__goFree.SetActive(true);
|
|
__goPrice.SetActive(false);
|
|
_adCostWidget.SetCount(cur, max);
|
|
}
|
|
|
|
private void SetTime(int seconds)
|
|
{
|
|
__goPrice.SetActive(false);
|
|
__goFree.SetActive(false);
|
|
|
|
var canOpen = seconds <= 0;
|
|
_btnGet.interactable = canOpen;
|
|
_tmpGet.text = canOpen ? "领取" : F.Utils.Time.ToTimeString2(seconds);
|
|
_imgIcon.ShowSprite(canOpen ? 0 : 1);
|
|
}
|
|
|
|
public void UpdateState()
|
|
{
|
|
if (this.data is ShopProxy.KeyBox keyBox)
|
|
{
|
|
if (keyBox.recoverSecond > 0)
|
|
{
|
|
var seconds = keyBox.remainSecond;
|
|
//_goRemainTime.SetActive(seconds > 0);
|
|
//_tmpRemainTime.text = F.Utils.Time.ToTimeString2(seconds);
|
|
bool canOpen = keyBox.canOpen;
|
|
if (_btnGet.interactable != canOpen)
|
|
{
|
|
_btnGet.interactable = canOpen;
|
|
_imgIcon.ShowSprite(canOpen ? 0 : _imgIcon.sprites.Length - 1);
|
|
}
|
|
_tmpGet.text = canOpen ? "领取" : F.Utils.Time.ToTimeString2(seconds);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnGetBtnClick()
|
|
{
|
|
if (this.data is ShopProxy.KeyBox keyBox)
|
|
{
|
|
if (__goFree.activeSelf)
|
|
{
|
|
if (keyBox.CheckFreeCount())
|
|
KPlatform.Instance.PlayRewardAd("shop", $"ad_shop_key_box_{keyBox.id}", (error, message) =>
|
|
{
|
|
if (error == 0)
|
|
{
|
|
keyBox.CostFreeCount();
|
|
ShopProxy.Instance.OpenKeyBox(keyBox.id, true);
|
|
Refresh();
|
|
}
|
|
});
|
|
else
|
|
ToastBox.ShowText("次数不足");
|
|
}
|
|
else
|
|
{
|
|
int result = ShopProxy.Instance.OpenKeyBox(keyBox.id, false);
|
|
switch (result)
|
|
{
|
|
case 1:
|
|
ToastBox.ShowText("所需货币不足");
|
|
break;
|
|
case 2:
|
|
ToastBox.ShowText("时间未到");
|
|
break;
|
|
case 3:
|
|
ToastBox.ShowText("宝箱错误");
|
|
break;
|
|
}
|
|
Refresh();
|
|
}
|
|
}
|
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Unity
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private void Awake()
|
|
{
|
|
SetViewData();
|
|
_costWidget = __goPrice.AddComponent<CostWidget>();
|
|
_adCostWidget = __goFree.AddComponent<AdCostWidget>();
|
|
|
|
_btnGet.onClick.AddListener(this.OnGetBtnClick);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
}
|