MessageClass.cs 9.7 KB

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