Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / tileSetEditorSegment / TileSelected.cs
  1. using Godot;
  2.  
  3. namespace UI.TileSetEditorSegment;
  4.  
  5. public partial class TileSelected : VBoxContainer, IUiNodeScript
  6. {
  7. private TileSetEditorSegment.RightBg _rightBg;
  8. private UiGrid<TileSetEditorSegment.CellButton, Vector2I> _grid;
  9. public void SetUiNode(IUiNode uiNode)
  10. {
  11. _rightBg = (TileSetEditorSegment.RightBg)uiNode;
  12.  
  13. _grid = new UiGrid<TileSetEditorSegment.CellButton, Vector2I>(_rightBg.L_ScrollContainer.L_CellButton, typeof(TileCell));
  14. _grid.SetCellOffset(new Vector2I(5, 5));
  15. _grid.SetAutoColumns(true);
  16. _grid.SetHorizontalExpand(true);
  17. _rightBg.UiPanel.AddEventListener(EventEnum.OnImportTileCell, OnImportCell);
  18. _rightBg.UiPanel.AddEventListener(EventEnum.OnRemoveTileCell, OnRemoveCell);
  19. }
  20.  
  21. /// <summary>
  22. /// 导入选中的Cell图块
  23. /// </summary>
  24. private void OnImportCell(object obj)
  25. {
  26. if (obj is Vector2I cell)
  27. {
  28. _grid.Add(cell);
  29. _grid.Sort();
  30. }
  31. }
  32. /// <summary>
  33. /// 移除选中的Cell图块
  34. /// </summary>
  35. private void OnRemoveCell(object obj)
  36. {
  37. if (obj is Vector2I cell)
  38. {
  39. var uiCell = _grid.Find(c => c.Data == cell);
  40. if (uiCell != null)
  41. {
  42. _grid.RemoveByIndex(uiCell.Index);
  43. }
  44. }
  45. }
  46.  
  47. public void OnDestroy()
  48. {
  49. _grid.Destroy();
  50. }
  51.  
  52. /// <summary>
  53. /// 改变TileSet纹理
  54. /// </summary>
  55. public void OnChangeTileSetTexture(Texture2D texture)
  56. {
  57. _grid.RemoveAll();
  58. }
  59. }