Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / tileSetEditorCombination / TileSetEditorCombinationPanel.cs
@小李xl 小李xl on 7 Jan 2024 2 KB 读取TileSet数据, 基础完成
  1. using Godot;
  2. using UI.TileSetEditor;
  3.  
  4. namespace UI.TileSetEditorCombination;
  5.  
  6. public partial class TileSetEditorCombinationPanel : TileSetEditorCombination
  7. {
  8. /// <summary>
  9. /// 父Ui
  10. /// </summary>
  11. public TileSetEditorPanel EditorPanel;
  12. public override void OnCreateUi()
  13. {
  14. EditorPanel = (TileSetEditorPanel)ParentUi;
  15. //改变选中资源事件
  16. AddEventListener(EventEnum.OnSelectTileSetSource, OnSelectTileSetSource);
  17. //改变纹理事件
  18. AddEventListener(EventEnum.OnSetTileTexture, OnSetTileTexture);
  19. //改变背景颜色事件
  20. AddEventListener(EventEnum.OnSetTileSetBgColor, OnSetTileSetBgColor);
  21. }
  22. public override void OnShowUi()
  23. {
  24. if (EditorPanel.Texture == null)
  25. {
  26. EditorWindowManager.ShowTips("警告", "请先导入纹理!", () =>
  27. {
  28. EditorPanel.TabGrid.SelectIndex = 0;
  29. });
  30. }
  31. }
  32.  
  33. public override void OnDestroyUi()
  34. {
  35. }
  36. //改变选中资源事件
  37. private void OnSelectTileSetSource(object obj)
  38. {
  39. //取消选中组合
  40. S_LeftBottomBg.Instance.ClearSelectCell();
  41. //清除绘制的组合
  42. S_LeftTopBg.Instance.ClearAllCell();
  43. //清除gird中的组合
  44. var grid = S_RightBg.Instance.Grid;
  45. grid.RemoveAll();
  46. if (obj != null)
  47. {
  48. //grid加载组合
  49. var sourceInfo = (TileSetSourceInfo)obj;
  50. foreach (var combinationInfo in sourceInfo.Combination)
  51. {
  52. var src = EditorPanel.TextureImage;
  53. var previewImage = ImportCombinationData.GetPreviewTexture(src, combinationInfo.Cells, combinationInfo.Positions);
  54. grid.Add(new ImportCombinationData(ImageTexture.CreateFromImage(previewImage), combinationInfo));
  55. }
  56. }
  57. }
  58.  
  59. //改变TileSet纹理
  60. private void OnSetTileTexture(object arg)
  61. {
  62. S_LeftBottomBg.Instance.OnChangeTileSetTexture();
  63. if (EditorPanel.InitTexture)
  64. {
  65. S_RightBg.Instance.OnChangeTileSetTexture();
  66. }
  67. }
  68. //改变TileSet背景颜色
  69. private void OnSetTileSetBgColor(object arg)
  70. {
  71. //背景颜色
  72. if (arg is Color color)
  73. {
  74. S_LeftTopBg.Instance.Color = color;
  75. S_LeftBottomBg.Instance.Color = color;
  76. }
  77. }
  78. }