DialogueBubblePanel.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. using System;
  2. using System.Text;
  3. using Common.Utility.CombatEvent;
  4. using Core.Language;
  5. using Excel2Json;
  6. using Fort23.Core;
  7. using Fort23.UTool;
  8. using GameLogic.Combat;
  9. using UnityEngine;
  10. namespace Fort23.Mono
  11. {
  12. [UIBinding(prefab = "DialogueBubblePanel")]
  13. public partial class DialogueBubblePanel : UIPanel
  14. {
  15. private int[] dialogueMessaga;
  16. private ShowDialogueEventData.MessageShowType messageShowType = ShowDialogueEventData.MessageShowType.Verbatim;
  17. private Action<int?> finish;
  18. private int index;
  19. private char[] _currShowMessage;
  20. private float _showTime = 0.05f;
  21. private float _currShowTime = 0;
  22. protected StringBuilder _sb = new StringBuilder();
  23. private int _currShowIndex;
  24. private bool _isUpdate;
  25. private bool _isShowNextButton;
  26. private EventLinkConfig eventConditionConfig;
  27. private bool _skipTyping;
  28. private bool _isShowingOptions;
  29. public static async CTask OpenDialoguePanel(int id, Action<int?> finish)
  30. {
  31. DialogueBubblePanel dialoguePanel = await UIManager.Instance.LoadAndOpenPanel<DialogueBubblePanel>(null, UILayer.Bottom, isFocus: false);
  32. dialoguePanel.ShowPanel(id, finish);
  33. }
  34. private void Init()
  35. {
  36. isAddStack = false;
  37. _skipTyping = false;
  38. _isShowingOptions = false;
  39. }
  40. protected override void AddEvent()
  41. {
  42. }
  43. protected override void DelEvent()
  44. {
  45. }
  46. public override void AddButtonEvent()
  47. {
  48. button_bg.onClick.AddListener(NextShow);
  49. }
  50. private void SkipTyping()
  51. {
  52. _skipTyping = true;
  53. _timerEntity?.Dispose();
  54. _timerEntity = null;
  55. if (_isUpdate)
  56. {
  57. _sb.Clear();
  58. _sb.Append(_currShowMessage);
  59. message.text = _sb.ToString();
  60. _currShowIndex = _currShowMessage.Length;
  61. _isUpdate = false;
  62. }
  63. }
  64. private void NextShow()
  65. {
  66. if (_isShowingOptions)
  67. return;
  68. if (_isUpdate)
  69. {
  70. SkipTyping();
  71. }
  72. else
  73. {
  74. StartShowMassge();
  75. }
  76. }
  77. public void ShowPanel(int id,
  78. Action<int?> finish)
  79. {
  80. eventConditionConfig = ConfigComponent.Instance.Get<EventLinkConfig>(id);
  81. this.dialogueMessaga = eventConditionConfig.LanID;
  82. this.finish = finish;
  83. index = 0;
  84. StaticUpdater.Instance.AddRenderUpdateCallBack(Update);
  85. StartShowMassge();
  86. }
  87. private void StartShowMassge()
  88. {
  89. _timerEntity?.Dispose();
  90. _timerEntity = null;
  91. if (index >= dialogueMessaga.Length)
  92. {
  93. UIManager.Instance.HideUIUIPanel(this);
  94. finish?.Invoke(null);
  95. return;
  96. }
  97. _isShowNextButton = false;
  98. string m = LanguageManager.Instance.Text(dialogueMessaga[index]);
  99. index++;
  100. switch (messageShowType)
  101. {
  102. case ShowDialogueEventData.MessageShowType.Default:
  103. message.text = m;
  104. break;
  105. case ShowDialogueEventData.MessageShowType.Verbatim:
  106. _sb.Clear();
  107. _currShowMessage = m.ToCharArray();
  108. if(_currShowMessage.Length > 0)
  109. _sb.Append(_currShowMessage[0]);
  110. message.text = _sb.ToString();
  111. _isUpdate = true;
  112. _currShowIndex = 1;
  113. _skipTyping = false;
  114. break;
  115. }
  116. }
  117. public override void Hide()
  118. {
  119. base.Hide();
  120. StaticUpdater.Instance.RemoveRenderUpdateCallBack(Update);
  121. }
  122. private TimerEntity _timerEntity;
  123. public void Update()
  124. {
  125. // Vector3 p = CombatDrive.Instance.CombatController.CombatHeroController.playerHeroEntity.GameObject.transform.Find("hitpos").position;
  126. // p.x -= 0.2f;
  127. // p.y += 0.7f;
  128. // p = CombatDrive.Instance.CombatController.CombatCameraControllder.Camera.WorldToScreenPoint(p);
  129. // p = UIManager.Instance.UICamera.ScreenToWorldPoint(p);
  130. //
  131. //
  132. // p = transform.worldToLocalMatrix * p;
  133. //
  134. // dotPoint.anchoredPosition = p;
  135. // if (EventSystemManager.Instance.isOpenUi)
  136. // return;
  137. //不是组界面不进行挂机事件对话
  138. // MainPanel mainPanel = UIManager.Instance.GetComponent<MainPanel>();
  139. // if (mainPanel == null || mainPanel.IsClose || !mainPanel.transform.gameObject.activeInHierarchy)
  140. // {
  141. // return;
  142. // }
  143. if (UIManager.Instance.currOpenPanel == null || UIManager.Instance.currOpenPanel.GetType() != typeof(MainPanel) || UIManager.Instance.popUIPanels.Count > 0)
  144. {
  145. return;
  146. }
  147. Vector3 worldPos = CombatDrive.Instance.CombatController.playerHeroEntity.combatHeroGameObject.hpTransform.position;
  148. Vector3 p = UIManager.Instance.CurrCustomCameraStack.camera.WorldToScreenPoint(worldPos);
  149. Vector3 p2 = UIManager.Instance.UICamera.ScreenToWorldPoint(p);
  150. dotPoint.transform.position = p2;
  151. if (!_isUpdate) return;
  152. if (messageShowType == ShowDialogueEventData.MessageShowType.Verbatim)
  153. {
  154. if (_currShowIndex >= _currShowMessage.Length)
  155. {
  156. _isUpdate = false;
  157. _timerEntity?.Dispose();
  158. _timerEntity = null;
  159. _timerEntity = TimerComponent.Instance.AddTimer(800, () =>
  160. {
  161. _timerEntity?.Dispose();
  162. _timerEntity = null;
  163. StartShowMassge();
  164. });
  165. return;
  166. }
  167. _currShowTime += Time.deltaTime;
  168. if (_currShowTime > _showTime)
  169. {
  170. _currShowTime -= _showTime;
  171. _sb.Append(_currShowMessage[_currShowIndex]);
  172. _currShowIndex++;
  173. message.text = _sb.ToString();
  174. }
  175. }
  176. }
  177. public override void Close()
  178. {
  179. UIManager.Instance.DormancyAllGComponent<DialogueOptionWidget>();
  180. _isShowingOptions = false;
  181. _skipTyping = false;
  182. _timerEntity?.Dispose();
  183. _timerEntity = null;
  184. base.Close();
  185. }
  186. }
  187. }