Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / mapEditorMapLayer / LayerButtonCell.cs
@小李xl 小李xl on 20 Jan 2024 2 KB 调整TileMap编辑器布局
  1. using UI.MapEditor;
  2.  
  3. namespace UI.MapEditorMapLayer;
  4.  
  5. public class LayerButtonCell : UiCell<MapEditorMapLayer.LayerButton, TileMapLayerData>
  6. {
  7. private bool _visible;
  8. public override void OnInit()
  9. {
  10. CellNode.L_VisibleButton.Instance.Pressed += OnVisibleButtonClick;
  11. CellNode.L_SelectTexture.Instance.Visible = false;
  12. }
  13.  
  14. public override void OnSetData(TileMapLayerData data)
  15. {
  16. if (data.IsLock)
  17. {
  18. CellNode.Instance.Icon = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_ui_commonIcon_Lock_png);
  19. }
  20. else
  21. {
  22. CellNode.Instance.Icon = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_ui_commonIcon_Unlock_png);
  23. }
  24.  
  25. CellNode.Instance.Text = data.Title;
  26. var panel = CellNode.UiPanel.ParentUi as MapEditorPanel;
  27. if (panel != null)
  28. {
  29. if (Data.Layer == MapLayer.MarkLayer) //标记层
  30. {
  31. _visible = true;
  32. CellNode.UiPanel.EditorTileMap.IsDrawMark = _visible;
  33. }
  34. else
  35. {
  36. _visible = panel.S_TileMap.Instance.IsLayerEnabled(data.Layer);
  37. }
  38. SetVisibleIcon(_visible);
  39. }
  40. }
  41.  
  42. /// <summary>
  43. /// 设置层级是否显示
  44. /// </summary>
  45. public void SetLayerVisible(bool visible)
  46. {
  47. var panel = CellNode.UiPanel.ParentUi as MapEditorPanel;
  48. if (panel != null)
  49. {
  50. _visible = visible;
  51. if (Data.Layer == MapLayer.MarkLayer) //隐藏标记层
  52. {
  53. CellNode.UiPanel.EditorTileMap.IsDrawMark = visible;
  54. panel.S_MapEditorTools.Instance.S_ToolRoot.Instance.Visible = visible;
  55. }
  56. else //隐藏地图层级
  57. {
  58. panel.S_TileMap.Instance.SetLayerEnabled(Data.Layer, visible);
  59. }
  60. SetVisibleIcon(visible);
  61. }
  62. }
  63.  
  64. private void OnVisibleButtonClick()
  65. {
  66. SetLayerVisible(!_visible);
  67. }
  68.  
  69. private void SetVisibleIcon(bool visible)
  70. {
  71. if (visible)
  72. {
  73. CellNode.L_VisibleButton.Instance.TextureNormal = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_ui_commonIcon_Visible_png);
  74. }
  75. else
  76. {
  77. CellNode.L_VisibleButton.Instance.TextureNormal = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_ui_commonIcon_Hide_png);
  78. }
  79. }
  80.  
  81. public override void OnSelect()
  82. {
  83. CellNode.L_SelectTexture.Instance.Visible = true;
  84. CellNode.UiPanel.EditorTileMap.SetCurrLayer(Data);
  85. }
  86.  
  87. public override void OnUnSelect()
  88. {
  89. CellNode.L_SelectTexture.Instance.Visible = false;
  90. }
  91.  
  92. public override bool CanSelect()
  93. {
  94. return !Data.IsLock;
  95. }
  96. }