using System.Globalization; using UnityEngine; using UnityEngine.UI; using DevilLink2.Gameplay; namespace DevilLink2.UI { // Wheel-only art direction, reading existing UI-bound values; no reward or ticket mutations. public sealed class WheelVisualDesign : MonoBehaviour { private const float WheelRadius=160,IconRadius=WheelRadius*.7125f,TextRadius=WheelRadius*.5f; private RectTransform[] inventoryIcons;private Text[] inventoryNames; private LuckyWheelScreen screen;private Text[] inventory; public static void Install(LuckyWheelScreen screen,GameplayArtCatalog art,LobbyArtCatalog shared) { if(screen.GetComponent())return; var view=screen.gameObject.AddComponent();view.screen=screen;view.inventory=new Text[3];view.inventoryIcons=new RectTransform[3];view.inventoryNames=new Text[3]; var face=screen.Wheel.parent; var oldRim=face.Find("GoldRim");if(oldRim)oldRim.gameObject.SetActive(false); var cluster=UIBuilder.Rect("WheelDesignCluster",face,0,0,340,354); screen.Wheel.SetParent(cluster,false);UIBuilder.Place(screen.Wheel,10,22,320,320); screen.Wheel.pivot=new Vector2(.5f,.5f);screen.Wheel.anchoredPosition+=new Vector2(160,-160); for(int i=0;i<8;i++){ var reward=RewardCatalog.Wheel(i+1);float angle=LuckyWheelScreen.SectorAngle(i+1); var group=UIBuilder.Rect("RewardGroup"+(i+1),screen.Wheel,WheelRadius,WheelRadius,0,0); group.pivot=new Vector2(.5f,.5f);group.localRotation=Quaternion.Euler(0,0,-angle); var label=screen.SectorLabels[i];label.transform.SetParent(group,false); CenterChild(label.rectTransform,new Vector2(0,TextRadius),new Vector2(54,26)); label.horizontalOverflow=HorizontalWrapMode.Overflow;label.verticalOverflow=VerticalWrapMode.Overflow; label.fontSize=11;label.fontStyle=FontStyle.Bold;label.supportRichText=true;label.color=UIBuilder.Hex("F5E9D0"); string primary=reward.Kind==RewardKind.Coins?reward.Amount.ToString("N0",CultureInfo.InvariantCulture):reward.Kind.ToString().ToUpperInvariant(); string secondary=reward.Kind==RewardKind.Coins?"COINS":reward.Kind==RewardKind.Time?"+30s":"x"+reward.Amount; label.text=""+primary+"\n"+secondary+""; var icon=screen.Wheel.Find("SectorIcon"+(i+1)); if(icon){icon.SetParent(group,false);CenterChild((RectTransform)icon,new Vector2(0,IconRadius),new Vector2(26,26));} var divider=screen.Wheel.Find("SectorDivider"+i);if(divider)divider.gameObject.SetActive(false); float edge=i*45*Mathf.Deg2Rad; if(shared && shared.PointerGem)LobbyArtView.Picture("RimGem"+i,screen.Wheel,shared.PointerGem,156+Mathf.Sin(edge)*153,155-Mathf.Cos(edge)*153,8,10); } var arrow=face.Find("FixedPointer");if(arrow)arrow.gameObject.SetActive(false); var gem=face.Find("PointerGem");if(gem){gem.SetParent(cluster,false);UIBuilder.Place((RectTransform)gem,163,3,14,19);} var pointer=UIBuilder.Rect("WheelPointerMetal",cluster,142,-14,56,52).gameObject; pointer.AddComponent();pointer.AddComponent().raycastTarget=false; if(gem)gem.gameObject.SetActive(false); // The shield now contains its own faceted jewel. var spin=screen.SpinButton; if(spin is UIFeedbackButton feedbackButton)feedbackButton.PreserveAppearanceDuringModalLock=true;spin.transform.SetParent(cluster,false);UIBuilder.Place((RectTransform)spin.transform,130,142,80,80); // Single-layer diagnostic design: the root is the purple face; no inset or gold backing. var rim=spin.GetComponent();rim.Radius=40;rim.color=Color.white; var gradient=spin.GetComponent();if(gradient){gradient.enabled=false;} spin.gameObject.AddComponent(); spin.targetGraphic=rim;spin.transition=Selectable.Transition.None; // Cancel a possible inherited ColorTint tween and restore neutral renderer tint once. rim.CrossFadeColor(Color.white,0,true,true); var ornament=UIBuilder.Rect("SpinOrnament",spin.transform,-8,-8,96,96); ornament.gameObject.AddComponent();ornament.gameObject.AddComponent().raycastTarget=false; var text=spin.GetComponentInChildren();UIBuilder.Place(text.rectTransform,0,0,80,80);text.fontSize=18;text.color=UIBuilder.LightGold;text.transform.SetAsLastSibling(); UIBuilder.Place(screen.StatusLabel.rectTransform,12,64,340,26);screen.StatusLabel.fontSize=12; // One shared information bar, not three independent product cards. // Preserve the measurement slot; the compact backing sits naturally inside it. var balances=UIBuilder.Rect("WheelInventory",face,0,0,340,60); UIBuilder.Fill("InventoryBacking",balances,UIBuilder.Hex("392442"),UIBuilder.Hex("1D142B"),0,3,340,54,10); var sprites=new[]{art?art.Hint:null,art?art.Shuffle:null,art?art.Time:null}; for(int i=0;i<3;i++){ float width=340f/3; var column=UIBuilder.Rect("InventoryColumn"+i,balances,i*width,0,width,60); var image=LobbyArtView.Picture("InventoryIcon"+i,column,sprites[i],0,18,24,24); view.inventoryIcons[i]=image?image.rectTransform:null; view.inventory[i]=UIBuilder.Label("InventoryValue"+i,column,"",14,UIBuilder.Hex("F5E9D0"),0,26,40,22,TextAnchor.MiddleLeft); view.inventory[i].horizontalOverflow=HorizontalWrapMode.Overflow;view.inventory[i].verticalOverflow=VerticalWrapMode.Overflow; var name=UIBuilder.Label("InventoryName"+i,column,new[]{"HINT","SHUFFLE","TIME"}[i],9,UIBuilder.Hex("B5A0BF"),0,11,width,13);view.inventoryNames[i]=name; name.horizontalOverflow=HorizontalWrapMode.Overflow; } // Keep the bound source label for Refresh and other existing consumers, without duplicate drawing. screen.BalanceLabel.enabled=false; UIBuilder.Place(screen.FeedbackLabel.rectTransform,18,508,340,28);screen.FeedbackLabel.fontSize=15;screen.FeedbackLabel.fontStyle=FontStyle.Bold;screen.FeedbackLabel.alignment=TextAnchor.MiddleCenter;screen.FeedbackLabel.color=UIBuilder.Hex("E2BC75"); var note=face.Find("Note") as RectTransform;if(note){UIBuilder.Place(note,12,618,340,18);var label=note.GetComponent();label.fontSize=9;label.color=UIBuilder.Hex("8F7D9B");} view.SyncInventory();view.RefreshLabelFacing();view.StyleFeedback(); } private string lastBalance,lastFeedback; private void LateUpdate(){if(!screen)return;SyncInventory();RefreshLabelFacing();StyleFeedback();} private void StyleFeedback() { var label=screen.FeedbackLabel;if(lastFeedback==label.text)return;lastFeedback=label.text; // Preserve the fixed 28px slot: normal prompts get +25%; long error text keeps its old size. var settings=label.GetGenerationSettings(Vector2.zero);settings.fontSize=15;settings.resizeTextForBestFit=false;settings.horizontalOverflow=HorizontalWrapMode.Overflow; float width=label.cachedTextGeneratorForLayout.GetPreferredWidth(label.text,settings)/label.pixelsPerUnit; label.fontSize=width<=label.rectTransform.rect.width?15:12; } private void SyncInventory() { if(lastBalance==screen.BalanceLabel.text)return;lastBalance=screen.BalanceLabel.text; var values=lastBalance.Split('|'); for(int i=0;i=0?token.Substring(split+1):"—";LayoutInventory(i);} } private void LayoutInventory(int index) { var value=inventory[index];float width=((RectTransform)value.transform.parent).rect.width; float numberWidth=Mathf.Max(10,Mathf.Ceil(Mathf.Max(value.preferredWidth,inventoryNames[index].preferredWidth))+2); float left=(width-(24+6+numberWidth))*.5f; if(inventoryIcons[index])UIBuilder.Place(inventoryIcons[index],left,18,24,24); UIBuilder.Place(value.rectTransform,left+30,26,numberWidth,22); UIBuilder.Place(inventoryNames[index].rectTransform,left+30,11,numberWidth,13);inventoryNames[index].alignment=TextAnchor.MiddleLeft; } private static void CenterChild(RectTransform child,Vector2 position,Vector2 size) { child.anchorMin=child.anchorMax=new Vector2(.5f,.5f);child.pivot=new Vector2(.5f,.5f); child.anchoredPosition=position;child.sizeDelta=size;child.localRotation=Quaternion.identity;child.localScale=Vector3.one; } public const float ReadingCorrectionSeconds=.18f; private float lastSettledAngle=float.NaN,correctionElapsed; private RewardResult lastFacingResult; private bool correctionActive; private readonly float[] correctionFrom=new float[8],correctionTo=new float[8]; public void PrepareForSpin() { // Called synchronously after service success, before the wheel animation starts moving. correctionActive=false;correctionElapsed=0;lastSettledAngle=float.NaN;lastFacingResult=null; if(!screen || screen.SectorLabels==null)return; for(int i=0;i90.1f?180:0; } // Initial hidden construction is composed directly; every completed spin is eased. correctionActive=screen.LastResult!=null; ApplyTextFacing(correctionActive?0:1);return; } if(!correctionActive)return; correctionElapsed=Mathf.Min(ReadingCorrectionSeconds,correctionElapsed+Time.unscaledDeltaTime); float t=correctionElapsed/ReadingCorrectionSeconds; ApplyTextFacing(t*t*(3-2*t)); if(t>=1)correctionActive=false; } private void ApplyTextFacing(float progress) { for(int i=0;i<8;i++)screen.SectorLabels[i].rectTransform.localRotation=Quaternion.Euler(0,0,Mathf.LerpAngle(correctionFrom[i],correctionTo[i],progress)); } private void OnDisable() { // No delayed callbacks survive closing/rebinding; reopening measures the current labels anew. correctionActive=false;correctionElapsed=0;lastSettledAngle=float.NaN;lastFacingResult=null; } } [RequireComponent(typeof(CanvasRenderer))] internal sealed class WheelPointerGraphic : Image { protected override void OnEnable() { base.OnEnable();sprite=Resources.Load("WheelOrnaments/Wheel_Pointer_Ornate_R12") ?? Resources.Load("WheelOrnaments/Wheel_Pointer_Ornate"); preserveAspect=true;raycastTarget=false; } protected override void OnPopulateMesh(VertexHelper mesh) { if(sprite){base.OnPopulateMesh(mesh);return;} WheelDecorationMesh.Pointer(mesh,GetPixelAdjustedRect()); } } }