| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using TMPro;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Sprites;
- namespace DevilLink2.UI
- {
- // Visual-only composition of the existing two Buttons; never attaches click listeners.
- internal static class DailyButtonVisuals
- {
- internal static void Install(DailyCheckInScreen daily, GameplayArtCatalog art)
- {
- if(daily.CloseButton.transform.Find("DailyCloseFace"))return;
- var font=Resources.Load<TMP_FontAsset>("Fonts & Materials/LiberationSans SDF");
- // Missing font leaves the original legible labels intact.
- StyleClose(daily.CloseButton);
- if(art && art.Normal)
- {
- var rect=(RectTransform)daily.ClaimButton.transform;
- var graphic=UIBuilder.Rect("DailyClaimArtwork",rect,0,0,rect.rect.width,rect.rect.height).gameObject.AddComponent<DailyClaimImage>();
- graphic.sprite=art.Normal;graphic.raycastTarget=false;graphic.color=Color.white;
- graphic.transform.SetAsFirstSibling();
- var gradient=rect.GetComponent<UIGradient>();if(gradient)gradient.enabled=false;
- var shadow=rect.GetComponent<Shadow>();if(shadow)shadow.enabled=false;
- rect.GetComponent<Image>().color=Color.clear; // Original raycast surface remains enabled.
- daily.ClaimButton.targetGraphic=graphic;daily.ClaimButton.transition=Selectable.Transition.SpriteSwap;
- daily.ClaimButton.spriteState=new SpriteState{highlightedSprite=art.Normal,selectedSprite=art.Normal,pressedSprite=art.Pressed?art.Pressed:art.Normal,disabledSprite=art.Disabled?art.Disabled:art.Normal};
- }
- Label(daily.CloseButton,"X",18,font);
- Label(daily.ClaimButton,"CLAIM",18,font);
- }
- private static void StyleClose(Button button)
- {
- var rect=(RectTransform)button.transform;
- // Keep the 46x44 raycast surface; paint only a centered 32px circular control.
- var edge=rect.GetComponent<RoundedPanel>();edge.color=Color.clear;
- var gradient=rect.GetComponent<UIGradient>();if(gradient)gradient.enabled=false;
- var shadow=rect.GetComponent<Shadow>();if(shadow)shadow.enabled=false;
- var rim=UIBuilder.Fill("DailyCloseRim",rect,UIBuilder.Hex("8E7449"),UIBuilder.Hex("5B442E"),7,6,32,32,16);
- rim.transform.SetAsFirstSibling();rim.raycastTarget=false;
- var face=UIBuilder.Fill("DailyCloseFace",rect,UIBuilder.Hex("392443"),UIBuilder.Hex("21142F"),8,7,30,30,15);
- face.transform.SetSiblingIndex(rim.transform.GetSiblingIndex()+1);face.raycastTarget=false;
- button.targetGraphic=face;button.transition=Selectable.Transition.ColorTint;
- var colors=button.colors;colors.normalColor=Color.white;colors.highlightedColor=new Color(1,.93f,.8f);
- colors.selectedColor=colors.normalColor;colors.pressedColor=new Color(.63f,.52f,.72f);
- colors.disabledColor=new Color(.42f,.4f,.46f,.7f);colors.fadeDuration=.08f;button.colors=colors;
- }
- private static void Label(Button button,string value,int size,TMP_FontAsset font)
- {
- var legacy=button.GetComponentInChildren<Text>(true);
- if(!font){if(legacy){legacy.text=value;legacy.color=UIBuilder.LightGold;}return;}
- var rect=(RectTransform)button.transform;
- var label=UIBuilder.Rect("DailyButtonLabel",rect,5,2,rect.rect.width-10,rect.rect.height-4).gameObject.AddComponent<TextMeshProUGUI>();
- label.font=font;label.text=value;label.fontSize=size;label.fontStyle=FontStyles.Bold;
- label.alignment=TextAlignmentOptions.Center;label.color=UIBuilder.LightGold;
- label.textWrappingMode=TextWrappingModes.NoWrap;label.raycastTarget=false;
- if(legacy)legacy.enabled=false;
- }
- }
- // Source-preserving horizontal stretch: fixed ends and central gem, two elastic spans.
- internal sealed class DailyClaimImage : Image
- {
- protected override void OnPopulateMesh(VertexHelper mesh)
- {
- var active=overrideSprite?overrideSprite:sprite;
- if(!active){base.OnPopulateMesh(mesh);return;}
- mesh.Clear();var rect=GetPixelAdjustedRect();var uv=DataUtility.GetOuterUV(active);
- float w=active.rect.width,h=active.rect.height,scale=rect.height/h;
- float edge=w*.2f,center=w*.16f;
- scale=Mathf.Min(scale,rect.width/(edge*2+center));
- float cap=edge*scale,half=center*scale*.5f;
- var xs=new[]{rect.xMin,rect.xMin+cap,rect.center.x-half,rect.center.x+half,rect.xMax-cap,rect.xMax};
- var sx=new[]{0f,.2f,.42f,.58f,.8f,1f};
- for(int i=0;i<5;i++)
- {
- int start=mesh.currentVertCount;
- float left=Mathf.Lerp(uv.x,uv.z,sx[i]),right=Mathf.Lerp(uv.x,uv.z,sx[i+1]);
- mesh.AddVert(new Vector3(xs[i],rect.yMin),color,new Vector2(left,uv.y));
- mesh.AddVert(new Vector3(xs[i],rect.yMax),color,new Vector2(left,uv.w));
- mesh.AddVert(new Vector3(xs[i+1],rect.yMax),color,new Vector2(right,uv.w));
- mesh.AddVert(new Vector3(xs[i+1],rect.yMin),color,new Vector2(right,uv.y));
- mesh.AddTriangle(start,start+1,start+2);mesh.AddTriangle(start,start+2,start+3);
- }
- }
- }
- }
|