Support for connecting nodes. Adding taglines does not require changing random ranges in the code.

支持连接节点了。添加标语无需到代码内修改随机范围了。
This commit is contained in:
Cold-Mint 2024-05-12 23:06:07 +08:00
parent 2a28702fc6
commit 968fa7d723
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
14 changed files with 211 additions and 65 deletions

View File

@ -17,4 +17,5 @@ create_room,创建房间,Create room,部屋を作ります
close,关闭,Close,閉じます close,关闭,Close,閉じます
name,名称,Name,めいしょう name,名称,Name,めいしょう
describe,描述,Describe,ないよう describe,描述,Describe,ないよう
creation,创建,Creation,創建 creation,创建,Creation,創建
default_room_name,房间{0},Room{0},部屋{0}です
1 id zh en jp
17 close 关闭 Close 閉じます
18 name 名称 Name めいしょう
19 describe 描述 Describe ないよう
20 creation 创建 Creation 創建
21 default_room_name 房间{0} Room{0} 部屋{0}です

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2,5 +2,5 @@ id,zh,en,jp
slogan_1,游戏属于每一个人。,The game belongs to everyone.,ゲームはすべての人のものです。 slogan_1,游戏属于每一个人。,The game belongs to everyone.,ゲームはすべての人のものです。
slogan_2,如果你想要得到爱,你就播种爱。,"If you want love, you sow love.",愛を手に入れたければ、愛の種をまきます。 slogan_2,如果你想要得到爱,你就播种爱。,"If you want love, you sow love.",愛を手に入れたければ、愛の種をまきます。
slogan_3,快乐?伤心?痛苦?,Happy? Sad? Pain?,楽しいですか?悲しいですか?苦しいですか? slogan_3,快乐?伤心?痛苦?,Happy? Sad? Pain?,楽しいですか?悲しいですか?苦しいですか?
slogan_4,0001 0011 0001 0101 0100 1111 0100,0001 0011 0001 0101 0100 1111 0100,0001 0011 0001 0101 0100 1111 0100 slogan_4,kaWaYi!,kaWaYi!,kaWaYi!
slogan_5,kaWaYi!,kaWaYi!,kaWaYi! slogan_5,魔法是想象的世界。,Magic is an imaginary world.,魔法は想像の世界です。
1 id zh en jp
2 slogan_1 游戏属于每一个人。 The game belongs to everyone. ゲームはすべての人のものです。
3 slogan_2 如果你想要得到爱,你就播种爱。 If you want love, you sow love. 愛を手に入れたければ、愛の種をまきます。
4 slogan_3 快乐?伤心?痛苦? Happy? Sad? Pain? 楽しいですか?悲しいですか?苦しいですか?
5 slogan_4 0001 0011 0001 0101 0100 1111 0100 kaWaYi! 0001 0011 0001 0101 0100 1111 0100 kaWaYi! 0001 0011 0001 0101 0100 1111 0100 kaWaYi!
6 slogan_5 kaWaYi! 魔法是想象的世界。 kaWaYi! Magic is an imaginary world. kaWaYi! 魔法は想像の世界です。

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -3,6 +3,19 @@
[ext_resource type="Script" path="res://scripts/levelGraphEditor/RoomNode.cs" id="1_jiu7r"] [ext_resource type="Script" path="res://scripts/levelGraphEditor/RoomNode.cs" id="1_jiu7r"]
[node name="RoomNode" type="GraphNode"] [node name="RoomNode" type="GraphNode"]
offset_right = 571.0 offset_right = 363.0
offset_bottom = 253.0 offset_bottom = 218.0
slot/0/left_enabled = true
slot/0/left_type = 0
slot/0/left_color = Color(1, 1, 1, 1)
slot/0/left_icon = null
slot/0/right_enabled = true
slot/0/right_type = 0
slot/0/right_color = Color(1, 1, 1, 1)
slot/0/right_icon = null
slot/0/draw_stylebox = true
script = ExtResource("1_jiu7r") script = ExtResource("1_jiu7r")
[node name="DescribeLabel" type="Label" parent="."]
layout_mode = 2
text = "describe"

View File

