Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / tileSetEditorCombination / right / TileCell.cs
  1. using Godot;
  2.  
  3. namespace UI.TileSetEditorCombination;
  4.  
  5. public class TileCell : UiCell<TileSetEditorCombination.CellButton, Vector2I>
  6. {
  7. private Image _image;
  8. private ImageTexture _previewTexture;
  9. public override void OnInit()
  10. {
  11. CellNode.L_SelectTexture.Instance.Visible = false;
  12. _image = Image.Create(GameConfig.TileCellSize, GameConfig.TileCellSize, false, Image.Format.Rgba8);
  13. _previewTexture = ImageTexture.CreateFromImage(_image);
  14. CellNode.L_PreviewImage.Instance.Texture = _previewTexture;
  15. }
  16.  
  17. public override void OnSetData(Vector2I data)
  18. {
  19. var image = CellNode.UiPanel.EditorPanel.TextureImage;
  20. _image.BlitRect(image, new Rect2I(data * GameConfig.TileCellSizeVector2I, GameConfig.TileCellSizeVector2I), Vector2I.Zero);
  21. _previewTexture.Update(_image);
  22. CellNode.L_CellId.Instance.Text = data.ToString();
  23. }
  24.  
  25. public override void OnDoubleClick()
  26. {
  27. //双击移除Cell数据
  28. //EventManager.EmitEvent(EventEnum.OnRemoveTileCell, Data);
  29. }
  30.  
  31. public override void OnDestroy()
  32. {
  33. _previewTexture.Dispose();
  34. }
  35.  
  36. public override void OnSelect()
  37. {
  38. CellNode.L_SelectTexture.Instance.Visible = true;
  39. }
  40.  
  41. public override void OnUnSelect()
  42. {
  43. CellNode.L_SelectTexture.Instance.Visible = false;
  44. }
  45.  
  46. public override int OnSort(UiCell<TileSetEditorCombination.CellButton, Vector2I> other)
  47. {
  48. if (Data.Y != other.Data.Y)
  49. {
  50. return Data.Y - other.Data.Y;
  51. }
  52. return Data.X - other.Data.X;
  53. }
  54. }