少年修仙传客户端代码仓库
client_Wu Xijin
2019-04-16 fc714208ff3a320c3bb52bddd5ea3d91f647a206
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
    public class HazyRegionIncidentPanel : MonoBehaviour
    {
        [SerializeField] HazyRegionCyclicScroll m_CyclicScroll;
        [SerializeField] Transform m_ContainerPoint;
        [SerializeField] Slider m_Slider;
        [SerializeField] Text m_Point;
        [SerializeField] Button m_Back;
        [SerializeField] Button m_Goto;
 
        List<int> incidents = new List<int>();
 
        HazyRegionModel model { get { return ModelCenter.Instance.GetModel<HazyRegionModel>(); } }
 
        private void Awake()
        {
            m_Back.AddListener(OnBack);
            m_Goto.AddListener(Goto);
        }
 
        public void Display()
        {
            DisplayPoint();
            DisplayIncidents();
            DisplayBackButton();
        }
 
        void DisplayIncidents()
        {
            incidents.Clear();
            incidents.AddRange(model.GetAllIncidents());
            incidents.Sort(Compare);
 
            if (incidents.Count > 0)
            {
                model.selectIncident = incidents[0];
            }
 
            m_CyclicScroll.Init(incidents);
 
            if (model.requireIncidentAnimation)
            {
                m_CyclicScroll.DisplayAnimation();
                model.requireIncidentAnimation = false;
            }
        }
 
        void DisplayPoint()
        {
            m_ContainerPoint.gameObject.SetActive(!model.InFakeHazyRegion);
 
            if (!model.InFakeHazyRegion)
            {
                var point = Mathf.Min(model.point, model.limitPoint);
                m_Point.text = StringUtility.Contact(point, "/", model.limitPoint);
                m_Slider.value = Mathf.Clamp01((float)point / model.limitPoint);
            }
        }
 
        void DisplayBackButton()
        {
            m_Back.gameObject.SetActive(!model.InFakeHazyRegion);
        }
 
        int Compare(int lhs, int rhs)
        {
            var lhs_config = HazyRegionConfig.Get(lhs);
            var rhs_config = HazyRegionConfig.Get(rhs);
            if (lhs_config.incidentType != rhs_config.incidentType)
            {
                return lhs_config.incidentType.CompareTo(rhs_config.incidentType);
            }
            return 0;
        }
 
        private void OnBack()
        {
            if (model.IsIncidentDungeon())
            {
 
                return;
            }
 
            var state = 0;
 
            bool allComplete = true;
            int minpoint = int.MaxValue;
 
            foreach (var id in incidents)
            {
                HazyRegionModel.Incident incident;
                if (model.TryGetIncident(id, out incident))
                {
                    if (incident.state == HazyRegionModel.IncidentState.Processing)
                    {
                        state = 2;
                        allComplete = false;
                        break;
                    }
                    if(incident.state != HazyRegionModel.IncidentState.Complete)
                    {
                        allComplete = false;
                    }
                    var config = HazyRegionConfig.Get(id);
                    if (minpoint > config.point)
                    {
                        minpoint = config.point;
                    }
                }
            }
 
            if (state == 0 && !allComplete && model.point >= minpoint)
            {
                state = 1;
            }
 
            switch (state)
            {
                case 1:
                    ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("HazyRegionBackRemind_1"), (bool isOk) =>
                    {
                        if (isOk)
                        {
                            model.SendBackHazyRegion();
                        }
                    });
                    break;
                case 2:
                    ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("HazyRegionBackRemind_2"), (bool isOk) =>
                    {
                        if (isOk)
                        {
                            model.SendBackHazyRegion();
                        }
                    });
                    break;
                default:
                    model.SendBackHazyRegion();
                    break;
            }
        }
 
        private void Goto()
        {
            var error = 0;
            if (!model.TryGotoIncident(model.selectIncident, out error))
            {
                model.DisplayErrorRemind(error);
            }
            else
            {
                model.SendGotoIncident(model.selectIncident);
            }
        }
 
        public void Dispose()
        {
            m_CyclicScroll.Dispose();
        }
 
#if UNITY_EDITOR
        void OnGUI()
        {
            if (GUILayout.Button("Back"))
            {
                OnBack();
            }
        }
#endif
    }
}