StoryLookBackView.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. using UI.Main;
  2. using System.Text.RegularExpressions;
  3. using System.Collections.Generic;
  4. namespace GFGGame
  5. {
  6. public class StoryLookBackView : BaseWindow
  7. {
  8. private UI_StoryLookBackUI _ui;
  9. private List<StoryDialogCfg> _stepListToRead;
  10. private List<string> _dialogListLookBack;
  11. private StoryDialogCfg _currentStepCfg;
  12. private string _nextStepId;
  13. private string[] _wordList;
  14. private int _wordIndex = 0;
  15. private bool _isShowLetters;
  16. private string _currentWords;
  17. private string _currentData;
  18. public override void Dispose()
  19. {
  20. if (_ui != null)
  21. {
  22. _ui.Dispose();
  23. _ui = null;
  24. }
  25. base.Dispose();
  26. }
  27. protected override void OnInit()
  28. {
  29. base.OnInit();
  30. _ui = UI_StoryLookBackUI.Create();
  31. this.viewCom = _ui.target;
  32. this.isfullScreen = true;
  33. this.modal = true;
  34. this.clickBlankToClose = false;
  35. _ui.m_btnBack.onClick.Add(this.Hide);
  36. }
  37. protected override void OnShown()
  38. {
  39. base.OnShown();
  40. _ui.m_content.m_txtContent.text = "";
  41. bool needScrollBottom = false;
  42. if (this.viewData is string)
  43. {
  44. string storyStartID = (string)this.viewData;
  45. _dialogListLookBack = new List<string>();
  46. ShowNextStep(storyStartID);
  47. }
  48. else
  49. {
  50. _dialogListLookBack = (List<string>)this.viewData;
  51. needScrollBottom = true;
  52. }
  53. if (_dialogListLookBack != null)
  54. {
  55. string content = "";
  56. foreach (string words in _dialogListLookBack)
  57. {
  58. content += words + "\n";
  59. }
  60. _ui.m_content.m_txtContent.text = content;
  61. _ui.m_content.m_txtContent.height = _ui.m_content.m_txtContent.textHeight;
  62. }
  63. if (needScrollBottom)
  64. {
  65. _ui.m_content.target.scrollPane.ScrollBottom();
  66. }
  67. else
  68. {
  69. _ui.m_content.target.scrollPane.ScrollTop();
  70. }
  71. }
  72. protected override void OnHide()
  73. {
  74. base.OnHide();
  75. }
  76. private void InitStepListById(string dialogID)
  77. {
  78. var temp = StoryDialogCfgArray.Instance.GetCfgsByid(dialogID);
  79. _stepListToRead = new List<StoryDialogCfg>(temp);
  80. }
  81. private void ShowNextStep(string nextStepId)
  82. {
  83. if (nextStepId != null)
  84. {
  85. InitStepListById(nextStepId);
  86. }
  87. if (_stepListToRead != null && _stepListToRead.Count > 0)
  88. {
  89. StoryDialogCfg storyDialogCfg = (StoryDialogCfg)_stepListToRead[0];
  90. _stepListToRead.RemoveAt(0);
  91. InitStepContent(storyDialogCfg);
  92. }
  93. else
  94. {
  95. }
  96. }
  97. private void InitStepContent(StoryDialogCfg storyDialogCfg)
  98. {
  99. string content = storyDialogCfg.content;
  100. content = storyDialogCfg.content.Replace("self", RoleDataManager.roleName);
  101. if (content.IndexOf("//") >= 0)
  102. {
  103. showList(content);
  104. }
  105. else
  106. {
  107. ShowDialog(storyDialogCfg);
  108. }
  109. }
  110. private void showList(string content)
  111. {
  112. _currentData = null;
  113. string[] list = Regex.Split(content, "//");
  114. string itemInfo = list[0];
  115. string[] itemInfoList = Regex.Split(itemInfo, "=");
  116. _dialogListLookBack.Add(itemInfoList[0]);
  117. string stepID = itemInfoList.Length > 1 ? itemInfoList[1] : null;
  118. if (stepID == null)
  119. {
  120. stepID = "0";
  121. }
  122. OnStepComplete(stepID);
  123. }
  124. private void OnStepComplete(string nextStepId = null)
  125. {
  126. _nextStepId = nextStepId;
  127. OnScreenEffectComplete();
  128. }
  129. private void OnScreenEffectComplete(object param = null)
  130. {
  131. if (_nextStepId == "0")
  132. {
  133. Over();
  134. }
  135. else
  136. {
  137. ShowNextStep(_nextStepId);
  138. }
  139. }
  140. private void ShowDialog(StoryDialogCfg storyDialogCfg)
  141. {
  142. var content = storyDialogCfg.content.Replace("self", RoleDataManager.roleName);
  143. string words = content;
  144. string roleName = storyDialogCfg.name;
  145. if (roleName == "self")
  146. {
  147. roleName = RoleDataManager.roleName;
  148. }
  149. //»Ø¹Ë
  150. if (!string.IsNullOrEmpty(roleName))
  151. {
  152. _dialogListLookBack.Add("[color=#FDA2B1]" + roleName + "[/color]");
  153. }
  154. _wordList = Regex.Split(words, "&&");
  155. _wordIndex = 0;
  156. ShowNextDialog();
  157. }
  158. private void ShowNextDialog()
  159. {
  160. if (_wordList != null && _wordList.Length > _wordIndex)
  161. {
  162. string itemInfo = _wordList[_wordIndex];
  163. string[] itemInfoList = Regex.Split(itemInfo, "=");
  164. _currentWords = itemInfoList[0];
  165. if (itemInfoList.Length > 1)
  166. {
  167. _currentData = itemInfoList[1];
  168. }
  169. else
  170. {
  171. _currentData = null;
  172. }
  173. ShowCurrentWords();
  174. }
  175. else
  176. {
  177. OnStepComplete();
  178. }
  179. }
  180. private void ShowCurrentWords()
  181. {
  182. _dialogListLookBack.Add(_currentWords);
  183. _wordIndex++;
  184. ShowNextWords(null);
  185. }
  186. private void ShowNextWords(object param = null)
  187. {
  188. string stepID = _currentData;
  189. if (stepID != null)
  190. {
  191. OnStepComplete(stepID);
  192. }
  193. else
  194. {
  195. ShowNextDialog();
  196. }
  197. }
  198. private void UpdateBg(string value)
  199. {
  200. if (value.Length > 0)
  201. {
  202. }
  203. }
  204. private void UpdatePic(string value)
  205. {
  206. if (value.Length > 0)
  207. {
  208. }
  209. }
  210. private void UpdateMusic(string value)
  211. {
  212. if (value.Length > 0)
  213. {
  214. if (value == "0")
  215. {
  216. MusicManager.Instance.Stop();
  217. }
  218. else
  219. {
  220. MusicManager.Instance.PlayCroutine(ResPathUtil.GetMusicPath(value, "mp3"));
  221. }
  222. }
  223. }
  224. private void PlayEffect(string[] infos)
  225. {
  226. }
  227. private void PlayShake(int[] shakeInfoArr)
  228. {
  229. if (shakeInfoArr != null && shakeInfoArr.Length > 0)
  230. {
  231. }
  232. }
  233. private void Over(bool isSkip = false)
  234. {
  235. }
  236. }
  237. }