MessageClass.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using UnityEngine;
  5. public class MessageClass
  6. {
  7. public MessageClass(GameObject message_window_panel, MessageWindowMgr message_mgr)
  8. {
  9. this.script_mgr_ = GameMain.Instance.ScriptMgr;
  10. this.message_mgr_ = message_mgr;
  11. this.exit_wait_count_ = -1;
  12. this.message_window_panel_ = message_window_panel;
  13. this.message_label_ = UTY.GetChildObject(this.message_window_panel_, "MessageViewer/MsgParent/Message", false).GetComponent<UILabel>();
  14. this.name_label_ = UTY.GetChildObject(this.message_window_panel_, "MessageViewer/MsgParent/SpeakerName/Name", false).GetComponent<UILabel>();
  15. this.subtitles_manager_ = UTY.GetChildObject(this.message_window_panel_, "MessageViewer/MsgParent/SubtitlesDisplayPanel", false).GetComponent<SubtitleDisplayManager>();
  16. this.hitret_sprite_ = UTY.GetChildObject(this.message_window_panel_, "MessageViewer/MsgParent/Hitret", false).GetComponent<UISprite>();
  17. this.hitret_sprite_.alpha = 0f;
  18. this.mainTextAnimation = new MessageClass.TextAnimation();
  19. this.subTextAnimation = new MessageClass.TextAnimation();
  20. this.subtitles_manager_.visible = true;
  21. this.message_label_.gameObject.SetActive(false);
  22. this.name_label_.gameObject.SetActive(false);
  23. UTY.GetChildObject(this.message_window_panel_, "MessageViewer/MsgParent/MessageBox", false).SetActive(false);
  24. this.message_label_ = (this.name_label_ = null);
  25. }
  26. public static KeyValuePair<string, string> GetTranslationText(string baseText)
  27. {
  28. if (string.IsNullOrEmpty(baseText))
  29. {
  30. return new KeyValuePair<string, string>(string.Empty, string.Empty);
  31. }
  32. int num = baseText.IndexOf("<E>");
  33. if (num < 0)
  34. {
  35. num = baseText.IndexOf("<e>");
  36. if (num < 0)
  37. {
  38. return new KeyValuePair<string, string>(baseText, string.Empty);
  39. }
  40. }
  41. return new KeyValuePair<string, string>(baseText.Substring(0, num), baseText.Substring(num + 3, baseText.Length - (num + 3)));
  42. }
  43. public static string GetWrapString(UILabel draw_target, string text)
  44. {
  45. string text2 = string.Empty;
  46. draw_target.Wrap(text, out text2);
  47. if (text2.IndexOf('\n') == -1)
  48. {
  49. return text2;
  50. }
  51. string a = text2;
  52. string[] collection = text2.Split(new char[]
  53. {
  54. '\n'
  55. });
  56. List<string> list = new List<string>();
  57. list.AddRange(collection);
  58. text2 = string.Empty;
  59. for (int i = 0; i < list.Count - 1; i++)
  60. {
  61. string text3 = list[i];
  62. string text4 = list[i + 1];
  63. StringInfo stringInfo = new StringInfo(text3);
  64. int lengthInTextElements = stringInfo.LengthInTextElements;
  65. StringInfo stringInfo2 = new StringInfo(text4);
  66. int lengthInTextElements2 = stringInfo2.LengthInTextElements;
  67. while (0 < lengthInTextElements2 && 0 < lengthInTextElements)
  68. {
  69. string value = stringInfo2.SubstringByTextElements(0, 1);
  70. if (0 > MessageClass.kInsokuString.IndexOf(value))
  71. {
  72. break;
  73. }
  74. text4 = stringInfo.SubstringByTextElements(lengthInTextElements - 1, 1) + text4;
  75. text3 = stringInfo.SubstringByTextElements(0, lengthInTextElements - 1);
  76. stringInfo = new StringInfo(text3);
  77. lengthInTextElements = stringInfo.LengthInTextElements;
  78. stringInfo2 = new StringInfo(text4);
  79. lengthInTextElements2 = stringInfo2.LengthInTextElements;
  80. }
  81. text2 = text2 + text3 + '\n';
  82. list[i] = string.Empty;
  83. list[i + 1] = text4;
  84. string text5 = string.Empty;
  85. foreach (string text6 in list)
  86. {
  87. if (!(text6 == string.Empty) && !(text6 == "\n"))
  88. {
  89. text5 += text6;
  90. }
  91. }
  92. string empty = string.Empty;
  93. draw_target.Wrap(text5, out empty);
  94. text5 = empty;
  95. list.Clear();
  96. list.AddRange(text5.Split(new char[]
  97. {
  98. '\n'
  99. }));
  100. i = -1;
  101. if (a == text5)
  102. {
  103. break;
  104. }
  105. a = text5;
  106. }
  107. if (1 <= list.Count)
  108. {
  109. text2 += list[list.Count - 1];
  110. }
  111. return text2;
  112. }
  113. public void SetText(string name, string text, string voice_file, int voice_pitch)
  114. {
  115. this.exit_wait_count_ = -1;
  116. this.hitret_sprite_.alpha = 0f;
  117. this.charaNameText = name;
  118. KeyValuePair<string, string> translationText = MessageClass.GetTranslationText(text);
  119. this.mainTextAnimation.StartAnimation(translationText.Key);
  120. this.subTextAnimation.StartAnimation(translationText.Value);
  121. this.message_mgr_.AddBackLog(name, this.mainTextAnimation.text, this.subTextAnimation.text, voice_file, voice_pitch);
  122. this.Update();
  123. }
  124. public void Clear()
  125. {
  126. this.exit_wait_count_ = -1;
  127. string text = string.Empty;
  128. this.charaNameText = text;
  129. text = text;
  130. this.messageText = text;
  131. this.subtitlesText = text;
  132. this.mainTextAnimation.Clear();
  133. this.subTextAnimation.Clear();
  134. this.hitret_sprite_.alpha = 0f;
  135. }
  136. public void FinishChAnime()
  137. {
  138. if (!this.ch_anime_enabled)
  139. {
  140. return;
  141. }
  142. this.messageText = this.mainTextAnimation.text;
  143. this.mainTextAnimation.Clear();
  144. this.subtitlesText = this.subTextAnimation.text;
  145. this.subTextAnimation.Clear();
  146. this.hitret_sprite_.alpha = 255f;
  147. this.exit_wait_count_ = GameMain.tick_count;
  148. }
  149. public void Update()
  150. {
  151. if (!this.ch_anime_enabled)
  152. {
  153. return;
  154. }
  155. KeyValuePair<bool, string> keyValuePair = this.mainTextAnimation.UodateAnimation();
  156. KeyValuePair<bool, string> keyValuePair2 = this.subTextAnimation.UodateAnimation();
  157. if (this.skip_mode || keyValuePair.Key)
  158. {
  159. this.FinishChAnime();
  160. }
  161. else
  162. {
  163. this.messageText = keyValuePair.Value;
  164. this.subtitlesText = (keyValuePair2.Key ? this.subTextAnimation.text : keyValuePair2.Value);
  165. }
  166. }
  167. public int GetExitWaitCount()
  168. {
  169. return (this.exit_wait_count_ >= 0) ? (GameMain.tick_count - this.exit_wait_count_) : this.exit_wait_count_;
  170. }
  171. public bool ch_anime_enabled
  172. {
  173. get
  174. {
  175. return this.mainTextAnimation.isPlay;
  176. }
  177. }
  178. private string messageText
  179. {
  180. set
  181. {
  182. if (this.message_label_ != null)
  183. {
  184. this.message_label_.text = value;
  185. }
  186. if (this.subtitles_manager_ != null)
  187. {
  188. this.subtitles_manager_.originalText = value;
  189. }
  190. }
  191. }
  192. private string subtitlesText
  193. {
  194. set
  195. {
  196. if (this.subtitles_manager_ != null)
  197. {
  198. this.subtitles_manager_.subtitlesText = value;
  199. }
  200. }
  201. }
  202. private string charaNameText
  203. {
  204. set
  205. {
  206. if (this.name_label_ != null)
  207. {
  208. this.name_label_.text = value;
  209. }
  210. if (this.subtitles_manager_ != null)
  211. {
  212. this.subtitles_manager_.charaNameText = value;
  213. }
  214. }
  215. }
  216. private bool skip_mode
  217. {
  218. get
  219. {
  220. return this.script_mgr_.adv_kag.skip_mode;
  221. }
  222. }
  223. public static readonly string kInsokuString = "。、・?!゛゜ヽヾゝゞ々ー)]}」』!),.:;?]}。」、・ー゚";
  224. private GameObject message_window_panel_;
  225. private readonly MessageWindowMgr message_mgr_;
  226. private readonly ScriptManager script_mgr_;
  227. private UISprite hitret_sprite_;
  228. private int exit_wait_count_;
  229. private MessageClass.TextAnimation mainTextAnimation;
  230. private MessageClass.TextAnimation subTextAnimation;
  231. private UILabel message_label_;
  232. private UILabel name_label_;
  233. public SubtitleDisplayManager subtitles_manager_;
  234. private class TextAnimation
  235. {
  236. private int ch_wait
  237. {
  238. get
  239. {
  240. if (this.text_info == null || this.text_info.LengthInTextElements == 0)
  241. {
  242. return 0;
  243. }
  244. return (100 - GameMain.Instance.CMSystem.MsgTextSpeed) * 20 / this.text_info.LengthInTextElements;
  245. }
  246. }
  247. public bool isPlay
  248. {
  249. get
  250. {
  251. return this.type != MessageClass.TextAnimation.Type.Null;
  252. }
  253. }
  254. public string text
  255. {
  256. get
  257. {
  258. return (this.text_info == null) ? string.Empty : this.text_info.String;
  259. }
  260. }
  261. public void StartAnimation(string text)
  262. {
  263. this.Clear();
  264. this.text_info = new StringInfo(text);
  265. this.type = MessageClass.TextAnimation.Type.Execution;
  266. this.start_time = GameMain.tick_count - this.ch_wait;
  267. }
  268. public KeyValuePair<bool, string> UodateAnimation()
  269. {
  270. if (this.type == MessageClass.TextAnimation.Type.Null || this.ch_wait <= 0)
  271. {
  272. return new KeyValuePair<bool, string>(true, null);
  273. }
  274. int num = Mathf.Max(0, Mathf.Min((GameMain.tick_count - this.start_time) / this.ch_wait, this.text_info.LengthInTextElements));
  275. if (num == this.text_info.LengthInTextElements)
  276. {
  277. return new KeyValuePair<bool, string>(true, null);
  278. }
  279. return new KeyValuePair<bool, string>(false, this.text_info.SubstringByTextElements(0, num));
  280. }
  281. public void Clear()
  282. {
  283. this.type = MessageClass.TextAnimation.Type.Null;
  284. this.start_time = 0;
  285. this.text_info = null;
  286. }
  287. private MessageClass.TextAnimation.Type type;
  288. private int start_time;
  289. private StringInfo text_info;
  290. private enum Type
  291. {
  292. Null,
  293. Execution
  294. }
  295. }
  296. }