少年修仙传客户端代码仓库
client_Wu Xijin
2019-06-13 033958214c0b16d7e7b93cc821b018c295251867
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
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
    public class ChatBubbleSelectBehaviour : MonoBehaviour
    {
        [SerializeField] Button m_Func;
        [SerializeField] Image m_Icon;
        [SerializeField] Image m_Using;
        [SerializeField] Text m_BubbleName;
        [SerializeField] RectTransform m_ContainerUnGet;
        [SerializeField] Text m_Condition;
 
        private int bubbleId = 0;
 
        ChatBubbleModel model
        {
            get { return ModelCenter.Instance.GetModel<ChatBubbleModel>(); }
        }
 
        VipModel vipModel
        {
            get { return ModelCenter.Instance.GetModel<VipModel>(); }
        }
 
        private void Awake()
        {
            m_Func.onClick.AddListener(OnFunc);
        }
 
        private void OnEnable()
        {
            PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshInfoEvent;
            vipModel.OnVipGiftEvent += OnVipGiftEvent;
            model.chatBubbleStateRefresh += ChatBubbleStateRefresh;
        }
 
        private void OnDisable()
        {
            PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshInfoEvent;
            vipModel.OnVipGiftEvent -= OnVipGiftEvent;
            model.chatBubbleStateRefresh -= ChatBubbleStateRefresh;
        }
 
        private void ChatBubbleStateRefresh()
        {
            DisplayState();
        }
 
        private void PlayerDataRefreshInfoEvent(PlayerDataType refreshType)
        {
            if (refreshType == PlayerDataType.ExAttr10)
            {
                DisplaySelect();
            }
            else if (refreshType == PlayerDataType.LV)
            {
                DisplayState();
            }
        }
 
        private void OnVipGiftEvent()
        {
            DisplayState();
        }
 
        public void Display(int id)
        {
            ChatBubbleModel.ChatBubble bubble;
            if (model.TryGetBubble(id, out bubble))
            {
                bubbleId = id;
                var config = ChatBubbleBoxConfig.Get(bubbleId);
                m_BubbleName.text = config.Name;
                m_Icon.SetSprite(config.Icon);
                DisplayState();
                DisplaySelect();
            }
        }
 
        void DisplaySelect()
        {
            m_Using.gameObject.SetActive(PlayerDatas.Instance.baseData.bubbleId == bubbleId);
        }
 
        void DisplayState()
        {
            ChatBubbleModel.ChatBubble bubble;
            if (model.TryGetBubble(bubbleId, out bubble))
            {
                var got = model.IsBubbleGot(bubbleId);
                m_ContainerUnGet.gameObject.SetActive(!got);
                var config = ChatBubbleBoxConfig.Get(bubbleId);
                if (!got)
                {
                    m_Condition.text = config.GainTip;
                }
            }
        }
 
        private void OnFunc()
        {
            if (model.IsBubbleGot(bubbleId))
            {
                model.SendUseBubble(bubbleId);
            }
            else
            {
                ChatBubblePreviewWin.previewBubbleId = bubbleId;
                WindowCenter.Instance.Open<ChatBubblePreviewWin>();
            }
        }
    }
}