Enemy viewer revamp, loading screen improvement
This commit is contained in:
@@ -6,12 +6,15 @@ using Godot;
|
||||
using Godot.Collections;
|
||||
using NathanHoad;
|
||||
using SimpleInjector.Lifestyles;
|
||||
using System;
|
||||
using System.IO.Abstractions;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
using Zennysoft.Game.Implementation;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
using static Zennysoft.Game.Ma.SceneLoader;
|
||||
using static Zennysoft.Ma.Adapter.AppLogic.State;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
@@ -42,15 +45,22 @@ public partial class App : Node, IApp
|
||||
public IAppLogic AppLogic { get; set; } = default!;
|
||||
public AppLogic.IBinding AppBinding { get; set; } = default!;
|
||||
|
||||
private Array _progress;
|
||||
private Godot.Collections.Array _progress;
|
||||
private SimpleInjector.Container _container;
|
||||
|
||||
private AutoProp<string> _loadedScene = new(string.Empty);
|
||||
private DataViewer _dataViewer;
|
||||
private bool _loadingGame = false;
|
||||
private bool _loadingEnemyViewer = false;
|
||||
private string _optionsSavePath = string.Empty;
|
||||
private string _controllerSavePath = string.Empty;
|
||||
private ISaveFileManager _saveFileManager;
|
||||
private IGame _game;
|
||||
private IDataViewer _enemyViewer;
|
||||
|
||||
private event Action OnGameLoaded;
|
||||
private event Action OnEnemyViewerLoaded;
|
||||
|
||||
private double _reportedProgress = 0;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
@@ -82,7 +92,6 @@ public partial class App : Node, IApp
|
||||
MainMenu.Gallery += OnGallery;
|
||||
MainMenu.Options += OnOptions;
|
||||
MainMenu.Quit += OnQuit;
|
||||
_loadedScene.Changed += OnGameLoaded;
|
||||
|
||||
GalleryMenu.GalleryExited += GalleryExited;
|
||||
|
||||
@@ -94,6 +103,8 @@ public partial class App : Node, IApp
|
||||
AppLogic.Set(AppRepo);
|
||||
AppLogic.Set(new AppLogic.Data());
|
||||
|
||||
AppRepo.DataViewerExited += DataViewerExited;
|
||||
|
||||
Input.MouseMode = Input.MouseModeEnum.Visible;
|
||||
_progress = [];
|
||||
this.Provide();
|
||||
@@ -105,6 +116,11 @@ public partial class App : Node, IApp
|
||||
saveFileManager.DeleteSaveData();
|
||||
}
|
||||
|
||||
private void DataViewerExited()
|
||||
{
|
||||
AppLogic.Input(new AppLogic.Input.EnemyViewerExited());
|
||||
}
|
||||
|
||||
private async void OptionsMenu_OptionsMenuExited()
|
||||
{
|
||||
var saveFileManager = _container.GetInstance<ISaveFileManager>();
|
||||
@@ -121,14 +137,6 @@ public partial class App : Node, IApp
|
||||
MainMenu.GalleryButton.GrabFocus();
|
||||
}
|
||||
|
||||
private void OnGameLoaded(string sceneName)
|
||||
{
|
||||
LoadingScreen.Hide();
|
||||
var scene = (PackedScene)ResourceLoader.LoadThreadedGet(sceneName);
|
||||
var node = scene.Instantiate();
|
||||
AddChild(node);
|
||||
}
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
AppBinding = AppLogic.Bind();
|
||||
@@ -142,8 +150,7 @@ public partial class App : Node, IApp
|
||||
})
|
||||
.Handle((in AppLogic.Output.SetupGameScene _) =>
|
||||
{
|
||||
ResourceLoader.LoadThreadedRequest(GAME_SCENE_PATH);
|
||||
_loadingGame = true;
|
||||
LoadGame(GAME_SCENE_PATH);
|
||||
MainMenu.ReleaseFocus();
|
||||
MainMenu.Hide();
|
||||
})
|
||||
@@ -158,10 +165,17 @@ public partial class App : Node, IApp
|
||||
})
|
||||
.Handle((in AppLogic.Output.EnemyViewerOpened _) =>
|
||||
{
|
||||
ResourceLoader.LoadThreadedRequest(ENEMY_VIEWER_PATH);
|
||||
_loadingEnemyViewer = true;
|
||||
LoadEnemyViewer(ENEMY_VIEWER_PATH);
|
||||
MainMenu.ReleaseFocus();
|
||||
MainMenu.Hide();
|
||||
})
|
||||
.Handle((in AppLogic.Output.EnemyViewerExited _) =>
|
||||
{
|
||||
if (_enemyViewer != null && _enemyViewer is DataViewer enemyViewer)
|
||||
enemyViewer.CallDeferred(MethodName.QueueFree);
|
||||
MainMenu.Show();
|
||||
MainMenu.EnemyViewerButton.GrabFocus();
|
||||
})
|
||||
.Handle((in AppLogic.Output.ExitGame _) =>
|
||||
{
|
||||
GetTree().Quit();
|
||||
@@ -172,21 +186,10 @@ public partial class App : Node, IApp
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (_loadingGame)
|
||||
{
|
||||
ResourceLoader.LoadThreadedGetStatus(GAME_SCENE_PATH, _progress);
|
||||
LoadingScreen.ProgressBar.Value = (double)_progress.Single();
|
||||
if ((double)_progress.Single() == 1)
|
||||
_loadedScene.OnNext(GAME_SCENE_PATH);
|
||||
}
|
||||
|
||||
if (_loadingEnemyViewer)
|
||||
{
|
||||
ResourceLoader.LoadThreadedGetStatus(ENEMY_VIEWER_PATH, _progress);
|
||||
LoadingScreen.ProgressBar.Value = (double)_progress.Single();
|
||||
if ((double)_progress.Single() == 1)
|
||||
_loadedScene.OnNext(ENEMY_VIEWER_PATH);
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
public void OnStartGame() => AppLogic.Input(new AppLogic.Input.NewGame());
|
||||
@@ -195,6 +198,37 @@ public partial class App : Node, IApp
|
||||
|
||||
private void OnGalleryViewer() => AppLogic.Input(new AppLogic.Input.GalleryOpened());
|
||||
|
||||
private async void LoadGame(string sceneName)
|
||||
{
|
||||
var scene = await LoadSceneInternal(sceneName);
|
||||
_game = scene as IGame;
|
||||
await ToSignal(GetTree().CreateTimer(0.8f), "timeout");
|
||||
CallDeferred(MethodName.AddChild, scene);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private async Task<Node> LoadSceneInternal(string sceneName)
|
||||
{
|
||||
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();
|
||||
@@ -223,6 +257,5 @@ public partial class App : Node, IApp
|
||||
MainMenu.StartGame -= OnStartGame;
|
||||
MainMenu.EnemyViewer -= OnEnemyViewer;
|
||||
MainMenu.Quit -= OnQuit;
|
||||
_loadedScene.Changed -= OnGameLoaded;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user