少年修仙传客户端代码仓库
client_Wu Xijin
2019-04-28 8d06932ebf186837e048da4822bd837dbf90e212
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Snxxz.UI
{
    public class AlchemyScrollBehaviour : MonoBehaviour
    {
        [SerializeField] ScrollerController m_Controller;
 
        int alchemyType = 0;
 
        AlchemyModel model { get { return ModelCenter.Instance.GetModel<AlchemyModel>(); } }
 
        private void Awake()
        {
            m_Controller.OnRefreshCell += OnRefreshCell;
            m_Controller.lockType = EnhanceLockType.KeepVertical;
        }
 
        public void Display(int type)
        {
            alchemyType = type;
 
            DisplayRecipes();
 
            var qualities = new List<int>(AlchemyConfig.GetAlchemyQualities(alchemyType));
            var index = qualities.IndexOf(model.selectQuality);
            if (index != -1)
            {
                m_Controller.JumpIndex(index);
            }
 
            model.selectQualityRefresh += SelectQualityRefresh;
            model.selectAlchemyRefresh += SelectAlchemyRefresh;
            model.alchemyStateRefresh += AlchemyStateRefresh;
        }
 
        void DisplayRecipes()
        {
            m_Controller.Refresh();
            var qualities = AlchemyConfig.GetAlchemyQualities(alchemyType);
            foreach (var quality in qualities)
            {
                m_Controller.AddCell(ScrollerDataType.Header, quality);
                if (model.selectQuality == quality)
                {
                    var recipes = AlchemyConfig.GetAlchemies(alchemyType, quality);
                    foreach (var id in recipes)
                    {
                        m_Controller.AddCell(ScrollerDataType.Normal, id);
                    }
                }
            }
            m_Controller.Restart();
        }
 
        private void OnRefreshCell(ScrollerDataType type, CellView cell)
        {
            if (type == ScrollerDataType.Header)
            {
                var qualityCell = cell as AlchemyQualityCell;
                qualityCell.Display(cell.index);
            }
            else if (type == ScrollerDataType.Normal)
            {
                var recipeCell = cell as AlchemyRecipeCell;
                recipeCell.Display(cell.index);
            }
        }
 
        private void SelectQualityRefresh()
        {
            DisplayRecipes();
        }
 
        private void SelectAlchemyRefresh()
        {
            m_Controller.m_Scorller.RefreshActiveCellViews();
        }
 
        private void AlchemyStateRefresh()
        {
            m_Controller.m_Scorller.RefreshActiveCellViews();
        }
 
        public void Dispose()
        {
            model.selectQualityRefresh -= SelectQualityRefresh;
            model.selectAlchemyRefresh -= SelectAlchemyRefresh;
            model.alchemyStateRefresh -= AlchemyStateRefresh;
        }
    }
}