diff --git a/DungeonShooting_Godot/prefab/ui/TileSetEditorCombination.tscn b/DungeonShooting_Godot/prefab/ui/TileSetEditorCombination.tscn
index c4f6702..4f906ac 100644
--- a/DungeonShooting_Godot/prefab/ui/TileSetEditorCombination.tscn
+++ b/DungeonShooting_Godot/prefab/ui/TileSetEditorCombination.tscn
@@ -52,7 +52,7 @@
[node name="LeftTop" type="Panel" parent="HSplitContainer/VSplitContainer"]
layout_mode = 2
size_flags_vertical = 3
-size_flags_stretch_ratio = 31.0
+size_flags_stretch_ratio = 40.0
[node name="MarginContainer" type="MarginContainer" parent="HSplitContainer/VSplitContainer/LeftTop"]
layout_mode = 1
@@ -90,6 +90,7 @@
mouse_filter = 2
[node name="BrushRoot" type="Node2D" parent="HSplitContainer/VSplitContainer/LeftTop/MarginContainer/LeftTopBg/CombinationRoot"]
+z_index = 1
[node name="Grid" type="ColorRect" parent="HSplitContainer/VSplitContainer/LeftTop/MarginContainer/LeftTopBg"]
material = SubResource("ShaderMaterial_df7va")
@@ -105,7 +106,7 @@
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
-size_flags_stretch_ratio = 68.0
+size_flags_stretch_ratio = 60.0
[node name="MarginContainer" type="MarginContainer" parent="HSplitContainer/VSplitContainer/LeftBottom"]
layout_mode = 1
diff --git a/DungeonShooting_Godot/src/game/event/EventEnum.cs b/DungeonShooting_Godot/src/game/event/EventEnum.cs
index 7cab6b1..b133ecd 100644
--- a/DungeonShooting_Godot/src/game/event/EventEnum.cs
+++ b/DungeonShooting_Godot/src/game/event/EventEnum.cs
@@ -159,9 +159,9 @@
///
/// 选中组合模式下的Cell图块, 参数为
///
- OnSelectContainerCell,
+ OnSelectCombinationCell,
///
/// 清除组合模式下的Cell图块
///
- OnClearContainerCell,
+ OnClearCombinationCell,
}
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/TileEditArea.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/TileEditArea.cs
index 47c6b9c..ec72cdd 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/TileEditArea.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/TileEditArea.cs
@@ -68,7 +68,7 @@
_useMask.Add(cell);
uiCell.SetData(true);
- EventManager.EmitEvent(EventEnum.OnSelectContainerCell, cell);
+ EventManager.EmitEvent(EventEnum.OnSelectCombinationCell, cell);
}
}
}
@@ -89,7 +89,7 @@
}
}
- EventManager.EmitEvent(EventEnum.OnClearContainerCell);
+ EventManager.EmitEvent(EventEnum.OnClearCombinationCell);
}
///
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/CombinationCell.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/CombinationCell.cs
index 9bb9880..416235d 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/CombinationCell.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/CombinationCell.cs
@@ -18,4 +18,13 @@
Texture = texture;
RegionRect = new Rect2(texturePos * GameConfig.TileCellSize, GameConfig.TileCellSizeVector2I);
}
+
+ ///
+ /// 从指定的组合单元克隆数据
+ ///
+ public void CloneFrom(CombinationCell combinationCell)
+ {
+ Texture = combinationCell.Texture;
+ RegionRect = combinationCell.RegionRect;
+ }
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs
index 053a89d..9fc4298 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs
@@ -5,13 +5,20 @@
public partial class TileEditCombination : GridBg
{
- //kay: 代表原图中的坐标
+ //kay: 代表原图中的坐标, 单位: 格
private Dictionary _brushData = new Dictionary();
+ //笔刷偏移, 单位: 像素
private Vector2I _brushOffset = Vector2I.Zero;
- private int _xStart = 0;
- private int _yStart = 0;
- private int _xEnd = 0;
- private int _yEnd = 0;
+ //上一帧笔刷位置
+ private Vector2 _brushPrevPos = Vector2.Zero;
+ private bool _initBrush = false;
+ private bool _drawBrushFlag = false;
+ private int _xStart = int.MaxValue;
+ private int _yStart = int.MaxValue;
+ private int _xEnd = int.MinValue;
+ private int _yEnd = int.MinValue;
+
+ private Dictionary _canvas = new Dictionary();
public override void SetUiNode(IUiNode uiNode)
{
@@ -19,8 +26,8 @@
Grid = UiNode.L_Grid.Instance;
ContainerRoot = UiNode.L_CombinationRoot.Instance;
- UiNode.UiPanel.AddEventListener(EventEnum.OnSelectContainerCell, OnSelectContainerCell);
- UiNode.UiPanel.AddEventListener(EventEnum.OnClearContainerCell, OnClearContainerCell);
+ UiNode.UiPanel.AddEventListener(EventEnum.OnSelectCombinationCell, OnSelectCombinationCell);
+ UiNode.UiPanel.AddEventListener(EventEnum.OnClearCombinationCell, OnClearCombinationCell);
}
public override void _Process(double delta)
@@ -30,37 +37,83 @@
return;
}
- UiNode.L_CombinationRoot.L_BrushRoot.Instance.Position = UiNode.L_CombinationRoot.Instance
- .GetLocalMousePosition().FloorAdsorption(GameConfig.TileCellSizeVector2I);
+ var brushRoot = UiNode.L_CombinationRoot.L_BrushRoot.Instance;
+ var combinationRoot = UiNode.L_CombinationRoot.Instance;
+ Vector2 newPos = combinationRoot.GetLocalMousePosition().FloorAdsorption(GameConfig.TileCellSizeVector2I) + _brushOffset;
+ brushRoot.Position = newPos;
+
+ //左键按下开始绘制
+ if (_initBrush && Input.IsMouseButtonPressed(MouseButton.Left) && this.IsMouseInRect())
+ {
+ if (_brushPrevPos != newPos || !_drawBrushFlag)
+ {
+ _drawBrushFlag = true;
+ _brushPrevPos = newPos;
+ DrawBrush();
+ }
+ }
+ else
+ {
+ _drawBrushFlag = false;
+ }
+ }
+
+ //绘制笔刷
+ private void DrawBrush()
+ {
+ var brushRoot = UiNode.L_CombinationRoot.L_BrushRoot.Instance;
+ foreach (var keyValuePair in _brushData)
+ {
+ var combinationCell = keyValuePair.Value;
+ var pos = (combinationCell.Position + brushRoot.Position).AsVector2I();
+ if (_canvas.TryGetValue(pos, out var canvasCell))
+ {
+ canvasCell.CloneFrom(combinationCell);
+ }
+ else
+ {
+ canvasCell = (CombinationCell)combinationCell.Duplicate();
+ canvasCell.Position = pos;
+ UiNode.L_CombinationRoot.AddChild(canvasCell);
+ _canvas.Add(pos, canvasCell);
+ }
+ }
}
- private void OnSelectContainerCell(object obj)
+ //选中组合的图块
+ private void OnSelectCombinationCell(object obj)
{
if (obj is Vector2I cell && !_brushData.ContainsKey(cell))
{
+ _initBrush = true;
var cellData = new CombinationCell();
- var pos = cell * GameConfig.TileCellSize + _brushOffset;
- cellData.Position = pos;
+ cellData.Position = cell * GameConfig.TileCellSize;
cellData.InitData(UiNode.UiPanel.EditorPanel.Texture, cell);
UiNode.L_CombinationRoot.L_BrushRoot.AddChild(cellData);
_brushData.Add(cell, cellData);
//计算起始点和终点
- //if (pos.X < _xStart || pos.X > _xEnd || pos.)
+ _xStart = Mathf.Min(cell.X, _xStart);
+ _yStart = Mathf.Min(cell.Y, _yStart);
+ _xEnd = Mathf.Max(cell.X, _xEnd);
+ _yEnd = Mathf.Max(cell.Y, _yEnd);
+ _brushOffset = new Vector2I(-(_xStart + (_xEnd - _xStart) / 2), -(_yStart + (_yEnd - _yStart) / 2)) * GameConfig.TileCellSize;
}
}
- private void OnClearContainerCell(object obj)
+ //移除组合图块
+ private void OnClearCombinationCell(object obj)
{
foreach (var keyValuePair in _brushData)
{
keyValuePair.Value.QueueFree();
}
_brushData.Clear();
+ _initBrush = false;
_brushOffset = Vector2I.Zero;
- _xStart = 0;
- _yStart = 0;
- _xEnd = 0;
- _yEnd = 0;
+ _xStart = int.MaxValue;
+ _yStart = int.MaxValue;
+ _xEnd = int.MinValue;
+ _yEnd = int.MinValue;
}
}
\ No newline at end of file