Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / mapEditorMapTile / MapEditorMapTilePanel.cs
@小李xl 小李xl on 20 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. AddEventListener(EventEnum.OnSelectTileLayer, OnSelectTileLayer);
  47. OnSelectTileLayer(0);
  48. }
  49.  
  50. public override void OnDestroyUi()
  51. {
  52. }
  53.  
  54. /// <summary>
  55. /// 初始化TileSet数据
  56. /// </summary>
  57. public void InitData(TileSetSplit tileSetSplit)
  58. {
  59. TileSetSplit = tileSetSplit;
  60. //初始化Source下拉框
  61. var optionButton = S_SourceOption.Instance;
  62. foreach (var sourceInfo in tileSetSplit.TileSetInfo.Sources)
  63. {
  64. optionButton.AddItem(sourceInfo.Name);
  65. }
  66.  
  67. optionButton.Selected = 0;
  68. OnChangeSource(0);
  69. }
  70. //选中层级
  71. private void OnSelectTileLayer(object obj)
  72. {
  73. if (obj is int v)
  74. {
  75. S_MaskBg.Instance.Visible = v == 0;
  76. }
  77. }
  78. // 切换选中的资源
  79. private void OnChangeSource(long index)
  80. {
  81. SourceIndex = (int)index;
  82. if (index >= 0)
  83. {
  84. var sourceInfo = TileSetSourceInfo;
  85. //单格页签纹理
  86. S_Tab1.Instance.SetImage(sourceInfo.GetSourceImage());
  87. //触发聚焦
  88. S_Tab1.Instance.OnFocusClick();
  89. //地形页签
  90. S_Tab2.Instance.RefreshTerrain(sourceInfo);
  91. //组合页签
  92. S_Tab3.Instance.RefreshCombination(sourceInfo);
  93. }
  94. EditorTileMap.SetCurrSourceIndex(SourceIndex);
  95. }
  96. //切换笔刷类型
  97. private void OnChangeBrush(long index)
  98. {
  99. var v1 = false;
  100. var v2 = false;
  101. var v3 = false;
  102. if (index == 0) //自由绘制
  103. {
  104. v1 = true;
  105. EditorTileMap.SetCurrBrushType(EditorTileMap.TileMapDrawMode.Free);
  106. }
  107. else if (index == 1) //地形
  108. {
  109. v2 = true;
  110. EditorTileMap.SetCurrBrushType(EditorTileMap.TileMapDrawMode.Terrain);
  111. }
  112. else if (index == 2) //组合
  113. {
  114. v3 = true;
  115. EditorTileMap.SetCurrBrushType(EditorTileMap.TileMapDrawMode.Combination);
  116. }
  117. else
  118. {
  119. EditorTileMap.SetCurrBrushType(EditorTileMap.TileMapDrawMode.Free);
  120. }
  121.  
  122. S_Tab1.Instance.Visible = v1;
  123. S_Tab2.Instance.Visible = v2;
  124. S_Tab3.Instance.Visible = v3;
  125. }
  126. }