feat: Add fatal error dialog

This commit is contained in:
2025-07-05 01:10:15 +08:00
parent 1eeaa4f728
commit 4628db1d49
6 changed files with 965 additions and 32 deletions

View File

@@ -23,6 +23,12 @@ namespace Cryville.Common.Unity.UI {
[SerializeField]
protected bool m_ChildScaleHeight;
[SerializeField]
protected bool m_ChildOverflowWidth;
[SerializeField]
protected bool m_ChildOverflowHeight;
public override void CalculateLayoutInputHorizontal() {
base.CalculateLayoutInputHorizontal();
CalcAlongAxis(0);
@@ -60,9 +66,10 @@ namespace Cryville.Common.Unity.UI {
float size = rectTransform.rect.size[axis];
bool controlSize = (axis == 0) ? m_ChildControlWidth : m_ChildControlHeight;
bool useScale = (axis == 0) ? m_ChildScaleWidth : m_ChildScaleHeight;
bool overflow = (axis == 0) ? m_ChildOverflowWidth : m_ChildOverflowHeight;
bool childForceExpandSize = (axis == 0) ? m_ChildForceExpandWidth : m_ChildForceExpandHeight;
float alignmentOnAxis = GetAlignmentOnAxis(axis);
float innerSize = size - ((axis == 0) ? padding.horizontal : padding.vertical);
float innerSize = overflow ? float.PositiveInfinity : (size - ((axis == 0) ? padding.horizontal : padding.vertical));
RectTransform child = rectChildren[0];
GetChildSizes(child, axis, controlSize, childForceExpandSize, out var min2, out var preferred2, out var flexible2);
float scaleFactor2 = useScale ? child.localScale[axis] : 1f;

View File

@@ -4,7 +4,7 @@ MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
executionOrder: -95
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@@ -0,0 +1,37 @@
using Cryville.Common.Unity;
using Cryville.Common.Unity.UI;
using System.Globalization;
using UnityEngine;
namespace Cryville.EEW.Unity.UI {
public class Dialog : MonoBehaviour {
public static Dialog Instance { get; private set; }
[SerializeField] CanvasGroup m_mask;
PropertyTweener<float> _groupAlphaTweener;
[SerializeField] TMPLocalizedText m_title;
[SerializeField] TMPLocalizedText m_message;
void Awake() {
Instance = this;
m_mask.gameObject.SetActive(false);
_groupAlphaTweener = new(() => m_mask.alpha, v => m_mask.alpha = v, Tweeners.Single);
}
public void Show(string title, string message) {
Show(SharedCultures.CurrentUICulture, title, message);
}
public void Show(CultureInfo culture, string title, string message) {
m_title.SetText(title, culture);
m_message.SetText(message, culture);
m_mask.gameObject.SetActive(true);
_groupAlphaTweener.Start(1, 0.2f);
}
void Update() {
_groupAlphaTweener.Advance(Time.deltaTime);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f1b4f209f34bc6e4c8e13aeb4dd5789d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: -5
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -53,40 +53,52 @@ namespace Cryville.EEW.Unity {
}
Instance = this;
App.Init();
try {
App.Init();
_worker = new(new TTSWorker());
_grouper = new ReportGrouper();
_cancellationTokenSource = new();
_worker = new(new TTSWorker());
_grouper = new ReportGrouper();
_cancellationTokenSource = new();
}
catch (Exception ex) {
Dialog.Instance.Show("FATAL ERROR", ex.ToString());
throw;
}
}
void Start() {
App.MainLogger.Log(1, "App", null, "Initializing localized resources manager");
LocalizedResources.Init(new LocalizedResourcesManager());
RegisterViewModelGenerators(_worker);
RegisterTTSMessageGenerators(_worker);
BuildWorkers();
_worker.RVMGeneratorContext = SharedSettings.Instance;
_worker.TTSMessageGeneratorContext = SharedSettings.Instance;
_worker.RVMCulture = SharedSettings.Instance.RVMCulture;
_worker.SetTTSCultures(SharedSettings.Instance.TTSCultures ?? new TTSCultureConfig[0]);
_worker.IgnoreLanguageVariant = SharedSettings.Instance.DoIgnoreLanguageVariant;
_ongoingReportManager.Changed += OnOngoingReported;
_worker.Reported += OnReported;
_grouper.GroupUpdated += OnGroupUpdated;
_grouper.GroupRemoved += OnGroupRemoved;
App.MainLogger.Log(1, "App", null, "Worker ready");
Task.Run(() => GatewayVerify(_cancellationTokenSource.Token)).ContinueWith(task => {
if (task.IsFaulted) {
OnReported(this, new() { Title = task.Exception.Message });
return;
}
_verified = true;
_uiActionQueue.Enqueue(() => m_connectingHint.SetActive(false));
Task.Run(() => ScheduledGatewayVerify(_cancellationTokenSource, _cancellationTokenSource.Token));
Task.Run(() => _worker.RunAsync(_cancellationTokenSource.Token));
Task.Run(() => _ongoingReportManager.RunAsync(_cancellationTokenSource.Token));
}, TaskScheduler.Current);
try {
App.MainLogger.Log(1, "App", null, "Initializing localized resources manager");
LocalizedResources.Init(new LocalizedResourcesManager());
RegisterViewModelGenerators(_worker);
RegisterTTSMessageGenerators(_worker);
BuildWorkers();
_worker.RVMGeneratorContext = SharedSettings.Instance;
_worker.TTSMessageGeneratorContext = SharedSettings.Instance;
_worker.RVMCulture = SharedSettings.Instance.RVMCulture;
_worker.SetTTSCultures(SharedSettings.Instance.TTSCultures ?? new TTSCultureConfig[0]);
_worker.IgnoreLanguageVariant = SharedSettings.Instance.DoIgnoreLanguageVariant;
_ongoingReportManager.Changed += OnOngoingReported;
_worker.Reported += OnReported;
_grouper.GroupUpdated += OnGroupUpdated;
_grouper.GroupRemoved += OnGroupRemoved;
App.MainLogger.Log(1, "App", null, "Worker ready");
Task.Run(() => GatewayVerify(_cancellationTokenSource.Token)).ContinueWith(task => {
if (task.IsFaulted) {
OnReported(this, new() { Title = task.Exception.Message });
return;
}
_verified = true;
_uiActionQueue.Enqueue(() => m_connectingHint.SetActive(false));
Task.Run(() => ScheduledGatewayVerify(_cancellationTokenSource, _cancellationTokenSource.Token));
Task.Run(() => _worker.RunAsync(_cancellationTokenSource.Token));
Task.Run(() => _ongoingReportManager.RunAsync(_cancellationTokenSource.Token));
}, TaskScheduler.Current);
}
catch (Exception ex) {
Dialog.Instance.Show("FATAL ERROR", ex.ToString());
throw;
}
}
void OnDestroy() {

File diff suppressed because it is too large Load Diff