using UnityEngine; using UnityEngine.UI; namespace DevilLink2.UI { // Shop-only composition. Keeps all original bound texts, Buttons and purchase listeners. public sealed class ShopProductVisuals : MonoBehaviour { private ShopScreen shop;private RectTransform items,balance;private ShopTab lastTab;private bool styled; private float lastWidth=-1,lastBalanceWidth=-1;private string lastBalanceText;private RectTransform balanceHeader; public static void Install(ShopScreen shop,LobbyArtCatalog shared) { if(shop.GetComponent())return; var view=shop.gameObject.AddComponent();view.shop=shop; view.items=(RectTransform)shop.BuyButtons[0].transform.parent.parent; var text=shop.CoinsLabel;var r=text.rectTransform;var pos=r.anchoredPosition;var size=r.sizeDelta; // Keep the original economic text binding; Shop alone moves this group into its header. view.balance=UIBuilder.Rect("Balance",r.parent,pos.x,-pos.y,size.x,size.y); text.name="BalanceValue";r.SetParent(view.balance,false); var icon=LobbyArtView.Picture("ShopCoin",view.balance,shared?shared.CoinIcon:null,0,6,20,20); if(icon){var ir=icon.rectTransform;ir.anchorMin=ir.anchorMax=ir.pivot=new Vector2(1,1);ir.anchoredPosition=new Vector2(-144,-3);} r.anchorMin=r.anchorMax=r.pivot=new Vector2(1,1);r.anchoredPosition=Vector2.zero;r.sizeDelta=new Vector2(136,32); text.fontSize=14;text.fontStyle=FontStyle.Bold;text.color=UIBuilder.LightGold;text.alignment=TextAnchor.MiddleLeft; text.resizeTextForBestFit=true;text.resizeTextMinSize=8;text.resizeTextMaxSize=14; text.raycastTarget=false;if(icon)icon.raycastTarget=false; view.balance.gameObject.AddComponent(); for(int i=0;i<3;i++){ var card=shop.BuyButtons[i].transform.parent; var gradient=card.GetComponent();if(gradient){gradient.Top=UIBuilder.Hex("352440");gradient.Bottom=UIBuilder.Hex("1D142C");card.GetComponent().SetVerticesDirty();} var trim=UIBuilder.Rect("ShopCardTrim",card,0,0,370,140);trim.anchorMin=Vector2.zero;trim.anchorMax=Vector2.one;trim.offsetMin=trim.offsetMax=Vector2.zero; trim.gameObject.AddComponent();trim.gameObject.AddComponent().raycastTarget=false; var name=card.Find("Name").GetComponent();name.fontSize=14;name.fontStyle=FontStyle.Bold;name.color=UIBuilder.LightGold; var desc=card.Find("Description").GetComponent();desc.fontSize=11;desc.color=UIBuilder.Hex("C6B8D4");desc.horizontalOverflow=HorizontalWrapMode.Wrap; shop.StockLabels[i].color=UIBuilder.Hex("AB9BB9");shop.PriceLabels[i].color=UIBuilder.Hex("F1CB85");shop.PriceLabels[i].fontStyle=FontStyle.Bold; var buy=shop.BuyButtons[i];var colors=buy.colors;colors.highlightedColor=colors.selectedColor=colors.normalColor;buy.colors=colors; // Existing SpriteSwap already maps hover/selected to Normal; do not replace its gold frame. } foreach(var tab in new[]{shop.ItemsButton,shop.RecordsButton}){ var colors=tab.colors;colors.normalColor=colors.highlightedColor=colors.selectedColor=colors.disabledColor=Color.white;colors.fadeDuration=0;tab.colors=colors; } UIBuilder.Place((RectTransform)shop.ItemsButton.transform,18,104,179,46); UIBuilder.Place((RectTransform)shop.RecordsButton.transform,209,104,179,46); view.Layout();view.LayoutBalance();view.StyleTabs(); } private void LateUpdate(){if(!shop)return;Layout();LayoutBalance();if(!styled || lastTab!=shop.CurrentTab)StyleTabs();} private void Layout() { float width=Mathf.Min(370,((RectTransform)items.parent).rect.width);if(width<250 || Mathf.Approximately(lastWidth,width))return;lastWidth=width; items.sizeDelta=new Vector2(width,items.sizeDelta.y); for(int i=0;i<3;i++){ var card=(RectTransform)shop.BuyButtons[i].transform.parent;UIBuilder.Place(card,0,i*150,width,140); var icon=card.Find("ProductIcon") as RectTransform;if(icon)LayoutProductIcon(icon,i); UIBuilder.Place((RectTransform)card.Find("Name"),76,10,width-90,28); UIBuilder.Place((RectTransform)card.Find("Description"),76,40,width-90,36); UIBuilder.Place(shop.StockLabels[i].rectTransform,14,80,width-154,22); UIBuilder.Place(shop.PriceLabels[i].rectTransform,14,106,width-154,24); UIBuilder.Place((RectTransform)shop.BuyButtons[i].transform,width-126,82,112,46); } } private void LayoutBalance() { if(!balanceHeader){ var header=shop.GetComponentInChildren(true);if(!header)return; balanceHeader=(RectTransform)header.transform;balance.SetParent(balanceHeader,false); } // Reserve the centered title and corner ornaments independently of amount length. float width=Mathf.Max(1,balanceHeader.rect.width*.5f-80); UIBuilder.Place(balance,32,10,width,32); var value=shop.CoinsLabel; if(lastBalanceText==value.text && Mathf.Approximately(lastBalanceWidth,width))return; lastBalanceText=value.text;lastBalanceWidth=width; float amountWidth=Mathf.Min(Mathf.Ceil(value.preferredWidth)+2,Mathf.Max(1,width-26)); UIBuilder.Place(value.rectTransform,26,4,amountWidth,24); var icon=balance.Find("ShopCoin") as RectTransform; if(icon)UIBuilder.Place(icon,0,6,20,20); } // Alpha>=16 bounds measured from the three existing PNGs; positions use top-left image coordinates. private static readonly Rect[] ProductBounds={ new Rect(6f/250,9f/214,239f/250,201f/214), new Rect(5f/219,5f/176,210f/219,167f/176), new Rect(6f/178,6f/239,168f/178,228f/239)}; private static readonly float[] ProductExtent={40,42,45.5f}; private static void LayoutProductIcon(RectTransform rect,int index) { var image=rect.GetComponent(); if(!image || !image.sprite){UIBuilder.Place(rect,14,12,48,48);return;} var bounds=ProductBounds[index];var size=image.sprite.rect.size; float scale=ProductExtent[index]/Mathf.Max(bounds.width*size.x,bounds.height*size.y); float w=size.x*scale,h=size.y*scale; // Common 48x48 logical region (14,12); align the visible bounds center, not transparent padding. UIBuilder.Place(rect,38-bounds.center.x*w,36-bounds.center.y*h,w,h); image.preserveAspect=true; } private void StyleTabs() { lastTab=shop.CurrentTab;styled=true; foreach(var tab in new[]{shop.ItemsButton,shop.RecordsButton}){ bool selected=tab==shop.ItemsButton?lastTab==ShopTab.Items:lastTab==ShopTab.CoinRecords; var g=tab.GetComponent();if(g){g.Top=UIBuilder.Hex(selected?"50305C":"241C30");g.Bottom=UIBuilder.Hex(selected?"30203E":"191321");tab.GetComponent().SetVerticesDirty();} var label=tab.GetComponentInChildren(true);label.color=UIBuilder.Hex(selected?"F3D391":"AA9CB9");label.fontStyle=selected?FontStyle.Bold:FontStyle.Normal; } } } [RequireComponent(typeof(CanvasRenderer))] internal sealed class ShopCardTrim : MaskableGraphic { protected override void OnPopulateMesh(VertexHelper mesh) { mesh.Clear();var r=GetPixelAdjustedRect();var gold=UIBuilder.Hex("79603F");const int steps=8;const float radius=12,thickness=.8f; for(int corner=0;corner<4;corner++){ var c=new Vector2(corner==0||corner==3?r.xMax-radius-1:r.xMin+radius+1,corner<2?r.yMax-radius-1:r.yMin+radius+1); for(int i=0;i