少年修仙传客户端代码仓库
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
using System;
using UnityEngine;
namespace vnxbqy.UI
{
    public class BlessedLandCell : CellView
    {
        [SerializeField] RectTransform rectCombatScope;
        [SerializeField] RectTransform rectItem;
        [SerializeField] ImageEx imgExclusive;
        [SerializeField] ButtonEx btnItemCell;
        [SerializeField] UIEffect hostUIEffect;
        [SerializeField] UIEffect theftUIEffect;
        [SerializeField] Transform transHostStart;
        [SerializeField] Transform transHostEnd;
        [SerializeField] Transform transTheftStart;
        [SerializeField] Transform transTheftEnd;
        [SerializeField] ImageEx imgMyFlag;
        [SerializeField] ImageEx imgHostCountBG;
        [SerializeField] ImageEx imgHostArrow;
        [SerializeField] FrameEffect skeHostSpriteAnimation;
        [SerializeField] ImageEx imgTheftCountBG;
        [SerializeField] ImageEx imgTheftArrow;
        [SerializeField] FrameEffect skeTheftSpriteAnimation;
        [SerializeField] AvatarCell avatarCell;
        [SerializeField] TextEx txtHostCount;
        [SerializeField] TextEx txtTheftCount;
        [SerializeField] ImageEx imgPublicItemTime;
        [SerializeField] TextEx txtPublicItemTime;
        [SerializeField] TextEx txtSuperTime;
        [SerializeField] ItemCell itemCell;
 
        int index;                                              //当前cell的索引
        int state;                                              //当前cell的state
        float itemCellNowX;                                     //itemCell中心点的Y值
        float combatScopeLength;                                //可移动的总长度
        float combatScopeMin;                                   //可移动范围底部的Y值
        float gridSpacing;                                      //1格的具体距离 
        MineItemInfo mineItems;
        BlessedLandModel blessedLandModel { get { return ModelCenter.Instance.GetModel<BlessedLandModel>(); } }
 
        void Awake()
        {
            float itemCellWidth = rectItem.sizeDelta.x;
            float combatScopeWidth = rectCombatScope.sizeDelta.x;
            float itemCellSpacing = itemCellWidth / 2;
            combatScopeLength = combatScopeWidth - itemCellWidth; //总可移动的距离 = 可移动范围的长度 - ItemCell的长度
            combatScopeMin = itemCellSpacing;
            gridSpacing = (float)Math.Round(combatScopeLength / 100, 4);    //一格的距离
        }
 
        void OnEnable()
        {
            GlobalTimeEvent.Instance.secondEvent += OnSecondEvent;
            WindowCenter.Instance.windowBeforeOpenEvent += OnWindowBeforeOpenEvent;
            WindowCenter.Instance.windowBeforeCloseEvent += OnWindowBeforeCloseEvent;
        }
 
        void OnDisable()
        {
            GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent;
            WindowCenter.Instance.windowBeforeOpenEvent -= OnWindowBeforeOpenEvent;
            WindowCenter.Instance.windowBeforeCloseEvent -= OnWindowBeforeCloseEvent;
        }
 
        private void OnWindowBeforeCloseEvent(Window window)
        {
            if (window.name == "BlessedLandDetailsWin" || window.name == "BlessedLandCornucopiaWin"
                || window.name == "BlessedLandManageWin" || window.name == "BlessedLandOtherWin"
                || window.name == "BlessedLandPKWin" || window.name == "BlessedLandRecordWin"
                || window.name == "BlessedLandSeekWin")
            {
                state = blessedLandModel.GetMyBlessedLandCellState(index);
                bool isHost = state == 2 || state == 4 || state == 6 || state == 7;
                bool isTheft = state == 5 || state == 6 || state == 7;
                hostUIEffect.SetActive(isHost);
                theftUIEffect.SetActive(isTheft);
            }
        }
 
        private void OnWindowBeforeOpenEvent(Window window)
        {
            if (window.name == "BlessedLandDetailsWin" || window.name == "BlessedLandCornucopiaWin"
                || window.name == "BlessedLandManageWin" || window.name == "BlessedLandOtherWin"
                || window.name == "BlessedLandPKWin" || window.name == "BlessedLandRecordWin"
                || window.name == "BlessedLandSeekWin")
            {
                hostUIEffect.SetActive(false);
                theftUIEffect.SetActive(false);
            }
        }
 
        private void OnSecondEvent()
        {
            if (state == 1 || state == 2 || state == 4 || state == 5 || state == 6 || state == 7)
            {
                if (!MineAreaItemConfig.Has(mineItems.MineID))
                    return;
                UpdateItemCellPosition();
                ChangeShow();
            }
        }
 
