StoryLookBackView.cs 7.2 KB

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