77 lines
2.6 KiB
C#
77 lines
2.6 KiB
C#
using UnityEngine;
|
|
using AibisDream.UI;
|
|
using AibisDream.Framework;
|
|
using System;
|
|
using System.Globalization;
|
|
using TMPro;
|
|
|
|
namespace AibisDream.FixSystem
|
|
{
|
|
public class ScreenPanel : MonoBehaviour, ILineView
|
|
{
|
|
private const string WarningCharacterKey = "Error";
|
|
private static readonly Color WarningRedColor = new(0.9607843f, 0.4235294f, 0.4235294f, 1f);
|
|
private static readonly Color AmberColor = new(0.9019608f, 0.6352941f, 0.2352941f, 1f);
|
|
private static readonly Color BodyTextColor = new(0.9196079f, 0.7009804f, 0.372549f, 1f);
|
|
|
|
[SerializeField] private TMP_Text title;
|
|
[SerializeField] private TerminalText logText;
|
|
|
|
private void Awake()
|
|
{
|
|
EnumEventSystem.Global.Register<ScreenEventEnum, GameObject>(ScreenEventEnum.Selected, OnSelected);
|
|
EnumEventSystem.Global.Register(EventEnum.PlugOut, ClearScreen);
|
|
|
|
logText?.SetTextColor(BodyTextColor);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
EnumEventSystem.Global.UnRegister(ScreenEventEnum.Selected);
|
|
EnumEventSystem.Global.UnRegister(EventEnum.PlugOut);
|
|
}
|
|
|
|
private void OnSelected(GameObject obj)
|
|
{
|
|
gameObject.SetActive(obj == gameObject);
|
|
}
|
|
|
|
// ---------------------- 对话框功能 ----------------------
|
|
public void RunLine(LineSyncToken token)
|
|
{
|
|
if (logText != null)
|
|
{
|
|
EnumEventSystem.Global.Send(ScreenEventEnum.Selected, gameObject);
|
|
|
|
logText.OnTextShown += () => token.TextShown();
|
|
|
|
bool isWarning = string.Equals(token.lineInfo.character.key, WarningCharacterKey,
|
|
StringComparison.OrdinalIgnoreCase);
|
|
|
|
title.overrideColorTags = true;
|
|
title.color = isWarning ? WarningRedColor : AmberColor;
|
|
title.text = token.lineInfo.character.GetActorName();
|
|
logText.SetTypewriterSpeed(GetTextSpeedValue());
|
|
logText.AddText(token.lineInfo.lineText);
|
|
token.TextStart();
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("UniversalScreen: logText 为空");
|
|
}
|
|
}
|
|
|
|
private float GetTextSpeedValue()
|
|
{
|
|
var textSpeedStr = SettingLoader.Instance.TryRead("TextSpeed", out string textSpeed) ? textSpeed : "1";
|
|
return float.TryParse(textSpeedStr, NumberStyles.Float, CultureInfo.InvariantCulture, out float result) ? result : 1f;
|
|
}
|
|
|
|
public void ClearScreen()
|
|
{
|
|
logText.Clear();
|
|
title.text = string.Empty;
|
|
}
|
|
}
|
|
}
|