| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using TMPro;
- using UnityEngine;
- using UnityEngine.UI;
- namespace DevilLink2.UI
- {
- // Instantiated from the one common prefab; keeps original bound title/button objects.
- public sealed class PopupHeader : MonoBehaviour
- {
- private Text title;private Button close;private bool bound;
- public void Bind(Text source,Button button)
- {
- if(bound)return;bound=true;title=source;close=button;
- var slot=(RectTransform)transform.Find("TitleText");
- var template=slot.GetComponent<Text>();
- source.transform.SetParent(slot,false);source.font=template && template.font?template.font:Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
- source.fontSize=template?template.fontSize:20;source.fontStyle=FontStyle.Bold;source.color=template?template.color:UIBuilder.LightGold;source.alignment=TextAnchor.MiddleCenter;
- if(template)template.enabled=false;
- source.resizeTextForBestFit=false;source.raycastTarget=false;
- var ornament=transform.Find("TitleOrnament");
- var art=UIArtResources.Catalog;
- var gem=ornament.Find("CenterGem").GetComponent<Image>();if(!gem)gem=ornament.Find("CenterGem").gameObject.AddComponent<Image>();gem.sprite=art?art.PointerGem:null;gem.preserveAspect=true;gem.raycastTarget=false;
- if(!gem.sprite)gem.color=UIBuilder.Hex("B67CD3");
- foreach(var name in new[]{"GoldLine_Left","GoldLine_Right"}){
- var line=ornament.Find(name).GetComponent<Image>();if(!line)line=ornament.Find(name).gameObject.AddComponent<Image>();line.color=new Color(.72f,.56f,.30f,.65f);line.raycastTarget=false;
- }
- var closeSlot=(RectTransform)transform.Find("CloseButtonRoot");closeSlot.gameObject.SetActive(button);
- if(button){
- button.transform.SetParent(closeSlot,false);
- foreach(var graphic in button.GetComponentsInChildren<Graphic>(true))graphic.enabled=false;
- var surface=button.GetComponent<Image>();surface.enabled=true;surface.color=Color.clear;surface.raycastTarget=true;
- var gradient=button.GetComponent<UIGradient>();if(gradient)gradient.enabled=false;
- var shadow=button.GetComponent<Shadow>();if(shadow)shadow.enabled=false;
- var rim=UIBuilder.Fill("CommonCloseRim",button.transform,UIBuilder.Hex("8E7449"),UIBuilder.Hex("5B442E"),6,6,32,32,16);
- var face=UIBuilder.Fill("CommonCloseFace",button.transform,UIBuilder.Hex("392443"),UIBuilder.Hex("21142F"),7,7,30,30,15);
- rim.raycastTarget=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.pressedColor=new Color(.63f,.52f,.72f);colors.disabledColor=new Color(.42f,.4f,.46f,.7f);colors.fadeDuration=.08f;button.colors=colors;
- var mark=UIBuilder.Rect("CommonCloseX",button.transform,0,0,44,44).gameObject.AddComponent<TextMeshProUGUI>();
- mark.font=Resources.Load<TMP_FontAsset>("Fonts & Materials/LiberationSans SDF");mark.text="X";mark.fontSize=18;mark.fontStyle=FontStyles.Bold;mark.color=UIBuilder.LightGold;mark.alignment=TextAlignmentOptions.Center;mark.raycastTarget=false;
- }
- Resize(((RectTransform)transform.parent).rect.width);
- }
- public void Resize(float width)
- {
- UIBuilder.Place((RectTransform)transform,0,44,width,64);
- var slot=(RectTransform)transform.Find("TitleText");UIBuilder.Place(slot,68,-4,width-136,48);
- if(title)UIBuilder.Place(title.rectTransform,0,0,width-136,48);
- var ornament=(RectTransform)transform.Find("TitleOrnament");UIBuilder.Place(ornament,(width-116)*.5f,46,116,11);
- UIBuilder.Place((RectTransform)ornament.Find("GoldLine_Left"),0,5,48,1);
- UIBuilder.Place((RectTransform)ornament.Find("CenterGem"),54,0,8,11);
- UIBuilder.Place((RectTransform)ornament.Find("GoldLine_Right"),68,5,48,1);
- UIBuilder.Place((RectTransform)transform.Find("CloseButtonRoot"),width-68,4,44,44);
- if(close)UIBuilder.Place((RectTransform)close.transform,0,0,44,44);
- }
- }
- }
|