Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / tileSetEditorCombination / TileSetEditorCombinationPanel.cs
@小李xl 小李xl on 20 Jan 2024 2 KB TileSet导入Image面板, 开发中
  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. OnSetTileSetBgColor(EditorPanel.BgColor);
  22. }
  23. public override void OnShowUi()
  24. {
  25. if (EditorPanel.Texture == null)
  26. {
  27. EditorWindowManager.ShowTips("警告", "请先导入纹理!", () =>
  28. {
  29. EditorPanel.TabGrid.SelectIndex = 0;
  30. });
  31. }
  32. }
  33.  
  34. public override void OnDestroyUi()
  35. {
  36. }
  37. //改变选中资源事件
  38. private void OnSelectTileSetSource(object obj)
  39. {
  40. //取消选中组合
  41. S_LeftBottomBg.Instance.ClearSelectCell();
  42. //清除绘制的组合
  43. S_LeftTopBg.Instance.ClearAllCell();
  44. //清除gird中的组合
  45. var grid = S_RightBg.Instance.Grid;
  46. grid.RemoveAll();
  47. if (obj != null)
  48. {
  49. //grid加载组合
  50. var sourceInfo = (TileSetSourceInfo)obj;
  51. foreach (var combinationInfo in sourceInfo.Combination)
  52. {
  53. var src = EditorPanel.TextureImage;
  54. var previewImage = ImportCombinationData.GetPreviewTexture(src, combinationInfo.Cells, combinationInfo.Positions);
  55. grid.Add(new ImportCombinationData(ImageTexture.CreateFromImage(previewImage), combinationInfo));
  56. }
  57. }
  58. }
  59.  
  60. //改变TileSet纹理
  61. private void OnSetTileTexture(object arg)
  62. {
  63. S_LeftBottomBg.Instance.OnChangeTileSetTexture();
  64. if (EditorPanel.InitTexture)
  65. {
  66. S_RightBg.Instance.OnChangeTileSetTexture();
  67. }
  68. }
  69. //改变TileSet背景颜色
  70. private void OnSetTileSetBgColor(object arg)
  71. {
  72. //背景颜色
  73. if (arg is Color color)
  74. {
  75. S_LeftTopBg.Instance.Color = color;
  76. S_LeftBottomBg.Instance.Color = color;
  77. }
  78. }
  79. }