少年修仙传客户端代码仓库
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
using System;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
 
namespace vnxbqy.UI
{
   
    public class NewYearToHiAwardCell : CellView
    {
        [SerializeField] Text titleText;
        [SerializeField] Button receiveBtn;
        [SerializeField] GameObject noReachImg;
        [SerializeField] GameObject alreadyImg;
        [SerializeField] List<CommonItemBaisc> itemBaiscs = new List<CommonItemBaisc>();
 
        List<NewYearFairylandCeremonyModel.AwardItem> itemlist;
        
        NewYearFairylandCeremonyModel.ReceiveState receiveState = NewYearFairylandCeremonyModel.ReceiveState.NoReach;
        PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
        NewYearFairylandCeremonyModel ceremonyModel { get { return ModelCenter.Instance.GetModel<NewYearFairylandCeremonyModel>(); } }
        NewAllPeoplePartyAwardConfig awardConfig;
 
        private void OnEnable()
        {
            ceremonyModel.RefreshHiAwardStateAct += SetAwardState;
        }
 
        private void OnDisable()
        {
            ceremonyModel.RefreshHiAwardStateAct -= SetAwardState;
        }
        public void Init(NewAllPeoplePartyAwardConfig awardConfig)
        {
            this.awardConfig = awardConfig;
            titleText.text = Language.Get("CeremoneyToHiAward", awardConfig.NeedPoint);
            itemlist = ceremonyModel.GetPeoplePartyAwardById(awardConfig.ID);
            for (int i = 0; i < itemBaiscs.Count; i++)
            {
                if (i < itemlist.Count)
                {
                    itemBaiscs[i].SetActive(true);
                    NewYearFairylandCeremonyModel.AwardItem itemData = itemlist[i];
                    ItemCellModel cellModel = new ItemCellModel(itemData.itemId, true,(ulong)itemData.itemCount);
                    itemBaiscs[i].Init(cellModel);
                    itemBaiscs[i].button.RemoveAllListeners();
                    itemBaiscs[i].button.AddListener(() =>
                    {
                        ItemTipUtility.Show(itemData.itemId);
                    });
                }
                else
                {
                    itemBaiscs[i].SetActive(false);
                }
            }
 
            SetAwardState();
        }
 
        private void SetAwardState()
        {
            if (awardConfig == null) return;
 
           if(ceremonyModel.GetPeopleAwardRecordByIndex(awardConfig.Index))
            {
                receiveState = NewYearFairylandCeremonyModel.ReceiveState.Already;
            }
           else
            {
                if(ceremonyModel.sumHiPoint >= awardConfig.NeedPoint)
                {
                    receiveState = NewYearFairylandCeremonyModel.ReceiveState.Reach;
                }
                else
                {
                    receiveState = NewYearFairylandCeremonyModel.ReceiveState.NoReach;
                }
            }
            RefreshAwardStateUI();
        }
 
        private void RefreshAwardStateUI()
        {
            receiveBtn.RemoveAllListeners();
            switch (receiveState)
            {
                case NewYearFairylandCeremonyModel.ReceiveState.NoReach:
                    noReachImg.SetActive(true);
                    alreadyImg.SetActive(false);
                    receiveBtn.SetActive(false);
                    break;
                case NewYearFairylandCeremonyModel.ReceiveState.Reach:
                    noReachImg.SetActive(false);
                    alreadyImg.SetActive(false);
                    receiveBtn.SetActive(true);
                    receiveBtn.AddListener(OnReceiveGift);
                    break;
                case NewYearFairylandCeremonyModel.ReceiveState.Already:
                    noReachImg.SetActive(false);
                    alreadyImg.SetActive(true);
                    receiveBtn.SetActive(false);
                    break;
            }
        }
 
        private void OnReceiveGift()
        {
            bool isGrid = playerPack.GetEmptyGridCount(PackType.Item) - itemlist.Count >= 0 ? true : false;
            if (isGrid)
            {
                ceremonyModel.SendReceiveAward(GotServerRewardType.Def_RewardType_NewFairyCParty, awardConfig.Index);
            }
            else
            {
                SysNotifyMgr.Instance.ShowTip("BagFull");
            }
        }
 
    }
}