78 lines
2.8 KiB
C#
78 lines
2.8 KiB
C#
using Intrepid.GameManagers;
|
|
using Intrepid.Gameplay.Codex.Visual.Events;
|
|
using Intrepid.Utilities;
|
|
using UnityEngine;
|
|
|
|
namespace Intrepid.Gameplay.Codex.Visual
|
|
{
|
|
/// <summary>
|
|
/// New visual-language entrypoint for CODEX/PDA/ActionBelt/world marks.
|
|
/// Transitional note: this currently uses the existing Theme asset.
|
|
/// Later Theme can be renamed/wrapped as PictorialProtocol without changing consumers much.
|
|
/// </summary>
|
|
public class CodexVisualService : SingletonMonoBehaviour<CodexVisualService>
|
|
{
|
|
[GroupConfigurations, SerializeField] private PictorialProtocolTag defaultProtocol;
|
|
[GroupDebug, SerializeField] private PictorialProtocolTag currentProtocol;
|
|
|
|
private int version;
|
|
private PictorialProtocolTag committedProtocol;
|
|
private CodexVisualContext currentContext;
|
|
|
|
public PictorialProtocolTag CurrentPictorialProtocol => currentProtocol ?? defaultProtocol;
|
|
public CodexVisualContext CurrentContext
|
|
{
|
|
get
|
|
{
|
|
currentContext ??= new CodexVisualContext(CurrentPictorialProtocol, version);
|
|
return currentContext;
|
|
}
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
SingletonInstantiation(false, _ => { });
|
|
committedProtocol = CurrentPictorialProtocol;
|
|
currentContext = new CodexVisualContext(CurrentPictorialProtocol, version);
|
|
}
|
|
|
|
public void ApplyTheme(PictorialProtocolTag protocol, CodexVisualChangeMode mode = CodexVisualChangeMode.Commit)
|
|
{
|
|
var nextProtocol = protocol ?? defaultProtocol;
|
|
var previousProtocol = CurrentPictorialProtocol;
|
|
|
|
if (previousProtocol == nextProtocol && mode != CodexVisualChangeMode.CancelPreview) return;
|
|
|
|
currentProtocol = nextProtocol;
|
|
if (CodexVisualChangeMode.Preview != mode)
|
|
{
|
|
committedProtocol = nextProtocol;
|
|
}
|
|
|
|
currentContext = new CodexVisualContext(CurrentPictorialProtocol, ++version, mode == CodexVisualChangeMode.Preview);
|
|
RaiseChanged(previousProtocol, CurrentPictorialProtocol, mode);
|
|
}
|
|
|
|
public void PreviewTheme(PictorialProtocolTag protocol)
|
|
{
|
|
ApplyTheme(protocol, CodexVisualChangeMode.Preview);
|
|
}
|
|
|
|
public void CancelPreview()
|
|
{
|
|
ApplyTheme(committedProtocol, CodexVisualChangeMode.CancelPreview);
|
|
}
|
|
|
|
private void RaiseChanged(PictorialProtocolTag previousProtocol, PictorialProtocolTag nextProtocol, CodexVisualChangeMode mode)
|
|
{
|
|
Proxy.Instance.EventBus.Raise(new CodexVisualChangedEvent
|
|
{
|
|
PreviousProtocol = previousProtocol,
|
|
CurrentProtocol = nextProtocol,
|
|
Context = CurrentContext,
|
|
Mode = mode
|
|
});
|
|
}
|
|
}
|
|
}
|