Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / mapEditorMapLayer / LayerButtonCell.cs
@小李xl 小李xl on 2 Aug 2023 1 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. _visible = panel.S_TileMap.Instance.IsLayerEnabled(data.Layer);
  29. SetVisibleIcon(_visible);
  30. }
  31. }
  32.  
  33. private void OnVisibleButtonClick()
  34. {
  35. var panel = CellNode.UiPanel.ParentUi as MapEditorPanel;
  36. if (panel != null)
  37. {
  38. _visible = !_visible;
  39. panel.S_TileMap.Instance.SetLayerEnabled(Data.Layer, _visible);
  40. SetVisibleIcon(_visible);
  41. }
  42. }
  43.  
  44. private void SetVisibleIcon(bool visible)
  45. {
  46. if (visible)
  47. {
  48. CellNode.L_VisibleButton.Instance.TextureNormal = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_ui_commonIcon_Visible_png);
  49. }
  50. else
  51. {
  52. CellNode.L_VisibleButton.Instance.TextureNormal = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_ui_commonIcon_Hide_png);
  53. }
  54. }
  55. }