VanguardReMaster/client/Assets/Vanguard/Runtime/UI/AppRootView.cs

149 lines
3.7 KiB
C#

using UnityEngine;
using Vanguard.Api.Contracts;
using Vanguard.App;
using Vanguard.Auth;
using Vanguard.Battle;
using Vanguard.Meta;
using Vanguard.State;
namespace Vanguard.UI
{
/// <summary>Владелец Canvas и переключения экранов.</summary>
public sealed class AppRootView
{
private readonly AppConfig _config;
private readonly AuthService _auth;
private readonly PlayerState _player;
private readonly MetaService _metaService;
private LoginView _login;
private MetaView _metaView;
private OnboardingView _onboarding;
private CollectionView _collection;
private DecksView _decks;
private QueueView _queue;
private BattleView _battle;
public AppRootView(
AppConfig config,
AuthService auth,
PlayerState player,
MetaService metaService)
{
_config = config;
_auth = auth;
_player = player;
_metaService = metaService;
}
public void Initialize()
{
var canvas = UiKit.CreateCanvas("Vanguard Canvas");
_login = new LoginView(canvas.transform, _config, _auth, OnAuthenticated);
_metaView = new MetaView(
canvas.transform,
_auth,
_player,
OnLoggedOut,
ShowCollection,
ShowDecks,
ShowDecks,
ShowOnboarding);
_onboarding = new OnboardingView(
canvas.transform, _auth, _metaService, OnOnboarded, OnLoggedOut);
_collection = new CollectionView(
canvas.transform, _metaService, _player, ShowMeta);
_decks = new DecksView(
canvas.transform, _metaService, _player, ShowMeta, ShowQueue);
_queue = new QueueView(
canvas.transform, _metaService, _auth, ShowDecks, ShowBattle);
_battle = new BattleView(
canvas.transform, _metaService, ShowMeta);
ShowLogin("Проверяем сессию…");
}
public void Tick()
{
_battle?.Tick();
}
public void ShowLogin(string status = null)
{
HideAll();
_login.Show(status);
}
public void ShowAfterLogin()
{
if (_player.OnboardingCompleted)
ShowMeta();
else
ShowOnboarding();
}
public void ShowMeta()
{
HideAll();
_metaView.Show();
}
public void ShowOnboarding()
{
HideAll();
_onboarding.Show();
}
public void ShowCollection()
{
HideAll();
_collection.Show();
}
public void ShowDecks()
{
HideAll();
_decks.Show();
}
public void ShowQueue(DeckDto deck)
{
HideAll();
_queue.Show(deck);
}
public void ShowBattle(MatchConnectionInfo info)
{
HideAll();
_battle.Show(info);
}
private void HideAll()
{
_login.Hide();
_metaView.Hide();
_onboarding.Hide();
_collection.Hide();
_decks.Hide();
_queue.Hide();
_battle.Hide();
}
private void OnAuthenticated()
{
ShowAfterLogin();
}
private void OnOnboarded()
{
ShowMeta();
}
private void OnLoggedOut()
{
ShowLogin("Сессия завершена. Войдите снова.");
}
}
}