using System;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
//使用货币购买坊市表商品
|
public class BuyItemWin : UIBase
|
{
|
[SerializeField] ItemCell itemCell;
|
[SerializeField] Text nameText;
|
[SerializeField] Text countText;
|
[SerializeField] Text descText;
|
[SerializeField] SliderPanel sliderPanel;
|
[SerializeField] Text limitText;
|
[SerializeField] Image moneyIcon;
|
[SerializeField] Text moneyText;
|
[SerializeField] Button buyButton;
|
|
|
int itemCount;
|
int useCnt;
|
int maxCnt;
|
protected override void InitComponent()
|
{
|
buyButton.AddListener(BuyGoods);
|
}
|
|
|
|
protected override void OnPreOpen()
|
{
|
useCnt = 1;
|
Display();
|
}
|
|
void Display()
|
{
|
var shopConfig = StoreConfig.Get(StoreModel.Instance.buyShopID);
|
var itemID = shopConfig.ItemID;
|
var itemCount = shopConfig.ItemCnt;
|
itemCell.Init(new ItemCellModel(itemID, false, itemCount));
|
var itemConfig = ItemConfig.Get(itemID);
|
nameText.text = itemConfig.ItemName;
|
countText.text = Language.Get("storename12", PackManager.Instance.GetItemCountByID(PackType.Item, itemID));
|
descText.text = itemConfig.Description;
|
|
var buyCnt = StoreModel.Instance.GetShopLimitBuyCount(StoreModel.Instance.buyShopID);
|
maxCnt = shopConfig.LimitCnt - buyCnt;
|
if (maxCnt == 0)
|
{
|
//没有限购,用货币可购买数量
|
maxCnt = Math.Max(1, (int)(UIHelper.GetMoneyCnt(shopConfig.MoneyType)/shopConfig.MoneyNum));
|
}
|
|
OnSliderChange(useCnt);
|
sliderPanel.Init((value) => { OnSliderChange(value); }, maxCnt);
|
}
|
|
void OnSliderChange(int value)
|
{
|
var shopConfig = StoreConfig.Get(StoreModel.Instance.buyShopID);
|
useCnt = value;
|
itemCell.countText.text = value.ToString();
|
|
string limitStr = "";
|
if (shopConfig.LimitCnt == 0)
|
{
|
limitStr = "";
|
}
|
else if (shopConfig.ResetType == 0)
|
{
|
//限购
|
limitStr = Language.Get("storename8", useCnt, maxCnt);
|
}
|
else if (shopConfig.ResetType == 1)
|
{
|
//每日限购
|
limitStr = Language.Get("storename6", useCnt, maxCnt);
|
}
|
else if (shopConfig.ResetType == 2)
|
{
|
//每周限购
|
limitStr = Language.Get("storename7", useCnt, maxCnt);
|
}
|
limitText.text = limitStr;
|
|
moneyIcon.SetIconWithMoneyType(shopConfig.MoneyType);
|
moneyText.text = UIHelper.ShowUseMoney(shopConfig.MoneyType, shopConfig.MoneyNum * useCnt);
|
|
}
|
|
void BuyGoods()
|
{
|
CloseWindow();
|
StoreModel.Instance.SendBuyShopItem(StoreConfig.Get(StoreModel.Instance.buyShopID), useCnt);
|
}
|
}
|