少年修仙传客户端代码仓库
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
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Monday, April 22, 2019
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace vnxbqy.UI
{
 
    public class TreasureChapterWin : Window
    {
        [SerializeField] RawImage m_GaussianMask;
        [SerializeField] UIAlphaTween m_AlphaTween;
        [SerializeField] Text m_ChapterName;
        [SerializeField] Image m_ChapterIcon;
        [SerializeField] Image m_TreasureIcon;
        [SerializeField] Text m_Description;
        [SerializeField] Text m_CloseRemind;
        [SerializeField] Transform m_ContainerFly;
        [SerializeField] Button m_Close;
        [SerializeField] float m_AutoCloseSeconds = 6f;
 
        float timer = 0f;
        float perSecond = 0f;
 
        bool flying = false;
 
        FunctionUnlockFlyObject flyObject = null;
 
        public static int displayId = 0;
 
        TreasureModel model { get { return ModelCenter.Instance.GetModel<TreasureModel>(); } }
        TaskModel taskModel { get { return ModelCenter.Instance.GetModel<TaskModel>(); } }
 
        #region Built-in
        protected override void BindController()
        {
        }
 
        protected override void AddListeners()
        {
            m_Close.AddListener(OnClickClose);
        }
 
        protected override void OnPreOpen()
        {
            if (flyObject != null)
            {
                Destroy(flyObject.gameObject);
                flyObject = null;
            }
 
            timer = 0f;
            perSecond = 0f;
 
            flying = false;
 
            m_GaussianMask.SetActive(false);
 
            m_AlphaTween.from = 0f;
            m_AlphaTween.to = 1f;
            m_AlphaTween.SetStartState();
 
            PlayerDatas.Instance.hero.StopAll();
 
            Display();
            DisplayTimer();
        }
 
        protected override void OnActived()
        {
            base.OnActived();
            CameraUtility.ScreenShotCut(m_GaussianMask, DoPrepare, true);
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
            model.treasureChapterId = 0;
        }
 
        protected override void OnAfterClose()
        {
            taskModel.AutomaticTripToTask(taskModel.currentMission);
        }
 
        protected override void LateUpdate()
        {
            perSecond += Time.deltaTime;
            if (perSecond >= 0.5f)
            {
                DisplayTimer();
                perSecond = 0f;
            }
 
            timer += Time.deltaTime;
            if (timer >= m_AutoCloseSeconds && !flying)
            {
                OnClickClose();
            }
        }
        #endregion
 
        private void DoPrepare()
        {
            m_GaussianMask.SetActive(true);
            m_AlphaTween.Play();
        }
 
        void Display()
        {
            var instance = UIUtility.CreateWidget("TreasureChapterFlyObject", "TreasureChapterFlyObject");
            instance.transform.SetParentEx(m_ContainerFly, Vector3.zero, Quaternion.identity, Vector3.one);
            flyObject = instance.GetComponent<FunctionUnlockFlyObject>();
            flyObject.SetContent(FunctionUnlockType.TreasureChapter, model.treasureChapterId);
            flyObject.SetSpeed(6f);
            flyObject.SetActive(true);
 
            var config = TreasureConfig.Get(model.treasureChapterId);
            if (config != null)
            {
                m_TreasureIcon.SetSprite(config.Icon);
            }
 
            var chapterConfig = TreasureChapterConfig.Get(model.treasureChapterId);
 
            if (chapterConfig != null)
            {
                m_ChapterIcon.SetSprite(chapterConfig.taskTitle);
                m_ChapterName.text = Language.Get("TreasureChapterName", Language.Get("Num_CHS_" + chapterConfig.chapterIndex));
                m_Description.text = UIHelper.ReplaceNewLine(chapterConfig.description);
            }
        }
 
        void DisplayTimer()
        {
            m_CloseRemind.text = Language.Get("AutoCloseAfterSeconds", m_AutoCloseSeconds - (int)timer);
        }
 
        private void OnClickClose()
        {
            if (timer < 2f || flying)
            {
                return;
            }
            m_GaussianMask.SetActive(false);
            flying = true;
            m_AlphaTween.from = 1f;
            m_AlphaTween.to = 0f;
            m_AlphaTween.Play(OnTweenComplete);
        }
 
        private void OnTweenComplete()
        {
            if (flyObject != null)
            {
                flyObject.Begin(OnReach);
            }
        }
 
        private void OnReach()
        {
            CloseClick();
        }
    }
 
}