Tag is now supported when creating a room.

创建房间时支持指定Tag了。
This commit is contained in:
Cold-Mint 2024-05-27 22:10:05 +08:00
parent 4b9bac6ac7
commit 0c0adf3a25
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
3 changed files with 66 additions and 3 deletions

View File

@ -35,7 +35,6 @@ offset_bottom = 32.0
text = "level_graph_editor" text = "level_graph_editor"
[node name="CreateOrEditorPanel" type="Panel" parent="."] [node name="CreateOrEditorPanel" type="Panel" parent="."]
visible = false
layout_mode = 1 layout_mode = 1
anchors_preset = 15 anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
@ -152,6 +151,16 @@ offset_right = 61.0
offset_bottom = 379.0 offset_bottom = 379.0
text = "tags" text = "tags"
[node name="TagLineEdit" type="LineEdit" parent="CreateOrEditorPanel"]
layout_mode = 1
anchors_preset = 10
anchor_right = 1.0
offset_left = 16.0
offset_top = 388.0
offset_right = -15.0
offset_bottom = 421.0
grow_horizontal = 2
[node name="HBoxContainer" type="HBoxContainer" parent="."] [node name="HBoxContainer" type="HBoxContainer" parent="."]
layout_mode = 1 layout_mode = 1
anchors_preset = 1 anchors_preset = 1

View File

