StoryDialogView.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. using FairyGUI;
  2. using UnityEngine;
  3. using UI.Main;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Text.RegularExpressions;
  7. using System;
  8. namespace GFGGame
  9. {
  10. public delegate void OnCompleteStoryDialogCall(bool isSkip, object param);
  11. public class StoryDialogView : BaseView
  12. {
  13. private UI_StoryDialogUI _ui;
  14. private UI_CompArrow _arrow;
  15. private GameObject _sceneObject;
  16. private EffectUI _effectUI1;
  17. private DressUpObjUI _dressUpObjUI;
  18. private GTextField _wordTextField;
  19. //剧情完成回调
  20. private OnCompleteStoryDialogCall _onCompleteStoryDialogCall;
  21. private object _onCompleteStoryDialogCallParam;
  22. //回顾
  23. private List<string> _dialogListLookBack;
  24. //自动播放
  25. private int _speedAutoPlay = 1;
  26. private bool _autoPlay = false;
  27. //剧情状态
  28. private List<StoryDialogCfg> _stepListToRead;
  29. private StoryDialogCfg _currentStepCfg;
  30. private string _nextStepId;
  31. private string[] _wordList;
  32. private int _wordIndex = 0;
  33. private bool _isShowLetters;
  34. private bool _canClickBtnNext;
  35. private string _currentWords;
  36. private string _storyStartID;
  37. private string lastTextFieldType; // 上一段文本框的类型
  38. private bool IsTeaParty; //是否是茶话会里的对话
  39. TypingFadeEffectPro _typingEffect;
  40. //屏幕效果中
  41. private Action<object> _onScreenEffectComplete;
  42. public override void Dispose()
  43. {
  44. if (_sceneObject != null)
  45. {
  46. PrefabManager.Instance.Restore(_sceneObject);
  47. _sceneObject = null;
  48. }
  49. _dressUpObjUI?.Dispose();
  50. _dressUpObjUI = null;
  51. _wordTextField = null;
  52. _arrow = null;
  53. _isShowLetters = false;
  54. EffectUIPool.Recycle(_effectUI1);
  55. _effectUI1 = null;
  56. _onScreenEffectComplete = null;
  57. _typingEffect = null;
  58. if (_ui != null)
  59. {
  60. _ui.Dispose();
  61. _ui = null;
  62. }
  63. base.Dispose();
  64. }
  65. protected override void Init()
  66. {
  67. base.Init();
  68. packageName = UI_StoryDialogUI.PACKAGE_NAME;
  69. _ui = UI_StoryDialogUI.Create();
  70. viewCom = _ui.target;
  71. isfullScreen = true;
  72. }
  73. protected override void OnInit()
  74. {
  75. base.OnInit();
  76. _ui.m_dialogText.target.visible = false;
  77. _ui.m_dialogName.target.visible = false;
  78. _ui.m_dialogHead.target.visible = false;
  79. _ui.m_list.visible = false;
  80. _ui.m_btnNext.width = GRoot.inst.width;
  81. _ui.m_btnNext.height = GRoot.inst.height;
  82. _ui.m_btnNext.AddRelation(GRoot.inst, RelationType.Size);
  83. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  84. _ui.m_btnNext.onClick.Add(OnClickBtnNext);
  85. _ui.m_btnLookBack.onClick.Add(OnClickBtnLookBack);
  86. _ui.m_btnSkip.onClick.Add(OnBtnSkip);
  87. _ui.m_list.onClickItem.Add(OnClickListItem);
  88. _ui.m_btnSpeedUp.onClick.Add(OnClickBtnSpeedUp);
  89. _ui.m_btnAutoPlay.onClick.Add(OnClickBtnAutoPlay);
  90. }
  91. protected override void OnShown()
  92. {
  93. base.OnShown();
  94. if (_sceneObject == null)
  95. {
  96. _sceneObject = PrefabManager.Instance.InstantiateSync(ResPathUtil.GetPrefabPath("SceneStoryDialog"));
  97. }
  98. if (_dressUpObjUI == null)
  99. {
  100. _dressUpObjUI = new DressUpObjUI();
  101. }
  102. _speedAutoPlay = FightDataManager.Instance.dialogSpeed;
  103. lastTextFieldType = "";
  104. UpdateSpeedUpBtn();
  105. _dialogListLookBack = new List<string>();
  106. object[] datas = viewData as object[];
  107. _storyStartID = (string)datas[0];
  108. bool skipable = (bool)datas[1];
  109. _onCompleteStoryDialogCall = (OnCompleteStoryDialogCall)datas[2];
  110. if (datas.Length > 3)
  111. {
  112. _onCompleteStoryDialogCallParam = datas[3];
  113. }
  114. IsTeaParty = (bool)datas[4];
  115. _autoPlay = IsTeaParty;
  116. if (LauncherConfig.netType == LauncherConfig.EnumNetType.TEMP && !InstanceZonesDataManager.CheckLevelPass(MainStoryDataManager.currentLevelCfgId))
  117. {
  118. // 临时设置都可以跳过对话
  119. skipable = false;
  120. }
  121. else
  122. {
  123. skipable = true;
  124. }
  125. _ui.m_btnSkip.visible = skipable;
  126. ShowNextStep(_storyStartID);
  127. _ui.m_c1.selectedIndex = 0;
  128. _ui.m_btnAutoPlay.selected = false;
  129. if (_storyStartID == MainStoryDataManager.priorId)
  130. {
  131. _ui.m_c1.selectedIndex = 1;
  132. // _ui.m_btnAutoPlay.selected = true;
  133. OnClickBtnAutoPlay();
  134. _speedAutoPlay = 1;
  135. FightDataManager.Instance.dialogSpeed = _speedAutoPlay;
  136. }
  137. if (IsTeaParty) {
  138. _ui.m_c1.selectedIndex = 2;
  139. }
  140. _ui.m_btnBack.visible = InstanceZonesDataManager.CheckLevelPass(100001001);
  141. }
  142. protected override void OnHide()
  143. {
  144. base.OnHide();
  145. Timers.inst.Remove(UpdateShake);
  146. Timers.inst.Remove(OnScreenEffectComplete);
  147. Timers.inst.Remove(ShowNextWords);
  148. ScreenBlackController.Instance.HideBlack();
  149. StopAutoPlay();
  150. if (_sceneObject != null)
  151. {
  152. PrefabManager.Instance.Restore(_sceneObject);
  153. _sceneObject = null;
  154. }
  155. _dressUpObjUI.dressUpObj.TakeOffAll();
  156. MusicManager.Instance.PlayCroutine(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  157. _onCompleteStoryDialogCall = null;
  158. _onCompleteStoryDialogCallParam = null;
  159. StoryDialogDataManager.Instance.Clear();
  160. }
  161. private void OnClickBtnBack()
  162. {
  163. // this.Hide();
  164. ViewManager.GoBackFrom(typeof(StoryDialogView).FullName);
  165. // Over(false);
  166. }
  167. private void OnClickBtnNext()
  168. {
  169. if (!_canClickBtnNext || IsTeaParty)
  170. {
  171. return;
  172. }
  173. StopAutoPlay();
  174. if (_onScreenEffectComplete != null)
  175. {
  176. Timers.inst.Remove(OnScreenEffectComplete);
  177. _onScreenEffectComplete.Invoke(null);
  178. }
  179. else
  180. {
  181. ShowNextWords();
  182. }
  183. }
  184. private void OnClickBtnLookBack()
  185. {
  186. StopAutoPlay();
  187. if (_ui.m_btnSkip.enabled)
  188. {
  189. ViewManager.Show<StoryLookBackView>(_storyStartID);
  190. }
  191. else
  192. {
  193. ViewManager.Show<StoryLookBackView>(_dialogListLookBack);
  194. }
  195. }
  196. private void OnBtnSkip()
  197. {
  198. Over(true);
  199. }
  200. private void OnClickListItem(EventContext context)
  201. {
  202. UI_ListDialogItem dialogItem = UI_ListDialogItem.Proxy(context.data as GObject);
  203. _dialogListLookBack.Add(dialogItem.m_txtContent.text);
  204. string stepID = (string)dialogItem.target.data;
  205. if (stepID == null)
  206. {
  207. stepID = "0";
  208. }
  209. UI_ListDialogItem.ProxyEnd();
  210. OnStepComplete(stepID);
  211. }
  212. private void OnClickBtnSpeedUp()
  213. {
  214. //如果没有自动播放先开始自动播放
  215. if (!_autoPlay)
  216. {
  217. _ui.m_btnAutoPlay.selected = true;
  218. OnClickBtnAutoPlay();
  219. }
  220. _speedAutoPlay = _speedAutoPlay * 2;
  221. if (_speedAutoPlay > GameConst.MAX_SPEED_AUTO_PLAY)
  222. {
  223. _speedAutoPlay = 1;
  224. }
  225. FightDataManager.Instance.dialogSpeed = _speedAutoPlay;
  226. UpdateSpeedUpBtn();
  227. }
  228. private void OnClickBtnAutoPlay()
  229. {
  230. _autoPlay = _ui.m_btnAutoPlay.selected;
  231. if (_autoPlay)
  232. {
  233. ShowNextWords();
  234. }
  235. }
  236. private void InitStepListById(string dialogID)
  237. {
  238. var temp = StoryDialogCfgArray.Instance.GetCfgsByid(dialogID);
  239. _stepListToRead = new List<StoryDialogCfg>(temp);
  240. }
  241. private void ShowNextStep(string nextStepId)
  242. {
  243. if (nextStepId != null)
  244. {
  245. InitStepListById(nextStepId);
  246. }
  247. if (_stepListToRead != null && _stepListToRead.Count > 0)
  248. {
  249. StoryDialogCfg storyDialogCfg = (StoryDialogCfg)_stepListToRead[0];
  250. _stepListToRead.RemoveAt(0);
  251. Timers.inst.StartCoroutine(InitStepContent(storyDialogCfg));
  252. }
  253. else
  254. {
  255. Over();
  256. }
  257. }
  258. private void OnStepComplete(string nextStepId = null)
  259. {
  260. _nextStepId = nextStepId;
  261. _ui.m_dialogText.target.visible = false;
  262. _ui.m_dialogName.target.visible = false;
  263. _ui.m_dialogHead.target.visible = false;
  264. float delay = 0;
  265. //屏幕效果
  266. if (_currentStepCfg != null)
  267. {
  268. if (_currentStepCfg.blackScreenDur > 0)
  269. {
  270. delay = _currentStepCfg.blackScreenDur;
  271. ScreenBlackController.Instance.ShowBlack(delay, this.viewCom, 0);
  272. }
  273. else if (_currentStepCfg.blankScreenDur > 0)
  274. {
  275. delay = _currentStepCfg.blankScreenDur;
  276. UpdatePic("0");
  277. }
  278. }
  279. if (delay > 0)
  280. {
  281. //转换成秒
  282. delay = delay / 1000f;
  283. _onScreenEffectComplete = OnScreenEffectComplete;
  284. Timers.inst.Add(delay, 1, OnScreenEffectComplete);
  285. StoryDialogDataManager.Instance.dialogShowDelay = 0.6f;
  286. }
  287. else
  288. {
  289. OnScreenEffectComplete();
  290. }
  291. }
  292. private void OnScreenEffectComplete(object param = null)
  293. {
  294. _onScreenEffectComplete = null;
  295. if (_nextStepId == "0")
  296. {
  297. Over();
  298. }
  299. else
  300. {
  301. ShowNextStep(_nextStepId);
  302. }
  303. }
  304. private IEnumerator InitStepContent(StoryDialogCfg storyDialogCfg)
  305. {
  306. _canClickBtnNext = false;
  307. StoryDialogDataManager.Instance.waitPicFade = false;
  308. HideAllDialogUI();
  309. // Init resource
  310. _currentStepCfg = storyDialogCfg;
  311. UpdateMusic(storyDialogCfg.musicRes);
  312. UpdateBg(storyDialogCfg.bgRes);
  313. UpdatePic(storyDialogCfg.picRes);
  314. UpdateRoleObj(storyDialogCfg.name);
  315. PlayEffect(storyDialogCfg.effectInfoArr);
  316. PlayShake(storyDialogCfg.shakeInfoArr);
  317. string content = storyDialogCfg.content;
  318. content = storyDialogCfg.content.Replace("self", RoleDataManager.roleName);
  319. while (StoryDialogDataManager.Instance.waitBgChange)
  320. {
  321. yield return new WaitForEndOfFrame();
  322. }
  323. if(StoryDialogDataManager.Instance.dialogShowDelay > 0)
  324. {
  325. yield return new WaitForSeconds(StoryDialogDataManager.Instance.dialogShowDelay);
  326. StoryDialogDataManager.Instance.dialogShowDelay = 0f;
  327. }
  328. _canClickBtnNext = true;
  329. if (content.IndexOf("//") >= 0)
  330. {
  331. showList(content);
  332. }
  333. else
  334. {
  335. Timers.inst.StartCoroutine(ShowDialog(storyDialogCfg));
  336. }
  337. }
  338. private void showList(string content)
  339. {
  340. StopAutoPlay();
  341. _ui.m_btnAutoPlay.enabled = false;
  342. _wordTextField = null;
  343. _ui.m_list.visible = true;
  344. _ui.m_list.RemoveChildrenToPool();
  345. string[] list = Regex.Split(content, "//");
  346. _ui.m_list.itemRenderer = (int index, GObject item) =>
  347. {
  348. string itemInfo = list[index];
  349. string[] itemInfoList = Regex.Split(itemInfo, "=");
  350. UI_ListDialogItem dialogItem = UI_ListDialogItem.Proxy(item);
  351. dialogItem.m_txtContent.text = itemInfoList[0];
  352. dialogItem.target.data = itemInfoList.Length > 1 ? itemInfoList[1] : null;
  353. UI_ListDialogItem.ProxyEnd();
  354. };
  355. _ui.m_list.numItems = list.Length;
  356. }
  357. private void HideAllDialogUI()
  358. {
  359. _ui.m_dialogText.target.visible = false;
  360. _ui.m_dialogName.target.visible = false;
  361. _ui.m_dialogHead.target.visible = false;
  362. _ui.m_list.visible = false;
  363. }
  364. private IEnumerator ShowDialog(StoryDialogCfg storyDialogCfg)
  365. {
  366. if (storyDialogCfg.showChangeName == 1 && StorageDataManager.Instance.GetStorageValue(ConstStorageId.CHANGE_NAME) == 0)
  367. {
  368. GameController.ShowCreateRole();
  369. StoryDialogDataManager.Instance.waiting = true;
  370. while (StoryDialogDataManager.Instance.waiting)
  371. {
  372. yield return new WaitForEndOfFrame();
  373. }
  374. if (_autoPlay)
  375. {
  376. _ui.m_btnAutoPlay.selected = false;
  377. OnClickBtnAutoPlay();
  378. }
  379. }
  380. _ui.m_loaMask.url = ResPathUtil.GetBgImgPath(storyDialogCfg.maskRes);
  381. _ui.m_btnAutoPlay.enabled = true;
  382. _ui.m_list.visible = false;
  383. var content = storyDialogCfg.content.Replace("self", RoleDataManager.roleName);
  384. string words = content;
  385. string roleName = storyDialogCfg.name;
  386. string headRes = storyDialogCfg.head;
  387. string headAniRes = storyDialogCfg.headAni;
  388. if (roleName == "self")
  389. {
  390. roleName = RoleDataManager.roleName;
  391. }
  392. //回顾
  393. if (roleName != null)
  394. {
  395. _dialogListLookBack.Add("[color=#FDA2B1]" + roleName + "[/color]");
  396. }
  397. if (!string.IsNullOrEmpty(headAniRes) || storyDialogCfg.suitId > 0)
  398. {
  399. //显示对话框半身像
  400. _ui.m_dialogHead.target.visible = true;
  401. _ui.m_dialogHead.m_txtName.text = roleName;
  402. _ui.m_dialogHead.m_comphead.m_head.visible = false;
  403. _ui.m_dialogHead.m_comphead.m_holder.visible = true;
  404. var headAniCfg = HeadAniCfgArray.Instance.GetCfg(headAniRes);
  405. if (headAniCfg != null && !string.IsNullOrEmpty(headAniCfg.headAni))
  406. {
  407. //独立动画
  408. _ui.m_dialogHead.m_compDressUp.target.visible = false;
  409. _ui.m_dialogHead.m_comphead.target.visible = true;
  410. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_dialogHead.m_comphead.m_holder, "ui_nzbq", headAniCfg.headAni);
  411. }
  412. else
  413. {
  414. //换装
  415. _ui.m_dialogHead.m_compDressUp.target.visible = true;
  416. _ui.m_dialogHead.m_comphead.target.visible = false;
  417. _dressUpObjUI.ResetSceneObj(80, true, false, null, false);
  418. if (storyDialogCfg.suitId > 0)
  419. {
  420. _dressUpObjUI.dressUpObj.PutOnSuitCfg(storyDialogCfg.suitId, false, new int[] { ConstDressUpItemType.SHOU_CHI_WU }, false, false);
  421. }
  422. else
  423. {
  424. _dressUpObjUI.dressUpObj.PutOnDressUpData(CustomSuitDataManager.GetCurrentSuitData().dressUpData, new int[] { ConstDressUpItemType.SHOU_CHI_WU });
  425. if (_dressUpObjUI.dressUpObj.actionId > 0)
  426. {
  427. _dressUpObjUI.dressUpObj.CancelAction(true);
  428. }
  429. //_dressUpObjUI.dressUpObj.PutOnDressUpData(_dressUpObjUI.dressUpObj.DressUpDataClone(), new int[] { ConstDressUpItemType.SHOU_CHI_WU });
  430. }
  431. if (headAniCfg != null && headAniCfg.faceId > 0)
  432. {
  433. //表情
  434. _dressUpObjUI.dressUpObj.AddOrRemove(headAniCfg.faceId, true);
  435. _dressUpObjUI.UpdateWrapper(_ui.m_dialogHead.m_compDressUp.m_holder);
  436. }
  437. }
  438. _wordTextField = _ui.m_dialogHead.m_txtContent;
  439. _arrow = _ui.m_dialogHead.m_iconNext;
  440. lastTextFieldType = "head";
  441. }
  442. else if (!string.IsNullOrEmpty(headRes))
  443. {
  444. _ui.m_dialogHead.target.visible = true;
  445. _ui.m_dialogHead.m_txtName.text = roleName;
  446. _ui.m_dialogHead.m_comphead.m_head.visible = true;
  447. _ui.m_dialogHead.m_comphead.m_holder.visible = false;
  448. _ui.m_dialogHead.m_comphead.m_head.url = ResPathUtil.GetNpcHeadPath(headRes);
  449. _wordTextField = _ui.m_dialogHead.m_txtContent;
  450. _arrow = _ui.m_dialogHead.m_iconNext;
  451. lastTextFieldType = "head";
  452. }
  453. else if (!string.IsNullOrEmpty(roleName))
  454. {
  455. _ui.m_dialogName.target.visible = true;
  456. if (IsTeaParty)
  457. {
  458. var roleContainerList = LeagueDataManager.Instance.RoleContainerList;
  459. var teapartyRoleCfg = TeapartyRoleCfgArray.Instance.GetCfgsByid(LeagueDataManager.Instance.TeaPartyId);
  460. int roleIndex = Convert.ToInt32(roleName);
  461. _ui.m_dialogName.m_txtName.text = teapartyRoleCfg[roleIndex - 1].name;
  462. _ui.m_dialogName.m_bgType.selectedIndex = 1;
  463. _ui.m_dialogName.m_showArrow.selectedIndex = 1;
  464. if (roleIndex <= roleContainerList.Count && roleContainerList[roleIndex - 1].MaxScoreRoleName != null && roleContainerList[roleIndex - 1].MaxScoreRoleName != "" && _ui.m_dialogName.m_txtName.text != "")
  465. {
  466. _ui.m_comPlayName.visible = true;
  467. _ui.m_txtPlayName.text = roleContainerList[roleIndex - 1].MaxScoreRoleName;
  468. if (_ui.m_txtPlayName.text == RoleDataManager.roleName)
  469. _ui.m_dialogName.m_bgType.selectedIndex = 0;
  470. }
  471. else
  472. _ui.m_comPlayName.visible = false;
  473. }
  474. else {
  475. _ui.m_dialogName.m_bgType.selectedIndex = 0;
  476. _ui.m_dialogName.m_showArrow.selectedIndex = 0;
  477. _ui.m_dialogName.m_txtName.text = roleName;
  478. }
  479. _wordTextField = _ui.m_dialogName.m_txtContent;
  480. _arrow = _ui.m_dialogName.m_iconNext;
  481. if (!lastTextFieldType.Equals("name"))
  482. {
  483. lastTextFieldType = "name";
  484. StoryDialogDataManager.Instance.waiting = true;
  485. _ui.m_t0.Play(()=>
  486. {
  487. StoryDialogDataManager.Instance.waiting = false;
  488. });
  489. }
  490. }
  491. else
  492. {
  493. if (IsTeaParty)
  494. _ui.m_dialogText.m_showArrow.selectedIndex = 1;
  495. else
  496. _ui.m_dialogText.m_showArrow.selectedIndex = 0;
  497. _ui.m_dialogText.target.visible = true;
  498. _wordTextField = _ui.m_dialogText.m_txtContent;
  499. _arrow = _ui.m_dialogText.m_iconNext;
  500. lastTextFieldType = "text";
  501. _ui.m_comPlayName.visible = false;
  502. }
  503. _wordList = Regex.Split(words, "&&");
  504. _wordIndex = 0;
  505. _typingEffect = new TypingFadeEffectPro(_wordTextField);
  506. _typingEffect.typeFinishedAction = ShowCurrentWords;
  507. ShowNextDialog();
  508. }
  509. private void ShowNextDialog()
  510. {
  511. if (_wordList != null && _wordList.Length > _wordIndex)
  512. {
  513. string itemInfo = _wordList[_wordIndex];
  514. string[] itemInfoList = Regex.Split(itemInfo, "=");
  515. _currentWords = itemInfoList[0];
  516. if (itemInfoList.Length > 1)
  517. {
  518. _wordTextField.data = itemInfoList[1];
  519. }
  520. else
  521. {
  522. _wordTextField.data = null;
  523. }
  524. Timers.inst.StartCoroutine(StartShowLetters());
  525. }
  526. else
  527. {
  528. OnStepComplete();
  529. }
  530. }
  531. private void ShowCurrentWords()
  532. {
  533. _arrow.target.visible = true;
  534. //Timers.inst.Remove(UpdateLetters);
  535. StopTyping();
  536. _typingEffect?.Cancel();
  537. _wordTextField.text = _currentWords;
  538. _dialogListLookBack.Add(_currentWords);
  539. _isShowLetters = false;
  540. _wordIndex++;
  541. if (_autoPlay)
  542. {
  543. Timers.inst.Add(GameConst.NEXT_WORDS_INTERVAL_MAX / _speedAutoPlay, 1, ShowNextWords);
  544. }
  545. }
  546. private void ShowNextWords(object param = null)
  547. {
  548. if (_wordTextField != null)
  549. {
  550. if (_isShowLetters)
  551. {
  552. ShowCurrentWords();
  553. }
  554. else
  555. {
  556. string stepID = (string)_wordTextField.data;
  557. if (stepID != null)
  558. {
  559. OnStepComplete(stepID);
  560. }
  561. else
  562. {
  563. ShowNextDialog();
  564. }
  565. }
  566. }
  567. }
  568. private IEnumerator StartShowLetters()
  569. {
  570. _isShowLetters = true;
  571. _arrow.target.visible = false;
  572. _wordTextField.verticalAlign = VertAlignType.Top;
  573. _wordTextField.text = "";
  574. ArrayList letters = StoryUtil.GetLettersList(_currentWords);
  575. _canClickBtnNext = false;
  576. while (StoryDialogDataManager.Instance.waitPicFade || StoryDialogDataManager.Instance.waiting)
  577. {
  578. yield return new WaitForEndOfFrame();
  579. }
  580. _canClickBtnNext = true;
  581. _wordTextField.text = _currentWords;
  582. StartTyping();
  583. }
  584. private void StartTyping()
  585. {
  586. _typingEffect.SetSpeed(_speedAutoPlay);
  587. _typingEffect.Start();
  588. }
  589. private void StopTyping()
  590. {
  591. _typingEffect.Cancel();
  592. }
  593. private void UpdateBg(string value)
  594. {
  595. if (value.Length > 0)
  596. {
  597. SceneController.UpdateDialogBg(value, _sceneObject);
  598. }
  599. }
  600. private void UpdatePic(string value)
  601. {
  602. if(value.Length > 0 && !IsTeaParty)
  603. {
  604. SceneController.UpdateDialogPic(value, _sceneObject);
  605. }
  606. }
  607. private void UpdateRoleObj(string value)
  608. {
  609. if (IsTeaParty)
  610. {
  611. var roleContainerList = LeagueDataManager.Instance.RoleContainerList;
  612. MyDressUpHelper.dressUpObj.setSceneObj(_sceneObject, false, false);
  613. for (int i = 0; i < roleContainerList.Count; i++)
  614. {
  615. if (value == (i + 1).ToString() && roleContainerList[i].EquipIds.Count > 0)
  616. {
  617. MyDressUpHelper.dressUpObj.PutOnItemList(roleContainerList[i].EquipIds);
  618. return;
  619. }
  620. }
  621. MyDressUpHelper.dressUpObj.PutOnDefaultDressUpData(IsTeaParty);
  622. }
  623. }
  624. private void UpdateMusic(string value)
  625. {
  626. if (value.Length > 0)
  627. {
  628. if (value == "0")
  629. {
  630. MusicManager.Instance.Stop();
  631. }
  632. else
  633. {
  634. MusicManager.Instance.PlayCroutine(ResPathUtil.GetMusicPath(value, "mp3"));
  635. }
  636. }
  637. }
  638. private void PlayEffect(string[] infos)
  639. {
  640. }
  641. private void PlayShake(int[] shakeInfoArr)
  642. {
  643. if (shakeInfoArr != null && shakeInfoArr.Length > 0)
  644. {
  645. Vector3 position = _sceneObject.transform.position;
  646. position.x = (float)shakeInfoArr[0] / GameConst.PIXELS_PER_UNITY_UNIT;
  647. position.y = (float)shakeInfoArr[1] / GameConst.PIXELS_PER_UNITY_UNIT;
  648. _sceneObject.transform.position = position;
  649. float attenuationX = (float)shakeInfoArr[2] / GameConst.PIXELS_PER_UNITY_UNIT;
  650. float attenuationY = (float)shakeInfoArr[3] / GameConst.PIXELS_PER_UNITY_UNIT;
  651. float interval = (float)shakeInfoArr[4] / 1000;
  652. float duration = (float)shakeInfoArr[5] / 1000;
  653. int repeat = Mathf.RoundToInt(duration / interval);
  654. Timers.inst.Add(interval, 0, UpdateShake, new float[] { attenuationX, attenuationY });
  655. }
  656. }
  657. private void UpdateShake(object param)
  658. {
  659. float[] attenuations = param as float[];
  660. float attenuationX = attenuations[0];
  661. float attenuationY = attenuations[1];
  662. Vector3 position = _sceneObject.transform.position;
  663. bool done = false;
  664. bool doneX = false;
  665. float absX = Mathf.Abs(position.x);
  666. if (absX > attenuationX)
  667. {
  668. int dir = (int)(position.x / absX);
  669. position.x = Mathf.Abs(position.x) - attenuationX;
  670. position.x *= -1 * dir;
  671. }
  672. else
  673. {
  674. doneX = true;
  675. position.x = 0;
  676. }
  677. bool doneY = false;
  678. float absY = Mathf.Abs(position.y);
  679. if (absY > attenuationY)
  680. {
  681. int dir = (int)(position.y / absY);
  682. position.y = Mathf.Abs(position.y) - attenuationY;
  683. position.y *= -1 * dir;
  684. }
  685. else
  686. {
  687. doneY = true;
  688. position.y = 0;
  689. }
  690. done = doneX && doneY;
  691. _sceneObject.transform.position = position;
  692. if (done)
  693. {
  694. Timers.inst.Remove(UpdateShake);
  695. }
  696. }
  697. private void Over(bool isSkip = false)
  698. {
  699. if (_onCompleteStoryDialogCall != null)
  700. {
  701. _onCompleteStoryDialogCall(isSkip, _onCompleteStoryDialogCallParam);
  702. }
  703. }
  704. private void UpdateSpeedUpBtn()
  705. {
  706. if (_speedAutoPlay > 1)
  707. {
  708. _ui.m_btnSpeedUp.text = "x" + _speedAutoPlay;
  709. }
  710. else
  711. {
  712. _ui.m_btnSpeedUp.text = "";
  713. }
  714. _typingEffect?.SetSpeed(_speedAutoPlay);
  715. }
  716. private void StopAutoPlay()
  717. {
  718. _autoPlay = false;
  719. _ui.m_btnAutoPlay.selected = false;
  720. Timers.inst.Remove(ShowNextWords);
  721. }
  722. }
  723. }