少年修仙传客户端代码仓库
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
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
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
 
namespace vnxbqy.UI
{
    public class CrossServerOneVsOneHonorStoreWin : Window
    {
        [SerializeField] ScrollerController shopCtrl;
 
        StoreModel model { get { return ModelCenter.Instance.GetModel<StoreModel>(); } }
 
        List<StoreModel.StoreData> shoplist;
        int SingleLineCnt = 2;
        int selectedGoodId = 0;
 
        protected override void BindController()
        {
            shopCtrl.OnRefreshCell += RefreshShopCell;
            shopCtrl.lockType = EnhanceLockType.KeepVertical;
        }
 
        protected override void AddListeners()
        {
 
        }
 
        protected override void OnPreOpen()
        {
            model.RefreshBuyShopLimitEvent += CreateShopCell;
            model.storeFuncType = StoreFunc.CrossOneVsOneHonor;
            CreateShopCell();
        }
 
        protected override void OnAfterOpen()
        {
            CheckJumpToModel();
        }
 
        protected override void OnPreClose()
        {
            selectedGoodId = 0;
            model.RefreshBuyShopLimitEvent -= CreateShopCell;
        }
        protected override void OnAfterClose()
        {
 
        }
 
        private void CheckJumpToModel()
        {
            if (model.jumpToItemId != 0)
            {
                var p_shopItemlist = model.TryGetStoreDatas(model.storeFuncType);
                for (int i = 0; i < p_shopItemlist.Count; i++)
                {
                    var storeData = p_shopItemlist[i];
                    if (storeData.storeConfig.ItemID == model.jumpToItemId)
                    {
                        selectedGoodId = storeData.shopId;
                        int index = i / 2;
                        shopCtrl.JumpIndex(index);
                        shopCtrl.m_Scorller.RefreshActiveCellViews();
                        break;
                    }
                }
 
                model.ClearJump();
            }
        }
 
        private void CreateShopCell()
        {
            shoplist = model.TryGetStoreDatas(model.storeFuncType);
            if (shoplist == null)
            {
                DebugEx.Log("跨服商店数据为空");
                return;
            }
 
            shopCtrl.Refresh();
            if (shoplist.Count > 0)
            {
                int i = 0;
                int remain = shoplist.Count % SingleLineCnt;
                int line = (int)shoplist.Count / SingleLineCnt;
                if (remain > 0)
                {
                    line += 1;
                }
 
                for (i = 0; i < line; i++)
                {
                    shopCtrl.AddCell(ScrollerDataType.Header, i);
                }
            }
            shopCtrl.Restart();
 
            shopCtrl.JumpIndex(0);
        }
 
        private void RefreshShopCell(ScrollerDataType type, CellView cell)
        {
            int length = cell.transform.childCount;
            for (int i = 0; i < length; i++)
            {
                int cellCount = length * cell.index + (i + 1);
                var shopCell = cell.transform.GetChild(i).GetComponent<CrossServerOneVsOneHonorShopCell>();
                if (shoplist.Count >= cellCount)
                {
                    shopCell.SetActive(true);
                    shopCell.SetDisplay(shoplist[cellCount - 1].storeConfig ,selectedGoodId);
                }
                else
                {
                    shopCell.SetActive(false);
                }
            }
        }
 
    }
}