少年修仙传客户端代码仓库
lcy
2025-05-14 be01b026ec888646537d2c7403e0c2ebdddd022d
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
using System;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
 
namespace vnxbqy.UI
{
    public class FairySiegeBasePrepWin : Window
    {
        [SerializeField] FairySiegeStarGroup baseStarGroup;
        [SerializeField] ButtonEx btnHighDonation;
        [SerializeField] ButtonEx btnLowDonation;
        [SerializeField] ScrollerController scrHighReward;
        [SerializeField] ScrollerController scrLowReward;
        [SerializeField] Slider slidBase;
        [SerializeField] Text txtSlidExp;
        [SerializeField] ImageEx imgBase;
        [SerializeField] TextEx txtLV;
        [SerializeField] TextEx txtResNext;
        [SerializeField] TextEx txtResNow;
        [SerializeField] TextEx txtTip;
        [SerializeField] ButtonEx btnLvInfo;
 
        [SerializeField] Transform transHigh;
        [SerializeField] ImageEx imgHighDonateItem;
        [SerializeField] TextEx txtHighDonateMoneyCnt;
        [SerializeField] TextEx txtHighDonationName;
        [SerializeField] TextEx txtHighRemainDonateCnt;
 
        [SerializeField] Transform transLow;
        [SerializeField] TextEx txtLowDonateMoneyCnt;
        [SerializeField] TextEx txtLowDonationCnt;
        [SerializeField] TextEx txtLowDonationName;
        [SerializeField] ImageEx imgNoLowDonationCnt;
        [SerializeField] ImageEx imgLowDonateMoneyType;
 
        [SerializeField] RedpointBehaviour rpLowDonation;
        [SerializeField] RedpointBehaviour rpHighDonation;
 
        FairySiegeActModel model { get { return ModelCenter.Instance.GetModel<FairySiegeActModel>(); } }
        PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
 
        #region Build-in
 
        protected override void AddListeners()
        {
            btnLowDonation.SetListener(LowDonationClick);
            btnHighDonation.SetListener(HighDonationClick);
            btnLvInfo.SetListener(() => WindowCenter.Instance.Open<FairySiegeBaseLvInfoWin>());
        }
 
        protected override void BindController()
        {
        }
 
        protected override void OnPreOpen()
        {
            rpLowDonation.redpointId = model.GetRedpointId(FairySiegeRedPointType.BaseLowContribution);
            rpHighDonation.redpointId = model.GetRedpointId(FairySiegeRedPointType.BaseHighContribution);
            scrLowReward.OnRefreshCell += OnRefreshLowRewardCell;
            scrHighReward.OnRefreshCell += OnRefreshHighRewardCell;
            PlayerDatas.Instance.playerDataRefreshEvent += OnPlayerDataRefreshEvent;
            packModel.refreshItemCountEvent += OnRefreshItemCountEvent;
            model.UpdateCampInfoEvent += OnUpdateCampInfoEvent;
            model.UpdateFamilyGCZPlayerInfoEvent += OnUpdateFamilyGCZPlayerInfoEvent;
            GlobalTimeEvent.Instance.secondEvent += OnSecondEvent;
            ShowPrep();
        }
 
        protected override void OnPreClose()
        {
            scrLowReward.OnRefreshCell -= OnRefreshLowRewardCell;
            scrHighReward.OnRefreshCell -= OnRefreshHighRewardCell;
            PlayerDatas.Instance.playerDataRefreshEvent -= OnPlayerDataRefreshEvent;
            packModel.refreshItemCountEvent -= OnRefreshItemCountEvent;
            model.UpdateCampInfoEvent -= OnUpdateCampInfoEvent;
            model.UpdateFamilyGCZPlayerInfoEvent -= OnUpdateFamilyGCZPlayerInfoEvent;
            GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent;
        }
 
        private void OnSecondEvent()
        {
            txtTip.SetActive(model.matchRound == model.matchRoundMax && model.TryGetCurrentStateValue(out int stateValue) && model.GetStateByStateValue(stateValue) >= 2);
        }
 
        private void OnUpdateFamilyGCZPlayerInfoEvent()
        {
            ShowPrep();
        }
 
