少年修仙传客户端代码仓库
client_Wu Xijin
2019-03-14 007541eae116f6b73f992c1a4df7ecbe77178099
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
    public class RealmLevelUpBehaviour : MonoBehaviour
    {
        [SerializeField] Transform m_ContainerCondition;
        [SerializeField] RealmUpCondition m_LevelCondition;
        [SerializeField] RealmUpCondition m_BossCondition;
        [SerializeField] Transform m_ContainerCost;
        [SerializeField] ItemBehaviour m_Item;
        [SerializeField] Text m_RequireRealmLevel;
        [SerializeField] Button m_LevelUp;
 
        int realmLevel = 0;
 
        RealmModel model { get { return ModelCenter.Instance.GetModel<RealmModel>(); } }
        PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
 
        private void Awake()
        {
            m_LevelUp.AddListener(OnLevelUp);
        }
 
        public void Display(int realmLevel)
        {
            this.realmLevel = realmLevel;
            var currentRealmLevel = PlayerDatas.Instance.baseData.realmLevel;
            var isNext = realmLevel == currentRealmLevel + 1;
            m_ContainerCondition.gameObject.SetActive(isNext);
            m_ContainerCost.gameObject.SetActive(isNext);
            m_LevelUp.gameObject.SetActive(isNext);
            m_RequireRealmLevel.gameObject.SetActive(!isNext);
 
            if (isNext)
            {
                DisplayCondition();
                DisplayCost();
            }
            else
            {
                var config = RealmConfig.Get(realmLevel - 1);
                m_RequireRealmLevel.text = Language.Get("RealmLevelUpRequire", config.Img);
            }
        }
 
        public void DisplayCondition()
        {
            var config = RealmConfig.Get(realmLevel - 1);
            m_LevelCondition.DisplayLevel(realmLevel - 1);
            m_BossCondition.SetActive(config.BossID != 0);
            if (config.BossID != 0)
            {
                m_BossCondition.DisplayBoss(realmLevel - 1);
            }
        }
 
        public void DisplayCost()
        {
            var config = RealmConfig.Get(realmLevel - 1);
            m_ContainerCost.gameObject.SetActive(config.NeedGood != 0);
            m_Item.SetItem(config.NeedGood, config.NeedNum);
        }
 
        private void OnLevelUp()
        {
            var error = 0;
            if (TryLevelUp(out error))
            {
                CA523_tagCMRealmLVUp pak = new CA523_tagCMRealmLVUp();
                GameNetSystem.Instance.SendInfo(pak);
            }
            else
            {
                DisplayErrorTip(error);
            }
        }
 
        bool TryLevelUp(out int error)
        {
            error = 0;
            var config = RealmConfig.Get(realmLevel - 1);
            if (PlayerDatas.Instance.baseData.LV < config.NeedLV)
            {
                error = 1;
                return false;
            }
            if (config.BossID != 0 && !model.isBossPass)
            {
                error = 2;
                return false;
            }
            if (config.NeedGood != 0)
            {
                var count = packModel.GetItemCountByID(PackType.Item, config.NeedGood);
                if (count < config.NeedNum)
                {
                    error = 3;
                    return false;
                }
            }
            return true;
        }
 
        void DisplayErrorTip(int error)
        {
            switch (error)
            {
                case 1:
                    break;
                case 2:
                    break;
                case 3:
                    break;
            }
        }
    }
 
    [Serializable]
    public class RealmUpCondition
    {
        [SerializeField] Transform m_Container;
        [SerializeField] Text m_Condition;
        [SerializeField] Text m_Progress;
 
        RealmModel model { get { return ModelCenter.Instance.GetModel<RealmModel>(); } }
 
        public void DisplayLevel(int realmLevel)
        {
            var config = RealmConfig.Get(realmLevel);
            m_Condition.text = Language.Get("RealmConditionLevel", config.NeedLV);
            var level = PlayerDatas.Instance.baseData.LV;
            var satisfy = level >= config.NeedLV;
            m_Progress.text = StringUtility.Contact(level, "/", config.NeedLV);
            m_Progress.color = satisfy ? UIHelper.s_LightGreen : UIHelper.s_DarkRedColor;
        }
 
        public void DisplayBoss(int realmLevel)
        {
            var config = RealmConfig.Get(realmLevel);
            var label = UIHelper.GetRealmColorByLv(realmLevel, StringUtility.Contact("[", config.Name, "]"));
            m_Condition.text = Language.Get("RealmConditionBoss", label);
            var progress = model.isBossPass ? 1 : 0;
            m_Progress.text = StringUtility.Contact(progress, "/", 1);
            m_Progress.color = model.isBossPass ? UIHelper.s_LightGreen : UIHelper.s_DarkRedColor;
        }
 
        public void SetActive(bool active)
        {
            m_Container.gameObject.SetActive(active);
        }
    }
}