剧情+对话完善

This commit is contained in:
SoulliesOfficial
2026-07-21 15:24:42 -04:00
parent 8f230831e9
commit 810d019619
161 changed files with 7271 additions and 1893 deletions

View File

@@ -6,11 +6,9 @@ namespace Ichni.Story.YarnFunctions
public static class GeneralFunctions
{
[YarnCommand("log")]
public static void Log(string message, string logType)
public static void Log(string message, string logType = "info")
{
logType = logType.ToLower();
switch (logType)
switch (logType?.ToLowerInvariant())
{
case "info":
Debug.Log(message);
@@ -27,4 +25,4 @@ namespace Ichni.Story.YarnFunctions
}
}
}
}
}

View File

@@ -23,31 +23,18 @@ namespace Ichni.Story.YarnFunctions
[YarnCommand("unlock_song")]
public static void UnlockSong(string songUnlockKey)
{
if (!TryGrantUnlockKey(songUnlockKey, out bool wasNewlyGranted) || !wasNewlyGranted)
ExecuteAfterDialogueCommit(() =>
{
return;
}
// 将歌曲提示加入对话结束队列。弹窗本地化将由后续 Localization 阶段替换,
// 这里不参与内容是否解锁的授权判断。
if (StoryDialogueController.instance != null)
{
StoryDialogueController.instance.dialogueEndActions.Add(() =>
if (!TryGrantUnlockKey(songUnlockKey, out bool wasNewlyGranted) || !wasNewlyGranted)
{
if (MessageUIPage.instance != null)
{
MessageUIPage.instance.ShowUnlockMessage(songUnlockKey);
}
else
{
Debug.LogError("[StoryTreeCommands] 弹窗失败:场景中未找到 StoryMessageBoxUIPage 实例!");
}
});
}
else
{
Debug.LogError("[StoryTreeCommands] 弹窗队列注册失败:未找到 StoryDialogueController 实例!");
}
return;
}
if (MessageUIPage.instance != null)
MessageUIPage.instance.ShowUnlockMessage(songUnlockKey);
else
Debug.LogError("[StoryTreeCommands] 弹窗失败:场景中未找到 StoryMessageBoxUIPage 实例!");
});
}
/// <summary>
@@ -59,7 +46,9 @@ namespace Ichni.Story.YarnFunctions
[YarnCommand("grant_unlock")]
public static void GrantUnlock(string unlockKey)
{
TryGrantUnlockKey(unlockKey, out _);
// 全局解锁不属于 ChapterStorySaveTimeline 回滚永远不会撤销已提交的 Key
// 但在当前对话尚未正常结束前,也不能因 Back 而提前写入。
ExecuteAfterDialogueCommit(() => TryGrantUnlockKey(unlockKey, out _));
}
/// <summary>
@@ -76,12 +65,34 @@ namespace Ichni.Story.YarnFunctions
string translatedTitle = GetTranslatedText(tableName, titleKey);
string translatedContent = GetTranslatedText(tableName, contentKey);
Debug.Log($"[StoryTreeCommands] 准备在对话结束后显示自定义弹窗:标题='{translatedTitle}',内容='{translatedContent}'");
StoryDialogueController.instance.dialogueEndActions.Add(() =>
ExecuteAfterDialogueCommit(() =>
{
MessageUIPage.instance.ShowCustomMessage(translatedTitle, translatedContent);
if (MessageUIPage.instance != null)
MessageUIPage.instance.ShowCustomMessage(translatedTitle, translatedContent);
else
Debug.LogError("[StoryTreeCommands] 无法显示自定义弹窗:未找到 MessageUIPage 实例。");
});
}
/// <summary>
/// 在 TextBlock 事务活跃时延后执行全局副作用;无活动事务时立即执行。
/// 这样 Yarn 命令可以在对话和未来的非对话入口共用,同时保持 Back/失败时不落盘的事务边界。
/// </summary>
private static void ExecuteAfterDialogueCommit(System.Action action)
{
if (action == null)
return;
StoryDialogueController controller = StoryDialogueController.instance;
if (controller != null)
{
controller.ExecuteAfterDialogueCommit(action.Invoke);
return;
}
action.Invoke();
}
/// <summary>
/// 所有 Yarn 解锁命令共用的授予入口。它负责模块存在性检查、重复授予的幂等处理及立即 ES3 保存。
/// </summary>

