fix(dialog): 重构对话推进模式为响应式状态绑定
This commit is contained in:
@@ -33,6 +33,7 @@ namespace AibisDream
|
||||
SingleCastEventSystem.Global.Register<DialogEventEnum, string>(DialogEventEnum.StartNode, StartDialogNode);
|
||||
|
||||
EnumEventSystem.Global.Register(GameLoopEnum.GameStart, ResetAdvanceMode);
|
||||
EnumEventSystem.Global.Register(GameLoopEnum.GameQuit, ResetAdvanceMode);
|
||||
|
||||
EnumEventSystem.Global.Register(DialogEventEnum.OptionShow, OnOptionShow);
|
||||
EnumEventSystem.Global.Register<DialogEventEnum, LineInfo>(DialogEventEnum.OptionSelected, OnOptionSelected);
|
||||
@@ -43,6 +44,7 @@ namespace AibisDream
|
||||
SingleCastEventSystem.Global.Unregister(DialogEventEnum.StartNode);
|
||||
|
||||
EnumEventSystem.Global.UnRegister(GameLoopEnum.GameStart, ResetAdvanceMode);
|
||||
EnumEventSystem.Global.UnRegister(GameLoopEnum.GameQuit, ResetAdvanceMode);
|
||||
|
||||
EnumEventSystem.Global.UnRegister(DialogEventEnum.OptionShow, OnOptionShow);
|
||||
EnumEventSystem.Global.UnRegister<DialogEventEnum, LineInfo>(DialogEventEnum.OptionSelected, OnOptionSelected);
|
||||
@@ -50,7 +52,7 @@ namespace AibisDream
|
||||
|
||||
private void ResetAdvanceMode()
|
||||
{
|
||||
advanceMode = new AdvanceMode
|
||||
advanceMode.Value = new AdvanceMode
|
||||
{
|
||||
isAuto = false,
|
||||
isQuick = false
|
||||
@@ -60,7 +62,6 @@ namespace AibisDream
|
||||
lineSyncToken = null;
|
||||
|
||||
Time.timeScale = 1f;
|
||||
lineAdvanceInput.ResetAdvanceMode();
|
||||
}
|
||||
|
||||
#region Yarn控制
|
||||
@@ -128,25 +129,37 @@ namespace AibisDream
|
||||
|
||||
#region 推进方式修改
|
||||
|
||||
public AdvanceMode advanceMode;
|
||||
public BindProperty<AdvanceMode> advanceMode = new(new AdvanceMode());
|
||||
|
||||
public void SwitchAutoMode()
|
||||
{
|
||||
advanceMode.isAuto = !advanceMode.isAuto;
|
||||
lineAdvanceInput.SwitchAdvanceHandler(advanceMode.CurrentMode);
|
||||
var mode = advanceMode.Value;
|
||||
mode.isAuto = !mode.isAuto;
|
||||
advanceMode.Value = mode;
|
||||
}
|
||||
|
||||
public void SwitchQuickMode()
|
||||
{
|
||||
advanceMode.isQuick = !advanceMode.isQuick;
|
||||
var mode = advanceMode.Value;
|
||||
mode.isQuick = !mode.isQuick;
|
||||
advanceMode.Value = mode;
|
||||
|
||||
lineAdvanceInput.SwitchAdvanceHandler(advanceMode.CurrentMode);
|
||||
Time.timeScale = advanceMode.CurrentMode == AdvanceModeEnum.Quick ? 8f : 1f;
|
||||
Time.timeScale = advanceMode.Value.CurrentMode == AdvanceModeEnum.Quick ? 8f : 1f;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public LineSyncToken lineSyncToken;
|
||||
private LineSyncToken _lineSyncToken;
|
||||
public LineSyncToken lineSyncToken
|
||||
{
|
||||
get => _lineSyncToken;
|
||||
set
|
||||
{
|
||||
_lineSyncToken = value;
|
||||
lineAdvanceInput?.RunLine(value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool isInOption;
|
||||
|
||||
public LineSyncState GetDialogState()
|
||||
|
||||
@@ -20,7 +20,27 @@ namespace AibisDream
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
ResetAdvanceMode();
|
||||
if (DialogController.Instance != null)
|
||||
{
|
||||
DialogController.Instance.advanceMode.RegisterAndTrigger(OnAdvanceModeChanged);
|
||||
}
|
||||
else
|
||||
{
|
||||
ResetAdvanceMode();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (DialogController.Instance != null)
|
||||
{
|
||||
DialogController.Instance.advanceMode.UnRegister(OnAdvanceModeChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAdvanceModeChanged(AdvanceMode mode)
|
||||
{
|
||||
SwitchAdvanceHandler(mode.CurrentMode);
|
||||
}
|
||||
|
||||
public void RunLine(LineSyncToken lineSyncEvent)
|
||||
@@ -28,9 +48,8 @@ namespace AibisDream
|
||||
_curSyncToken = lineSyncEvent;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
private void LateUpdate()
|
||||
{
|
||||
|
||||
_handler.Handle(_curSyncToken, IsInputAvailable);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ namespace AibisDream
|
||||
{
|
||||
public class LineRunner : DialogueViewBase
|
||||
{
|
||||
[SerializeField] private LineAdvanceInput advanceInput;
|
||||
[SerializeField] private DialogViewType defaultViewType = DialogViewType.StandardBubble;
|
||||
|
||||
private readonly Dictionary<DialogViewType, ILineView> _screenViewDict = new();
|
||||
@@ -74,8 +73,6 @@ namespace AibisDream
|
||||
}
|
||||
}
|
||||
|
||||
// 最后交给推进处理
|
||||
advanceInput.RunLine(lineSyncEvent);
|
||||
}
|
||||
|
||||
public void LoadBubbleData(BubbleSlotGroupData data)
|
||||
|
||||
@@ -404,6 +404,12 @@ namespace AibisDream.Framework
|
||||
OnValueChanged += onValueChanged;
|
||||
}
|
||||
|
||||
public void RegisterAndTrigger(Action<T> onValueChanged)
|
||||
{
|
||||
OnValueChanged += onValueChanged;
|
||||
onValueChanged?.Invoke(_value);
|
||||
}
|
||||
|
||||
public void UnRegister(Action<T> onValueChanged) => OnValueChanged -= onValueChanged;
|
||||
|
||||
public override string ToString() => Value.ToString();
|
||||
|
||||
@@ -29,7 +29,29 @@ namespace AibisDream.UI
|
||||
{
|
||||
RegisterButton();
|
||||
}
|
||||
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (DialogController.Instance != null)
|
||||
{
|
||||
DialogController.Instance.advanceMode.RegisterAndTrigger(OnAdvanceModeChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (DialogController.Instance != null)
|
||||
{
|
||||
DialogController.Instance.advanceMode.UnRegister(OnAdvanceModeChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAdvanceModeChanged(AdvanceMode mode)
|
||||
{
|
||||
_autoBtn.FreshState();
|
||||
_ffwdBtn.FreshState();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKey(KeyCode.Q) && Input.GetKeyDown(KeyCode.P))
|
||||
@@ -50,25 +72,21 @@ namespace AibisDream.UI
|
||||
// 自动跳过和快进包括状态变换
|
||||
_autoBtn = topBar.Find("Auto Skip").GetComponent<BoolButton>();
|
||||
_autoBtn.OnClick.AddListener(AutoSkip);
|
||||
_autoBtn.getBool = () => DialogController.Instance.advanceMode.CurrentMode == AdvanceModeEnum.Auto;
|
||||
_autoBtn.getBool = () => DialogController.Instance.advanceMode.Value.CurrentMode == AdvanceModeEnum.Auto;
|
||||
|
||||
_ffwdBtn = topBar.Find("Quick Forward").GetComponent<BoolButton>();
|
||||
_ffwdBtn.OnClick.AddListener(QuickForward);
|
||||
_ffwdBtn.getBool = () => DialogController.Instance.advanceMode.CurrentMode == AdvanceModeEnum.Quick;
|
||||
_ffwdBtn.getBool = () => DialogController.Instance.advanceMode.Value.CurrentMode == AdvanceModeEnum.Quick;
|
||||
}
|
||||
|
||||
private void AutoSkip()
|
||||
{
|
||||
DialogController.Instance.SwitchAutoMode();
|
||||
_autoBtn.FreshState();
|
||||
_ffwdBtn.FreshState();
|
||||
}
|
||||
|
||||
private void QuickForward()
|
||||
{
|
||||
DialogController.Instance.SwitchQuickMode();
|
||||
_ffwdBtn.FreshState();
|
||||
_autoBtn.FreshState();
|
||||
}
|
||||
|
||||
private void OpenSettingPanel()
|
||||
|
||||
Reference in New Issue
Block a user