yyl
2025-08-11 b2d7bb59dc37c7b350786b076ee2f344b7c8911f
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
//--------------------------------------------------------
//    [Author]:           玩个游戏
//    [  Date ]:           Tuesday, July 24, 2018
//--------------------------------------------------------
 
 
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
 
//通用玩家个人排行榜
public class PlayerRankWin : UIBase
{
    [SerializeField] List<PlayerTop3Cell> playerTop3Cells;
    [SerializeField] ScrollerController scrollerController;
    [SerializeField] Text cmpStrText;   //排行榜排名内容,如战力,通过层数等
    [SerializeField] PlayerRankCell myRankCell;
    [SerializeField] Button btnClose;
 
 
    [HideInInspector] public int rankType;
    [HideInInspector] public string valueFormat = "{0}";
    [HideInInspector] public int groupValue1 = 0;   //一般用于跨服
    [HideInInspector] public int groupValue2 = 0;   //一般用于跨服
 
    protected override void InitComponent()
    {
        btnClose.AddListener(()=>
        {
            CloseWindow();
        });
    }
 
    protected override void NextFrameAfterOpen()
    {
        RankModel.Instance.onRankRefresh += OnRankRefresh;
        scrollerController.OnRefreshCell += OnRefreshCell;
        Refresh();
        
    }
 
    protected override void OnPreClose()
    {
        RankModel.Instance.onRankRefresh -= OnRankRefresh;
        scrollerController.OnRefreshCell -= OnRefreshCell;
    }
 
    protected override void OnClose()
    {
        base.OnClose();
    }
 
    public override void Refresh()
    {
        cmpStrText.text = Language.Get("RankTypeName_" + rankType);
        ShowTop3();
        CreateScroller();
        ShowMyRank();
    }
 
    void CreateScroller()
    {
        scrollerController.Refresh();
        var cnt = RankModel.Instance.GetRankShowMaxCnt(rankType);
        for (int i = 3; i < cnt; i++)
        {
            scrollerController.AddCell(ScrollerDataType.Header, i);
        }
        scrollerController.Restart();
    }
 
    void OnRefreshCell(ScrollerDataType type, CellView cell)
    {
        var _cell = cell.GetComponent<PlayerRankCell>();
        _cell.Display(rankType, cell.index + 1, valueFormat);
        RankModel.Instance.ListenRankPage(rankType, cell.index, groupValue1, groupValue2);
    }
 
 
    void ShowTop3()
    { 
        for (int i = 0; i < playerTop3Cells.Count; i++)
        {
            playerTop3Cells[i].Display(functionOrder, i + 1);
        }
    }
 
    void ShowMyRank()
    {
        myRankCell.Display(rankType, 0, valueFormat);
    }
 
 
    void OnRankRefresh(int type)
    {
        ShowTop3();
        scrollerController.m_Scorller.RefreshActiveCellViews();
        ShowMyRank();
    }
 
    void OnMyRankRefresh(int type)
    { 
        ShowMyRank();
    }
 
}