HexPanels.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. using System;
  2. using System.Collections;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using HexaCrazy.Ads;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. using TMPro;
  9. namespace HexaCrazy
  10. {
  11. public partial class HexGameApp
  12. {
  13. readonly bool[] faqOpen={true,true,false,false,false,false,false,false,false,false,false};
  14. bool helpShowsFaq;
  15. RectTransform drawWheel;
  16. float drawRestAngle;
  17. TMP_InputField nicknameInput;
  18. Button adButton;
  19. TextMeshProUGUI adLabel;
  20. string readyCaption;
  21. RewardedAdStatus? displayedAdStatus;
  22. public void OpenPanel(string name)
  23. {
  24. if(modal!=null&&currentPanel!=name&&currentPanel!="result")panelHistory.Push(currentPanel);
  25. BuildPanel(name);
  26. }
  27. void Reopen(string name){BuildPanel(name);}
  28. void RemoveModal(){adButton=null;adLabel=null;drawWheel=null;if(modal!=null){modal.gameObject.SetActive(false);Destroy(modal.gameObject);modal=null;}}
  29. public void ClosePanel()
  30. {
  31. if(currentPanel=="result")return;
  32. RemoveModal();currentPanel=null;
  33. if(panelHistory.Count>0){BuildPanel(panelHistory.Pop());return;}
  34. if(ScreenName=="Lobby")ShowLobby();else if(ScreenName=="Game"){DrawDock();UpdateHud();}
  35. }
  36. void CloseAll(){RemoveModal();currentPanel=null;panelHistory.Clear();}
  37. void BuildPanel(string name)
  38. {
  39. RemoveModal();currentPanel=name;modal=Layer("Modal_"+name);modal.SetAsLastSibling();toastLayer.SetAsLastSibling();
  40. var shade=HexUI.Image(modal,"Dimmer",null,375,667,750,1334,new Color(0,0,0,.76f));shade.raycastTarget=true;
  41. string title=name=="draw"?"LUCKY DRAW":name=="checkin"?"CHECK-IN":name=="ledger"?"COIN LEDGER":name=="result"?resultTitle:name.ToUpperInvariant();
  42. switch (name)
  43. {
  44. case "checkin":
  45. int day = Profile.CanCheckin ? Profile.CheckinSlot : Profile.ClaimedCheckinSlot;
  46. FolioHeader(title, "dock_checkin", "DAY " + day + " OF 7"); break;
  47. case "shop": case "draw":
  48. FolioHeader(title, "dock_" + name, Profile.Data.coins.ToString("N0") + " COINS"); break;
  49. case "help": FolioHeader(title, "rulebook", "PLAYER HANDBOOK"); break;
  50. case "profile": FolioHeader(title, "dock_profile", "LOCAL PLAYER · ID " + Profile.Data.id); break;
  51. case "settings": FolioHeader(title, "pref_gear", "HEXA CRAZY 7+ · v1.0"); break;
  52. case "result": FolioBackdrop(); break;
  53. default:
  54. HexUI.Image(modal,"Dialog","card",375,667,700,1100,null,true);
  55. HexUI.Text(modal,"PanelTitle",title,350,208,540,72,46,true);
  56. HexUI.IconButton(modal,"ClosePanel","close",666,205,55,ClosePanel);
  57. HexUI.Image(modal,"PanelRule","ornament",375,259,570,20);
  58. break;
  59. }
  60. switch(name)
  61. {
  62. case "shop":ShopPanel();break;case "ledger":LedgerPanel();break;case "checkin":CheckinPanel();break;case "draw":DrawPanel();break;
  63. case "profile":ProfilePanel();break;case "settings":SettingsPanel();break;case "help":HelpPanel();break;case "pause":PausePanel();break;
  64. case "result":ResultPanel();break;case "reset":ResetPanel();break;
  65. }
  66. }
  67. void FolioBackdrop()
  68. {
  69. HexUI.Image(modal, "FolioBacking", null, 375, 667, 664, 1070, HexUI.ColorOf("220C20"));
  70. HexUI.Image(modal, "Dialog", "folio", 375, 667, 710, 1124);
  71. }
  72. void FolioHeader(string title, string icon, string detail)
  73. {
  74. FolioBackdrop();
  75. HexUI.Image(modal, "PageIcon", icon, 149, 215, 75, 75);
  76. LeftText(modal, "PanelTitle", title, 205, 198, 372, 61, 46, true);
  77. LeftText(modal, "PanelDetail", detail, 208, 243, 368, 30, 20, false, HexUI.Gold);
  78. var close = HexUI.Button(modal, "ClosePanel", "", 611, 214, 68, 68, ClosePanel, null);
  79. close.targetGraphic = HexUI.Image(close.transform, "Icon", "icon_close", 34, 34, 33, 33);
  80. HexUI.Image(modal, "PanelRule", "ornament", 375, 278, 536, 14);
  81. }
  82. static TextMeshProUGUI LeftText(Transform parent, string name, string value, float left, float y,
  83. float width, float height, float size, bool display = false, Color? color = null)
  84. {
  85. var label = HexUI.Text(parent, name, value, left + width / 2, y, width, height, size, display, color);
  86. label.alignment = TextAlignmentOptions.MidlineLeft;
  87. return label;
  88. }
  89. static void Hairline(Transform parent, float x, float y, float width)
  90. {
  91. HexUI.Image(parent, "Rule", null, x, y, width, 1.5f, HexUI.ColorOf("A47B4C99"));
  92. }
  93. RectTransform Content(float height=740,float topInset=0)
  94. {
  95. float h=788-topInset;
  96. var view=HexUI.Node(modal,"ScrollViewport",375,682+topInset/2,620,h);view.gameObject.AddComponent<RectMask2D>();
  97. var touch=view.gameObject.AddComponent<Image>();touch.color=new Color(0,0,0,.001f);touch.raycastTarget=true;
  98. var content=HexUI.Node(view,"Content",310,0,620,Mathf.Max(h,height));content.pivot=new Vector2(.5f,1);content.anchoredPosition=new Vector2(310,0);
  99. var scroll=view.gameObject.AddComponent<ScrollRect>();scroll.viewport=view;scroll.content=content;scroll.horizontal=false;scroll.vertical=height>h;scroll.movementType=ScrollRect.MovementType.Clamped;scroll.scrollSensitivity=35;
  100. return content;
  101. }
  102. void PText(Transform p,string value,float y,float h=55,float size=24,bool title=false){HexUI.Text(p,"Text",value,310,y,580,h,size,title);}
  103. Button Footer(string label,Action action,string second=null,Action other=null)
  104. {
  105. if(second==null)return HexUI.Button(modal,"Footer_"+label,label,375,1144,460,82,action,"primary",34,true);
  106. HexUI.Button(modal,"Footer_"+label,label,215,1144,290,82,action,"panel",28,true);
  107. return HexUI.Button(modal,"Footer_"+second,second,530,1144,290,82,other,"primary",28,true);
  108. }
  109. void BindAdButton(Button button)
  110. {
  111. adButton = button;
  112. adLabel = button.GetComponentInChildren<TextMeshProUGUI>();
  113. readyCaption = adLabel.text;
  114. displayedAdStatus = null;
  115. RefreshAdButton();
  116. }
  117. void RefreshAdButton()
  118. {
  119. if (adButton == null || Ads == null || displayedAdStatus == Ads.Status) return;
  120. var status = Ads.Status;
  121. displayedAdStatus = status;
  122. adButton.interactable = status != RewardedAdStatus.Preparing && status != RewardedAdStatus.Loading;
  123. switch (status)
  124. {
  125. case RewardedAdStatus.Ready: adLabel.text = readyCaption; break;
  126. case RewardedAdStatus.Preparing: adLabel.text = "PREPARING ADS…"; break;
  127. case RewardedAdStatus.Loading: adLabel.text = "LOADING AD…"; break;
  128. case RewardedAdStatus.NetworkError: adLabel.text = "NETWORK ERROR\nRETRY AD"; break;
  129. case RewardedAdStatus.NoFill: adLabel.text = "NO AD AVAILABLE\nRETRY"; break;
  130. case RewardedAdStatus.PrivacyUnavailable: adLabel.text = "PRIVACY CHECK\nRETRY"; break;
  131. default: adLabel.text = "AD LOAD FAILED\nRETRY"; break;
  132. }
  133. }
  134. void ShopPanel()
  135. {
  136. var c = Content();
  137. string[] descriptions = {
  138. "Remove an occupied stack without scoring.",
  139. "Replace the remaining hand with three new groups.",
  140. "Add a group of three. Replaces slot 3 if the hand is full.",
  141. "Open the locked cell with the lowest score threshold."
  142. };
  143. Hairline(c, 310, 391, 558);
  144. HexUI.Image(c, "ShelfDivider", null, 310, 391, 1.5f, 710, HexUI.ColorOf("A47B4C66"));
  145. for (int i = 0; i < descriptions.Length; i++)
  146. {
  147. int item = i;
  148. float x = 160 + i % 2 * 300, y = 14 + i / 2 * 385;
  149. HexUI.Image(c, "ItemIcon", "power_" + HexUI.ItemIcons[i], x, y + 79, 117, 117);
  150. HexUI.Text(c, "ItemName", LevelDatabase.ItemNames[i], x, y + 161, 272, 46, 33, true);
  151. HexUI.Text(c, "Owned", "OWNED " + Profile.Data.items[i], x, y + 200, 260, 27, 18, false, HexUI.Gold);
  152. HexUI.Text(c, "Description", descriptions[i], x, y + 252, 260, 67, 21);
  153. var buy = HexUI.Button(c, "BuyItem_" + i, "BUY · " + LevelDatabase.Prices[i].ToString("N0"),
  154. x, y + 326, 218, 59, () =>
  155. {
  156. if (Profile.Buy(item)) { audioPlayer.Play("coin"); Reopen("shop"); Toast("Purchased " + LevelDatabase.ItemNames[item]); }
  157. else Toast("Need " + (LevelDatabase.Prices[item] - Profile.Data.coins).ToString("N0") + " more coins");
  158. }, "primary", 23);
  159. if(Profile.Data.coins<LevelDatabase.Prices[i])buy.image.color=new Color(.65f,.55f,.6f);
  160. }
  161. Footer("COIN LEDGER",()=>OpenPanel("ledger"));
  162. }
  163. void LedgerPanel()
  164. {
  165. var d=Profile.Data;int count=Math.Min(60,d.ledger.Count);var c=Content(160+count*78);
  166. PText(c,"BALANCE "+d.coins.ToString("N0"),42,62,39,true);
  167. PText(c,"INCOME "+d.earned.ToString("N0")+" · SPENT "+Math.Max(0,d.earned-d.coins).ToString("N0"),102,42,22);
  168. for(int i=0;i<count;i++){var entry=d.ledger[i];float y=176+i*78;HexUI.Image(c,"LedgerRow","panel",310,y,600,70,null,true);HexUI.Text(c,"Source",entry.source+"\n"+entry.time,230,y,430,62,19);HexUI.Text(c,"Amount",(entry.amount>0?"+":"")+entry.amount.ToString("N0"),527,y,135,55,25,false,entry.amount>0?HexUI.Gold:HexUI.ColorOf("FF8092"));}
  169. Footer("BACK",ClosePanel);
  170. }
  171. void CheckinPanel()
  172. {
  173. var c = Content();
  174. bool canClaim = Profile.CanCheckin;
  175. int slot = canClaim ? Profile.CheckinSlot : Profile.ClaimedCheckinSlot;
  176. PText(c, "Rewards advance each day. Missed days are skipped.", 43, 54, 21);
  177. for (int i = 0; i < 6; i++)
  178. {
  179. bool today = i + 1 == slot;
  180. var tile = HexUI.Image(c, "Day_" + (i+1), null, 113 + i % 3 * 197, 206 + i / 3 * 222,
  181. 181, 201, HexUI.ColorOf(today ? "17494C" : "3D1A38"));
  182. HexUI.Image(tile.transform, "TopEdge", null, 90.5f, 1.5f, 181, 3, today ? HexUI.Gold : HexUI.ColorOf("825B59"));
  183. HexUI.Text(tile.transform, "Day", "DAY " + (i+1), 90.5f, 30, 128, 32, 21, false, HexUI.Gold);
  184. string icon = i % 2 == 0 ? "reward_coins" : "power_" + HexUI.ItemIcons[i / 2];
  185. HexUI.Image(tile.transform, "Reward", icon, 90.5f, 100, 77, 77);
  186. HexUI.Text(tile.transform, "Name", LocalProfile.CheckinRewardName(i+1), 90.5f, 165, 173, 36, 22);
  187. if (today && !canClaim) HexUI.Image(tile.transform, "Claimed", "icon_check", 154, 30, 22, 22);
  188. }
  189. var finalDay = HexUI.Image(c, "Day_7", "dock_frame", 310, 659, 598, 180);
  190. HexUI.Image(finalDay.transform, "Reward", "reward_chest", 172, 90, 110, 120);
  191. LeftText(finalDay.transform, "Day", "DAY 7", 261, 57, 210, 36, 23, false, HexUI.Gold);
  192. LeftText(finalDay.transform, "Name", LocalProfile.CheckinRewardName(7), 261, 108, 240, 55, 34, true);
  193. if (slot == 7) HexUI.Image(finalDay.transform, "Today", canClaim ? "coin" : "icon_check", 367, 57, 23, 23);
  194. if (Ads != null && Ads.Supported && Profile.CanClaimCheckinBonus)
  195. {
  196. var profile = Profile;
  197. string date = profile.Data.checkinLast;
  198. BindAdButton(HexUI.Button(modal, "AdCheckin", "WATCH AD · " + LocalProfile.CheckinRewardName(slot), 375,1144,590,82, () =>
  199. {
  200. if (!profile.CanClaimCheckinBonus || profile.Data.checkinLast != date) { Reopen("checkin"); return; }
  201. WatchReward("checkin", () => profile.ClaimCheckinBonus(date), "Extra daily reward claimed");
  202. }, "primary", 29, true));
  203. return;
  204. }
  205. Footer(Profile.CanCheckin?"CLAIM DAY "+slot:"CLAIMED TODAY",()=>{if(Profile.ClaimCheckin()){audioPlayer.Play("coin");Reopen("checkin");Toast("Daily reward claimed");}else Toast("Come back tomorrow");});
  206. }
  207. void DrawPanel()
  208. {
  209. var c = Content();
  210. PText(c, "ONE FREE SPIN EACH DAY", 29, 36, 23);
  211. var frame = HexUI.Node(c, "WheelFrame", 310, 351, 580, 580);
  212. HexUI.Image(frame, "WheelRim", "prize_wheel", 290, 290, 580, 580);
  213. // The gold rim and its four fan ornaments stay on the stationary layer.
  214. // Clip a slightly enlarged copy to the velvet opening so only wedges turn.
  215. const float faceRadius = 240;
  216. var aperture = HexUI.Fill(frame, "WheelAperture", 290, 290, faceRadius * 2, faceRadius * 2);
  217. aperture.Value = 1;
  218. aperture.canvasRenderer.SetColor(HexUI.ColorOf("291420"));
  219. aperture.gameObject.AddComponent<Mask>();
  220. drawWheel = HexUI.Image(aperture.transform, "PrizeWheel", "prize_wheel", faceRadius, faceRadius, 580, 580).rectTransform;
  221. drawWheel.localScale = Vector3.one * 1.035f;
  222. for (int i = 0; i < LocalProfile.DrawNames.Length; i++)
  223. {
  224. Vector2 pos = WheelPoint(i, 157);
  225. var wedge = HexUI.Node(drawWheel, "Wedge_" + i, pos.x, pos.y, 128, 88);
  226. string icon = LocalProfile.DrawCoins[i] > 0 ? "reward_coins" : "power_" + HexUI.ItemIcons[LocalProfile.DrawItems[i]];
  227. HexUI.Image(wedge, "Prize_" + i, icon, 64, 29, 57, 57);
  228. HexUI.Text(wedge, "PrizeName", LocalProfile.DrawNames[i], 64, 74, 128, 30, 18);
  229. }
  230. SetWheelRotation(drawWheel, drawRestAngle);
  231. var pointer = HexUI.Image(frame, "PrizeIndicator", "icon_play", 290, 39, 40, 44).rectTransform;
  232. pointer.localRotation = Quaternion.Euler(0, 0, -90);
  233. HexUI.Image(pointer, "Enamel", "icon_play", 19, 22, 27, 30, HexUI.ColorOf("C82D4B"));
  234. // An opaque disc behind the medallion covers the rotating spokes.
  235. var hub = HexUI.Fill(frame, "HubBacking", 290, 290, 136, 136);
  236. hub.Value = 1;
  237. hub.canvasRenderer.SetColor(HexUI.ColorOf("391329"));
  238. var spin = HexUI.Button(frame, "Spin", "", 290, 290, 142, 142, StartDraw, "medallion");
  239. var colors = spin.colors;
  240. colors.disabledColor = new Color(.74f, .68f, .72f, 1f);
  241. spin.colors = colors;
  242. HexUI.Text(spin.transform, "Label", "SPIN", 71, 57, 109, 55, 40, true);
  243. string status = drawBusy ? "SPINNING…" : Profile.FreeDraw ? "FREE TODAY" : Profile.Data.tickets > 0 ? "USE 1 TICKET" : "NO TICKET";
  244. spin.interactable = !drawBusy && (Profile.FreeDraw || Profile.Data.tickets > 0);
  245. HexUI.Text(c, "SpinStatus", status, 172, 687, 275, 40, 25, false, HexUI.Gold);
  246. HexUI.Image(c, "Divider", null, 310, 687, 1.5f, 30, HexUI.Muted);
  247. HexUI.Text(c, "DrawTickets", "DRAW TICKETS " + Profile.Data.tickets, 453, 687, 270, 40, 23);
  248. PText(c, "Free play rewards · no cash value", 752, 32, 19);
  249. if (Ads != null && Ads.Supported)
  250. {
  251. var profile = Profile;
  252. HexUI.Button(modal, "Footer_BACK", "BACK", 160, 1144, 176, 78, ClosePanel, "panel", 26);
  253. const string rewardCaption = "WATCH AD · +1 TICKET";
  254. var reward = HexUI.Button(modal, "Footer_" + rewardCaption, rewardCaption, 472, 1144, 412, 82, () =>
  255. {
  256. if (!drawBusy) WatchReward("draw", profile.GrantDrawTicket, "+1 draw ticket");
  257. }, "primary", 27);
  258. var label = reward.GetComponentInChildren<TextMeshProUGUI>();
  259. label.rectTransform.sizeDelta = new Vector2(326, 62);
  260. label.textWrappingMode = TextWrappingModes.NoWrap;
  261. BindAdButton(reward);
  262. }
  263. else Footer("BACK",ClosePanel);
  264. }
  265. void WatchReward(string panel, Action grant, string message, Action resume = null)
  266. {
  267. if (currentPanel != panel || Ads.IsShowing) return;
  268. if (Ads.Status != RewardedAdStatus.Ready)
  269. {
  270. Ads.Retry();
  271. RefreshAdButton();
  272. return;
  273. }
  274. var view = modal;
  275. if (!Ads.TryShow(grant, earned =>
  276. {
  277. if (this == null || modal != view) return;
  278. if (earned && resume != null) resume();
  279. else Reopen(panel);
  280. Toast(earned ? message : "Ad ended without a reward · try again");
  281. }))
  282. {
  283. Ads.Retry();
  284. RefreshAdButton();
  285. }
  286. }
  287. void StartDraw()
  288. {
  289. if(drawBusy)return;int prize=Profile.Draw(rng);if(prize<0){Toast("Clear levels to earn more tickets");return;}
  290. drawBusy=true;Reopen("draw");StartCoroutine(SpinAnimation(prize));
  291. }
  292. static Vector2 WheelPoint(int prize, float radius)
  293. {
  294. float angle = prize * 2 * Mathf.PI / LocalProfile.DrawNames.Length;
  295. return new Vector2(290 + Mathf.Sin(angle) * radius, 290 - Mathf.Cos(angle) * radius);
  296. }
  297. static void SetWheelRotation(RectTransform wheel, float angle)
  298. {
  299. var rotation = Quaternion.Euler(0, 0, angle);
  300. wheel.localRotation = rotation;
  301. // Keep the prize illustrations and names upright as their wedges move.
  302. var upright = Quaternion.Inverse(rotation);
  303. for (int i = 0; i < wheel.childCount; i++)
  304. wheel.GetChild(i).localRotation = upright;
  305. }
  306. IEnumerator SpinAnimation(int prize)
  307. {
  308. var wheel = drawWheel;
  309. float target = prize * 360f / LocalProfile.DrawNames.Length;
  310. float start = drawRestAngle;
  311. float travel = 3 * 360f + Mathf.Repeat(start - target, 360f);
  312. const float duration = 2.8f;
  313. float startedAt = Time.unscaledTime;
  314. while (wheel != null && wheel == drawWheel && !Profile.Data.reduceMotion)
  315. {
  316. float t = (Time.unscaledTime - startedAt) / duration;
  317. if (t >= 1) break;
  318. SetWheelRotation(wheel, start - travel * Mathf.SmoothStep(0, 1, t));
  319. yield return null;
  320. }
  321. drawRestAngle = target;
  322. drawBusy=false;audioPlayer.Play("coin");Toast("WON "+LocalProfile.DrawNames[prize]);
  323. if(currentPanel=="draw") Reopen("draw");
  324. }
  325. void ProfilePanel()
  326. {
  327. var d = Profile.Data;
  328. var c = Content();
  329. int selected = Mathf.Clamp(d.avatar, 0, HexUI.Symbols.Length - 1);
  330. var medal = HexUI.Image(c, "PortraitMedal", "medallion", 89, 92, 120, 120);
  331. var portrait = HexUI.Image(medal.transform, "Portrait", HexUI.Symbols[selected], 60, 54, 78, 78);
  332. LeftText(c, "NicknameLabel", "NICKNAME", 174, 30, 405, 32, 20, false, HexUI.Gold);
  333. var input = HexUI.Image(c, "NicknameInput", "nickname_field", 379, 82, 428, 63);
  334. input.raycastTarget = true;
  335. nicknameInput = input.gameObject.AddComponent<TMP_InputField>();
  336. var text = LeftText(input.transform, "EditableName", d.nickname, 34, 32, 360, 48, 27);
  337. nicknameInput.textComponent=text;nicknameInput.textViewport=input.rectTransform;nicknameInput.characterLimit=16;nicknameInput.text=d.nickname;nicknameInput.lineType=TMP_InputField.LineType.SingleLine;
  338. LeftText(c, "NameHint", "3–16 letters, numbers, _ or -", 174, 138, 416, 30, 18, false, HexUI.Muted);
  339. LeftText(c, "AvatarLabel", "AVATAR", 24, 190, 566, 30, 20, false, HexUI.Gold);
  340. var avatars = new Button[HexUI.Symbols.Length];
  341. for (int i = 0; i < avatars.Length; i++)
  342. {
  343. int index = i;
  344. var b = HexUI.Button(c, "ChooseAvatar_" + i, "", 56 + i * 72.5f, 248, 69, 72, () =>
  345. {
  346. avatars[selected].image.sprite = HexUI.Sprite("holder");
  347. selected = index;
  348. avatars[selected].image.sprite = HexUI.Sprite("chip_teal");
  349. portrait.sprite = HexUI.Sprite(HexUI.Symbols[selected]);
  350. d.avatar = selected;
  351. Profile.Save();
  352. }, selected == i ? "chip_teal" : "holder");
  353. avatars[i] = b;
  354. HexUI.Image(b.transform, "OriginalIcon", HexUI.Symbols[i], 34.5f, 34, 45, 45);
  355. }
  356. Hairline(c, 310, 306, 570);
  357. HexUI.Text(c, "PlayerLevel", "LEVEL " + (1+d.totalWins/3), 152, 352, 248, 55, 34, true);
  358. HexUI.Text(c, "Balance", d.coins.ToString("N0") + " COINS", 436, 352, 312, 55, 32, true);
  359. string[] statNames = { "WINS", "CLEARS", "BEST SCORE", "TOTAL EARNED" };
  360. int[] values = { d.totalWins, d.totalClears, d.best, d.earned };
  361. for (int i = 0; i < values.Length; i++)
  362. {
  363. float x = 92 + i * 145;
  364. HexUI.Text(c, "StatValue", values[i].ToString("N0"), x, 430, 139, 43, 30);
  365. HexUI.Text(c, "StatName", statNames[i], x, 468, 141, 30, 17, false, HexUI.Muted);
  366. }
  367. Hairline(c, 310, 513, 570);
  368. LeftText(c, "ProgressTitle", "MODE PROGRESS", 24, 558, 560, 44, 28, true);
  369. for (int i = 0; i < LevelDatabase.ModeNames.Length; i++)
  370. {
  371. float y = 620 + i * 62;
  372. LeftText(c, "ModeName", LevelDatabase.ModeNames[i], 25, y, 230, 35, 22);
  373. HexUI.Image(c, "ProgressTrack", "bar", 365, y, 193, 16);
  374. HexUI.Fill(c, "ProgressFill", 365, y, 185, 8).Value = d.cleared[i] / 20f;
  375. HexUI.Text(c, "ModeCount", d.cleared[i] + " / 20", 546, y, 104, 34, 23, false, HexUI.Gold);
  376. }
  377. Footer("SAVE PROFILE",()=>{string value=nicknameInput.text.Trim();if(!Regex.IsMatch(value,"^[A-Za-z0-9_-]{3,16}$")){Toast("Use 3–16 letters, digits, _ or -");return;}d.nickname=value;Profile.Save();Toast("Profile saved");});
  378. }
  379. void SettingsPanel()
  380. {
  381. var c = Content();
  382. var d = Profile.Data;
  383. AddSettingSwitch(c, "Toggle_0", "Music", "pref_music", 73, d.music, () => d.music = !d.music);
  384. AddSettingSwitch(c, "Toggle_1", "Sound effects", "pref_sound", 184, d.sound, () => d.sound = !d.sound);
  385. AddSettingSwitch(c, "Toggle_2", "Reduce motion", "pref_motion", 295, d.reduceMotion, () => d.reduceMotion = !d.reduceMotion);
  386. LeftText(c, "DataHeading", "LOCAL DATA", 35, 407, 250, 45, 29, true);
  387. var saveState = HexUI.Text(c, "SaveState", Profile.Available ? "SAVE AVAILABLE" : "SAVE UNAVAILABLE",
  388. 465, 407, 240, 36, 18, false, HexUI.Muted);
  389. saveState.alignment = TextAlignmentOptions.Right;
  390. SettingsLink(c, "OpenLedger", "Coin ledger", 488, () => OpenPanel("ledger"), HexUI.Cream);
  391. bool privacy = Ads != null && Ads.NeedsPrivacyOptions;
  392. if (privacy) SettingsLink(c, "AdPrivacy", "Ad privacy options", 569, Ads.ShowPrivacyOptions, HexUI.Cream);
  393. SettingsLink(c, "ResetSave", "Reset save", privacy ? 650 : 569, () => OpenPanel("reset"), HexUI.ColorOf("FFA3A8"));
  394. HexUI.Text(c, "GameInfo", "3 MODES · 60 LEVELS", 310, 747, 530, 32, 18, false, HexUI.Muted);
  395. Footer("DONE",ClosePanel);
  396. }
  397. void AddSettingSwitch(Transform parent, string name, string label, string icon, float y, bool enabled, Action toggle)
  398. {
  399. var row = HexUI.Button(parent, name, "", 310, y, 568, 96, () =>
  400. {
  401. toggle();
  402. Profile.Save();
  403. SyncAudio();
  404. Reopen("settings");
  405. }, null);
  406. HexUI.Image(row.transform, "Icon", icon, 48, 48, 61, 61);
  407. LeftText(row.transform, "SettingName", label, 104, 48, 263, 50, 28);
  408. var track = HexUI.Image(row.transform, "Switch", "switch_track", 494, 48, 124, 48, enabled ? Color.white : HexUI.Muted);
  409. row.targetGraphic = track;
  410. HexUI.Image(track.transform, "Thumb", enabled ? "chip_teal" : "holder", enabled ? 98 : 26, 24, 32, 32);
  411. HexUI.Text(track.transform, "Value", enabled ? "ON" : "OFF", enabled ? 46 : 79, 24, 57, 30, 20);
  412. Hairline(parent, 310, y + 55, 550);
  413. }
  414. static void SettingsLink(Transform parent, string name, string label, float y, Action action, Color ink)
  415. {
  416. var row = HexUI.Button(parent, name, "", 310, y, 558, 78, action, null);
  417. row.targetGraphic = LeftText(row.transform, "Label", label, 9, 39, 461, 47, 25, false, ink);
  418. var arrow = HexUI.Image(row.transform, "Chevron", "icon_back", 533, 39, 17, 22, ink);
  419. arrow.rectTransform.localScale = new Vector3(-1, 1, 1);
  420. Hairline(parent, 310, y + 40, 550);
  421. }
  422. void PausePanel()
  423. {
  424. var c=Content();PText(c,"TAKE YOUR TIME",95,90,49,true);PText(c,"Your table will be here when you return.",178,70,24);
  425. HexUI.Button(c,"Resume","RESUME",310,306,520,100,ClosePanel,"primary",42,true);
  426. HexUI.Button(c,"Restart","RESTART LEVEL",310,453,520,92,()=>{int mode=Game.Spec.mode,level=Game.Spec.level;CloseAll();StartLevel(mode,level);},"panel",33,true);
  427. HexUI.Button(c,"ReturnLobby","BACK TO LOBBY",310,590,520,92,LeaveGame,"panel",33,true);
  428. PText(c,"Used power-ups are not refunded.",705,40,20);
  429. }
  430. void ResultPanel()
  431. {
  432. var round = Game;
  433. int mode = round.Spec.mode, level = round.Spec.level;
  434. bool timedOut = resultTitle == "TIME UP";
  435. HexUI.Text(modal, "ResultLevel", LevelDatabase.ModeNames[mode] + " · LEVEL " + level, 375, 187, 500, 34, 22, false, HexUI.Gold);
  436. HexUI.Text(modal, "PanelTitle", resultWin ? "TABLE CLEARED" : resultTitle, 375, 249, 555, 80, 56, true);
  437. var c = Content();
  438. string art = resultWin ? "result_trophy" : timedOut ? "result_hourglass" : "result_hive";
  439. HexUI.Image(c, "ResultIcon", art, 310, 144, 225, 225);
  440. Hairline(c, 108, 144, 116);
  441. Hairline(c, 512, 144, 116);
  442. ResultStat(c, "SCORE", round.Score, 108);
  443. ResultStat(c, "TARGET", round.Spec.target, 310);
  444. ResultStat(c, "CLEARS", round.Clears, 512);
  445. HexUI.Image(c, "ProgressTrack", "bar", 310, 435, 520, 20);
  446. HexUI.Fill(c, "ScoreProgress", 310, 435, 510, 10).Value = (float)round.Score / round.Spec.target;
  447. if (resultWin)
  448. {
  449. HexUI.Text(c, "RewardHeading", "REWARDS", 310, 548, 350, 42, 27, true);
  450. var plaque = HexUI.Image(c, "RewardPlaque", "dock_frame", 310, 655, 585, 133);
  451. ResultReward(plaque.transform, "reward_coins", resultCoins, "COINS", resultTicket > 0 ? 114 : 229);
  452. if (resultTicket > 0) ResultReward(plaque.transform, "reward_ticket", resultTicket, "DRAW TICKET", 340);
  453. }
  454. else
  455. {
  456. HexUI.Text(c, "OutcomeDetail", timedOut ? "Time ran out before you reached the target." :
  457. "There are no open cells for your next group.", 310, 563, 510, 72, 28);
  458. if (!round.ReviveUsed && Ads != null && Ads.Supported)
  459. {
  460. string effect = timedOut ? "+30 SECONDS" : "FREE 3 CELLS";
  461. if (timedOut && !round.Cells.Any(cell => cell.need <= round.Score && cell.tiles.Count == 0))
  462. effect = "+30 SECONDS · FREE 3 CELLS";
  463. BindAdButton(HexUI.Button(c, "AdRevive", "WATCH AD TO REVIVE\n" + effect, 310, 685, 535, 93,
  464. () => WatchReward("result", null, "Back in play", () => ResumeRound(round)), "panel", 26));
  465. }
  466. else HexUI.Text(c, "RewardStatus", "No reward this round.", 310, 647, 500, 42, 21, false, HexUI.Muted);
  467. }
  468. var back = HexUI.Button(modal, "Footer_BACK", "", 193, 1144, 181, 82, LeaveGame, null);
  469. HexUI.Image(back.transform, "BackArrow", "icon_back", 38, 41, 22, 25);
  470. back.targetGraphic = HexUI.Text(back.transform, "Label", "BACK", 107, 41, 116, 46, 26);
  471. string next = resultWin ? (level == 20 ? "REPLAY LV 20" : "NEXT LEVEL") : "RETRY";
  472. HexUI.Button(modal, "Footer_" + next, next, 480, 1144, 360, 84,
  473. () => { CloseAll(); StartLevel(mode, resultWin ? Math.Min(20, level + 1) : level); }, "primary", 32, true);
  474. }
  475. static void ResultStat(Transform parent, string label, int value, float x)
  476. {
  477. HexUI.Text(parent, label + "Label", label, x, 318, 178, 35, 21, false, HexUI.Muted);
  478. HexUI.Text(parent, label + "Value", value.ToString("N0"), x, 375, 180, 66, 46, true);
  479. }
  480. static void ResultReward(Transform parent, string icon, int amount, string label, float x)
  481. {
  482. HexUI.Image(parent, icon, icon, x, 66, 60, 60);
  483. LeftText(parent, label + "Amount", "+" + amount.ToString("N0"), x + 42, 52, 132, 45, 35, true);
  484. LeftText(parent, label + "Label", label, x + 43, 90, 133, 33, 18);
  485. }
  486. void ResumeRound(HexRules round)
  487. {
  488. if (Game != round || !round.TryRevive()) return;
  489. CloseAll();
  490. finished = Busy = hammer = false;
  491. resumedFrame = Time.frameCount;
  492. SelectedSlot = activePointerSlot = -1;
  493. if (dragGhost != null) Destroy(dragGhost.gameObject);
  494. dragGhost = null;
  495. hintText.text = "DRAG TO AN EMPTY CELL";
  496. DrawBoard(); DrawHand(); DrawDock(); UpdateHud();
  497. }
  498. void ResetPanel()
  499. {
  500. var c=Content();HexUI.Image(c,"ResetIcon","icon_close",310,160,110,110);PText(c,"RESET ALL PROGRESS?",310,100,43,true);
  501. PText(c,"This clears coins, items, all mode progress,\ncheck-in history and player statistics.\nThis cannot be undone.",482,180,27);
  502. Footer("CANCEL",ClosePanel,"RESET",()=>{Profile.Reset();CloseAll();SyncAudio();ShowLobby();Toast("Save reset");});
  503. }
  504. static readonly string[] Steps={
  505. "THREE GROUPS AT A TIME|Each hand has three single-color groups of 2–4 tiles. Place all three before the next hand arrives.",
  506. "DRAG OR TAP|Drag a whole group onto the board. You can also tap a hand group, then tap a cell.",
  507. "EMPTY CELLS ONLY|You cannot place on any existing stack, even if its color matches. Locked cells are unavailable.",
  508. "MERGE AND CLEAR|Adjacent matching top colors merge automatically. Eight or more consecutive matching tiles clear together.",
  509. "LOCKS AND LAYERS|Score opens locked cells. Mixed starting stacks reveal another color when their top segment moves away.",
  510. "SCORE AND CHAIN|Each placed tile earns 2 points. Eight tiles clear for 60 points; extras add 12 each. Successive clears multiply the reward.",
  511. "NEIGHBOR BONUS|A clear adds a tile to each matching neighboring top. This can start another chain. Reach the target score to win.",
  512. "KEEP ROOM TO PLAY|A full board ends the game after settlement. Time Rush also ends when time expires; each clear adds four seconds."
  513. };
  514. static readonly string[] Faqs={
  515. "How do I play?|Place groups in empty cells next to the same color. Let automatic merges make room.",
  516. "When does a stack clear?|A continuous run of at least eight matching tiles is collected.",
  517. "Can I stack different colors?|No. Hand groups only go into empty cells. Mixed stacks are starting obstacles.",
  518. "Why can I not drop here?|The cell is occupied, locked, or an animation is still settling.",
  519. "How do locks open?|The number shows points still needed. Reach that score or use UNLOCK.",
  520. "What are mixed starting stacks?|They contain two colors. Only the top matching segment can move during a merge.",
  521. "How do chains work?|Multiple clears from one move increase the score multiplier to ×2, ×3 and beyond.",
  522. "How do I win?|Reach the target score. Each mode has twenty levels and saves progress separately.",
  523. "When do I lose?|When no unlocked empty cell remains after settlement, or the Time Rush clock reaches zero.",
  524. "Where do coins come from?|The welcome gift, wins, check-in and Lucky Draw. Coins buy power-ups and have no cash value.",
  525. "Where is my progress?|On this device only. There is no account or cloud sync. Active games are not saved."
  526. };
  527. void HelpPanel()
  528. {
  529. HelpTab("HOW TO PLAY", false, 228);
  530. HelpTab("FAQ", true, 522);
  531. if (helpShowsFaq) BuildFaqList();
  532. else
  533. {
  534. const float rowHeight = 174;
  535. var c = Content(16 + Steps.Length * rowHeight, 85);
  536. for (int i = 0; i < Steps.Length; i++)
  537. {
  538. float y = 10 + i * rowHeight;
  539. var parts = Steps[i].Split('|');
  540. HexUI.Text(c, "Number", (i+1).ToString("00"), 60, y + 38, 76, 53, 35, true);
  541. LeftText(c, "StepTitle", parts[0], 118, y + 37, 468, 43, 26, true);
  542. LeftText(c, "StepBody", parts[1], 118, y + 109, 466, 89, 22);
  543. Hairline(c, 310, y + 165, 552);
  544. }
  545. }
  546. Footer("GOT IT",ClosePanel);
  547. }
  548. void HelpTab(string label, bool faq, float x)
  549. {
  550. var tab = HexUI.Button(modal, "Tab_" + label, "", x, 332, 282, 65, () =>
  551. {
  552. if (helpShowsFaq == faq) return;
  553. helpShowsFaq = faq;
  554. Reopen("help");
  555. }, null);
  556. bool active = helpShowsFaq == faq;
  557. tab.targetGraphic = HexUI.Text(tab.transform, "Label", label, 141, 28, 256, 43, 25, false, active ? HexUI.Cream : HexUI.Muted);
  558. HexUI.Image(tab.transform, "Underline", null, 141, 61, 266, active ? 4 : 1.5f, active ? HexUI.Gold : HexUI.ColorOf("825B59"));
  559. }
  560. void BuildFaqList()
  561. {
  562. const float questionHeight = 76, answerHeight = 92;
  563. var c = Content(24 + Faqs.Length * questionHeight + faqOpen.Count(open => open) * answerHeight, 85);
  564. float y = 10;
  565. for (int i = 0; i < Faqs.Length; i++)
  566. {
  567. int index = i;
  568. var parts = Faqs[i].Split('|');
  569. var question = HexUI.Button(c, "FAQ_" + i, "", 310, y + questionHeight / 2, 572, questionHeight, () =>
  570. {
  571. float offset = c.anchoredPosition.y;
  572. faqOpen[index] = !faqOpen[index];
  573. Reopen("help");
  574. var list = modal.GetComponentInChildren<ScrollRect>();
  575. list.content.anchoredPosition = new Vector2(list.content.anchoredPosition.x,
  576. Mathf.Clamp(offset, 0, Mathf.Max(0, list.content.rect.height - list.viewport.rect.height)));
  577. }, null);
  578. question.targetGraphic = LeftText(question.transform, "Question", parts[0], 8, 38, 506, 60, 23);
  579. HexUI.Text(question.transform, "Toggle", faqOpen[i] ? "−" : "+", 548, 38, 40, 48, 31, false, HexUI.Gold);
  580. y += questionHeight;
  581. if (faqOpen[i])
  582. {
  583. LeftText(c, "Answer", parts[1], 45, y + 40, 527, 83, 21, false, HexUI.Muted);
  584. y += answerHeight;
  585. }
  586. Hairline(c, 310, y, 552);
  587. }
  588. }
  589. }
  590. }