diff --git a/DungeonShooting_Godot/prefab/ui/TileSetEditorCombination.tscn b/DungeonShooting_Godot/prefab/ui/TileSetEditorCombination.tscn index e1af09c..a7e81c5 100644 --- a/DungeonShooting_Godot/prefab/ui/TileSetEditorCombination.tscn +++ b/DungeonShooting_Godot/prefab/ui/TileSetEditorCombination.tscn @@ -1,9 +1,8 @@ -[gd_scene load_steps=15 format=3 uid="uid://daias2tkvj20c"] +[gd_scene load_steps=14 format=3 uid="uid://daias2tkvj20c"] [ext_resource type="Script" path="res://src/game/ui/tileSetEditorCombination/TileSetEditorCombinationPanel.cs" id="1_to1lc"] [ext_resource type="Script" path="res://src/game/ui/tileSetEditorCombination/leftBottom/TileEditArea.cs" id="2_h43yx"] [ext_resource type="Shader" path="res://resource/material/Grid.gdshader" id="2_t1p2n"] -[ext_resource type="Texture2D" uid="uid://uhhfgdhpk7i4" path="res://icon.png" id="2_wr143"] [ext_resource type="Script" path="res://src/game/ui/tileSetEditorCombination/leftTop/RectBrush.cs" id="3_avikb"] [ext_resource type="Script" path="res://src/game/ui/tileSetEditorCombination/leftBottom/MaskBrush.cs" id="4_ytys0"] [ext_resource type="Texture2D" uid="uid://fkg21rtph51d" path="res://resource/sprite/ui/commonIcon/Delete2.png" id="5_6jqro"] @@ -39,6 +38,7 @@ grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_to1lc") +Layer = null [node name="HSplitContainer" type="HSplitContainer" parent="."] layout_mode = 1 @@ -56,7 +56,7 @@ [node name="LeftTop" type="Panel" parent="HSplitContainer/VSplitContainer"] layout_mode = 2 size_flags_vertical = 3 -size_flags_stretch_ratio = 60.0 +size_flags_stretch_ratio = 50.0 [node name="MarginContainer" type="MarginContainer" parent="HSplitContainer/VSplitContainer/LeftTop"] layout_mode = 1 @@ -160,7 +160,7 @@ layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 3 -size_flags_stretch_ratio = 40.0 +size_flags_stretch_ratio = 50.0 [node name="MarginContainer" type="MarginContainer" parent="HSplitContainer/VSplitContainer/LeftBottom"] layout_mode = 1 @@ -188,15 +188,10 @@ anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 -offset_left = -32.0 -offset_top = -32.0 -offset_right = 32.0 -offset_bottom = 32.0 grow_horizontal = 2 grow_vertical = 2 scale = Vector2(2, 2) mouse_filter = 2 -texture = ExtResource("2_wr143") [node name="MaskRoot" type="Control" parent="HSplitContainer/VSplitContainer/LeftBottom/MarginContainer/LeftBottomBg/TileTexture"] layout_mode = 1 @@ -272,14 +267,14 @@ [node name="Label" type="Label" parent="HSplitContainer/Right/MarginContainer/RightBg"] layout_mode = 2 -text = "已经导入的组合(双击移除):" +text = "已经导入的组合:" [node name="ScrollContainer" type="ScrollContainer" parent="HSplitContainer/Right/MarginContainer/RightBg"] layout_mode = 2 size_flags_vertical = 3 [node name="CellButton" type="Button" parent="HSplitContainer/Right/MarginContainer/RightBg/ScrollContainer"] -custom_minimum_size = Vector2(120, 160) +custom_minimum_size = Vector2(120, 170) layout_mode = 2 [node name="PreviewImage" type="TextureRect" parent="HSplitContainer/Right/MarginContainer/RightBg/ScrollContainer/CellButton"] @@ -290,28 +285,29 @@ offset_left = 2.0 offset_top = 2.0 offset_right = -2.0 -offset_bottom = -42.0 +offset_bottom = -52.0 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"] +[node name="CellName" type="Label" parent="HSplitContainer/Right/MarginContainer/RightBg/ScrollContainer/CellButton"] layout_mode = 1 anchors_preset = 12 anchor_top = 1.0 anchor_right = 1.0 anchor_bottom = 1.0 -offset_top = -40.0 +offset_top = -52.0 grow_horizontal = 2 grow_vertical = 0 theme_override_font_sizes/font_size = 16 text = "名称" horizontal_alignment = 1 vertical_alignment = 1 +autowrap_mode = 2 clip_text = true -text_overrun_behavior = 1 +text_overrun_behavior = 2 [node name="SelectTexture" type="NinePatchRect" parent="HSplitContainer/Right/MarginContainer/RightBg/ScrollContainer/CellButton"] layout_mode = 1 diff --git a/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs b/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs index 3de91cf..27691d0 100644 --- a/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs +++ b/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs @@ -442,20 +442,25 @@ window.SetWindowTitle("导入组合"); var body = window.OpenBody(UiManager.UiNames.EditorImportCombination); body.InitData(showName, texture); - + var accept = false; + if (onCancel != null) + { + window.CloseEvent += () => + { + if (!accept) onCancel(); + }; + } + window.SetButtonList( new EditorWindowPanel.ButtonData("确定", () => { + accept = true; 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/tileSetEditor/TileSetEditorPanel.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs index d6d34fc..3f59ae4 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs @@ -5,9 +5,14 @@ public partial class TileSetEditorPanel : TileSetEditor { /// + /// 是否初始化过纹理 + /// + public bool InitTexture { get; private set; } + + /// /// 纹理 /// - public Texture2D Texture { get; private set; } + public ImageTexture Texture { get; private set; } /// /// 纹理的Image对象 @@ -36,6 +41,7 @@ public override void OnCreateUi() { + Texture = new ImageTexture(); S_Back.Instance.Visible = PrevUi != null; S_Back.Instance.Pressed += OnBackClick; @@ -62,6 +68,11 @@ public override void OnDestroyUi() { TabGrid.Destroy(); + if (Texture != null) + { + Texture.Dispose(); + } + if (TextureImage != null) { TextureImage.Dispose(); @@ -75,26 +86,27 @@ { S_Title.Instance.Text = "正在编辑:" + tileSetInfo.Name; - SetTexture(ImageTexture.CreateFromImage(Image.LoadFromFile("resource/tileSprite/map1/16x16 dungeon ii wall reconfig v04 spritesheet.png"))); + //SetTexture(ImageTexture.CreateFromImage(Image.LoadFromFile("resource/tileSprite/map1/16x16 dungeon ii wall reconfig v04 spritesheet.png"))); TabGrid.SelectIndex = 0; } /// /// 设置纹理 /// - public void SetTexture(Texture2D texture) + public void SetTextureData(Image image) { - Texture = texture; + InitTexture = true; + Texture.SetImage(image); if (TextureImage != null) { TextureImage.Dispose(); } - TextureImage = texture.GetImage(); - CellHorizontal = texture.GetWidth() / GameConfig.TileCellSize; - CellVertical = texture.GetHeight() / GameConfig.TileCellSize; + TextureImage = image; + CellHorizontal = image.GetWidth() / GameConfig.TileCellSize; + CellVertical = image.GetHeight() / GameConfig.TileCellSize; //派发事件 - EventManager.EmitEvent(EventEnum.OnSetTileTexture, texture); + EventManager.EmitEvent(EventEnum.OnSetTileTexture, Texture); } /// @@ -105,7 +117,7 @@ BgColor = color; //派发事件 - EventManager.EmitEvent(EventEnum.OnSetTileTexture, color); + EventManager.EmitEvent(EventEnum.OnSetTileSetBgColor, color); } /// diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/TileSetEditorCombination.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/TileSetEditorCombination.cs index 89feacd..63379d9 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/TileSetEditorCombination.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/TileSetEditorCombination.cs @@ -499,12 +499,12 @@ } /// - /// 类型: , 路径: TileSetEditorCombination.HSplitContainer.Right.MarginContainer.RightBg.ScrollContainer.CellButton.CellId + /// 类型: , 路径: TileSetEditorCombination.HSplitContainer.Right.MarginContainer.RightBg.ScrollContainer.CellButton.CellName /// - public class CellId : UiNode + public class CellName : UiNode { - public CellId(TileSetEditorCombinationPanel uiPanel, Godot.Label node) : base(uiPanel, node) { } - public override CellId Clone() => new (UiPanel, (Godot.Label)Instance.Duplicate()); + public CellName(TileSetEditorCombinationPanel uiPanel, Godot.Label node) : base(uiPanel, node) { } + public override CellName Clone() => new (UiPanel, (Godot.Label)Instance.Duplicate()); } /// @@ -535,17 +535,17 @@ private PreviewImage _L_PreviewImage; /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorCombination.HSplitContainer.Right.MarginContainer.RightBg.ScrollContainer.CellId + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorCombination.HSplitContainer.Right.MarginContainer.RightBg.ScrollContainer.CellName /// - public CellId L_CellId + public CellName L_CellName { get { - if (_L_CellId == null) _L_CellId = new CellId(UiPanel, Instance.GetNode("CellId")); - return _L_CellId; + if (_L_CellName == null) _L_CellName = new CellName(UiPanel, Instance.GetNode("CellName")); + return _L_CellName; } } - private CellId _L_CellId; + private CellName _L_CellName; /// /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorCombination.HSplitContainer.Right.MarginContainer.RightBg.ScrollContainer.SelectTexture @@ -787,9 +787,9 @@ public PreviewImage S_PreviewImage => L_HSplitContainer.L_Right.L_MarginContainer.L_RightBg.L_ScrollContainer.L_CellButton.L_PreviewImage; /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorCombination.HSplitContainer.Right.MarginContainer.RightBg.ScrollContainer.CellButton.CellId + /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorCombination.HSplitContainer.Right.MarginContainer.RightBg.ScrollContainer.CellButton.CellName /// - public CellId S_CellId => L_HSplitContainer.L_Right.L_MarginContainer.L_RightBg.L_ScrollContainer.L_CellButton.L_CellId; + public CellName S_CellName => L_HSplitContainer.L_Right.L_MarginContainer.L_RightBg.L_ScrollContainer.L_CellButton.L_CellName; /// /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorCombination.HSplitContainer.Right.MarginContainer.RightBg.ScrollContainer.CellButton.SelectTexture diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/TileSetEditorCombinationPanel.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/TileSetEditorCombinationPanel.cs index 78f12e6..fd9368e 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/TileSetEditorCombinationPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/TileSetEditorCombinationPanel.cs @@ -18,8 +18,6 @@ AddEventListener(EventEnum.OnSetTileTexture, OnSetTileTexture); //改变背景颜色事件 AddEventListener(EventEnum.OnSetTileSetBgColor, OnSetTileSetBgColor); - - } public override void OnShowUi() @@ -44,11 +42,8 @@ //改变TileSet纹理 private void OnSetTileTexture(object arg) { - if (arg is Texture2D texture) - { - S_LeftBottomBg.Instance.OnChangeTileSetTexture(texture); - S_RightBg.Instance.OnChangeTileSetTexture(texture); - } + S_LeftBottomBg.Instance.OnChangeTileSetTexture(); + S_RightBg.Instance.OnChangeTileSetTexture(); } //改变TileSet背景颜色 @@ -58,6 +53,7 @@ if (arg is Color color) { S_LeftTopBg.Instance.Color = color; + S_LeftBottomBg.Instance.Color = color; } } } diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/MaskBrush.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/MaskBrush.cs index 0dc9697..94c0cdb 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/MaskBrush.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/MaskBrush.cs @@ -24,8 +24,9 @@ //绘制texture区域 if (TileTexture.Texture != null) { + var editorPanel = TileEditArea.UiNode.UiPanel.EditorPanel; DrawRect( - new Rect2(Vector2.Zero, TileTexture.Size), + new Rect2(Vector2.Zero, editorPanel.CellHorizontal * GameConfig.TileCellSize, editorPanel.CellVertical * GameConfig.TileCellSize), new Color(1, 1, 0, 0.5f), false, 2f / TileTexture.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 76f6f29..59b05dd 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/TileEditArea.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/TileEditArea.cs @@ -13,6 +13,7 @@ base.SetUiNode(uiNode); Grid = UiNode.L_Grid.Instance; ContainerRoot = UiNode.L_TileTexture.Instance; + UiNode.L_TileTexture.Instance.Texture = UiNode.UiPanel.EditorPanel.Texture; var maskBrush = UiNode.L_TileTexture.L_MaskBrush.Instance; maskBrush.TileTexture = UiNode.L_TileTexture.Instance; @@ -138,11 +139,11 @@ /// /// 改变TileSet纹理 /// - public void OnChangeTileSetTexture(Texture2D texture) + public void OnChangeTileSetTexture() { - UiNode.L_TileTexture.Instance.Texture = texture; var width = UiNode.UiPanel.EditorPanel.CellHorizontal; var height = UiNode.UiPanel.EditorPanel.CellVertical; + UiNode.L_TileTexture.Instance.Size = UiNode.L_TileTexture.Instance.Texture.GetSize(); _maskGrid.RemoveAll(); _useMask.Clear(); _maskGrid.SetColumns(width); diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs index 62fe7af..a15d60e 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs @@ -291,13 +291,14 @@ 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); + var image = Image.Create(rectSize.X + 4, rectSize.Y + 4, 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); + image.BlendRect(src, new Rect2I(srcRect.Position.AsVector2I(), srcRect.Size.AsVector2I()), + pos - originPos + new Vector2I(2, 2)); } return ImageTexture.CreateFromImage(image); } diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileCell.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileCell.cs index 2b85f04..dd1314c 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileCell.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileCell.cs @@ -11,7 +11,7 @@ public override void OnSetData(ImportCombinationData data) { - CellNode.L_CellId.Instance.Text = data.Name; + CellNode.L_CellName.Instance.Text = data.Name; CellNode.L_PreviewImage.Instance.Texture = data.PreviewTexture; } diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileSelected.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileSelected.cs index 673978a..e2d1270 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileSelected.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/right/TileSelected.cs @@ -56,7 +56,7 @@ /// /// 改变TileSet纹理 /// - public void OnChangeTileSetTexture(Texture2D texture) + public void OnChangeTileSetTexture() { _grid.RemoveAll(); } diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImportPanel.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImportPanel.cs index 752e662..5c1f29e 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImportPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImportPanel.cs @@ -15,6 +15,7 @@ { _tileSetEditor = (TileSetEditor.TileSetEditorPanel)ParentUi; _tileSetEditor.SetBgColor(S_ImportPreviewBg.Instance.Color); + S_ImportPreview.Instance.Texture = _tileSetEditor.Texture; _dragBinder = DragUiManager.BindDrag(S_ImportPreviewBg.Instance, OnDragCallback); @@ -25,7 +26,8 @@ S_ImportPreviewBg.Instance.Visible = false; S_ReimportButton.Instance.Visible = false; - + S_ImportColorPicker.Instance.Visible = false; + //监听TileSet纹理改变 AddEventListener(EventEnum.OnSetTileTexture, OnSetTileTexture); //监听TileSet背景颜色改变 @@ -42,20 +44,16 @@ private void OnSetTileTexture(object arg) { //判断是否已经初始化好纹理了 - if (arg is Texture2D texture) + if (_tileSetEditor.InitTexture) { - var sprite2D = S_ImportPreview.Instance; - if (sprite2D.Texture != texture) - { - sprite2D.Texture = texture; - S_ImportPreviewBg.Instance.Visible = true; - S_ReimportButton.Instance.Visible = true; - - //隐藏导入文本和icon - S_ImportLabel.Instance.Visible = false; - S_ImportIcon.Instance.Visible = false; - S_ImportButton.Instance.Visible = false; - } + S_ImportPreviewBg.Instance.Visible = true; + S_ReimportButton.Instance.Visible = true; + S_ImportColorPicker.Instance.Visible = true; + + //隐藏导入文本和icon + S_ImportLabel.Instance.Visible = false; + S_ImportIcon.Instance.Visible = false; + S_ImportButton.Instance.Visible = false; } } @@ -102,7 +100,7 @@ //点击导入按钮 private void OnImportButtonClick() { - if (_tileSetEditor.Texture != null) + if (_tileSetEditor.InitTexture) { return; } @@ -180,7 +178,6 @@ private void SetImportTexture(string file) { Debug.Log("导入文件: " + file); - var imageTexture = ImageTexture.CreateFromImage(Image.LoadFromFile(file)); - _tileSetEditor.SetTexture(imageTexture); + _tileSetEditor.SetTextureData(Image.LoadFromFile(file)); } }