StoryLookBackView.cs 6.7 KB

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