diff --git a/DungeonShooting_Godot/prefab/ui/EditorImportCombination.tscn b/DungeonShooting_Godot/prefab/ui/EditorImportCombination.tscn
index 26cf649..88bfb55 100644
--- a/DungeonShooting_Godot/prefab/ui/EditorImportCombination.tscn
+++ b/DungeonShooting_Godot/prefab/ui/EditorImportCombination.tscn
@@ -7,6 +7,8 @@
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
script = ExtResource("1_4wd6k")
[node name="MarginContainer" type="MarginContainer" parent="."]
@@ -54,7 +56,7 @@
horizontal_alignment = 2
vertical_alignment = 1
-[node name="RemarkInput" type="TextureRect" parent="MarginContainer/VBoxContainer/HBoxContainer2"]
+[node name="PreviewTexture" type="TextureRect" parent="MarginContainer/VBoxContainer/HBoxContainer2"]
custom_minimum_size = Vector2(0, 300)
layout_mode = 2
size_flags_horizontal = 3
diff --git a/DungeonShooting_Godot/prefab/ui/TileSetEditorCombination.tscn b/DungeonShooting_Godot/prefab/ui/TileSetEditorCombination.tscn
index 5bb24aa..e1af09c 100644
--- a/DungeonShooting_Godot/prefab/ui/TileSetEditorCombination.tscn
+++ b/DungeonShooting_Godot/prefab/ui/TileSetEditorCombination.tscn
@@ -294,6 +294,7 @@
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
+expand_mode = 2
stretch_mode = 5
[node name="CellId" type="Label" parent="HSplitContainer/Right/MarginContainer/RightBg/ScrollContainer/CellButton"]
@@ -302,11 +303,11 @@
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
-offset_top = -27.0
-offset_bottom = -3.0
+offset_top = -40.0
grow_horizontal = 2
grow_vertical = 0
-text = "#999"
+theme_override_font_sizes/font_size = 16
+text = "名称"
horizontal_alignment = 1
vertical_alignment = 1
clip_text = true
diff --git a/DungeonShooting_Godot/src/framework/map/tileSet/TileCombinationInfo.cs b/DungeonShooting_Godot/src/framework/map/tileSet/TileCombinationInfo.cs
new file mode 100644
index 0000000..0f2f48a
--- /dev/null
+++ b/DungeonShooting_Godot/src/framework/map/tileSet/TileCombinationInfo.cs
@@ -0,0 +1,8 @@
+
+///
+/// 组合图块数据
+///
+public class TileCombinationInfo
+{
+
+}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/data/ImportCombinationData.cs b/DungeonShooting_Godot/src/game/data/ImportCombinationData.cs
new file mode 100644
index 0000000..4a631c5
--- /dev/null
+++ b/DungeonShooting_Godot/src/game/data/ImportCombinationData.cs
@@ -0,0 +1,11 @@
+
+using Godot;
+
+///
+/// 导入的组合图块数据
+///
+public class ImportCombinationData
+{
+ public string Name { get; set; }
+ public Texture2D PreviewTexture { get; set; }
+}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/event/EventEnum.cs b/DungeonShooting_Godot/src/game/event/EventEnum.cs
index 431226d..dde9354 100644
--- a/DungeonShooting_Godot/src/game/event/EventEnum.cs
+++ b/DungeonShooting_Godot/src/game/event/EventEnum.cs
@@ -168,4 +168,8 @@
/// 清除组合模式下的Cell图块
///
OnClearCombinationCell,
+ ///
+ /// 导入组合, 参数为
+ ///
+ OnImportCombination,
}
diff --git a/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs b/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs
index 9c93ece..3de91cf 100644
--- a/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs
+++ b/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs
@@ -4,6 +4,7 @@
using Config;
using Godot;
using UI.EditorColorPicker;
+using UI.EditorImportCombination;
using UI.EditorTips;
using UI.EditorWindow;
using UI.MapEditorCreateGroup;
@@ -426,28 +427,35 @@
};
}
- public static void ShowImportCombination(string showName, Action onSelectObject, UiBase parentUi = null)
+ ///
+ /// 显示导入组合确认弹窗
+ ///
+ /// 组合名称
+ /// 显示纹理
+ /// 确定时回调
+ /// 取消时回调
+ /// 所属父级Ui
+ public static void ShowImportCombination(string showName, Texture2D texture, Action onAccept, Action onCancel, UiBase parentUi = null)
{
var window = CreateWindowInstance(parentUi);
window.S_Window.Instance.Size = new Vector2I(600, 500);
window.SetWindowTitle("导入组合");
- var body = window.OpenBody(UiManager.UiNames.EditorImportCombination);
+ var body = window.OpenBody(UiManager.UiNames.EditorImportCombination);
+ body.InitData(showName, texture);
+
window.SetButtonList(
new EditorWindowPanel.ButtonData("确定", () =>
{
- var selectObject = body.GetSelectData();
- if (selectObject == null)
- {
- ShowTips("提示", "您未选择任何物体");
- }
- else
- {
- window.CloseWindow();
- onSelectObject("");
- }
+ var selectObject = body.GetName();
+ window.CloseWindow();
+ onAccept(selectObject);
}),
new EditorWindowPanel.ButtonData("取消", () =>
{
+ if (onCancel != null)
+ {
+ window.CloseEvent += onCancel;
+ }
window.CloseWindow();
})
);
diff --git a/DungeonShooting_Godot/src/game/ui/editorImportCombination/EditorImportCombination.cs b/DungeonShooting_Godot/src/game/ui/editorImportCombination/EditorImportCombination.cs
index d457f82..b0220d8 100644
--- a/DungeonShooting_Godot/src/game/ui/editorImportCombination/EditorImportCombination.cs
+++ b/DungeonShooting_Godot/src/game/ui/editorImportCombination/EditorImportCombination.cs
@@ -91,12 +91,12 @@
}
///
- /// 类型: , 路径: EditorImportCombination.MarginContainer.VBoxContainer.HBoxContainer2.RemarkInput
+ /// 类型: , 路径: EditorImportCombination.MarginContainer.VBoxContainer.HBoxContainer2.PreviewTexture
///
- public class RemarkInput : UiNode
+ public class PreviewTexture : UiNode
{
- public RemarkInput(EditorImportCombinationPanel uiPanel, Godot.TextureRect node) : base(uiPanel, node) { }
- public override RemarkInput Clone() => new (UiPanel, (Godot.TextureRect)Instance.Duplicate());
+ public PreviewTexture(EditorImportCombinationPanel uiPanel, Godot.TextureRect node) : base(uiPanel, node) { }
+ public override PreviewTexture Clone() => new (UiPanel, (Godot.TextureRect)Instance.Duplicate());
}
///
@@ -118,17 +118,17 @@
private PreviewLabel _L_PreviewLabel;
///
- /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: EditorImportCombination.MarginContainer.VBoxContainer.RemarkInput
+ /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: EditorImportCombination.MarginContainer.VBoxContainer.PreviewTexture
///
- public RemarkInput L_RemarkInput
+ public PreviewTexture L_PreviewTexture
{
get
{
- if (_L_RemarkInput == null) _L_RemarkInput = new RemarkInput(UiPanel, Instance.GetNode("RemarkInput"));
- return _L_RemarkInput;
+ if (_L_PreviewTexture == null) _L_PreviewTexture = new PreviewTexture(UiPanel, Instance.GetNode("PreviewTexture"));
+ return _L_PreviewTexture;
}
}
- private RemarkInput _L_RemarkInput;
+ private PreviewTexture _L_PreviewTexture;
public HBoxContainer2(EditorImportCombinationPanel uiPanel, Godot.HBoxContainer node) : base(uiPanel, node) { }
public override HBoxContainer2 Clone() => new (UiPanel, (Godot.HBoxContainer)Instance.Duplicate());
@@ -213,9 +213,9 @@
public PreviewLabel S_PreviewLabel => L_MarginContainer.L_VBoxContainer.L_HBoxContainer2.L_PreviewLabel;
///
- /// 场景中唯一名称的节点, 节点类型: , 节点路径: EditorImportCombination.MarginContainer.VBoxContainer.HBoxContainer2.RemarkInput
+ /// 场景中唯一名称的节点, 节点类型: , 节点路径: EditorImportCombination.MarginContainer.VBoxContainer.HBoxContainer2.PreviewTexture
///
- public RemarkInput S_RemarkInput => L_MarginContainer.L_VBoxContainer.L_HBoxContainer2.L_RemarkInput;
+ public PreviewTexture S_PreviewTexture => L_MarginContainer.L_VBoxContainer.L_HBoxContainer2.L_PreviewTexture;
///
/// 场景中唯一名称的节点, 节点类型: , 节点路径: EditorImportCombination.MarginContainer.VBoxContainer.HBoxContainer2
diff --git a/DungeonShooting_Godot/src/game/ui/editorImportCombination/EditorImportCombinationPanel.cs b/DungeonShooting_Godot/src/game/ui/editorImportCombination/EditorImportCombinationPanel.cs
index 2caeb49..ad90fe9 100644
--- a/DungeonShooting_Godot/src/game/ui/editorImportCombination/EditorImportCombinationPanel.cs
+++ b/DungeonShooting_Godot/src/game/ui/editorImportCombination/EditorImportCombinationPanel.cs
@@ -4,15 +4,23 @@
public partial class EditorImportCombinationPanel : EditorImportCombination
{
-
- public override void OnCreateUi()
+ ///
+ /// 初始化页面数据
+ ///
+ /// 显示名称
+ /// 显示预览纹理
+ public void InitData(string name, Texture2D texture)
{
-
+ S_NameInput.Instance.Text = name;
+ S_PreviewTexture.Instance.Texture = texture;
}
- public override void OnDestroyUi()
+ ///
+ /// 获取输入框内的名称
+ ///
+ public string GetName()
{
-
+ return S_NameInput.Instance.Text;
}
}
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/RectBrush.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/RectBrush.cs
index 7f9253a..fe763d3 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/RectBrush.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/RectBrush.cs
@@ -41,7 +41,15 @@
}
///
- /// 获取中心点坐标
+ /// 获取原点坐标, 单位: 像素
+ ///
+ public Vector2I GetOriginPosition()
+ {
+ return new Vector2I(_x, _y);
+ }
+
+ ///
+ /// 获取中心点坐标, 单位: 像素
///
public Vector2I GetCenterPosition()
{
@@ -53,7 +61,7 @@
}
///
- /// 获取绘制的矩形大小
+ /// 获取绘制的矩形大小, 单位: 像素
///
public Vector2I GetRectSize()
{
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs
index 72ff60b..62fe7af 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs
@@ -176,7 +176,20 @@
EditorWindowManager.ShowTips("警告", "导入一格大小的组合图块没有任何意义!");
return;
}
-
+
+ var texture = GetCombinationPreviewTexture();
+ EditorWindowManager.ShowImportCombination("组合名称", texture, (name) =>
+ {
+ //派发导入组合图块事件
+ EventManager.EmitEvent(EventEnum.OnImportCombination, new ImportCombinationData()
+ {
+ Name = name,
+ PreviewTexture = texture
+ });
+ }, () => //取消添加组件
+ {
+ texture.Dispose();
+ });
}
//绘制笔刷
@@ -268,4 +281,24 @@
_xEnd = int.MinValue;
_yEnd = int.MinValue;
}
+
+ ///
+ /// 获取组合的预览图
+ ///
+ private Texture2D GetCombinationPreviewTexture()
+ {
+ var rectBrush = UiNode.L_CombinationRoot.L_RectBrush.Instance;
+ var src = UiNode.UiPanel.EditorPanel.TextureImage;
+ var rectSize = rectBrush.GetRectSize();
+ var originPos = rectBrush.GetOriginPosition();
+ var image = Image.Create(rectSize.X, rectSize.Y, false, Image.Format.Rgba8);
+ image.Fill(Colors.Gray);
+ foreach (var keyValuePair in _canvas)
+ {
+ var pos = keyValuePair.Key;
+ var srcRect = keyValuePair.Value.RegionRect;
+ image.BlendRect(src, new Rect2I(srcRect.Position.AsVector2I(), srcRect.Size.AsVector2I()), pos - originPos);
+ }
+ return ImageTexture.CreateFromImage(image);
+ }
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileCell.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileCell.cs
index d4148f2..2b85f04 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileCell.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileCell.cs
@@ -2,26 +2,17 @@
namespace UI.TileSetEditorCombination;
-public class TileCell : UiCell
+public class TileCell : UiCell
{
- private Image _image;
- private ImageTexture _previewTexture;
-
public override void OnInit()
{
CellNode.L_SelectTexture.Instance.Visible = false;
- _image = Image.Create(GameConfig.TileCellSize, GameConfig.TileCellSize, false, Image.Format.Rgba8);
- _previewTexture = ImageTexture.CreateFromImage(_image);
- CellNode.L_PreviewImage.Instance.Texture = _previewTexture;
}
-
- public override void OnSetData(Vector2I data)
+ public override void OnSetData(ImportCombinationData data)
{
- var image = CellNode.UiPanel.EditorPanel.TextureImage;
- _image.BlitRect(image, new Rect2I(data * GameConfig.TileCellSizeVector2I, GameConfig.TileCellSizeVector2I), Vector2I.Zero);
- _previewTexture.Update(_image);
- CellNode.L_CellId.Instance.Text = data.ToString();
+ CellNode.L_CellId.Instance.Text = data.Name;
+ CellNode.L_PreviewImage.Instance.Texture = data.PreviewTexture;
}
public override void OnDoubleClick()
@@ -30,11 +21,6 @@
//EventManager.EmitEvent(EventEnum.OnRemoveTileCell, Data);
}
- public override void OnDestroy()
- {
- _previewTexture.Dispose();
- }
-
public override void OnSelect()
{
CellNode.L_SelectTexture.Instance.Visible = true;
@@ -44,13 +30,4 @@
{
CellNode.L_SelectTexture.Instance.Visible = false;
}
-
- public override int OnSort(UiCell other)
- {
- if (Data.Y != other.Data.Y)
- {
- return Data.Y - other.Data.Y;
- }
- return Data.X - other.Data.X;
- }
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileSelected.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileSelected.cs
index 3bb201d..673978a 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileSelected.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileSelected.cs
@@ -5,29 +5,29 @@
public partial class TileSelected : VBoxContainer, IUiNodeScript
{
private TileSetEditorCombination.RightBg _rightBg;
- private UiGrid _grid;
+ private UiGrid _grid;
public void SetUiNode(IUiNode uiNode)
{
_rightBg = (TileSetEditorCombination.RightBg)uiNode;
- _grid = new UiGrid(_rightBg.L_ScrollContainer.L_CellButton, typeof(TileCell));
+ _grid = new UiGrid(_rightBg.L_ScrollContainer.L_CellButton, typeof(TileCell));
_grid.SetCellOffset(new Vector2I(5, 5));
_grid.SetAutoColumns(true);
_grid.SetHorizontalExpand(true);
- // _rightBg.UiPanel.AddEventListener(EventEnum.OnImportTileCell, OnImportCell);
+ _rightBg.UiPanel.AddEventListener(EventEnum.OnImportCombination, OnImportCombination);
// _rightBg.UiPanel.AddEventListener(EventEnum.OnRemoveTileCell, OnRemoveCell);
}
///
- /// 导入选中的Cell图块
+ /// 导入组合图块
///
- private void OnImportCell(object obj)
+ private void OnImportCombination(object obj)
{
- if (obj is Vector2I cell)
+ if (obj is ImportCombinationData data)
{
- _grid.Add(cell);
+ _grid.Add(data);
_grid.Sort();
}
}
@@ -37,14 +37,14 @@
///
private void OnRemoveCell(object obj)
{
- if (obj is Vector2I cell)
- {
- var uiCell = _grid.Find(c => c.Data == cell);
- if (uiCell != null)
- {
- _grid.RemoveByIndex(uiCell.Index);
- }
- }
+ // if (obj is ImportCombinationData data)
+ // {
+ // var uiCell = _grid.Find(c => c.Data == data);
+ // if (uiCell != null)
+ // {
+ // _grid.RemoveByIndex(uiCell.Index);
+ // }
+ // }
}
public void OnDestroy()