yyl
2 天以前 973edc44a04dceb8b48a32ca912e6167f86189d4
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
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
 
public class ChooseItemsWin : UIBase
{
    [SerializeField] ItemCell itemCell;
    [SerializeField] Text nameText;
    [SerializeField] Text descText;
    [SerializeField] ScrollerController scroller;
    [SerializeField] Button openButton;
    [SerializeField] Text txtChooseNum;
    [SerializeField] CellView _InitCell;
 
    string guid;
    int itemID;
    int itemCount;
    int[][] selectArray;
    protected override void InitComponent()
    {
        openButton.AddListener(() =>
        {
            if (BoxGetItemModel.Instance.TrySendUse())
            { 
                CloseWindow();
            }
        });
    }
 
    protected override void Start()
    {
        _InitCell.cellIdentifier = _InitCell.cellIdentifier + this.GetInstanceID().ToString();
    }
 
 
    protected override void OnPreOpen()
    {
        BoxGetItemModel.Instance.countChangeAction += OnCountChangeAction;
        scroller.OnRefreshCell += OnRefreshCell;
        itemID = ItemTipUtility.mainTipData.baseInfo.itemId;
        itemCount = ItemTipUtility.mainTipData.baseInfo.count;
        guid = ItemTipUtility.mainTipData.guid;
        InitItemsData();
 
        itemCell.Init(new ItemCellModel(itemID, false, itemCount));
        var itemConfig = ItemConfig.Get(itemID);
        nameText.text = itemConfig.ItemName;
        descText.text = itemConfig.Description;
 
        if (string.IsNullOrEmpty(guid))
        {
            //预览
            openButton.SetActive(false);
        }
        else
        {
            BoxGetItemModel.Instance.ClearAll();
            openButton.SetActive(true);
        }
 
        int nowChooseItemCount = BoxGetItemModel.Instance.GetNowChooseItemCount();
        txtChooseNum.text = Language.Get("L1100", Language.Get("L1107"),
        UIHelper.AppendColor(TextColType.DarkGreen, $"{nowChooseItemCount}/{itemCount}"));
        
        CreateScroller();
    }
 
    protected override void OnPreClose()
    {
        scroller.OnRefreshCell -= OnRefreshCell;
    }
 
    void CreateScroller()
    {
        scroller.Refresh();
        for (int i = 0; i < selectArray.Length; i++)
        {
            scroller.AddCell(ScrollerDataType.Header, i);
        }
        scroller.Restart();
    }
 
 
    void OnRefreshCell(ScrollerDataType type, CellView cell)
    {
 
        var _cell = cell as ChooseItemsCell;
        _cell.Display(selectArray[cell.index], guid);
    }
 
 
 
    void InitItemsData()
    {
        selectArray = BoxGetItemModel.Instance.GetSelectItemsByID(itemID);
    }
 
 
 
    private void OnCountChangeAction()
    {
        int nowChooseItemCount = BoxGetItemModel.Instance.GetNowChooseItemCount();
        txtChooseNum.text = Language.Get("L1100", Language.Get("L1107"),
        UIHelper.AppendColor(TextColType.DarkGreen, $"{nowChooseItemCount}/{itemCount}"));
    }
 
 
 
}