Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / mapEditorMapTile / MapEditorMapTilePanel.cs
@小李xl 小李xl on 17 Jan 2024 3 KB TileMap读取组合数据
  1. using Godot;
  2. using UI.MapEditor;
  3.  
  4. namespace UI.MapEditorMapTile;
  5.  
  6. public partial class MapEditorMapTilePanel : MapEditorMapTile
  7. {
  8. /// <summary>
  9. /// 使用的TileSet数据
  10. /// </summary>
  11. public TileSetSplit TileSetSplit { get; private set; }
  12.  
  13. /// <summary>
  14. /// 选中的资源 Id
  15. /// </summary>
  16. public int SourceIndex { get; private set; } = -1;
  17. /// <summary>
  18. /// 选中的 Source
  19. /// </summary>
  20. public TileSetSourceInfo TileSetSourceInfo
  21. {
  22. get
  23. {
  24. if (SourceIndex < 0)
  25. {
  26. return null;
  27. }
  28. return TileSetSplit.TileSetInfo.Sources[SourceIndex];
  29. }
  30. }
  31. /// <summary>
  32. /// 编辑器Tile对象
  33. /// </summary>
  34. public EditorTileMap EditorTileMap { get; private set; }
  35.  
  36. public override void OnCreateUi()
  37. {
  38. var editorPanel = (MapEditorPanel)ParentUi;
  39. EditorTileMap = editorPanel.S_TileMap.Instance;
  40. //切换资源
  41. S_SourceOption.Instance.ItemSelected += OnChangeSource;
  42. //切换笔刷类型
  43. S_HandleOption.Instance.ItemSelected += OnChangeBrush;
  44. OnChangeBrush(0);
  45. }
  46.  
  47. public override void OnDestroyUi()
  48. {
  49. }
  50.  
  51. /// <summary>
  52. /// 初始化TileSet数据
  53. /// </summary>
  54. public void InitData(TileSetSplit tileSetSplit)
  55. {
  56. TileSetSplit = tileSetSplit;
  57. //初始化Source下拉框
  58. var optionButton = S_SourceOption.Instance;
  59. foreach (var sourceInfo in tileSetSplit.TileSetInfo.Sources)
  60. {
  61. optionButton.AddItem(sourceInfo.Name);
  62. }
  63.  
  64. optionButton.Selected = 0;
  65. OnChangeSource(0);
  66. }
  67. // 切换选中的资源
  68. private void OnChangeSource(long index)
  69. {
  70. SourceIndex = (int)index;
  71. if (index >= 0)
  72. {
  73. var sourceInfo = TileSetSourceInfo;
  74. //单格页签纹理
  75. S_Tab1.Instance.SetImage(sourceInfo.GetSourceImage());
  76. //触发聚焦
  77. S_Tab1.Instance.OnFocusClick();
  78. //地形页签
  79. S_Tab2.Instance.RefreshTerrain(sourceInfo);
  80. //组合页签
  81. S_Tab3.Instance.RefreshCombination(sourceInfo);
  82. }
  83. EditorTileMap.SetCurrSourceIndex(SourceIndex);
  84. }
  85. //切换笔刷类型
  86. private void OnChangeBrush(long index)
  87. {
  88. var v1 = false;
  89. var v2 = false;
  90. var v3 = false;
  91. if (index == 0) //自由绘制
  92. {
  93. v1 = true;
  94. EditorTileMap.SetCurrBrushType(EditorTileMap.TileMapDrawMode.Free);
  95. }
  96. else if (index == 1) //地形
  97. {
  98. v2 = true;
  99. EditorTileMap.SetCurrBrushType(EditorTileMap.TileMapDrawMode.Terrain);
  100. }
  101. else if (index == 2) //组合
  102. {
  103. v3 = true;
  104. EditorTileMap.SetCurrBrushType(EditorTileMap.TileMapDrawMode.Combination);
  105. }
  106. else
  107. {
  108. EditorTileMap.SetCurrBrushType(EditorTileMap.TileMapDrawMode.Free);
  109. }
  110.  
  111. S_Tab1.Instance.Visible = v1;
  112. S_Tab2.Instance.Visible = v2;
  113. S_Tab3.Instance.Visible = v3;
  114. }
  115. }