diff --git a/DungeonShooting_Godot/addons/dungeonShooting_plugin/NodeMonitor.cs b/DungeonShooting_Godot/addons/dungeonShooting_plugin/NodeMonitor.cs index f12aa0c..fbae904 100644 --- a/DungeonShooting_Godot/addons/dungeonShooting_plugin/NodeMonitor.cs +++ b/DungeonShooting_Godot/addons/dungeonShooting_plugin/NodeMonitor.cs @@ -70,10 +70,18 @@ //更新前检查旧的节点是否发生改变 if (node != _targetNode && _targetNode != null) { - var tempNode = ParseNodeTree(_targetNode); - if (!_sceneNode.Equals(tempNode)) + try { - OnSceneNodeChange(_targetNode); + var tempNode = ParseNodeTree(_targetNode); + if (!_sceneNode.Equals(tempNode)) + { + OnSceneNodeChange(_targetNode); + } + } + catch (Exception e) + { + //检查节点存在报错, 直接跳过该节点的检查 + GD.PrintErr(e.ToString()); } } @@ -93,17 +101,25 @@ { if (_targetNode == null) return; - + _checkTreeTimer += delta; - if (_checkTreeTimer >= 1) + if (_checkTreeTimer >= 5) //5秒检查一次 { - var tempNode = ParseNodeTree(_targetNode); - if (!_sceneNode.Equals(tempNode)) + try { - OnSceneNodeChange(_targetNode); - _sceneNode = tempNode; + var tempNode = ParseNodeTree(_targetNode); + if (!_sceneNode.Equals(tempNode)) + { + OnSceneNodeChange(_targetNode); + _sceneNode = tempNode; + } } - + catch (Exception e) + { + //检查节点存在报错, 直接跳过该节点的检查 + GD.PrintErr(e.ToString()); + _targetNode = null; + } _checkTreeTimer = 0; } } diff --git a/DungeonShooting_Godot/addons/dungeonShooting_plugin/Plugin.cs b/DungeonShooting_Godot/addons/dungeonShooting_plugin/Plugin.cs index 714e16f..d1ad903 100644 --- a/DungeonShooting_Godot/addons/dungeonShooting_plugin/Plugin.cs +++ b/DungeonShooting_Godot/addons/dungeonShooting_plugin/Plugin.cs @@ -73,8 +73,6 @@ "res://addons/dungeonShooting_plugin/Mark.svg" ), }; - - private bool _clickSave = false; public override void _Process(double delta) { @@ -83,20 +81,6 @@ { _uiMonitor.Process((float) delta); } - - //按下 ctrl + s 保存 - if (Input.IsKeyPressed(Key.Ctrl) && Input.IsKeyPressed(Key.S)) - { - if (!_clickSave) - { - OnSaveClick(); - } - _clickSave = true; - } - else - { - _clickSave = false; - } } public override void _EnterTree() @@ -150,7 +134,7 @@ SceneChanged += OnSceneChanged; _uiMonitor = new NodeMonitor(); - _uiMonitor.SceneNodeChangeEvent += OnUiSceneChange; + _uiMonitor.SceneNodeChangeEvent += GenerateUiCode; } public override void _ExitTree() @@ -199,7 +183,7 @@ if (_uiMonitor != null) { - _uiMonitor.SceneNodeChangeEvent -= OnUiSceneChange; + _uiMonitor.SceneNodeChangeEvent -= GenerateUiCode; _uiMonitor = null; } } @@ -226,36 +210,12 @@ _editorTools.Visible = visible; } } - - //当ctrl+s按下 - private void OnSaveClick() - { - var root = GetEditorInterface().GetEditedSceneRoot(); - if (root != null) - { - if (CheckIsUi(root)) //生成ui代码 - { - OnUiSceneChange(root); - } - } - } - - /// - /// 切换场景 - /// - private void OnSceneChanged(Node node) - { - _uiMonitor.ChangeCurrentNode(null); - if (CheckIsUi(node)) - { - _uiMonitor.ChangeCurrentNode(node); - } - } - + + /// /// 检查节点是否为UI节点 /// - private bool CheckIsUi(Node node) + public bool CheckIsUi(Node node) { var resourcePath = node.GetScript().As()?.ResourcePath; if (resourcePath == null) @@ -277,22 +237,26 @@ return false; } - //ui场景存在修改 - private void OnUiSceneChange(Node node) + /// + /// 执行生成ui代码操作 + /// + public void GenerateUiCode(Node node) { - try + UiGenerator.GenerateUiCodeFromEditor(node); + } + + /// + /// 切换场景 + /// + private void OnSceneChanged(Node node) + { + _uiMonitor.ChangeCurrentNode(null); + if (CheckIsUi(node)) { - var uiName = node.Name.ToString(); - var path = GameConfig.UiCodeDir + uiName.FirstToLower() + "/" + uiName + ".cs"; - GD.Print("重新生成ui代码: " + path); - //生成ui代码 - UiGenerator.GenerateUiFromEditor(node, path); - } - catch (Exception e) - { - GD.PrintErr(e.ToString()); + _uiMonitor.ChangeCurrentNode(node); } } + } } #endif diff --git a/DungeonShooting_Godot/prefab/ui/EditorTools.tscn b/DungeonShooting_Godot/prefab/ui/EditorTools.tscn index 49235a7..9ad22fa 100644 --- a/DungeonShooting_Godot/prefab/ui/EditorTools.tscn +++ b/DungeonShooting_Godot/prefab/ui/EditorTools.tscn @@ -38,13 +38,13 @@ [node name="Label" type="Label" parent="ScrollContainer/MarginContainer/VBoxContainer/HBoxContainer"] layout_mode = 2 -text = "ResourcePath.cs" +text = "重新生成ResourcePath.cs文件" vertical_alignment = 1 [node name="Button" type="Button" parent="ScrollContainer/MarginContainer/VBoxContainer/HBoxContainer"] layout_mode = 2 size_flags_horizontal = 0 -text = "重新生成" +text = "运行" [node name="HBoxContainer2" type="HBoxContainer" parent="ScrollContainer/MarginContainer/VBoxContainer"] layout_mode = 2 @@ -52,11 +52,23 @@ [node name="Label" type="Label" parent="ScrollContainer/MarginContainer/VBoxContainer/HBoxContainer2"] layout_mode = 2 -text = "地牢房间配置" +text = "重新打包地牢房间配置" [node name="Button" type="Button" parent="ScrollContainer/MarginContainer/VBoxContainer/HBoxContainer2"] layout_mode = 2 -text = "重新打包" +text = "运行" + +[node name="HBoxContainer4" type="HBoxContainer" parent="ScrollContainer/MarginContainer/VBoxContainer"] +layout_mode = 2 +theme_override_constants/separation = 5 + +[node name="Label" type="Label" parent="ScrollContainer/MarginContainer/VBoxContainer/HBoxContainer4"] +layout_mode = 2 +text = "重新生成当前UI的代码" + +[node name="Button" type="Button" parent="ScrollContainer/MarginContainer/VBoxContainer/HBoxContainer4"] +layout_mode = 2 +text = "运行" [node name="HBoxContainer3" type="HBoxContainer" parent="ScrollContainer/MarginContainer/VBoxContainer"] layout_mode = 2 @@ -83,5 +95,4 @@ [node name="Tips" type="AcceptDialog" parent="."] initial_position = 1 -size = Vector2i(200, 124) unresizable = true diff --git a/DungeonShooting_Godot/resource/theme/mainTheme.tres b/DungeonShooting_Godot/resource/theme/mainTheme.tres index a8ca8c4..5a106f8 100644 --- a/DungeonShooting_Godot/resource/theme/mainTheme.tres +++ b/DungeonShooting_Godot/resource/theme/mainTheme.tres @@ -352,7 +352,7 @@ [sub_resource type="ImageTexture" id="58"] -[sub_resource type="Image" id="Image_87aka"] +[sub_resource type="Image" id="Image_hesun"] data = { "data": PackedByteArray(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 1, 255, 255, 255, 39, 255, 255, 255, 67, 255, 255, 255, 67, 255, 255, 255, 39, 255, 255, 255, 1, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 39, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 39, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 66, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 66, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 66, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 66, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 39, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 39, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 1, 255, 255, 255, 39, 255, 255, 255, 67, 255, 255, 255, 67, 255, 255, 255, 39, 255, 255, 255, 1, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "format": "RGBA8", @@ -362,7 +362,7 @@ } [sub_resource type="ImageTexture" id="60"] -image = SubResource("Image_87aka") +image = SubResource("Image_hesun") [sub_resource type="StyleBoxTexture" id="61"] content_margin_left = 2.0 @@ -372,7 +372,7 @@ texture = SubResource("60") region_rect = Rect2(0, 0, 12, 12) -[sub_resource type="Image" id="Image_lvs72"] +[sub_resource type="Image" id="Image_wi0e1"] data = { "data": PackedByteArray(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 191, 191, 191, 0, 247, 247, 247, 0, 248, 248, 248, 0, 248, 248, 248, 0, 247, 247, 247, 0, 191, 191, 191, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 191, 191, 191, 0, 191, 191, 191, 4, 247, 247, 247, 98, 248, 248, 248, 167, 248, 248, 248, 167, 247, 247, 247, 98, 191, 191, 191, 4, 191, 191, 191, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 247, 247, 247, 0, 247, 247, 247, 97, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 247, 247, 247, 97, 247, 247, 247, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 248, 248, 248, 0, 248, 248, 248, 164, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 164, 248, 248, 248, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 248, 248, 248, 0, 248, 248, 248, 164, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 164, 248, 248, 248, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 247, 247, 247, 0, 247, 247, 247, 97, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 247, 247, 247, 97, 247, 247, 247, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 191, 191, 191, 0, 191, 191, 191, 4, 247, 247, 247, 98, 248, 248, 248, 167, 248, 248, 248, 167, 247, 247, 247, 98, 191, 191, 191, 4, 191, 191, 191, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 191, 191, 191, 0, 247, 247, 247, 0, 248, 248, 248, 0, 248, 248, 248, 0, 247, 247, 247, 0, 191, 191, 191, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "format": "RGBA8", @@ -382,7 +382,7 @@ } [sub_resource type="ImageTexture" id="63"] -image = SubResource("Image_lvs72") +image = SubResource("Image_wi0e1") [sub_resource type="StyleBoxTexture" id="64"] content_margin_left = 2.0 @@ -392,7 +392,7 @@ texture = SubResource("63") region_rect = Rect2(0, 0, 12, 12) -[sub_resource type="Image" id="Image_iiw45"] +[sub_resource type="Image" id="Image_2csp5"] data = { "data": PackedByteArray(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 127, 127, 0, 173, 173, 173, 0, 173, 173, 173, 0, 173, 173, 173, 0, 173, 173, 173, 0, 127, 127, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 127, 127, 0, 127, 127, 127, 4, 173, 173, 173, 97, 173, 173, 173, 166, 173, 173, 173, 166, 173, 173, 173, 97, 127, 127, 127, 4, 127, 127, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 172, 172, 172, 0, 172, 172, 172, 96, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 172, 172, 172, 96, 172, 172, 172, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 173, 173, 173, 0, 173, 173, 173, 163, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 163, 173, 173, 173, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 173, 173, 173, 0, 173, 173, 173, 163, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 163, 173, 173, 173, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 172, 172, 172, 0, 172, 172, 172, 96, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 172, 172, 172, 96, 172, 172, 172, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 127, 127, 0, 127, 127, 127, 4, 173, 173, 173, 97, 173, 173, 173, 166, 173, 173, 173, 166, 173, 173, 173, 97, 127, 127, 127, 4, 127, 127, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 127, 127, 0, 173, 173, 173, 0, 173, 173, 173, 0, 173, 173, 173, 0, 173, 173, 173, 0, 127, 127, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "format": "RGBA8", @@ -402,7 +402,7 @@ } [sub_resource type="ImageTexture" id="66"] -image = SubResource("Image_iiw45") +image = SubResource("Image_2csp5") [sub_resource type="StyleBoxTexture" id="67"] content_margin_left = 2.0 @@ -412,7 +412,7 @@ texture = SubResource("66") region_rect = Rect2(0, 0, 12, 12) -[sub_resource type="Image" id="Image_c2227"] +[sub_resource type="Image" id="Image_jm034"] data = { "data": PackedByteArray(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 4, 255, 255, 255, 16, 255, 255, 255, 16, 255, 255, 255, 4, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 16, 255, 255, 255, 21, 255, 255, 255, 21, 255, 255, 255, 16, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 16, 255, 255, 255, 21, 255, 255, 255, 21, 255, 255, 255, 16, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 4, 255, 255, 255, 16, 255, 255, 255, 16, 255, 255, 255, 4, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "format": "RGBA8", @@ -422,7 +422,7 @@ } [sub_resource type="ImageTexture" id="69"] -image = SubResource("Image_c2227") +image = SubResource("Image_jm034") [sub_resource type="StyleBoxTexture" id="70"] content_margin_left = 0.0 @@ -446,7 +446,7 @@ content_margin_right = 4.0 content_margin_bottom = 4.0 -[sub_resource type="Image" id="Image_w18da"] +[sub_resource type="Image" id="Image_3cwrn"] data = { "data": PackedByteArray(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 76, 255, 255, 255, 17, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 17, 255, 255, 255, 76, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 76, 255, 255, 255, 228, 255, 255, 255, 188, 255, 255, 255, 17, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 17, 255, 255, 255, 188, 255, 255, 255, 228, 255, 255, 255, 76, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 18, 255, 255, 255, 188, 255, 255, 255, 229, 255, 255, 255, 187, 255, 255, 255, 17, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 17, 255, 255, 255, 187, 255, 255, 255, 229, 255, 255, 255, 188, 255, 255, 255, 18, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 19, 255, 255, 255, 188, 255, 255, 255, 229, 255, 255, 255, 185, 255, 255, 255, 17, 255, 255, 255, 17, 255, 255, 255, 186, 255, 255, 255, 229, 255, 255, 255, 188, 255, 255, 255, 19, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 19, 255, 255, 255, 190, 255, 255, 255, 229, 255, 255, 255, 185, 255, 255, 255, 185, 255, 255, 255, 229, 255, 255, 255, 189, 255, 255, 255, 19, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 19, 255, 255, 255, 191, 255, 255, 255, 229, 255, 255, 255, 229, 255, 255, 255, 190, 255, 255, 255, 19, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 17, 255, 255, 255, 188, 255, 255, 255, 229, 255, 255, 255, 229, 255, 255, 255, 188, 255, 255, 255, 17, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 17, 255, 255, 255, 188, 255, 255, 255, 229, 255, 255, 255, 188, 255, 255, 255, 188, 255, 255, 255, 229, 255, 255, 255, 187, 255, 255, 255, 17, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 17, 255, 255, 255, 187, 255, 255, 255, 229, 255, 255, 255, 188, 255, 255, 255, 18, 255, 255, 255, 19, 255, 255, 255, 188, 255, 255, 255, 229, 255, 255, 255, 186, 255, 255, 255, 17, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 17, 255, 255, 255, 185, 255, 255, 255, 229, 255, 255, 255, 189, 255, 255, 255, 19, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 19, 255, 255, 255, 189, 255, 255, 255, 229, 255, 255, 255, 185, 255, 255, 255, 17, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 76, 255, 255, 255, 229, 255, 255, 255, 190, 255, 255, 255, 19, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 19, 255, 255, 255, 190, 255, 255, 255, 229, 255, 255, 255, 76, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 77, 255, 255, 255, 19, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 19, 255, 255, 255, 77, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "format": "RGBA8", @@ -456,7 +456,7 @@ } [sub_resource type="ImageTexture" id="56"] -image = SubResource("Image_w18da") +image = SubResource("Image_3cwrn") [sub_resource type="StyleBoxFlat" id="57"] content_margin_left = 6.0 diff --git a/DungeonShooting_Godot/src/framework/generator/ResourcePathGenerator.cs b/DungeonShooting_Godot/src/framework/generator/ResourcePathGenerator.cs index 4416ee1..2ab0e39 100644 --- a/DungeonShooting_Godot/src/framework/generator/ResourcePathGenerator.cs +++ b/DungeonShooting_Godot/src/framework/generator/ResourcePathGenerator.cs @@ -1,4 +1,5 @@ +using System; using System.IO; using System.Linq; using System.Text.RegularExpressions; @@ -29,39 +30,49 @@ public static string savePath = "src/game/manager/ResourcePath.cs"; /// - /// 执行生成操作 + /// 执行生成操作, 返回是否执行成功 /// - public static void Generate() + public static bool Generate() { - resultStr = "/// \n" + - "/// 编辑器下所有资源路径, 该类为 Automation 面板下自动生成的, 请不要手动编辑!\n" + - "/// \n" + - "public class ResourcePath\n" + - "{\n"; - - GD.Print("更新 ResourcePath..."); - - var directoryInfo = new DirectoryInfo(currDir); - - var directories = directoryInfo.GetDirectories(); - for (int i = 0; i < directories.Length; i++) + try { - var directory = directories[i]; - if (!exclude.Contains(directory.Name)) + resultStr = "/// \n" + + "/// 编辑器下所有资源路径, 该类为 Automation 面板下自动生成的, 请不要手动编辑!\n" + + "/// \n" + + "public class ResourcePath\n" + + "{\n"; + + GD.Print("更新 ResourcePath..."); + + var directoryInfo = new DirectoryInfo(currDir); + + var directories = directoryInfo.GetDirectories(); + for (int i = 0; i < directories.Length; i++) { - EachDir(directory); + var directory = directories[i]; + if (!exclude.Contains(directory.Name)) + { + EachDir(directory); + } } - } - var fileInfos = directoryInfo.GetFiles(); - for (var i = 0; i < fileInfos.Length; i++) + var fileInfos = directoryInfo.GetFiles(); + for (var i = 0; i < fileInfos.Length; i++) + { + HandleFile(fileInfos[i]); + } + + resultStr += "}"; + File.WriteAllText(savePath, resultStr); + GD.Print("ResourcePath.cs 写出完成!"); + } + catch (Exception e) { - HandleFile(fileInfos[i]); + GD.PrintErr(e.ToString()); + return false; } - resultStr += "}"; - File.WriteAllText(savePath, resultStr); - GD.Print("ResourcePath.cs 写出完成!"); + return true; } private static void EachDir(DirectoryInfo directoryInfos) diff --git a/DungeonShooting_Godot/src/framework/generator/RoomPackGenerator.cs b/DungeonShooting_Godot/src/framework/generator/RoomPackGenerator.cs index 5d3a4ce..510757f 100644 --- a/DungeonShooting_Godot/src/framework/generator/RoomPackGenerator.cs +++ b/DungeonShooting_Godot/src/framework/generator/RoomPackGenerator.cs @@ -13,99 +13,107 @@ /// public static class RoomPackGenerator { - private static string _currDir = System.Environment.CurrentDirectory; - /// - /// 执行生成操作 + /// 执行生成操作, 返回是否执行成功 /// - public static void Generate() + public static bool Generate() { - //地图路径 - var tileDir = GameConfig.RoomTileDir; - //地图描述数据路径 - var tileDataDir = GameConfig.RoomTileDataDir; + try + { + //地图路径 + var tileDir = GameConfig.RoomTileDir; + //地图描述数据路径 + var tileDataDir = GameConfig.RoomTileDataDir; - var tileDirInfo = new DirectoryInfo(tileDir); - var tileDataDirInfo = new DirectoryInfo(tileDataDir); + var tileDirInfo = new DirectoryInfo(tileDir); + var tileDataDirInfo = new DirectoryInfo(tileDataDir); - //所有地图列表 - var mapList = new HashSet(); + //所有地图列表 + var mapList = new HashSet(); - //收集所有名称 - var fileDataInfos = tileDataDirInfo.GetFiles(); - foreach (var fileInfo in fileDataInfos) - { - mapList.Add(RemoveExtension(fileInfo.Name)); - } - //收集所有名称 - var fileInfos = tileDirInfo.GetFiles(); - foreach (var fileInfo in fileInfos) - { - if (fileInfo.Extension == ".tscn") - { - mapList.Add(RemoveExtension(fileInfo.Name)); - } - } + //收集所有名称 + var fileDataInfos = tileDataDirInfo.GetFiles(); + foreach (var fileInfo in fileDataInfos) + { + mapList.Add(RemoveExtension(fileInfo.Name)); + } + //收集所有名称 + var fileInfos = tileDirInfo.GetFiles(); + foreach (var fileInfo in fileInfos) + { + if (fileInfo.Extension == ".tscn") + { + mapList.Add(RemoveExtension(fileInfo.Name)); + } + } - //剔除多余的 tile.json - var arrays = mapList.ToArray(); - foreach (var item in arrays) - { - if (!File.Exists(tileDir + item + ".tscn")) - { - mapList.Remove(item); - var filePath = tileDataDir + item + ".json"; - if (File.Exists(filePath)) - { - GD.Print($"未找到'{tileDir + item}.tscn', 删除配置文件: {filePath}"); - File.Delete(filePath); - } - } - } + //剔除多余的 tile.json + var arrays = mapList.ToArray(); + foreach (var item in arrays) + { + if (!File.Exists(tileDir + item + ".tscn")) + { + mapList.Remove(item); + var filePath = tileDataDir + item + ".json"; + if (File.Exists(filePath)) + { + GD.Print($"未找到'{tileDir + item}.tscn', 删除配置文件: {filePath}"); + File.Delete(filePath); + } + } + } - //手动生成缺失的 tile.json - foreach (var item in mapList) - { - if (!File.Exists(tileDataDir + item + ".json")) - { - var tscnName = tileDir + item + ".tscn"; - var packedScene = ResourceManager.Load(tscnName, false); - if (packedScene != null) - { - var dungeonRoomTemplate = packedScene.Instantiate(); - var usedRect = dungeonRoomTemplate.GetUsedRect(); - var dungeonTile = new DungeonTile(dungeonRoomTemplate); - dungeonTile.SetFloorAtlasCoords(new List() { new Vector2I(0, 8) }); - //计算导航网格 - dungeonTile.GenerateNavigationPolygon(0); - var polygonData = dungeonTile.GetPolygonData(); - DungeonRoomTemplate.SaveConfig(new List(), usedRect.Position, usedRect.Size, polygonData.ToList(), item); - dungeonRoomTemplate.QueueFree(); - } - } - } + //手动生成缺失的 tile.json + foreach (var item in mapList) + { + if (!File.Exists(tileDataDir + item + ".json")) + { + var tscnName = tileDir + item + ".tscn"; + var packedScene = ResourceManager.Load(tscnName, false); + if (packedScene != null) + { + var dungeonRoomTemplate = packedScene.Instantiate(); + var usedRect = dungeonRoomTemplate.GetUsedRect(); + var dungeonTile = new DungeonTile(dungeonRoomTemplate); + dungeonTile.SetFloorAtlasCoords(new List() { new Vector2I(0, 8) }); + //计算导航网格 + dungeonTile.GenerateNavigationPolygon(0); + var polygonData = dungeonTile.GetPolygonData(); + DungeonRoomTemplate.SaveConfig(new List(), usedRect.Position, usedRect.Size, polygonData.ToList(), item); + dungeonRoomTemplate.QueueFree(); + } + } + } - var list = new List(); - //整合操作 - foreach (var item in mapList) - { - var configPath = tileDataDir + item + ".json"; - var configText = File.ReadAllText(configPath); - var roomInfo = DungeonRoomTemplate.DeserializeDungeonRoomInfo(configText); - var split = new DungeonRoomSplit(); - split.ScenePath = ToResPath(tileDir + item + ".tscn"); - split.ConfigPath = ToResPath(configPath); - split.RoomInfo = roomInfo; - list.Add(split); - } + var list = new List(); + //整合操作 + foreach (var item in mapList) + { + var configPath = tileDataDir + item + ".json"; + var configText = File.ReadAllText(configPath); + var roomInfo = DungeonRoomTemplate.DeserializeDungeonRoomInfo(configText); + var split = new DungeonRoomSplit(); + split.ScenePath = ToResPath(tileDir + item + ".tscn"); + split.ConfigPath = ToResPath(configPath); + split.RoomInfo = roomInfo; + list.Add(split); + } - //写出配置 - var config = new JsonSerializerOptions(); - config.WriteIndented = true; - var text = JsonSerializer.Serialize(list, config); - File.WriteAllText(GameConfig.RoomTileConfigFile, text); + //写出配置 + var config = new JsonSerializerOptions(); + config.WriteIndented = true; + var text = JsonSerializer.Serialize(list, config); + File.WriteAllText(GameConfig.RoomTileConfigFile, text); - GD.Print("地牢房间配置, 重新打包完成!"); + GD.Print("地牢房间配置, 重新打包完成!"); + } + catch (Exception e) + { + GD.PrintErr(e.ToString()); + return false; + } + + return true; } private static string ToResPath(string path) diff --git a/DungeonShooting_Godot/src/framework/generator/UiGenerator.cs b/DungeonShooting_Godot/src/framework/generator/UiGenerator.cs index ddd40cc..4f8a2a1 100644 --- a/DungeonShooting_Godot/src/framework/generator/UiGenerator.cs +++ b/DungeonShooting_Godot/src/framework/generator/UiGenerator.cs @@ -14,10 +14,70 @@ { private static Dictionary _nodeNameMap = new Dictionary(); + public static bool CreateUi(string uiName) + { + try + { + //创建脚本代码 + var scriptPath = GameConfig.UiCodeDir + uiName.FirstToLower(); + var scriptFile = scriptPath + "/" + uiName + "Panel.cs"; + var scriptCode = $"using Godot;\n" + + $"\n" + + $"namespace UI.{uiName};\n" + + $"\n" + + $"public partial class {uiName}Panel : {uiName}\n" + + $"{{\n" + + $"\n" + + $" public override void OnShowUi(params object[] args)\n" + + $" {{\n" + + $" \n" + + $" }}\n" + + $"" + + $" public override void OnHideUi()\n" + + $" {{\n" + + $" \n" + + $" }}\n" + + $"\n" + + $"}}\n"; + if (!Directory.Exists(scriptPath)) + { + Directory.CreateDirectory(scriptPath); + } + File.WriteAllText(scriptFile, scriptCode); + + //加载脚本资源 + var scriptRes = GD.Load("res://" + scriptFile); + + //创建场景资源 + var prefabFile = GameConfig.UiPrefabDir + uiName + ".tscn"; + if (!Directory.Exists(GameConfig.UiPrefabDir)) + { + Directory.CreateDirectory(GameConfig.UiPrefabDir); + } + var uiNode = new Control(); + uiNode.Name = uiName; + uiNode.SetAnchorsPreset(Control.LayoutPreset.FullRect, true); + uiNode.SetScript(scriptRes); + var scene = new PackedScene(); + scene.Pack(uiNode); + ResourceSaver.Save(scene, "res://" + prefabFile); + + //生成Ui结构代码 + GenerateUiCode(uiNode, scriptPath + "/" + uiName + ".cs"); + } + catch (Exception e) + { + GD.PrintErr(e.ToString()); + return false; + } + + return true; + } + /// /// 根据指定ui节点生成相应的Ui类, 并保存到指定路径下 /// - public static void GenerateUi(Node control, string path) + public static void GenerateUiCode(Node control, string path) { _nodeNameMap.Clear(); var uiNode = EachNode(control); @@ -28,12 +88,27 @@ /// /// 从编辑器中生成ui代码 /// - public static void GenerateUiFromEditor(Node control, string path) + public static bool GenerateUiCodeFromEditor(Node control) { - _nodeNameMap.Clear(); - var uiNode = EachNodeFromEditor(control); - var code = GenerateClassCode(uiNode); - File.WriteAllText(path, code); + try + { + _nodeNameMap.Clear(); + + var uiName = control.Name.ToString(); + var path = GameConfig.UiCodeDir + uiName.FirstToLower() + "/" + uiName + ".cs"; + GD.Print("重新生成ui代码: " + path); + + var uiNode = EachNodeFromEditor(control); + var code = GenerateClassCode(uiNode); + File.WriteAllText(path, code); + } + catch (Exception e) + { + GD.PrintErr(e.ToString()); + return false; + } + + return true; } private static string GenerateClassCode(UiNodeInfo uiNodeInfo) diff --git a/DungeonShooting_Godot/src/game/GameConfig.cs b/DungeonShooting_Godot/src/game/GameConfig.cs index 33785d1..238deea 100644 --- a/DungeonShooting_Godot/src/game/GameConfig.cs +++ b/DungeonShooting_Godot/src/game/GameConfig.cs @@ -52,6 +52,10 @@ /// public const string RoomTileConfigFile = "resource/map/RoomConfig.json"; /// + /// ui预制体路径 + /// + public const string UiPrefabDir = "prefab/ui/"; + /// /// ui代码根路径 /// public const string UiCodeDir = "src/game/ui/"; diff --git a/DungeonShooting_Godot/src/game/ui/editorTools/EditorTools.cs b/DungeonShooting_Godot/src/game/ui/editorTools/EditorTools.cs index f5a0046..1f93ee4 100644 --- a/DungeonShooting_Godot/src/game/ui/editorTools/EditorTools.cs +++ b/DungeonShooting_Godot/src/game/ui/editorTools/EditorTools.cs @@ -153,7 +153,7 @@ } /// - /// 类型: , 路径: EditorTools.ScrollContainer.MarginContainer.VBoxContainer.HBoxContainer3.Label + /// 类型: , 路径: EditorTools.ScrollContainer.MarginContainer.VBoxContainer.HBoxContainer4.Label /// public class UiNode2_Label : IUiNode { @@ -162,6 +162,59 @@ } /// + /// 类型: , 路径: EditorTools.ScrollContainer.MarginContainer.VBoxContainer.HBoxContainer4.Button + /// + public class UiNode2_Button : IUiNode + { + public UiNode2_Button(Godot.Button node) : base(node) { } + public override UiNode2_Button Clone() => new ((Godot.Button)Instance.Duplicate()); + } + + /// + /// 类型: , 路径: EditorTools.ScrollContainer.MarginContainer.VBoxContainer.HBoxContainer4 + /// + public class UiNode_HBoxContainer4 : IUiNode + { + /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: EditorTools.ScrollContainer.MarginContainer.VBoxContainer.Label + /// + public UiNode2_Label L_Label + { + get + { + if (_L_Label == null) _L_Label = new UiNode2_Label(Instance.GetNodeOrNull("Label")); + return _L_Label; + } + } + private UiNode2_Label _L_Label; + + /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: EditorTools.ScrollContainer.MarginContainer.VBoxContainer.Button + /// + public UiNode2_Button L_Button + { + get + { + if (_L_Button == null) _L_Button = new UiNode2_Button(Instance.GetNodeOrNull("Button")); + return _L_Button; + } + } + private UiNode2_Button _L_Button; + + public UiNode_HBoxContainer4(Godot.HBoxContainer node) : base(node) { } + public override UiNode_HBoxContainer4 Clone() => new ((Godot.HBoxContainer)Instance.Duplicate()); + } + + /// + /// 类型: , 路径: EditorTools.ScrollContainer.MarginContainer.VBoxContainer.HBoxContainer3.Label + /// + public class UiNode3_Label : IUiNode + { + public UiNode3_Label(Godot.Label node) : base(node) { } + public override UiNode3_Label Clone() => new ((Godot.Label)Instance.Duplicate()); + } + + /// /// 类型: , 路径: EditorTools.ScrollContainer.MarginContainer.VBoxContainer.HBoxContainer3.LineEdit /// public class UiNode_LineEdit : IUiNode @@ -173,10 +226,10 @@ /// /// 类型: , 路径: EditorTools.ScrollContainer.MarginContainer.VBoxContainer.HBoxContainer3.Button /// - public class UiNode2_Button : IUiNode + public class UiNode3_Button : IUiNode { - public UiNode2_Button(Godot.Button node) : base(node) { } - public override UiNode2_Button Clone() => new ((Godot.Button)Instance.Duplicate()); + public UiNode3_Button(Godot.Button node) : base(node) { } + public override UiNode3_Button Clone() => new ((Godot.Button)Instance.Duplicate()); } /// @@ -187,15 +240,15 @@ /// /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: EditorTools.ScrollContainer.MarginContainer.VBoxContainer.Label /// - public UiNode2_Label L_Label + public UiNode3_Label L_Label { get { - if (_L_Label == null) _L_Label = new UiNode2_Label(Instance.GetNodeOrNull("Label")); + if (_L_Label == null) _L_Label = new UiNode3_Label(Instance.GetNodeOrNull("Label")); return _L_Label; } } - private UiNode2_Label _L_Label; + private UiNode3_Label _L_Label; /// /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: EditorTools.ScrollContainer.MarginContainer.VBoxContainer.LineEdit @@ -213,15 +266,15 @@ /// /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: EditorTools.ScrollContainer.MarginContainer.VBoxContainer.Button /// - public UiNode2_Button L_Button + public UiNode3_Button L_Button { get { - if (_L_Button == null) _L_Button = new UiNode2_Button(Instance.GetNodeOrNull("Button")); + if (_L_Button == null) _L_Button = new UiNode3_Button(Instance.GetNodeOrNull("Button")); return _L_Button; } } - private UiNode2_Button _L_Button; + private UiNode3_Button _L_Button; public UiNode_HBoxContainer3(Godot.HBoxContainer node) : base(node) { } public override UiNode_HBoxContainer3 Clone() => new ((Godot.HBoxContainer)Instance.Duplicate()); @@ -259,6 +312,19 @@ private UiNode_HBoxContainer2 _L_HBoxContainer2; /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: EditorTools.ScrollContainer.MarginContainer.HBoxContainer4 + /// + public UiNode_HBoxContainer4 L_HBoxContainer4 + { + get + { + if (_L_HBoxContainer4 == null) _L_HBoxContainer4 = new UiNode_HBoxContainer4(Instance.GetNodeOrNull("HBoxContainer4")); + return _L_HBoxContainer4; + } + } + private UiNode_HBoxContainer4 _L_HBoxContainer4; + + /// /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: EditorTools.ScrollContainer.MarginContainer.HBoxContainer3 /// public UiNode_HBoxContainer3 L_HBoxContainer3 diff --git a/DungeonShooting_Godot/src/game/ui/editorTools/EditorToolsPanel.cs b/DungeonShooting_Godot/src/game/ui/editorTools/EditorToolsPanel.cs index 1b35d41..a9d99b4 100644 --- a/DungeonShooting_Godot/src/game/ui/editorTools/EditorToolsPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/editorTools/EditorToolsPanel.cs @@ -1,4 +1,6 @@ using System; +using System.IO; +using System.Text.RegularExpressions; using Generator; using Godot; @@ -35,6 +37,8 @@ container.L_HBoxContainer.L_Button.Instance.Pressed += GenerateResourcePath; //重新生成 RoomPack container.L_HBoxContainer2.L_Button.Instance.Pressed += GenerateRoomPack; + //重新生成ui代码 + container.L_HBoxContainer4.L_Button.Instance.Pressed += OnGenerateCurrentUiCode; //创建ui container.L_HBoxContainer3.L_Button.Instance.Pressed += OnCreateUI; } @@ -52,6 +56,7 @@ var container = L_ScrollContainer.L_MarginContainer.L_VBoxContainer; container.L_HBoxContainer.L_Button.Instance.Pressed -= GenerateResourcePath; container.L_HBoxContainer2.L_Button.Instance.Pressed -= GenerateRoomPack; + container.L_HBoxContainer4.L_Button.Instance.Pressed -= OnGenerateCurrentUiCode; container.L_HBoxContainer3.L_Button.Instance.Pressed -= OnCreateUI; } @@ -166,6 +171,34 @@ L_Confirm.Instance.Hide(); _onConfirmClose = null; } + + /// + /// 重新生成当前ui的代码 + /// + private void OnGenerateCurrentUiCode() + { +#if TOOLS + if (Plugin.Plugin.Instance != null) + { + var root = Plugin.Plugin.Instance.GetEditorInterface().GetEditedSceneRoot(); + if (Plugin.Plugin.Instance.CheckIsUi(root)) + { + if (UiGenerator.GenerateUiCodeFromEditor(root)) + { + ShowTips("提示", "生成UI代码执行成功!"); + } + else + { + ShowTips("错误", "生成UI代码执行失败! 前往控制台查看错误日志!"); + } + } + else + { + ShowTips("错误", "当前的场景不是受管束的UI场景!"); + } + } +#endif + } /// /// 创建Ui @@ -177,7 +210,31 @@ { if (result) { - ShowTips("提示", "创建Ui成功!"); + //检查名称是否合规 + if (!Regex.IsMatch(text, "^[A-Z][a-zA-Z0-9]*$")) + { + ShowTips("错误", "UI名称'" + text + "'不符合名称约束, UI名称只允许大写字母开头, 且名称中只允许出现大小字母和数字!"); + return; + } + + //检查是否有同名的Ui + var path = GameConfig.UiCodeDir + text.FirstToLower(); + if (Directory.Exists(path)) + { + ShowTips("错误", "已经存在相同名称'" + text + "'的UI了, 不能重复创建!"); + return; + } + + //执行创建操作 + if (UiGenerator.CreateUi(text)) + { + ShowTips("提示", "创建UI成功!"); + } + else + { + ShowTips("错误", "创建UI失败! 前往控制台查看错误日志!"); + } + } }); } @@ -187,7 +244,14 @@ /// private void GenerateResourcePath() { - ResourcePathGenerator.Generate(); + if (ResourcePathGenerator.Generate()) + { + ShowTips("提示", "ResourcePath.cs生成完成!"); + } + else + { + ShowTips("错误", "ResourcePath.cs生成失败! 前往控制台查看错误日志!"); + } } /// @@ -195,6 +259,13 @@ /// private void GenerateRoomPack() { - RoomPackGenerator.Generate(); + if (RoomPackGenerator.Generate()) + { + ShowTips("提示", "打包地牢房间配置执行完成!"); + } + else + { + ShowTips("错误", "打包地牢房间配置执行失败! 前往控制台查看错误日志!"); + } } } diff --git a/DungeonShooting_Godot/src/game/ui/roomUI/RoomUIPanel.cs b/DungeonShooting_Godot/src/game/ui/roomUI/RoomUIPanel.cs index 6c4d956..f1fdc34 100644 --- a/DungeonShooting_Godot/src/game/ui/roomUI/RoomUIPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/roomUI/RoomUIPanel.cs @@ -1,4 +1,3 @@ -using Godot; namespace UI.RoomUI;