少年修仙传客户端代码仓库
client_Wu Xijin
2019-02-19 c79cc04f70abae072dfb724b15382902999afd20
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
129
130
131
132
133
134
135
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Friday, September 08, 2017
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
 
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Snxxz.UI
{
 
    public class RunePackWin : Window
    {
        [SerializeField] ScrollerController packController;
        [SerializeField] Text runePackCap;
        [SerializeField] Button runePackClostBtn;
        [SerializeField] Button m_RuneGetBtn;
        [SerializeField] Button m_RuneComposeBtn;
 
        RuneModel m_Model;
        RuneModel model
        {
            get
            {
                return m_Model ?? (m_Model = ModelCenter.Instance.GetModel<RuneModel>());
            }
        }
        #region Built-in
        protected override void BindController()
        {
        }
 
        protected override void AddListeners()
        {
            runePackClostBtn.onClick.AddListener(OnRunePackClose);
            m_RuneGetBtn.onClick.AddListener(OnRuneGetBtn);
            m_RuneComposeBtn.onClick.AddListener(OnRuneComposeBtn);
        }
 
        private void OnRunePackClose()
        {
            CloseClick();
        }
 
        protected override void OnPreOpen()
        {
            model.OnRefreshRunePack += OnRunePackRefresh;
            OnRunePackRefresh();
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
        }
 
        protected override void OnAfterClose()
        {
            model.OnRefreshRunePack -= OnRunePackRefresh;
        }
        #endregion
        /// <summary>
        /// 对符文背包里进行排序
        /// 1.按品质降序
        /// 2.按等级降序
        /// 3.按id降序
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        private int Compare(RuneData x, RuneData y)
        {
            ItemConfig xItemCfg = ItemConfig.Get(x.id);
            ItemConfig yItemCfg = ItemConfig.Get(y.id);
            bool xSame = model.IsSameInHoleRune(xItemCfg.ID, model.sltRuneHole);
            bool ySame = model.IsSameInHoleRune(yItemCfg.ID, model.sltRuneHole);
            if (xSame.CompareTo(ySame) != 0) return xSame.CompareTo(ySame);
            if (xItemCfg.ItemColor.CompareTo(yItemCfg.ItemColor) != 0) return -xItemCfg.ItemColor.CompareTo(yItemCfg.ItemColor);
            else if (x.lv.CompareTo(y.lv) != 0) return -x.lv.CompareTo(y.lv);
            else if (x.id.CompareTo(y.id) != 0) return -x.id.CompareTo(y.id);
            else return 1;
        }
        void OnRunePackRefresh()
        {
            packController.Refresh();
            if (model.runePackList != null)
            {
                model.runePackList.Clear();
            }
            else
            {
                model.runePackList = new List<RuneData>();
            }
            List<RuneData> list = model.GetPackRune().Values.ToList();
            for (int i = 0; i < list.Count; i++)
            {
                RuneData data = list[i];
                ItemConfig cfg = ItemConfig.Get(data.id);
                if (cfg.Type == 30)
                {
                    model.runePackList.Add(data);
                }
            }
            model.runePackList.Sort(Compare);
            int itemCnt = Mathf.CeilToInt((float)model.runePackList.Count / 3);
            for (int i = 0; i < itemCnt; i++)
            {
                packController.AddCell(ScrollerDataType.Normal, i);
            }
            packController.Restart();
            runePackCap.text = StringUtility.Contact(model.GetPackRune().Count, "/",
                FuncConfigConfig.Get("RunePackageNum").Numerical1);
        }
 
        private void OnRuneComposeBtn()
        {
            CloseImmediately();
            model.JumpToRuneCompose();
        }
 
        private void OnRuneGetBtn()
        {
            CloseImmediately();
            WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.RuneTower);
        }
    }
 
}