Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / mapEditorMapTile / CombinationCell.cs
@小李xl 小李xl on 18 Jan 2024 1 KB TileMap编辑器绘制组合
  1. using Godot;
  2.  
  3. namespace UI.MapEditorMapTile;
  4.  
  5. public class CombinationCell : UiCell<MapEditorMapTile.CellButton, ImportCombinationData>
  6. {
  7. public override void OnInit()
  8. {
  9. CellNode.L_SelectTexture.Instance.Visible = false;
  10. }
  11. public override void OnSetData(ImportCombinationData data)
  12. {
  13. CellNode.L_CellName.Instance.Text = data.CombinationInfo.Name;
  14. CellNode.L_PreviewImage.Instance.Texture = data.PreviewTexture;
  15. }
  16. public override void OnDisable()
  17. {
  18. if (Data.PreviewTexture != null)
  19. {
  20. Data.PreviewTexture.Dispose();
  21. Data.PreviewTexture = null;
  22. }
  23. }
  24.  
  25. public override void OnDestroy()
  26. {
  27. if (Data.PreviewTexture != null)
  28. {
  29. Data.PreviewTexture.Dispose();
  30. Data.PreviewTexture = null;
  31. }
  32. }
  33. public override void OnSelect()
  34. {
  35. CellNode.L_SelectTexture.Instance.Visible = true;
  36. //选中组合, 将组合数据设置到笔刷上
  37. var editorTileMap = CellNode.UiPanel.EditorTileMap;
  38. editorTileMap.ClearCurrBrushAtlasCoords();
  39. var positions = Data.CombinationInfo.Positions;
  40. var cells = Data.CombinationInfo.Cells;
  41. for (var i = 0; i < cells.Length; i++)
  42. {
  43. editorTileMap.AddCurrBrushAtlasCoords(
  44. positions[i].AsVector2I() / GameConfig.TileCellSize,
  45. cells[i].AsVector2I() / GameConfig.TileCellSize
  46. );
  47. }
  48. }
  49.  
  50. public override void OnUnSelect()
  51. {
  52. CellNode.L_SelectTexture.Instance.Visible = false;
  53. }
  54. }