DialogueBubblePanel.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 EventConditionConfig 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);
  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<EventConditionConfig>(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. _sb.Append(_currShowMessage[0]);
  109. message.text = _sb.ToString();
  110. _isUpdate = true;
  111. _currShowIndex = 1;
  112. _skipTyping = false;
  113. break;
  114. }
  115. }
  116. public override void Hide()
  117. {
  118. base.Hide();
  119. StaticUpdater.Instance.RemoveRenderUpdateCallBack(Update);
  120. }
  121. private TimerEntity _timerEntity;
  122. public void Update()
  123. {
  124. // Vector3 p = CombatDrive.Instance.CombatController.CombatHeroController.playerHeroEntity.GameObject.transform.Find("hitpos").position;
  125. // p.x -= 0.2f;
  126. // p.y += 0.7f;
  127. // p = CombatDrive.Instance.CombatController.CombatCameraControllder.Camera.WorldToScreenPoint(p);
  128. // p = UIManager.Instance.UICamera.ScreenToWorldPoint(p);
  129. //
  130. //
  131. // p = transform.worldToLocalMatrix * p;
  132. //
  133. // dotPoint.anchoredPosition = p;
  134. if (EventSystemManager.Instance.isOpenUi)
  135. return;
  136. Vector3 worldPos = CombatDrive.Instance.CombatController.playerHeroEntity.combatHeroGameObject.hpTransform.position;
  137. Vector3 p = UIManager.Instance.CurrCustomCameraStack.camera.WorldToScreenPoint(worldPos);
  138. Vector3 p2 = UIManager.Instance.UICamera.ScreenToWorldPoint(p);
  139. dotPoint.transform.position = p2;
  140. if (!_isUpdate) return;
  141. if (messageShowType == ShowDialogueEventData.MessageShowType.Verbatim)
  142. {
  143. if (_currShowIndex >= _currShowMessage.Length)
  144. {
  145. _isUpdate = false;
  146. _timerEntity?.Dispose();
  147. _timerEntity = null;
  148. _timerEntity = TimerComponent.Instance.AddTimer(800, () =>
  149. {
  150. _timerEntity?.Dispose();
  151. _timerEntity = null;
  152. StartShowMassge();
  153. });
  154. return;
  155. }
  156. _currShowTime += Time.deltaTime;
  157. if (_currShowTime > _showTime)
  158. {
  159. _currShowTime -= _showTime;
  160. _sb.Append(_currShowMessage[_currShowIndex]);
  161. _currShowIndex++;
  162. message.text = _sb.ToString();
  163. }
  164. }
  165. }
  166. public override void Close()
  167. {
  168. UIManager.Instance.DormancyAllGComponent<DialogueOptionWidget>();
  169. _isShowingOptions = false;
  170. _skipTyping = false;
  171. _timerEntity?.Dispose();
  172. _timerEntity = null;
  173. base.Close();
  174. }
  175. }
  176. }