280 lines
6.5 KiB
C#
280 lines
6.5 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2021-04-12
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "BeautyGiftPanel" company="Kunpo"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
|
|||
|
using TMPro;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
namespace G.UI
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public class BeautyGiftPanel : KUIWidget
|
|||
|
{
|
|||
|
class GiftWidget : KUIWidget
|
|||
|
{
|
|||
|
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|||
|
[KUIFlag]
|
|||
|
Button _btnGive;
|
|||
|
[KUIFlag]
|
|||
|
Image _imgIcon;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpName;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpDescription;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpCount;
|
|||
|
[KUIFlag]
|
|||
|
KUIImage _imgQuality;
|
|||
|
|
|||
|
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|||
|
|
|||
|
public override void Refresh()
|
|||
|
{
|
|||
|
if (this.data is EntityItemProp gift)
|
|||
|
{
|
|||
|
var propItem = gift.propItem;
|
|||
|
_tmpName.text = propItem.name;
|
|||
|
_tmpDescription.text = propItem.text;
|
|||
|
_tmpCount.text = gift.count.ToString();
|
|||
|
_imgQuality.ShowSprite(propItem.quality);
|
|||
|
IconProxy.Instance.SetSprite(_imgIcon, propItem.icon);
|
|||
|
}
|
|||
|
}
|
|||
|
private void Refresh2()
|
|||
|
{
|
|||
|
if (this.data is EntityItemProp gift)
|
|||
|
{
|
|||
|
_tmpCount.text = gift.count.ToString();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnGiveBtnClick()
|
|||
|
{
|
|||
|
if (_Instance.GiveGift(this.data as EntityItemProp))
|
|||
|
{
|
|||
|
Refresh2();
|
|||
|
}
|
|||
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|||
|
}
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
SetViewData();
|
|||
|
_btnGive.onClick.AddListener(this.OnGiveBtnClick);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#region Field
|
|||
|
|
|||
|
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|||
|
[KUIFlag]
|
|||
|
Button _btnClose;
|
|||
|
[KUIFlag]
|
|||
|
GameObject __goProp1;
|
|||
|
[KUIFlag]
|
|||
|
GameObject __goProp2;
|
|||
|
[KUIFlag]
|
|||
|
KUIList __listGifts;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpTitle;
|
|||
|
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|||
|
|
|||
|
private MoneyWidget _propItem1;
|
|||
|
private MoneyWidget _propItem2;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Method
|
|||
|
|
|||
|
public void ShowGift1()
|
|||
|
{
|
|||
|
_tmpTitle.text = "红颜问候";
|
|||
|
|
|||
|
__goProp1.SetActive(true);
|
|||
|
|
|||
|
__listGifts.Clear();
|
|||
|
var gifts = BeautyProxy.Instance.GetGifts1();
|
|||
|
for (int i = 0; i < gifts.Count; i++)
|
|||
|
{
|
|||
|
__listGifts.GetItem().SetData(gifts[i]);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void ShowGift2()
|
|||
|
{
|
|||
|
__goProp1.SetActive(false);
|
|||
|
_tmpTitle.text = "赏赐红颜";
|
|||
|
|
|||
|
__listGifts.Clear();
|
|||
|
var gifts = BeautyProxy.Instance.GetGifts2();
|
|||
|
for (int i = 0; i < gifts.Count; i++)
|
|||
|
{
|
|||
|
__listGifts.GetItem().SetData(gifts[i]);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public override void Refresh()
|
|||
|
{
|
|||
|
if (this.data is BeautyProxy.BeautyInfo beautyInfo)
|
|||
|
{
|
|||
|
_propItem1.SetMoney(Item.Id.kBeautyLevel, beautyInfo.level);
|
|||
|
_propItem2.SetMoney(Item.Id.kBeautyExp, beautyInfo.exp);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnCloseBtnClick()
|
|||
|
{
|
|||
|
this.Close();
|
|||
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|||
|
}
|
|||
|
|
|||
|
private bool GiveGift(EntityItemProp gift)
|
|||
|
{
|
|||
|
if (this.data is BeautyProxy.BeautyInfo beautyInfo)
|
|||
|
{
|
|||
|
//if (gift.id == 50)
|
|||
|
//{
|
|||
|
// if (beautyInfo.giftFreeCount > 0)
|
|||
|
// {
|
|||
|
// beautyInfo.giftFreeCount--;
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// ToastBox.ShowText("今天免费问候次数不足");
|
|||
|
// return false;
|
|||
|
// }
|
|||
|
//}
|
|||
|
//else if (gift.id == 51)
|
|||
|
//{
|
|||
|
// if (beautyInfo.gifAdCount > 0)
|
|||
|
// {
|
|||
|
// beautyInfo.giftFreeCount--;
|
|||
|
// KPlatform.Instance.PlayRewardAd("ad_beauty_gift", (error) =>
|
|||
|
// {
|
|||
|
// if (error == 0)
|
|||
|
// {
|
|||
|
// bool result1 = HomeProxy.Instance.GiveGift(beautyInfo, gift.item.use);
|
|||
|
// if (result1)
|
|||
|
// {
|
|||
|
// var prop = ItemProxy.Instance.GetStaticItem<ItemProp>(gift.item.use[0]);
|
|||
|
// ToastBox.ShowText($"{prop.name} + {gift.item.use[1]}");
|
|||
|
// Refresh();
|
|||
|
// }
|
|||
|
// //return result;
|
|||
|
// }
|
|||
|
// return;
|
|||
|
// });
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// ToastBox.ShowText("今天广告问候次数不足");
|
|||
|
// return false;
|
|||
|
// }
|
|||
|
//}
|
|||
|
//else if (gift.id == 52)
|
|||
|
//{
|
|||
|
// if (beautyInfo.gifAdCount2 > 0)
|
|||
|
// {
|
|||
|
// beautyInfo.gifAdCount2--;
|
|||
|
// KPlatform.Instance.PlayRewardAd("ad_beauty_gift", (error) =>
|
|||
|
// {
|
|||
|
// if (error == 0)
|
|||
|
// {
|
|||
|
// bool result1 = HomeProxy.Instance.GiveGift(beautyInfo, gift.item.use);
|
|||
|
// if (result1)
|
|||
|
// {
|
|||
|
// var prop = ItemProxy.Instance.GetStaticItem<ItemProp>(gift.item.use[0]);
|
|||
|
// ToastBox.ShowText($"{prop.name} + {gift.item.use[1]}");
|
|||
|
// Refresh();
|
|||
|
// }
|
|||
|
// //return result;
|
|||
|
// }
|
|||
|
// return;
|
|||
|
// });
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// ToastBox.ShowText("今天广告问候次数不足");
|
|||
|
// return false;
|
|||
|
// }
|
|||
|
//}
|
|||
|
|
|||
|
//else if (gift.id == 53 || gift.id == 54 || gift.id == 55 || gift.id == 56)
|
|||
|
//{
|
|||
|
// if (gift.count > 0)
|
|||
|
// {
|
|||
|
// gift.count--;
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// ToastBox.ShowText("道具不足");
|
|||
|
// return false;
|
|||
|
// }
|
|||
|
//}
|
|||
|
if (gift.count > 0)
|
|||
|
{
|
|||
|
gift.count--;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
KUIWindow.OpenWindow<GainwayBox>(gift.item);
|
|||
|
//ToastBox.ShowText("道具不足");
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
var use = gift.item.use;
|
|||
|
bool result = BeautyProxy.Instance.GiveGift(beautyInfo, use);
|
|||
|
if (result)
|
|||
|
{
|
|||
|
if (use.Length == 4)
|
|||
|
{
|
|||
|
var prop = ItemProxy.Instance.GetStaticItem<ItemProp>(use[0]);
|
|||
|
ToastBox.ShowText($"{prop.name} + {use[1]}");
|
|||
|
prop = ItemProxy.Instance.GetStaticItem<ItemProp>(use[2]);
|
|||
|
ToastBox.ShowText($"{prop.name} + {use[3]}");
|
|||
|
}
|
|||
|
else if (use.Length == 2)
|
|||
|
{
|
|||
|
var prop = ItemProxy.Instance.GetStaticItem<ItemProp>(use[0]);
|
|||
|
ToastBox.ShowText($"{prop.name} + {use[1]}");
|
|||
|
}
|
|||
|
Refresh();
|
|||
|
}
|
|||
|
return result;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Unity
|
|||
|
|
|||
|
static BeautyGiftPanel _Instance;
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
_Instance = this;
|
|||
|
SetViewData();
|
|||
|
_btnClose.onClick.AddListener(this.OnCloseBtnClick);
|
|||
|
_propItem1 = __goProp1.AddComponent<MoneyWidget>();
|
|||
|
_propItem2 = __goProp2.AddComponent<MoneyWidget>();
|
|||
|
__listGifts.AddTemplate<GiftWidget>(true);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|