Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / editorWindow / EditorWindowPanel.cs
  1. using System;
  2. using Godot;
  3.  
  4. namespace UI.EditorWindow;
  5.  
  6. public partial class EditorWindowPanel : EditorWindow
  7. {
  8.  
  9. public class ButtonData
  10. {
  11. /// <summary>
  12. /// 显示文本
  13. /// </summary>
  14. public string Text;
  15. /// <summary>
  16. /// 点击的回调
  17. /// </summary>
  18. public Action Callback;
  19.  
  20. public ButtonData(string text, Action callback)
  21. {
  22. Text = text;
  23. Callback = callback;
  24. }
  25. }
  26. /// <summary>
  27. /// 关闭窗口时回调
  28. /// </summary>
  29. public event Action CloseEvent;
  30.  
  31. /// <summary>
  32. /// 设置按钮列表
  33. /// </summary>
  34. public UiGrid<CustomButton, ButtonData> ButtonGrid { get; private set; }
  35.  
  36. public override void OnCreateUi()
  37. {
  38. S_CustomButton.Instance.Visible = false;
  39. S_Window.Instance.CloseRequested += OnCloseWindow;
  40. }
  41.  
  42. /// <summary>
  43. /// 设置自定义按钮
  44. /// </summary>
  45. public void SetButtonList(params ButtonData[] buttons)
  46. {
  47. if (ButtonGrid == null)
  48. {
  49. S_CustomButton.Instance.Visible = true;
  50. ButtonGrid = CreateUiGrid<CustomButton, ButtonData, CustomButtonCell>(S_CustomButton);
  51. ButtonGrid.SetHorizontalExpand(true);
  52. }
  53. ButtonGrid.SetColumns(buttons.Length);
  54. ButtonGrid.SetDataList(buttons);
  55. }
  56.  
  57. /// <summary>
  58. /// 打开子Ui并放入 Body 节点中
  59. /// </summary>
  60. /// <param name="uiName">Ui名称</param>
  61. public UiBase OpenBody(string uiName)
  62. {
  63. var nestedUi = S_Body.OpenNestedUi(uiName);
  64. S_Window.Instance.Popup();
  65. return nestedUi;
  66. }
  67. /// <summary>
  68. /// 打开子Ui并放入 Body 节点中
  69. /// </summary>
  70. /// <param name="uiName">Ui名称</param>
  71. public T OpenBody<T>(string uiName) where T : UiBase
  72. {
  73. return (T)OpenBody(uiName);
  74. }
  75.  
  76. /// <summary>
  77. /// 设置标题
  78. /// </summary>
  79. public void SetWindowTitle(string title)
  80. {
  81. S_Window.Instance.Title = title;
  82. }
  83.  
  84. /// <summary>
  85. /// 设置窗体大小
  86. /// </summary>
  87. public void SetWindowSize(Vector2I size)
  88. {
  89. S_Window.Instance.Size = size;
  90. }
  91.  
  92. /// <summary>
  93. /// 设置窗体最小大小
  94. /// </summary>
  95. public void SetWindowMinSize(Vector2I size)
  96. {
  97. S_Window.Instance.MinSize = size;
  98. }
  99.  
  100. /// <summary>
  101. /// 关闭窗口
  102. /// </summary>
  103. /// <param name="triggerEvent">是否派发关闭窗口的事件</param>
  104. public void CloseWindow(bool triggerEvent = true)
  105. {
  106. if (IsDestroyed)
  107. {
  108. return;
  109. }
  110. if (triggerEvent && CloseEvent != null)
  111. {
  112. CloseEvent();
  113. }
  114. Destroy();
  115. }
  116.  
  117. private void OnCloseWindow()
  118. {
  119. CloseWindow();
  120. }
  121. }