diff --git a/DungeonShooting_Godot/prefab/ui/TileSetEditorCombination.tscn b/DungeonShooting_Godot/prefab/ui/TileSetEditorCombination.tscn index 67899fc..4a4806a 100644 --- a/DungeonShooting_Godot/prefab/ui/TileSetEditorCombination.tscn +++ b/DungeonShooting_Godot/prefab/ui/TileSetEditorCombination.tscn @@ -19,6 +19,7 @@ grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_to1lc") +Layer = null [node name="HSplitContainer" type="HSplitContainer" parent="."] layout_mode = 1 diff --git a/DungeonShooting_Godot/prefab/ui/TileSetEditorTerrain.tscn b/DungeonShooting_Godot/prefab/ui/TileSetEditorTerrain.tscn index 69d5e89..044a624 100644 --- a/DungeonShooting_Godot/prefab/ui/TileSetEditorTerrain.tscn +++ b/DungeonShooting_Godot/prefab/ui/TileSetEditorTerrain.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=10 format=3 uid="uid://dfqb73y4br8yd"] +[gd_scene load_steps=11 format=3 uid="uid://dfqb73y4br8yd"] [ext_resource type="Script" path="res://src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs" id="1_6jjk7"] [ext_resource type="Script" path="res://src/game/ui/tileSetEditorTerrain/left/TileEditArea.cs" id="2_ynf0r"] @@ -9,6 +9,7 @@ [ext_resource type="Texture2D" uid="uid://18dira1me63t" path="res://resource/sprite/map/PreviewMap.png" id="5_m0oxr"] [ext_resource type="Texture2D" uid="uid://bqdrgtiyilkma" path="res://resource/sprite/map/PreviewMapShadow.png" id="7_68ntx"] [ext_resource type="Script" path="res://src/game/ui/tileSetEditorTerrain/right/TerrainBrush.cs" id="7_lmu64"] +[ext_resource type="Script" path="res://src/game/ui/tileSetEditorTerrain/right/TerrainCellDropHandler.cs" id="8_7xxcq"] [node name="TileSetEditorTerrain" type="Control"] layout_mode = 3 @@ -18,6 +19,7 @@ grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_6jjk7") +Layer = null [node name="HSplitContainer" type="HSplitContainer" parent="."] layout_mode = 1 @@ -70,7 +72,7 @@ offset_bottom = 1.0 mouse_filter = 2 -[node name="Cell" type="TextureButton" parent="HSplitContainer/LeftBottom/MarginContainer/LeftBg/TileTexture/CellRoot"] +[node name="LeftCell" type="TextureButton" parent="HSplitContainer/LeftBottom/MarginContainer/LeftBg/TileTexture/CellRoot"] layout_mode = 0 offset_right = 16.0 offset_bottom = 16.0 @@ -134,36 +136,57 @@ clip_children = 2 z_index = 1 layout_mode = 2 -color = Color(0, 0, 0, 1) +color = Color(0.496094, 0.496094, 0.496094, 1) script = ExtResource("5_0x7yx") [node name="TileTexture" type="TextureRect" parent="HSplitContainer/LeftBottom2/MarginContainer/LeftBottomBg"] +self_modulate = Color(1, 1, 1, 0.470588) layout_mode = 1 anchors_preset = 8 anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 -offset_left = -64.0 -offset_top = -72.0 -offset_right = 64.0 -offset_bottom = 72.0 +offset_left = -237.0 +offset_top = -270.0 +offset_right = -77.0 +offset_bottom = -94.0 grow_horizontal = 2 grow_vertical = 2 +scale = Vector2(3, 3) mouse_filter = 2 texture = ExtResource("5_m0oxr") stretch_mode = 2 [node name="TileShadow" type="TextureRect" parent="HSplitContainer/LeftBottom2/MarginContainer/LeftBottomBg/TileTexture"] +modulate = Color(0.498039, 0.498039, 0.498039, 1) layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +mouse_filter = 2 texture = ExtResource("7_68ntx") stretch_mode = 2 +[node name="CellRoot" type="Control" parent="HSplitContainer/LeftBottom2/MarginContainer/LeftBottomBg/TileTexture"] +layout_mode = 3 +anchors_preset = 0 +offset_right = 1.0 +offset_bottom = 1.0 +mouse_filter = 2 + +[node name="RightCell" type="Control" parent="HSplitContainer/LeftBottom2/MarginContainer/LeftBottomBg/TileTexture/CellRoot"] +anchors_preset = 0 +offset_right = 16.0 +offset_bottom = 16.0 +mouse_filter = 1 +script = ExtResource("8_7xxcq") + +[node name="CellTexture" type="Sprite2D" parent="HSplitContainer/LeftBottom2/MarginContainer/LeftBottomBg/TileTexture/CellRoot/RightCell"] +centered = false + [node name="Brush" type="Control" parent="HSplitContainer/LeftBottom2/MarginContainer/LeftBottomBg/TileTexture"] layout_mode = 1 anchors_preset = 0 diff --git a/DungeonShooting_Godot/resource/sprite/map/PreviewMap.png b/DungeonShooting_Godot/resource/sprite/map/PreviewMap.png index 10ab06e..9a371b6 100644 --- a/DungeonShooting_Godot/resource/sprite/map/PreviewMap.png +++ b/DungeonShooting_Godot/resource/sprite/map/PreviewMap.png Binary files differ diff --git a/DungeonShooting_Godot/resource/sprite/map/PreviewMapShadow.png b/DungeonShooting_Godot/resource/sprite/map/PreviewMapShadow.png index d68ed77..f325155 100644 --- a/DungeonShooting_Godot/resource/sprite/map/PreviewMapShadow.png +++ b/DungeonShooting_Godot/resource/sprite/map/PreviewMapShadow.png Binary files differ diff --git a/DungeonShooting_Godot/scene/Main.tscn b/DungeonShooting_Godot/scene/Main.tscn index 346e221..698f3f2 100644 --- a/DungeonShooting_Godot/scene/Main.tscn +++ b/DungeonShooting_Godot/scene/Main.tscn @@ -39,5 +39,6 @@ process_callback = 0 editor_draw_drag_margin = true script = ExtResource("2_2j367") +RecoveryCoefficient = null [node name="GlobalNodeRoot" type="Node2D" parent="."] diff --git a/DungeonShooting_Godot/src/framework/common/NodeExtend.cs b/DungeonShooting_Godot/src/framework/common/NodeExtend.cs index b46b4b8..250aea8 100644 --- a/DungeonShooting_Godot/src/framework/common/NodeExtend.cs +++ b/DungeonShooting_Godot/src/framework/common/NodeExtend.cs @@ -87,16 +87,16 @@ /// /// 返回鼠标是否在Ui矩形内 /// - public static bool IsMouseInRect(this Control control) + public static bool IsMouseInRect(this Control control, float border = 0) { var pos = control.GetLocalMousePosition(); - if (pos.X < 0 || pos.Y < 0) + if (pos.X < border || pos.Y < border) { return false; } var size = control.Size; - return pos.X <= size.X && pos.Y <= size.Y; + return pos.X <= size.X - border && pos.Y <= size.Y - border; } /// diff --git a/DungeonShooting_Godot/src/game/common/ui/EditorMaskBrush.cs b/DungeonShooting_Godot/src/game/common/ui/EditorMaskBrush.cs index 313e6cb..5b70200 100644 --- a/DungeonShooting_Godot/src/game/common/ui/EditorMaskBrush.cs +++ b/DungeonShooting_Godot/src/game/common/ui/EditorMaskBrush.cs @@ -32,6 +32,10 @@ public override void _Draw() { + if (TileTexture == null) + { + return; + } //绘制texture区域 if (TileTexture.Texture != null) { diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrain.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrain.cs index 9ed217a..7fbba3f 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrain.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrain.cs @@ -27,17 +27,16 @@ { _ = L_HSplitContainer.L_LeftBottom.L_MarginContainer.L_LeftBg; _ = L_HSplitContainer.L_LeftBottom2.L_MarginContainer.L_LeftBottomBg; - _ = L_HSplitContainer.L_LeftBottom2.L_MarginContainer.L_LeftBottomBg.L_TileTexture.L_Brush; } /// - /// 类型: , 路径: TileSetEditorTerrain.HSplitContainer.LeftBottom.MarginContainer.LeftBg.TileTexture.CellRoot.Cell + /// 类型: , 路径: TileSetEditorTerrain.HSplitContainer.LeftBottom.MarginContainer.LeftBg.TileTexture.CellRoot.LeftCell /// - public class Cell : UiNode + public class LeftCell : UiNode { - public Cell(TileSetEditorTerrainPanel uiPanel, UI.TileSetEditorTerrain.TerrainCellDragHandler node) : base(uiPanel, node) { } - public override Cell Clone() => new (UiPanel, (UI.TileSetEditorTerrain.TerrainCellDragHandler)Instance.Duplicate()); + public LeftCell(TileSetEditorTerrainPanel uiPanel, UI.TileSetEditorTerrain.TerrainCellDragHandler node) : base(uiPanel, node) { } + public override LeftCell Clone() => new (UiPanel, (UI.TileSetEditorTerrain.TerrainCellDragHandler)Instance.Duplicate()); } /// @@ -46,17 +45,17 @@ public class CellRoot : UiNode { /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorTerrain.HSplitContainer.LeftBottom.MarginContainer.LeftBg.TileTexture.Cell + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorTerrain.HSplitContainer.LeftBottom.MarginContainer.LeftBg.TileTexture.LeftCell /// - public Cell L_Cell + public LeftCell L_LeftCell { get { - if (_L_Cell == null) _L_Cell = new Cell(UiPanel, Instance.GetNode("Cell")); - return _L_Cell; + if (_L_LeftCell == null) _L_LeftCell = new LeftCell(UiPanel, Instance.GetNode("LeftCell")); + return _L_LeftCell; } } - private Cell _L_Cell; + private LeftCell _L_LeftCell; public CellRoot(TileSetEditorTerrainPanel uiPanel, Godot.Control node) : base(uiPanel, node) { } public override CellRoot Clone() => new (UiPanel, (Godot.Control)Instance.Duplicate()); @@ -217,6 +216,59 @@ } /// + /// 类型: , 路径: TileSetEditorTerrain.HSplitContainer.LeftBottom2.MarginContainer.LeftBottomBg.TileTexture.CellRoot.RightCell.CellTexture + /// + public class CellTexture : UiNode + { + public CellTexture(TileSetEditorTerrainPanel uiPanel, Godot.Sprite2D node) : base(uiPanel, node) { } + public override CellTexture Clone() => new (UiPanel, (Godot.Sprite2D)Instance.Duplicate()); + } + + /// + /// 类型: , 路径: TileSetEditorTerrain.HSplitContainer.LeftBottom2.MarginContainer.LeftBottomBg.TileTexture.CellRoot.RightCell + /// + public class RightCell : UiNode + { + /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorTerrain.HSplitContainer.LeftBottom2.MarginContainer.LeftBottomBg.TileTexture.CellRoot.CellTexture + /// + public CellTexture L_CellTexture + { + get + { + if (_L_CellTexture == null) _L_CellTexture = new CellTexture(UiPanel, Instance.GetNode("CellTexture")); + return _L_CellTexture; + } + } + private CellTexture _L_CellTexture; + + public RightCell(TileSetEditorTerrainPanel uiPanel, UI.TileSetEditorTerrain.TerrainCellDropHandler node) : base(uiPanel, node) { } + public override RightCell Clone() => new (UiPanel, (UI.TileSetEditorTerrain.TerrainCellDropHandler)Instance.Duplicate()); + } + + /// + /// 类型: , 路径: TileSetEditorTerrain.HSplitContainer.LeftBottom2.MarginContainer.LeftBottomBg.TileTexture.CellRoot + /// + public class CellRoot_1 : UiNode + { + /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorTerrain.HSplitContainer.LeftBottom2.MarginContainer.LeftBottomBg.TileTexture.RightCell + /// + public RightCell L_RightCell + { + get + { + if (_L_RightCell == null) _L_RightCell = new RightCell(UiPanel, Instance.GetNode("RightCell")); + return _L_RightCell; + } + } + private RightCell _L_RightCell; + + public CellRoot_1(TileSetEditorTerrainPanel uiPanel, Godot.Control node) : base(uiPanel, node) { } + public override CellRoot_1 Clone() => new (UiPanel, (Godot.Control)Instance.Duplicate()); + } + + /// /// 类型: , 路径: TileSetEditorTerrain.HSplitContainer.LeftBottom2.MarginContainer.LeftBottomBg.TileTexture.TileShadow /// public class TileShadow : UiNode @@ -240,6 +292,19 @@ public class TileTexture_1 : UiNode { /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorTerrain.HSplitContainer.LeftBottom2.MarginContainer.LeftBottomBg.CellRoot + /// + public CellRoot_1 L_CellRoot + { + get + { + if (_L_CellRoot == null) _L_CellRoot = new CellRoot_1(UiPanel, Instance.GetNode("CellRoot")); + return _L_CellRoot; + } + } + private CellRoot_1 _L_CellRoot; + + /// /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorTerrain.HSplitContainer.LeftBottom2.MarginContainer.LeftBottomBg.TileShadow /// public TileShadow L_TileShadow @@ -416,14 +481,9 @@ /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorTerrain.HSplitContainer.LeftBottom.MarginContainer.LeftBg.TileTexture.CellRoot.Cell + /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorTerrain.HSplitContainer.LeftBottom.MarginContainer.LeftBg.TileTexture.CellRoot.LeftCell /// - public Cell S_Cell => L_HSplitContainer.L_LeftBottom.L_MarginContainer.L_LeftBg.L_TileTexture.L_CellRoot.L_Cell; - - /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorTerrain.HSplitContainer.LeftBottom.MarginContainer.LeftBg.TileTexture.CellRoot - /// - public CellRoot S_CellRoot => L_HSplitContainer.L_LeftBottom.L_MarginContainer.L_LeftBg.L_TileTexture.L_CellRoot; + public LeftCell S_LeftCell => L_HSplitContainer.L_LeftBottom.L_MarginContainer.L_LeftBg.L_TileTexture.L_CellRoot.L_LeftCell; /// /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorTerrain.HSplitContainer.LeftBottom.MarginContainer.LeftBg.TileTexture.MaskBrush @@ -441,6 +501,16 @@ public LeftBottom S_LeftBottom => L_HSplitContainer.L_LeftBottom; /// + /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorTerrain.HSplitContainer.LeftBottom2.MarginContainer.LeftBottomBg.TileTexture.CellRoot.RightCell.CellTexture + /// + public CellTexture S_CellTexture => L_HSplitContainer.L_LeftBottom2.L_MarginContainer.L_LeftBottomBg.L_TileTexture.L_CellRoot.L_RightCell.L_CellTexture; + + /// + /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorTerrain.HSplitContainer.LeftBottom2.MarginContainer.LeftBottomBg.TileTexture.CellRoot.RightCell + /// + public RightCell S_RightCell => L_HSplitContainer.L_LeftBottom2.L_MarginContainer.L_LeftBottomBg.L_TileTexture.L_CellRoot.L_RightCell; + + /// /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorTerrain.HSplitContainer.LeftBottom2.MarginContainer.LeftBottomBg.TileTexture.TileShadow /// public TileShadow S_TileShadow => L_HSplitContainer.L_LeftBottom2.L_MarginContainer.L_LeftBottomBg.L_TileTexture.L_TileShadow; diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs index 90a3d7c..4e3cffa 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs @@ -15,7 +15,8 @@ /// public bool IsDraggingCell { get; set; } - private UiGrid _grid; + private UiGrid _leftGrid; + private UiGrid _rightGrid; public override void OnCreateUi() { @@ -23,36 +24,69 @@ //改变纹理事件 AddEventListener(EventEnum.OnSetTileTexture, OnSetTileTexture); + //背景颜色改变 + AddEventListener(EventEnum.OnSetTileSetBgColor, OnChangeTileSetBgColor); + + _leftGrid = CreateUiGrid(S_LeftCell); + _leftGrid.SetCellOffset(Vector2I.Zero); - _grid = CreateUiGrid(S_Cell); - _grid.SetCellOffset(Vector2I.Zero); + var sRightCell = S_RightCell; + var tileShadowSize = S_TileShadow.Instance.Texture.GetSize().AsVector2I(); + tileShadowSize = tileShadowSize / GameConfig.TileCellSize - new Vector2I(2, 2); + Debug.Log("tileShadowSize: " + tileShadowSize); + sRightCell.Instance.Position = GameConfig.TileCellSizeVector2I; + _rightGrid = CreateUiGrid(sRightCell); + _rightGrid.SetCellOffset(Vector2I.Zero); + _rightGrid.SetColumns(tileShadowSize.X); + for (var y = 0; y < tileShadowSize.Y; y++) + { + for (var x = 0; x < tileShadowSize.X; x++) + { + _rightGrid.Add(false); + } + } + OnSetTileTexture(EditorPanel.Texture); + OnChangeTileSetBgColor(EditorPanel.BgColor); } public override void OnDestroyUi() { } - + + public override void Process(float delta) + { + S_MaskBrush.Instance.Visible = !IsDraggingCell; + } + //改变TileSet纹理 private void OnSetTileTexture(object arg) { S_LeftBg.Instance.OnChangeTileSetTexture(); - _grid.RemoveAll(); + _leftGrid.RemoveAll(); var cellHorizontal = EditorPanel.CellHorizontal; if (cellHorizontal <= 0) { return; } var cellVertical = EditorPanel.CellVertical; - _grid.SetColumns(cellHorizontal); + _leftGrid.SetColumns(cellHorizontal); for (var y = 0; y < cellVertical; y++) { for (var x = 0; x < cellHorizontal; x++) { - _grid.Add(new Rect2I(x * GameConfig.TileCellSize, y * GameConfig.TileCellSize, GameConfig.TileCellSize, GameConfig.TileCellSize)); + _leftGrid.Add(new Rect2I(x * GameConfig.TileCellSize, y * GameConfig.TileCellSize, GameConfig.TileCellSize, GameConfig.TileCellSize)); } } } + + //更改背景颜色 + private void OnChangeTileSetBgColor(object obj) + { + S_LeftBg.Instance.Color = EditorPanel.BgColor; + S_LeftBottomBg.Instance.Color = EditorPanel.BgColor; + S_TileShadow.Instance.Modulate = EditorPanel.BgColor; + } } diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/left/MaskCell.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/left/MaskCell.cs index cf22503..1c2a77a 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/left/MaskCell.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/left/MaskCell.cs @@ -2,39 +2,18 @@ namespace UI.TileSetEditorTerrain; -public class MaskCell : UiCell +public class MaskCell : UiCell { public override void OnInit() { - CellNode.Instance.DragOutline = false; - CellNode.Instance.InitTexture(CellNode.UiPanel.S_LeftBg.L_TileTexture.Instance); - CellNode.Instance.AddDragListener(OnDrag); + CellNode.Instance.Init(this); } public override void OnSetData(Rect2I data) { CellNode.Instance.SetRect(data); } - - public override void Process(float delta) - { - CellNode.Instance.QueueRedraw(); - } - - private void OnDrag(DragState state, Vector2 delta) - { - if (state == DragState.DragStart) - { - CellNode.UiPanel.IsDraggingCell = true; - Grid.SelectIndex = Index; - Debug.Log($"data: {Data}"); - } - else if (state == DragState.DragEnd) - { - CellNode.UiPanel.IsDraggingCell = false; - } - } - + public override void OnSelect() { CellNode.Instance.DragOutline = true; diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/left/TerrainCellDragHandler.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/left/TerrainCellDragHandler.cs index 266dd52..fc0c25a 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/left/TerrainCellDragHandler.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/left/TerrainCellDragHandler.cs @@ -12,11 +12,15 @@ private TextureRect _textureRect; private Texture2D _texture; private Rect2I _rect2I; + private MaskCell _maskCell; + private TileSetEditorTerrainPanel _panel; - public void InitTexture(TextureRect textureRect) + public void Init(MaskCell maskCell) { - _textureRect = textureRect; - _texture = textureRect.Texture; + _maskCell = maskCell; + _panel = maskCell.CellNode.UiPanel; + _textureRect = _panel.S_LeftBg.L_TileTexture.Instance; + _texture = _textureRect.Texture; } public void SetRect(Rect2I rect) @@ -26,14 +30,20 @@ public override void _Process(double delta) { - if (DragOutline) + QueueRedraw(); + if (_maskCell.Grid.SelectIndex == _maskCell.Index && _panel.IsDraggingCell) { - QueueRedraw(); + if (!Input.IsActionPressed(InputAction.MouseLeft)) + { + _panel.IsDraggingCell = false; + } } } public override Variant _GetDragData(Vector2 atPosition) { + _panel.IsDraggingCell = true; + _maskCell.Grid.SelectIndex = _maskCell.Index; var sprite = new Sprite2D(); sprite.Texture = _texture; sprite.RegionEnabled = true; @@ -41,9 +51,9 @@ var control = new Control(); control.AddChild(sprite); control.ZIndex = 10; - control.Scale = _textureRect.Scale; + control.Scale = _panel.S_LeftBottomBg.L_TileTexture.Instance.Scale; SetDragPreview(control); - return ""; + return _rect2I; } public override void _Draw() diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/right/TerrainBrush.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/right/TerrainBrush.cs index 4793d95..52ba052 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/right/TerrainBrush.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/right/TerrainBrush.cs @@ -2,21 +2,10 @@ namespace UI.TileSetEditorTerrain; -public partial class TerrainBrush : Control, IUiNodeScript +public partial class TerrainBrush : Control { - public TileSetEditorTerrain.TileTexture_1 TileTexture { get; set; } + public TextureRect TileTexture { get; set; } - private TileSetEditorTerrain.Brush _brush; - - public void SetUiNode(IUiNode uiNode) - { - _brush = (TileSetEditorTerrain.Brush)uiNode; - } - - public void OnDestroy() - { - - } public override void _Process(double delta) { @@ -25,9 +14,20 @@ public override void _Draw() { + //绘制区域 DrawRect( new Rect2(GameConfig.TileCellSizeVector2I, - TileTexture.Instance.Texture.GetSize() - GameConfig.TileCellSizeVector2I * 2), Colors.Green, false, - 2f / TileTexture.Instance.Scale.X); + TileTexture.Texture.GetSize() - GameConfig.TileCellSizeVector2I * 2), new Color(1, 1, 0, 0.5f), false, + 2f / TileTexture.Scale.X); + + //绘制鼠标悬停区域 + if (TileTexture.IsMouseInRect(GameConfig.TileCellSize)) + { + var pos = Utils.GetMouseCellPosition(TileTexture) * GameConfig.TileCellSize; + DrawRect( + new Rect2(pos,GameConfig.TileCellSizeVector2I), + Colors.Green, false, 3f / TileTexture.Scale.X + ); + } } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/right/TerrainCell.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/right/TerrainCell.cs new file mode 100644 index 0000000..a63671f --- /dev/null +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/right/TerrainCell.cs @@ -0,0 +1,11 @@ +using Godot; + +namespace UI.TileSetEditorTerrain; + +public class TerrainCell : UiCell +{ + public override void OnInit() + { + CellNode.Instance.Init(this); + } +} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/right/TerrainCellDropHandler.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/right/TerrainCellDropHandler.cs new file mode 100644 index 0000000..e3387d9 --- /dev/null +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/right/TerrainCellDropHandler.cs @@ -0,0 +1,46 @@ +using Godot; + +namespace UI.TileSetEditorTerrain; + +public partial class TerrainCellDropHandler : Control +{ + /// + /// 是否放置了图块 + /// + public bool IsPutDownTexture { get; set; } + + private TerrainCell _cell; + private TileSetEditorTerrainPanel _panel; + + public void Init(TerrainCell cell) + { + _cell = cell; + _panel = cell.CellNode.UiPanel; + } + + public override bool _CanDropData(Vector2 atPosition, Variant data) + { + return data.VariantType == Variant.Type.Rect2I; + } + + public override void _DropData(Vector2 atPosition, Variant data) + { + var rect = data.AsRect2I(); + var sprite2D = _cell.CellNode.L_CellTexture.Instance; + sprite2D.Texture = _panel.EditorPanel.Texture; + sprite2D.RegionEnabled = true; + sprite2D.RegionRect = rect; + IsPutDownTexture = true; + } + + public override void _GuiInput(InputEvent @event) + { + //右键擦除图块 + if (@event is InputEventMouseButton mouseEvent && mouseEvent.ButtonIndex == MouseButton.Right && mouseEvent.Pressed) + { + AcceptEvent(); + _cell.CellNode.L_CellTexture.Instance.Texture = null; + IsPutDownTexture = false; + } + } +} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/right/TileEditTerrain.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/right/TileEditTerrain.cs index d069044..e05df44 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/right/TileEditTerrain.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/right/TileEditTerrain.cs @@ -7,8 +7,9 @@ public override void SetUiNode(IUiNode uiNode) { base.SetUiNode(uiNode); - InitNode(UiNode.L_TileTexture.Instance, UiNode.L_Grid.Instance); - UiNode.L_TileTexture.L_Brush.Instance.TileTexture = UiNode.L_TileTexture; + var tileTexture = UiNode.L_TileTexture; + InitNode(tileTexture.Instance, UiNode.L_Grid.Instance); + tileTexture.L_Brush.Instance.TileTexture = tileTexture.Instance; //聚焦按钮点击 UiNode.L_FocusBtn.Instance.Pressed += OnFocusClick;