diff --git a/DungeonShooting_Godot/prefab/ui/TileSetEditorSegment.tscn b/DungeonShooting_Godot/prefab/ui/TileSetEditorSegment.tscn index b829d83..a0e53fe 100644 --- a/DungeonShooting_Godot/prefab/ui/TileSetEditorSegment.tscn +++ b/DungeonShooting_Godot/prefab/ui/TileSetEditorSegment.tscn @@ -18,6 +18,8 @@ anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 script = ExtResource("1_to1lc") [node name="HSplitContainer" type="HSplitContainer" parent="."] @@ -46,12 +48,25 @@ theme_override_constants/margin_bottom = 2 [node name="LeftBg" type="ColorRect" parent="HSplitContainer/Left/MarginContainer"] +clip_children = 2 +z_index = 1 layout_mode = 2 color = Color(0.203922, 0.203922, 0.203922, 1) script = ExtResource("3_dnmr6") -[node name="TileTexture" type="Sprite2D" parent="HSplitContainer/Left/MarginContainer/LeftBg"] -position = Vector2(547, 493) +[node name="TileTexture" type="TextureRect" parent="HSplitContainer/Left/MarginContainer/LeftBg"] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +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 texture = ExtResource("2_wr143") [node name="Grid" type="ColorRect" parent="HSplitContainer/Left/MarginContainer/LeftBg"] diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs index a9b0ead..3a5f751 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs @@ -47,7 +47,6 @@ Text = "地形", UiName = UiManager.UiNames.TileSetEditorTerrain, }); - TabGrid.SelectIndex = 0; } public override void OnDestroyUi() @@ -58,6 +57,11 @@ public void InitData(TileSetInfo tileSetInfo) { S_Title.Instance.Text = "正在编辑:" + tileSetInfo.Name; + + TexturePath = "icon.png"; + Texture = ImageTexture.CreateFromImage(Image.LoadFromFile(TexturePath)); + + TabGrid.SelectIndex = 0; } //返回上一级按钮点击 diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImportPanel.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImportPanel.cs index 3e93a36..732f083 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImportPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImportPanel.cs @@ -10,6 +10,7 @@ private bool _isOpenColorPicker; private TileSetEditor.TileSetEditorPanel _tileSetEditor; + private bool _initTexture = false; public override void OnCreateUi() { @@ -33,7 +34,14 @@ _dragBinder.UnBind(); } - + public override void OnShowUi() + { + if (!_initTexture && _tileSetEditor.Texture != null) + { + SetTexture(_tileSetEditor.Texture); + } + } + public override void _Input(InputEvent @event) { if (@event is InputEventMouseButton mouseButton) @@ -138,7 +146,6 @@ SetImportTexture(file); } - } /// @@ -151,7 +158,15 @@ var imageTexture = ImageTexture.CreateFromImage(Image.LoadFromFile(file)); _tileSetEditor.TexturePath = file; _tileSetEditor.Texture = imageTexture; - + SetTexture(imageTexture); + } + + /// + /// 设置纹理 + /// + public void SetTexture(Texture2D imageTexture) + { + _initTexture = true; var textureRect = S_Control.L_ImportPreview.Instance; if (textureRect.Texture != null) { @@ -167,5 +182,4 @@ S_ImportIcon.Instance.Visible = false; S_ImportButton.Instance.Visible = false; } - } diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorSegment/TileSetEditorSegment.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorSegment/TileSetEditorSegment.cs index abec544..a0b796c 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorSegment/TileSetEditorSegment.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorSegment/TileSetEditorSegment.cs @@ -30,12 +30,12 @@ } /// - /// 类型: , 路径: TileSetEditorSegment.HSplitContainer.Left.MarginContainer.LeftBg.TileTexture + /// 类型: , 路径: TileSetEditorSegment.HSplitContainer.Left.MarginContainer.LeftBg.TileTexture /// - public class TileTexture : UiNode + public class TileTexture : UiNode { - public TileTexture(TileSetEditorSegmentPanel uiPanel, Godot.Sprite2D node) : base(uiPanel, node) { } - public override TileTexture Clone() => new (UiPanel, (Godot.Sprite2D)Instance.Duplicate()); + public TileTexture(TileSetEditorSegmentPanel uiPanel, Godot.TextureRect node) : base(uiPanel, node) { } + public override TileTexture Clone() => new (UiPanel, (Godot.TextureRect)Instance.Duplicate()); } /// @@ -53,13 +53,13 @@ public class LeftBg : UiNode { /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorSegment.HSplitContainer.Left.MarginContainer.TileTexture + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorSegment.HSplitContainer.Left.MarginContainer.TileTexture /// public TileTexture L_TileTexture { get { - if (_L_TileTexture == null) _L_TileTexture = new TileTexture(UiPanel, Instance.GetNode("TileTexture")); + if (_L_TileTexture == null) _L_TileTexture = new TileTexture(UiPanel, Instance.GetNode("TileTexture")); return _L_TileTexture; } } @@ -194,7 +194,7 @@ /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorSegment.HSplitContainer.Left.MarginContainer.LeftBg.TileTexture + /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorSegment.HSplitContainer.Left.MarginContainer.LeftBg.TileTexture /// public TileTexture S_TileTexture => L_HSplitContainer.L_Left.L_MarginContainer.L_LeftBg.L_TileTexture; diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorSegment/TileSetEditorSegmentLeftBg.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorSegment/TileSetEditorSegmentLeftBg.cs index 91d8844..60a98fd 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorSegment/TileSetEditorSegmentLeftBg.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorSegment/TileSetEditorSegmentLeftBg.cs @@ -23,9 +23,8 @@ { if (state == DragState.DragMove) { - var p = _leftBg.L_TileTexture.Instance.Position + pos; - _leftBg.L_TileTexture.Instance.Position = p; - _leftBg.L_Grid.Instance.Material.SetShaderMaterialParameter(ShaderParamNames.Offset, -p); + _leftBg.L_TileTexture.Instance.Position += pos; + OnLeftBgResize(); } } @@ -40,10 +39,7 @@ if (GetGlobalRect().HasPoint(mouseButton.GlobalPosition)) { //缩小 - var scale = _leftBg.L_TileTexture.Instance.Scale; - scale = new Vector2(Mathf.Max(0.1f, scale.X / 1.1f), Mathf.Max(0.1f, scale.Y / 1.1f)); - _leftBg.L_TileTexture.Instance.Scale = scale; - OnLeftBgResize(); + Shrink(); } } else if (mouseButton.ButtonIndex == MouseButton.WheelUp) @@ -51,15 +47,52 @@ if (GetGlobalRect().HasPoint(mouseButton.GlobalPosition)) { //放大 - var scale = _leftBg.L_TileTexture.Instance.Scale; - scale = new Vector2(Mathf.Min(20f, scale.X * 1.1f), Mathf.Min(20f, scale.Y * 1.1f)); - _leftBg.L_TileTexture.Instance.Scale = scale; - OnLeftBgResize(); + Magnify(); } } } } } + + //缩小 + private void Shrink() + { + // var sprite = _leftBg.L_TileTexture.Instance; + // var pos = sprite.GetLocalMousePosition(); + // var scale = sprite.Scale / 1.1f; + // if (scale.LengthSquared() >= 0.5f) + // { + // sprite.Scale = scale; + // var tempPos = sprite.Position + pos * 0.1f * scale; + // SetGridTransform(tempPos, scale.X); + // } + // OnLeftBgResize(); + + var scale = _leftBg.L_TileTexture.Instance.Scale; + scale = new Vector2(Mathf.Max(0.1f, scale.X / 1.1f), Mathf.Max(0.1f, scale.Y / 1.1f)); + _leftBg.L_TileTexture.Instance.Scale = scale; + OnLeftBgResize(); + } + //放大 + private void Magnify() + { + // var sprite = _leftBg.L_TileTexture.Instance; + // var pos = GetLocalMousePosition(); + // var prevScale = sprite.Scale; + // var scale = prevScale * 1.1f; + // if (scale.LengthSquared() <= 2000) + // { + // sprite.Scale = scale; + // var tempPos = sprite.Position - pos * 0.1f * prevScale; + // SetGridTransform(tempPos, scale.X); + // } + // OnLeftBgResize(); + + var scale = _leftBg.L_TileTexture.Instance.Scale; + scale = new Vector2(Mathf.Min(20f, scale.X * 1.1f), Mathf.Min(20f, scale.Y * 1.1f)); + _leftBg.L_TileTexture.Instance.Scale = scale; + OnLeftBgResize(); + } /// /// 当前Ui被显示出来时调用 @@ -67,10 +100,10 @@ public void OnShow() { //背景颜色 - Color = _leftBg.UiPanel.EditorPanel.BgColor; - OnLeftBgResize(); + Color = _leftBg.UiPanel.EditorPanel.BgColor; + OnLeftBgResize(); } - + //背景宽度变化 private void OnLeftBgResize() { @@ -78,7 +111,13 @@ sprite.Texture = _leftBg.UiPanel.EditorPanel.Texture; var colorRect = _leftBg.L_Grid.Instance; colorRect.Material.SetShaderMaterialParameter(ShaderParamNames.Size, Size); - colorRect.Material.SetShaderMaterialParameter(ShaderParamNames.GridSize, GameConfig.TileCellSize * sprite.Scale.X); - + SetGridTransform(sprite.Position, sprite.Scale.X); + } + + private void SetGridTransform(Vector2 pos, float scale) + { + var colorRect = _leftBg.L_Grid.Instance; + colorRect.Material.SetShaderMaterialParameter(ShaderParamNames.GridSize, GameConfig.TileCellSize * scale); + colorRect.Material.SetShaderMaterialParameter(ShaderParamNames.Offset, -pos); } } \ No newline at end of file