From d80bf0cbfbfcd3f6c7224bb0e5122f8371f91c88 Mon Sep 17 00:00:00 2001 From: lightyears Date: Sat, 3 Jun 2023 14:56:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E9=A6=96=E9=A1=B5=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Models/Changelog.cs | 30 ++++++++++++------- Scenes/MainScene/ChangelogContainer.cs | 40 ++++++++++++++++++++++++++ Scenes/{ => MainScene}/MainScene.cs | 0 Scenes/{ => MainScene}/MainScene.tscn | 26 +++++++++-------- project.godot | 2 +- 5 files changed, 74 insertions(+), 24 deletions(-) create mode 100644 Scenes/MainScene/ChangelogContainer.cs rename Scenes/{ => MainScene}/MainScene.cs (100%) rename Scenes/{ => MainScene}/MainScene.tscn (72%) diff --git a/Models/Changelog.cs b/Models/Changelog.cs index 86b1cf6..965cf57 100644 --- a/Models/Changelog.cs +++ b/Models/Changelog.cs @@ -4,13 +4,13 @@ namespace CMSGame.Models { internal record class Changelog { - public DateOnly Date { set; get; } + public DateOnly? Date { set; get; } public string Title { set; get; } public string Description { set; get; } - public Changelog(DateOnly date, string title, string description) + public Changelog(DateOnly? date, string title, string description) { Date = date; Title = title; @@ -41,6 +41,18 @@ namespace CMSGame.Models Changelog? changelog = null; StringBuilder contentBuilder = new StringBuilder(); + + var commitChangelog = () => + { + if (changelog != null) + { + changelog.Description = contentBuilder.ToString(); + contentBuilder.Clear(); + this.Add(changelog); + changelog = null; + } + }; + foreach (var line in fileContent.Split("\n")) { if (line.Trim() == "") @@ -58,7 +70,7 @@ namespace CMSGame.Models if (line.StartsWith("## ")) // 二号标题,格式为 [未发布] 或 [1.0.0] - 2023-06-03 { string title = line.TrimStart(new char[] { '#', ' ' }); - string[] parts = title.Split('-').Select(str => str.Trim()).ToArray(); + string[] parts = title.Split('-', 2).Select(str => str.Trim()).ToArray(); string versionString = parts[0]; string dateString = ""; @@ -67,14 +79,8 @@ namespace CMSGame.Models dateString = parts[1]; } - if (changelog != null) - { - changelog.Description = contentBuilder.ToString(); - contentBuilder.Clear(); - this.Add(changelog); - } - - changelog = new Changelog(DateOnly.Parse(dateString), versionString, ""); + commitChangelog(); + changelog = new Changelog(dateString != string.Empty ? DateOnly.Parse(dateString) : null, versionString, ""); continue; } @@ -82,6 +88,8 @@ namespace CMSGame.Models contentBuilder.AppendLine(line.Trim()); } + + commitChangelog(); } } } diff --git a/Scenes/MainScene/ChangelogContainer.cs b/Scenes/MainScene/ChangelogContainer.cs new file mode 100644 index 0000000..b360ad2 --- /dev/null +++ b/Scenes/MainScene/ChangelogContainer.cs @@ -0,0 +1,40 @@ +using CMSGame.Models; +using System.Text; + +namespace CMSGame +{ + public partial class ChangelogContainer : VBoxContainer + { + private readonly ChangelogList _changelogList = new(); + + public RichTextLabel? ChangelogLabel; + + public override void _Ready() + { + this.GetUniqueNode(ref ChangelogLabel, nameof(ChangelogLabel)); + + SetLabelText(); + } + + public void SetLabelText() + { + var changelogText = _changelogList.Select(log => + { + StringBuilder textBuilder = new StringBuilder(); + textBuilder.Append($"[b]{log.Title}[/b]"); + + if (log.Date != null) + { + textBuilder.Append($" [i]{log.Date}[/i]"); + } + + textBuilder.Append('\n'); + textBuilder.Append(log.Description); + + return textBuilder.ToString(); + }).ToArray().Join("\n"); + + ChangelogLabel!.Text = changelogText; + } + } +} diff --git a/Scenes/MainScene.cs b/Scenes/MainScene/MainScene.cs similarity index 100% rename from Scenes/MainScene.cs rename to Scenes/MainScene/MainScene.cs diff --git a/Scenes/MainScene.tscn b/Scenes/MainScene/MainScene.tscn similarity index 72% rename from Scenes/MainScene.tscn rename to Scenes/MainScene/MainScene.tscn index eebe404..b838a53 100644 --- a/Scenes/MainScene.tscn +++ b/Scenes/MainScene/MainScene.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=4 format=3 uid="uid://c3ovsoq6o7y3t"] +[gd_scene load_steps=5 format=3 uid="uid://c3ovsoq6o7y3t"] -[ext_resource type="Script" path="res://Scenes/MainScene.cs" id="1_kso8c"] -[ext_resource type="Theme" uid="uid://cn55cr5w4yy3n" path="res://Themes/UI.tres" id="1_y72s3"] -[ext_resource type="PackedScene" uid="uid://cslqihnfw0me2" path="res://Components/Settings/SettingsMenuPopup.tscn" id="3_1d7q7"] +[ext_resource type="Script" path="res://Scenes/MainScene/MainScene.cs" id="1_115p1"] +[ext_resource type="Theme" uid="uid://cn55cr5w4yy3n" path="res://Themes/UI.tres" id="2_05oip"] +[ext_resource type="PackedScene" uid="uid://cslqihnfw0me2" path="res://Components/Settings/SettingsMenuPopup.tscn" id="3_c8lv8"] +[ext_resource type="Script" path="res://Scenes/MainScene/ChangelogContainer.cs" id="4_ccxmt"] [node name="MainScene" type="Control"] layout_mode = 3 @@ -11,7 +12,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -script = ExtResource("1_kso8c") +script = ExtResource("1_115p1") [node name="BackgroundImage" type="Label" parent="."] layout_mode = 1 @@ -34,7 +35,7 @@ offset_top = -65.5 offset_right = 287.0 offset_bottom = 65.5 grow_vertical = 2 -theme = ExtResource("1_y72s3") +theme = ExtResource("2_05oip") theme_override_constants/separation = 16 [node name="StartButton" type="Button" parent="StartMenu"] @@ -49,13 +50,13 @@ text = "设置" layout_mode = 2 text = "退出" -[node name="SettingsMenuPopup" parent="." instance=ExtResource("3_1d7q7")] +[node name="SettingsMenuPopup" parent="." instance=ExtResource("3_c8lv8")] unique_name_in_owner = true title = "游戏设置" visible = false borderless = false -[node name="VBoxContainer" type="VBoxContainer" parent="."] +[node name="ChangelogContainer" type="VBoxContainer" parent="."] layout_mode = 1 anchors_preset = 6 anchor_left = 1.0 @@ -68,18 +69,19 @@ offset_right = -60.0 offset_bottom = 374.0 grow_horizontal = 0 grow_vertical = 2 +script = ExtResource("4_ccxmt") -[node name="Label" type="Label" parent="VBoxContainer"] +[node name="Label" type="Label" parent="ChangelogContainer"] layout_mode = 2 -theme = ExtResource("1_y72s3") +theme = ExtResource("2_05oip") text = "更新日志" horizontal_alignment = 1 -[node name="ScrollContainer" type="ScrollContainer" parent="VBoxContainer"] +[node name="ScrollContainer" type="ScrollContainer" parent="ChangelogContainer"] layout_mode = 2 size_flags_vertical = 3 -[node name="ChanglogLabel" type="RichTextLabel" parent="VBoxContainer/ScrollContainer"] +[node name="ChangelogLabel" type="RichTextLabel" parent="ChangelogContainer/ScrollContainer"] unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 3 diff --git a/project.godot b/project.godot index 25c2758..ff25d57 100644 --- a/project.godot +++ b/project.godot @@ -16,7 +16,7 @@ config/name_localized={ "zh_Hans": "山与海的国", "zh_Hant": "山與海的囯" } -run/main_scene="res://Scenes/MainScene.tscn" +run/main_scene="res://Scenes/MainScene/MainScene.tscn" config/features=PackedStringArray("4.0", "C#", "Forward Plus") config/icon="res://icon.svg"