MessageClass.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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.hitret_sprite_ = UTY.GetChildObject(this.message_window_panel_, "MessageViewer/MsgParent/Hitret", false).GetComponent<UISprite>();
  16. NDebug.AssertNull(this.message_label_ != null && this.name_label_ != null && this.hitret_sprite_ != null);
  17. this.message_label_.ProcessText();
  18. this.hitret_sprite_.alpha = 0f;
  19. }
  20. public static KeyValuePair<string, string> GetTranslationText(string baseText)
  21. {
  22. if (string.IsNullOrEmpty(baseText))
  23. {
  24. return new KeyValuePair<string, string>(string.Empty, string.Empty);
  25. }
  26. int num = baseText.IndexOf("<E>");
  27. if (num < 0)
  28. {
  29. num = baseText.IndexOf("<e>");
  30. if (num < 0)
  31. {
  32. return new KeyValuePair<string, string>(baseText, string.Empty);
  33. }
  34. }
  35. return new KeyValuePair<string, string>(baseText.Substring(0, num), baseText.Substring(num + 3, baseText.Length - (num + 3)));
  36. }
  37. public static string GetWrapString(UILabel draw_target, string text)
  38. {
  39. string text2 = string.Empty;
  40. draw_target.Wrap(text, out text2);
  41. if (text2.IndexOf('\n') == -1)
  42. {
  43. return text2;
  44. }
  45. string a = text2;
  46. string[] collection = text2.Split(new char[]
  47. {
  48. '\n'
  49. });
  50. List<string> list = new List<string>();
  51. list.AddRange(collection);
  52. text2 = string.Empty;
  53. for (int i = 0; i < list.Count - 1; i++)
  54. {
  55. string text3 = list[i];
  56. string text4 = list[i + 1];
  57. StringInfo stringInfo = new StringInfo(text3);
  58. int lengthInTextElements = stringInfo.LengthInTextElements;
  59. StringInfo stringInfo2 = new StringInfo(text4);
  60. int lengthInTextElements2 = stringInfo2.LengthInTextElements;
  61. while (0 < lengthInTextElements2 && 0 < lengthInTextElements)
  62. {
  63. string value = stringInfo2.SubstringByTextElements(0, 1);
  64. if (0 > MessageClass.kInsokuString.IndexOf(value))
  65. {
  66. break;
  67. }
  68. text4 = stringInfo.SubstringByTextElements(lengthInTextElements - 1, 1) + text4;
  69. text3 = stringInfo.SubstringByTextElements(0, lengthInTextElements - 1);
  70. stringInfo = new StringInfo(text3);
  71. lengthInTextElements = stringInfo.LengthInTextElements;
  72. stringInfo2 = new StringInfo(text4);
  73. lengthInTextElements2 = stringInfo2.LengthInTextElements;
  74. }
  75. text2 = text2 + text3 + '\n';
  76. list[i] = string.Empty;
  77. list[i + 1] = text4;
  78. string text5 = string.Empty;
  79. foreach (string text6 in list)
  80. {
  81. if (!(text6 == string.Empty) && !(text6 == "\n"))
  82. {
  83. text5 += text6;
  84. }
  85. }
  86. string empty = string.Empty;
  87. draw_target.Wrap(text5, out empty);
  88. text5 = empty;
  89. list.Clear();
  90. list.AddRange(text5.Split(new char[]
  91. {
  92. '\n'
  93. }));
  94. i = -1;
  95. if (a == text5)
  96. {
  97. break;
  98. }
  99. a = text5;
  100. }
  101. if (1 <= list.Count)
  102. {
  103. text2 += list[list.Count - 1];
  104. }
  105. return text2;
  106. }
  107. public void SetText(string name, string text, string voice_file, int voice_pitch)
  108. {
  109. this.exit_wait_count_ = -1;
  110. this.name_label_.text = name;
  111. this.ch_anime_data_.Clear();
  112. this.ch_anime_data_.text_info = new StringInfo(MessageClass.GetWrapString(this.message_label_, text));
  113. this.ch_anime_data_.type = MessageClass.ChAnimeData.Type.Execution;
  114. this.ch_anime_data_.start_time = GameMain.tick_count;
  115. this.ch_anime_data_.start_time = this.ch_anime_data_.start_time - this.ch_wait;
  116. this.hitret_sprite_.alpha = 0f;
  117. this.message_mgr_.AddBackLog(name, this.ch_anime_data_.text_info.String, voice_file, voice_pitch);
  118. this.Update();
  119. }
  120. public void Clear()
  121. {
  122. this.exit_wait_count_ = -1;
  123. UILabel uilabel = this.message_label_;
  124. string empty = string.Empty;
  125. this.name_label_.text = empty;
  126. uilabel.text = empty;
  127. this.ch_anime_data_.Clear();
  128. this.hitret_sprite_.alpha = 0f;
  129. }
  130. public void FinishChAnime()
  131. {
  132. if (this.ch_anime_data_.type == MessageClass.ChAnimeData.Type.Null)
  133. {
  134. return;
  135. }
  136. this.message_label_.text = this.ch_anime_data_.text_info.String;
  137. this.ch_anime_data_.Clear();
  138. this.hitret_sprite_.alpha = 255f;
  139. this.exit_wait_count_ = GameMain.tick_count;
  140. }
  141. public void Update()
  142. {
  143. if (this.ch_anime_data_.type == MessageClass.ChAnimeData.Type.Null)
  144. {
  145. return;
  146. }
  147. if (this.skip_mode || this.ch_wait <= 0)
  148. {
  149. this.FinishChAnime();
  150. return;
  151. }
  152. int num = Mathf.Max(0, Mathf.Min((GameMain.tick_count - this.ch_anime_data_.start_time) / this.ch_wait, this.ch_anime_data_.text_info.LengthInTextElements));
  153. if (num == this.ch_anime_data_.text_info.LengthInTextElements)
  154. {
  155. this.FinishChAnime();
  156. }
  157. else
  158. {
  159. this.message_label_.text = this.ch_anime_data_.text_info.SubstringByTextElements(0, num);
  160. }
  161. }
  162. public int GetExitWaitCount()
  163. {
  164. return (this.exit_wait_count_ >= 0) ? (GameMain.tick_count - this.exit_wait_count_) : this.exit_wait_count_;
  165. }
  166. public bool ch_anime_enabled
  167. {
  168. get
  169. {
  170. return this.ch_anime_data_.type == MessageClass.ChAnimeData.Type.Execution;
  171. }
  172. }
  173. private int ch_wait
  174. {
  175. get
  176. {
  177. return (int)((100f - (float)GameMain.Instance.CMSystem.MsgTextSpeed) * 1.5f);
  178. }
  179. }
  180. private bool skip_mode
  181. {
  182. get
  183. {
  184. return this.script_mgr_.adv_kag.skip_mode;
  185. }
  186. }
  187. public static readonly string kInsokuString = "。、・?!゛゜ヽヾゝゞ々ー)]}」』!),.:;?]}。」、・ー゚";
  188. private GameObject message_window_panel_;
  189. private readonly MessageWindowMgr message_mgr_;
  190. private readonly ScriptManager script_mgr_;
  191. private UILabel message_label_;
  192. private UILabel name_label_;
  193. private UISprite hitret_sprite_;
  194. private MessageClass.ChAnimeData ch_anime_data_;
  195. private int exit_wait_count_;
  196. private struct ChAnimeData
  197. {
  198. public void Clear()
  199. {
  200. this.type = MessageClass.ChAnimeData.Type.Null;
  201. this.start_time = (this.cur_pos = 0);
  202. this.text_info = null;
  203. }
  204. public MessageClass.ChAnimeData.Type type;
  205. public int start_time;
  206. public StringInfo text_info;
  207. public int cur_pos;
  208. public enum Type
  209. {
  210. Null,
  211. Execution
  212. }
  213. }
  214. }