        public void Display(int index)
        {
            this.index = index;
            this.gameObject.name = "BlessedLandCell_" + index;
            mineItems = blessedLandModel.newAreaDataDict[blessedLandModel.myPlayerId].MineItems[index];
            if (mineItems.MineID == 0 || !MineAreaItemConfig.GetKeys().Contains(mineItems.MineID.ToString()))
            {
                rectItem.SetActive(false);
                txtSuperTime.SetActive(false);
                imgExclusive.SetActive(false);
                imgHostCountBG.SetActive(false);
                imgTheftCountBG.SetActive(false);
                skeHostSpriteAnimation.SetActive(false);
                skeTheftSpriteAnimation.SetActive(false);
                imgMyFlag.SetActive(false);
                avatarCell.bgImage.SetActive(false);
                avatarCell.avatarImage.SetActive(false);
                avatarCell.avatarFrameImage.SetActive(false);
                imgHostArrow.SetActive(false);
                imgTheftArrow.SetActive(false);
                hostUIEffect.SetActive(false);
                theftUIEffect.SetActive(false);
                btnItemCell.SetActive(false);
                imgPublicItemTime.SetActive(false);
                txtPublicItemTime.SetActive(false);
                return;
            }
            state = blessedLandModel.GetMyBlessedLandCellState(index);
            //0 无物品 1 有物品-超级物品-无人拉 2 有物品-超级物品-自己拉
            //3 有物品-普通物品-无人拉 4 有物品-普通物品-自己拉 5 有物品-普通物品-对方拉
            //6 有物品-普通物品-双方拉-向自己移动 7 有物品-普通物品-双方拉-向对方移动
            bool isHost = state == 2 || state == 4 || state == 6 || state == 7;
            bool isTheft = state == 5 || state == 6 || state == 7;
            bool isMoveToHost = state == 2 || state == 4 || state == 6;
            bool isMoveToTheft = state == 5 || state == 7;
            rectItem.SetActive(state != 0);
            imgExclusive.SetActive(state == 1 || state == 2);
            imgHostCountBG.SetActive(isHost);
            imgTheftCountBG.SetActive(isTheft);
            skeHostSpriteAnimation.SetActive(isHost);
            skeTheftSpriteAnimation.SetActive(isTheft);
            imgMyFlag.SetActive(isHost);
            avatarCell.bgImage.SetActive(isTheft);
            avatarCell.avatarImage.SetActive(isTheft);
            avatarCell.avatarFrameImage.SetActive(isTheft);
            imgHostArrow.SetActive(isMoveToHost);
            imgTheftArrow.SetActive(isMoveToTheft);
            hostUIEffect.SetActive(isHost);
            theftUIEffect.SetActive(isTheft);
            btnItemCell.SetActive(true);
 
            imgPublicItemTime.SetActive(state == 1 || state == 2 || state == 4 || isTheft);
            txtPublicItemTime.SetActive(state == 2 || state == 4 || isTheft);
            txtSuperTime.SetActive(state == 1);
 
            var com = hostUIEffect.AddMissingComponent<UIEffectTransmitController>();
            com.start = transHostStart;
            com.end = transHostEnd;
            com.transmit = hostUIEffect;
            com.scale = 22;
            com.enabled = true;
 
            com = theftUIEffect.AddMissingComponent<UIEffectTransmitController>();
            com.start = transTheftStart;
            com.end = transTheftEnd;
            com.transmit = theftUIEffect;
            com.scale = 22;
            com.enabled = true;
 
            var canvas = rectItem.AddMissingComponent<Canvas>();
            canvas.overrideSorting = true;
            canvas.sortingLayerName = "UI";
            canvas.sortingOrder = 3001;
            ChangeShow();
        }
 
        void ChangeShow()
        {
 
            txtHostCount.text = mineItems.WorkerCount.ToString();
            txtTheftCount.text = mineItems.RobWorkerCount.ToString();
            avatarCell.InitUI(mineItems.RobPlayerID < 10000 ? blessedLandModel.GetModelForPlayerId((int)mineItems.RobPlayerID) : AvatarHelper.GetAvatarModel((int)mineItems.RobPlayerID, (int)mineItems.RobFace, (int)mineItems.RobFacePic, mineItems.RobJob));
            txtSuperTime.text = TimeUtility.SecondsToDHMS((int)mineItems.UpdTime + blessedLandModel.superRefreshDefaultSpecialItemOutputDurationSeconds - TimeUtility.AllSeconds);
            txtPublicItemTime.text = TimeUtility.SecondsToDHMS((int)mineItems.EndTime - TimeUtility.AllSeconds);
            UpdateItemCellPosition();
            int itemID = MineAreaItemConfig.Get(mineItems.MineID).ItemID;
            int itemLV = MineAreaItemConfig.Get(mineItems.MineID).ItemLV;
            itemCell.Init(new ItemCellModel(itemID, false, (ulong)itemLV));
            itemCell.countText.SetActive(true);
            itemCell.countText.text = Language.Get("FashionDress106", itemLV);
            btnItemCell.SetListener(() =>
            {
                ModelCenter.Instance.GetModel<BlessedLandModel>().detailsIndex = (byte)index;
                blessedLandModel.SendCB030Pack(0, blessedLandModel.detailsIndex, (byte)Mathf.Max(mineItems.WorkerCount, 1), 1);
                WindowCenter.Instance.Open<BlessedLandDetailsWin>();
            });
        }
 
        void UpdateItemCellPosition()
        {
            float consumeTime = Mathf.Max(TimeUtility.AllSeconds - mineItems.UpdTime, 0);
            float moveSpeed = float.Parse(mineItems.MoveSpeed);
            float positionAdjustment = consumeTime * moveSpeed * gridSpacing;
            positionAdjustment = state == 2 || state == 4 || state == 6 ? -positionAdjustment : positionAdjustment;
            itemCellNowX = combatScopeMin + float.Parse(mineItems.Position) * gridSpacing + positionAdjustment;
            if (itemCellNowX > combatScopeLength)
            {
                itemCellNowX = combatScopeLength;
            }
            if (itemCellNowX < combatScopeMin)
            {
                itemCellNowX = combatScopeMin;
            }
            rectItem.anchoredPosition = new Vector2(itemCellNowX, rectItem.anchoredPosition.y);
            btnItemCell.GetComponent<RectTransform>().anchoredPosition = new Vector2(itemCellNowX, rectItem.anchoredPosition.y);
        }
 
 
    }
}