207 lines
4.3 KiB
C#
207 lines
4.3 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2021-07-24
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "PropBuyBox.View" company="Kunpo"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
namespace G.UI
|
|||
|
{
|
|||
|
using TMPro;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
partial class PropBuyBox
|
|||
|
{
|
|||
|
#region Field
|
|||
|
|
|||
|
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|||
|
|
|||
|
[KUIFlag]
|
|||
|
Button _btnClose;
|
|||
|
[KUIFlag]
|
|||
|
GameObject __goProp;
|
|||
|
[KUIFlag]
|
|||
|
GameObject __goUnitPrice;
|
|||
|
[KUIFlag]
|
|||
|
GameObject __goTotalPrice;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpName;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpDescription;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpNumber;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnSub1;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnSub10;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnAdd1;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnAdd10;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnAddMax;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnBuy;
|
|||
|
|
|||
|
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|||
|
|
|||
|
private PropWidget _propWidget;
|
|||
|
private CostWidget _unitPriceWidget;
|
|||
|
private CostWidget _totalPriceWidget;
|
|||
|
|
|||
|
private int _buyCount = 1;
|
|||
|
private int _buyMax = 100;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Method
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public void InitView()
|
|||
|
{
|
|||
|
SetViewData();
|
|||
|
|
|||
|
_propWidget = __goProp.AddComponent<PropWidget>();
|
|||
|
_unitPriceWidget = __goUnitPrice.AddComponent<CostWidget>();
|
|||
|
_totalPriceWidget = __goTotalPrice.AddComponent<CostWidget>();
|
|||
|
|
|||
|
_btnBuy.onClick.AddListener(this.OnBuyBtnClick);
|
|||
|
_btnAdd1.onClick.AddListener(this.OnAdd1BtnClick);
|
|||
|
_btnAdd10.onClick.AddListener(this.OnAdd10BtnClick);
|
|||
|
_btnAddMax.onClick.AddListener(this.OnAddMaxBtnClick);
|
|||
|
_btnSub1.onClick.AddListener(this.OnSub1BtnClick);
|
|||
|
_btnSub10.onClick.AddListener(this.OnSub10BtnClick);
|
|||
|
_btnClose.onClick.AddListener(this.OnCloseBtnClick);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public void RefreshView()
|
|||
|
{
|
|||
|
if (this.data is ItemProp propItem)
|
|||
|
{
|
|||
|
_buyMax = TimeProxy.Instance.GetTimes(TimeProxy.宠物重铸丹);
|
|||
|
_buyCount = 1;
|
|||
|
_propWidget.SetItem(propItem);
|
|||
|
_unitPriceWidget.SetPrice(propItem.buyPriceInfo);
|
|||
|
_totalPriceWidget.SetAndCheckPrice(propItem.buyPriceInfo);
|
|||
|
_tmpNumber.text = _buyCount.ToString();
|
|||
|
|
|||
|
_tmpName.text = propItem.name;
|
|||
|
_tmpDescription.text = propItem.text;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void RefreshCount()
|
|||
|
{
|
|||
|
if (this.data is ItemProp propItem)
|
|||
|
{
|
|||
|
_tmpNumber.text = $"{_buyCount}/{_buyMax}";
|
|||
|
var buyPriceInfo = propItem.buyPriceInfo;
|
|||
|
buyPriceInfo.Apply(_buyCount);
|
|||
|
_totalPriceWidget.SetAndCheckPrice(buyPriceInfo);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
bool CheckCount()
|
|||
|
{
|
|||
|
if (_buyCount > _buyMax)
|
|||
|
{
|
|||
|
ToastBox.ShowText("今天已达购买上限");
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
void OnBuyBtnClick()
|
|||
|
{
|
|||
|
if (!CheckCount())
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (this.data is ItemProp propItem)
|
|||
|
{
|
|||
|
var buyPriceInfo = propItem.buyPriceInfo;
|
|||
|
buyPriceInfo.Apply(_buyCount);
|
|||
|
|
|||
|
var success = MoneyProxy.Instance.CheckAndCostMoney(buyPriceInfo);
|
|||
|
if (success)
|
|||
|
{
|
|||
|
//RefreshCount();
|
|||
|
TimeProxy.Instance.SetTimes(TimeProxy.宠物重铸丹, _buyMax - _buyCount);
|
|||
|
ItemProxy.Instance.AddProp(propItem.id, _buyCount);
|
|||
|
|
|||
|
CloseWindow(this);
|
|||
|
|
|||
|
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|||
|
GetWindow<PetWindow>().RefreshUpgradeCost();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
ToastBox.ShowText("货币不足");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void OnAdd1BtnClick()
|
|||
|
{
|
|||
|
if (!CheckCount())
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
_buyCount = Mathf.Min(_buyCount + 1, _buyMax);
|
|||
|
RefreshCount();
|
|||
|
}
|
|||
|
|
|||
|
void OnAdd10BtnClick()
|
|||
|
{
|
|||
|
if (!CheckCount())
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
_buyCount = Mathf.Min(_buyCount + 10, _buyMax);
|
|||
|
RefreshCount();
|
|||
|
}
|
|||
|
|
|||
|
void OnAddMaxBtnClick()
|
|||
|
{
|
|||
|
if (!CheckCount())
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
_buyCount = Mathf.Min(_buyCount + 100, _buyMax);
|
|||
|
RefreshCount();
|
|||
|
}
|
|||
|
|
|||
|
void OnSub1BtnClick()
|
|||
|
{
|
|||
|
_buyCount = Mathf.Max(_buyCount - 1, 0);
|
|||
|
RefreshCount();
|
|||
|
}
|
|||
|
|
|||
|
void OnSub10BtnClick()
|
|||
|
{
|
|||
|
_buyCount = Mathf.Max(_buyCount - 10, 0);
|
|||
|
RefreshCount();
|
|||
|
}
|
|||
|
|
|||
|
void OnCloseBtnClick()
|
|||
|
{
|
|||
|
CloseWindow(this);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|