        private void OnUpdateCampInfoEvent()
        {
            ShowPrep();
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnAfterClose()
        {
        }
 
        #endregion
 
        private void OnPlayerDataRefreshEvent(PlayerDataType type)
        {
            if (type != PlayerDataType.GoldPaper)
                return;
            ShowPrep();
        }
 
        private void OnRefreshItemCountEvent(PackType type, int arg2, int arg3)
        {
            if (type != PackType.Item && arg3 != model.highDonateItemId)
                return;
            ShowPrep();
        }
 
        private void OnRefreshLowRewardCell(ScrollerDataType type, CellView cell)
        {
            var _cell = cell.GetComponent<FairySiegeBasePrepLowAwardCell>();
            _cell?.Display(cell.index);
        }
 
        private void OnRefreshHighRewardCell(ScrollerDataType type, CellView cell)
        {
            var _cell = cell.GetComponent<FairySiegeBasePrepHighAwardCell>();
            _cell?.Display(cell.index);
        }
 
        private void CreateLowRewardScroller()
        {
            scrLowReward.Refresh();
            var list = model.GetAllUniqueItemIDs(model.lowDonateRewardDict);
            if (!list.IsNullOrEmpty())
            {
                for (var i = 0; i < list.Count; i++)
                {
                    scrLowReward.AddCell(ScrollerDataType.Header, i);
                }
            }
            scrLowReward.Restart();
        }
 
        private void CreateHighRewardScroller()
        {
            scrHighReward.Refresh();
            var list = model.GetAllUniqueItemIDs(model.highDonateRewardDict);
            if (!list.IsNullOrEmpty())
            {
                for (var i = 0; i < list.Count; i++)
                {
                    scrHighReward.AddCell(ScrollerDataType.Header, i);
                }
            }
            scrHighReward.Restart();
        }
 
        private void DisplayBaseInfo()
        {
            if (!FamilyGCZCampLVConfig.Has(model.myCampLV))
            {
                DebugEx.LogError($"X.仙盟攻城战大本营等级表 中没有找到当前大本营等级:{model.myCampLV}");
                return;
            }
            FamilyGCZCampLVConfig config = FamilyGCZCampLVConfig.Get(model.myCampLV);
 
            txtLV.text = Language.Get("FashionDress106", model.myCampLV);
            float fillAmount = Mathf.Round((float)model.myCampExp / config.LVUPNeedExp * 1000f) / 1000f;
            string info = Language.Get("FairySiege125", model.myCampExp, config.LVUPNeedExp);
            slidBase.value = fillAmount;
            txtSlidExp.text = info;
            baseStarGroup.Display(config.StarCount);
 
            txtResNow.text = Language.Get("FairySiege056", UIHelper.AppendColor(TextColType.DarkGreen, Language.Get("FairySiege140", config.AddHPPer)));
            bool hasNext = model.TryGetNextHPPer(model.myCampLV, out int nextAddHPPer);
            txtResNext.text = Language.Get("FairySiege057", hasNext ? UIHelper.AppendColor(TextColType.DarkGreen, Language.Get("FairySiege140", nextAddHPPer)) : Language.Get("HallTipsWin__5"));
        }
 
        public int GetNowExp()
        {
            if (!FamilyGCZCampLVConfig.Has(model.myCampLV))
                return 0;
 
            var list = FamilyGCZCampLVConfig.GetKeys().Select(s => int.Parse(s)).ToList();
            list.Sort();
            int index = list.IndexOf(model.myCampLV);
            if (index == -1)
                return 0;
            int res = (int)model.myCampExp;
            for (int i = 0; i < index; i++)
            {
                res -= FamilyGCZCampLVConfig.Get(list[i]).LVUPNeedExp;
            }
 
            return res;
        }
 
        public void ShowPrep()
        {
            transLow.SetActive(model.lowDonateMoneyType > 0);
            DisplayBaseInfo();
            bool hasLowDonationCnt = model.TryGetNeedMoney(out int needMoney);
            imgNoLowDonationCnt.SetActive(!hasLowDonationCnt);
            btnLowDonation.SetActive(hasLowDonationCnt);
            imgLowDonateMoneyType.SetActive(hasLowDonationCnt);
            txtLowDonateMoneyCnt.SetActive(hasLowDonationCnt);
 
            imgLowDonateMoneyType.SetIconWithMoneyType(model.lowDonateMoneyType);
            txtLowDonationName.text = Language.Get("FairySiege052", UIHelper.AppendColor(TextColType.DarkGreen, Language.Get("FairySiege054", model.lowDonateOnceExpAdd)));
            int remainLowDonationCnt = model.lowDonateMaxCnt - model.contributionCnt;
            txtLowDonationCnt.text = Language.Get("FairySiege053", UIHelper.AppendColor(remainLowDonationCnt > 0 ? TextColType.DarkGreen : TextColType.Red, remainLowDonationCnt.ToString()));
            var hasMoney = UIHelper.GetMoneyCnt(model.lowDonateMoneyType);
            txtLowDonateMoneyCnt.text = UIHelper.AppendColor(hasMoney >= (ulong)needMoney ? TextColType.DarkGreen : TextColType.Red, StringUtility.Contact(UIHelper.ReplaceLargeNum(hasMoney), "/", needMoney));
            CreateLowRewardScroller();
 
            txtHighDonationName.text = Language.Get("FairySiege089", UIHelper.AppendColor(TextColType.DarkGreen, Language.Get("FairySiege054", model.highDonateOnceExpAdd)));
            txtHighRemainDonateCnt.text = Language.Get("FairySiege053", UIHelper.AppendColor(TextColType.DarkGreen, Language.Get("FairySiege119")));
            imgHighDonateItem.SetSprite(ItemConfig.Get(model.highDonateItemId).IconKey);
            var hasItemCnt = packModel.GetItemCountByID(PackType.Item, model.highDonateItemId);
            txtHighDonateMoneyCnt.text = UIHelper.AppendColor(hasItemCnt > 0 ? TextColType.DarkGreen : TextColType.Red, StringUtility.Contact(UIHelper.ReplaceLargeNum(hasItemCnt), "/", 1));
            CreateHighRewardScroller();
            OnSecondEvent();
        }
 
        private void LowDonationClick()
        {
            if (model.myCityHP <= 0)
            {
                SysNotifyMgr.Instance.ShowTip("FairySiege05");
                return;
            }
 
            //货币数量不足
            var hasMoney = UIHelper.GetMoneyCnt(model.lowDonateMoneyType);
            if (model.TryGetNeedMoney(out int needMoney))
            {
                if (hasMoney < (ulong)needMoney)
                {
                    SysNotifyMgr.Instance.ShowTip("FairySiege03");
                    return;
                }
            }
 
            model.nowContiributionType = 0;
            model.SendContribution(0, (uint)needMoney);
        }
 
        private void HighDonationClick()
        {
            //我方大本营已被摧毁
            var familyId = (int)PlayerDatas.Instance.baseData.FamilyId;
            if (model.myCityHP <= 0)
            {
                SysNotifyMgr.Instance.ShowTip("FairySiege05");
                return;
            }
            WindowCenter.Instance.Open<FairySiegeBaseDonateUseItemWin>();
        }
    }
}