using System; using UnityEngine; using UnityEngine.UI; namespace Vanguard.UI { public enum CommunityTab { Guides, Decks, Tickets, } /// /// Сцена Community: вкладки гайдов, публичных колод и тикетов. Пока это /// каркас — серверных данных для разделов нет. /// public sealed class CommunityView { public const string RootName = "CommunityScreen"; private static readonly Color PanelFill = new Color(0.024f, 0.058f, 0.15f, 0.92f); 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 TextDim = new Color(0.44f, 0.55f, 0.75f); private readonly RectTransform _root; private readonly RectTransform[] _contents; private readonly Button[] _tabs; public CommunityView(Transform parent, Action onBack) { _root = UiKit.CreatePanel(parent, RootName, new Color(0f, 0f, 0f, 0f)); _root.GetComponent().raycastTarget = false; var top = Surface(_root, "TopBar", new Color(0.012f, 0.03f, 0.08f, 0.94f), 0); top.anchorMin = new Vector2(0f, 1f); top.anchorMax = new Vector2(1f, 1f); top.pivot = new Vector2(0.5f, 1f); top.sizeDelta = new Vector2(0f, 88f); top.anchoredPosition = Vector2.zero; var back = UiKit.CreateButton(top, "Back", "← Назад", () => onBack(), 18); var backRect = back.GetComponent(); backRect.anchorMin = new Vector2(0f, 0.5f); backRect.anchorMax = new Vector2(0f, 0.5f); backRect.pivot = new Vector2(0f, 0.5f); backRect.sizeDelta = new Vector2(150f, 44f); backRect.anchoredPosition = new Vector2(24f, 0f); ApplyFill(back.GetComponent(), new Color(0.06f, 0.12f, 0.24f, 0.95f), Border); var title = UiKit.CreateText( top, "Title", "Сообщество", 30, TextPrimary, TextAnchor.MiddleLeft); title.fontStyle = FontStyle.Bold; var titleRect = title.rectTransform; titleRect.anchorMin = new Vector2(0f, 0.5f); titleRect.anchorMax = new Vector2(0f, 0.5f); titleRect.pivot = new Vector2(0f, 0.5f); titleRect.sizeDelta = new Vector2(420f, 44f); titleRect.anchoredPosition = new Vector2(196f, 0f); var hint = UiKit.CreateText( top, "Hint", "Гайды, колоды и обратная связь", 15, TextDim, TextAnchor.MiddleRight); var hintRect = hint.rectTransform; hintRect.anchorMin = new Vector2(1f, 0.5f); hintRect.anchorMax = new Vector2(1f, 0.5f); hintRect.pivot = new Vector2(1f, 0.5f); hintRect.sizeDelta = new Vector2(420f, 30f); hintRect.anchoredPosition = new Vector2(-24f, 0f); var tabs = NewRect(_root, "Tabs"); tabs.anchorMin = new Vector2(0f, 1f); tabs.anchorMax = new Vector2(0f, 1f); tabs.pivot = new Vector2(0f, 1f); tabs.sizeDelta = new Vector2(900f, 56f); tabs.anchoredPosition = new Vector2(24f, -104f); _tabs = new Button[3]; _contents = new RectTransform[3]; for (var i = 0; i < 3; i++) { var index = i; var label = TabTitle((CommunityTab)i); var tab = UiKit.CreateButton(tabs, "Tab" + i, label, () => SelectTab((CommunityTab)index), 17); var rect = tab.GetComponent(); rect.anchorMin = new Vector2(0f, 0.5f); rect.anchorMax = new Vector2(0f, 0.5f); rect.pivot = new Vector2(0f, 0.5f); rect.sizeDelta = new Vector2(250f, 52f); rect.anchoredPosition = new Vector2(i * 266f, 0f); _tabs[i] = tab; } var body = Surface(_root, "Body", PanelFill, 16); body.anchorMin = new Vector2(0f, 0f); body.anchorMax = new Vector2(1f, 1f); body.offsetMin = new Vector2(24f, 24f); body.offsetMax = new Vector2(-24f, -180f); for (var i = 0; i < 3; i++) { var tab = (CommunityTab)i; _contents[i] = StubUi.Panel( body, "Content" + i, TabTitle(tab), TabNote(tab)); } SelectTab(CommunityTab.Guides); _root.gameObject.SetActive(false); } public CommunityTab Current { get; private set; } public void Show() => UiKit.SetActive(_root, true); public void Hide() => UiKit.SetActive(_root, false); public void SelectTab(CommunityTab tab) { Current = tab; for (var i = 0; i < 3; i++) { var active = (CommunityTab)i == tab; _contents[i].gameObject.SetActive(active); ApplyFill( _tabs[i].GetComponent(), active ? new Color(0.16f, 0.40f, 0.80f, 0.95f) : new Color(0.05f, 0.10f, 0.22f, 0.9f), active ? BorderStrong : Border); } } private static string TabTitle(CommunityTab tab) { switch (tab) { case CommunityTab.Decks: return "Колоды"; case CommunityTab.Tickets: return "Тикеты"; default: return "Гайды"; } } private static string TabNote(CommunityTab tab) { switch (tab) { case CommunityTab.Decks: return "Публичные колоды появятся позже. Сейчас колодой можно поделиться по коду в редакторе."; case CommunityTab.Tickets: return "Отправка сообщений о багах и улучшениях появится позже: нужен серверный раздел тикетов."; default: return "Разборы карт, колод и механик появятся позже. Материалы будут открываться прямо здесь."; } } private static RectTransform NewRect(Transform parent, string name) { var go = new GameObject(name, typeof(RectTransform)); var rect = (RectTransform)go.transform; rect.SetParent(parent, false); return rect; } private static RectTransform Surface(Transform parent, string name, Color fill, int radius) { var go = new GameObject(name, typeof(RectTransform), typeof(Image)); var rect = (RectTransform)go.transform; rect.SetParent(parent, false); var image = go.GetComponent(); image.sprite = NeonUi.BodySliced(radius, fill, Border, 1); image.type = Image.Type.Sliced; image.color = Color.white; image.raycastTarget = false; return rect; } private static void ApplyFill(Image image, Color fill, Color border) { image.sprite = NeonUi.BodySliced(12, fill, border, 1); image.type = Image.Type.Sliced; image.color = Color.white; } } }