少年修仙传客户端代码仓库
client_Hale
2018-11-05 1b4e8bb37f33dc03e0119b1d2fcaefbc291d6fad
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
using System.Collections;
using System.Collections.Generic;
using TableConfig;
using UnityEngine;
namespace Snxxz.UI
{
    public class ChatBubbleModel : Model
    {
        public Dictionary<int, ChatBubble> chatBubbles = new Dictionary<int, ChatBubble>();
        public override void Init()
        {
            ParseConfig();
        }
 
        public override void UnInit()
        {
        }
 
        void ParseConfig()
        {
            var configs = Config.Instance.GetAllValues<ChatBubbleBoxConfig>();
            for (int i = 0; i < configs.Count; i++)
            {
                var config = configs[i];
                if (chatBubbles.ContainsKey(config.ID))
                {
                    continue;
                }
                var bubble = new ChatBubble();
                bubble.id = config.ID;
                bubble.name = config.Name;
                bubble.requireLevel = config.NeedLV;
                bubble.requireVipLevel = config.NeedVIPLVGift;
                bubble.leftBubbleIcon = config.leftBubbleIcon;
                bubble.rightBubbleIcon = config.rightBubbleIcon;
                bubble.leftPadding = new RectOffset()
                {
                    left = config.leftOffset.Length > 0 ? config.leftOffset[0] : 0,
                    right = config.leftOffset.Length > 1 ? config.leftOffset[1] : 0,
                    top = config.leftOffset.Length > 2 ? config.leftOffset[2] : 0,
                    bottom = config.leftOffset.Length > 3 ? config.leftOffset[3] : 0,
                };
                bubble.rifhtPadding = new RectOffset()
                {
                    left = config.rightOffset.Length > 0 ? config.rightOffset[0] : 0,
                    right = config.rightOffset.Length > 1 ? config.rightOffset[1] : 0,
                    top = config.rightOffset.Length > 2 ? config.rightOffset[2] : 0,
                    bottom = config.rightOffset.Length > 3 ? config.rightOffset[3] : 0,
                };
                chatBubbles.Add(config.ID, bubble);
            }
        }
 
        public bool TryGetBubble(int id, out ChatBubble bubble)
        {
            return chatBubbles.TryGetValue(id, out bubble);
        }
 
        public struct ChatBubble
        {
            public int id;
            public string name;
            public int requireLevel;
            public int requireVipLevel;
            public string leftBubbleIcon;
            public string rightBubbleIcon;
            public RectOffset leftPadding;
            public RectOffset rifhtPadding;
 
            public string GetBubbleIcon(bool left, ref bool isFlip)
            {
                isFlip = false;
                if (left)
                {
                    if (string.IsNullOrEmpty(leftBubbleIcon))
                    {
                        isFlip = true;
                        return rightBubbleIcon;
                    }
                    return leftBubbleIcon;
                }
                else
                {
                    if (string.IsNullOrEmpty(rightBubbleIcon))
                    {
                        isFlip = true;
                        return leftBubbleIcon;
                    }
                    return rightBubbleIcon;
                }
            }
        }
    }
}