MessageClass.cs 5.8 KB

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