MessageClass.cs 8.5 KB

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