diff --git a/DungeonShooting_Godot/prefab/ui/TileSetEditorTerrain.tscn b/DungeonShooting_Godot/prefab/ui/TileSetEditorTerrain.tscn
index b6154e8..f486d98 100644
--- a/DungeonShooting_Godot/prefab/ui/TileSetEditorTerrain.tscn
+++ b/DungeonShooting_Godot/prefab/ui/TileSetEditorTerrain.tscn
@@ -1,16 +1,14 @@
-[gd_scene load_steps=12 format=3 uid="uid://dfqb73y4br8yd"]
+[gd_scene load_steps=10 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/down/TileEditArea.cs" id="2_ynf0r"]
[ext_resource type="Script" path="res://src/game/common/ui/EditorMaskBrush.cs" id="3_gydh0"]
-[ext_resource type="Script" path="res://src/game/ui/tileSetEditorTerrain/down/TerrainCellDragHandler.cs" id="3_ssd86"]
[ext_resource type="Script" path="res://src/game/ui/tileSetEditorTerrain/up/TileEditTerrain.cs" id="5_0x7yx"]
[ext_resource type="Texture2D" uid="uid://d2wslibovwv7w" path="res://resource/sprite/ui/commonIcon/CenterTool.png" id="5_08bc4"]
[ext_resource type="Texture2D" uid="uid://bud6ah5xyey37" path="res://resource/sprite/map/TerrainMask2.png" id="5_xabgh"]
[ext_resource type="Texture2D" uid="uid://chisfq2alcq16" path="res://resource/sprite/map/TerrainMask3.png" id="6_vmj5y"]
[ext_resource type="Texture2D" uid="uid://cvjj6jnmxgprw" path="res://resource/sprite/map/TerrainMask.png" id="7_g8dxk"]
[ext_resource type="Script" path="res://src/game/ui/tileSetEditorTerrain/up/TerrainBrush.cs" id="7_lmu64"]
-[ext_resource type="Script" path="res://src/game/ui/tileSetEditorTerrain/up/TerrainCellDropHandler.cs" id="8_7xxcq"]
[node name="TileSetEditorTerrain" type="Control"]
layout_mode = 3
@@ -20,7 +18,6 @@
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_6jjk7")
-Layer = null
[node name="VSplitContainer" type="VSplitContainer" parent="."]
layout_mode = 1
@@ -84,7 +81,6 @@
offset_right = 16.0
offset_bottom = 16.0
mouse_filter = 1
-script = ExtResource("8_7xxcq")
[node name="CellTexture" type="Sprite2D" parent="VSplitContainer/PanelTop/MarginContainer/TopBg/TerrainRoot/CellRoot/RightCell"]
centered = false
@@ -221,12 +217,11 @@
offset_bottom = 1.0
mouse_filter = 2
-[node name="BottomCell" type="TextureButton" parent="VSplitContainer/PanelBottom/MarginContainer/BottomBg/TileTexture/CellRoot"]
-layout_mode = 0
+[node name="BottomCell" type="Control" parent="VSplitContainer/PanelBottom/MarginContainer/BottomBg/TileTexture/CellRoot"]
+anchors_preset = 0
offset_right = 16.0
offset_bottom = 16.0
mouse_filter = 1
-script = ExtResource("3_ssd86")
[node name="MaskBrush" type="Control" parent="VSplitContainer/PanelBottom/MarginContainer/BottomBg/TileTexture"]
layout_mode = 1
@@ -262,3 +257,7 @@
texture_normal = ExtResource("5_08bc4")
ignore_texture_size = true
stretch_mode = 5
+
+[node name="DragSprite" type="Sprite2D" parent="."]
+z_index = 10
+region_enabled = true
diff --git a/DungeonShooting_Godot/resource/map/tileSet/TileSet1/Main.png b/DungeonShooting_Godot/resource/map/tileSet/TileSet1/Main.png
index 83a63c2..c3cbdb1 100644
--- a/DungeonShooting_Godot/resource/map/tileSet/TileSet1/Main.png
+++ b/DungeonShooting_Godot/resource/map/tileSet/TileSet1/Main.png
Binary files differ
diff --git a/DungeonShooting_Godot/resource/map/tileSet/TileSet2/Main.png b/DungeonShooting_Godot/resource/map/tileSet/TileSet2/Main.png
new file mode 100644
index 0000000..d74eba2
--- /dev/null
+++ b/DungeonShooting_Godot/resource/map/tileSet/TileSet2/Main.png
Binary files differ
diff --git a/DungeonShooting_Godot/resource/map/tileSet/TileSet2/Main.png.import b/DungeonShooting_Godot/resource/map/tileSet/TileSet2/Main.png.import
new file mode 100644
index 0000000..be7dd76
--- /dev/null
+++ b/DungeonShooting_Godot/resource/map/tileSet/TileSet2/Main.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://c6pesrr162s6"
+path="res://.godot/imported/Main.png-d5a6dac6cf1a2b2af633c597ddadfe73.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://resource/map/tileSet/TileSet2/Main.png"
+dest_files=["res://.godot/imported/Main.png-d5a6dac6cf1a2b2af633c597ddadfe73.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/normal_map_invert_y=false
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1
diff --git a/DungeonShooting_Godot/resource/map/tileSet/TileSet2/Test2.png b/DungeonShooting_Godot/resource/map/tileSet/TileSet2/Test2.png
new file mode 100644
index 0000000..d74eba2
--- /dev/null
+++ b/DungeonShooting_Godot/resource/map/tileSet/TileSet2/Test2.png
Binary files differ
diff --git a/DungeonShooting_Godot/resource/map/tileSet/TileSet2/Test2.png.import b/DungeonShooting_Godot/resource/map/tileSet/TileSet2/Test2.png.import
new file mode 100644
index 0000000..2dd9ddc
--- /dev/null
+++ b/DungeonShooting_Godot/resource/map/tileSet/TileSet2/Test2.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://dslcjy284qx53"
+path="res://.godot/imported/Test2.png-427a8c43a36ea928d410624045881fbb.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://resource/map/tileSet/TileSet2/Test2.png"
+dest_files=["res://.godot/imported/Test2.png-427a8c43a36ea928d410624045881fbb.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/normal_map_invert_y=false
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1
diff --git a/DungeonShooting_Godot/resource/map/tileSet/TileSet2/TileSet.json b/DungeonShooting_Godot/resource/map/tileSet/TileSet2/TileSet.json
new file mode 100644
index 0000000..a7c8f84
--- /dev/null
+++ b/DungeonShooting_Godot/resource/map/tileSet/TileSet2/TileSet.json
@@ -0,0 +1,345 @@
+{
+ "Name": "TileSet2",
+ "Sources": [
+ {
+ "Name": "Main",
+ "SourcePath": "resource/map/tileSet/TileSet2/Main.png",
+ "Terrain": {
+ "F": {},
+ "M": {
+ "1": [
+ 16,
+ 32
+ ],
+ "2": [
+ 32,
+ 32
+ ]
+ },
+ "T": {
+ "432": [
+ 16,
+ 32
+ ]
+ }
+ },
+ "Combination": [
+ {
+ "Id": "638404496948408912",
+ "Name": "\u7EC4\u5408",
+ "Cells": [
+ {
+ "X": 160,
+ "Y": 128
+ },
+ {
+ "X": 176,
+ "Y": 128
+ },
+ {
+ "X": 192,
+ "Y": 128
+ },
+ {
+ "X": 208,
+ "Y": 128
+ },
+ {
+ "X": 224,
+ "Y": 128
+ },
+ {
+ "X": 240,
+ "Y": 128
+ },
+ {
+ "X": 240,
+ "Y": 144
+ },
+ {
+ "X": 224,
+ "Y": 144
+ },
+ {
+ "X": 208,
+ "Y": 144
+ },
+ {
+ "X": 192,
+ "Y": 144
+ },
+ {
+ "X": 176,
+ "Y": 144
+ },
+ {
+ "X": 160,
+ "Y": 144
+ },
+ {
+ "X": 160,
+ "Y": 128
+ },
+ {
+ "X": 176,
+ "Y": 128
+ },
+ {
+ "X": 192,
+ "Y": 128
+ },
+ {
+ "X": 208,
+ "Y": 128
+ },
+ {
+ "X": 224,
+ "Y": 128
+ },
+ {
+ "X": 240,
+ "Y": 128
+ },
+ {
+ "X": 240,
+ "Y": 144
+ },
+ {
+ "X": 224,
+ "Y": 144
+ },
+ {
+ "X": 208,
+ "Y": 144
+ },
+ {
+ "X": 192,
+ "Y": 144
+ },
+ {
+ "X": 176,
+ "Y": 144
+ },
+ {
+ "X": 160,
+ "Y": 144
+ }
+ ],
+ "Positions": [
+ {
+ "X": 0,
+ "Y": 0
+ },
+ {
+ "X": 16,
+ "Y": 0
+ },
+ {
+ "X": 32,
+ "Y": 0
+ },
+ {
+ "X": 48,
+ "Y": 0
+ },
+ {
+ "X": 64,
+ "Y": 0
+ },
+ {
+ "X": 80,
+ "Y": 0
+ },
+ {
+ "X": 80,
+ "Y": 16
+ },
+ {
+ "X": 64,
+ "Y": 16
+ },
+ {
+ "X": 48,
+ "Y": 16
+ },
+ {
+ "X": 32,
+ "Y": 16
+ },
+ {
+ "X": 16,
+ "Y": 16
+ },
+ {
+ "X": 0,
+ "Y": 16
+ },
+ {
+ "X": 0,
+ "Y": 32
+ },
+ {
+ "X": 16,
+ "Y": 32
+ },
+ {
+ "X": 32,
+ "Y": 32
+ },
+ {
+ "X": 48,
+ "Y": 32
+ },
+ {
+ "X": 64,
+ "Y": 32
+ },
+ {
+ "X": 80,
+ "Y": 32
+ },
+ {
+ "X": 80,
+ "Y": 48
+ },
+ {
+ "X": 64,
+ "Y": 48
+ },
+ {
+ "X": 48,
+ "Y": 48
+ },
+ {
+ "X": 32,
+ "Y": 48
+ },
+ {
+ "X": 16,
+ "Y": 48
+ },
+ {
+ "X": 0,
+ "Y": 48
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "Name": "Test2",
+ "SourcePath": "resource/map/tileSet/TileSet2/Test2.png",
+ "Terrain": {
+ "F": {},
+ "M": {},
+ "T": {}
+ },
+ "Combination": [
+ {
+ "Id": "638404127381228219",
+ "Name": "\u67F1\u5B50",
+ "Cells": [
+ {
+ "X": 224,
+ "Y": 64
+ },
+ {
+ "X": 224,
+ "Y": 80
+ },
+ {
+ "X": 224,
+ "Y": 96
+ },
+ {
+ "X": 224,
+ "Y": 64
+ },
+ {
+ "X": 224,
+ "Y": 80
+ },
+ {
+ "X": 224,
+ "Y": 96
+ },
+ {
+ "X": 224,
+ "Y": 64
+ },
+ {
+ "X": 224,
+ "Y": 80
+ },
+ {
+ "X": 224,
+ "Y": 96
+ },
+ {
+ "X": 224,
+ "Y": 64
+ },
+ {
+ "X": 224,
+ "Y": 80
+ },
+ {
+ "X": 224,
+ "Y": 96
+ }
+ ],
+ "Positions": [
+ {
+ "X": 48,
+ "Y": 0
+ },
+ {
+ "X": 48,
+ "Y": 16
+ },
+ {
+ "X": 48,
+ "Y": 32
+ },
+ {
+ "X": 32,
+ "Y": 0
+ },
+ {
+ "X": 32,
+ "Y": 16
+ },
+ {
+ "X": 32,
+ "Y": 32
+ },
+ {
+ "X": 16,
+ "Y": 0
+ },
+ {
+ "X": 16,
+ "Y": 16
+ },
+ {
+ "X": 16,
+ "Y": 32
+ },
+ {
+ "X": 0,
+ "Y": 0
+ },
+ {
+ "X": 0,
+ "Y": 16
+ },
+ {
+ "X": 0,
+ "Y": 32
+ }
+ ]
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/resource/map/tileSet/TileSetConfig.json b/DungeonShooting_Godot/resource/map/tileSet/TileSetConfig.json
index 052c022..d7d71d6 100644
--- a/DungeonShooting_Godot/resource/map/tileSet/TileSetConfig.json
+++ b/DungeonShooting_Godot/resource/map/tileSet/TileSetConfig.json
@@ -3,5 +3,10 @@
"ErrorType": 0,
"Path": "resource/map/tileSet/TileSet1",
"Remark": ""
+ },
+ "TileSet2": {
+ "ErrorType": 0,
+ "Path": "resource/map/tileSet/TileSet2",
+ "Remark": ""
}
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/framework/ui/grid/UiGrid.cs b/DungeonShooting_Godot/src/framework/ui/grid/UiGrid.cs
index c341827..db987d8 100644
--- a/DungeonShooting_Godot/src/framework/ui/grid/UiGrid.cs
+++ b/DungeonShooting_Godot/src/framework/ui/grid/UiGrid.cs
@@ -286,6 +286,20 @@
callback(uiCell);
}
}
+
+ ///
+ /// 遍历所有 Cell, 回调函数返回 false 跳出循环
+ ///
+ public void ForEach(Func, bool> callback)
+ {
+ foreach (var uiCell in _cellList)
+ {
+ if (!callback(uiCell))
+ {
+ return;
+ }
+ }
+ }
///
/// 设置当前网格组件中的所有 Cell 数据, 性能较低
diff --git a/DungeonShooting_Godot/src/game/common/ui/EditorGridBg.cs b/DungeonShooting_Godot/src/game/common/ui/EditorGridBg.cs
index 45d75c1..44dbb5c 100644
--- a/DungeonShooting_Godot/src/game/common/ui/EditorGridBg.cs
+++ b/DungeonShooting_Godot/src/game/common/ui/EditorGridBg.cs
@@ -19,6 +19,7 @@
public T UiNode { get; private set; }
private ShaderMaterial _gridMaterial;
+ private bool _dragMoveFlag = false;
///
/// 初始化节点数据
@@ -75,10 +76,24 @@
//拖拽回调
private void OnDrag(DragState state, Vector2 pos)
{
- if (state == DragState.DragMove)
+ if (state == DragState.DragStart)
{
- ContainerRoot.Position += pos;
- RefreshGridTrans();
+ if (this.IsMouseInRect())
+ {
+ _dragMoveFlag = true;
+ }
+ }
+ else if (state == DragState.DragMove)
+ {
+ if (_dragMoveFlag)
+ {
+ ContainerRoot.Position += pos;
+ RefreshGridTrans();
+ }
+ }
+ else
+ {
+ _dragMoveFlag = false;
}
}
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs
index 96d3367..5695611 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs
@@ -241,7 +241,12 @@
{
var optionButton = S_OptionButton.Instance;
var selectIndex = optionButton.Selected;
- if (selectIndex >= 0)
+ if (selectIndex == 0)
+ {
+ EditorWindowManager.ShowTips("警告", "不允许删除 Main Source!");
+ return;
+ }
+ else if (selectIndex > 0)
{
EditorWindowManager.ShowConfirm("提示", "是否需要删除该资源!", v =>
{
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorProject/TileSetEditorProjectPanel.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorProject/TileSetEditorProjectPanel.cs
index 75a55a4..535bda5 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditorProject/TileSetEditorProjectPanel.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorProject/TileSetEditorProjectPanel.cs
@@ -1,5 +1,4 @@
using System.IO;
-using System.Text.Json;
using Godot;
namespace UI.TileSetEditorProject;
@@ -83,6 +82,12 @@
var tileSetInfo = new TileSetInfo();
tileSetInfo.InitData();
tileSetInfo.Name = name;
+ //默认创建一个Main Source, 该Source不可删除
+ var tileSetSourceInfo = new TileSetSourceInfo();
+ tileSetSourceInfo.InitData();
+ tileSetSourceInfo.Name = "Main";
+ tileSetInfo.Sources.Add(tileSetSourceInfo);
+
split.SetTileSetInfo(tileSetInfo);
GameApplication.Instance.TileSetConfig.Add(name, split);
//保存TileSetInfo
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrain.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrain.cs
index cc586b7..0f40a5d 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrain.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrain.cs
@@ -18,6 +18,19 @@
}
private VSplitContainer _L_VSplitContainer;
+ ///
+ /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorTerrain.DragSprite
+ ///
+ public DragSprite L_DragSprite
+ {
+ get
+ {
+ if (_L_DragSprite == null) _L_DragSprite = new DragSprite((TileSetEditorTerrainPanel)this, GetNode("DragSprite"));
+ return _L_DragSprite;
+ }
+ }
+ private DragSprite _L_DragSprite;
+
public TileSetEditorTerrain() : base(nameof(TileSetEditorTerrain))
{
@@ -40,9 +53,9 @@
}
///
- /// 类型: , 路径: TileSetEditorTerrain.VSplitContainer.PanelTop.MarginContainer.TopBg.TerrainRoot.CellRoot.RightCell
+ /// 类型: , 路径: TileSetEditorTerrain.VSplitContainer.PanelTop.MarginContainer.TopBg.TerrainRoot.CellRoot.RightCell
///
- public class RightCell : UiNode
+ public class RightCell : UiNode
{
///
/// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorTerrain.VSplitContainer.PanelTop.MarginContainer.TopBg.TerrainRoot.CellRoot.CellTexture
@@ -57,8 +70,8 @@
}
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());
+ public RightCell(TileSetEditorTerrainPanel uiPanel, Godot.Control node) : base(uiPanel, node) { }
+ public override RightCell Clone() => new (UiPanel, (Godot.Control)Instance.Duplicate());
}
///
@@ -67,13 +80,13 @@
public class CellRoot : UiNode
{
///
- /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorTerrain.VSplitContainer.PanelTop.MarginContainer.TopBg.TerrainRoot.RightCell
+ /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorTerrain.VSplitContainer.PanelTop.MarginContainer.TopBg.TerrainRoot.RightCell
///
public RightCell L_RightCell
{
get
{
- if (_L_RightCell == null) _L_RightCell = new RightCell(UiPanel, Instance.GetNode("RightCell"));
+ if (_L_RightCell == null) _L_RightCell = new RightCell(UiPanel, Instance.GetNode("RightCell"));
return _L_RightCell;
}
}
@@ -370,12 +383,12 @@
}
///
- /// 类型: , 路径: TileSetEditorTerrain.VSplitContainer.PanelBottom.MarginContainer.BottomBg.TileTexture.CellRoot.BottomCell
+ /// 类型: , 路径: TileSetEditorTerrain.VSplitContainer.PanelBottom.MarginContainer.BottomBg.TileTexture.CellRoot.BottomCell
///
- public class BottomCell : UiNode
+ public class BottomCell : UiNode
{
- public BottomCell(TileSetEditorTerrainPanel uiPanel, UI.TileSetEditorTerrain.TerrainCellDragHandler node) : base(uiPanel, node) { }
- public override BottomCell Clone() => new (UiPanel, (UI.TileSetEditorTerrain.TerrainCellDragHandler)Instance.Duplicate());
+ public BottomCell(TileSetEditorTerrainPanel uiPanel, Godot.Control node) : base(uiPanel, node) { }
+ public override BottomCell Clone() => new (UiPanel, (Godot.Control)Instance.Duplicate());
}
///
@@ -384,13 +397,13 @@
public class CellRoot_1 : UiNode
{
///
- /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorTerrain.VSplitContainer.PanelBottom.MarginContainer.BottomBg.TileTexture.BottomCell
+ /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorTerrain.VSplitContainer.PanelBottom.MarginContainer.BottomBg.TileTexture.BottomCell
///
public BottomCell L_BottomCell
{
get
{
- if (_L_BottomCell == null) _L_BottomCell = new BottomCell(UiPanel, Instance.GetNode("BottomCell"));
+ if (_L_BottomCell == null) _L_BottomCell = new BottomCell(UiPanel, Instance.GetNode("BottomCell"));
return _L_BottomCell;
}
}
@@ -589,6 +602,15 @@
public override VSplitContainer Clone() => new (UiPanel, (Godot.VSplitContainer)Instance.Duplicate());
}
+ ///
+ /// 类型: , 路径: TileSetEditorTerrain.DragSprite
+ ///
+ public class DragSprite : UiNode
+ {
+ public DragSprite(TileSetEditorTerrainPanel uiPanel, Godot.Sprite2D node) : base(uiPanel, node) { }
+ public override DragSprite Clone() => new (UiPanel, (Godot.Sprite2D)Instance.Duplicate());
+ }
+
///
/// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorTerrain.VSplitContainer.PanelTop.MarginContainer.TopBg.TerrainRoot.CellRoot.RightCell.CellTexture
@@ -596,7 +618,7 @@
public CellTexture S_CellTexture => L_VSplitContainer.L_PanelTop.L_MarginContainer.L_TopBg.L_TerrainRoot.L_CellRoot.L_RightCell.L_CellTexture;
///
- /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorTerrain.VSplitContainer.PanelTop.MarginContainer.TopBg.TerrainRoot.CellRoot.RightCell
+ /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorTerrain.VSplitContainer.PanelTop.MarginContainer.TopBg.TerrainRoot.CellRoot.RightCell
///
public RightCell S_RightCell => L_VSplitContainer.L_PanelTop.L_MarginContainer.L_TopBg.L_TerrainRoot.L_CellRoot.L_RightCell;
@@ -636,7 +658,7 @@
public PanelTop S_PanelTop => L_VSplitContainer.L_PanelTop;
///
- /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorTerrain.VSplitContainer.PanelBottom.MarginContainer.BottomBg.TileTexture.CellRoot.BottomCell
+ /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorTerrain.VSplitContainer.PanelBottom.MarginContainer.BottomBg.TileTexture.CellRoot.BottomCell
///
public BottomCell S_BottomCell => L_VSplitContainer.L_PanelBottom.L_MarginContainer.L_BottomBg.L_TileTexture.L_CellRoot.L_BottomCell;
@@ -665,4 +687,9 @@
///
public VSplitContainer S_VSplitContainer => L_VSplitContainer;
+ ///
+ /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorTerrain.DragSprite
+ ///
+ public DragSprite S_DragSprite => L_DragSprite;
+
}
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs
index 2c95197..20f313c 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/TileSetEditorTerrainPanel.cs
@@ -11,9 +11,9 @@
public TileSetEditorPanel EditorPanel;
///
- /// 是否正在拖拽图块
+ /// 正在拖拽的图块
///
- public bool IsDraggingCell { get; set; }
+ public MaskCell DraggingCell { get; set; }
private UiGrid _topGrid1;
private UiGrid _topGrid2;
@@ -23,6 +23,7 @@
public override void OnCreateUi()
{
EditorPanel = (TileSetEditorPanel)ParentUi;
+ S_DragSprite.Instance.Visible = false;
//改变选中的TileSet资源
AddEventListener(EventEnum.OnSelectTileSetSource, OnSelectTileSetSource);
@@ -49,7 +50,7 @@
public override void Process(float delta)
{
- S_MaskBrush.Instance.Visible = !IsDraggingCell;
+ S_MaskBrush.Instance.Visible = DraggingCell == null;
}
private UiGrid InitTopGrid(Control texture, Vector2I size, byte type)
@@ -75,9 +76,9 @@
private void OnSelectTileSetSource(object obj)
{
//先清除所有绑定的Terrain
- _topGrid1.ForEach(cell => cell.CellNode.Instance.ClearCell());
- _topGrid2.ForEach(cell => cell.CellNode.Instance.ClearCell());
- _topGrid3.ForEach(cell => cell.CellNode.Instance.ClearCell());
+ _topGrid1.ForEach(cell => ((TerrainCell)cell).ClearCell());
+ _topGrid2.ForEach(cell => ((TerrainCell)cell).ClearCell());
+ _topGrid3.ForEach(cell => ((TerrainCell)cell).ClearCell());
//再加载Terrain
if (obj != null)
@@ -88,7 +89,7 @@
var ints = terrain.GetTerrainCell( cell.Index, cell.Data);
if (ints != null)
{
- cell.CellNode.Instance.SetCell(new Rect2I(ints[0], ints[1], GameConfig.TileCellSize, GameConfig.TileCellSize));
+ ((TerrainCell)cell).SetCell(new Rect2I(ints[0], ints[1], GameConfig.TileCellSize, GameConfig.TileCellSize));
}
});
_topGrid2.ForEach(cell =>
@@ -96,7 +97,7 @@
var ints = terrain.GetTerrainCell(cell.Index, cell.Data);
if (ints != null)
{
- cell.CellNode.Instance.SetCell(new Rect2I(ints[0], ints[1], GameConfig.TileCellSize, GameConfig.TileCellSize));
+ ((TerrainCell)cell).SetCell(new Rect2I(ints[0], ints[1], GameConfig.TileCellSize, GameConfig.TileCellSize));
}
});
_topGrid3.ForEach(cell =>
@@ -104,12 +105,40 @@
var ints = terrain.GetTerrainCell( cell.Index, cell.Data);
if (ints != null)
{
- cell.CellNode.Instance.SetCell(new Rect2I(ints[0], ints[1], GameConfig.TileCellSize, GameConfig.TileCellSize));
+ ((TerrainCell)cell).SetCell(new Rect2I(ints[0], ints[1], GameConfig.TileCellSize, GameConfig.TileCellSize));
}
});
}
}
+ ///
+ /// 放置地形Cell纹理
+ ///
+ public void OnDropCell(MaskCell maskCell)
+ {
+ var flag = true;
+ _topGrid1.ForEach((cell) =>
+ {
+ flag = !((TerrainCell)cell).OnDropCell(maskCell);
+ return flag;
+ });
+ if (flag)
+ {
+ _topGrid2.ForEach((cell) =>
+ {
+ flag = !((TerrainCell)cell).OnDropCell(maskCell);
+ return flag;
+ });
+ }
+ if (flag)
+ {
+ _topGrid3.ForEach((cell) =>
+ {
+ return ((TerrainCell)cell).OnDropCell(maskCell);
+ });
+ }
+ }
+
//改变TileSet纹理
private void OnSetTileTexture(object arg)
{
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/TerrainCellDragHandler.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/TerrainCellDragHandler.cs
deleted file mode 100644
index acb84b2..0000000
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/TerrainCellDragHandler.cs
+++ /dev/null
@@ -1,70 +0,0 @@
-using Godot;
-
-namespace UI.TileSetEditorTerrain;
-
-public partial class TerrainCellDragHandler : TextureButton
-{
- ///
- /// 是否绘制轮廓
- ///
- public bool DragOutline { get; set; } = false;
-
- private TextureRect _textureRect;
- private Texture2D _texture;
- private Rect2I _rect2I;
- private MaskCell _maskCell;
- private TileSetEditorTerrainPanel _panel;
-
- public void Init(MaskCell maskCell)
- {
- _maskCell = maskCell;
- _panel = maskCell.CellNode.UiPanel;
- _textureRect = _panel.S_BottomBg.L_TileTexture.Instance;
- _texture = _textureRect.Texture;
- }
-
- public void SetRect(Rect2I rect)
- {
- _rect2I = rect;
- }
-
- public override void _Process(double delta)
- {
- QueueRedraw();
- if (_maskCell.Grid.SelectIndex == _maskCell.Index && _panel.IsDraggingCell)
- {
- 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;
- sprite.RegionRect = _rect2I;
- var control = new Control();
- control.AddChild(sprite);
- control.ZIndex = 10;
- control.Scale = _panel.S_TopBg.L_TerrainRoot.Instance.Scale;
- SetDragPreview(control);
- return _rect2I;
- }
-
- public override void _Draw()
- {
- if (DragOutline)
- {
- //选中时绘制轮廓
- DrawRect(
- new Rect2(Vector2.Zero, Size),
- new Color(0, 1, 1), false, 2f / _textureRect.Scale.X
- );
- }
- }
-}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TerrainCell.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TerrainCell.cs
index f73831e..00c9deb 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TerrainCell.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TerrainCell.cs
@@ -4,8 +4,91 @@
public class TerrainCell : UiCell
{
+ ///
+ /// 是否放置了图块
+ ///
+ public bool IsPutDownTexture { get; private set; }
+
+ ///
+ /// 图块在 Source 中的位置, 单位: 像素
+ ///
+ public Vector2I TextureCell { get; private set; }
+
+ private TileSetEditorTerrainPanel _panel;
+
public override void OnInit()
{
- CellNode.Instance.Init(this);
+ _panel = CellNode.UiPanel;
+ CellNode.Instance.GuiInput += OnGuiInput;
+ }
+
+ public bool OnDropCell(MaskCell maskCell)
+ {
+ if (CellNode.Instance.IsMouseInRect())
+ {
+ OnDropData(maskCell);
+ return true;
+ }
+
+ return false;
+ }
+
+ private void OnGuiInput(InputEvent @event)
+ {
+ if (@event is InputEventMouseButton mouseEvent)
+ {
+ if (mouseEvent.ButtonIndex == MouseButton.Right && mouseEvent.Pressed) //右键擦除图块
+ {
+ CellNode.Instance.AcceptEvent();
+ var flag = IsPutDownTexture;
+ ClearCell();
+ if (flag)
+ {
+ SetTerrainBitData(null);
+ }
+ }
+ }
+ }
+
+ ///
+ /// 设置选择的Cell
+ ///
+ public void SetCell(Rect2I rect)
+ {
+ TextureCell = rect.Position;
+ var sprite2D = CellNode.L_CellTexture.Instance;
+ sprite2D.Texture = _panel.EditorPanel.Texture;
+ sprite2D.RegionEnabled = true;
+ sprite2D.RegionRect = rect;
+ IsPutDownTexture = true;
+ }
+
+ ///
+ /// 清除选中的cell
+ ///
+ public void ClearCell()
+ {
+ CellNode.L_CellTexture.Instance.Texture = null;
+ IsPutDownTexture = false;
+ }
+
+ private void OnDropData(MaskCell maskCell)
+ {
+ SetCell(maskCell.Data);
+ SetTerrainBitData(new []{ TextureCell.X, TextureCell.Y });
+ }
+
+ private void SetTerrainBitData(int[] cellData)
+ {
+ if (cellData == null)
+ {
+ _panel.EditorPanel.TileSetSourceInfo.Terrain.RemoveTerrainCell(Index, Data);
+ }
+ else
+ {
+ _panel.EditorPanel.TileSetSourceInfo.Terrain.SetTerrainCell(Index, Data, cellData);
+ }
+
+ EventManager.EmitEvent(EventEnum.OnTileSetDirty);
}
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TerrainCellDropHandler.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TerrainCellDropHandler.cs
deleted file mode 100644
index 2f7a0fc..0000000
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TerrainCellDropHandler.cs
+++ /dev/null
@@ -1,88 +0,0 @@
-using Godot;
-
-namespace UI.TileSetEditorTerrain;
-
-public partial class TerrainCellDropHandler : Control
-{
- ///
- /// 是否放置了图块
- ///
- public bool IsPutDownTexture { get; private set; }
-
- ///
- /// 图块在 Source 中的位置, 单位: 像素
- ///
- public Vector2I TextureCell { get; private 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();
- SetCell(rect);
- SetTerrainBitData(new []{ TextureCell.X, TextureCell.Y });
- }
-
- public override void _GuiInput(InputEvent @event)
- {
- //右键擦除图块
- if (@event is InputEventMouseButton mouseEvent && mouseEvent.ButtonIndex == MouseButton.Right && mouseEvent.Pressed)
- {
- AcceptEvent();
- var flag = IsPutDownTexture;
- ClearCell();
- if (flag)
- {
- SetTerrainBitData(null);
- }
- }
- }
-
- ///
- /// 设置选择的Cell
- ///
- public void SetCell(Rect2I rect)
- {
- TextureCell = rect.Position;
- var sprite2D = _cell.CellNode.L_CellTexture.Instance;
- sprite2D.Texture = _panel.EditorPanel.Texture;
- sprite2D.RegionEnabled = true;
- sprite2D.RegionRect = rect;
- IsPutDownTexture = true;
- }
-
- ///
- /// 清除选中的cell
- ///
- public void ClearCell()
- {
- _cell.CellNode.L_CellTexture.Instance.Texture = null;
- IsPutDownTexture = false;
- }
-
- private void SetTerrainBitData(int[] cellData)
- {
- if (cellData == null)
- {
- _panel.EditorPanel.TileSetSourceInfo.Terrain.RemoveTerrainCell(_cell.Index, _cell.Data);
- }
- else
- {
- _panel.EditorPanel.TileSetSourceInfo.Terrain.SetTerrainCell(_cell.Index, _cell.Data, cellData);
- }
-
- EventManager.EmitEvent(EventEnum.OnTileSetDirty);
- }
-}
\ No newline at end of file