1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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;
 
    [SerializeField] Text titleText;
    [SerializeField] Text buyBtnText;
 
 
    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*useCnt));
        var itemConfig = ItemConfig.Get(itemID);
        nameText.text = itemConfig.ItemName;
        countText.text = Language.Get("storename12", GetItemCount(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);
 
        if (shopConfig.ShopType == (int)StoreFunc.OSGalaChange)
        {
            titleText.text = Language.Get("OSActivity13");
            buyBtnText.text = Language.Get("OSActivity9");
        }
        else
        {
            titleText.text = Language.Get("storename3");
            buyBtnText.text = Language.Get("storename4");
        }
    }
 
    void OnSliderChange(int value)
    {
        var shopConfig = StoreConfig.Get(StoreModel.Instance.buyShopID);
        useCnt = value;
        itemCell.countText.text = UIHelper.ReplaceLargeNum(value*shopConfig.ItemCnt);
 
        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, false);
 
    }
 
    void BuyGoods()
    {
        CloseWindow();
        StoreModel.Instance.SendBuyShopItem(StoreConfig.Get(StoreModel.Instance.buyShopID), useCnt);
    }
 
    //如果物品是自动转换货币类型的,则返回货币数量,否则返回物品数量
    long GetItemCount(int id)
    {
        var config = ItemConfig.Get(id);
        if (config.Effect1 == 264)
        {
            return UIHelper.GetMoneyCnt(config.EffectValueB1);
        }
 
        var count = PackManager.Instance.GetItemCountByID(GeneralDefine.GetPackTypeByItemType(config.Type), id);
        if (config.Type == 150)
        {
            count = Math.Max(0, count - 1);
        }
        
        return count;
    }
}