StoryLookBackView.cs 6.5 KB

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