StoryLookBackView.cs 7.2 KB

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