@ -27,6 +27,12 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate
/// </summary> /// </summary>
private int _roomIndex = 1; private int _roomIndex = 1;
/// <summary>
/// <para>Is there a start node?</para>
/// <para>是否有开始节点了?</para>
/// </summary>
private bool _hasStartNode;
private PackedScene? _roomNodeScene; private PackedScene? _roomNodeScene;
private readonly List<Node> _selectedNodes = new List<Node>(); private readonly List<Node> _selectedNodes = new List<Node>();
@ -235,6 +241,7 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate
} }
var nodes = _selectedNodes.ToArray(); var nodes = _selectedNodes.ToArray();
_roomIndex -= _selectedNodes.Count;
foreach (var node in nodes) foreach (var node in nodes)
{ {
if (node is not RoomNode roomNode) if (node is not RoomNode roomNode)
@ -242,10 +249,18 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate
continue; continue;
} }
if (roomNode.RoomNodeData != null && roomNode.RoomNodeData.HasTag(Config.RoomDataTag.StartingRoom))
{
//The node with the start room label was deleted.
//删除了带有起始房间标签的节点。
_hasStartNode = false;
}
_nodeBinding.GraphEdit.RemoveChild(node); _nodeBinding.GraphEdit.RemoveChild(node);
roomNode.QueueFree(); roomNode.QueueFree();
_selectedNodes.Remove(node); _selectedNodes.Remove(node);
} }
}; };
} }
@ -268,6 +283,23 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate
_nodeBinding.RoomNameLineEdit.Text = string.Format(_defaultRoomName, _roomIndex); _nodeBinding.RoomNameLineEdit.Text = string.Format(_defaultRoomName, _roomIndex);
} }
if (_nodeBinding.RoomDescriptionLineEdit != null)
{
_nodeBinding.RoomDescriptionLineEdit.Text = string.Empty;
}
if (_nodeBinding.TagLineEdit != null)
{
if (_hasStartNode)
{
_nodeBinding.TagLineEdit.Text = string.Empty;
}
else
{
_nodeBinding.TagLineEdit.Text = Config.RoomDataTag.StartingRoom;
}
}
if (_nodeBinding.HBoxContainer != null) if (_nodeBinding.HBoxContainer != null)
{ {
_nodeBinding.HBoxContainer.Visible = false; _nodeBinding.HBoxContainer.Visible = false;
@ -293,7 +325,7 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate
_nodeBinding.CreateRoomButton.Pressed += () => _nodeBinding.CreateRoomButton.Pressed += () =>
{ {
if (_nodeBinding.RoomNameLineEdit == null || _nodeBinding.RoomDescriptionLineEdit == null || if (_nodeBinding.RoomNameLineEdit == null || _nodeBinding.RoomDescriptionLineEdit == null ||
_nodeBinding.RoomTemplateCollectionTextEdit == null) _nodeBinding.RoomTemplateCollectionTextEdit == null || _nodeBinding.TagLineEdit == null)
{ {
return; return;
} }
@ -310,13 +342,27 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate
return; return;
} }
string[]? tagArray = null;
var tagData = _nodeBinding.TagLineEdit.Text;
if (!string.IsNullOrEmpty(tagData))
{
tagArray = tagData.Split(',');
}
var roomNodeData = new RoomNodeData var roomNodeData = new RoomNodeData
{ {
Id = GuidUtils.GetGuid(), Id = GuidUtils.GetGuid(),
Title = _nodeBinding.RoomNameLineEdit.Text, Title = _nodeBinding.RoomNameLineEdit.Text,
Description = _nodeBinding.RoomDescriptionLineEdit.Text, Description = _nodeBinding.RoomDescriptionLineEdit.Text,
RoomTemplateSet = roomTemplateArray RoomTemplateSet = roomTemplateArray,
Tags = tagArray
}; };
if (!_hasStartNode && roomNodeData.HasTag(Config.RoomDataTag.StartingRoom))
{
_hasStartNode = true;
}
var roomNode = CreateRoomNode(roomNodeData); var roomNode = CreateRoomNode(roomNodeData);
if (roomNode != null) if (roomNode != null)
{ {
@ -587,6 +633,7 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate
//不要调用DeleteAllChildAsync方法这会引发“ERROR: Caller thread can't call this function in this node”。 //不要调用DeleteAllChildAsync方法这会引发“ERROR: Caller thread can't call this function in this node”。
NodeUtils.DeleteAllChild(_nodeBinding.GraphEdit); NodeUtils.DeleteAllChild(_nodeBinding.GraphEdit);
_roomIndex = 1; _roomIndex = 1;
_hasStartNode = false;
var roomNodeDataList = levelGraphEditorSaveData.RoomNodeDataList; var roomNodeDataList = levelGraphEditorSaveData.RoomNodeDataList;
if (roomNodeDataList != null) if (roomNodeDataList != null)
{ {
@ -597,6 +644,11 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate
continue; continue;
} }
if (!_hasStartNode && roomNodeData.HasTag(Config.RoomDataTag.StartingRoom))
{
_hasStartNode = true;
}
//Instantiate the room node. //Instantiate the room node.
//实例化房间节点。 //实例化房间节点。
var roomNode = CreateRoomNode(roomNodeData); var roomNode = CreateRoomNode(roomNodeData);

View File

@ -30,6 +30,7 @@ public class LevelGraphEditorBinding : INodeBinding
public LineEdit? FileNameLineEdit; public LineEdit? FileNameLineEdit;
public Button? ShowLoadPanelButton; public Button? ShowLoadPanelButton;
public Button? DeleteSelectedNodeButton; public Button? DeleteSelectedNodeButton;
public LineEdit? TagLineEdit;
public void Binding(Node root) public void Binding(Node root)
{ {
RoomTemplateTipsLabel = root.GetNode<Label>("CreateOrEditorPanel/RoomTemplateTipsLabel"); RoomTemplateTipsLabel = root.GetNode<Label>("CreateOrEditorPanel/RoomTemplateTipsLabel");
@ -52,5 +53,6 @@ public class LevelGraphEditorBinding : INodeBinding
RoomNameLineEdit = root.GetNode<LineEdit>("CreateOrEditorPanel/RoomNameLineEdit"); RoomNameLineEdit = root.GetNode<LineEdit>("CreateOrEditorPanel/RoomNameLineEdit");
RoomDescriptionLineEdit = root.GetNode<LineEdit>("CreateOrEditorPanel/RoomDescriptionLineEdit"); RoomDescriptionLineEdit = root.GetNode<LineEdit>("CreateOrEditorPanel/RoomDescriptionLineEdit");
CreateRoomButton = root.GetNode<Button>("CreateOrEditorPanel/CreateRoomButton"); CreateRoomButton = root.GetNode<Button>("CreateOrEditorPanel/CreateRoomButton");
TagLineEdit = root.GetNode<LineEdit>("CreateOrEditorPanel/TagLineEdit");
} }
} }