少年修仙传客户端代码仓库
client_Wu Xijin
2019-06-13 033958214c0b16d7e7b93cc821b018c295251867
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Monday, March 04, 2019
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI {
 
    public class MyAuctionWin : Window
    {
        [SerializeField] ScrollerController m_ScrollerController;
        AuctionModel model { get { return ModelCenter.Instance.GetModel<AuctionModel>(); } }
        AuctionHelpModel auctionHelpModel { get { return ModelCenter.Instance.GetModel<AuctionHelpModel>(); } }
 
        List<string> myAuctionItems = new List<string>();
 
        #region Built-in
        protected override void BindController()
        {
            m_ScrollerController.OnRefreshCell += OnRefreshGridCell;
            m_ScrollerController.lockType = EnhanceLockType.KeepVertical;
        }
 
        protected override void AddListeners()
        {
        }
 
        protected override void OnPreOpen()
        {
            GetPlayerAuctionItemList();
            ListSotr();
            OnCreateGridLineCell(m_ScrollerController);
        }
 
        protected override void OnAfterOpen()
        {
            model.myFocusAuctionRefresh += ResetUpdate;
            model.onAuctionRemove += ResetUpdate;
            model.auctionItemRefresh += AuctionItemUpdate;//刷新
            model.fairyAuctionRefresh += ResetUpdate;
            model.onFocusAuctionRefresh += ResetUpdate;
            model.myAuctionRefresh += ResetUpdate;
        }
 
        protected override void OnPreClose()
        {
            model.myFocusAuctionRefresh -= ResetUpdate;
            model.onAuctionRemove -= ResetUpdate;
            model.auctionItemRefresh -= AuctionItemUpdate;//刷新
            model.fairyAuctionRefresh -= ResetUpdate;
            model.onFocusAuctionRefresh -= ResetUpdate;
            model.myAuctionRefresh -= ResetUpdate;
        }
 
        protected override void OnAfterClose()
        {
        }
        #endregion
 
        private void ResetUpdate()
        {
            GetPlayerAuctionItemList();
            ListSotr();
            OnCreateGridLineCell(m_ScrollerController);
        }
 
        private void AuctionItemUpdate()
        {
            m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
        }
 
        private void OnCreateGridLineCell(ScrollerController gridCtrl)
        {
            gridCtrl.Refresh();
            for (int i = 0; i < myAuctionItems.Count; i++)
            {
                gridCtrl.AddCell(ScrollerDataType.Header, i);
            }
            gridCtrl.Restart();
        }
 
        private void OnRefreshGridCell(ScrollerDataType type, CellView cell)
        {
            int index = cell.index;
            MyAuctionCell myAuctionCell = cell.GetComponent<MyAuctionCell>();
            myAuctionCell.GetMyAuctionGUID(myAuctionItems[index]);
        }
 
        private void GetPlayerAuctionItemList()
        {
            model.GetMyAuctionItems(ref myAuctionItems);
        }
 
        private void ListSotr()
        {
            myAuctionItems.Sort(Compare);
        }
 
        int Compare(string x, string y)//数组排列
        {
            AuctionItem lhs;
            AuctionItem rhs;
            if (model.TryGetMyAuctionItem(x, out lhs)
                && model.TryGetMyAuctionItem(y, out rhs))
            {
                if (lhs.auctionType != rhs.auctionType)
                {
                    return lhs.auctionType.CompareTo(rhs.auctionType);
                }
                var lhs_hasBidding = lhs.biddingPrice != 0;
                var rhs_hasBidding = rhs.biddingPrice != 0;
                if (lhs_hasBidding != rhs_hasBidding)//是否有收益
                {
                    return -lhs_hasBidding.CompareTo(rhs_hasBidding);
                }
                var lhs_Config = AuctionItemConfig.Get(lhs.itemId);
                var rhs_Config = AuctionItemConfig.Get(rhs.itemId);
                if (lhs_Config.Sortpriority != rhs_Config.Sortpriority)//按照拍卖物品表排序
                {
                    return lhs_Config.Sortpriority.CompareTo(rhs_Config.Sortpriority);
                }
            }
            return 1;
        }
    }
 
}