Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / mapEditorSelectObject / MapEditorSelectObjectPanel.cs
@小李xl 小李xl on 29 Oct 2023 3 KB 更改配置表名
  1. using System;
  2. using System.Linq;
  3. using Config;
  4. using Godot;
  5.  
  6. namespace UI.MapEditorSelectObject;
  7.  
  8. public partial class MapEditorSelectObjectPanel : MapEditorSelectObject
  9. {
  10. /// <summary>
  11. /// 双击选中物体事件
  12. /// </summary>
  13. public event Action<ExcelConfig.ActivityBase> SelectObjectEvent;
  14. public class TypeButtonData
  15. {
  16. /// <summary>
  17. /// 类型名称
  18. /// </summary>
  19. public string Name;
  20. /// <summary>
  21. /// 类型值
  22. /// </summary>
  23. public int Type;
  24.  
  25. public TypeButtonData(string name, int type)
  26. {
  27. Name = name;
  28. Type = type;
  29. }
  30. }
  31. //类型网格组件
  32. private UiGrid<TypeButton, TypeButtonData> _typeGrid;
  33. //物体网格组件
  34. private UiGrid<ObjectButton, ExcelConfig.ActivityBase> _objectGrid;
  35. //允许出现在该面板中的物体类型
  36. private int[] _typeArray = new[] { 4, 5, 9 };
  37. public override void OnCreateUi()
  38. {
  39. S_Search.Instance.Pressed += OnSearch;
  40. _typeGrid = new UiGrid<TypeButton, TypeButtonData>(S_TypeButton, typeof(TypeButtonCell));
  41. _typeGrid.SetColumns(1);
  42. _typeGrid.SetHorizontalExpand(true);
  43. _typeGrid.SetCellOffset(new Vector2I(0, 5));
  44. _objectGrid = new UiGrid<ObjectButton, ExcelConfig.ActivityBase>(S_ObjectButton, typeof(ObjectButtonCell));
  45. _objectGrid.SetAutoColumns(true);
  46. _objectGrid.SetHorizontalExpand(true);
  47. _objectGrid.SetCellOffset(new Vector2I(10, 10));
  48. }
  49.  
  50. public override void OnDestroyUi()
  51. {
  52. _typeGrid.Destroy();
  53. _objectGrid.Destroy();
  54. }
  55.  
  56. /// <summary>
  57. /// 设置显示的物体类型
  58. /// </summary>
  59. public void SetShowType(ActivityType activityType)
  60. {
  61. _typeGrid.RemoveAll();
  62. if (activityType == ActivityType.None)
  63. {
  64. _typeGrid.Add(new TypeButtonData("所有", -1));
  65. _typeGrid.Add(new TypeButtonData(ActivityId.GetTypeName(ActivityType.Weapon), (int)ActivityType.Weapon));
  66. _typeGrid.Add(new TypeButtonData(ActivityId.GetTypeName(ActivityType.Prop), (int)ActivityType.Prop));
  67. _typeGrid.Add(new TypeButtonData(ActivityId.GetTypeName(ActivityType.Enemy), (int)ActivityType.Enemy));
  68. }
  69. else
  70. {
  71. _typeGrid.Add(new TypeButtonData(ActivityId.GetTypeName(activityType), (int)activityType));
  72. }
  73. _typeGrid.SelectIndex = 0;
  74. }
  75.  
  76. /// <summary>
  77. /// 搜索对象
  78. /// </summary>
  79. public void OnSearch()
  80. {
  81. //类型
  82. int type;
  83. //名称
  84. var name = S_LineEdit.Instance.Text;
  85. var buttonData = _typeGrid.GetData(_typeGrid.SelectIndex);
  86. if (buttonData != null)
  87. {
  88. type = buttonData.Type;
  89. }
  90. else
  91. {
  92. type = -1;
  93. }
  94.  
  95. //搜索结果
  96. var arr = ExcelConfig.ActivityBase_List.Where(
  97. o =>
  98. {
  99. return o.ShowInMapEditor &&
  100. (string.IsNullOrEmpty(name) || o.Name.Contains(name) || o.Id.Contains(name)) &&
  101. (type < 0 ? _typeArray.Contains(o.Type) : o.Type == type);
  102. }
  103. ).ToArray();
  104. _objectGrid.SetDataList(arr);
  105. }
  106.  
  107. /// <summary>
  108. /// 选中对象
  109. /// </summary>
  110. public void SelectCell(ExcelConfig.ActivityBase activityObject)
  111. {
  112. if (SelectObjectEvent != null)
  113. {
  114. SelectObjectEvent(activityObject);
  115. }
  116. }
  117.  
  118. /// <summary>
  119. /// 获取选中的数据
  120. /// </summary>
  121. public ExcelConfig.ActivityBase GetSelectData()
  122. {
  123. return _objectGrid.SelectData;
  124. }
  125. }