存档重构,游戏内容解锁机制;教程完善(未完成)

This commit is contained in:
SoulliesOfficial
2026-07-18 16:51:18 -04:00
parent d48ef1e65e
commit dda354ebb9
123 changed files with 4032 additions and 558 deletions

View File

@@ -14,39 +14,29 @@ namespace Ichni.Story.YarnFunctions
// ── Yarn Commands ────────────────────────────────────────────────────────
/// <summary>
/// 解锁一首新歌曲,并在当前这段对话结束(对话 UI 淡出)后,弹出 MessageBox 提示。
/// 格式: &lt;&lt;unlock_song songUnlockKey&gt;&gt;
/// 兼容既有 Yarn 脚本:授予歌曲相关的解锁 Key,并在当前对话结束后弹出提示。
/// 格式: &lt;&lt;unlock_song unlock_key&gt;&gt;
/// <para>Key 必须使用小写字母、数字和下划线,例如 <c>story_ch0_prologue_completed</c>。</para>
/// 新内容若不需要歌曲提示,优先使用 <see cref="GrantUnlock"/>。
/// </summary>
/// <param name="songUnlockKey">要解锁的歌曲密钥/ID</param>
/// <param name="songUnlockKey">要授予的稳定解锁 Key而不是歌曲显示名称。</param>
[YarnCommand("unlock_song")]
public static void UnlockSong(string songUnlockKey)
{
if (GameSaveManager.instance == null || GameSaveManager.instance.SongSaveModule == null)
if (!TryGrantUnlockKey(songUnlockKey, out bool wasNewlyGranted) || !wasNewlyGranted)
{
Debug.LogError("[StoryTreeCommands] 无法解锁歌曲GameSaveManager 或其 SongSaveModule 未初始化!");
return;
}
// 1. 检查是否已经解锁
if (GameSaveManager.instance.SongSaveModule.CheckStoryKey(songUnlockKey))
{
Debug.Log($"[StoryTreeCommands] 歌曲 {songUnlockKey} 已处于解锁状态。");
return;
}
// 2. 写入解锁状态并保存存档
GameSaveManager.instance.SongSaveModule.storyUnlockKeys.Add(songUnlockKey);
GameSaveManager.instance.SongSaveModule.SaveStoryUnlockKeys();
Debug.Log($"[StoryTreeCommands] 已成功写入并保存歌曲解锁密钥:{songUnlockKey}");
// 3. 将 UI 弹窗提示加入到对话结束队列中
// 将歌曲提示加入对话结束队列。弹窗本地化将由后续 Localization 阶段替换,
// 这里不参与内容是否解锁的授权判断。
if (StoryDialogueController.instance != null)
{
StoryDialogueController.instance.dialogueEndActions.Add(() =>
{
if (StoryMessageBoxUIPage.instance != null)
if (MessageUIPage.instance != null)
{
StoryMessageBoxUIPage.instance.ShowUnlockMessage(songUnlockKey);
MessageUIPage.instance.ShowUnlockMessage(songUnlockKey);
}
else
{
@@ -60,6 +50,18 @@ namespace Ichni.Story.YarnFunctions
}
}
/// <summary>
/// 通用内容解锁命令,可用于章节、歌曲、教程及未来内容。
/// 格式: &lt;&lt;grant_unlock unlock_key&gt;&gt;。
/// 本命令只授予并保存 Key不绑定任何 UI 提示;需要提示时应由 Yarn 额外调用 <c>show_message</c>。
/// </summary>
/// <param name="unlockKey">符合 <see cref="UnlockSaveModule.KeyNamingRule"/> 的稳定解锁 Key。</param>
[YarnCommand("grant_unlock")]
public static void GrantUnlock(string unlockKey)
{
TryGrantUnlockKey(unlockKey, out _);
}
/// <summary>
/// 在对话结束后,弹出一个自定义 MessageBox 提示。
/// 会尝试使用 Unity Localization 进行翻译如果找不到对应条目则回退显示原文本Key
@@ -76,10 +78,39 @@ namespace Ichni.Story.YarnFunctions
Debug.Log($"[StoryTreeCommands] 准备在对话结束后显示自定义弹窗:标题='{translatedTitle}',内容='{translatedContent}'");
StoryDialogueController.instance.dialogueEndActions.Add(() =>
{
StoryMessageBoxUIPage.instance.ShowCustomMessage(translatedTitle, translatedContent);
MessageUIPage.instance.ShowCustomMessage(translatedTitle, translatedContent);
});
}
/// <summary>
/// 所有 Yarn 解锁命令共用的授予入口。它负责模块存在性检查、重复授予的幂等处理及立即 ES3 保存。
/// </summary>
/// <returns>模块已正常处理该 Key 时返回 trueKey 非法或模块尚未初始化时返回 false。</returns>
private static bool TryGrantUnlockKey(string unlockKey, out bool wasNewlyGranted)
{
wasNewlyGranted = false;
UnlockSaveModule unlockSaveModule = GameSaveManager.instance?.UnlockSaveModule;
if (unlockSaveModule == null)
{
Debug.LogError("[StoryTreeCommands] 无法授予解锁 KeyUnlockSaveModule 尚未初始化!");
return false;
}
if (unlockSaveModule.HasKey(unlockKey))
{
Debug.Log($"[StoryTreeCommands] 解锁 Key 已存在:{unlockKey}");
return true;
}
wasNewlyGranted = unlockSaveModule.GrantKey(unlockKey);
if (wasNewlyGranted)
{
Debug.Log($"[StoryTreeCommands] 已成功写入并保存解锁 Key{unlockKey}");
}
return wasNewlyGranted;
}
// ── 内部辅助 ─────────────────────────────────────────────────────────────
private static string GetTranslatedText(string tableName, string key)