StoryLookBackView.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. if (this.viewData is string)
  42. {
  43. string stroyStartID = (string)this.viewData;
  44. _dialogListLookBack = new List<string>();
  45. ShowNextStep(stroyStartID);
  46. }
  47. else
  48. {
  49. _dialogListLookBack = (List<string>)this.viewData;
  50. }
  51. if (_dialogListLookBack != null)
  52. {
  53. string content = "";
  54. foreach (string words in _dialogListLookBack)
  55. {
  56. content += words + "\n";
  57. }
  58. _ui.m_content.m_txtContent.text = content;
  59. _ui.m_content.m_txtContent.height = _ui.m_content.m_txtContent.textHeight;
  60. }
  61. }
  62. protected override void OnHide()
  63. {
  64. base.OnHide();
  65. }
  66. private void InitStepListById(string dialogID)
  67. {
  68. var temp = StoryDialogCfgArray.Instance.GetCfgs(dialogID);
  69. _stepListToRead = new List<StoryDialogCfg>(temp);
  70. }
  71. private void ShowNextStep(string nextStepId)
  72. {
  73. if (nextStepId != null)
  74. {
  75. InitStepListById(nextStepId);
  76. }
  77. if (_stepListToRead != null && _stepListToRead.Count > 0)
  78. {
  79. StoryDialogCfg storyDialogCfg = (StoryDialogCfg)_stepListToRead[0];
  80. _stepListToRead.RemoveAt(0);
  81. InitStepContent(storyDialogCfg);
  82. }
  83. else
  84. {
  85. }
  86. }
  87. private void InitStepContent(StoryDialogCfg storyDialogCfg)
  88. {
  89. string content = storyDialogCfg.content;
  90. content = storyDialogCfg.content.Replace("self", RoleDataManager.roleName);
  91. if (content.IndexOf("//") >= 0)
  92. {
  93. showList(content);
  94. }
  95. else
  96. {
  97. ShowDialog(storyDialogCfg);
  98. }
  99. }
  100. private void showList(string content)
  101. {
  102. _currentData = null;
  103. string[] list = Regex.Split(content, "//");
  104. string itemInfo = list[0];
  105. string[] itemInfoList = Regex.Split(itemInfo, "=");
  106. _dialogListLookBack.Add(itemInfoList[0]);
  107. string stepID = itemInfoList.Length > 1 ? itemInfoList[1] : null;
  108. if (stepID == null)
  109. {
  110. stepID = "0";
  111. }
  112. OnStepComplete(stepID);
  113. }
  114. private void OnStepComplete(string nextStepId = null)
  115. {
  116. _nextStepId = nextStepId;
  117. OnScreenEffectComplete();
  118. }
  119. private void OnScreenEffectComplete(object param = null)
  120. {
  121. if (_nextStepId == "0")
  122. {
  123. Over();
  124. }
  125. else
  126. {
  127. ShowNextStep(_nextStepId);
  128. }
  129. }
  130. private void ShowDialog(StoryDialogCfg storyDialogCfg)
  131. {
  132. var content = storyDialogCfg.content.Replace("self", RoleDataManager.roleName);
  133. string words = content;
  134. string roleName = storyDialogCfg.name;
  135. if (roleName == "self")
  136. {
  137. roleName = RoleDataManager.roleName;
  138. }
  139. //»Ø¹Ë
  140. if (!string.IsNullOrEmpty(roleName))
  141. {
  142. _dialogListLookBack.Add("[color=#FDA2B1]" + roleName + "[/color]");
  143. }
  144. _wordList = Regex.Split(words, "&&");
  145. _wordIndex = 0;
  146. ShowNextDialog();
  147. }
  148. private void ShowNextDialog()
  149. {
  150. if (_wordList != null && _wordList.Length > _wordIndex)
  151. {
  152. string itemInfo = _wordList[_wordIndex];
  153. string[] itemInfoList = Regex.Split(itemInfo, "=");
  154. _currentWords = itemInfoList[0];
  155. if (itemInfoList.Length > 1)
  156. {
  157. _currentData = itemInfoList[1];
  158. }
  159. else
  160. {
  161. _currentData = null;
  162. }
  163. ShowCurrentWords();
  164. }
  165. else
  166. {
  167. OnStepComplete();
  168. }
  169. }
  170. private void ShowCurrentWords()
  171. {
  172. _dialogListLookBack.Add(_currentWords);
  173. _wordIndex++;
  174. ShowNextWords(null);
  175. }
  176. private void ShowNextWords(object param = null)
  177. {
  178. string stepID = _currentData;
  179. if (stepID != null)
  180. {
  181. OnStepComplete(stepID);
  182. }
  183. else
  184. {
  185. ShowNextDialog();
  186. }
  187. }
  188. private void UpdateBg(string value)
  189. {
  190. if (value.Length > 0)
  191. {
  192. }
  193. }
  194. private void UpdatePic(string value)
  195. {
  196. if (value.Length > 0)
  197. {
  198. }
  199. }
  200. private void UpdateMusic(string value)
  201. {
  202. if (value.Length > 0)
  203. {
  204. if (value == "0")
  205. {
  206. MusicManager.Instance.Stop();
  207. }
  208. else
  209. {
  210. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(value, "mp3"));
  211. }
  212. }
  213. }
  214. private void PlayEffect(string[] infos)
  215. {
  216. }
  217. private void PlayShake(int[] shakeInfoArr)
  218. {
  219. if (shakeInfoArr != null && shakeInfoArr.Length > 0)
  220. {
  221. }
  222. }
  223. private void Over(bool isSkip = false)
  224. {
  225. }
  226. }
  227. }