Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / mapEditorMapLayer / LayerButtonCell.cs
@小李xl 小李xl on 20 Aug 2023 2 KB 创建房间标记, 开发中
  1. using UI.MapEditor;
  2.  
  3. namespace UI.MapEditorMapLayer;
  4.  
  5. public class LayerButtonCell : UiCell<MapEditorMapLayer.LayerButton, MapEditorMapLayerPanel.LayerButtonData>
  6. {
  7. private bool _visible;
  8. public override void OnInit()
  9. {
  10. CellNode.L_VisibleButton.Instance.Pressed += OnVisibleButtonClick;
  11. }
  12.  
  13. public override void OnSetData(MapEditorMapLayerPanel.LayerButtonData data)
  14. {
  15. if (data.IsLock)
  16. {
  17. CellNode.Instance.Icon = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_ui_commonIcon_Lock_png);
  18. }
  19. else
  20. {
  21. CellNode.Instance.Icon = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_ui_commonIcon_Unlock_png);
  22. }
  23.  
  24. CellNode.Instance.Text = data.Title;
  25. var panel = CellNode.UiPanel.ParentUi as MapEditorPanel;
  26. if (panel != null)
  27. {
  28. if (Data.Layer == EditorTileMap.MarkLayer) //标记层
  29. {
  30. _visible = true;
  31. }
  32. else
  33. {
  34. _visible = panel.S_TileMap.Instance.IsLayerEnabled(data.Layer);
  35. }
  36. SetVisibleIcon(_visible);
  37. }
  38. }
  39.  
  40. private void OnVisibleButtonClick()
  41. {
  42. var panel = CellNode.UiPanel.ParentUi as MapEditorPanel;
  43. if (panel != null)
  44. {
  45. _visible = !_visible;
  46. if (Data.Layer == EditorTileMap.MarkLayer) //隐藏标记层
  47. {
  48. panel.S_MapEditorTools.Instance.S_ToolRoot.Instance.Visible = _visible;
  49. }
  50. else //隐藏地图层级
  51. {
  52. panel.S_TileMap.Instance.SetLayerEnabled(Data.Layer, _visible);
  53. }
  54. SetVisibleIcon(_visible);
  55. }
  56. }
  57.  
  58. private void SetVisibleIcon(bool visible)
  59. {
  60. if (visible)
  61. {
  62. CellNode.L_VisibleButton.Instance.TextureNormal = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_ui_commonIcon_Visible_png);
  63. }
  64. else
  65. {
  66. CellNode.L_VisibleButton.Instance.TextureNormal = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_ui_commonIcon_Hide_png);
  67. }
  68. }
  69. }