using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.UI; namespace DevilLink2.UI { public enum PopupSize { Large, Compact } public static class PopupSizeSpecification { public const float LargeWidth=.94f,LargeMaxHeight=.88f,CompactWidth=.84f,CompactMaxHeight=.82f; } public enum PopupKind { Daily, Wheel, Shop, Profile, Settings, Help, Pause, Result } // Layout only. Moves original bound objects, never clones controls or modifies player state. public sealed class PopupLayout : MonoBehaviour { private sealed class Block { public RectTransform Rect; public float Height,Width; public bool Flexible; } private readonly List body=new List(),footer=new List(); private RectTransform card,viewport,content,foot;private ScrollRect scroll;private PopupHeader header; private Text feedback;private bool detachedFeedback;private Vector2 feedbackSize; private PopupKind kind;private bool ready;private int signature;private Rect lastSafe; public PopupSize Size => kind==PopupKind.Daily||kind==PopupKind.Wheel||kind==PopupKind.Shop||kind==PopupKind.Help?PopupSize.Large:PopupSize.Compact; public Vector2 CurrentSize => card?card.rect.size:Vector2.zero; public bool IsBodyScrollable => scroll && scroll.vertical; public static void Install(RectTransform panel,Text title,Button close,PopupKind kind) { if(panel.GetComponent())return; var prefab=Resources.Load("PopupHeader_Common"); if(!prefab || !prefab.GetComponent()){Debug.LogError("PopupHeader_Common prefab is missing; popup left unchanged.");return;} var layout=panel.gameObject.AddComponent();layout.card=panel;layout.kind=kind; foreach(var old in panel.GetComponentsInChildren(true).Where(i=>i.name=="TitleIcon"))old.gameObject.SetActive(false); layout.header=Instantiate(prefab,panel,false).GetComponent();layout.header.name="PopupHeader_Common";layout.header.Bind(title,close); if(kind!=PopupKind.Daily)layout.BuildBody(); layout.ready=true;layout.Apply(); } private RectTransform Named(string name) { return card.GetComponentsInChildren(true).FirstOrDefault(r=>r.name==name); } private void Add(string name,bool buttons=false) { var r=Named(name);if(!r)return; var item=new Block{Rect=r,Height=r.rect.height,Width=r.rect.width,Flexible=r.GetComponent() || r.GetComponent