Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
HyphenationJpn.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Text.RegularExpressions;
5using UnityEngine;
6using UnityEngine.EventSystems;
7using UnityEngine.UI;
8
9[RequireComponent(typeof(Text))]
10public class HyphenationJpn : UIBehaviour
11{
12 public int padding;
13
14 public bool useParentWidth = true;
15
16 public bool usePreferredWidth = true;
17
18 public bool evaluateLate;
19
20 private string text;
21
22 private bool useHypenation;
23
24 private RectTransform _rectTransform;
25
26 private Text _text;
27
28 private float width;
29
30 private static readonly string RITCH_TEXT_REPLACE = "(\\<color=.*\\>|</color>|\\<size=.n\\>|</size>|<b>|</b>|<i>|</i>)";
31
32 private static readonly char[] HYP_FRONT = ",)]}、。)〕〉》」』】〙〗〟’”⦆»ァィゥェォッャュョヮヵヶっぁぃぅぇぉっゃゅょゎ‐゠–〜ー?!!?‼⁇⁈⁉・:;。.".ToCharArray();
33
34 private static readonly char[] HYP_BACK = "(([{〔〈《「『【〘〖〝‘“⦅«".ToCharArray();
35
36 private static readonly char[] HYP_LATIN = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789<>=/().,".ToCharArray();
37
38 private RectTransform _RectTransform
39 {
40 get
41 {
42 if (_rectTransform == null)
43 {
44 _rectTransform = GetComponent<RectTransform>();
45 }
46 return _rectTransform;
47 }
48 }
49
50 public Text _Text
51 {
52 get
53 {
54 if (_text == null)
55 {
56 _text = GetComponent<Text>();
57 }
58 return _text;
59 }
60 }
61
62 private void UpdateText(string str)
63 {
64 if (useHypenation)
65 {
66 _Text.text = GetFormatedText(str).IsEmpty(str);
67 }
68 }
69
70 public void _SetText(string str, bool useHypenation)
71 {
72 text = str;
73 this.useHypenation = useHypenation;
74 if (!useHypenation)
75 {
76 _Text.horizontalOverflow = HorizontalWrapMode.Wrap;
77 _Text.text = text;
78 return;
79 }
80 _Text.text = text;
81 width = GetWidth();
82 if (width < 50f)
83 {
84 this.RebuildLayoutTo<Canvas>();
85 this.RebuildLayout();
86 width = GetWidth();
87 if (width < 50f)
88 {
90 {
91 width = GetWidth();
93 this.RebuildLayout();
94 });
95 }
96 else
97 {
99 this.RebuildLayout();
100 }
101 }
102 else
103 {
105 }
106 }
107
108 public float GetWidth()
109 {
111 {
112 LayoutElement component = GetComponent<LayoutElement>();
113 if ((bool)component && component.enabled && component.preferredWidth != -1f)
114 {
115 return component.preferredWidth;
116 }
117 }
118 if ((bool)base.transform.parent && useParentWidth)
119 {
120 LayoutGroup component2 = base.transform.parent.GetComponent<LayoutGroup>();
121 float num = base.transform.parent.Rect().rect.width;
122 if ((bool)component2)
123 {
124 num = num - (float)component2.padding.left - (float)component2.padding.right;
125 }
126 return num;
127 }
128 return _RectTransform.rect.width;
129 }
130
131 private float GetSpaceWidth()
132 {
133 float textWidth = GetTextWidth("m m");
134 float textWidth2 = GetTextWidth("mm");
135 return textWidth - textWidth2;
136 }
137
138 private float GetTextWidth(string message)
139 {
140 if (_text.supportRichText)
141 {
142 message = Regex.Replace(message, RITCH_TEXT_REPLACE, string.Empty);
143 }
144 _Text.text = message;
145 return _Text.preferredWidth;
146 }
147
148 private string GetFormatedText(string msg)
149 {
150 if (string.IsNullOrEmpty(msg))
151 {
152 return string.Empty;
153 }
154 msg = Regex.Replace(msg, "\\n", "〒");
155 float num = width;
156 float spaceWidth = GetSpaceWidth();
157 _Text.horizontalOverflow = HorizontalWrapMode.Overflow;
158 StringBuilder stringBuilder = new StringBuilder();
159 float num2 = 0f;
160 foreach (string word in GetWordList(msg))
161 {
162 string text = word;
163 num2 += GetTextWidth(text);
164 if (text.StartsWith("〒"))
165 {
166 num2 = 0f;
167 stringBuilder.AppendLine();
168 text = text.Replace("〒", "");
169 }
170 if (text == "〒")
171 {
172 num2 = 0f;
173 stringBuilder.AppendLine();
174 continue;
175 }
176 if (text == " ")
177 {
178 num2 += spaceWidth;
179 }
180 if (num2 > num - (float)padding)
181 {
182 stringBuilder.Append(Environment.NewLine);
183 num2 = GetTextWidth(text);
184 }
185 stringBuilder.Append(text);
186 }
187 return stringBuilder.ToString();
188 }
189
190 private List<string> GetWordList(string tmpText)
191 {
192 List<string> list = new List<string>();
193 StringBuilder stringBuilder = new StringBuilder();
194 char c = '\0';
195 bool flag = false;
196 for (int i = 0; i < tmpText.Length; i++)
197 {
198 char c2 = tmpText[i];
199 char c3 = ((i < tmpText.Length - 1) ? tmpText[i + 1] : c);
200 char c4 = ((i <= 0) ? c : (c4 = tmpText[i - 1]));
201 if (c2 == '<')
202 {
203 flag = true;
204 }
205 if (c2 == '>')
206 {
207 flag = false;
208 }
209 stringBuilder.Append(c2);
210 if (!flag && ((IsLatin(c2) && IsLatin(c4) && IsLatin(c2) && !IsLatin(c4)) || (!IsLatin(c2) && CHECK_HYP_BACK(c4)) || (!IsLatin(c3) && !CHECK_HYP_FRONT(c3) && !CHECK_HYP_BACK(c2)) || i == tmpText.Length - 1))
211 {
212 list.Add(stringBuilder.ToString());
213 stringBuilder = new StringBuilder();
214 }
215 }
216 return list;
217 }
218
219 private static bool CHECK_HYP_FRONT(char str)
220 {
221 return Array.Exists(HYP_FRONT, (char item) => item == str);
222 }
223
224 private static bool CHECK_HYP_BACK(char str)
225 {
226 return Array.Exists(HYP_BACK, (char item) => item == str);
227 }
228
229 private static bool IsLatin(char s)
230 {
231 return false;
232 }
233}
List< Action > actionsNextFrame
Definition: BaseCore.cs:31
static BaseCore Instance
Definition: BaseCore.cs:11
List< string > GetWordList(string tmpText)
RectTransform _rectTransform
static bool CHECK_HYP_BACK(char str)
void _SetText(string str, bool useHypenation)
float GetTextWidth(string message)
static bool IsLatin(char s)
float GetSpaceWidth()
static bool CHECK_HYP_FRONT(char str)
string GetFormatedText(string msg)
RectTransform _RectTransform
static readonly string RITCH_TEXT_REPLACE
static readonly char[] HYP_FRONT
void UpdateText(string str)
static readonly char[] HYP_BACK
static readonly char[] HYP_LATIN