@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://ckl23uwxrjat4"] [gd_scene load_steps=2 format=3 uid="uid://ckl23uwxrjat4"]
[ext_resource type="Script" path="res://scripts/loader/uiLoader/LevelGraphEditorLoader.cs" id="1_7nyq6"] [ext_resource type="Script" path="res://scripts/loader/uiLoader/LevelGraphEditorLoader.cs" id="1_g1axq"]
[node name="LevelGraphEditor" type="Control"] [node name="LevelGraphEditor" type="Control"]
layout_mode = 3 layout_mode = 3
@ -9,15 +9,17 @@ anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
script = ExtResource("1_7nyq6") script = ExtResource("1_g1axq")
[node name="GraphEdit" type="GraphEdit" parent="."] [node name="GraphEdit" type="GraphEdit" parent="."]
visible = false
layout_mode = 1 layout_mode = 1
anchors_preset = 15 anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
offset_top = 39.0 offset_left = 12.0
offset_top = 52.0
offset_right = -16.0
offset_bottom = -13.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
show_grid = false show_grid = false
@ -33,79 +35,104 @@ 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
anchor_bottom = 1.0 anchor_bottom = 1.0
offset_left = 45.0 offset_left = 15.0
offset_top = 42.0 offset_top = 44.0
offset_right = -39.0 offset_right = -16.0
offset_bottom = -45.0 offset_bottom = -15.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
[node name="Label" type="Label" parent="CreateOrEditorPanel"] [node name="Label" type="Label" parent="CreateOrEditorPanel"]
layout_mode = 0 layout_mode = 1
offset_left = 15.0 offset_left = 10.0
offset_top = 11.0 offset_top = 13.0
offset_right = 102.0 offset_right = 97.0
offset_bottom = 36.0 offset_bottom = 38.0
text = "create_room" text = "create_room"
[node name="Label3" type="Label" parent="CreateOrEditorPanel"] [node name="Label3" type="Label" parent="CreateOrEditorPanel"]
layout_mode = 0 layout_mode = 1
offset_left = 7.0 offset_left = 12.0
offset_top = 109.0 offset_top = 106.0
offset_right = 94.0 offset_right = 72.0
offset_bottom = 134.0 offset_bottom = 131.0
text = "describe" text = "describe"
[node name="RoomNameLineEdit" type="LineEdit" parent="CreateOrEditorPanel"] [node name="RoomNameLineEdit" type="LineEdit" parent="CreateOrEditorPanel"]
layout_mode = 0 layout_mode = 1
offset_left = 75.0 anchors_preset = 10
offset_top = 54.0 anchor_right = 1.0
offset_right = 1053.0 offset_left = 100.0
offset_bottom = 87.0 offset_top = 59.0
offset_right = -8.0
offset_bottom = 92.0
grow_horizontal = 2
[node name="RoomDescriptionLineEdit" type="LineEdit" parent="CreateOrEditorPanel"] [node name="RoomDescriptionLineEdit" type="LineEdit" parent="CreateOrEditorPanel"]
layout_mode = 0 layout_mode = 1
offset_left = 82.0 anchors_preset = 10
offset_top = 108.0 anchor_right = 1.0
offset_right = 1060.0 offset_left = 100.0
offset_bottom = 141.0 offset_top = 104.0
offset_right = -8.0
offset_bottom = 137.0
grow_horizontal = 2
[node name="HideCreateRoomPanelButton" type="Button" parent="CreateOrEditorPanel"] [node name="HideCreateRoomPanelButton" type="Button" parent="CreateOrEditorPanel"]
layout_mode = 1 layout_mode = 1
anchors_preset = 1 anchors_preset = 1
anchor_left = 1.0 anchor_left = 1.0
anchor_right = 1.0 anchor_right = 1.0
offset_left = -46.0 offset_left = -57.0
offset_bottom = 33.0 offset_top = 6.0
offset_right = -11.0
offset_bottom = 39.0
grow_horizontal = 0 grow_horizontal = 0
text = "close" text = "close"
[node name="Label2" type="Label" parent="CreateOrEditorPanel"] [node name="Label2" type="Label" parent="CreateOrEditorPanel"]
layout_mode = 0 layout_mode = 1
offset_left = 22.0 offset_left = 13.0
offset_top = 56.0 offset_top = 60.0
offset_right = 62.0 offset_right = 48.0
offset_bottom = 81.0 offset_bottom = 85.0
text = "name" text = "name"
[node name="CreateRoomButton" type="Button" parent="CreateOrEditorPanel"] [node name="CreateRoomButton" type="Button" parent="CreateOrEditorPanel"]
layout_mode = 0 layout_mode = 1
offset_left = 972.0 anchors_preset = 3
offset_top = 507.0 anchor_left = 1.0
offset_right = 1039.0 anchor_top = 1.0
offset_bottom = 540.0 anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -80.0
offset_top = -46.0
offset_right = -13.0
offset_bottom = -13.0
grow_horizontal = 0
grow_vertical = 0
text = "creation" text = "creation"
[node name="ShowCreateRoomPanelButton" type="Button" parent="."] [node name="HBoxContainer" type="HBoxContainer" parent="."]
layout_mode = 1 layout_mode = 1
anchors_preset = 1 anchors_preset = 1
anchor_left = 1.0 anchor_left = 1.0
anchor_right = 1.0 anchor_right = 1.0
offset_left = -95.0 offset_left = -160.0
offset_bottom = 33.0 offset_top = 4.0
offset_right = -15.0
offset_bottom = 47.0
grow_horizontal = 0 grow_horizontal = 0
[node name="ShowCreateRoomPanelButton" type="Button" parent="HBoxContainer"]
layout_mode = 2
text = "create_room" text = "create_room"
[node name="ReturnButton" type="Button" parent="HBoxContainer"]
layout_mode = 2
text = "close"

