forked from Shardstone/trail-into-darkness
77 lines
3.3 KiB
C#
77 lines
3.3 KiB
C#
using Nox.Core;
|
|
using Nox.Game;
|
|
using Jovian.SaveSystem;
|
|
using UnityEngine;
|
|
using UnityEngine.AddressableAssets;
|
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
|
|
|
namespace Nox.UI {
|
|
/// <summary>
|
|
/// Main menu interface class which is responsible for creating the main menu view and handling the main menu events
|
|
/// </summary>
|
|
public class MainMenuView : IGameLifecycle {
|
|
private readonly MenuPrefabsContainer menuPrefabsContainer;
|
|
private readonly MenuGameStateData menuGameStateData;
|
|
private readonly ISaveSystem saveSystem;
|
|
private readonly GameDataState gameDataState;
|
|
private readonly PartySettings partySettings;
|
|
private readonly ICharacterSystems characterSystems;
|
|
private MainMenuReference mainMenuReference;
|
|
private CharacterCreationReference characterCreationReference;
|
|
private CharacterCreationView characterCreationView;
|
|
private AsyncOperationHandle<GameObject> charCreationHandle;
|
|
|
|
public MainMenuView(
|
|
MenuPrefabsContainer menuPrefabsContainer,
|
|
MenuGameStateData menuGameStateData,
|
|
ISaveSystem saveSystem,
|
|
GameDataState gameDataState,
|
|
PartySettings partySettings,
|
|
ICharacterSystems characterSystems
|
|
) {
|
|
this.menuPrefabsContainer = menuPrefabsContainer;
|
|
this.menuGameStateData = menuGameStateData;
|
|
this.saveSystem = saveSystem;
|
|
this.gameDataState = gameDataState;
|
|
this.partySettings = partySettings;
|
|
this.characterSystems = characterSystems;
|
|
}
|
|
public void Initialize() {
|
|
if(mainMenuReference == null) {
|
|
mainMenuReference = Addressables.InstantiateAsync(menuPrefabsContainer.mainMenuReference).WaitForCompletion().GetComponent<MainMenuReference>();
|
|
}
|
|
mainMenuReference.exitButton.onClick.AddListener(Application.Quit);
|
|
mainMenuReference.optionsButton.onClick.AddListener(() => {/* options logic here */});
|
|
mainMenuReference.newGameButton.onClick.AddListener(InitializeCharacterCreation);
|
|
|
|
bool hasSave = saveSystem.HasAnySaves();
|
|
mainMenuReference.continueButton.gameObject.SetActive(hasSave);
|
|
if(hasSave) {
|
|
mainMenuReference.continueButton.onClick.AddListener(() => menuGameStateData.continueGameRequest.Invoke());
|
|
}
|
|
}
|
|
|
|
private void InitializeCharacterCreation() {
|
|
charCreationHandle = Addressables.InstantiateAsync(menuPrefabsContainer.characterCreationReference);
|
|
charCreationHandle.Task.ContinueWith(t => {
|
|
if(t.IsFaulted) {
|
|
Debug.LogError(t.Exception);
|
|
}
|
|
characterCreationReference =t.Result.GetComponent<CharacterCreationReference>();
|
|
characterCreationView = new CharacterCreationView(characterCreationReference, menuGameStateData, saveSystem, gameDataState, partySettings, characterSystems);
|
|
characterCreationView.Show();
|
|
});
|
|
}
|
|
|
|
public void Tick() {
|
|
characterCreationView?.Tick();
|
|
}
|
|
|
|
public void Dispose() {
|
|
characterCreationView?.Dispose();
|
|
Object.Destroy(characterCreationReference.gameObject);
|
|
charCreationHandle.Release();
|
|
}
|
|
}
|
|
}
|