211 lines
5.0 KiB
C#
211 lines
5.0 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2021-04-12
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "BeautySkinPanel" company="Kunpo"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
|
|
using DG.Tweening;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace G.UI
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class BeautySkinPanel : KUIWidget
|
|
{
|
|
class BeautySkinItemWidget : KUIWidget
|
|
{
|
|
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpName;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpLabel;
|
|
[KUIFlag]
|
|
Image _imgIcon;
|
|
[KUIFlag]
|
|
Button _btnState;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpState;
|
|
[KUIFlag]
|
|
Image _imgCostIcon;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpCostCount;
|
|
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
|
|
public override void Refresh()
|
|
{
|
|
if (this.data is BeautyProxy.BeautyInfo beautyInfo)
|
|
{
|
|
ItemBeautySkin skin = beautyInfo.skins[this.index];
|
|
//_tmpLabel.text = skin.label;
|
|
_tmpName.text = skin.name;
|
|
if (skin.icon != null && skin.icon.Length > 0)
|
|
IconProxy.Instance.SetSpriteAsync(_imgIcon, skin.icon[0]);
|
|
|
|
if (skin.isHave)
|
|
{
|
|
if (beautyInfo.IsSetSkin(skin))
|
|
{
|
|
_btnState.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
_btnState.gameObject.SetActive(true);
|
|
_tmpState.text = "穿戴";
|
|
}
|
|
RefreshCost(0, 0);
|
|
}
|
|
else
|
|
{
|
|
_btnState.gameObject.SetActive(true);
|
|
_tmpState.text = "兑换";
|
|
RefreshCost(skin.cost[0], skin.cost[1]);
|
|
}
|
|
|
|
//StartCoroutine(BeautyWindow.LoadBeautySkin(skin, _imgPicture, _skeleton));
|
|
}
|
|
}
|
|
|
|
void RefreshCost(int id, int count)
|
|
{
|
|
if (id == 0)
|
|
{
|
|
_imgCostIcon.gameObject.SetActive(false);
|
|
_tmpCostCount.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
_imgCostIcon.gameObject.SetActive(true);
|
|
_tmpCostCount.gameObject.SetActive(true);
|
|
var propItem = ItemProxy.Instance.GetStaticItem<ItemProp>(id);
|
|
if (propItem != null)
|
|
IconProxy.Instance.SetSprite(_imgCostIcon, propItem.icon);
|
|
_tmpCostCount.text = "x" + count.ToString();
|
|
}
|
|
}
|
|
|
|
private void OnBtnClick()
|
|
{
|
|
if (this.data is BeautyProxy.BeautyInfo beautyInfo)
|
|
{
|
|
ItemBeautySkin skin = beautyInfo.skins[this.index];
|
|
PostNotification(GlobalDefine.EVENT_BEAUTY_SKIN, skin);
|
|
}
|
|
}
|
|
|
|
private void OnStateBtnClick()
|
|
{
|
|
if (this.data is BeautyProxy.BeautyInfo beautyInfo)
|
|
{
|
|
ItemBeautySkin skin = beautyInfo.skins[this.index];
|
|
if (skin.isHave)
|
|
{
|
|
if (!beautyInfo.IsSetSkin(skin))
|
|
{
|
|
if (BeautyProxy.Instance.SetSkin(beautyInfo, skin))
|
|
{
|
|
PostNotification(GlobalDefine.EVENT_BEAUTY_SKIN, skin);
|
|
_Instance.Refresh();
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var costInfo = skin.costInfo;
|
|
if (MoneyProxy.Instance.CheckAndCostMoney(costInfo))
|
|
{
|
|
if (BeautyProxy.Instance.BuySkin(beautyInfo, skin))
|
|
PostNotification(GlobalDefine.EVENT_SHOW_TOAST, "兑换成功");
|
|
Refresh();
|
|
}
|
|
else
|
|
{
|
|
PostNotification(GlobalDefine.EVENT_SHOW_TOAST, KLocalization.GetLocalString(36));
|
|
}
|
|
}
|
|
}
|
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
SetViewData();
|
|
GetComponent<Button>().onClick.AddListener(this.OnBtnClick);
|
|
_btnState.onClick.AddListener(this.OnStateBtnClick);
|
|
}
|
|
}
|
|
|
|
#region Field
|
|
|
|
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
[KUIFlag]
|
|
Button _btnClose;
|
|
[KUIFlag]
|
|
KUIList __listSkins;
|
|
[KUIFlag]
|
|
RectTransform _goPanel;
|
|
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
public override void Refresh()
|
|
{
|
|
if (this.data is BeautyProxy.BeautyInfo beautyInfo)
|
|
{
|
|
var beautyItem = beautyInfo.item;
|
|
|
|
__listSkins.Clear();
|
|
for (int i = 0; i < beautyInfo.skins.Length; i++)
|
|
{
|
|
var skin = beautyInfo.skins[i];
|
|
var item = __listSkins.GetItem();
|
|
item.index = i;
|
|
item.SetData(beautyInfo);
|
|
}
|
|
}
|
|
}
|
|
|
|
void OnCloseBtnClick()
|
|
{
|
|
_goPanel.DOAnchorPos(new Vector2(0, -400), 0.3f, true).SetEase(Ease.InQuad).OnComplete(this.Close);
|
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Unity
|
|
|
|
static BeautySkinPanel _Instance;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private void Awake()
|
|
{
|
|
_Instance = this;
|
|
SetViewData();
|
|
GetComponent<Button>().onClick.AddListener(this.OnCloseBtnClick);
|
|
|
|
__listSkins.AddTemplate<BeautySkinItemWidget>(true);
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
_goPanel.DOAnchorPos(Vector2.zero, 0.3f, true).SetEase(Ease.OutQuad);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|