少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace vnxbqy.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 alchemies = new List<int>(AlchemyConfig.GetAlchemies(alchemyType));
            var index = alchemies.IndexOf(model.selectAlchemy);
            if (index != -1)
            {
                m_Controller.JumpIndex(index);
            }
 
            model.selectAlchemyRefresh += SelectAlchemyRefresh;
            model.alchemyStateRefresh += AlchemyStateRefresh;
        }
 
        void DisplayRecipes()
        {
            m_Controller.Refresh();
            var alchemies = AlchemyConfig.GetAlchemies(alchemyType);
            foreach (var id in alchemies)
            {
                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.selectAlchemyRefresh -= SelectAlchemyRefresh;
            model.alchemyStateRefresh -= AlchemyStateRefresh;
        }
    }
}