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

509 lines
12 KiB
C#

// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2021-04-12
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "BeautySkillPanel" company="Kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.EventSystems;
namespace G.UI
{
/// <summary>
///
/// </summary>
public class BeautyGiftAndSkillPanel : KUIWidget
{
class BeautyTipsWeiget : KUIWidget, IPointerDownHandler, IPointerUpHandler
{
#region Field
Coroutine _goOpen;
float _time;
bool _isGo;
#endregion
#region Method
IEnumerator GoOpen()
{
while (true)
{
_time += Time.deltaTime;
if (_time > 0.5 && _isGo)
{
if (this.data is int id)
{
_Instance.OpenAttributesPanle(id);
}
_isGo = false;
}
yield return null;
}
}
private void OpenShow()
{
if (this.data is int id)
{
_Instance.OpenAttributesPanle(id);
}
}
public void OnPointerDown(PointerEventData eventData)
{
//_time = 0;
//_isGo = true;
//_goOpen = StartCoroutine(GoOpen());
Invoke("OpenShow", 0.5f);
}
public void OnPointerUp(PointerEventData eventData)
{
//StopCoroutine(_goOpen);
//_Instance.CloseAttributesPanle();
}
#endregion
#region Unity
#endregion
}
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;
[KUIFlag]
Button _btnOpenProp;
#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 OnPropBtnClick()
{
if (this.data is EntityItemProp gift)
{
KUIWindow.OpenWindow<GainwayBox>(gift.item);
}
}
private void Awake()
{
SetViewData();
_btnGive.onClick.AddListener(this.OnGiveBtnClick);
_btnOpenProp.onClick.AddListener(this.OnPropBtnClick);
}
}
class SkillWidget : KUIWidget
{
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
[KUIFlag]
Button _btnUpgrade;
[KUIFlag]
TextMeshProUGUI _tmpName;
[KUIFlag]
TextMeshProUGUI _tmpDescription;
[KUIFlag]
TextMeshProUGUI _tmpDescription2;
[KUIFlag]
TextMeshProUGUI _tmpDescription3;
[KUIFlag]
TextMeshProUGUI _tmpNumber;
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
public override void Refresh()
{
if (this.data is ItemBeautySkill skill)
{
if (skill.isMax)
{
_tmpName.text = $"{skill.name} (Lv.max)";
_tmpDescription2.text = skill.currGradeText;
_tmpDescription.text = "";
_tmpDescription3.text = "";
_btnUpgrade.gameObject.SetActive(false);
}
else if (skill.grade > 0)
{
_tmpName.text = $"{skill.name} (Lv.{skill.grade}/{skill.maxGrade})";
_tmpDescription.text = "";// skill.currGradeText;
_tmpDescription2.text = skill.nextGradeText;
_tmpDescription3.text = "升级所需:" + skill.upgradeText;
_btnUpgrade.gameObject.SetActive(true);
}
else
{
_tmpName.text = skill.name;
_tmpDescription.text = "解锁效果:" + skill.currGradeText;
_tmpDescription2.text = "";
_tmpDescription3.text = "解锁条件:" + skill.unlockText;
_btnUpgrade.gameObject.SetActive(false);
}
_tmpNumber.text = (this.index + 1).ToString();
}
}
private void OnUpgradeBtnClick()
{
if (_Instance.UpgradeSkill(this.data as ItemBeautySkill))
{
Refresh();
}
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
private void Awake()
{
SetViewData();
_btnUpgrade.onClick.AddListener(this.OnUpgradeBtnClick);
}
}
#region Field
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
[KUIFlag]
Button _btnClose;
[KUIFlag]
KUIList __listSkills;
[KUIFlag]
GameObject __goProp1;
[KUIFlag]
GameObject __goProp2;
[KUIFlag]
KUIList __listGifts;
[KUIFlag]
TextMeshProUGUI _tmpTitle;
[KUIFlag]
GameObject _goSkill;
[KUIFlag]
GameObject _goGift;
[KUIFlag]
KUIToggleGroup _goToggles;
[KUIFlag]
GameObject _goAttributes;//属性显示
[KUIFlag]
TextMeshProUGUI _tmpDetailName;//属性名字
[KUIFlag]
TextMeshProUGUI _tmpDetailAttributes;//属性值
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
private MoneyWidget _propItem1;
private MoneyWidget _propItem2;
private float _showTime;
#endregion
#region Method
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);
if (_goToggles.toggles[0].isOn)
ShowGift1();
else
ShowSkill();
}
}
public void ShowSkill()
{
_goSkill.SetActive(true);
_goGift.SetActive(false);
if (this.data is BeautyProxy.BeautyInfo beauty)
{
__listSkills.Clear();
for (int i = 0; i < beauty.skills.Length; i++)
{
__listSkills.GetItem().SetData(beauty.skills[i]);
}
}
}
private void OnCloseBtnClick()
{
this.Close();
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
private void OnToggleSelected(int index)
{
if (index == 0)
{
ShowGift1();
}
else if (index == 1)
{
ShowSkill();
}
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
private bool UpgradeSkill(ItemBeautySkill skill)
{
var result = BeautyProxy.Instance.UpgradeBeautySkill(this.data as BeautyProxy.BeautyInfo, skill);
if (result)
{
Refresh();
ToastBox.ShowText("升级成功");
}
else
{
ToastBox.ShowText("红颜经验不足.");
}
return result;
}
public void ShowGift1()
{
_goSkill.SetActive(false);
_goGift.SetActive(true);
_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]);
}
}
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;
}
public void OpenAttributesPanle(int id)
{
_goAttributes.SetActive(true);
if (id ==1)
{
_tmpDetailName.text = KLocalization.GetLocalString(90);
_tmpDetailAttributes.text = KLocalization.GetLocalString(91);
}
else if (id ==2)
{
_tmpDetailName.text = KLocalization.GetLocalString(92);
_tmpDetailAttributes.text = KLocalization.GetLocalString(93);
}
_showTime = 2f;
}
public void CloseAttributesPanle()
{
_goAttributes.SetActive(false);
}
#endregion
#region Unity
private static BeautyGiftAndSkillPanel _Instance;
/// <summary>
///
/// </summary>
private void Awake()
{
_Instance = this;
SetViewData();
_btnClose.onClick.AddListener(this.OnCloseBtnClick);
_goToggles.onToggleSelected.AddListener(this.OnToggleSelected);
_propItem1 = __goProp1.AddComponent<MoneyWidget>();
_propItem2 = __goProp2.AddComponent<MoneyWidget>();
__goProp1.AddComponent<BeautyTipsWeiget>().SetData(1);
__goProp2.AddComponent<BeautyTipsWeiget>().SetData(2);
__listGifts.AddTemplate<GiftWidget>(true);
__listSkills.AddTemplate<SkillWidget>(true);
ShowGift1();
}
private void OnEnable()
{
}
private void LateUpdate()
{
if (_showTime >0f)
{
_showTime -= Time.deltaTime;
if (_showTime <= 0f)
{
_goAttributes.SetActive(false);
}
}
}
#endregion
}
}