Loading screen fixes, transition screen UI fixes

This commit is contained in:
2026-02-03 01:47:42 -08:00
parent 51010c4f7d
commit 34dce8c5a2
14 changed files with 335 additions and 256 deletions

View File

@@ -55,144 +55,142 @@ public partial class App : Node, IApp
public void Initialize()
{
_container = new SimpleInjector.Container();
_container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();
_container.RegisterSingleton<IAppRepo, AppRepo>();
_container.RegisterSingleton<IAppLogic, AppLogic>();
_container.RegisterSingleton<IFileSystem, FileSystem>();
_container.RegisterSingleton<ISaveFileManager, SaveFileManager>();
_container = new SimpleInjector.Container();
_container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();
_container.RegisterSingleton<IAppRepo, AppRepo>();
_container.RegisterSingleton<IAppLogic, AppLogic>();
_container.RegisterSingleton<IFileSystem, FileSystem>();
_container.RegisterSingleton<ISaveFileManager, SaveFileManager>();
_saveFileManager = _container.GetInstance<ISaveFileManager>();
_optionsSavePath = $"{OS.GetUserDataDir()}/options.json";
_controllerSavePath = $"{OS.GetUserDataDir()}/controls.json";
_saveFileManager = _container.GetInstance<ISaveFileManager>();
_optionsSavePath = $"{OS.GetUserDataDir()}/options.json";
_controllerSavePath = $"{OS.GetUserDataDir()}/controls.json";
MainMenu.StartGame += OnStartGame;
MainMenu.EnemyViewer += OnEnemyViewer;
MainMenu.Gallery += OnGallery;
MainMenu.Options += OnOptions;
MainMenu.Quit += OnQuit;
MainMenu.StartGame += OnStartGame;
MainMenu.EnemyViewer += OnEnemyViewer;
MainMenu.Gallery += OnGallery;
MainMenu.Options += OnOptions;
MainMenu.Quit += OnQuit;
GalleryMenu.GalleryExited += GalleryExited;
GalleryMenu.GalleryExited += GalleryExited;
OptionsMenu.OptionsMenuExited += OptionsMenu_OptionsMenuExited;
OptionsMenu.DeleteSaveData += DeleteSaveData;
AppRepo = _container.GetInstance<IAppRepo>();
AppLogic = _container.GetInstance<IAppLogic>();
OptionsMenu.OptionsMenuExited += OptionsMenu_OptionsMenuExited;
OptionsMenu.DeleteSaveData += DeleteSaveData;
AppRepo = _container.GetInstance<IAppRepo>();
AppLogic = _container.GetInstance<IAppLogic>();
Task.Run(() => _saveFileManager.ReadFromFile<string>(_controllerSavePath).ContinueWith((data) =>
{
if (data.IsCompletedSuccessfully)
OptionsMenu.Controller.CallDeferred(nameof(OptionsMenu.Controller.LoadControllerInput), data.Result);
}));
Task.Run(() => _saveFileManager.ReadFromFile<string>(_controllerSavePath).ContinueWith((data) =>
{
if (data.IsCompletedSuccessfully)
OptionsMenu.Controller.CallDeferred(nameof(OptionsMenu.Controller.LoadControllerInput), data.Result);
}));
AppLogic.Set(AppRepo);
AppLogic.Set(new AppLogic.Data());
AppLogic.Set(AppRepo);
AppLogic.Set(new AppLogic.Data());
AppRepo.DataViewerExited += DataViewerExited;
AppRepo.DataViewerExited += DataViewerExited;
Input.MouseMode = Input.MouseModeEnum.Visible;
_progress = [];
this.Provide();
Input.MouseMode = Input.MouseModeEnum.Visible;
_progress = [];
this.Provide();
}
private void GameExitRequested()
{
AppLogic.Input(new AppLogic.Input.QuitGame());
AppLogic.Input(new AppLogic.Input.QuitGame());
}
private void DeleteSaveData()
{
var saveFileManager = _container.GetInstance<ISaveFileManager>();
saveFileManager.DeleteSaveData();
var saveFileManager = _container.GetInstance<ISaveFileManager>();
saveFileManager.DeleteSaveData();
}
private void DataViewerExited()
{
AppLogic.Input(new AppLogic.Input.EnemyViewerExited());
AppLogic.Input(new AppLogic.Input.EnemyViewerExited());
}
private async void OptionsMenu_OptionsMenuExited()
{
var saveFileManager = _container.GetInstance<ISaveFileManager>();
await saveFileManager.WriteToFile(OptionsMenu.OptionsData, _optionsSavePath);
var controllerOutput = InputHelper.SerializeInputsForActions();
await saveFileManager.WriteToFile(controllerOutput, _controllerSavePath);
OptionsMenu.Hide();
MainMenu.OptionsButton.GrabFocus();
var saveFileManager = _container.GetInstance<ISaveFileManager>();
await saveFileManager.WriteToFile(OptionsMenu.OptionsData, _optionsSavePath);
var controllerOutput = InputHelper.SerializeInputsForActions();
await saveFileManager.WriteToFile(controllerOutput, _controllerSavePath);
OptionsMenu.Hide();
MainMenu.OptionsButton.GrabFocus();
}
private void GalleryExited()
{
GalleryMenu.Hide();
MainMenu.GalleryButton.GrabFocus();
GalleryMenu.Hide();
MainMenu.GalleryButton.GrabFocus();
}
public void OnReady()
{
AppBinding = AppLogic.Bind();
AppBinding = AppLogic.Bind();
AppBinding
.Handle((in AppLogic.Output.Initialize _) =>
{
Task.Run(() => _saveFileManager.ReadFromFile<string>(_optionsSavePath).ContinueWith((data) =>
{
AppLogic.Input(new AppLogic.Input.SaveFileLoaded());
}));
})
.Handle((in AppLogic.Output.ShowSplashScreen _) =>
{
AppLogic.Input(new AppLogic.Input.FadeOutFinished());
})
.Handle((in AppLogic.Output.HideSplashScreen _) =>
{
})
.Handle((in AppLogic.Output.SetupGameScene _) =>
{
LoadingScreen.Show();
LoadGame(GAME_SCENE_PATH);
})
.Handle((in AppLogic.Output.ShowMainMenu _) =>
{
MainMenu.CallDeferred(MainMenu.MethodName.FadeIn);
})
.Handle((in AppLogic.Output.CloseGame _) =>
{
LoadingScreen.Hide();
_game.GameExitRequested -= GameExitRequested;
MainMenu.StartGameButton.GrabFocus();
_game.CallDeferred(MethodName.QueueFree, []);
GetTree().Paused = false;
})
.Handle((in AppLogic.Output.StartLoadingSaveFile _) =>
{
})
.Handle((in AppLogic.Output.EnemyViewerOpened _) =>
{
LoadingScreen.Show();
LoadEnemyViewer(ENEMY_VIEWER_PATH);
})
.Handle((in AppLogic.Output.EnemyViewerExited _) =>
{
LoadingScreen.Hide();
if (_enemyViewer != null && _enemyViewer is DataViewer enemyViewer)
enemyViewer.CallDeferred(MethodName.QueueFree);
MainMenu.Show();
MainMenu.EnemyViewerButton.GrabFocus();
})
.Handle((in AppLogic.Output.ExitGame _) =>
{
GetTree().Quit();
});
AppBinding
.Handle((in AppLogic.Output.Initialize _) =>
{
Task.Run(() => _saveFileManager.ReadFromFile<string>(_optionsSavePath).ContinueWith((data) =>
{
AppLogic.Input(new AppLogic.Input.SaveFileLoaded());
}));
})
.Handle((in AppLogic.Output.ShowSplashScreen _) =>
{
AppLogic.Input(new AppLogic.Input.FadeOutFinished());
})
.Handle((in AppLogic.Output.HideSplashScreen _) =>
{
})
.Handle((in AppLogic.Output.SetupGameScene _) =>
{
LoadingScreen.Show();
LoadGame(GAME_SCENE_PATH);
})
.Handle((in AppLogic.Output.ShowMainMenu _) =>
{
MainMenu.CallDeferred(MainMenu.MethodName.FadeIn);
})
.Handle((in AppLogic.Output.CloseGame _) =>
{
LoadingScreen.Hide();
_game.GameExitRequested -= GameExitRequested;
MainMenu.StartGameButton.GrabFocus();
_game.CallDeferred(MethodName.QueueFree, []);
GetTree().Paused = false;
})
.Handle((in AppLogic.Output.StartLoadingSaveFile _) =>
{
})
.Handle((in AppLogic.Output.EnemyViewerOpened _) =>
{
LoadingScreen.Show();
MainMenu.Hide();
LoadEnemyViewer(ENEMY_VIEWER_PATH);
})
.Handle((in AppLogic.Output.EnemyViewerExited _) =>
{
LoadingScreen.Hide();
if (_enemyViewer != null && _enemyViewer is DataViewer enemyViewer)
enemyViewer.CallDeferred(MethodName.QueueFree);
MainMenu.Show();
MainMenu.EnemyViewerButton.GrabFocus();
})
.Handle((in AppLogic.Output.ExitGame _) =>
{
GetTree().Quit();
});
AppLogic.Start();
AppLogic.Start();
}
public override void _Process(double delta)
{
if (_reportedProgress < 1)
LoadingScreen.ProgressBar.Value = Mathf.RoundToInt(Mathf.Lerp(LoadingScreen.ProgressBar.Value, _reportedProgress * 100, (float)delta * 2));
else
LoadingScreen.ProgressBar.Value = Mathf.RoundToInt(Mathf.Lerp(LoadingScreen.ProgressBar.Value, 200, (float)delta * 5));
LoadingScreen.ProgressBar.Value = Mathf.RoundToInt(Mathf.Lerp(LoadingScreen.ProgressBar.Value, _reportedProgress * 100, (float)delta * 2));
}
public void OnStartGame() => AppLogic.Input(new AppLogic.Input.NewGame());
@@ -203,64 +201,68 @@ public partial class App : Node, IApp
private async void LoadGame(string sceneName)
{
var scene = await LoadSceneInternal(sceneName);
_game = scene as IGame;
_game.GameExitRequested += GameExitRequested;
await ToSignal(GetTree().CreateTimer(0.8f), "timeout");
CallDeferred(MethodName.AddChild, scene);
var scene = await LoadSceneInternal(sceneName);
_game = scene as IGame;
_game.GameLoaded += OnGameLoaded;
_game.GameExitRequested += GameExitRequested;
await ToSignal(GetTree().CreateTimer(0.8f), "timeout");
CallDeferred(MethodName.AddChild, scene);
}
private void OnGameLoaded() => LoadingScreen.Hide();
private async void LoadEnemyViewer(string sceneName)
{
var scene = await LoadSceneInternal(sceneName);
_enemyViewer = scene as IDataViewer;
await ToSignal(GetTree().CreateTimer(0.8f), "timeout");
CallDeferred(MethodName.AddChild, scene);
var scene = await LoadSceneInternal(sceneName);
_enemyViewer = scene as IDataViewer;
await ToSignal(GetTree().CreateTimer(0.8f), "timeout");
CallDeferred(MethodName.AddChild, scene);
LoadingScreen.Hide();
}
private async Task<Node> LoadSceneInternal(string sceneName)
{
LoadingScreen.Show();
LoadingScreen.ProgressBar.Value = 0;
var sceneLoader = new SceneLoader();
CallDeferred(MethodName.AddChild, sceneLoader);
sceneLoader.LoadSceneRequest(sceneName);
sceneLoader.SceneReportedProgress += SceneLoader_SceneReportedProgress;
await ToSignal(sceneLoader, SceneLoader.SignalName.SceneLoaded);
var result = sceneLoader.LoadedScene;
sceneLoader.QueueFree();
return result;
LoadingScreen.Show();
LoadingScreen.ProgressBar.Value = 0;
var sceneLoader = new SceneLoader();
CallDeferred(MethodName.AddChild, sceneLoader);
sceneLoader.LoadSceneRequest(sceneName);
sceneLoader.SceneReportedProgress += SceneLoader_SceneReportedProgress;
await ToSignal(sceneLoader, SceneLoader.SignalName.SceneLoaded);
var result = sceneLoader.LoadedScene;
sceneLoader.QueueFree();
return result;
}
private void SceneLoader_SceneReportedProgress(double progress) => _reportedProgress = progress;
private async void OnOptions()
{
OptionsMenu.Show();
OptionsMenu.GameTab.GrabFocus();
OptionsMenu.Show();
OptionsMenu.GameTab.GrabFocus();
}
private async void OnGallery()
{
GalleryMenu.Show();
GalleryMenu.ItemButton1.GrabFocus();
GalleryMenu.Show();
GalleryMenu.ItemButton1.GrabFocus();
}
public void OnQuit() => AppLogic.Input(new AppLogic.Input.QuitGame());
public void OnSaveFileLoaded()
{
AppLogic.Input(new AppLogic.Input.SaveFileLoaded());
AppLogic.Input(new AppLogic.Input.SaveFileLoaded());
}
public void OnExitTree()
{
AppLogic.Stop();
AppBinding.Dispose();
AppRepo.Dispose();
AppLogic.Stop();
AppBinding.Dispose();
AppRepo.Dispose();
MainMenu.StartGame -= OnStartGame;
MainMenu.EnemyViewer -= OnEnemyViewer;
MainMenu.Quit -= OnQuit;
MainMenu.StartGame -= OnStartGame;
MainMenu.EnemyViewer -= OnEnemyViewer;
MainMenu.Quit -= OnQuit;
}
}

View File

@@ -14,10 +14,6 @@ script = ExtResource("1_rt73h")
unique_name_in_owner = true
visible = false
[node name="LoadingScreen" parent="." instance=ExtResource("3_3st5l")]
unique_name_in_owner = true
visible = false
[node name="OptionsMenu" parent="." instance=ExtResource("2_v0mgf")]
unique_name_in_owner = true
visible = false
@@ -31,3 +27,9 @@ unique_name_in_owner = true
visible = false
offset_right = 40.0
offset_bottom = 40.0
[node name="LoadingScreen" parent="." instance=ExtResource("3_3st5l")]
unique_name_in_owner = true
visible = false
top_level = true
z_index = 999