| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using DevilLink2.Gameplay;
- using DevilLink2.Presentation;
- using UnityEngine;
- using UnityEngine.UI;
- namespace DevilLink2.UI
- {
- /// <summary>One-time UGUI composition, in prototype coordinates. Does not create a Canvas or generate assets.</summary>
- public static class UIBuilder
- {
- public const string RootName = "DevilLink2UI";
- public static Color Navy = Hex("05080F"), Panel = Hex("131C2E"), Gold = Hex("FFD34D"), LightGold = Hex("FFF0BF"), Muted = Hex("93A5C6"), TextColor = Hex("DCE6F7");
- public static Color Hex(string value) { ColorUtility.TryParseHtmlString("#" + value, out var color); return color; }
- public static UIManager Build(RectTransform frame, BoardDemoBootstrap bootstrap, BoardView boardView, Text existingTitle = null)
- {
- var existing = frame.Find(RootName);
- if (existing) return existing.GetComponent<UIManager>();
- var root = Rect(RootName, frame, 0, 0, 430, 932);
- root.anchorMin = root.anchorMax = root.pivot = new Vector2(.5f, .5f); root.anchoredPosition = Vector2.zero;
- root.gameObject.AddComponent<UIFitLayout>().Apply();
- var start = Start(root); var lobby = Lobby(root, Resources.Load<LobbyArtCatalog>("DevilLink2LobbyArt"));
- // Keep the original board in a sibling container so rebuilding the shell cannot destroy it.
- var gameplayRoot = frame.Find("DevilLink2GameplayScreen") as RectTransform;
- if (!gameplayRoot)
- {
- gameplayRoot = Rect("DevilLink2GameplayScreen", frame, 0, 0, 430, 932);
- gameplayRoot.anchorMin = gameplayRoot.anchorMax = gameplayRoot.pivot = new Vector2(.5f, .5f);
- gameplayRoot.anchoredPosition = Vector2.zero;
- gameplayRoot.gameObject.AddComponent<UIFitLayout>().Apply();
- }
- var gameplay = gameplayRoot.GetComponent<UIScreen>(); if (!gameplay) gameplay = gameplayRoot.gameObject.AddComponent<UIScreen>();
- boardView.transform.SetParent(gameplayRoot, false);
- var oldOverlay = frame.Find("InteractionOverlay"); if (oldOverlay) oldOverlay.SetParent(gameplayRoot, false);
- if (!existingTitle) existingTitle = gameplayRoot.Find("Title")?.GetComponent<Text>() ?? gameplayRoot.Find("ModeTitle")?.GetComponent<Text>();
- Text title = existingTitle ? existingTitle : Label("ModeTitle", gameplayRoot, "", 13, Color.white, 102, 10, 316, 32);
- if (existingTitle) { title.transform.SetParent(gameplayRoot, false); Place(title.rectTransform, 102, 10, 316, 32); title.fontSize = 13; }
- var back = gameplayRoot.Find("Lobby")?.GetComponent<Button>();
- if (!back) back = Button("Lobby", gameplayRoot, "< LOBBY", 12, 8, 82, 36, Gold, Hex("A56600"), 11);
- var hud = GameUIBuilder.Build(gameplayRoot, boardView, title);
- var error = Label("NavigationError", lobby.transform, "", 11, Hex("FF4D6A"), 12, 839, 406, 16);
- var manager = root.gameObject.AddComponent<UIManager>(); manager.Configure(start, lobby, gameplay, title, back, error);
- manager.AttachHUD(hud); manager.AttachShop(ShopScreen.Build(root)); manager.AttachDaily(DailyCheckInScreen.Build(root)); manager.AttachWheel(LuckyWheelScreen.Build(root)); manager.AttachProfile(ProfileScreen.Build(root)); manager.AttachSettings(SettingsScreen.Build(root)); manager.AttachHelp(HelpScreen.Build(root));
- FunctionalScreensVisuals.Install(manager);
- GameplayArtView.Install(hud, manager.GameShopButton, Resources.Load<GameplayArtCatalog>("DevilLink2GameplayArt"));
- return manager;
- }
- private static StartScreen Start(RectTransform parent)
- { return StartScreenVisuals.Build(parent, Resources.Load<LobbyArtCatalog>("DevilLink2LobbyArt")); }
- private static LobbyScreen Lobby(RectTransform parent, LobbyArtCatalog art)
- {
- var root = Rect("LobbyScreen", parent, 0, 0, 430, 932); var screen = root.gameObject.AddComponent<LobbyScreen>();
- Fill("Background", root, Hex("0D1220"), Navy, 0, 0, 430, 932, 0);
- Fill("TopHUD", root, Hex("131C2E"), Hex("0D1220"), 0, 0, 430, 56, 0);
- Fill("AvatarBorder", root, Gold, Hex("A56600"), 14, 9, 38, 38, 19);
- Fill("AvatarPlaceholder", root, Hex("3A2C60"), Hex("151B2E"), 16, 11, 34, 34, 17);
- Label("AvatarMark", root, "?", 23, LightGold, 16, 11, 34, 34);
- var name = Label("NicknamePlaceholder", root, "LOCAL PLAYER", 15, Color.white, 62, 8, 96, 24, TextAnchor.MiddleLeft);
- name.resizeTextForBestFit = true; name.resizeTextMinSize = 9; name.resizeTextMaxSize = 15;
- Label("Identity", root, "LOCAL", 9, Hex("34E0FF"), 62, 32, 84, 16, TextAnchor.MiddleLeft);
- var coinPanel = Fill("CoinDisplay", root, Hex("2E2614"), Hex("14100A"), 164, 8, 154, 40, 16);
- coinPanel.raycastTarget = true; var coinButton = coinPanel.gameObject.AddComponent<UIFeedbackButton>(); coinButton.targetGraphic = coinPanel;
- Label("CoinIcon", root, "C", 16, Gold, 172, 12, 20, 32);
- var coins = Label("CoinsValue", root, "", 16, LightGold, 196, 12, 114, 32, TextAnchor.MiddleRight); FitText(coins);
- Fill("TicketDisplay", root, Hex("222D46"), Hex("131C2E"), 324, 8, 92, 40, 16);
- Label("TicketIcon", root, "T", 13, Gold, 330, 12, 16, 32);
- var tickets = Label("TicketsValue", root, "", 16, LightGold, 348, 12, 60, 32, TextAnchor.MiddleRight); FitText(tickets);
- var cards = new ModeCard[3];
- var accents = new[] { Gold, Hex("FF2E9A"), Hex("34E0FF") };
- var tops = new[] { Hex("2A2350"), Hex("3A1E46"), Hex("1B3A44") };
- var bottoms = new[] { Hex("0E1122"), Hex("0F0C1C"), Hex("0A1420") };
- for (int i = 0; i < 3; i++)
- {
- var mode = (GameMode)i; float h = ScreenLayout.CardHeight;
- var outer = Fill(mode + "Card", root, accents[i], accents[i] * .65f, 12, ScreenLayout.CardTop(i), 406, h, 16);
- Shadow(outer.gameObject, 4);
- var body = Fill("Panel", outer.transform, tops[i], bottoms[i], 2, 2, 402, h - 4, 14);
- var button = outer.gameObject.AddComponent<UIFeedbackButton>(); button.targetGraphic = body; button.navigation = new Navigation { mode = Navigation.Mode.None };
- body.raycastTarget = true;
- var tag = Fill("Tag", outer.transform, accents[i], accents[i] * .65f, 8, 8, 86, 26, 6);
- Label("TagText", tag.transform, i == 0 ? "TOP PICK" : i == 1 ? "FAST" : "RELAX", 9, i == 1 ? Color.white : Hex("4A2A00"), 0, 0, 86, 26);
- Ornament(outer.transform, i == 0 ? "IMP" : i == 1 ? "TRI" : "POT", 10, 46, 100, -11, accents[i]);
- Ornament(outer.transform, i == 0 ? "RNG" : i == 1 ? "STR" : "CND", 145, 28, 116, 2, accents[i]);
- Ornament(outer.transform, i == 0 ? "A" : i == 1 ? "10" : "PIG", 296, 46, 100, 12, accents[i]);
- Label("ModeName", outer.transform, UIManager.ModeName(mode), 25, accents[i], 12, h - 102, 382, 32, TextAnchor.MiddleLeft);
- string meta = i == 0 ? "4 x 8 > 10 x 14 | 3:00 | 20 LEVELS" : i == 1 ? "6 x 8 | 2:00 > 0:44 | 20 LEVELS" : "6 x 8 > 9 x 14 | NO TIMER | 20 LEVELS";
- Label("Metadata", outer.transform, meta, 11, TextColor, 12, h - 68, 382, 22, TextAnchor.MiddleLeft);
- var progress = Label("Progress", outer.transform, "", 11, Muted, 12, h - 36, 275, 26, TextAnchor.MiddleLeft);
- var play = Fill("PlayLabel", outer.transform, accents[i], accents[i] * .7f, 314, h - 44, 80, 34, 9);
- Label("PlayText", play.transform, "PLAY", 13, Hex("4A2A00"), 0, 0, 80, 34);
- cards[i] = outer.gameObject.AddComponent<ModeCard>(); cards[i].Configure(mode, button, progress);
- }
- Button shopButton = null; Button dailyButton = null; Button wheelButton = null; Button profileButton = null; Button settingsButton = null; Button helpButton = null;
- var labels = new[] { "DAILY", "WHEEL", "SHOP", "PROFILE", "SETTINGS", "HELP" };
- for (int i = 0; i < labels.Length; i++)
- {
- var reserved = Button(labels[i] == "HELP" ? "HelpEntry" : labels[i] == "SETTINGS" ? "SettingsEntry" : labels[i] == "PROFILE" ? "ProfileEntry" : labels[i] == "WHEEL" ? "WheelEntry" : labels[i] == "DAILY" ? "DailyEntry" : labels[i] == "SHOP" ? "ShopEntry" : labels[i] + "Unavailable", root, labels[i] == "HELP" || labels[i] == "SETTINGS" || labels[i] == "PROFILE" || labels[i] == "WHEEL" || labels[i] == "DAILY" || labels[i] == "SHOP" ? labels[i] : labels[i] + "\nNOT OPEN", 14 + i * 68, 858, 62, 58, Panel, Navy, 9);
- reserved.interactable = labels[i] == "SHOP" || labels[i] == "DAILY" || labels[i] == "WHEEL" || labels[i] == "PROFILE" || labels[i] == "SETTINGS" || labels[i] == "HELP"; if(labels[i] == "HELP")helpButton=reserved; if(labels[i] == "SETTINGS")settingsButton=reserved; if(labels[i] == "PROFILE")profileButton=reserved; if(labels[i] == "WHEEL")wheelButton=reserved; if(labels[i] == "DAILY")dailyButton=reserved; if (labels[i] == "SHOP") shopButton = reserved;
- }
- screen.Configure(coins, tickets, name, cards); screen.ConfigureShop(coinButton, shopButton); screen.ConfigureDaily(dailyButton); screen.ConfigureWheel(wheelButton);screen.ConfigureSettings(settingsButton);screen.ConfigureHelp(helpButton);
- var profileArea=Button("ProfileArea",root,"",14,8,144,40,new Color(0,0,0,0),new Color(0,0,0,0),1);
- screen.ConfigureProfile(profileButton,profileArea,root.Find("AvatarMark").GetComponent<Text>());
- LobbyArtView.Install(screen, art); return screen;
- }
- private static void FitText(Text text) { text.resizeTextForBestFit = true; text.resizeTextMinSize = 8; text.resizeTextMaxSize = 16; }
- private static void Ornament(Transform parent, string symbol, float x, float y, float size, float angle, Color accent)
- {
- var border = Fill("ArtTile_" + symbol, parent, accent, accent * .5f, x, y, size, size, 14);
- border.transform.localRotation = Quaternion.Euler(0, 0, angle);
- var inner = Fill("Face", border.transform, Hex("222D46"), Hex("1A2338"), 2, 2, size - 4, size - 4, 12);
- Label("Symbol", inner.transform, symbol, 24, TextColor, 0, 0, size - 4, size - 4);
- }
- internal static RoundedPanel Fill(string name, Transform parent, Color top, Color bottom, float x, float y, float w, float h, float radius)
- {
- var rect = Rect(name, parent, x, y, w, h); var panel = rect.gameObject.AddComponent<RoundedPanel>();
- panel.Radius = radius; panel.color = Color.white; panel.raycastTarget = false; Gradient(panel.gameObject, top, bottom); return panel;
- }
- internal static Button Button(string name, Transform parent, string text, float x, float y, float w, float h, Color top, Color bottom, int size)
- {
- var image = Fill(name, parent, top, bottom, x, y, w, h, 12); image.raycastTarget = true; Shadow(image.gameObject, 3);
- var button = image.gameObject.AddComponent<UIFeedbackButton>(); button.targetGraphic = image; button.navigation = new Navigation { mode = Navigation.Mode.None };
- Label("Label", image.transform, text, size, Hex("4A2A00"), 4, 0, w - 8, h); return button;
- }
- private static void Gradient(GameObject go, Color top, Color bottom)
- { var gradient = go.AddComponent<UIGradient>(); gradient.Top = top; gradient.Bottom = bottom; }
- private static void Shadow(GameObject go, float distance)
- { var shadow = go.AddComponent<Shadow>(); shadow.effectColor = new Color(0, 0, 0, .55f); shadow.effectDistance = new Vector2(0, -distance); }
- public static RectTransform Rect(string name, Transform parent, float x, float y, float w, float h)
- { var rect = (RectTransform)new GameObject(name, typeof(RectTransform)).transform; rect.SetParent(parent, false); Place(rect, x, y, w, h); return rect; }
- internal static void Place(RectTransform rect, float x, float y, float w, float h)
- { rect.anchorMin = rect.anchorMax = new Vector2(0, 1); rect.pivot = new Vector2(0, 1); rect.anchoredPosition = new Vector2(x, -y); rect.sizeDelta = new Vector2(w, h); }
- public static Text Label(string name, Transform parent, string value, int size, Color color, float x, float y, float w, float h, TextAnchor alignment = TextAnchor.MiddleCenter)
- {
- var text = Rect(name, parent, x, y, w, h).gameObject.AddComponent<Text>();
- text.font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf"); text.fontSize = size; text.fontStyle = FontStyle.Bold;
- text.text = value; text.color = color; text.alignment = alignment; text.raycastTarget = false; text.supportRichText = false;
- text.horizontalOverflow = HorizontalWrapMode.Wrap; text.verticalOverflow = VerticalWrapMode.Truncate; return text;
- }
- }
- }
|