少年修仙传客户端代码仓库
client_linchunjie
2018-09-19 aecb6a5a62d8a4cfc7b924ce957a9c7ea90c235d
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
 
namespace Snxxz.UI
{
    public class RedpointCenter : Singleton<RedpointCenter>
    {
        public event Action<int> redpointValueChangeEvent;
 
        Dictionary<int, Redpoint> redpoints = new Dictionary<int, Redpoint>();
        Dictionary<int, List<int>> parentChildren = new Dictionary<int, List<int>>();
 
        public RedpointCenter()
        {
 
        }
 
        public void ResetAllRedpointState()
        {
            foreach (var redpoint in redpoints.Values)
            {
                redpoint.state = RedPointState.None;
            }
        }
 
        public void Register(Redpoint _redpoint)
        {
            var id = _redpoint.id;
            redpoints[id] = _redpoint;
 
            var parentId = _redpoint.parent;
            if (parentId > 0)
            {
                List<int> children = null;
                if (!parentChildren.TryGetValue(parentId, out children))
                {
                    parentChildren[parentId] = children = new List<int>();
                }
 
                if (!children.Contains(id))
                {
                    children.Add(id);
                }
            }
        }
 
        public void Report(Redpoint _redpoint)
        {
            var parentId = _redpoint.parent;
 
            if (redpointValueChangeEvent != null)
            {
                redpointValueChangeEvent(_redpoint.id);
            }
 
            if (parentId > 0)
            {
                TestParentValue(_redpoint.parent);
            }
        }
 
        public void ReportWithoutParent(Redpoint _redpoint)
        {
            if (redpointValueChangeEvent != null)
            {
                redpointValueChangeEvent(_redpoint.id);
            }
        }
 
        public RedPointState GetRedpointState(int _id)
        {
            Redpoint redpoint = null;
            if (this.redpoints.TryGetValue(_id, out redpoint))
            {
                return redpoint.state;
            }
            else
            {
                return RedPointState.None;
            }
        }
 
        public int GetRedpointCount(int _id)
        {
            Redpoint redpoint = null;
            if (this.redpoints.TryGetValue(_id, out redpoint))
            {
                return redpoint.count;
            }
            else
            {
                return 0;
            }
        }
 
        void TestParentValue(int _parentId)
        {
            List<int> children = null;
            Redpoint parent = null;
            if (redpoints.TryGetValue(_parentId, out parent) && parentChildren.TryGetValue(_parentId, out children))
            {
                var parentState = RedPointState.None;
                for (int i = 0; i < children.Count; i++)
                {
                    Redpoint child = null;
                    if (redpoints.TryGetValue(children[i], out child))
                    {
                        if (child.state > parentState)
                        {
                            parentState = child.state;
                        }
                    }
 
                    if (parentState == RedPointState.Full)
                    {
                        break;
                    }
 
                }
                parent.state = parentState;
            }
        }
 
    }
}