Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / editorTools / EditorToolsPanel.cs
@lijincheng lijincheng on 18 Mar 2023 5 KB 编辑器中弹出 Confirm
  1. using System;
  2. using Generator;
  3. using Godot;
  4.  
  5. namespace UI.EditorTools;
  6.  
  7. [Tool]
  8. public partial class EditorToolsPanel : EditorTools
  9. {
  10. //Tips 关闭回调
  11. private Action _onTipsClose;
  12.  
  13. //询问窗口关闭
  14. private Action<bool> _onConfirmClose;
  15. public override void OnShowUi(params object[] args)
  16. {
  17. //tips
  18. _onTipsClose = null;
  19. L_Tips.Instance.OkButtonText = "确定";
  20. L_Tips.Instance.CloseRequested += OnTipsClose;
  21. L_Tips.Instance.Confirmed += OnTipsClose;
  22. L_Tips.Instance.Canceled += OnTipsClose;
  23.  
  24. //confirm
  25. _onConfirmClose = null;
  26. L_Confirm.Instance.OkButtonText = "确定";
  27. L_Confirm.Instance.CancelButtonText = "取消";
  28. L_Confirm.Instance.Canceled += OnCanceled;
  29. L_Confirm.Instance.CloseRequested += OnCanceled;
  30. L_Confirm.Instance.Confirmed += OnConfirm;
  31.  
  32. var container = L_ScrollContainer.L_MarginContainer.L_VBoxContainer;
  33. //重新生成 ResourcePath
  34. container.L_HBoxContainer.L_Button.Instance.Pressed += GenerateResourcePath;
  35. //重新生成 RoomPack
  36. container.L_HBoxContainer2.L_Button.Instance.Pressed += GenerateRoomPack;
  37. //创建ui
  38. container.L_HBoxContainer3.L_Button.Instance.Pressed += OnCreateUI;
  39. }
  40.  
  41. public override void OnHideUi()
  42. {
  43. L_Tips.Instance.CloseRequested -= OnTipsClose;
  44. L_Tips.Instance.Confirmed -= OnTipsClose;
  45. L_Tips.Instance.Canceled -= OnTipsClose;
  46. L_Confirm.Instance.Canceled -= OnCanceled;
  47. L_Confirm.Instance.CloseRequested -= OnCanceled;
  48. L_Confirm.Instance.Confirmed -= OnConfirm;
  49. var container = L_ScrollContainer.L_MarginContainer.L_VBoxContainer;
  50. container.L_HBoxContainer.L_Button.Instance.Pressed -= GenerateResourcePath;
  51. container.L_HBoxContainer2.L_Button.Instance.Pressed -= GenerateRoomPack;
  52. container.L_HBoxContainer3.L_Button.Instance.Pressed -= OnCreateUI;
  53. }
  54.  
  55. /// <summary>
  56. /// Tips 关闭信号回调
  57. /// </summary>
  58. private void OnTipsClose()
  59. {
  60. if (_onTipsClose != null)
  61. {
  62. _onTipsClose();
  63. _onTipsClose = null;
  64. }
  65. }
  66.  
  67. /// <summary>
  68. /// Confirm 确认信号回调
  69. /// </summary>
  70. private void OnConfirm()
  71. {
  72. if (_onConfirmClose != null)
  73. {
  74. _onConfirmClose(true);
  75. _onConfirmClose = null;
  76. }
  77. }
  78.  
  79. /// <summary>
  80. /// Confirm 取消信号回调
  81. /// </summary>
  82. private void OnCanceled()
  83. {
  84. if (_onConfirmClose != null)
  85. {
  86. _onConfirmClose(false);
  87. _onConfirmClose = null;
  88. }
  89. }
  90. /// <summary>
  91. /// 打开提示窗口, 并设置宽高
  92. /// </summary>
  93. /// <param name="title">窗口标题</param>
  94. /// <param name="message">显示内容</param>
  95. /// <param name="width">窗口宽度</param>
  96. /// <param name="height">窗口高度</param>
  97. /// <param name="onClose">当窗口关闭时的回调</param>
  98. public void ShowTips(string title, string message, int width, int height, Action onClose = null)
  99. {
  100. var tips = L_Tips.Instance;
  101. tips.Size = new Vector2I(width, height);
  102. tips.Title = title;
  103. tips.DialogText = message;
  104. _onTipsClose = onClose;
  105. tips.Show();
  106. }
  107. /// <summary>
  108. /// 打开提示窗口
  109. /// </summary>
  110. /// <param name="title">窗口标题</param>
  111. /// <param name="message">显示内容</param>
  112. /// <param name="onClose">当窗口关闭时的回调</param>
  113. public void ShowTips(string title, string message, Action onClose = null)
  114. {
  115. ShowTips(title, message, 200, 124, onClose);
  116. }
  117.  
  118. /// <summary>
  119. /// 关闭提示窗口
  120. /// </summary>
  121. public void CloseTips()
  122. {
  123. L_Tips.Instance.Hide();
  124. _onTipsClose = null;
  125. }
  126.  
  127. /// <summary>
  128. /// 打开询问窗口, 并设置宽高
  129. /// </summary>
  130. /// <param name="title">窗口标题</param>
  131. /// <param name="message">显示内容</param>
  132. /// <param name="width">窗口宽度</param>
  133. /// <param name="height">窗口高度</param>
  134. /// <param name="onClose">当窗口关闭时的回调, 参数如果为 true 表示点击了确定按钮</param>
  135. public void ShowConfirm(string title, string message, int width, int height, Action<bool> onClose = null)
  136. {
  137. var confirm = L_Confirm.Instance;
  138. confirm.Size = new Vector2I(width, height);
  139. confirm.Title = title;
  140. confirm.DialogText = message;
  141. _onConfirmClose = onClose;
  142. confirm.Show();
  143. }
  144. /// <summary>
  145. /// 打开询问窗口
  146. /// </summary>
  147. /// <param name="title">窗口标题</param>
  148. /// <param name="message">显示内容</param>
  149. /// <param name="onClose">当窗口关闭时的回调, 参数如果为 true 表示点击了确定按钮</param>
  150. public void ShowConfirm(string title, string message, Action<bool> onClose = null)
  151. {
  152. ShowConfirm(title, message, 200, 124, onClose);
  153. }
  154.  
  155. /// <summary>
  156. /// 关闭询问窗口
  157. /// </summary>
  158. public void CloseConfirm()
  159. {
  160. L_Confirm.Instance.Hide();
  161. _onConfirmClose = null;
  162. }
  163. /// <summary>
  164. /// 创建Ui
  165. /// </summary>
  166. private void OnCreateUI()
  167. {
  168. var text = L_ScrollContainer.L_MarginContainer.L_VBoxContainer.L_HBoxContainer3.L_LineEdit.Instance.Text;
  169. ShowConfirm("提示", "是否创建UI:" + text, (result) =>
  170. {
  171. if (result)
  172. {
  173. ShowTips("提示", "创建Ui成功!");
  174. }
  175. });
  176. }
  177.  
  178. /// <summary>
  179. /// 更新 ResourcePath
  180. /// </summary>
  181. private void GenerateResourcePath()
  182. {
  183. ResourcePathGenerator.Generate();
  184. }
  185.  
  186. /// <summary>
  187. /// 重新打包房间配置
  188. /// </summary>
  189. private void GenerateRoomPack()
  190. {
  191. RoomPackGenerator.Generate();
  192. }
  193. }