Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / tileSetEditorCombination / right / TileSelected.cs
@小李xl 小李xl on 7 Jan 2024 2 KB 标记数据脏了
  1. using Godot;
  2.  
  3. namespace UI.TileSetEditorCombination;
  4.  
  5. public partial class TileSelected : VBoxContainer, IUiNodeScript
  6. {
  7. /// <summary>
  8. /// 存放所有组合数据
  9. /// </summary>
  10. public UiGrid<TileSetEditorCombination.CellButton, ImportCombinationData> Grid { get; private set; }
  11. private TileSetEditorCombination.RightBg _rightBg;
  12. public void SetUiNode(IUiNode uiNode)
  13. {
  14. _rightBg = (TileSetEditorCombination.RightBg)uiNode;
  15.  
  16. Grid = new UiGrid<TileSetEditorCombination.CellButton, ImportCombinationData>(_rightBg.L_ScrollContainer.L_CellButton, typeof(TileCell));
  17. Grid.SetCellOffset(new Vector2I(5, 5));
  18. Grid.SetAutoColumns(true);
  19. Grid.SetHorizontalExpand(true);
  20. _rightBg.UiPanel.AddEventListener(EventEnum.OnImportCombination, OnImportCombination);
  21. _rightBg.UiPanel.AddEventListener(EventEnum.OnRemoveCombination, OnRemoveCombination);
  22. _rightBg.UiPanel.AddEventListener(EventEnum.OnUpdateCombination, OnUpdateCombination);
  23. }
  24. /// <summary>
  25. /// 导入组合图块
  26. /// </summary>
  27. private void OnImportCombination(object obj)
  28. {
  29. if (obj is ImportCombinationData data)
  30. {
  31. _rightBg.UiPanel.EditorPanel.TileSetSourceInfo.Combination.Add(data.CombinationInfo);
  32. Grid.Add(data);
  33. Grid.Sort();
  34. EventManager.EmitEvent(EventEnum.OnTileSetDirty);
  35. }
  36. }
  37. /// <summary>
  38. /// 移除组合图块
  39. /// </summary>
  40. private void OnRemoveCombination(object obj)
  41. {
  42. if (obj is ImportCombinationData data)
  43. {
  44. var uiCell = Grid.Find(c => c.Data.CombinationInfo.Id == data.CombinationInfo.Id);
  45. _rightBg.UiPanel.EditorPanel.TileSetSourceInfo.Combination.Remove(data.CombinationInfo);
  46. if (uiCell != null)
  47. {
  48. Grid.RemoveByIndex(uiCell.Index);
  49. }
  50. EventManager.EmitEvent(EventEnum.OnTileSetDirty);
  51. }
  52. }
  53.  
  54. /// <summary>
  55. /// 修改组合图块
  56. /// </summary>
  57. private void OnUpdateCombination(object obj)
  58. {
  59. if (obj is ImportCombinationData data)
  60. {
  61. var uiCell = Grid.Find(c => c.Data.CombinationInfo.Id == data.CombinationInfo.Id);
  62. if (uiCell != null)
  63. {
  64. uiCell.SetData(data);
  65. }
  66. EventManager.EmitEvent(EventEnum.OnTileSetDirty);
  67. }
  68. }
  69.  
  70. public void OnDestroy()
  71. {
  72. Grid.Destroy();
  73. }
  74.  
  75. /// <summary>
  76. /// 改变TileSet纹理
  77. /// </summary>
  78. public void OnChangeTileSetTexture()
  79. {
  80. //_grid.RemoveAll();
  81. //刷新预览图
  82. Grid.ForEach(cell =>
  83. {
  84. cell.Data.UpdatePreviewTexture(_rightBg.UiPanel.EditorPanel.TextureImage);
  85. });
  86. }
  87. }