DiamondArrowGame.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. using System;
  2. using System.Collections;
  3. using DiamondArrow.Platform;
  4. using UnityEngine;
  5. using UnityEngine.EventSystems;
  6. using UnityEngine.UI;
  7. namespace DiamondArrow
  8. {
  9. public sealed partial class DiamondArrowGame : MonoBehaviour
  10. {
  11. public TextAsset levelData;
  12. public NeonTheme theme;
  13. public HomeLayoutView homeLayout;
  14. public VictoryView victoryLayout;
  15. public LevelBook Book { get; private set; }
  16. public PlayerSave Save { get; private set; }
  17. public GameSession Run { get; private set; }
  18. public string CurrentScreen { get; private set; }
  19. public string CurrentModal { get; private set; }
  20. SaveStore store;
  21. RectTransform canvasRect,root,screen,modal,toastRoot;
  22. Sprite[] icons,avatarSprites;
  23. ArrowBoard board;
  24. Text gemsText,timeText,heartsText,leftText,toastText;
  25. Image heartIcon;int lastHearts=-1;
  26. RectTransform timeFill;
  27. readonly Text[] toolCounts=new Text[3];
  28. readonly Button[] toolButtons=new Button[3];
  29. float toastEnd,readyAt;
  30. bool appPaused,resultScheduled,chestBusy;
  31. int tutorialStep;
  32. RectTransform tutorialBubble;
  33. GameAudio gameAudio;
  34. int lastCountdownSecond=-1;
  35. static readonly Color TileTop = Neon.Hex("#372544");
  36. static readonly Color TileBottom = Neon.Hex("#190E24");
  37. static readonly Color ArmedTop = Neon.Hex("#78365F");
  38. readonly System.Random random=new System.Random();
  39. PlatformServices platform;
  40. Text profileName, chestActionText;
  41. Image profilePortrait;
  42. HomeLayoutView lobby;
  43. VictoryView victory;
  44. Button chestAction;
  45. bool rewardPending;
  46. long lastChestDisplaySecond = -1;
  47. string DisplayName => string.IsNullOrWhiteSpace(platform.PlayerName) ? Save.name : platform.PlayerName;
  48. string Today=>DateTime.Now.ToString("yyyy-MM-dd");
  49. Font Font=>theme.font!=null?theme.font:Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
  50. void Awake()
  51. {
  52. Application.targetFrameRate=60;
  53. #if UNITY_IOS
  54. Screen.orientation=ScreenOrientation.Portrait;
  55. #endif
  56. #if UNITY_EDITOR
  57. Application.runInBackground=true;
  58. #endif
  59. Book=LevelBook.Parse(levelData.text);var issues=Book.Validate();if(issues.Count>0)throw new InvalidOperationException(string.Join("; ",issues));
  60. store=new SaveStore(Application.persistentDataPath);Save=store.Load();
  61. icons=new Sprite[16];float cell=theme.icons.width/4f;
  62. for(int i=0;i<16;i++)icons[i]=Sprite.Create(theme.icons,new Rect(i%4*cell,theme.icons.height-(i/4+1)*cell,cell,cell),new Vector2(.5f,.5f),100);
  63. if(!theme.avatarAtlas)Debug.LogError("Diamond Arrow: avatar atlas is unassigned. Run Diamond Arrow/Refresh avatar portraits.",this);
  64. if(theme.avatarAtlas){avatarSprites=new Sprite[AvatarCatalog.NewCount];float aw=theme.avatarAtlas.width/3f,ah=theme.avatarAtlas.height/2f;for(int i=0;i<avatarSprites.Length;i++)avatarSprites[i]=Sprite.Create(theme.avatarAtlas,new Rect(i%3*aw,theme.avatarAtlas.height-(i/3+1)*ah,aw,ah),new Vector2(.5f,.5f),100);}
  65. BuildCanvas();CreateAudio();ShowLoading();
  66. if (Save.InitializeGuest(random)) Persist();
  67. var services = new GameObject("DiamondServices-" + Guid.NewGuid().ToString("N"));
  68. services.transform.SetParent(transform, false);
  69. platform = services.AddComponent<PlatformServices>();
  70. platform.ProfileChanged += RefreshIdentity;
  71. AppRuntimesEvents.OnPlatformOpen += OnPlatformOpen;
  72. platform.Initialize();
  73. }
  74. void OnDestroy(){AppRuntimesEvents.OnPlatformOpen-=OnPlatformOpen;if(platform)platform.ProfileChanged-=RefreshIdentity;if(icons!=null)foreach(var s in icons)if(s!=null)Destroy(s);if(avatarSprites!=null)foreach(var s in avatarSprites)if(s)Destroy(s);}
  75. void OnPlatformOpen()
  76. {
  77. Save.music = false;
  78. gameAudio.StopMusic();
  79. Persist();
  80. if (CurrentModal == "SETTINGS") ShowSettings();
  81. }
  82. void Update()
  83. {
  84. if (CurrentScreen == "Lobby") RefreshChestControls(DateTimeOffset.Now);
  85. if(toastRoot&&Time.unscaledTime>toastEnd)toastRoot.gameObject.SetActive(false);
  86. if(Run!=null&&CurrentScreen=="Game"&&Run.Status==RunStatus.Playing&&modal==null&&tutorialStep==0&&!appPaused&&Time.unscaledTime>=readyAt)
  87. { Run.Tick(Time.unscaledDeltaTime);UpdateGameHud();CountdownAudio();if(Run.Status!=RunStatus.Playing)ScheduleOutcome(); }
  88. if(!rewardPending && Input.GetKeyDown(KeyCode.Escape)) { if(modal!=null&&!chestBusy&&CurrentModal!="Result"&&CurrentModal!="Fail")CloseModal();else if(CurrentScreen=="Game")ShowQuit(); }
  89. }
  90. void OnApplicationPause(bool paused){appPaused=paused;if(gameAudio)gameAudio.SetSuspended(paused);if(paused)Persist();}
  91. void OnApplicationFocus(bool focused){appPaused=!focused;}
  92. void OnApplicationQuit(){if(Save!=null)Persist();}
  93. void Persist(){if(store==null||Save==null)return;if(!store.Save(Save))Toast("Unable to save progress on this device");}
  94. void BuildCanvas()
  95. {
  96. var go=new GameObject("DiamondArrowCanvas",typeof(RectTransform),typeof(Canvas),typeof(CanvasScaler),typeof(GraphicRaycaster));go.transform.SetParent(transform,false);
  97. var canvas=go.GetComponent<Canvas>();canvas.renderMode=RenderMode.ScreenSpaceCamera;canvas.worldCamera=Camera.main;canvas.planeDistance=10;canvas.sortingOrder=10;canvas.additionalShaderChannels=AdditionalCanvasShaderChannels.TexCoord1|AdditionalCanvasShaderChannels.TexCoord2|AdditionalCanvasShaderChannels.TexCoord3;
  98. var scaler=go.GetComponent<CanvasScaler>();scaler.uiScaleMode=CanvasScaler.ScaleMode.ScaleWithScreenSize;scaler.referenceResolution=new Vector2(750,1334);scaler.matchWidthOrHeight=.5f;
  99. canvasRect=(RectTransform)go.transform;
  100. var backdrop = Node(canvasRect, "Background", 0, 0, 750, 1334);
  101. backdrop.pivot = new Vector2(.5f, .5f);
  102. var image = backdrop.gameObject.AddComponent<Image>();
  103. image.sprite = theme.background;
  104. image.raycastTarget = false;
  105. var aspect = backdrop.gameObject.AddComponent<AspectRatioFitter>();
  106. aspect.aspectRatio = image.sprite.rect.width / image.sprite.rect.height;
  107. aspect.aspectMode = AspectRatioFitter.AspectMode.EnvelopeParent;
  108. root=Node(canvasRect,"SafeArea",0,0,750,1334);root.anchorMin=root.anchorMax=root.pivot=new Vector2(.5f,.5f);root.anchoredPosition=Vector2.zero;
  109. var safe=go.AddComponent<SafeCanvas>();safe.content=root;safe.Apply();
  110. if(EventSystem.current==null)new GameObject("DiamondArrowEventSystem",typeof(EventSystem),typeof(StandaloneInputModule)).transform.SetParent(transform);
  111. toastRoot=Panel(root,"Toast",65,1125,620,70,false);toastRoot.anchorMin=toastRoot.anchorMax=new Vector2(.5f,0);toastRoot.anchoredPosition=new Vector2(-310,209);toastText=Label(toastRoot,"",18,12,584,46,22,Neon.Ice);toastRoot.gameObject.SetActive(false);
  112. }
  113. public void Toast(string message){if(!toastRoot)return;toastText.text=message;toastRoot.gameObject.SetActive(true);toastRoot.SetAsLastSibling();toastEnd=Time.unscaledTime+2.8f;}
  114. void ClearScreen(string name)
  115. {
  116. StopAllCoroutines();CloseModal();if(screen){screen.gameObject.SetActive(false);Destroy(screen.gameObject);}board=null;gemsText=null;tutorialStep=0;tutorialBubble=null;resultScheduled=false;chestBusy=false;
  117. lobby = null;
  118. CurrentScreen=name;if(gameAudio)gameAudio.SetGameplay(name=="Game");screen=Node(root,name,0,0,750,1334);screen.SetAsFirstSibling();
  119. if (name == "Lobby") Stretch(screen);
  120. else Center(screen);
  121. }
  122. static void Stretch(RectTransform rect)
  123. {
  124. rect.anchorMin = Vector2.zero;
  125. rect.anchorMax = Vector2.one;
  126. rect.offsetMin = rect.offsetMax = Vector2.zero;
  127. }
  128. static void Center(RectTransform rect)
  129. {
  130. rect.anchorMin = rect.anchorMax = rect.pivot = new Vector2(.5f, .5f);
  131. rect.anchoredPosition = Vector2.zero;
  132. }
  133. void ShowLoading(){ClearScreen("Loading");Logo(screen,70,360,610,210);Label(screen,"OPENING THE VAULT",100,640,550,40,22,Neon.Ice);var fill=Panel(screen,"Loading bar",120,710,510,12,false);StartCoroutine(Loading(fill));}
  134. IEnumerator Loading(RectTransform bar){for(float t=0;t<1.1f;t+=Time.unscaledDeltaTime){bar.sizeDelta=new Vector2(510*t/1.1f,12);yield return null;}ShowStart();}
  135. public void ShowStart()
  136. {
  137. ClearScreen("Start");
  138. Logo(screen, 60, 368, 630, 216);
  139. Button(screen, "Start playing", 140, 918, 470, 104, "PLAY", () => {
  140. Save.seen = true;
  141. Persist();
  142. ShowLobby();
  143. }, true, 14);
  144. if (store.Warning != null) Toast(store.Warning);
  145. }
  146. Sprite PlayerPortrait()
  147. {
  148. int index = Save.avatar - AvatarCatalog.LegacyCount;
  149. Sprite local = avatarSprites != null && index >= 0 && index < avatarSprites.Length ? avatarSprites[index] : icons[0];
  150. return platform.Portrait ? platform.Portrait : local;
  151. }
  152. static void SetPortrait(RawImage portrait, Sprite sprite)
  153. {
  154. var texture = sprite.texture;
  155. var rect = sprite.rect;
  156. portrait.texture = texture;
  157. portrait.uvRect = new Rect(rect.x / texture.width, rect.y / texture.height,
  158. rect.width / texture.width, rect.height / texture.height);
  159. }
  160. void RefreshIdentity()
  161. {
  162. if (lobby)
  163. {
  164. lobby.nickname.text = DisplayName;
  165. SetPortrait(lobby.portrait, PlayerPortrait());
  166. }
  167. if (profileName) profileName.text = DisplayName;
  168. if (victory)
  169. {
  170. victory.playerName.text = DisplayName;
  171. SetPortrait(victory.portrait, PlayerPortrait());
  172. }
  173. if (profilePortrait) profilePortrait.sprite = PlayerPortrait();
  174. }
  175. Text FittedLabel(Text label)
  176. {
  177. label.supportRichText = false;
  178. label.resizeTextForBestFit = true;
  179. label.resizeTextMinSize = 12;
  180. label.resizeTextMaxSize = label.fontSize;
  181. return label;
  182. }
  183. public void ShowLobby()
  184. {
  185. ClearScreen("Lobby");
  186. Run = null;
  187. lobby = Instantiate(homeLayout, screen, false);
  188. // The persistent canvas backdrop extends beyond the lobby's safe area.
  189. lobby.previewBackground.SetActive(false);
  190. Stretch((RectTransform)lobby.transform);
  191. int number = Save.NextLevel;
  192. var level = Book.GetLevel(number);
  193. lobby.board.Configure(level);
  194. lobby.chapter.text = Book.Chapter(number).ToUpperInvariant();
  195. lobby.levelNumber.text = "LEVEL " + number;
  196. lobby.details.text = level.arrows.Length + " arrows · " + level.size + "×" + level.size + " · " + Clock(level.seconds);
  197. lobby.totalStars.text = Save.TotalStars.ToString();
  198. gemsText = lobby.balance;
  199. gemsText.text = Save.gems.ToString();
  200. RefreshIdentity();
  201. RefreshChestControls(DateTimeOffset.Now, true);
  202. BindAction(lobby.settings, ShowSettings);
  203. BindAction(lobby.diamonds, ShowDiamonds);
  204. BindAction(lobby.dailyChest, ShowChest);
  205. BindAction(lobby.checkIn, ShowCheckin);
  206. BindAction(lobby.shop, ShowShop);
  207. BindAction(lobby.help, ShowHelp);
  208. BindAction(lobby.play, () => StartLevel(number));
  209. }
  210. void BindAction(Button button, Action action)
  211. {
  212. button.onClick.AddListener(() => {
  213. Sound(SoundCue.Tap);
  214. action();
  215. });
  216. }
  217. public void StartLevel(int number)
  218. {
  219. if(!Save.Unlocked(number)){Toast("Clear the previous level first");return;}
  220. ClearScreen("Game");lastCountdownSecond=-1;Run=new GameSession(Book.GetLevel(number));readyAt=Time.unscaledTime+.65f;GameHeader();
  221. Label(screen,"STAGE",36,142,170,30,19,Neon.Muted,TextAnchor.MiddleLeft);Label(screen,number.ToString("00"),34,167,180,66,52,Color.white,TextAnchor.MiddleLeft);
  222. Label(screen,Book.Chapter(number),220,146,490,40,27,Neon.Ice,TextAnchor.MiddleRight);Label(screen,Run.Remaining+" arrows · "+Run.Level.size+"×"+Run.Level.size,260,194,450,30,20,Neon.Muted,TextAnchor.MiddleRight);
  223. timeText=Label(screen,"",32,234,132,42,27,Neon.Ice);var rail=Panel(screen,"Timer rail",180,247,530,13,false);rail.GetComponent<NeonPanel>().top=Neon.Hex("#251235");timeFill=Panel(rail,"Time remaining",0,0,530,13,false);timeFill.GetComponent<NeonPanel>().top=Neon.Ice;timeFill.GetComponent<NeonPanel>().bottom=Neon.Purple;
  224. var frame=Panel(screen,"Puzzle board",30,295,690,690);var viewport=Node(frame,"Arrow viewport",16,16,658,658);viewport.gameObject.AddComponent<RectMask2D>();var ar=Node(viewport,"Arrows",0,0,658,658);board=ar.gameObject.AddComponent<ArrowBoard>();board.Configure(Run.Level,Run);board.clicked=TapArrow;
  225. leftText=Label(screen,"",36,1000,678,42,23,Neon.Ice);
  226. BuildPowerUps();
  227. UpdateGameHud();
  228. if(number==1&&!Save.tutorial){tutorialStep=1;board.TutorialArrow=Run.FreeArrows()[0];TutorialBubble();}
  229. }
  230. void BuildPowerUps()
  231. {
  232. Label(screen, "POWER-UPS", 36, 1058, 678, 30, 18, Neon.Muted, TextAnchor.MiddleLeft);
  233. string[] names = { "Spotlight", "Hammer", "+1 Heart" };
  234. const float gap = 24, width = 214;
  235. for (int i = 0; i < names.Length; i++)
  236. {
  237. int tool = i;
  238. var item = TileButton(screen, names[i], 30 + i * (width + gap), 1104, width, 164, () => UseTool(tool));
  239. toolButtons[i] = item.GetComponent<Button>();
  240. item.gameObject.AddComponent<CanvasGroup>();
  241. Icon(item, 10 + i, 26, 20, 72);
  242. toolCounts[i] = FittedLabel(Label(item, "", 107, 32, 82, 44, 24, Neon.Ice));
  243. Label(item, names[i], 16, 108, width - 32, 40, 24, Color.white);
  244. }
  245. }
  246. RectTransform TileButton(Transform parent, string name, float x, float y, float width, float height, Action action)
  247. {
  248. var item = Button(parent, name, x, y, width, height, "", action, false, false);
  249. var face = item.GetComponent<NeonPanel>();
  250. face.top = TileTop;
  251. face.bottom = TileBottom;
  252. return item;
  253. }
  254. public void TapArrow(int index)
  255. {
  256. if(Run==null||modal!=null||Run.Status!=RunStatus.Playing||Time.unscaledTime<readyAt||tutorialStep>1)return;
  257. if(tutorialStep==1&&index!=board.TutorialArrow){Toast("Tap the gold arrow inside the ring");return;}
  258. int blocker=Run.Blocker(index);bool armed=Run.HammerArmed;var result=Run.Tap(index);
  259. if(result==TapResult.Ignored)return;
  260. if(result==TapResult.Blocked){board.Flash(index,blocker);Sound(SoundCue.Blocked);Buzz();}
  261. else{if(armed){Save.hammer--;Persist();}board.AnimateExit(index,result==TapResult.Smashed);Sound(result==TapResult.Smashed?SoundCue.Hammer:SoundCue.Slide);if(tutorialStep==1){tutorialStep=2;board.TutorialArrow=-1;TutorialBubble();}}
  262. UpdateGameHud();if(Run.Status!=RunStatus.Playing)ScheduleOutcome();
  263. }
  264. void UseTool(int tool)
  265. {
  266. if(Run==null||Run.Status!=RunStatus.Playing||tutorialStep!=0||modal!=null)return;
  267. if(tool==0){if(Save.spotlight<=0){Toast("Out of Spotlight · visit the shop");return;}var free=Run.FreeArrows();if(free.Count==0)return;Save.spotlight--;board.highlight=free[random.Next(free.Count)];board.highlightUntil=Time.unscaledTime+4.2f;Toast("Follow the golden glow");Sound(SoundCue.Hint);}
  268. if(tool==1){if(Save.hammer<=0){Toast("Out of Hammer · visit the shop");return;}Run.HammerArmed=!Run.HammerArmed;Toast(Run.HammerArmed?"Tap an arrow to smash it":"Hammer cancelled");}
  269. if(tool==2){if(Save.heart<=0){Toast("Out of Heart refills · visit the shop");return;}if(!Run.RefillHeart()){Toast("Hearts are full");return;}Save.heart--;Toast("+1 heart");Sound(SoundCue.Heart);}
  270. Persist();UpdateGameHud();
  271. }
  272. void UpdateGameHud()
  273. {
  274. if(Run==null||!timeText)return;timeText.text=Clock(Run.TimeLeft);float ratio=Run.TimeLeft/Run.Level.seconds;timeText.color=ratio<=.16f?Color.red:ratio<=.42f?Neon.Gold:Neon.Ice;timeFill.sizeDelta=new Vector2(530*Mathf.Clamp01(ratio),13);
  275. heartsText.text="× "+Run.Hearts;heartsText.color=Run.Hearts<=1?Neon.Pink:Color.white;if(lastHearts!=Run.Hearts){lastHearts=Run.Hearts;heartIcon.color=Run.Hearts==0?new Color(.6f,.45f,.65f,.5f):Color.white;}leftText.text=Run.Remaining+" LEFT ━ "+Run.Mistakes+" mistakes";
  276. toolCounts[0].text = "× " + Save.spotlight;
  277. toolCounts[1].text = Run.HammerArmed ? "ON" : "× " + Save.hammer;
  278. toolCounts[2].text = "× " + Save.heart;
  279. bool[] available={Save.spotlight>0,Save.hammer>0,Save.heart>0&&Run.Hearts<5};
  280. for(int i=0;i<3;i++)if(toolButtons[i]){toolButtons[i].interactable=available[i];toolButtons[i].GetComponent<CanvasGroup>().alpha=available[i]?1:.38f;}
  281. var hammerFace = toolButtons[1].GetComponent<NeonPanel>();
  282. Color hammerColor = Run.HammerArmed ? ArmedTop : TileTop;
  283. if (hammerFace.top != hammerColor) { hammerFace.top = hammerColor; hammerFace.SetVerticesDirty(); }
  284. }
  285. void ScheduleOutcome(){if(resultScheduled)return;resultScheduled=true;StartCoroutine(Outcome());}
  286. IEnumerator Outcome(){yield return new WaitForSecondsRealtime(.42f);while(board&&board.HasActiveExits)yield return null;yield return new WaitForSecondsRealtime(.1f);if(Run.Status==RunStatus.Cleared)ShowResult();else ShowFail();}
  287. void TutorialBubble()
  288. {
  289. if(tutorialBubble){tutorialBubble.gameObject.SetActive(false);Destroy(tutorialBubble.gameObject);}tutorialBubble=Panel(screen,"Tutorial",50,1050,650,272);
  290. string[] title={"","TAP THE GOLD ARROW","BLOCKED ARROWS COST A HEART","CLEAR THE WHOLE BOARD"};string[] body={"","The ring marks its tip.\nTap anywhere on the gold arrow to slide it out.","Another arrow in the path? You lose a heart.\nYou have three. Look before you tap.","Remove every arrow before time runs out.\nNo mistakes earns three stars."};
  291. Label(tutorialBubble,title[tutorialStep],15,18,620,35,23,Neon.Ice);Label(tutorialBubble,body[tutorialStep],22,67,606,90,22,Color.white);
  292. if(tutorialStep>1)Button(tutorialBubble,"Tutorial next",175,168,300,88,tutorialStep==2?"GOT IT":"START",()=>{if(tutorialStep==2){tutorialStep=3;TutorialBubble();}else{tutorialStep=0;Save.tutorial=true;Persist();tutorialBubble.gameObject.SetActive(false);Destroy(tutorialBubble.gameObject);tutorialBubble=null;readyAt=Time.unscaledTime+.2f;}},true);
  293. }
  294. void GameHeader()
  295. {
  296. var back=Button(screen,"Back",30,38,80,80,"",ShowQuit,false);Icon(back,15,14,14,52);Logo(screen,122,12,418,139);
  297. var health=Panel(screen,"Lives",552,38,168,82);health.GetComponent<NeonPanel>().accent=Neon.Pink;heartIcon=Icon(health,12,5,3,76);heartsText=Label(health,"",78,18,82,46,32,Color.white);lastHearts=-1;
  298. }
  299. static string Clock(float sec){int s=Mathf.CeilToInt(Mathf.Max(0,sec));return s/60+":"+(s%60).ToString("00");}
  300. RectTransform Node(Transform parent,string name,float x,float y,float w,float h)
  301. {
  302. var r=new GameObject(name,typeof(RectTransform)).GetComponent<RectTransform>();r.SetParent(parent,false);r.anchorMin=r.anchorMax=new Vector2(0,1);r.pivot=new Vector2(0,1);r.anchoredPosition=new Vector2(x,-y);r.sizeDelta=new Vector2(w,h);return r;
  303. }
  304. RectTransform Panel(Transform parent,string name,float x,float y,float w,float h,bool frame=true)
  305. {var r=Node(parent,name,x,y,w,h);var p=r.gameObject.AddComponent<NeonPanel>();p.material=theme.surfaceMaterial;p.frame=frame;p.raycastTarget=false;p.top=Neon.Hex("#29163D");p.bottom=Neon.Hex("#0A0514");if(name=="Puzzle board"||name=="Board frame"){p.surface=5;p.accent=Neon.Hex("#9B64D1");}return r;}
  306. Text Label(Transform parent,string content,float x,float y,float w,float h,int size,Color color,TextAnchor alignment=TextAnchor.MiddleCenter)
  307. {
  308. var r=Node(parent,string.IsNullOrEmpty(content)?"Text":content,x,y,w,h);var text=r.gameObject.AddComponent<Text>();text.font=Font;text.text=content;text.fontSize=size;text.fontStyle=FontStyle.Bold;text.color=color;text.alignment=alignment;text.raycastTarget=false;text.horizontalOverflow=HorizontalWrapMode.Wrap;text.verticalOverflow=VerticalWrapMode.Truncate;if(size>=24){var shadow=r.gameObject.AddComponent<Shadow>();shadow.effectColor=new Color(.015f,0,.035f,.6f);shadow.effectDistance=new Vector2(0,-2);}return text;
  309. }
  310. RectTransform Button(Transform parent,string name,float x,float y,float w,float h,string title,Action action,bool primary=false,int icon=-1)
  311. {return MakeButton(parent,name,x,y,w,h,title,action,primary,true,icon);}
  312. RectTransform Button(Transform parent,string name,float x,float y,float w,float h,string title,Action action,bool primary,bool frame)
  313. {return MakeButton(parent,name,x,y,w,h,title,action,primary,frame,-1);}
  314. RectTransform MakeButton(Transform parent,string name,float x,float y,float w,float h,string title,Action action,bool primary,bool frame,int icon)
  315. {
  316. if(frame&&!string.IsNullOrEmpty(title)){h=Mathf.Max(88,h);w=Mathf.Max(88,w);}
  317. var r=Panel(parent,name,x,y,w,h,frame);var graphic=r.GetComponent<NeonPanel>();graphic.raycastTarget=true;graphic.surface=primary?3:4;if(primary){graphic.top=Neon.Hex("#ED259F");graphic.bottom=Neon.Hex("#850057");}else if(!frame){graphic.top=new Color(0,0,0,0);graphic.bottom=graphic.top;}
  318. var b=r.gameObject.AddComponent<UnityEngine.UI.Button>();b.targetGraphic=graphic;r.gameObject.AddComponent<ButtonDepth>();var colors=b.colors;colors.highlightedColor=new Color(1,.9f,1);colors.pressedColor=new Color(.65f,.5f,.75f);b.colors=colors;b.onClick.AddListener(()=>{Sound(SoundCue.Tap);action?.Invoke();});
  319. if(!string.IsNullOrEmpty(title))Label(r,title,icon>=0?42:10,4,w-(icon>=0?58:20),h-8,primary?32:25,Color.white);
  320. if(icon>=0)Icon(r,icon,w*.24f,Mathf.Max(6,(h-36)/2),36);return r;
  321. }
  322. Image Icon(Transform parent,int id,float x,float y,float size,Color? tint=null){var r=Node(parent,"Icon "+id,x,y,size,size);var im=r.gameObject.AddComponent<Image>();im.sprite=icons[id];im.preserveAspect=true;im.color=tint??Color.white;im.raycastTarget=false;return im;}
  323. void Logo(Transform parent,float x,float y,float w,float h){var r=Node(parent,"Logo",x,y,w,h);var im=r.gameObject.AddComponent<Image>();im.sprite=theme.logo;im.preserveAspect=true;im.raycastTarget=false;}
  324. void Rule(Transform parent,float x,float y,float w,Color color,float h=1){var line=Panel(parent,"Etched separator",x,y,w,h,false);var g=line.GetComponent<NeonPanel>();g.radius=0;g.top=new Color(color.r,color.g,color.b,.4f);g.bottom=g.top;}
  325. public void DebugShowLobby(){ShowLobby();}
  326. }
  327. }