View File

@ -1,4 +1,7 @@
using Godot; using System.Collections.Generic;
using System.IO;
using Godot;
using FileAccess = Godot.FileAccess;
namespace ColdMint.scripts; namespace ColdMint.scripts;
@ -8,19 +11,55 @@ namespace ColdMint.scripts;
/// </summary> /// </summary>
public static class SloganProvider public static class SloganProvider
{ {
private static string _csvPath = "res://locals/slogan.csv";
private static string[]? _sloganKeys;
/// <summary> /// <summary>
/// <para>Define how many banners you want to display</para> /// <para>Loading CSV file</para>
/// <para>定义共有多少条标语需要展示</para> /// <para>加载CSV文件</para>
/// </summary> /// </summary>
private const int Total = 5; public static void LoadSloganCsv()
{
var exists = FileAccess.FileExists(_csvPath);
if (!exists)
{
return;
}
using var file = FileAccess.Open(_csvPath, FileAccess.ModeFlags.Read);
var content = file.GetAsText();
var lineStrings = content.Split('\n');
var keys = new List<string>();
foreach (var lineString in lineStrings)
{
var index = lineString.IndexOf(',');
if (index > -1)
{
keys.Add(lineString[..index]);
}
}
if (keys.Count > 0)
{
keys.RemoveAt(0);
}
_sloganKeys = keys.ToArray();
}
/// <summary> /// <summary>
/// <para>Swipe the machine to get a slogan</para> /// <para>Swipe the machine to get a slogan</para>
/// <para>刷机获取一个标语</para> /// <para>刷机获取一个标语</para>
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static string GetSlogan() public static string? GetSlogan()
{ {
return TranslationServer.Translate("slogan_" + GD.RandRange(1, Total)); if (_sloganKeys == null || _sloganKeys.Length == 0)
{
return null;
}
return TranslationServer.Translate(_sloganKeys[GD.Randi() % _sloganKeys.Length]);
} }
} }

View File

@ -4,5 +4,34 @@ namespace ColdMint.scripts.levelGraphEditor;
public partial class RoomNode : GraphNode public partial class RoomNode : GraphNode
{ {
private Label? _describeLabel;
private IRoomNodeData? _roomNodeData;
public IRoomNodeData? RoomNodeData
{
get => _roomNodeData;
set
{
if (_describeLabel == null || value == null) return;
Title = value.Title;
if (value.Description.Length == 0)
{
_describeLabel.Visible = false;
}
else
{
_describeLabel.Visible = true;
_describeLabel.Text = value.Description;
}
_roomNodeData = value;
}
}
public override void _Ready()
{
base._Ready();
_describeLabel = GetNode<Label>("DescribeLabel");
}
} }

View File

