using System;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
using Vanguard.Api;
using Vanguard.App;
using Vanguard.Auth;
using Vanguard.State;
namespace Vanguard.UI
{
///
/// Главный экран после входа: профиль и балансы, вход в бой/колоды/магазин,
/// заглушки разделов без серверной части и гамбургер-меню.
///
public sealed class LobbyView : IDisposable
{
public const string RootName = "LobbyScreen";
private const float Margin = 24f;
private const float LeftWidth = 560f;
private const float RightWidth = 336f;
private const float Gutter = 16f;
private const float ContentTop = 112f;
private const float BottomMargin = 24f;
private const float BalanceHeight = 88f;
private static readonly Color PanelFill = new Color(0.024f, 0.058f, 0.15f, 0.92f);
private static readonly Color PanelFillSoft = new Color(0.035f, 0.08f, 0.19f, 0.55f);
private static readonly Color Border = new Color(0.18f, 0.49f, 1f, 0.55f);
private static readonly Color BorderStrong = new Color(0.34f, 0.72f, 1f, 0.9f);
private static readonly Color TextPrimary = new Color(0.88f, 0.93f, 1f);
private static readonly Color TextMuted = new Color(0.58f, 0.69f, 0.88f);
private static readonly Color TextDim = new Color(0.44f, 0.55f, 0.75f);
private static readonly Color Accent = new Color(0.37f, 0.69f, 1f);
private readonly AuthService _auth;
private readonly PlayerState _player;
private readonly Action _onLoggedOut;
private readonly Action _onStore;
private readonly PlayerTopBar _topBar;
private readonly StatusTicker _ticker;
private readonly RectTransform _root;
private Text _gold;
private Text _dust;
private Text _tokens;
private Text _status;
private bool _disposed;
private bool _refreshing;
public LobbyView(
Transform parent,
AppConfig config,
AuthService auth,
PlayerState player,
Action onLoggedOut,
Action onBattle,
Action onDecks,
Action onStore,
Action onHistory,
Action onRating,
Action onCommunity)
{
_auth = auth;
_player = player;
_onLoggedOut = onLoggedOut;
_onStore = onStore;
_root = UiKit.CreatePanel(parent, RootName, new Color(0f, 0f, 0f, 0f));
_root.GetComponent().raycastTarget = false;
_topBar = new PlayerTopBar(
_root,
config,
player,
onLoggedOut,
onHistory,
onRating,
onCommunity);
BuildActions(onBattle, onDecks, onStore);
BuildMissions(out _status);
BuildBalances(out _gold, out _dust, out _tokens);
BuildChat();
BuildFriends();
_ticker = _root.gameObject.AddComponent();
_ticker.Hide = () => SetStatus(string.Empty);
_player.Changed += UpdateTexts;
Loc.LanguageChanged += UpdateTexts;
UpdateTexts();
_root.gameObject.SetActive(false);
}
public bool IsMenuOpen => _topBar != null && _topBar.IsMenuOpen;
public void CloseMenu()
{
if (_topBar != null)
_topBar.CloseMenu();
}
public void Show()
{
UiKit.SetActive(_root, true);
UpdateTexts();
_ = RefreshAsync();
}
public void Hide() => UiKit.SetActive(_root, false);
public void Dispose()
{
if (_disposed)
return;
_disposed = true;
_player.Changed -= UpdateTexts;
Loc.LanguageChanged -= UpdateTexts;
_topBar?.Dispose();
}
// ------------------------------------------------------------ левая колонка
private void BuildActions(Action onBattle, Action onDecks, Action onStore)
{
var actions = NewRect(_root, "Actions");
actions.anchorMin = new Vector2(0f, 1f);
actions.anchorMax = new Vector2(0f, 1f);
actions.pivot = new Vector2(0f, 1f);
actions.sizeDelta = new Vector2(LeftWidth, 428f);
actions.anchoredPosition = new Vector2(Margin, -ContentTop);
ActionCard(
actions,
"BattleCard",
"BATTLE",
"Найдите соперника и сразитесь",
LobbyIcon.Swords,
0f,
true,
onBattle);
ActionCard(
actions,
"DecksCard",
"DECK BUILDER",
"Соберите и настройте колоду",
LobbyIcon.Deck,
-148f,
false,
onDecks);
ActionCard(
actions,
"ShopCard",
"SHOP",
"Бустеры, триал-деки и токены",
LobbyIcon.Shop,
-296f,
false,
onStore);
}
private static void ActionCard(
RectTransform parent,
string name,
string title,
string subtitle,
Action icon,
float y,
bool primary,
Action onClick)
{
var card = Surface(
parent,
name,
PanelFill,
primary ? BorderStrong : Border,
primary ? 2 : 1,
18);
card.anchorMin = new Vector2(0f, 1f);
card.anchorMax = new Vector2(0f, 1f);
card.pivot = new Vector2(0f, 1f);
card.sizeDelta = new Vector2(LeftWidth, 132f);
card.anchoredPosition = new Vector2(0f, y);
var image = card.GetComponent();
image.raycastTarget = true;
var button = card.gameObject.AddComponent