diff --git a/DungeonShooting_Godot/prefab/ui/TileSetEditorImport.tscn b/DungeonShooting_Godot/prefab/ui/TileSetEditorImport.tscn
index a4491a0..e83561b 100644
--- a/DungeonShooting_Godot/prefab/ui/TileSetEditorImport.tscn
+++ b/DungeonShooting_Godot/prefab/ui/TileSetEditorImport.tscn
@@ -1,7 +1,8 @@
-[gd_scene load_steps=3 format=3 uid="uid://d4h6gt4jkx25e"]
+[gd_scene load_steps=4 format=3 uid="uid://d4h6gt4jkx25e"]
[ext_resource type="Script" path="res://src/game/ui/tileSetEditorImport/TileSetEditorImportPanel.cs" id="1_rkxih"]
[ext_resource type="Texture2D" uid="uid://duos2p6if4kcp" path="res://resource/sprite/ui/commonIcon/Import.png" id="2_cc6ug"]
+[ext_resource type="Texture2D" uid="uid://d2wslibovwv7w" path="res://resource/sprite/ui/commonIcon/CenterTool.png" id="3_tbedj"]
[node name="TileSetEditorImport" type="Control"]
layout_mode = 3
@@ -101,3 +102,18 @@
offset_bottom = 188.0
grow_horizontal = 0
text = "重新导入"
+
+[node name="FocusBtn" type="TextureButton" parent="."]
+layout_mode = 1
+anchors_preset = 1
+anchor_left = 1.0
+anchor_right = 1.0
+offset_left = -129.0
+offset_top = 212.0
+offset_right = -65.0
+offset_bottom = 276.0
+grow_horizontal = 0
+tooltip_text = "聚焦"
+texture_normal = ExtResource("3_tbedj")
+ignore_texture_size = true
+stretch_mode = 5
diff --git a/DungeonShooting_Godot/resource/sprite/ui/commonIcon/Missing.png b/DungeonShooting_Godot/resource/sprite/ui/commonIcon/Missing.png
new file mode 100644
index 0000000..1e41480
--- /dev/null
+++ b/DungeonShooting_Godot/resource/sprite/ui/commonIcon/Missing.png
Binary files differ
diff --git a/DungeonShooting_Godot/resource/sprite/ui/commonIcon/Missing.png.import b/DungeonShooting_Godot/resource/sprite/ui/commonIcon/Missing.png.import
new file mode 100644
index 0000000..69ac8ed
--- /dev/null
+++ b/DungeonShooting_Godot/resource/sprite/ui/commonIcon/Missing.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://bit0o4oadgxr0"
+path="res://.godot/imported/Missing.png-a5d6965e8f7a3a0c127af8eb6ab18af8.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://resource/sprite/ui/commonIcon/Missing.png"
+dest_files=["res://.godot/imported/Missing.png-a5d6965e8f7a3a0c127af8eb6ab18af8.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/src/framework/common/Utils.cs b/DungeonShooting_Godot/src/framework/common/Utils.cs
index 1cc292d..28f327e 100644
--- a/DungeonShooting_Godot/src/framework/common/Utils.cs
+++ b/DungeonShooting_Godot/src/framework/common/Utils.cs
@@ -427,6 +427,25 @@
return false;
}
+
+ ///
+ /// 根据鼠标位置执行单步放大逻辑
+ ///
+ public static bool DoMagnifyByMousePosition(Node2D node, float maxXScale)
+ {
+ var offset = node.GetLocalMousePosition();
+ var prevScale = node.Scale;
+ var newScale = prevScale * 1.1f;
+ if (newScale.X <= maxXScale)
+ {
+ node.Scale = newScale;
+ var position = node.Position - offset * 0.1f * prevScale;
+ node.Position = position;
+ return true;
+ }
+
+ return false;
+ }
///
/// 根据鼠标位置执行单步缩小逻辑
@@ -446,4 +465,35 @@
return false;
}
+
+ ///
+ /// 根据鼠标位置执行单步缩小逻辑
+ ///
+ public static bool DoShrinkByMousePosition(Node2D node, float minXScale)
+ {
+ var offset = node.GetLocalMousePosition();
+ var prevScale = node.Scale;
+ var newScale = prevScale / 1.1f;
+ if (newScale.X >= minXScale)
+ {
+ node.Scale = newScale;
+ var position = node.Position + offset * 0.1f * newScale;
+ node.Position = position;
+ return true;
+ }
+
+ return false;
+ }
+
+ ///
+ /// 聚焦Ui节点
+ ///
+ /// 需要聚焦的节点
+ /// 父节点容器大小
+ /// 当前节点容器大小
+ public static void DoFocusNode(Control control, Vector2 parentSize, Vector2 selfSize)
+ {
+ control.Position = parentSize / 2 - selfSize * 0.5f * control.Scale;
+ }
+
}
\ 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 5ab54e2..9c9df08 100644
--- a/DungeonShooting_Godot/src/framework/ui/grid/UiGrid.cs
+++ b/DungeonShooting_Godot/src/framework/ui/grid/UiGrid.cs
@@ -466,7 +466,7 @@
}
//调用 cell 更新
- var uiCells = _cellPool.ToArray();
+ var uiCells = _cellList.ToArray();
for (var i = 0; i < uiCells.Length; i++)
{
var item = uiCells[i];
diff --git a/DungeonShooting_Godot/src/game/data/ImportCombinationData.cs b/DungeonShooting_Godot/src/game/data/ImportCombinationData.cs
index de9119e..4230b71 100644
--- a/DungeonShooting_Godot/src/game/data/ImportCombinationData.cs
+++ b/DungeonShooting_Godot/src/game/data/ImportCombinationData.cs
@@ -1,4 +1,5 @@
+using System.IO;
using Godot;
///
@@ -15,6 +16,8 @@
///
public TileCombinationInfo CombinationInfo { get; set; }
+ private static Image MissingImage;
+
public ImportCombinationData(ImageTexture previewTexture, TileCombinationInfo combinationInfo)
{
PreviewTexture = previewTexture;
@@ -40,14 +43,28 @@
/// 图块位置
public static Image GetPreviewTexture(Image src, SerializeVector2[] cells, SerializeVector2[] positions)
{
+ var srcSize = src.GetSize();
var rect = Utils.CalcTileRect(positions);
var rectSize = rect.Size;
var image = Image.Create(rectSize.X + 4, rectSize.Y + 4, false, Image.Format.Rgba8);
for (var i = 0; i < cells.Length; i++)
{
- var cell = cells[i];
- var pos = positions[i];
- image.BlendRect(src, new Rect2I(cell.AsVector2I(), GameConfig.TileCellSizeVector2I), pos.AsVector2I() + new Vector2I(2, 2));
+ var cell = cells[i].AsVector2I();
+ var pos = positions[i].AsVector2I();
+ //判断是否超出纹理范围
+ if (cell.X + GameConfig.TileCellSize > srcSize.X || cell.Y + GameConfig.TileCellSize > srcSize.Y) //超出范围
+ {
+ if (MissingImage == null)
+ {
+ MissingImage = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_ui_commonIcon_Missing_png).GetImage();
+ MissingImage.Convert(Image.Format.Rgba8);
+ }
+ image.BlendRect(MissingImage, new Rect2I(Vector2I.Zero, GameConfig.TileCellSizeVector2I), pos + new Vector2I(2, 2));
+ }
+ else
+ {
+ image.BlendRect(src, new Rect2I(cell, GameConfig.TileCellSizeVector2I), pos + new Vector2I(2, 2));
+ }
}
return image;
}
diff --git a/DungeonShooting_Godot/src/game/event/EventEnum.cs b/DungeonShooting_Godot/src/game/event/EventEnum.cs
index dde9354..d12df49 100644
--- a/DungeonShooting_Godot/src/game/event/EventEnum.cs
+++ b/DungeonShooting_Godot/src/game/event/EventEnum.cs
@@ -172,4 +172,12 @@
/// 导入组合, 参数为
///
OnImportCombination,
+ ///
+ /// 移除组合, 参数为
+ ///
+ OnRemoveCombination,
+ ///
+ /// 修改组合名称, 参数为
+ ///
+ OnUpdateCombination,
}
diff --git a/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs b/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs
index 2fca8b1..c349bf0 100644
--- a/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs
+++ b/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs
@@ -467,6 +467,47 @@
);
}
+ ///
+ /// 显示编辑组合弹窗
+ ///
+ /// 组合名称
+ /// 预览纹理背景颜色
+ /// 显示纹理
+ /// 确定时回调
+ /// 删除时回调
+ /// 所属父级Ui
+ public static void ShowEditCombination(string showName, Color color, Texture2D texture, Action onAccept, Action onDelete, UiBase parentUi = null)
+ {
+ var window = CreateWindowInstance(parentUi);
+ window.S_Window.Instance.Size = new Vector2I(750, 650);
+ window.SetWindowTitle("编辑组合");
+ var body = window.OpenBody(UiManager.UiNames.EditorImportCombination);
+ body.InitData(showName, color, texture);
+ window.SetButtonList(
+ new EditorWindowPanel.ButtonData("删除", () =>
+ {
+ ShowConfirm("提示", "您确定要删除该组合吗,该操作不能取消!", (flag) =>
+ {
+ if (flag)
+ {
+ window.CloseWindow();
+ onDelete();
+ }
+ }, window);
+ }),
+ new EditorWindowPanel.ButtonData("保存", () =>
+ {
+ var selectObject = body.GetName();
+ window.CloseWindow();
+ onAccept(selectObject);
+ }),
+ new EditorWindowPanel.ButtonData("取消", () =>
+ {
+ window.CloseWindow();
+ })
+ );
+ }
+
private static EditorWindowPanel CreateWindowInstance(UiBase parentUi = null)
{
if (parentUi != null)
diff --git a/DungeonShooting_Godot/src/game/manager/ResourcePath.cs b/DungeonShooting_Godot/src/game/manager/ResourcePath.cs
index c8c468d..c507d27 100644
--- a/DungeonShooting_Godot/src/game/manager/ResourcePath.cs
+++ b/DungeonShooting_Godot/src/game/manager/ResourcePath.cs
@@ -303,6 +303,7 @@
public const string resource_sprite_ui_commonIcon_Mark_png = "res://resource/sprite/ui/commonIcon/Mark.png";
public const string resource_sprite_ui_commonIcon_MarkCell_png = "res://resource/sprite/ui/commonIcon/MarkCell.png";
public const string resource_sprite_ui_commonIcon_MarkCell_placeholder_png = "res://resource/sprite/ui/commonIcon/MarkCell_placeholder.png";
+ public const string resource_sprite_ui_commonIcon_Missing_png = "res://resource/sprite/ui/commonIcon/Missing.png";
public const string resource_sprite_ui_commonIcon_PackageMark_png = "res://resource/sprite/ui/commonIcon/PackageMark.png";
public const string resource_sprite_ui_commonIcon_PenTool_png = "res://resource/sprite/ui/commonIcon/PenTool.png";
public const string resource_sprite_ui_commonIcon_Play_png = "res://resource/sprite/ui/commonIcon/Play.png";
diff --git a/DungeonShooting_Godot/src/game/ui/editorImportCombination/EditorImportCombinationPanel.cs b/DungeonShooting_Godot/src/game/ui/editorImportCombination/EditorImportCombinationPanel.cs
index 48e3f66..5fc6c8c 100644
--- a/DungeonShooting_Godot/src/game/ui/editorImportCombination/EditorImportCombinationPanel.cs
+++ b/DungeonShooting_Godot/src/game/ui/editorImportCombination/EditorImportCombinationPanel.cs
@@ -6,9 +6,13 @@
{
public override void OnShowUi()
{
+ //监听拖拽
S_PreviewBg.Instance.AddDragListener(DragButtonEnum.Left | DragButtonEnum.Right | DragButtonEnum.Middle, OnDragPreview);
+ //监听鼠标滚轮
+ S_PreviewBg.Instance.AddMouseWheelListener(OnMouseCallback);
}
-
+
+ //拖拽纹理
private void OnDragPreview(DragState state, Vector2 delta)
{
if (state == DragState.DragMove)
@@ -16,6 +20,19 @@
S_PreviewTexture.Instance.Position += delta;
}
}
+
+ //缩放/放大纹理
+ private void OnMouseCallback(int value)
+ {
+ if (value < 0) //缩小
+ {
+ Utils.DoShrinkByMousePosition(S_PreviewTexture.Instance, 0.2f);
+ }
+ else //放大
+ {
+ Utils.DoMagnifyByMousePosition(S_PreviewTexture.Instance, 20);
+ }
+ }
///
/// 初始化页面数据
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs
index c1f6400..fbd5409 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs
@@ -86,7 +86,7 @@
{
S_Title.Instance.Text = "正在编辑:" + tileSetInfo.Name;
- SetTextureData(Image.LoadFromFile("resource/tileSprite/map1/16x16 dungeon ii wall reconfig v04 spritesheet.png"));
+ //SetTextureData(Image.LoadFromFile("resource/tileSprite/map1/16x16 dungeon ii wall reconfig v04 spritesheet.png"));
TabGrid.SelectIndex = 0;
}
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/GridBg.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/GridBg.cs
index 0cfa685..2f6c1bd 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/GridBg.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/GridBg.cs
@@ -36,33 +36,22 @@
if (mouseButton.ButtonIndex == MouseButton.WheelDown)
{
//缩小
- Shrink();
+ if (Utils.DoShrinkByMousePosition(ContainerRoot, 0.4f))
+ {
+ SetGridTransform(ContainerRoot.Position, ContainerRoot.Scale.X);
+ }
}
else if (mouseButton.ButtonIndex == MouseButton.WheelUp)
{
//放大
- Magnify();
+ if (Utils.DoMagnifyByMousePosition(ContainerRoot, 20))
+ {
+ SetGridTransform(ContainerRoot.Position, ContainerRoot.Scale.X);
+ }
}
}
}
- //缩小
- private void Shrink()
- {
- if (Utils.DoShrinkByMousePosition(ContainerRoot, 0.2f))
- {
- SetGridTransform(ContainerRoot.Position, ContainerRoot.Scale.X);
- }
- }
- //放大
- private void Magnify()
- {
- if (Utils.DoMagnifyByMousePosition(ContainerRoot, 20))
- {
- SetGridTransform(ContainerRoot.Position, ContainerRoot.Scale.X);
- }
- }
-
//拖拽回调
private void OnDrag(DragState state, Vector2 pos)
{
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/MaskRectCell.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/MaskRectCell.cs
index 284d596..b5dc879 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/MaskRectCell.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/MaskRectCell.cs
@@ -17,7 +17,10 @@
public override void Process(float delta)
{
- CellNode.Instance.QueueRedraw();
+ if (Data)
+ {
+ CellNode.Instance.QueueRedraw();
+ }
}
private void OnDraw()
@@ -27,7 +30,7 @@
//选中时绘制轮廓
CellNode.Instance.DrawRect(
new Rect2(Vector2.Zero, CellNode.Instance.Size),
- new Color(0, 1, 1), false, 2 / CellNode.UiPanel.S_TileTexture.Instance.Scale.X
+ new Color(0, 1, 1), false, 2f / CellNode.UiPanel.S_TileTexture.Instance.Scale.X
);
}
}
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/TileEditArea.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/TileEditArea.cs
index 87e1507..3fc22ab 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/TileEditArea.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/TileEditArea.cs
@@ -65,15 +65,14 @@
//聚焦按钮点击
private void OnFocusClick()
{
- var pos = Size / 2;
var texture = UiNode.L_TileTexture.Instance.Texture;
if (texture != null)
{
- ContainerRoot.Position = pos - texture.GetSize() * 0.5f * ContainerRoot.Scale;
+ Utils.DoFocusNode(ContainerRoot, Size, texture.GetSize());
}
else
{
- ContainerRoot.Position = pos;
+ Utils.DoFocusNode(ContainerRoot, Size, Vector2.Zero);
}
RefreshGridTrans();
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs
index 89a9359..b50a9e2 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs
@@ -143,9 +143,7 @@
//点击聚焦按钮
private void OnFocusClick()
{
- var pos = Size / 2;
- var center = UiNode.L_CombinationRoot.L_RectBrush.Instance.GetCenterPosition();
- ContainerRoot.Position = pos - center * ContainerRoot.Scale;
+ Utils.DoFocusNode(ContainerRoot, Size, UiNode.L_CombinationRoot.L_RectBrush.Instance.GetCenterPosition() * 2);
RefreshGridTrans();
}
@@ -182,10 +180,10 @@
var src = UiNode.UiPanel.EditorPanel.TextureImage;
var image = ImportCombinationData.GetPreviewTexture(src, cells, positions);
var texture = ImageTexture.CreateFromImage(image);
- EditorWindowManager.ShowImportCombination("组合名称", color, texture, (name) =>
+ EditorWindowManager.ShowImportCombination("组合", color, texture, (name) =>
{
var combinationInfo = new TileCombinationInfo();
- combinationInfo.Id = "1";
+ combinationInfo.Id = DateTime.UtcNow.Ticks.ToString();
combinationInfo.Name = name;
combinationInfo.Cells = cells;
combinationInfo.Positions = positions;
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileCell.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileCell.cs
index 98b9a87..e4354f6 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileCell.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileCell.cs
@@ -15,10 +15,41 @@
CellNode.L_PreviewImage.Instance.Texture = data.PreviewTexture;
}
+ public override void OnDisable()
+ {
+ if (Data.PreviewTexture != null)
+ {
+ Data.PreviewTexture.Dispose();
+ Data.PreviewTexture = null;
+ }
+ }
+
+ public override void OnDestroy()
+ {
+ if (Data.PreviewTexture != null)
+ {
+ Data.PreviewTexture.Dispose();
+ Data.PreviewTexture = null;
+ }
+ }
+
public override void OnDoubleClick()
{
//双击移除Cell数据
- //EventManager.EmitEvent(EventEnum.OnRemoveTileCell, Data);
+ EditorWindowManager.ShowEditCombination(
+ Data.CombinationInfo.Name,
+ CellNode.UiPanel.EditorPanel.BgColor,
+ Data.PreviewTexture,
+ (newName) => //修改
+ {
+ Data.CombinationInfo.Name = newName;
+ EventManager.EmitEvent(EventEnum.OnUpdateCombination, Data);
+ },
+ () => //删除
+ {
+ EventManager.EmitEvent(EventEnum.OnRemoveCombination, Data);
+ }
+ );
}
public override void OnSelect()
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileSelected.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileSelected.cs
index a6683a7..388bef7 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileSelected.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileSelected.cs
@@ -17,7 +17,8 @@
_grid.SetHorizontalExpand(true);
_rightBg.UiPanel.AddEventListener(EventEnum.OnImportCombination, OnImportCombination);
- // _rightBg.UiPanel.AddEventListener(EventEnum.OnRemoveTileCell, OnRemoveCell);
+ _rightBg.UiPanel.AddEventListener(EventEnum.OnRemoveCombination, OnRemoveCombination);
+ _rightBg.UiPanel.AddEventListener(EventEnum.OnUpdateCombination, OnUpdateCombination);
}
///
@@ -33,18 +34,33 @@
}
///
- /// 移除选中的Cell图块
+ /// 移除组合图块
///
- private void OnRemoveCell(object obj)
+ private void OnRemoveCombination(object obj)
{
- // if (obj is ImportCombinationData data)
- // {
- // var uiCell = _grid.Find(c => c.Data == data);
- // if (uiCell != null)
- // {
- // _grid.RemoveByIndex(uiCell.Index);
- // }
- // }
+ if (obj is ImportCombinationData data)
+ {
+ var uiCell = _grid.Find(c => c.Data.CombinationInfo.Id == data.CombinationInfo.Id);
+ if (uiCell != null)
+ {
+ _grid.RemoveByIndex(uiCell.Index);
+ }
+ }
+ }
+
+ ///
+ /// 修改组合图块
+ ///
+ private void OnUpdateCombination(object obj)
+ {
+ if (obj is ImportCombinationData data)
+ {
+ var uiCell = _grid.Find(c => c.Data.CombinationInfo.Id == data.CombinationInfo.Id);
+ if (uiCell != null)
+ {
+ uiCell.SetData(data);
+ }
+ }
}
public void OnDestroy()
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImport.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImport.cs
index 0d51288..25b5aff 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImport.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImport.cs
@@ -96,6 +96,19 @@
}
private ReimportButton _L_ReimportButton;
+ ///
+ /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorImport.FocusBtn
+ ///
+ public FocusBtn L_FocusBtn
+ {
+ get
+ {
+ if (_L_FocusBtn == null) _L_FocusBtn = new FocusBtn((TileSetEditorImportPanel)this, GetNode("FocusBtn"));
+ return _L_FocusBtn;
+ }
+ }
+ private FocusBtn _L_FocusBtn;
+
public TileSetEditorImport() : base(nameof(TileSetEditorImport))
{
@@ -191,6 +204,15 @@
public override ReimportButton Clone() => new (UiPanel, (Godot.Button)Instance.Duplicate());
}
+ ///
+ /// 类型: , 路径: TileSetEditorImport.FocusBtn
+ ///
+ public class FocusBtn : UiNode
+ {
+ public FocusBtn(TileSetEditorImportPanel uiPanel, Godot.TextureButton node) : base(uiPanel, node) { }
+ public override FocusBtn Clone() => new (UiPanel, (Godot.TextureButton)Instance.Duplicate());
+ }
+
///
/// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorImport.ImportPreviewBg
@@ -232,4 +254,9 @@
///
public ReimportButton S_ReimportButton => L_ReimportButton;
+ ///
+ /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorImport.FocusBtn
+ ///
+ public FocusBtn S_FocusBtn => L_FocusBtn;
+
}
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImportPanel.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImportPanel.cs
index 35652b8..231aab2 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImportPanel.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImportPanel.cs
@@ -20,10 +20,12 @@
S_ImportButton.Instance.Pressed += OnImportButtonClick;
S_ReimportButton.Instance.Pressed += OnReimportButtonClick;
S_ImportColorPicker.Instance.Pressed += OnColorPickerClick;
+ S_FocusBtn.Instance.Pressed += OnFocusClick;
S_ImportPreviewBg.Instance.Visible = false;
S_ReimportButton.Instance.Visible = false;
S_ImportColorPicker.Instance.Visible = false;
+ S_FocusBtn.Instance.Visible = false;
//监听TileSet纹理改变
AddEventListener(EventEnum.OnSetTileTexture, OnSetTileTexture);
@@ -49,6 +51,7 @@
S_ImportPreviewBg.Instance.Visible = true;
S_ReimportButton.Instance.Visible = true;
S_ImportColorPicker.Instance.Visible = true;
+ S_FocusBtn.Instance.Visible = true;
//隐藏导入文本和icon
S_ImportLabel.Instance.Visible = false;
@@ -108,11 +111,17 @@
);
}
}
+
+ //聚焦
+ private void OnFocusClick()
+ {
+ S_ImportPreview.Instance.Position = Vector2.Zero;
+ }
//拖拽区域回调
private void OnDragCallback(DragState state, Vector2 position)
{
- var sprite2D = S_Control.L_ImportPreview.Instance;
+ var sprite2D = S_ImportPreview.Instance;
if (state == DragState.DragMove && sprite2D.Visible)
{
sprite2D.Position += position;
@@ -126,20 +135,16 @@
{
return;
}
- var textureRect = S_Control.L_ImportPreview.Instance;
+
if (v < 0)
{
//缩小
- var scale = textureRect.Scale;
- scale = new Vector2(Mathf.Max(0.1f, scale.X / 1.1f), Mathf.Max(0.1f, scale.Y / 1.1f));
- textureRect.Scale = scale;
+ Utils.DoShrinkByMousePosition(S_Control.L_ImportPreview.Instance, 0.4f);
}
else
{
//放大
- var scale = textureRect.Scale;
- scale = new Vector2(Mathf.Min(20f, scale.X * 1.1f), Mathf.Min(20f, scale.Y * 1.1f));
- textureRect.Scale = scale;
+ Utils.DoMagnifyByMousePosition(S_Control.L_ImportPreview.Instance, 20);
}
}