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"
[node name="CreateOrEditorPanel" type="Panel" parent="."]
visible = false
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
@ -152,6 +151,16 @@ offset_right = 61.0
offset_bottom = 379.0
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="."]
layout_mode = 1
anchors_preset = 1

View File

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

View File

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