少年修仙传客户端代码仓库
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class RichTextMgr {
 
    private static RichTextMgr _inst = null;
    public static RichTextMgr Inst {
        get {
            if (_inst == null) {
                _inst = new RichTextMgr();
                _inst.Init();
            }
            return _inst;
        }
    }
 
    private void Init()
    {
        new RichMoveEvent();
        new RichTableEvent();
        new RichNormalEvent();
        new RichFbEvent();
        new RichShowPlayerEvent();
    }
 
    public RichText presentRichText = null;
    /// <summary>
    /// Text 富文本解析
    /// </summary>
    /// <param name="_text"></param>
    /// <returns></returns>
    public string Analysis(string _text,out List<ImgInfo> imgList,out List<HrefInfo> hrefList,RichText text=null)
    {
        imgList = new List<ImgInfo>();
        m_ImgInfoList = imgList;
        hrefList = new List<HrefInfo>();
        m_HrefInfoList = hrefList;
 
        presentRichText = text;
 
        string result=GetAnalysis(_text);
        //for (int i = 0; i < m_ImgInfoList.Count; i++) {
            ImgAnalysis.Inst.CalculateTextIndex(result, 0);
        //}
        return result;
    }
 
    public string Analysis(string val)
    {
        m_HrefInfoList = null;
        m_ImgInfoList = null;
 
        return GetAnalysis(val);
    }
 
    private string GetAnalysis(string val)
    {
        string result = ImgAnalysis.ReplaceFace(val);
        try
        {
            result = ColorAnalysis.Inst.Analysis(result, true);
            result = WordAnalysis.Inst.ReplaceSpace(result);
            result = ImgAnalysis.Inst.Analysis(result, true);
            result = WordAnalysis.Inst.Analysis(result, true);
            result = HrefAnalysis.Inst.Analysis(result, true);
            result = SuitNameAnalysis.Inst.Analysis(result, true);
            result = HrefAnalysis.Inst.CalculateTextIndex(result, 0);
        }
        catch (System.Exception e)
        {
            DebugEx.LogError(e.Message+e.StackTrace);
        }
        return result;
    }
 
    public class HrefInfo
    {
        public int start = 0;
 
        public int end = 0;
 
        public List<Rect> boxs=new List<Rect>();
        public List<int> lines = new List<int>();
 
        public Dictionary<string, string> mSplits = new Dictionary<string, string>();
 
        public List<RichTextEventEnum> mEvents = new List<RichTextEventEnum>();
 
        public int start_cache_cnt = 0;
        public int end_cache_cnt = 0;
 
        public bool unline = true;
 
        public Color unlineColor = Color.green;
 
        public bool fromAutoTask = false;
 
        public void Add(string key,string value)
        {
            if (!mSplits.ContainsKey(key)) {
                mSplits.Add(key, value);
                return;
            }
            mSplits[key] = value;
        }
 
        public bool Execute(int index = 0)
        {
            if (mEvents.Count < 1) return false;
            return RichTextMgr.Inst.ExecuteEvent(mEvents[index], this);
        }
    }
 
    public class ImgInfo
    {
        public float width;
        public float height;
        public int end;
        public int index;
        public int cacheCnt;
 
        public Sprite sprite;
        public string spriteName;
        public bool IsFace;
        public float scale; //缩放图片的同时,二次缩放了图片在文本钟的占位大小,查看函数InverseToRichText
 
        public HrefInfo href = null;
    }
 
    private List<ImgInfo> m_ImgInfoList;
    public List<ImgInfo> GetImgList()
    {
        return m_ImgInfoList;
    }
 
    private List<HrefInfo> m_HrefInfoList;
    public List<HrefInfo> GetHrefList()
    {
        return m_HrefInfoList;
    }
 
 
    #region 富文本事件
    private static Dictionary<RichTextEventEnum, TRichTextEvent> m_RichEvents = new Dictionary<RichTextEventEnum, TRichTextEvent>();
    public void RegisterEvent(RichTextEventEnum type,TRichTextEvent evt)
    {
        if (!m_RichEvents.ContainsKey(type)) {
            m_RichEvents.Add(type, evt);
        }
    }
 
    public bool ExecuteEvent(RichTextEventEnum type,HrefInfo href)
    {
        return m_RichEvents[type].Execute(type,href);
    }
 
    public string GetDisplay(RichTextEventEnum type,Dictionary<string,string> dic)
    {
        return m_RichEvents[type].GetDisplay(type, dic);
    }
    #endregion
}