少年修仙传客户端代码仓库
client_linchunjie
2019-04-17 b0718b0ff46e1d337c28bb91105b67b66f93bee3
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Friday, September 21, 2018
//--------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
 
using System;
using System.Collections.Generic;
 
namespace Snxxz.UI
{
 
    public class DungenWHYJ : MonoBehaviour
    {
 
        [SerializeField] Button m_WHYJButton;
        [SerializeField] GameObject m_Container_WHYJ;        
        [SerializeField] Transform m_Horizontal;
        [SerializeField] Image m_Rating;//评级
        DungeonModel model { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
        List<int> ListRating = new List<int>();
        public void Init()
        {
            ListRating.Clear();
            var congfig = DungeonOpenTimeConfig.Get(51010).RewardRate;
            for (int i = 0; i < congfig.Length; i++)
            {
                ListRating.Add(congfig[i]);
            }           
            model.dungeonFightStageChangeEevent += dungeonFightStageChangeEevent;        
            model.updateMissionEvent += updateMissionEvent;
            if (model.dungeonFightStage == DungeonFightStage.Prepare)
            {
                m_Container_WHYJ.SetActive(true);
            }
            else
            {
                m_Container_WHYJ.SetActive(false);
            }
            SetRatingImage();
            SetTranItemCell();
        }
 
        public void Unit()
        {
            model.dungeonFightStageChangeEevent -= dungeonFightStageChangeEevent;
            model.updateMissionEvent -= updateMissionEvent;
        }
 
        private void updateMissionEvent()
        {
            SetRatingImage();
            SetTranItemCell();
        }
 
        private void Start()
        {
            m_WHYJButton.AddListener(OnClickButton);
        }
        private void OnEnable()
        {
           
        }
        private void OnDisable()
        {
          
        }
 
        private void dungeonFightStageChangeEevent(DungeonFightStage obj)
        {
            if (obj == DungeonFightStage.Prepare)
            {
                if (!m_Container_WHYJ.activeSelf)
                {
                    m_Container_WHYJ.SetActive(true);
                }
            }
            else if(obj == DungeonFightStage.Normal)
            {
                if (m_Container_WHYJ.activeSelf)
                {
                    m_Container_WHYJ.SetActive(false);
                }
            }
        }
 
        private void SetTranItemCell()
        {
            int lineID = model.mission.lineID;
            var WHYJConfig = WHYJRewardConfig.Get(lineID+1);
            int[] RewardList = ConfigParse.GetMultipleStr<int>(WHYJConfig.Reward);
            int[] QuantityList = ConfigParse.GetMultipleStr<int>(WHYJConfig.Quantity);
            for (int i = 0; i < m_Horizontal.childCount; i++)
            {
                if (i < RewardList.Length)
                {
                    m_Horizontal.GetChild(i).gameObject.SetActive(true);
                    ItemCell ItemCell = m_Horizontal.GetChild(i).GetComponent<ItemCell>();
                    float value = GetRating() * QuantityList[i];
                    ItemCellModel cellModel = new ItemCellModel(RewardList[i], true, (ulong)Math.Round(value,0));
                    ItemCell.Init(cellModel);
                }
                else
                {
                    m_Horizontal.GetChild(i).gameObject.SetActive(false);
                }
            }
        }
        private void OnClickButton()
        {
            m_Container_WHYJ.SetActive(!m_Container_WHYJ.activeSelf);
        }
 
        private float GetRating()
        {
            float Value = 1f;
            if (ListRating.Count < 4)
            {
                return Value;
            }
            switch (model.mission.grade)
            {
                case 1:
                    Value =(float)Math.Round((double)ListRating[4] / 100, 1);                
                    return Value;
                case 2:
                    Value = (float)Math.Round((double)ListRating[3] / 100, 1);
                    return Value;
                case 3:
                    Value = (float)Math.Round((double)ListRating[2] / 100, 1);
                    return Value;
                case 4:
                    Value = (float)Math.Round((double)ListRating[1] / 100, 1);
                    return Value;
                case 5:
                    Value = (float)Math.Round((double)ListRating[0] / 100, 1);
                    return Value;
                default:
                    Value = (float)Math.Round((double)ListRating[0] / 100, 1);
                    return Value;
            }              
        }
        private void SetRatingImage()
        {
            if (model.mission.Equals(default(DungeonMissionData)))
            {
                return;
            }
            switch (model.mission.grade)
            {
                case 1:
                    m_Rating.SetSprite("Rating_D");
                    break;
                case 2:
                    m_Rating.SetSprite("Rating_C");
                    break;
                case 3:
                    m_Rating.SetSprite("Rating_B");
                    break;
                case 4:
                    m_Rating.SetSprite("Rating_A");
                    break;
                case 5:
                    m_Rating.SetSprite("Rating_S");
                    break;
                default:
                    m_Rating.SetSprite("Rating_S");
                    break;
            }
        }
    }
}