少年修仙传客户端代码仓库
hch
2025-06-12 204ef05a831c9484e2abc561d27ecbff7c797453
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
using vnxbqy.UI;
using UnityEngine;
using System.Linq;
using System.Collections.Generic;
 
 
public class TreasurePavilionUpgradeChooseWin : Window
{
    [SerializeField] ScrollerController scroller;
    [SerializeField] TreasureCustomizedItemCell itemCell;
    [SerializeField] TextEx txtCount;
    [SerializeField] ButtonEx btnAutoAdd;
    [SerializeField] ButtonEx btnOk;
    Dictionary<int, int> dict;
    TreasurePavilionUpgradeChooseModel model { get { return ModelCenter.Instance.GetModelEx<TreasurePavilionUpgradeChooseModel>(); } }
    protected override void BindController()
    {
 
    }
 
    protected override void AddListeners()
    {
        btnOk.SetListener(CloseClick);
 
        btnAutoAdd.SetListener(() =>
        {
            model.AutoChoose();
            model.UpdateInfoAction?.Invoke();
        });
    }
 
    protected override void OnPreOpen()
    {
        model.UpdateInfoAction += OnUpdateInfoAction;
        scroller.OnRefreshCell += OnRefreshCell;
        Display();
    }
 
    protected override void OnPreClose()
    {
        model.UpdateInfoAction -= OnUpdateInfoAction;
        scroller.OnRefreshCell -= OnRefreshCell;
        model.UpdateInfoAction?.Invoke();
    }
 
    protected override void OnAfterOpen()
    {
        CreateScroller();
    }
 
    protected override void OnAfterClose()
    {
 
    }
 
    void Display()
    {
        int totalCount = ILGubaoStarConfig.GetNeedGubaPieceCountByQuality(model.nowGubaoId, model.nowStar, model.nowQuality);
        int allUseCount = model.GetAllGuBaoPieceCountByQuality(GubaoPieceInfoType.Choose, model.nowGubaoId, model.nowStar, model.nowQuality);
        txtCount.text = StringUtility.Contact(allUseCount, "/", totalCount);
        txtCount.color = UIHelper.GetUIColor(allUseCount >= totalCount ? TextColType.Green : TextColType.Red);
        itemCell.Init(null);
        itemCell.itemIcon.SetActive(true);
        itemCell.bgIcon.SetItemBackGround(model.nowQuality, 0);
        itemCell.itemIcon.SetSprite("TreasureClooseQualityType_" + model.nowQuality);
    }
 
    void CreateScroller()
    {
        scroller.Refresh();
        model.UpdateGubaoPieceInfo();
        if (!model.TryGetPieceDictInfo(GubaoPieceInfoType.Have, model.nowGubaoId, model.nowStar, model.nowQuality, out dict))
        {
            dict = new Dictionary<int, int>();
        }
        var list = dict.Keys.ToList();
        list.Sort(ShowCmp);
        for (int i = 0; i < list.Count; i++)
        {
            scroller.AddCell(ScrollerDataType.Header, list[i]);
        }
        scroller.Restart();
    }
 
    private void OnUpdateInfoAction()
    {
        Display();
        scroller.m_Scorller.RefreshActiveCellViews();
    }
 
    void OnRefreshCell(ScrollerDataType type, CellView cell)
    {
        var _cell = cell as TreasurePavilionUpgradeChooseCell;
        _cell.Display(_cell.index);
    }
 
    //展示排序规则 数量多 > 数量少
    public int ShowCmp(int a, int b)
    {
        int count1 = dict[a];
        int count2 = dict[b];
        if (count1 > count2)
        {
            return -1;  
        }
        else if (count1 < count2)
        {
            return 1;  
        }
        else
        {
            return 0;
        }
    }
}