| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- using TMPro;
- using UnityEngine;
- using UnityEngine.UI;
- namespace DevilLink2.UI
- {
- /// <summary>Lobby-only decoration of the existing controls. Owns no navigation or player data.</summary>
- public sealed class LobbyArtView : MonoBehaviour
- {
- public Image Background { get; private set; }
- public TextMeshProUGUI Coins { get; private set; }
- public TextMeshProUGUI Tickets { get; private set; }
- public const float CardWidth = 130, CardHeight = 286, CardTop = 476;
- public static LobbyArtView Install(LobbyScreen screen, LobbyArtCatalog art)
- {
- var existing = screen.GetComponent<LobbyArtView>();
- if (existing) return existing;
- var view = screen.gameObject.AddComponent<LobbyArtView>();
- if (art) view.Build(screen, art);
- return view;
- }
- private void Build(LobbyScreen screen, LobbyArtCatalog art)
- {
- Transform root = screen.transform;
- if (art.Background)
- {
- var clip = UIBuilder.Rect("LobbyArtworkViewport", root, 0, 0, 430, 932);
- clip.gameObject.AddComponent<RectMask2D>(); clip.SetSiblingIndex(1);
- Background = Picture("Castle", clip, art.Background, 0, 0, 430, 932);
- // Cover rather than stretch; clipping is confined to this background-only viewport.
- Background.rectTransform.pivot = new Vector2(.5f, .5f);
- var fitter = Background.gameObject.AddComponent<AspectRatioFitter>();
- // In EditMode, None recomputes aspectRatio from the current rect. Set the mode first.
- // EnvelopeParent owns anchors and size; do not overwrite them after configuration.
- fitter.aspectMode = AspectRatioFitter.AspectMode.EnvelopeParent;
- fitter.aspectRatio = art.Background.rect.width / art.Background.rect.height;
- }
- var logo = Picture("LobbyLogo", root, art.Logo, 65, 145, 300, 142);
- if (!logo) UIBuilder.Label("LobbyTitle", root, "DEVIL LINK 2", 30, UIBuilder.LightGold, 45, 158, 340, 60);
- else LobbyLogoAnimation.Install(screen, logo);
- if (art.Panel)
- {
- var panel = Picture("ModeHeadingPanel", root, art.Panel, 43, 311, 344, 161);
- UIBuilder.Label("Heading", panel.transform, "CHOOSE YOUR MODE", 19, UIBuilder.LightGold, 30, 65, 284, 30);
- UIBuilder.Label("Caption", panel.transform, "3 MODES / 20 LEVELS EACH", 11, UIBuilder.TextColor, 30, 100, 284, 24);
- }
- UIBuilder.Place((RectTransform)root.Find("TopHUD"), 0, 0, 430, 56);
- var top = root.Find("TopHUD");
- var topGradient = top.GetComponent<UIGradient>();
- if (topGradient) { topGradient.Top=UIBuilder.Hex("30203F"); topGradient.Bottom=UIBuilder.Hex("140E24"); }
- var topImage=top.GetComponent<Image>(); if(topImage)topImage.color=UIBuilder.Hex("241630");
- var seam=UIBuilder.Rect("PlayerBarDivider",top,12,54,406,1).gameObject.AddComponent<Image>();
- seam.color=new Color(.62f,.46f,.24f,.5f);seam.raycastTarget=false;
- UIBuilder.Place(screen.NameLabel.rectTransform, 62, 8, 240, 24);
- // Both resource backgrounds are exactly 3:1; their '+' remains in the button hit area.
- if (art.Coins)
- {
- var rect = (RectTransform)root.Find("CoinDisplay");
- UIBuilder.Place(rect, 12, 62, 198, 66);
- HideGraphic(rect); Picture("Art", rect, art.Coins, 0, 0, 198, 66);
- root.Find("CoinIcon").gameObject.SetActive(false);
- // The Button scales this resource root; all visible values must share that ancestor.
- Coins = Value("CoinsTMP", rect, 54, 21, 100, 24);
- screen.CoinsLabel.transform.SetParent(rect,false);
- UIBuilder.Place(screen.CoinsLabel.rectTransform, 54, 21, 100, 24);
- screen.CoinsLabel.enabled = !Coins;
- }
- if (art.Tickets)
- {
- var rect = (RectTransform)root.Find("TicketDisplay");
- UIBuilder.Place(rect, 220, 62, 198, 66);
- HideGraphic(rect); Picture("Art", rect, art.Tickets, 0, 0, 198, 66);
- var button = rect.gameObject.AddComponent<UIFeedbackButton>();
- button.targetGraphic = rect.GetComponent<Graphic>(); button.targetGraphic.raycastTarget = true;
- screen.ConfigureTicket(button);
- root.Find("TicketIcon").gameObject.SetActive(false);
- Tickets = Value("TicketsTMP", rect, 54, 21, 100, 24);
- screen.TicketsLabel.transform.SetParent(rect,false);
- UIBuilder.Place(screen.TicketsLabel.rectTransform, 54, 21, 100, 24);
- screen.TicketsLabel.enabled = !Tickets;
- }
- for (int i = 0; i < screen.Cards.Length; i++)
- {
- var card = screen.Cards[i]; var rect = (RectTransform)card.transform;
- UIBuilder.Place(rect, 12 + i * 138, CardTop, CardWidth, CardHeight);
- Sprite sprite = art.Mode(i);
- if (sprite)
- {
- foreach (Transform child in rect) if (child != card.ProgressLabel.transform) child.gameObject.SetActive(false);
- HideGraphic(rect);
- var artwork = Picture("ModeArtwork", rect, sprite, 0, 0, 130, 238);
- if (card.Button is UIFeedbackButton feedback) feedback.EnablePressScale = false;
- // Static rim/title plus real independent animated subject sprites. No click overlay.
- LobbyModeMagic.Install(screen, artwork, i);
- // The former body is hidden; retain the existing button and bind it to the root hit area.
- card.Button.targetGraphic = rect.GetComponent<Graphic>();
- card.Button.targetGraphic.raycastTarget = true;
- }
- else
- {
- // Missing card art: replace overflowing placeholder decoration with compact readable labels.
- foreach (Transform child in rect) if (child != card.ProgressLabel.transform) child.gameObject.SetActive(false);
- UIBuilder.Label("FallbackModeName", rect, UIManager.ModeName(card.Mode), 18, UIBuilder.LightGold, 6, 46, 118, 100);
- card.Button.targetGraphic = rect.GetComponent<Graphic>(); card.Button.targetGraphic.raycastTarget = true;
- }
- var backing = UIBuilder.Fill("ProgressBacking", rect, new Color(.025f,.018f,.045f,.68f),
- new Color(.025f,.018f,.045f,.55f), 1, 243, 128, 42, 5);
- backing.transform.SetAsLastSibling();
- UIBuilder.Place(card.ProgressLabel.rectTransform, 2, 243, 126, 42);
- card.ProgressLabel.fontSize = 13;
- card.ProgressLabel.alignment = TextAnchor.MiddleCenter;
- card.ProgressLabel.horizontalOverflow = HorizontalWrapMode.Overflow;
- card.ProgressLabel.lineSpacing = 1.05f;
- card.ProgressLabel.color = UIBuilder.TextColor;
- var textShadow = card.ProgressLabel.gameObject.AddComponent<Shadow>();
- textShadow.effectColor = new Color(0,0,0,.65f); textShadow.effectDistance = new Vector2(0,-1);
- card.ProgressLabel.transform.SetAsLastSibling();
- }
- var buttons = new[] { screen.DailyButton, screen.WheelButton, screen.ShopButton, screen.ProfileButton, screen.SettingsButton, screen.HelpButton };
- var dockSprite = Resources.Load<Sprite>("LobbyNavigation/DockFade");
- if (dockSprite) {
- var dock = Picture("NavigationDockFade", root, dockSprite, 0, 796, 430, 136);
- dock.preserveAspect = false;
- dock.rectTransform.anchorMin = Vector2.zero; dock.rectTransform.anchorMax = Vector2.right;
- dock.rectTransform.pivot = new Vector2(.5f, 0); dock.rectTransform.anchoredPosition = Vector2.zero;
- dock.rectTransform.sizeDelta = new Vector2(0, 136);
- dock.transform.SetSiblingIndex(buttons[0].transform.GetSiblingIndex());
- }
- var navigationNames = new[] { "Daily", "Wheel", "Shop", "Profile", "Settings", "Help" };
- var plate = Resources.Load<Sprite>("LobbyNavigation/ButtonFace");
- for (int i = 0; i < buttons.Length; i++)
- {
- var button = buttons[i]; var rect = (RectTransform)button.transform;
- UIBuilder.Place(rect, 14 + i * 68, 836, 62, 80);
- // Keep the existing root raycast and Button, but render one static native plate.
- var border = rect.GetComponent<RoundedPanel>(); border.Radius = 12;
- HideGraphic(rect); border.raycastTarget = true;
- Image face;
- if (plate) {
- face = Picture("NavigationFace", rect, plate, 1, 1, 60, 78);
- face.type = Image.Type.Sliced; face.preserveAspect = false; face.pixelsPerUnitMultiplier = 2;
- } else {
- face = UIBuilder.Rect("NavigationFace", rect, 1, 1, 60, 78).gameObject.AddComponent<Image>();
- face.sprite = Resources.Load<Sprite>("ProfileProgressCapsule"); face.type = Image.Type.Sliced;
- face.pixelsPerUnitMultiplier = 4; face.color = UIBuilder.Hex("24172F"); face.raycastTarget = false;
- }
- face.transform.SetAsFirstSibling(); button.targetGraphic = face;
- button.transition = Selectable.Transition.ColorTint;
- var colors = button.colors;
- colors.normalColor = colors.highlightedColor = colors.selectedColor = Color.white;
- colors.pressedColor = new Color(.78f, .72f, .85f, 1);
- colors.disabledColor = new Color(.42f, .40f, .48f, 1); colors.fadeDuration = 0;
- colors.colorMultiplier = 1; button.colors = colors;
- // Derived from the existing painted glyphs; source PNGs/catalog references stay intact.
- var sprite = Resources.Load<Sprite>("LobbyNavigation/" + navigationNames[i]);
- if (!sprite) sprite = i == 5 ? art.HelpIcon : art.Navigation(i);
- if (sprite) Picture("NavigationArtwork", rect, sprite, 9, 4, 44, 44);
- else UIBuilder.Label("NavigationFallback", rect, i == 5 ? "?" : navigationNames[i].Substring(0,1), 24,
- UIBuilder.LightGold, 9, 4, 44, 44);
- // Captions have their own clear row, never cover any part of the icon.
- var label = rect.Find("Label").GetComponent<Text>();
- UIBuilder.Place(label.rectTransform, 2, 54, 58, 20);
- label.color = UIBuilder.Hex("EAD7AB"); label.fontSize = 10; label.alignment = TextAnchor.MiddleCenter;
- label.horizontalOverflow = HorizontalWrapMode.Overflow;
- label.transform.SetAsLastSibling();
- }
- screen.ConfigureArtValues(Coins, Tickets);
- }
- public static Image Picture(string name, Transform parent, Sprite sprite, float x, float y, float width, float height)
- {
- if (!sprite) return null;
- var image = UIBuilder.Rect(name, parent, x, y, width, height).gameObject.AddComponent<Image>();
- image.sprite = sprite; image.preserveAspect = true; image.raycastTarget = false; image.color = Color.white;
- return image;
- }
- private static void HideGraphic(RectTransform rect)
- {
- // Preserve the original target and its raycasts for prefab/test compatibility.
- var graphic = rect.GetComponent<Graphic>(); if (graphic) graphic.color = Color.clear;
- var gradient = rect.GetComponent<UIGradient>(); if (gradient) gradient.enabled = false;
- var shadow = rect.GetComponent<Shadow>(); if (shadow) shadow.enabled = false;
- }
- private static TextMeshProUGUI Value(string name, Transform parent, float x, float y, float w, float h)
- {
- var font = Resources.Load<TMP_FontAsset>("Fonts & Materials/LiberationSans SDF");
- if (!font) return null;
- var rect = UIBuilder.Rect(name, parent, x, y, w, h);
- var text = rect.gameObject.AddComponent<TextMeshProUGUI>();
- text.font = font;
- text.fontSize = 18; text.fontStyle = FontStyles.Bold; text.color = UIBuilder.LightGold;
- text.alignment = TextAlignmentOptions.MidlineRight; text.enableAutoSizing = true;
- text.fontSizeMin = 8; text.fontSizeMax = 18; text.raycastTarget = false;
- text.textWrappingMode = TextWrappingModes.NoWrap; text.overflowMode = TextOverflowModes.Truncate;
- return text;
- }
- }
- }
|