@ -23,11 +23,15 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate
private LineEdit? _roomNameLineEdit; private LineEdit? _roomNameLineEdit;
private LineEdit? _roomDescriptionLineEdit; private LineEdit? _roomDescriptionLineEdit;
private Button? _createRoomButton; private Button? _createRoomButton;
private Button? _returnButton;
private string? _defaultRoomName;
private int _roomIndex = 1;
public override void InitializeData() public override void InitializeData()
{ {
base.InitializeData(); base.InitializeData();
_roomNodeScene = (PackedScene)GD.Load("res://prefab/ui/RoomNode.tscn"); _roomNodeScene = (PackedScene)GD.Load("res://prefab/ui/RoomNode.tscn");
_defaultRoomName = TranslationServer.Translate("default_room_name");
} }
@ -35,7 +39,8 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate
{ {
base.InitializeUi(); base.InitializeUi();
_graphEdit = GetNode<GraphEdit>("GraphEdit"); _graphEdit = GetNode<GraphEdit>("GraphEdit");
_showCreateRoomPanelButton = GetNode<Button>("ShowCreateRoomPanelButton"); _showCreateRoomPanelButton = GetNode<Button>("HBoxContainer/ShowCreateRoomPanelButton");
_returnButton = GetNode<Button>("HBoxContainer/ReturnButton");
_createOrEditorPanel = GetNode<Panel>("CreateOrEditorPanel"); _createOrEditorPanel = GetNode<Panel>("CreateOrEditorPanel");
_hideCreateRoomPanelButton = GetNode<Button>("CreateOrEditorPanel/HideCreateRoomPanelButton"); _hideCreateRoomPanelButton = GetNode<Button>("CreateOrEditorPanel/HideCreateRoomPanelButton");
_roomNameLineEdit = GetNode<LineEdit>("CreateOrEditorPanel/RoomNameLineEdit"); _roomNameLineEdit = GetNode<LineEdit>("CreateOrEditorPanel/RoomNameLineEdit");
@ -68,13 +73,26 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate
return false; return false;
} }
roomNode.Title = roomNodeData.Title; roomNode.RoomNodeData = roomNodeData;
_roomIndex++;
return true; return true;
} }
public override void LoadUiActions() public override void LoadUiActions()
{ {
base.LoadUiActions(); base.LoadUiActions();
if (_graphEdit != null)
{
_graphEdit.ConnectionRequest += (fromNode, fromPort, toNode, toPort) =>
{
_graphEdit.ConnectNode(fromNode, (int)fromPort, toNode, (int)toPort);
};
_graphEdit.DisconnectionRequest += (fromNode, fromPort, toNode, toPort) =>
{
_graphEdit.DisconnectNode(fromNode, (int)fromPort, toNode, (int)toPort);
};
}
if (_showCreateRoomPanelButton != null) if (_showCreateRoomPanelButton != null)
{ {
_showCreateRoomPanelButton.Pressed += () => _showCreateRoomPanelButton.Pressed += () =>
@ -89,10 +107,28 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate
_createOrEditorPanel.Visible = true; _createOrEditorPanel.Visible = true;
} }
if (_roomNameLineEdit != null && _defaultRoomName != null)
{
_roomNameLineEdit.Text = string.Format(_defaultRoomName, _roomIndex);
}
if (_returnButton != null)
{
_returnButton.Visible = false;
}
_showCreateRoomPanelButton.Visible = false; _showCreateRoomPanelButton.Visible = false;
}; };
} }
if (_returnButton != null)
{
_returnButton.Pressed += () =>
{
GetTree().ChangeSceneToPacked((PackedScene)GD.Load("res://scenes/mainMenu.tscn"));
};
}
if (_hideCreateRoomPanelButton != null) if (_hideCreateRoomPanelButton != null)
{ {
_hideCreateRoomPanelButton.Pressed += HideCreateRoomPanel; _hideCreateRoomPanelButton.Pressed += HideCreateRoomPanel;
@ -138,6 +174,11 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate
_createOrEditorPanel.Visible = false; _createOrEditorPanel.Visible = false;
} }
if (_returnButton != null)
{
_returnButton.Visible = true;
}
if (_showCreateRoomPanelButton != null) if (_showCreateRoomPanelButton != null)
{ {
_showCreateRoomPanelButton.Visible = true; _showCreateRoomPanelButton.Visible = true;

View File

@ -23,6 +23,9 @@ public partial class MainMenuLoader : UiLoaderTemplate
public override void InitializeData() public override void InitializeData()
{ {
//Load the slogan
//加载标语
SloganProvider.LoadSloganCsv();
//Register the corresponding encoding provider to solve the problem of garbled Chinese path of the compressed package //Register the corresponding encoding provider to solve the problem of garbled Chinese path of the compressed package
//注册对应的编码提供程序,解决压缩包中文路径乱码问题 //注册对应的编码提供程序,解决压缩包中文路径乱码问题
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
@ -32,13 +35,6 @@ public partial class MainMenuLoader : UiLoaderTemplate
{ {
Directory.CreateDirectory(dataPath); Directory.CreateDirectory(dataPath);
} }
//Registered article
//注册物品
// var staffOfTheUndead = new CommonItem();
// staffOfTheUndead.Name = "item_staff_of_the_undead";
// staffOfTheUndead.Id = "staff_of_the_undead";
// staffOfTheUndead.Description = "";
//Registered camp //Registered camp
//注册阵营 //注册阵营
var defaultCamp = new Camp(Config.CampId.Default) var defaultCamp = new Camp(Config.CampId.Default)
@ -95,12 +91,12 @@ public partial class MainMenuLoader : UiLoaderTemplate
}; };
} }
if (_levelGraphEditorButton!=null) if (_levelGraphEditorButton != null)
{ {
_levelGraphEditorButton.Pressed += () => _levelGraphEditorButton.Pressed += () =>
{ {
LogCat.Log("level_graph_editor"); LogCat.Log("level_graph_editor");
GetTree().ChangeSceneToPacked((PackedScene)GD.Load("res://scenes/LevelGraphEditor.tscn")); GetTree().ChangeSceneToPacked((PackedScene)GD.Load("res://scenes/levelGraphEditor.tscn"));
}; };
} }
} }