少年修仙传客户端代码仓库
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
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
 
public class ColorAnalysis : TRichAnalysis<ColorAnalysis>
{
    public static Regex Color_Start_Regex = new Regex(@"<color=#([0-9a-zA-Z]+)>", RegexOptions.Singleline);
 
    public override string Analysis(string val, bool IsRich)
    {
        if (!Color_Start_Regex.IsMatch(val) || RichTextMgr.Inst.presentRichText == null)
        {
            return val;
        }
        int index = 0;
        m_StringBuilder.Length = 0;
        var _text = RichTextMgr.Inst.presentRichText;
        if (_text.colorType == RichText.ColorType.Bright)
        {
            return val;
        }
        foreach (Match match in Color_Start_Regex.Matches(val))
        {
            m_StringBuilder.Append(val.Substring(index, match.Groups[1].Index - index));
            m_StringBuilder.Append(GetColorMap(match.Groups[1].Value));
            index = match.Groups[1].Index + match.Groups[1].Length;
        }
        m_StringBuilder.Append(val.Substring(index, val.Length - index));
        return m_StringBuilder.ToString();
    }
 
    private string GetColorMap(string _value)
    {
        if (_value.Length > 6)
        {
            _value = _value.Substring(0, 6);
        }
        switch (_value.ToLower())
        {
            case "109d06":
                return "35e122";
            case "ff6701":
                return "f8983b";
            case "006be3":
                return "31cefb";
            case "ff0303":
                return "fa0101";
            case "12a199":
                return "13a199";
            case "686868":
                return "f7f7f7";
        }
        return _value;
    }
 
    public override string CalculateTextIndex(string val, int index)
    {
        return string.Empty;
    }
}