在首页展示更新日志

master
lightyears 2 years ago
parent 57a139cf95
commit d80bf0cbfb
Signed by: lightyears
GPG Key ID: 98D80DDF26D4F2F9

@ -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();
}
}
}

@ -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;
}
}
}

@ -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

@ -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"

Loading…
Cancel
Save