shaoxiadiablo/Assets/AGame/Scripts/UI/ShopPanel/ShopPanel.TimeBoxWidget.cs
2025-05-18 01:04:31 +08:00

115 lines
3.2 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2020-12-10
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "ShopPanel.TimeBoxWidget" company="Kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace G.UI
{
partial class ShopPanel
{
/// <summary>
///
/// </summary>
public class TimeBoxWidget : KUIWidget
{
#region Field
//[KUIFlag]
//GameObject _goRemainTime;
//[KUIFlag]
//TextMeshProUGUI _tmpRemainTime;
[KUIFlag]
#pragma warning disable CS0649 // 从未对字段“ShopBoxItem._imgIcon”赋值字段将一直保持其默认值 null
Image _imgIcon;
#pragma warning restore CS0649 // 从未对字段“ShopBoxItem._imgIcon”赋值字段将一直保持其默认值 null
[KUIFlag]
TextMeshProUGUI _tmpName;
[KUIFlag]
#pragma warning disable CS0649 // 从未对字段“ShopBoxItem._btnGet”赋值字段将一直保持其默认值 null
Button _btnGet;
#pragma warning restore CS0649 // 从未对字段“ShopBoxItem._btnGet”赋值字段将一直保持其默认值 null
[KUIFlag]
#pragma warning disable CS0649 // 从未对字段“ShopBoxItem._tmpGet”赋值字段将一直保持其默认值 null
TextMeshProUGUI _tmpGet;
#pragma warning restore CS0649 // 从未对字段“ShopBoxItem._tmpGet”赋值字段将一直保持其默认值 null
private KUIImage _icon;
#endregion
#region Method
public override void Refresh()
{
if (this.data is ShopProxy.TimeBox boxInfo)
{
var seconds = boxInfo.remainSecond;
//_tmpRemainTime.text = F.Utils.Time.ToTimeString2(seconds);
//_tmpName.text = boxInfo.name;
_btnGet.interactable = boxInfo.canOpen;
_tmpGet.text = boxInfo.canOpen ? "领取" : F.Utils.Time.ToTimeString2(seconds);
_icon.ShowSprite(boxInfo.canOpen ? 0 : _icon.sprites.Length - 1);
}
}
public void UpdateState()
{
if (this.data is ShopProxy.TimeBox boxInfo)
{
var seconds = boxInfo.remainSecond;
//_goRemainTime.SetActive(seconds > 0);
//_tmpRemainTime.text = F.Utils.Time.ToTimeString2(seconds);
bool canOpen = boxInfo.canOpen;
if (_btnGet.interactable != canOpen)
{
_btnGet.interactable = canOpen;
_icon.ShowSprite(canOpen ? 0 : _icon.sprites.Length - 1);
}
_tmpGet.text = canOpen ? "领取" : F.Utils.Time.ToTimeString2(seconds);
}
}
private void OnGetBtnClick()
{
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
if (this.data is ShopProxy.TimeBox boxInfo)
{
if (ShopProxy.Instance.OpenGiftBox(boxInfo.id))
{
_icon.framesPerSecond = 20;
UpdateState();
}
}
}
#endregion
#region Unity
/// <summary>
///
/// </summary>
private void Awake()
{
SetViewData();
_btnGet.onClick.AddListener(this.OnGetBtnClick);
_icon = _imgIcon.GetComponent<KUIImage>();
}
#endregion
}
}
}