diff --git a/DungeonShooting_Godot/prefab/ui/TileSetEditor.tscn b/DungeonShooting_Godot/prefab/ui/TileSetEditor.tscn index 644e9cf..fe00307 100644 --- a/DungeonShooting_Godot/prefab/ui/TileSetEditor.tscn +++ b/DungeonShooting_Godot/prefab/ui/TileSetEditor.tscn @@ -1,11 +1,8 @@ -[gd_scene load_steps=7 format=3 uid="uid://dn5brsxa6w3l6"] +[gd_scene load_steps=4 format=3 uid="uid://dn5brsxa6w3l6"] [ext_resource type="Script" path="res://src/game/ui/tileSetEditor/TileSetEditorPanel.cs" id="1_rgx4n"] [ext_resource type="Texture2D" uid="uid://cajcnlimvoxk" path="res://resource/sprite/ui/commonIcon/Back.png" id="2_naycu"] [ext_resource type="Texture2D" uid="uid://cat35d7ueu7gu" path="res://resource/sprite/ui/commonIcon/Save.png" id="3_bcuxk"] -[ext_resource type="Texture2D" uid="uid://0878uloew5jo" path="res://resource/sprite/ui/commonIcon/Block.png" id="4_g67x4"] -[ext_resource type="Script" path="res://src/game/ui/tileSetEditor/TileSetEditorImportRoot.cs" id="4_ua8n7"] -[ext_resource type="Texture2D" uid="uid://duos2p6if4kcp" path="res://resource/sprite/ui/commonIcon/Import.png" id="6_4ra02"] [node name="TileSetEditor" type="Control"] layout_mode = 3 @@ -93,136 +90,12 @@ layout_mode = 2 size_flags_horizontal = 3 -[node name="ImportTab" type="Button" parent="Bg/VBoxContainer/HBoxContainer/LeftRoot/MarginContainer/GridContainer/VBoxContainer"] +[node name="Tab" type="Button" parent="Bg/VBoxContainer/HBoxContainer/LeftRoot/MarginContainer/GridContainer/VBoxContainer"] custom_minimum_size = Vector2(0, 60) layout_mode = 2 text = "纹理" -[node name="TileCellTab" type="Button" parent="Bg/VBoxContainer/HBoxContainer/LeftRoot/MarginContainer/GridContainer/VBoxContainer"] -custom_minimum_size = Vector2(0, 60) -layout_mode = 2 -text = "图块" - -[node name="TerrainTab" type="Button" parent="Bg/VBoxContainer/HBoxContainer/LeftRoot/MarginContainer/GridContainer/VBoxContainer"] -custom_minimum_size = Vector2(0, 60) -layout_mode = 2 -text = "地形" - -[node name="PatternTab" type="Button" parent="Bg/VBoxContainer/HBoxContainer/LeftRoot/MarginContainer/GridContainer/VBoxContainer"] -custom_minimum_size = Vector2(0, 60) -layout_mode = 2 -text = "组合" - -[node name="ObjectTab" type="Button" parent="Bg/VBoxContainer/HBoxContainer/LeftRoot/MarginContainer/GridContainer/VBoxContainer"] -custom_minimum_size = Vector2(0, 60) -layout_mode = 2 -text = "物体" - -[node name="TrapBtn" type="Button" parent="Bg/VBoxContainer/HBoxContainer/LeftRoot/MarginContainer/GridContainer/VBoxContainer"] -custom_minimum_size = Vector2(0, 60) -layout_mode = 2 -text = "陷阱" - [node name="RightRoot" type="Panel" parent="Bg/VBoxContainer/HBoxContainer"] layout_mode = 2 size_flags_horizontal = 3 size_flags_stretch_ratio = 8.0 - -[node name="ImportRoot" type="TextureRect" parent="Bg/VBoxContainer/HBoxContainer/RightRoot"] -clip_children = 1 -layout_mode = 2 -offset_right = 1707.0 -offset_bottom = 1010.0 -size_flags_vertical = 3 -texture = ExtResource("4_g67x4") -script = ExtResource("4_ua8n7") - -[node name="ImportButton" type="Button" parent="Bg/VBoxContainer/HBoxContainer/RightRoot/ImportRoot"] -layout_mode = 1 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 -flat = true - -[node name="ImportLabel" type="Label" parent="Bg/VBoxContainer/HBoxContainer/RightRoot/ImportRoot"] -layout_mode = 1 -anchors_preset = 8 -anchor_left = 0.5 -anchor_top = 0.5 -anchor_right = 0.5 -anchor_bottom = 0.5 -offset_left = -276.0 -offset_top = 61.0 -offset_right = 276.0 -offset_bottom = 101.0 -grow_horizontal = 2 -grow_vertical = 2 -text = "点击导入纹理或者将纹理拖拽到该区域, 格式为'.png'" - -[node name="ImportIcon" type="TextureRect" parent="Bg/VBoxContainer/HBoxContainer/RightRoot/ImportRoot"] -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 -mouse_filter = 2 -texture = ExtResource("6_4ra02") - -[node name="ImportPreviewBg" type="ColorRect" parent="Bg/VBoxContainer/HBoxContainer/RightRoot/ImportRoot"] -layout_mode = 1 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 -mouse_filter = 2 -color = Color(0.278431, 0.278431, 0.278431, 1) - -[node name="Control" type="Control" parent="Bg/VBoxContainer/HBoxContainer/RightRoot/ImportRoot"] -layout_mode = 1 -anchors_preset = 8 -anchor_left = 0.5 -anchor_top = 0.5 -anchor_right = 0.5 -anchor_bottom = 0.5 -offset_left = -0.5 -offset_top = -0.5 -offset_right = 0.5 -offset_bottom = 0.5 -grow_horizontal = 2 -grow_vertical = 2 - -[node name="ImportPreview" type="Sprite2D" parent="Bg/VBoxContainer/HBoxContainer/RightRoot/ImportRoot/Control"] - -[node name="ImportColorPicker" type="Button" parent="Bg/VBoxContainer/HBoxContainer/RightRoot/ImportRoot"] -layout_mode = 1 -anchors_preset = 1 -anchor_left = 1.0 -anchor_right = 1.0 -offset_left = -238.0 -offset_top = 25.0 -offset_right = -34.0 -offset_bottom = 82.0 -grow_horizontal = 0 -text = "背景颜色" - -[node name="ReimportButton" type="Button" parent="Bg/VBoxContainer/HBoxContainer/RightRoot/ImportRoot"] -layout_mode = 1 -anchors_preset = 1 -anchor_left = 1.0 -anchor_right = 1.0 -offset_left = -238.0 -offset_top = 106.0 -offset_right = -34.0 -offset_bottom = 163.0 -grow_horizontal = 0 -text = "重新导入" diff --git a/DungeonShooting_Godot/prefab/ui/TileSetEditorImport.tscn b/DungeonShooting_Godot/prefab/ui/TileSetEditorImport.tscn new file mode 100644 index 0000000..208baa3 --- /dev/null +++ b/DungeonShooting_Godot/prefab/ui/TileSetEditorImport.tscn @@ -0,0 +1,101 @@ +[gd_scene load_steps=3 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"] + +[node name="TileSetEditorImport" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource("1_rkxih") + +[node name="ImportPreviewBg" type="ColorRect" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 +color = Color(0.278431, 0.278431, 0.278431, 1) + +[node name="ImportButton" type="Button" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +flat = true + +[node name="ImportLabel" type="Label" parent="."] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -388.0 +offset_top = 39.0 +offset_right = 388.0 +offset_bottom = 79.0 +grow_horizontal = 2 +grow_vertical = 2 +text = "点击导入纹理或者将纹理拖拽到该区域, 格式为'.png'" + +[node name="ImportIcon" type="TextureRect" parent="."] +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 +mouse_filter = 2 +texture = ExtResource("2_cc6ug") + +[node name="Control" type="Control" parent="."] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -0.5 +offset_top = -0.5 +offset_right = 0.5 +offset_bottom = 0.5 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="ImportPreview" type="Sprite2D" parent="Control"] + +[node name="ImportColorPicker" type="Button" parent="."] +layout_mode = 1 +anchors_preset = 1 +anchor_left = 1.0 +anchor_right = 1.0 +offset_left = -269.0 +offset_top = 50.0 +offset_right = -65.0 +offset_bottom = 107.0 +grow_horizontal = 0 +text = "背景颜色" + +[node name="ReimportButton" type="Button" parent="."] +layout_mode = 1 +anchors_preset = 1 +anchor_left = 1.0 +anchor_right = 1.0 +offset_left = -269.0 +offset_top = 131.0 +offset_right = -65.0 +offset_bottom = 188.0 +grow_horizontal = 0 +text = "重新导入" diff --git a/DungeonShooting_Godot/src/game/manager/ResourcePath.cs b/DungeonShooting_Godot/src/game/manager/ResourcePath.cs index 43d6178..be86866 100644 --- a/DungeonShooting_Godot/src/game/manager/ResourcePath.cs +++ b/DungeonShooting_Godot/src/game/manager/ResourcePath.cs @@ -64,7 +64,6 @@ public const string prefab_ui_BottomTips_tscn = "res://prefab/ui/BottomTips.tscn"; public const string prefab_ui_Debugger_tscn = "res://prefab/ui/Debugger.tscn"; public const string prefab_ui_EditorColorPicker_tscn = "res://prefab/ui/EditorColorPicker.tscn"; - public const string prefab_ui_EditorFileDialog_tscn = "res://prefab/ui/EditorFileDialog.tscn"; public const string prefab_ui_EditorTips_tscn = "res://prefab/ui/EditorTips.tscn"; public const string prefab_ui_EditorTools_tscn = "res://prefab/ui/EditorTools.tscn"; public const string prefab_ui_EditorWindow_tscn = "res://prefab/ui/EditorWindow.tscn"; @@ -86,6 +85,7 @@ public const string prefab_ui_Setting_tscn = "res://prefab/ui/Setting.tscn"; public const string prefab_ui_Settlement_tscn = "res://prefab/ui/Settlement.tscn"; public const string prefab_ui_TileSetEditor_tscn = "res://prefab/ui/TileSetEditor.tscn"; + public const string prefab_ui_TileSetEditorImport_tscn = "res://prefab/ui/TileSetEditorImport.tscn"; public const string prefab_ui_TileSetEditorProject_tscn = "res://prefab/ui/TileSetEditorProject.tscn"; public const string prefab_weapon_Weapon0001_tscn = "res://prefab/weapon/Weapon0001.tscn"; public const string prefab_weapon_Weapon0002_tscn = "res://prefab/weapon/Weapon0002.tscn"; diff --git a/DungeonShooting_Godot/src/game/manager/UiManager_Methods.cs b/DungeonShooting_Godot/src/game/manager/UiManager_Methods.cs index 77558f6..5b9c65c 100644 --- a/DungeonShooting_Godot/src/game/manager/UiManager_Methods.cs +++ b/DungeonShooting_Godot/src/game/manager/UiManager_Methods.cs @@ -29,6 +29,7 @@ public const string Setting = "Setting"; public const string Settlement = "Settlement"; public const string TileSetEditor = "TileSetEditor"; + public const string TileSetEditorImport = "TileSetEditorImport"; public const string TileSetEditorProject = "TileSetEditorProject"; } @@ -1185,6 +1186,54 @@ } /// + /// 创建 TileSetEditorImport, 并返回UI实例, 该函数不会打开 Ui + /// + public static UI.TileSetEditorImport.TileSetEditorImportPanel Create_TileSetEditorImport() + { + return CreateUi(UiNames.TileSetEditorImport); + } + + /// + /// 打开 TileSetEditorImport, 并返回UI实例 + /// + public static UI.TileSetEditorImport.TileSetEditorImportPanel Open_TileSetEditorImport() + { + return OpenUi(UiNames.TileSetEditorImport); + } + + /// + /// 隐藏 TileSetEditorImport 的所有实例 + /// + public static void Hide_TileSetEditorImport() + { + var uiInstance = Get_TileSetEditorImport_Instance(); + foreach (var uiPanel in uiInstance) + { + uiPanel.HideUi(); + } + } + + /// + /// 销毁 TileSetEditorImport 的所有实例 + /// + public static void Destroy_TileSetEditorImport() + { + var uiInstance = Get_TileSetEditorImport_Instance(); + foreach (var uiPanel in uiInstance) + { + uiPanel.Destroy(); + } + } + + /// + /// 获取所有 TileSetEditorImport 的实例, 如果没有实例, 则返回一个空数组 + /// + public static UI.TileSetEditorImport.TileSetEditorImportPanel[] Get_TileSetEditorImport_Instance() + { + return GetUiInstance(nameof(UI.TileSetEditorImport.TileSetEditorImport)); + } + + /// /// 创建 TileSetEditorProject, 并返回UI实例, 该函数不会打开 Ui /// public static UI.TileSetEditorProject.TileSetEditorProjectPanel Create_TileSetEditorProject() diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditor.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditor.cs index 2fad5b9..9ac15a4 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditor.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditor.cs @@ -25,7 +25,6 @@ public sealed override void OnInitNestedUi() { - _ = L_Bg.L_VBoxContainer.L_HBoxContainer.L_RightRoot.L_ImportRoot; } @@ -105,57 +104,12 @@ } /// - /// 类型: , 路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.LeftRoot.MarginContainer.GridContainer.VBoxContainer.ImportTab + /// 类型: , 路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.LeftRoot.MarginContainer.GridContainer.VBoxContainer.Tab /// - public class ImportTab : UiNode + public class Tab : UiNode { - public ImportTab(TileSetEditorPanel uiPanel, Godot.Button node) : base(uiPanel, node) { } - public override ImportTab Clone() => new (UiPanel, (Godot.Button)Instance.Duplicate()); - } - - /// - /// 类型: , 路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.LeftRoot.MarginContainer.GridContainer.VBoxContainer.TileCellTab - /// - public class TileCellTab : UiNode - { - public TileCellTab(TileSetEditorPanel uiPanel, Godot.Button node) : base(uiPanel, node) { } - public override TileCellTab Clone() => new (UiPanel, (Godot.Button)Instance.Duplicate()); - } - - /// - /// 类型: , 路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.LeftRoot.MarginContainer.GridContainer.VBoxContainer.TerrainTab - /// - public class TerrainTab : UiNode - { - public TerrainTab(TileSetEditorPanel uiPanel, Godot.Button node) : base(uiPanel, node) { } - public override TerrainTab Clone() => new (UiPanel, (Godot.Button)Instance.Duplicate()); - } - - /// - /// 类型: , 路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.LeftRoot.MarginContainer.GridContainer.VBoxContainer.PatternTab - /// - public class PatternTab : UiNode - { - public PatternTab(TileSetEditorPanel uiPanel, Godot.Button node) : base(uiPanel, node) { } - public override PatternTab Clone() => new (UiPanel, (Godot.Button)Instance.Duplicate()); - } - - /// - /// 类型: , 路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.LeftRoot.MarginContainer.GridContainer.VBoxContainer.ObjectTab - /// - public class ObjectTab : UiNode - { - public ObjectTab(TileSetEditorPanel uiPanel, Godot.Button node) : base(uiPanel, node) { } - public override ObjectTab Clone() => new (UiPanel, (Godot.Button)Instance.Duplicate()); - } - - /// - /// 类型: , 路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.LeftRoot.MarginContainer.GridContainer.VBoxContainer.TrapBtn - /// - public class TrapBtn : UiNode - { - public TrapBtn(TileSetEditorPanel uiPanel, Godot.Button node) : base(uiPanel, node) { } - public override TrapBtn Clone() => new (UiPanel, (Godot.Button)Instance.Duplicate()); + public Tab(TileSetEditorPanel uiPanel, Godot.Button node) : base(uiPanel, node) { } + public override Tab Clone() => new (UiPanel, (Godot.Button)Instance.Duplicate()); } /// @@ -164,82 +118,17 @@ public class VBoxContainer_1 : UiNode { /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.LeftRoot.MarginContainer.GridContainer.ImportTab + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.LeftRoot.MarginContainer.GridContainer.Tab /// - public ImportTab L_ImportTab + public Tab L_Tab { get { - if (_L_ImportTab == null) _L_ImportTab = new ImportTab(UiPanel, Instance.GetNode("ImportTab")); - return _L_ImportTab; + if (_L_Tab == null) _L_Tab = new Tab(UiPanel, Instance.GetNode("Tab")); + return _L_Tab; } } - private ImportTab _L_ImportTab; - - /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.LeftRoot.MarginContainer.GridContainer.TileCellTab - /// - public TileCellTab L_TileCellTab - { - get - { - if (_L_TileCellTab == null) _L_TileCellTab = new TileCellTab(UiPanel, Instance.GetNode("TileCellTab")); - return _L_TileCellTab; - } - } - private TileCellTab _L_TileCellTab; - - /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.LeftRoot.MarginContainer.GridContainer.TerrainTab - /// - public TerrainTab L_TerrainTab - { - get - { - if (_L_TerrainTab == null) _L_TerrainTab = new TerrainTab(UiPanel, Instance.GetNode("TerrainTab")); - return _L_TerrainTab; - } - } - private TerrainTab _L_TerrainTab; - - /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.LeftRoot.MarginContainer.GridContainer.PatternTab - /// - public PatternTab L_PatternTab - { - get - { - if (_L_PatternTab == null) _L_PatternTab = new PatternTab(UiPanel, Instance.GetNode("PatternTab")); - return _L_PatternTab; - } - } - private PatternTab _L_PatternTab; - - /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.LeftRoot.MarginContainer.GridContainer.ObjectTab - /// - public ObjectTab L_ObjectTab - { - get - { - if (_L_ObjectTab == null) _L_ObjectTab = new ObjectTab(UiPanel, Instance.GetNode("ObjectTab")); - return _L_ObjectTab; - } - } - private ObjectTab _L_ObjectTab; - - /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.LeftRoot.MarginContainer.GridContainer.TrapBtn - /// - public TrapBtn L_TrapBtn - { - get - { - if (_L_TrapBtn == null) _L_TrapBtn = new TrapBtn(UiPanel, Instance.GetNode("TrapBtn")); - return _L_TrapBtn; - } - } - private TrapBtn _L_TrapBtn; + private Tab _L_Tab; public VBoxContainer_1(TileSetEditorPanel uiPanel, Godot.VBoxContainer node) : base(uiPanel, node) { } public override VBoxContainer_1 Clone() => new (UiPanel, (Godot.VBoxContainer)Instance.Duplicate()); @@ -312,208 +201,10 @@ } /// - /// 类型: , 路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportRoot.ImportButton - /// - public class ImportButton : UiNode - { - public ImportButton(TileSetEditorPanel uiPanel, Godot.Button node) : base(uiPanel, node) { } - public override ImportButton Clone() => new (UiPanel, (Godot.Button)Instance.Duplicate()); - } - - /// - /// 类型: , 路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportRoot.ImportLabel - /// - public class ImportLabel : UiNode - { - public ImportLabel(TileSetEditorPanel uiPanel, Godot.Label node) : base(uiPanel, node) { } - public override ImportLabel Clone() => new (UiPanel, (Godot.Label)Instance.Duplicate()); - } - - /// - /// 类型: , 路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportRoot.ImportIcon - /// - public class ImportIcon : UiNode - { - public ImportIcon(TileSetEditorPanel uiPanel, Godot.TextureRect node) : base(uiPanel, node) { } - public override ImportIcon Clone() => new (UiPanel, (Godot.TextureRect)Instance.Duplicate()); - } - - /// - /// 类型: , 路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportRoot.ImportPreviewBg - /// - public class ImportPreviewBg : UiNode - { - public ImportPreviewBg(TileSetEditorPanel uiPanel, Godot.ColorRect node) : base(uiPanel, node) { } - public override ImportPreviewBg Clone() => new (UiPanel, (Godot.ColorRect)Instance.Duplicate()); - } - - /// - /// 类型: , 路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportRoot.Control.ImportPreview - /// - public class ImportPreview : UiNode - { - public ImportPreview(TileSetEditorPanel uiPanel, Godot.Sprite2D node) : base(uiPanel, node) { } - public override ImportPreview Clone() => new (UiPanel, (Godot.Sprite2D)Instance.Duplicate()); - } - - /// - /// 类型: , 路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportRoot.Control - /// - public class Control : UiNode - { - /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportRoot.ImportPreview - /// - public ImportPreview L_ImportPreview - { - get - { - if (_L_ImportPreview == null) _L_ImportPreview = new ImportPreview(UiPanel, Instance.GetNode("ImportPreview")); - return _L_ImportPreview; - } - } - private ImportPreview _L_ImportPreview; - - public Control(TileSetEditorPanel uiPanel, Godot.Control node) : base(uiPanel, node) { } - public override Control Clone() => new (UiPanel, (Godot.Control)Instance.Duplicate()); - } - - /// - /// 类型: , 路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportRoot.ImportColorPicker - /// - public class ImportColorPicker : UiNode - { - public ImportColorPicker(TileSetEditorPanel uiPanel, Godot.Button node) : base(uiPanel, node) { } - public override ImportColorPicker Clone() => new (UiPanel, (Godot.Button)Instance.Duplicate()); - } - - /// - /// 类型: , 路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportRoot.ReimportButton - /// - public class ReimportButton : UiNode - { - public ReimportButton(TileSetEditorPanel uiPanel, Godot.Button node) : base(uiPanel, node) { } - public override ReimportButton Clone() => new (UiPanel, (Godot.Button)Instance.Duplicate()); - } - - /// - /// 类型: , 路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportRoot - /// - public class ImportRoot : UiNode - { - /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportButton - /// - public ImportButton L_ImportButton - { - get - { - if (_L_ImportButton == null) _L_ImportButton = new ImportButton(UiPanel, Instance.GetNode("ImportButton")); - return _L_ImportButton; - } - } - private ImportButton _L_ImportButton; - - /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportLabel - /// - public ImportLabel L_ImportLabel - { - get - { - if (_L_ImportLabel == null) _L_ImportLabel = new ImportLabel(UiPanel, Instance.GetNode("ImportLabel")); - return _L_ImportLabel; - } - } - private ImportLabel _L_ImportLabel; - - /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportIcon - /// - public ImportIcon L_ImportIcon - { - get - { - if (_L_ImportIcon == null) _L_ImportIcon = new ImportIcon(UiPanel, Instance.GetNode("ImportIcon")); - return _L_ImportIcon; - } - } - private ImportIcon _L_ImportIcon; - - /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportPreviewBg - /// - public ImportPreviewBg L_ImportPreviewBg - { - get - { - if (_L_ImportPreviewBg == null) _L_ImportPreviewBg = new ImportPreviewBg(UiPanel, Instance.GetNode("ImportPreviewBg")); - return _L_ImportPreviewBg; - } - } - private ImportPreviewBg _L_ImportPreviewBg; - - /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.Control - /// - public Control L_Control - { - get - { - if (_L_Control == null) _L_Control = new Control(UiPanel, Instance.GetNode("Control")); - return _L_Control; - } - } - private Control _L_Control; - - /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportColorPicker - /// - public ImportColorPicker L_ImportColorPicker - { - get - { - if (_L_ImportColorPicker == null) _L_ImportColorPicker = new ImportColorPicker(UiPanel, Instance.GetNode("ImportColorPicker")); - return _L_ImportColorPicker; - } - } - private ImportColorPicker _L_ImportColorPicker; - - /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ReimportButton - /// - public ReimportButton L_ReimportButton - { - get - { - if (_L_ReimportButton == null) _L_ReimportButton = new ReimportButton(UiPanel, Instance.GetNode("ReimportButton")); - return _L_ReimportButton; - } - } - private ReimportButton _L_ReimportButton; - - public ImportRoot(TileSetEditorPanel uiPanel, UI.TileSetEditor.TileSetEditorImportRoot node) : base(uiPanel, node) { } - public override ImportRoot Clone() => new (UiPanel, (UI.TileSetEditor.TileSetEditorImportRoot)Instance.Duplicate()); - } - - /// /// 类型: , 路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot /// public class RightRoot : UiNode { - /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.ImportRoot - /// - public ImportRoot L_ImportRoot - { - get - { - if (_L_ImportRoot == null) _L_ImportRoot = new ImportRoot(UiPanel, Instance.GetNode("ImportRoot")); - return _L_ImportRoot; - } - } - private ImportRoot _L_ImportRoot; - public RightRoot(TileSetEditorPanel uiPanel, Godot.Panel node) : base(uiPanel, node) { } public override RightRoot Clone() => new (UiPanel, (Godot.Panel)Instance.Duplicate()); } @@ -632,34 +323,9 @@ public Head S_Head => L_Bg.L_VBoxContainer.L_Head; /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.LeftRoot.MarginContainer.GridContainer.VBoxContainer.ImportTab + /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.LeftRoot.MarginContainer.GridContainer.VBoxContainer.Tab /// - public ImportTab S_ImportTab => L_Bg.L_VBoxContainer.L_HBoxContainer.L_LeftRoot.L_MarginContainer.L_GridContainer.L_VBoxContainer.L_ImportTab; - - /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.LeftRoot.MarginContainer.GridContainer.VBoxContainer.TileCellTab - /// - public TileCellTab S_TileCellTab => L_Bg.L_VBoxContainer.L_HBoxContainer.L_LeftRoot.L_MarginContainer.L_GridContainer.L_VBoxContainer.L_TileCellTab; - - /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.LeftRoot.MarginContainer.GridContainer.VBoxContainer.TerrainTab - /// - public TerrainTab S_TerrainTab => L_Bg.L_VBoxContainer.L_HBoxContainer.L_LeftRoot.L_MarginContainer.L_GridContainer.L_VBoxContainer.L_TerrainTab; - - /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.LeftRoot.MarginContainer.GridContainer.VBoxContainer.PatternTab - /// - public PatternTab S_PatternTab => L_Bg.L_VBoxContainer.L_HBoxContainer.L_LeftRoot.L_MarginContainer.L_GridContainer.L_VBoxContainer.L_PatternTab; - - /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.LeftRoot.MarginContainer.GridContainer.VBoxContainer.ObjectTab - /// - public ObjectTab S_ObjectTab => L_Bg.L_VBoxContainer.L_HBoxContainer.L_LeftRoot.L_MarginContainer.L_GridContainer.L_VBoxContainer.L_ObjectTab; - - /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.LeftRoot.MarginContainer.GridContainer.VBoxContainer.TrapBtn - /// - public TrapBtn S_TrapBtn => L_Bg.L_VBoxContainer.L_HBoxContainer.L_LeftRoot.L_MarginContainer.L_GridContainer.L_VBoxContainer.L_TrapBtn; + public Tab S_Tab => L_Bg.L_VBoxContainer.L_HBoxContainer.L_LeftRoot.L_MarginContainer.L_GridContainer.L_VBoxContainer.L_Tab; /// /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.LeftRoot.MarginContainer.GridContainer @@ -677,51 +343,6 @@ public LeftRoot S_LeftRoot => L_Bg.L_VBoxContainer.L_HBoxContainer.L_LeftRoot; /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportRoot.ImportButton - /// - public ImportButton S_ImportButton => L_Bg.L_VBoxContainer.L_HBoxContainer.L_RightRoot.L_ImportRoot.L_ImportButton; - - /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportRoot.ImportLabel - /// - public ImportLabel S_ImportLabel => L_Bg.L_VBoxContainer.L_HBoxContainer.L_RightRoot.L_ImportRoot.L_ImportLabel; - - /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportRoot.ImportIcon - /// - public ImportIcon S_ImportIcon => L_Bg.L_VBoxContainer.L_HBoxContainer.L_RightRoot.L_ImportRoot.L_ImportIcon; - - /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportRoot.ImportPreviewBg - /// - public ImportPreviewBg S_ImportPreviewBg => L_Bg.L_VBoxContainer.L_HBoxContainer.L_RightRoot.L_ImportRoot.L_ImportPreviewBg; - - /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportRoot.Control.ImportPreview - /// - public ImportPreview S_ImportPreview => L_Bg.L_VBoxContainer.L_HBoxContainer.L_RightRoot.L_ImportRoot.L_Control.L_ImportPreview; - - /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportRoot.Control - /// - public Control S_Control => L_Bg.L_VBoxContainer.L_HBoxContainer.L_RightRoot.L_ImportRoot.L_Control; - - /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportRoot.ImportColorPicker - /// - public ImportColorPicker S_ImportColorPicker => L_Bg.L_VBoxContainer.L_HBoxContainer.L_RightRoot.L_ImportRoot.L_ImportColorPicker; - - /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportRoot.ReimportButton - /// - public ReimportButton S_ReimportButton => L_Bg.L_VBoxContainer.L_HBoxContainer.L_RightRoot.L_ImportRoot.L_ReimportButton; - - /// - /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot.ImportRoot - /// - public ImportRoot S_ImportRoot => L_Bg.L_VBoxContainer.L_HBoxContainer.L_RightRoot.L_ImportRoot; - - /// /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditor.Bg.VBoxContainer.HBoxContainer.RightRoot /// public RightRoot S_RightRoot => L_Bg.L_VBoxContainer.L_HBoxContainer.L_RightRoot; diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorImportRoot.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorImportRoot.cs deleted file mode 100644 index 0489b97..0000000 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorImportRoot.cs +++ /dev/null @@ -1,154 +0,0 @@ -using System.IO; -using Godot; - -namespace UI.TileSetEditor; - -public partial class TileSetEditorImportRoot : TextureRect, IUiNodeScript -{ - private TileSetEditor.ImportRoot _importRoot; - private DragBinder _dragBinder; - //是否打开了颜色选择器 - private bool _isOpenColorPicker; - - public void SetUiNode(IUiNode uiNode) - { - _importRoot = (TileSetEditor.ImportRoot)uiNode; - _dragBinder = DragUiManager.BindDrag(_importRoot.L_ImportButton.Instance, OnDragCallback); - GetTree().Root.FilesDropped += OnFilesDropped; - _importRoot.L_ImportButton.Instance.Pressed += OnImportButtonClick; - _importRoot.L_ReimportButton.Instance.Pressed += OnReimportButtonClick; - _importRoot.L_ImportColorPicker.Instance.Pressed += OnColorPickerClick; - - _importRoot.L_ImportPreviewBg.Instance.Visible = false; - _importRoot.L_ReimportButton.Instance.Visible = false; - } - - public void OnDestroy() - { - GetTree().Root.FilesDropped -= OnFilesDropped; - _dragBinder.UnBind(); - } - - public override void _Input(InputEvent @event) - { - if (@event is InputEventMouseButton mouseButton) - { - var textureRect = _importRoot.L_Control.L_ImportPreview.Instance; - if (textureRect.Visible) - { - if (mouseButton.ButtonIndex == MouseButton.WheelDown) - { - //缩小 - 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; - } - else if (mouseButton.ButtonIndex == MouseButton.WheelUp) - { - //放大 - var scale = textureRect.Scale; - scale = new Vector2(Mathf.Min(20f, scale.X * 1.1f), Mathf.Min(20f, scale.Y * 1.1f)); - textureRect.Scale = scale; - } - } - } - } - - //点击导入按钮 - private void OnImportButtonClick() - { - if (_importRoot.UiPanel.Texture != null) - { - return; - } - - OnReimportButtonClick(); - } - - //重新导入 - private void OnReimportButtonClick() - { - EditorWindowManager.ShowOpenFileDialog(["*.png"], (path) => - { - if (path != null) - { - SetImportTexture(path); - } - }); - } - - //点击调整背景颜色 - private void OnColorPickerClick() - { - if (!_isOpenColorPicker) - { - _isOpenColorPicker = true; - EditorWindowManager.ShowColorPicker( - _importRoot.L_ImportColorPicker.Instance.GlobalPosition, - _importRoot.L_ImportPreviewBg.Instance.Color, - //设置颜色 - color => { _importRoot.L_ImportPreviewBg.Instance.Color = color; }, - //关闭窗口 - () => { _isOpenColorPicker = false; } - ); - } - } - - //拖拽区域回调 - private void OnDragCallback(DragState state, Vector2 position) - { - var sprite2D = _importRoot.L_Control.L_ImportPreview.Instance; - if (state == DragState.DragMove && sprite2D.Visible) - { - sprite2D.Position += position; - } - } - - //拖拽文件进入区域 - private void OnFilesDropped(string[] files) - { - if (files.Length == 0) - { - return; - } - var flag = GetGlobalRect().HasPoint(GetGlobalMousePosition()); - if (flag) - { - var file = files[0]; - if (Path.GetExtension(file) != ".png") - { - EditorWindowManager.ShowTips("警告", "只能导入'.png'格式的文件!"); - return; - } - - SetImportTexture(file); - } - - } - - /// - /// 导入纹理 - /// - /// 纹理路径 - private void SetImportTexture(string file) - { - Debug.Log("导入文件: " + file); - var imageTexture = ImageTexture.CreateFromImage(Image.LoadFromFile(file)); - _importRoot.UiPanel.TexturePath = file; - _importRoot.UiPanel.Texture = imageTexture; - - var textureRect = _importRoot.L_Control.L_ImportPreview.Instance; - if (textureRect.Texture != null) - { - textureRect.Texture.Dispose(); - } - - textureRect.Texture = imageTexture; - _importRoot.L_ImportPreviewBg.Instance.Visible = true; - _importRoot.L_ReimportButton.Instance.Visible = true; - - //隐藏导入文本和icon - _importRoot.L_ImportLabel.Instance.Visible = false; - _importRoot.L_ImportIcon.Instance.Visible = false; - } -} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs index 330bf7c..3996042 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs @@ -14,10 +14,19 @@ /// public Texture Texture; + private UiGrid _tabGrid; + public override void OnCreateUi() { S_Back.Instance.Visible = PrevUi != null; S_Back.Instance.Pressed += OnBackClick; + + _tabGrid = new UiGrid(S_Tab, typeof(object)); + } + + public override void OnDestroyUi() + { + _tabGrid.Destroy(); } public void InitData(TileSetInfo tileSetInfo) diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorTabData.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorTabData.cs new file mode 100644 index 0000000..414f15a --- /dev/null +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorTabData.cs @@ -0,0 +1,17 @@ +namespace UI.TileSetEditor; + +/// +/// 页签数据 +/// +public class TileSetEditorTabData +{ + /// + /// 显示文本 + /// + public string Text; + + /// + /// 打开的Ui + /// + public string UiName; +} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImport.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImport.cs new file mode 100644 index 0000000..0d51288 --- /dev/null +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImport.cs @@ -0,0 +1,235 @@ +namespace UI.TileSetEditorImport; + +/// +/// Ui代码, 该类是根据ui场景自动生成的, 请不要手动编辑该类, 以免造成代码丢失 +/// +public abstract partial class TileSetEditorImport : UiBase +{ + /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorImport.ImportPreviewBg + /// + public ImportPreviewBg L_ImportPreviewBg + { + get + { + if (_L_ImportPreviewBg == null) _L_ImportPreviewBg = new ImportPreviewBg((TileSetEditorImportPanel)this, GetNode("ImportPreviewBg")); + return _L_ImportPreviewBg; + } + } + private ImportPreviewBg _L_ImportPreviewBg; + + /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorImport.ImportButton + /// + public ImportButton L_ImportButton + { + get + { + if (_L_ImportButton == null) _L_ImportButton = new ImportButton((TileSetEditorImportPanel)this, GetNode("ImportButton")); + return _L_ImportButton; + } + } + private ImportButton _L_ImportButton; + + /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorImport.ImportLabel + /// + public ImportLabel L_ImportLabel + { + get + { + if (_L_ImportLabel == null) _L_ImportLabel = new ImportLabel((TileSetEditorImportPanel)this, GetNode("ImportLabel")); + return _L_ImportLabel; + } + } + private ImportLabel _L_ImportLabel; + + /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorImport.ImportIcon + /// + public ImportIcon L_ImportIcon + { + get + { + if (_L_ImportIcon == null) _L_ImportIcon = new ImportIcon((TileSetEditorImportPanel)this, GetNode("ImportIcon")); + return _L_ImportIcon; + } + } + private ImportIcon _L_ImportIcon; + + /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorImport.Control + /// + public Control L_Control + { + get + { + if (_L_Control == null) _L_Control = new Control((TileSetEditorImportPanel)this, GetNode("Control")); + return _L_Control; + } + } + private Control _L_Control; + + /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorImport.ImportColorPicker + /// + public ImportColorPicker L_ImportColorPicker + { + get + { + if (_L_ImportColorPicker == null) _L_ImportColorPicker = new ImportColorPicker((TileSetEditorImportPanel)this, GetNode("ImportColorPicker")); + return _L_ImportColorPicker; + } + } + private ImportColorPicker _L_ImportColorPicker; + + /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorImport.ReimportButton + /// + public ReimportButton L_ReimportButton + { + get + { + if (_L_ReimportButton == null) _L_ReimportButton = new ReimportButton((TileSetEditorImportPanel)this, GetNode("ReimportButton")); + return _L_ReimportButton; + } + } + private ReimportButton _L_ReimportButton; + + + public TileSetEditorImport() : base(nameof(TileSetEditorImport)) + { + } + + public sealed override void OnInitNestedUi() + { + + } + + /// + /// 类型: , 路径: TileSetEditorImport.ImportPreviewBg + /// + public class ImportPreviewBg : UiNode + { + public ImportPreviewBg(TileSetEditorImportPanel uiPanel, Godot.ColorRect node) : base(uiPanel, node) { } + public override ImportPreviewBg Clone() => new (UiPanel, (Godot.ColorRect)Instance.Duplicate()); + } + + /// + /// 类型: , 路径: TileSetEditorImport.ImportButton + /// + public class ImportButton : UiNode + { + public ImportButton(TileSetEditorImportPanel uiPanel, Godot.Button node) : base(uiPanel, node) { } + public override ImportButton Clone() => new (UiPanel, (Godot.Button)Instance.Duplicate()); + } + + /// + /// 类型: , 路径: TileSetEditorImport.ImportLabel + /// + public class ImportLabel : UiNode + { + public ImportLabel(TileSetEditorImportPanel uiPanel, Godot.Label node) : base(uiPanel, node) { } + public override ImportLabel Clone() => new (UiPanel, (Godot.Label)Instance.Duplicate()); + } + + /// + /// 类型: , 路径: TileSetEditorImport.ImportIcon + /// + public class ImportIcon : UiNode + { + public ImportIcon(TileSetEditorImportPanel uiPanel, Godot.TextureRect node) : base(uiPanel, node) { } + public override ImportIcon Clone() => new (UiPanel, (Godot.TextureRect)Instance.Duplicate()); + } + + /// + /// 类型: , 路径: TileSetEditorImport.Control.ImportPreview + /// + public class ImportPreview : UiNode + { + public ImportPreview(TileSetEditorImportPanel uiPanel, Godot.Sprite2D node) : base(uiPanel, node) { } + public override ImportPreview Clone() => new (UiPanel, (Godot.Sprite2D)Instance.Duplicate()); + } + + /// + /// 类型: , 路径: TileSetEditorImport.Control + /// + public class Control : UiNode + { + /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: TileSetEditorImport.ImportPreview + /// + public ImportPreview L_ImportPreview + { + get + { + if (_L_ImportPreview == null) _L_ImportPreview = new ImportPreview(UiPanel, Instance.GetNode("ImportPreview")); + return _L_ImportPreview; + } + } + private ImportPreview _L_ImportPreview; + + public Control(TileSetEditorImportPanel uiPanel, Godot.Control node) : base(uiPanel, node) { } + public override Control Clone() => new (UiPanel, (Godot.Control)Instance.Duplicate()); + } + + /// + /// 类型: , 路径: TileSetEditorImport.ImportColorPicker + /// + public class ImportColorPicker : UiNode + { + public ImportColorPicker(TileSetEditorImportPanel uiPanel, Godot.Button node) : base(uiPanel, node) { } + public override ImportColorPicker Clone() => new (UiPanel, (Godot.Button)Instance.Duplicate()); + } + + /// + /// 类型: , 路径: TileSetEditorImport.ReimportButton + /// + public class ReimportButton : UiNode + { + public ReimportButton(TileSetEditorImportPanel uiPanel, Godot.Button node) : base(uiPanel, node) { } + public override ReimportButton Clone() => new (UiPanel, (Godot.Button)Instance.Duplicate()); + } + + + /// + /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorImport.ImportPreviewBg + /// + public ImportPreviewBg S_ImportPreviewBg => L_ImportPreviewBg; + + /// + /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorImport.ImportButton + /// + public ImportButton S_ImportButton => L_ImportButton; + + /// + /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorImport.ImportLabel + /// + public ImportLabel S_ImportLabel => L_ImportLabel; + + /// + /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorImport.ImportIcon + /// + public ImportIcon S_ImportIcon => L_ImportIcon; + + /// + /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorImport.Control.ImportPreview + /// + public ImportPreview S_ImportPreview => L_Control.L_ImportPreview; + + /// + /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorImport.Control + /// + public Control S_Control => L_Control; + + /// + /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorImport.ImportColorPicker + /// + public ImportColorPicker S_ImportColorPicker => L_ImportColorPicker; + + /// + /// 场景中唯一名称的节点, 节点类型: , 节点路径: TileSetEditorImport.ReimportButton + /// + public ReimportButton S_ReimportButton => L_ReimportButton; + +} diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImportPanel.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImportPanel.cs new file mode 100644 index 0000000..43caebc --- /dev/null +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorImport/TileSetEditorImportPanel.cs @@ -0,0 +1,157 @@ +using System.IO; +using Godot; + +namespace UI.TileSetEditorImport; + +public partial class TileSetEditorImportPanel : TileSetEditorImport +{ + private DragBinder _dragBinder; + //是否打开了颜色选择器 + private bool _isOpenColorPicker; + + private TileSetEditor.TileSetEditorPanel _tileSetEditor; + + public override void OnCreateUi() + { + _tileSetEditor = (TileSetEditor.TileSetEditorPanel)ParentUi; + _dragBinder = DragUiManager.BindDrag(S_ImportButton.Instance, OnDragCallback); + GetTree().Root.FilesDropped += OnFilesDropped; + S_ImportButton.Instance.Pressed += OnImportButtonClick; + S_ReimportButton.Instance.Pressed += OnReimportButtonClick; + S_ImportColorPicker.Instance.Pressed += OnColorPickerClick; + + S_ImportPreviewBg.Instance.Visible = false; + S_ReimportButton.Instance.Visible = false; + } + + public override void OnDestroyUi() + { + GetTree().Root.FilesDropped -= OnFilesDropped; + _dragBinder.UnBind(); + } + + + public override void _Input(InputEvent @event) + { + if (@event is InputEventMouseButton mouseButton) + { + var textureRect = S_Control.L_ImportPreview.Instance; + if (textureRect.Visible) + { + if (mouseButton.ButtonIndex == MouseButton.WheelDown) + { + //缩小 + 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; + } + else if (mouseButton.ButtonIndex == MouseButton.WheelUp) + { + //放大 + var scale = textureRect.Scale; + scale = new Vector2(Mathf.Min(20f, scale.X * 1.1f), Mathf.Min(20f, scale.Y * 1.1f)); + textureRect.Scale = scale; + } + } + } + } + + //点击导入按钮 + private void OnImportButtonClick() + { + if (_tileSetEditor.Texture != null) + { + return; + } + + OnReimportButtonClick(); + } + + //重新导入 + private void OnReimportButtonClick() + { + EditorWindowManager.ShowOpenFileDialog(["*.png"], (path) => + { + if (path != null) + { + SetImportTexture(path); + } + }); + } + + //点击调整背景颜色 + private void OnColorPickerClick() + { + if (!_isOpenColorPicker) + { + _isOpenColorPicker = true; + EditorWindowManager.ShowColorPicker( + S_ImportColorPicker.Instance.GlobalPosition, + S_ImportPreviewBg.Instance.Color, + //设置颜色 + color => { S_ImportPreviewBg.Instance.Color = color; }, + //关闭窗口 + () => { _isOpenColorPicker = false; } + ); + } + } + + //拖拽区域回调 + private void OnDragCallback(DragState state, Vector2 position) + { + var sprite2D = S_Control.L_ImportPreview.Instance; + if (state == DragState.DragMove && sprite2D.Visible) + { + sprite2D.Position += position; + } + } + + //拖拽文件进入区域 + private void OnFilesDropped(string[] files) + { + if (files.Length == 0) + { + return; + } + var flag = GetGlobalRect().HasPoint(GetGlobalMousePosition()); + if (flag) + { + var file = files[0]; + if (Path.GetExtension(file) != ".png") + { + EditorWindowManager.ShowTips("警告", "只能导入'.png'格式的文件!"); + return; + } + + SetImportTexture(file); + } + + } + + /// + /// 导入纹理 + /// + /// 纹理路径 + private void SetImportTexture(string file) + { + Debug.Log("导入文件: " + file); + var imageTexture = ImageTexture.CreateFromImage(Image.LoadFromFile(file)); + _tileSetEditor.TexturePath = file; + _tileSetEditor.Texture = imageTexture; + + var textureRect = S_Control.L_ImportPreview.Instance; + if (textureRect.Texture != null) + { + textureRect.Texture.Dispose(); + } + + textureRect.Texture = imageTexture; + S_ImportPreviewBg.Instance.Visible = true; + S_ReimportButton.Instance.Visible = true; + + //隐藏导入文本和icon + S_ImportLabel.Instance.Visible = false; + S_ImportIcon.Instance.Visible = false; + } + +}