View File

@@ -1,76 +1,51 @@
using UnityEngine;
using Yarn.Unity;
using Ichni.Story;
using Yarn.Unity;
namespace Ichni.Story.YarnFunctions
{
/// <summary>
/// 提供可以直接在 Yarn 脚本中调用的全局变量读写指令
/// 完全兼容旧系统中的自定义函数(避免旧的 .yarn 报错),
/// 底层统一指向全新的 StoryVariables 枢纽。
/// ichni Official 的永久剧情变量 Yarn 接口
/// <para>所有变量都属于当前 StoryData 对应的章节存档。请不要在新台本中使用 Yarn 原生的
/// <c>&lt;&lt;declare&gt;&gt;</c>、<c>&lt;&lt;set&gt;&gt;</c> 或 <c>$variable</c>,它们会创建不受本章节回滚系统管理的临时变量。</para>
/// <para>推荐语法:<c>&lt;&lt;set_bool "c0_intro_read" true&gt;&gt;</c>、
/// <c>&lt;&lt;if get_int("c0_route") == 1&gt;&gt;</c>。</para>
/// </summary>
public static class VariableCommands
{
[YarnCommand("set_bool")]
public static void SetBool(string key, bool value)
{
StoryVariables.SetBool(key, value);
}
public static void SetBool(string key, bool value) => StoryProgress.SetBoolAndRefresh(key, value);
[YarnFunction("get_bool")]
public static bool GetBool(string key)
{
return StoryVariables.GetBool(key);
}
[YarnCommand("set_int")]
public static void SetInt(string key, int value)
{
StoryVariables.SetInt(key, value);
}
public static bool GetBool(string key) => StoryVariables.GetBool(key);
[YarnCommand("set_int")]
public static void SetInt(string key, int value) => StoryProgress.SetIntAndRefresh(key, value);
[YarnCommand("add_int")]
public static void AddInt(string key, int delta) => StoryProgress.AddIntAndRefresh(key, delta);
[YarnCommand("modify_int")]
public static void ModifyInt(string key, int modification)
{
int currentValue = StoryVariables.GetInt(key);
StoryVariables.SetInt(key, currentValue + modification);
}
[YarnFunction("get_int")]
public static int GetInt(string key)
{
return StoryVariables.GetInt(key);
}
public static int GetInt(string key) => StoryVariables.GetInt(key);
[YarnCommand("set_float")]
public static void SetFloat(string key, float value)
{
StoryVariables.SetFloat(key, value);
}
public static void SetFloat(string key, float value) => StoryProgress.SetFloatAndRefresh(key, value);
[YarnCommand("modify_float")]
public static void ModifyFloat(string key, float modification)
{
float currentValue = StoryVariables.GetFloat(key);
StoryVariables.SetFloat(key, currentValue + modification);
}
[YarnCommand("add_float")]
public static void AddFloat(string key, float delta) => StoryProgress.AddFloatAndRefresh(key, delta);
[YarnFunction("get_float")]
public static float GetFloat(string key)
{
return StoryVariables.GetFloat(key);
}
public static float GetFloat(string key) => StoryVariables.GetFloat(key);
[YarnCommand("set_string")]
public static void SetString(string key, string value)
{
StoryVariables.SetString(key, value);
}
public static void SetString(string key, string value) => StoryProgress.SetStringAndRefresh(key, value);
[YarnFunction("get_string")]
public static string GetString(string key)
{
return StoryVariables.GetString(key);
}
public static string GetString(string key) => StoryVariables.GetString(key);
[YarnCommand("remove_variable")]
public static void RemoveVariable(string key) => StoryProgress.RemoveVariableAndRefresh(key);
[YarnFunction("has_variable")]
public static bool HasVariable(string key) => StoryVariables.HasVariable(key);
}
}