Support opening monster viewer screen from main menu
This commit is contained in:
@@ -36,7 +36,9 @@ public partial class App : Node, IApp
|
||||
|
||||
private Array _progress;
|
||||
|
||||
private AutoProp<bool> _loaded = new(false);
|
||||
private AutoProp<string> _loadedScene = new(string.Empty);
|
||||
private bool _loadingGame = false;
|
||||
private bool _loadingEnemyViewer = false;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
@@ -47,8 +49,9 @@ public partial class App : Node, IApp
|
||||
|
||||
MainMenu.NewGame += OnNewGame;
|
||||
MainMenu.LoadGame += OnLoadGame;
|
||||
MainMenu.EnemyViewer += OnEnemyViewer;
|
||||
MainMenu.Quit += OnQuit;
|
||||
_loaded.Sync += OnGameLoaded;
|
||||
_loadedScene.Changed += OnGameLoaded;
|
||||
|
||||
Instantiator = new Instantiator(GetTree());
|
||||
|
||||
@@ -63,16 +66,13 @@ public partial class App : Node, IApp
|
||||
this.Provide();
|
||||
}
|
||||
|
||||
private void OnGameLoaded(bool gameLoaded)
|
||||
private void OnGameLoaded(string sceneName)
|
||||
{
|
||||
if (gameLoaded)
|
||||
{
|
||||
Loading.Hide();
|
||||
var gameScene = (PackedScene)ResourceLoader.LoadThreadedGet(GAME_SCENE_PATH);
|
||||
var game = gameScene.Instantiate();
|
||||
AddChild(game);
|
||||
Instantiator.SceneTree.Paused = false;
|
||||
}
|
||||
Loading.Hide();
|
||||
var scene = (PackedScene)ResourceLoader.LoadThreadedGet(sceneName);
|
||||
var node = scene.Instantiate();
|
||||
AddChild(node);
|
||||
Instantiator.SceneTree.Paused = false;
|
||||
}
|
||||
|
||||
public void OnReady()
|
||||
@@ -88,7 +88,8 @@ public partial class App : Node, IApp
|
||||
})
|
||||
.Handle((in AppLogic.Output.SetupGameScene _) =>
|
||||
{
|
||||
ResourceLoader.LoadThreadedRequest(GAME_SCENE_PATH, useSubThreads: true, cacheMode: ResourceLoader.CacheMode.Ignore);
|
||||
ResourceLoader.LoadThreadedRequest(GAME_SCENE_PATH);
|
||||
_loadingGame = true;
|
||||
MainMenu.Hide();
|
||||
})
|
||||
.Handle((in AppLogic.Output.ShowMainMenu _) =>
|
||||
@@ -102,7 +103,9 @@ public partial class App : Node, IApp
|
||||
})
|
||||
.Handle((in AppLogic.Output.EnemyViewerOpened _) =>
|
||||
{
|
||||
Instantiator.LoadAndInstantiate<Node>(ENEMY_VIEWER_PATH);
|
||||
ResourceLoader.LoadThreadedRequest(ENEMY_VIEWER_PATH);
|
||||
_loadingEnemyViewer = true;
|
||||
MainMenu.Hide();
|
||||
})
|
||||
.Handle((in AppLogic.Output.ExitGame _) =>
|
||||
{
|
||||
@@ -115,16 +118,25 @@ public partial class App : Node, IApp
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (!_loaded.Value)
|
||||
if (_loadingGame)
|
||||
{
|
||||
ResourceLoader.LoadThreadedGetStatus(GAME_SCENE_PATH, _progress);
|
||||
if ((double)_progress.Single() == 1)
|
||||
_loaded.OnNext(true);
|
||||
_loadedScene.OnNext(GAME_SCENE_PATH);
|
||||
}
|
||||
|
||||
if (_loadingEnemyViewer)
|
||||
{
|
||||
ResourceLoader.LoadThreadedGetStatus(ENEMY_VIEWER_PATH, _progress);
|
||||
if ((double)_progress.Single() == 1)
|
||||
_loadedScene.OnNext(ENEMY_VIEWER_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnNewGame() => AppLogic.Input(new AppLogic.Input.NewGame());
|
||||
|
||||
private void OnEnemyViewer() => AppLogic.Input(new AppLogic.Input.EnemyViewerOpened());
|
||||
|
||||
private void OnLoadGame() => AppLogic.Input(new AppLogic.Input.LoadGame());
|
||||
|
||||
public void OnQuit() => AppLogic.Input(new AppLogic.Input.QuitGame());
|
||||
|
||||
Reference in New Issue
Block a user