| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596 |
- using System;
- using System.Collections;
- using System.Linq;
- using System.Text.RegularExpressions;
- using HexaCrazy.Ads;
- using UnityEngine;
- using UnityEngine.UI;
- using TMPro;
- namespace HexaCrazy
- {
- public partial class HexGameApp
- {
- readonly bool[] faqOpen={true,true,false,false,false,false,false,false,false,false,false};
- bool helpShowsFaq;
- RectTransform drawWheel;
- float drawRestAngle;
- TMP_InputField nicknameInput;
- Button adButton;
- TextMeshProUGUI adLabel;
- string readyCaption;
- RewardedAdStatus? displayedAdStatus;
- public void OpenPanel(string name)
- {
- if(modal!=null&¤tPanel!=name&¤tPanel!="result")panelHistory.Push(currentPanel);
- BuildPanel(name);
- }
- void Reopen(string name){BuildPanel(name);}
- void RemoveModal(){adButton=null;adLabel=null;drawWheel=null;if(modal!=null){modal.gameObject.SetActive(false);Destroy(modal.gameObject);modal=null;}}
- public void ClosePanel()
- {
- if(currentPanel=="result")return;
- RemoveModal();currentPanel=null;
- if(panelHistory.Count>0){BuildPanel(panelHistory.Pop());return;}
- if(ScreenName=="Lobby")ShowLobby();else if(ScreenName=="Game"){DrawDock();UpdateHud();}
- }
- void CloseAll(){RemoveModal();currentPanel=null;panelHistory.Clear();}
- void BuildPanel(string name)
- {
- RemoveModal();currentPanel=name;modal=Layer("Modal_"+name);modal.SetAsLastSibling();toastLayer.SetAsLastSibling();
- var shade=HexUI.Image(modal,"Dimmer",null,375,667,750,1334,new Color(0,0,0,.76f));shade.raycastTarget=true;
- string title=name=="draw"?"LUCKY DRAW":name=="checkin"?"CHECK-IN":name=="ledger"?"COIN LEDGER":name=="result"?resultTitle:name.ToUpperInvariant();
- switch (name)
- {
- case "checkin":
- int day = Profile.CanCheckin ? Profile.CheckinSlot : Profile.ClaimedCheckinSlot;
- FolioHeader(title, "dock_checkin", "DAY " + day + " OF 7"); break;
- case "shop": case "draw":
- FolioHeader(title, "dock_" + name, Profile.Data.coins.ToString("N0") + " COINS"); break;
- case "help": FolioHeader(title, "rulebook", "PLAYER HANDBOOK"); break;
- case "profile": FolioHeader(title, "dock_profile", "LOCAL PLAYER · ID " + Profile.Data.id); break;
- case "settings": FolioHeader(title, "pref_gear", "HEXA CRAZY 7+ · v1.0"); break;
- case "result": FolioBackdrop(); break;
- default:
- HexUI.Image(modal,"Dialog","card",375,667,700,1100,null,true);
- HexUI.Text(modal,"PanelTitle",title,350,208,540,72,46,true);
- HexUI.IconButton(modal,"ClosePanel","close",666,205,55,ClosePanel);
- HexUI.Image(modal,"PanelRule","ornament",375,259,570,20);
- break;
- }
- switch(name)
- {
- case "shop":ShopPanel();break;case "ledger":LedgerPanel();break;case "checkin":CheckinPanel();break;case "draw":DrawPanel();break;
- case "profile":ProfilePanel();break;case "settings":SettingsPanel();break;case "help":HelpPanel();break;case "pause":PausePanel();break;
- case "result":ResultPanel();break;case "reset":ResetPanel();break;
- }
- }
- void FolioBackdrop()
- {
- HexUI.Image(modal, "FolioBacking", null, 375, 667, 664, 1070, HexUI.ColorOf("220C20"));
- HexUI.Image(modal, "Dialog", "folio", 375, 667, 710, 1124);
- }
- void FolioHeader(string title, string icon, string detail)
- {
- FolioBackdrop();
- HexUI.Image(modal, "PageIcon", icon, 149, 215, 75, 75);
- LeftText(modal, "PanelTitle", title, 205, 198, 372, 61, 46, true);
- LeftText(modal, "PanelDetail", detail, 208, 243, 368, 30, 20, false, HexUI.Gold);
- var close = HexUI.Button(modal, "ClosePanel", "", 611, 214, 68, 68, ClosePanel, null);
- close.targetGraphic = HexUI.Image(close.transform, "Icon", "icon_close", 34, 34, 33, 33);
- HexUI.Image(modal, "PanelRule", "ornament", 375, 278, 536, 14);
- }
- static TextMeshProUGUI LeftText(Transform parent, string name, string value, float left, float y,
- float width, float height, float size, bool display = false, Color? color = null)
- {
- var label = HexUI.Text(parent, name, value, left + width / 2, y, width, height, size, display, color);
- label.alignment = TextAlignmentOptions.MidlineLeft;
- return label;
- }
- static void Hairline(Transform parent, float x, float y, float width)
- {
- HexUI.Image(parent, "Rule", null, x, y, width, 1.5f, HexUI.ColorOf("A47B4C99"));
- }
- RectTransform Content(float height=740,float topInset=0)
- {
- float h=788-topInset;
- var view=HexUI.Node(modal,"ScrollViewport",375,682+topInset/2,620,h);view.gameObject.AddComponent<RectMask2D>();
- var touch=view.gameObject.AddComponent<Image>();touch.color=new Color(0,0,0,.001f);touch.raycastTarget=true;
- 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);
- 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;
- return content;
- }
- 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);}
- Button Footer(string label,Action action,string second=null,Action other=null)
- {
- if(second==null)return HexUI.Button(modal,"Footer_"+label,label,375,1144,460,82,action,"primary",34,true);
- HexUI.Button(modal,"Footer_"+label,label,215,1144,290,82,action,"panel",28,true);
- return HexUI.Button(modal,"Footer_"+second,second,530,1144,290,82,other,"primary",28,true);
- }
- void BindAdButton(Button button)
- {
- adButton = button;
- adLabel = button.GetComponentInChildren<TextMeshProUGUI>();
- readyCaption = adLabel.text;
- displayedAdStatus = null;
- RefreshAdButton();
- }
- void RefreshAdButton()
- {
- if (adButton == null || Ads == null || displayedAdStatus == Ads.Status) return;
- var status = Ads.Status;
- displayedAdStatus = status;
- adButton.interactable = status != RewardedAdStatus.Preparing && status != RewardedAdStatus.Loading;
- switch (status)
- {
- case RewardedAdStatus.Ready: adLabel.text = readyCaption; break;
- case RewardedAdStatus.Preparing: adLabel.text = "PREPARING ADS…"; break;
- case RewardedAdStatus.Loading: adLabel.text = "LOADING AD…"; break;
- case RewardedAdStatus.NetworkError: adLabel.text = "NETWORK ERROR\nRETRY AD"; break;
- case RewardedAdStatus.NoFill: adLabel.text = "NO AD AVAILABLE\nRETRY"; break;
- case RewardedAdStatus.PrivacyUnavailable: adLabel.text = "PRIVACY CHECK\nRETRY"; break;
- default: adLabel.text = "AD LOAD FAILED\nRETRY"; break;
- }
- }
- void ShopPanel()
- {
- var c = Content();
- string[] descriptions = {
- "Remove an occupied stack without scoring.",
- "Replace the remaining hand with three new groups.",
- "Add a group of three. Replaces slot 3 if the hand is full.",
- "Open the locked cell with the lowest score threshold."
- };
- Hairline(c, 310, 391, 558);
- HexUI.Image(c, "ShelfDivider", null, 310, 391, 1.5f, 710, HexUI.ColorOf("A47B4C66"));
- for (int i = 0; i < descriptions.Length; i++)
- {
- int item = i;
- float x = 160 + i % 2 * 300, y = 14 + i / 2 * 385;
- HexUI.Image(c, "ItemIcon", "power_" + HexUI.ItemIcons[i], x, y + 79, 117, 117);
- HexUI.Text(c, "ItemName", LevelDatabase.ItemNames[i], x, y + 161, 272, 46, 33, true);
- HexUI.Text(c, "Owned", "OWNED " + Profile.Data.items[i], x, y + 200, 260, 27, 18, false, HexUI.Gold);
- HexUI.Text(c, "Description", descriptions[i], x, y + 252, 260, 67, 21);
- var buy = HexUI.Button(c, "BuyItem_" + i, "BUY · " + LevelDatabase.Prices[i].ToString("N0"),
- x, y + 326, 218, 59, () =>
- {
- if (Profile.Buy(item)) { audioPlayer.Play("coin"); Reopen("shop"); Toast("Purchased " + LevelDatabase.ItemNames[item]); }
- else Toast("Need " + (LevelDatabase.Prices[item] - Profile.Data.coins).ToString("N0") + " more coins");
- }, "primary", 23);
- if(Profile.Data.coins<LevelDatabase.Prices[i])buy.image.color=new Color(.65f,.55f,.6f);
- }
- Footer("COIN LEDGER",()=>OpenPanel("ledger"));
- }
- void LedgerPanel()
- {
- var d=Profile.Data;int count=Math.Min(60,d.ledger.Count);var c=Content(160+count*78);
- PText(c,"BALANCE "+d.coins.ToString("N0"),42,62,39,true);
- PText(c,"INCOME "+d.earned.ToString("N0")+" · SPENT "+Math.Max(0,d.earned-d.coins).ToString("N0"),102,42,22);
- 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"));}
- Footer("BACK",ClosePanel);
- }
- void CheckinPanel()
- {
- var c = Content();
- bool canClaim = Profile.CanCheckin;
- int slot = canClaim ? Profile.CheckinSlot : Profile.ClaimedCheckinSlot;
- PText(c, "Rewards advance each day. Missed days are skipped.", 43, 54, 21);
- for (int i = 0; i < 6; i++)
- {
- bool today = i + 1 == slot;
- var tile = HexUI.Image(c, "Day_" + (i+1), null, 113 + i % 3 * 197, 206 + i / 3 * 222,
- 181, 201, HexUI.ColorOf(today ? "17494C" : "3D1A38"));
- HexUI.Image(tile.transform, "TopEdge", null, 90.5f, 1.5f, 181, 3, today ? HexUI.Gold : HexUI.ColorOf("825B59"));
- HexUI.Text(tile.transform, "Day", "DAY " + (i+1), 90.5f, 30, 128, 32, 21, false, HexUI.Gold);
- string icon = i % 2 == 0 ? "reward_coins" : "power_" + HexUI.ItemIcons[i / 2];
- HexUI.Image(tile.transform, "Reward", icon, 90.5f, 100, 77, 77);
- HexUI.Text(tile.transform, "Name", LocalProfile.CheckinRewardName(i+1), 90.5f, 165, 173, 36, 22);
- if (today && !canClaim) HexUI.Image(tile.transform, "Claimed", "icon_check", 154, 30, 22, 22);
- }
- var finalDay = HexUI.Image(c, "Day_7", "dock_frame", 310, 659, 598, 180);
- HexUI.Image(finalDay.transform, "Reward", "reward_chest", 172, 90, 110, 120);
- LeftText(finalDay.transform, "Day", "DAY 7", 261, 57, 210, 36, 23, false, HexUI.Gold);
- LeftText(finalDay.transform, "Name", LocalProfile.CheckinRewardName(7), 261, 108, 240, 55, 34, true);
- if (slot == 7) HexUI.Image(finalDay.transform, "Today", canClaim ? "coin" : "icon_check", 367, 57, 23, 23);
- if (Ads != null && Ads.Supported && Profile.CanClaimCheckinBonus)
- {
- var profile = Profile;
- string date = profile.Data.checkinLast;
- BindAdButton(HexUI.Button(modal, "AdCheckin", "WATCH AD · " + LocalProfile.CheckinRewardName(slot), 375,1144,590,82, () =>
- {
- if (!profile.CanClaimCheckinBonus || profile.Data.checkinLast != date) { Reopen("checkin"); return; }
- WatchReward("checkin", () => profile.ClaimCheckinBonus(date), "Extra daily reward claimed");
- }, "primary", 29, true));
- return;
- }
- 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");});
- }
- void DrawPanel()
- {
- var c = Content();
- PText(c, "ONE FREE SPIN EACH DAY", 29, 36, 23);
- var frame = HexUI.Node(c, "WheelFrame", 310, 351, 580, 580);
- HexUI.Image(frame, "WheelRim", "prize_wheel", 290, 290, 580, 580);
- // The gold rim and its four fan ornaments stay on the stationary layer.
- // Clip a slightly enlarged copy to the velvet opening so only wedges turn.
- const float faceRadius = 240;
- var aperture = HexUI.Fill(frame, "WheelAperture", 290, 290, faceRadius * 2, faceRadius * 2);
- aperture.Value = 1;
- aperture.canvasRenderer.SetColor(HexUI.ColorOf("291420"));
- aperture.gameObject.AddComponent<Mask>();
- drawWheel = HexUI.Image(aperture.transform, "PrizeWheel", "prize_wheel", faceRadius, faceRadius, 580, 580).rectTransform;
- drawWheel.localScale = Vector3.one * 1.035f;
- for (int i = 0; i < LocalProfile.DrawNames.Length; i++)
- {
- Vector2 pos = WheelPoint(i, 157);
- var wedge = HexUI.Node(drawWheel, "Wedge_" + i, pos.x, pos.y, 128, 88);
- string icon = LocalProfile.DrawCoins[i] > 0 ? "reward_coins" : "power_" + HexUI.ItemIcons[LocalProfile.DrawItems[i]];
- HexUI.Image(wedge, "Prize_" + i, icon, 64, 29, 57, 57);
- HexUI.Text(wedge, "PrizeName", LocalProfile.DrawNames[i], 64, 74, 128, 30, 18);
- }
- SetWheelRotation(drawWheel, drawRestAngle);
- var pointer = HexUI.Image(frame, "PrizeIndicator", "icon_play", 290, 39, 40, 44).rectTransform;
- pointer.localRotation = Quaternion.Euler(0, 0, -90);
- HexUI.Image(pointer, "Enamel", "icon_play", 19, 22, 27, 30, HexUI.ColorOf("C82D4B"));
- // An opaque disc behind the medallion covers the rotating spokes.
- var hub = HexUI.Fill(frame, "HubBacking", 290, 290, 136, 136);
- hub.Value = 1;
- hub.canvasRenderer.SetColor(HexUI.ColorOf("391329"));
- var spin = HexUI.Button(frame, "Spin", "", 290, 290, 142, 142, StartDraw, "medallion");
- var colors = spin.colors;
- colors.disabledColor = new Color(.74f, .68f, .72f, 1f);
- spin.colors = colors;
- HexUI.Text(spin.transform, "Label", "SPIN", 71, 57, 109, 55, 40, true);
- string status = drawBusy ? "SPINNING…" : Profile.FreeDraw ? "FREE TODAY" : Profile.Data.tickets > 0 ? "USE 1 TICKET" : "NO TICKET";
- spin.interactable = !drawBusy && (Profile.FreeDraw || Profile.Data.tickets > 0);
- HexUI.Text(c, "SpinStatus", status, 172, 687, 275, 40, 25, false, HexUI.Gold);
- HexUI.Image(c, "Divider", null, 310, 687, 1.5f, 30, HexUI.Muted);
- HexUI.Text(c, "DrawTickets", "DRAW TICKETS " + Profile.Data.tickets, 453, 687, 270, 40, 23);
- PText(c, "Free play rewards · no cash value", 752, 32, 19);
- if (Ads != null && Ads.Supported)
- {
- var profile = Profile;
- HexUI.Button(modal, "Footer_BACK", "BACK", 160, 1144, 176, 78, ClosePanel, "panel", 26);
- const string rewardCaption = "WATCH AD · +1 TICKET";
- var reward = HexUI.Button(modal, "Footer_" + rewardCaption, rewardCaption, 472, 1144, 412, 82, () =>
- {
- if (!drawBusy) WatchReward("draw", profile.GrantDrawTicket, "+1 draw ticket");
- }, "primary", 27);
- var label = reward.GetComponentInChildren<TextMeshProUGUI>();
- label.rectTransform.sizeDelta = new Vector2(326, 62);
- label.textWrappingMode = TextWrappingModes.NoWrap;
- BindAdButton(reward);
- }
- else Footer("BACK",ClosePanel);
- }
- void WatchReward(string panel, Action grant, string message, Action resume = null)
- {
- if (currentPanel != panel || Ads.IsShowing) return;
- if (Ads.Status != RewardedAdStatus.Ready)
- {
- Ads.Retry();
- RefreshAdButton();
- return;
- }
- var view = modal;
- if (!Ads.TryShow(grant, earned =>
- {
- if (this == null || modal != view) return;
- if (earned && resume != null) resume();
- else Reopen(panel);
- Toast(earned ? message : "Ad ended without a reward · try again");
- }))
- {
- Ads.Retry();
- RefreshAdButton();
- }
- }
- void StartDraw()
- {
- if(drawBusy)return;int prize=Profile.Draw(rng);if(prize<0){Toast("Clear levels to earn more tickets");return;}
- drawBusy=true;Reopen("draw");StartCoroutine(SpinAnimation(prize));
- }
- static Vector2 WheelPoint(int prize, float radius)
- {
- float angle = prize * 2 * Mathf.PI / LocalProfile.DrawNames.Length;
- return new Vector2(290 + Mathf.Sin(angle) * radius, 290 - Mathf.Cos(angle) * radius);
- }
- static void SetWheelRotation(RectTransform wheel, float angle)
- {
- var rotation = Quaternion.Euler(0, 0, angle);
- wheel.localRotation = rotation;
- // Keep the prize illustrations and names upright as their wedges move.
- var upright = Quaternion.Inverse(rotation);
- for (int i = 0; i < wheel.childCount; i++)
- wheel.GetChild(i).localRotation = upright;
- }
- IEnumerator SpinAnimation(int prize)
- {
- var wheel = drawWheel;
- float target = prize * 360f / LocalProfile.DrawNames.Length;
- float start = drawRestAngle;
- float travel = 3 * 360f + Mathf.Repeat(start - target, 360f);
- const float duration = 2.8f;
- float startedAt = Time.unscaledTime;
- while (wheel != null && wheel == drawWheel && !Profile.Data.reduceMotion)
- {
- float t = (Time.unscaledTime - startedAt) / duration;
- if (t >= 1) break;
- SetWheelRotation(wheel, start - travel * Mathf.SmoothStep(0, 1, t));
- yield return null;
- }
- drawRestAngle = target;
- drawBusy=false;audioPlayer.Play("coin");Toast("WON "+LocalProfile.DrawNames[prize]);
- if(currentPanel=="draw") Reopen("draw");
- }
- void ProfilePanel()
- {
- var d = Profile.Data;
- var c = Content();
- int selected = Mathf.Clamp(d.avatar, 0, HexUI.Symbols.Length - 1);
- var medal = HexUI.Image(c, "PortraitMedal", "medallion", 89, 92, 120, 120);
- var portrait = HexUI.Image(medal.transform, "Portrait", HexUI.Symbols[selected], 60, 54, 78, 78);
- LeftText(c, "NicknameLabel", "NICKNAME", 174, 30, 405, 32, 20, false, HexUI.Gold);
- var input = HexUI.Image(c, "NicknameInput", "nickname_field", 379, 82, 428, 63);
- input.raycastTarget = true;
- nicknameInput = input.gameObject.AddComponent<TMP_InputField>();
- var text = LeftText(input.transform, "EditableName", d.nickname, 34, 32, 360, 48, 27);
- nicknameInput.textComponent=text;nicknameInput.textViewport=input.rectTransform;nicknameInput.characterLimit=16;nicknameInput.text=d.nickname;nicknameInput.lineType=TMP_InputField.LineType.SingleLine;
- LeftText(c, "NameHint", "3–16 letters, numbers, _ or -", 174, 138, 416, 30, 18, false, HexUI.Muted);
- LeftText(c, "AvatarLabel", "AVATAR", 24, 190, 566, 30, 20, false, HexUI.Gold);
- var avatars = new Button[HexUI.Symbols.Length];
- for (int i = 0; i < avatars.Length; i++)
- {
- int index = i;
- var b = HexUI.Button(c, "ChooseAvatar_" + i, "", 56 + i * 72.5f, 248, 69, 72, () =>
- {
- avatars[selected].image.sprite = HexUI.Sprite("holder");
- selected = index;
- avatars[selected].image.sprite = HexUI.Sprite("chip_teal");
- portrait.sprite = HexUI.Sprite(HexUI.Symbols[selected]);
- d.avatar = selected;
- Profile.Save();
- }, selected == i ? "chip_teal" : "holder");
- avatars[i] = b;
- HexUI.Image(b.transform, "OriginalIcon", HexUI.Symbols[i], 34.5f, 34, 45, 45);
- }
- Hairline(c, 310, 306, 570);
- HexUI.Text(c, "PlayerLevel", "LEVEL " + (1+d.totalWins/3), 152, 352, 248, 55, 34, true);
- HexUI.Text(c, "Balance", d.coins.ToString("N0") + " COINS", 436, 352, 312, 55, 32, true);
- string[] statNames = { "WINS", "CLEARS", "BEST SCORE", "TOTAL EARNED" };
- int[] values = { d.totalWins, d.totalClears, d.best, d.earned };
- for (int i = 0; i < values.Length; i++)
- {
- float x = 92 + i * 145;
- HexUI.Text(c, "StatValue", values[i].ToString("N0"), x, 430, 139, 43, 30);
- HexUI.Text(c, "StatName", statNames[i], x, 468, 141, 30, 17, false, HexUI.Muted);
- }
- Hairline(c, 310, 513, 570);
- LeftText(c, "ProgressTitle", "MODE PROGRESS", 24, 558, 560, 44, 28, true);
- for (int i = 0; i < LevelDatabase.ModeNames.Length; i++)
- {
- float y = 620 + i * 62;
- LeftText(c, "ModeName", LevelDatabase.ModeNames[i], 25, y, 230, 35, 22);
- HexUI.Image(c, "ProgressTrack", "bar", 365, y, 193, 16);
- HexUI.Fill(c, "ProgressFill", 365, y, 185, 8).Value = d.cleared[i] / 20f;
- HexUI.Text(c, "ModeCount", d.cleared[i] + " / 20", 546, y, 104, 34, 23, false, HexUI.Gold);
- }
- 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");});
- }
- void SettingsPanel()
- {
- var c = Content();
- var d = Profile.Data;
- AddSettingSwitch(c, "Toggle_0", "Music", "pref_music", 73, d.music, () => d.music = !d.music);
- AddSettingSwitch(c, "Toggle_1", "Sound effects", "pref_sound", 184, d.sound, () => d.sound = !d.sound);
- AddSettingSwitch(c, "Toggle_2", "Reduce motion", "pref_motion", 295, d.reduceMotion, () => d.reduceMotion = !d.reduceMotion);
- LeftText(c, "DataHeading", "LOCAL DATA", 35, 407, 250, 45, 29, true);
- var saveState = HexUI.Text(c, "SaveState", Profile.Available ? "SAVE AVAILABLE" : "SAVE UNAVAILABLE",
- 465, 407, 240, 36, 18, false, HexUI.Muted);
- saveState.alignment = TextAlignmentOptions.Right;
- SettingsLink(c, "OpenLedger", "Coin ledger", 488, () => OpenPanel("ledger"), HexUI.Cream);
- bool privacy = Ads != null && Ads.NeedsPrivacyOptions;
- if (privacy) SettingsLink(c, "AdPrivacy", "Ad privacy options", 569, Ads.ShowPrivacyOptions, HexUI.Cream);
- SettingsLink(c, "ResetSave", "Reset save", privacy ? 650 : 569, () => OpenPanel("reset"), HexUI.ColorOf("FFA3A8"));
- HexUI.Text(c, "GameInfo", "3 MODES · 60 LEVELS", 310, 747, 530, 32, 18, false, HexUI.Muted);
- Footer("DONE",ClosePanel);
- }
- void AddSettingSwitch(Transform parent, string name, string label, string icon, float y, bool enabled, Action toggle)
- {
- var row = HexUI.Button(parent, name, "", 310, y, 568, 96, () =>
- {
- toggle();
- Profile.Save();
- SyncAudio();
- Reopen("settings");
- }, null);
- HexUI.Image(row.transform, "Icon", icon, 48, 48, 61, 61);
- LeftText(row.transform, "SettingName", label, 104, 48, 263, 50, 28);
- var track = HexUI.Image(row.transform, "Switch", "switch_track", 494, 48, 124, 48, enabled ? Color.white : HexUI.Muted);
- row.targetGraphic = track;
- HexUI.Image(track.transform, "Thumb", enabled ? "chip_teal" : "holder", enabled ? 98 : 26, 24, 32, 32);
- HexUI.Text(track.transform, "Value", enabled ? "ON" : "OFF", enabled ? 46 : 79, 24, 57, 30, 20);
- Hairline(parent, 310, y + 55, 550);
- }
- static void SettingsLink(Transform parent, string name, string label, float y, Action action, Color ink)
- {
- var row = HexUI.Button(parent, name, "", 310, y, 558, 78, action, null);
- row.targetGraphic = LeftText(row.transform, "Label", label, 9, 39, 461, 47, 25, false, ink);
- var arrow = HexUI.Image(row.transform, "Chevron", "icon_back", 533, 39, 17, 22, ink);
- arrow.rectTransform.localScale = new Vector3(-1, 1, 1);
- Hairline(parent, 310, y + 40, 550);
- }
- void PausePanel()
- {
- 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);
- HexUI.Button(c,"Resume","RESUME",310,306,520,100,ClosePanel,"primary",42,true);
- 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);
- HexUI.Button(c,"ReturnLobby","BACK TO LOBBY",310,590,520,92,LeaveGame,"panel",33,true);
- PText(c,"Used power-ups are not refunded.",705,40,20);
- }
- void ResultPanel()
- {
- var round = Game;
- int mode = round.Spec.mode, level = round.Spec.level;
- bool timedOut = resultTitle == "TIME UP";
- HexUI.Text(modal, "ResultLevel", LevelDatabase.ModeNames[mode] + " · LEVEL " + level, 375, 187, 500, 34, 22, false, HexUI.Gold);
- HexUI.Text(modal, "PanelTitle", resultWin ? "TABLE CLEARED" : resultTitle, 375, 249, 555, 80, 56, true);
- var c = Content();
- string art = resultWin ? "result_trophy" : timedOut ? "result_hourglass" : "result_hive";
- HexUI.Image(c, "ResultIcon", art, 310, 144, 225, 225);
- Hairline(c, 108, 144, 116);
- Hairline(c, 512, 144, 116);
- ResultStat(c, "SCORE", round.Score, 108);
- ResultStat(c, "TARGET", round.Spec.target, 310);
- ResultStat(c, "CLEARS", round.Clears, 512);
- HexUI.Image(c, "ProgressTrack", "bar", 310, 435, 520, 20);
- HexUI.Fill(c, "ScoreProgress", 310, 435, 510, 10).Value = (float)round.Score / round.Spec.target;
- if (resultWin)
- {
- HexUI.Text(c, "RewardHeading", "REWARDS", 310, 548, 350, 42, 27, true);
- var plaque = HexUI.Image(c, "RewardPlaque", "dock_frame", 310, 655, 585, 133);
- ResultReward(plaque.transform, "reward_coins", resultCoins, "COINS", resultTicket > 0 ? 114 : 229);
- if (resultTicket > 0) ResultReward(plaque.transform, "reward_ticket", resultTicket, "DRAW TICKET", 340);
- }
- else
- {
- HexUI.Text(c, "OutcomeDetail", timedOut ? "Time ran out before you reached the target." :
- "There are no open cells for your next group.", 310, 563, 510, 72, 28);
- if (!round.ReviveUsed && Ads != null && Ads.Supported)
- {
- string effect = timedOut ? "+30 SECONDS" : "FREE 3 CELLS";
- if (timedOut && !round.Cells.Any(cell => cell.need <= round.Score && cell.tiles.Count == 0))
- effect = "+30 SECONDS · FREE 3 CELLS";
- BindAdButton(HexUI.Button(c, "AdRevive", "WATCH AD TO REVIVE\n" + effect, 310, 685, 535, 93,
- () => WatchReward("result", null, "Back in play", () => ResumeRound(round)), "panel", 26));
- }
- else HexUI.Text(c, "RewardStatus", "No reward this round.", 310, 647, 500, 42, 21, false, HexUI.Muted);
- }
- var back = HexUI.Button(modal, "Footer_BACK", "", 193, 1144, 181, 82, LeaveGame, null);
- HexUI.Image(back.transform, "BackArrow", "icon_back", 38, 41, 22, 25);
- back.targetGraphic = HexUI.Text(back.transform, "Label", "BACK", 107, 41, 116, 46, 26);
- string next = resultWin ? (level == 20 ? "REPLAY LV 20" : "NEXT LEVEL") : "RETRY";
- HexUI.Button(modal, "Footer_" + next, next, 480, 1144, 360, 84,
- () => { CloseAll(); StartLevel(mode, resultWin ? Math.Min(20, level + 1) : level); }, "primary", 32, true);
- }
- static void ResultStat(Transform parent, string label, int value, float x)
- {
- HexUI.Text(parent, label + "Label", label, x, 318, 178, 35, 21, false, HexUI.Muted);
- HexUI.Text(parent, label + "Value", value.ToString("N0"), x, 375, 180, 66, 46, true);
- }
- static void ResultReward(Transform parent, string icon, int amount, string label, float x)
- {
- HexUI.Image(parent, icon, icon, x, 66, 60, 60);
- LeftText(parent, label + "Amount", "+" + amount.ToString("N0"), x + 42, 52, 132, 45, 35, true);
- LeftText(parent, label + "Label", label, x + 43, 90, 133, 33, 18);
- }
- void ResumeRound(HexRules round)
- {
- if (Game != round || !round.TryRevive()) return;
- CloseAll();
- finished = Busy = hammer = false;
- resumedFrame = Time.frameCount;
- SelectedSlot = activePointerSlot = -1;
- if (dragGhost != null) Destroy(dragGhost.gameObject);
- dragGhost = null;
- hintText.text = "DRAG TO AN EMPTY CELL";
- DrawBoard(); DrawHand(); DrawDock(); UpdateHud();
- }
- void ResetPanel()
- {
- var c=Content();HexUI.Image(c,"ResetIcon","icon_close",310,160,110,110);PText(c,"RESET ALL PROGRESS?",310,100,43,true);
- PText(c,"This clears coins, items, all mode progress,\ncheck-in history and player statistics.\nThis cannot be undone.",482,180,27);
- Footer("CANCEL",ClosePanel,"RESET",()=>{Profile.Reset();CloseAll();SyncAudio();ShowLobby();Toast("Save reset");});
- }
- static readonly string[] Steps={
- "THREE GROUPS AT A TIME|Each hand has three single-color groups of 2–4 tiles. Place all three before the next hand arrives.",
- "DRAG OR TAP|Drag a whole group onto the board. You can also tap a hand group, then tap a cell.",
- "EMPTY CELLS ONLY|You cannot place on any existing stack, even if its color matches. Locked cells are unavailable.",
- "MERGE AND CLEAR|Adjacent matching top colors merge automatically. Eight or more consecutive matching tiles clear together.",
- "LOCKS AND LAYERS|Score opens locked cells. Mixed starting stacks reveal another color when their top segment moves away.",
- "SCORE AND CHAIN|Each placed tile earns 2 points. Eight tiles clear for 60 points; extras add 12 each. Successive clears multiply the reward.",
- "NEIGHBOR BONUS|A clear adds a tile to each matching neighboring top. This can start another chain. Reach the target score to win.",
- "KEEP ROOM TO PLAY|A full board ends the game after settlement. Time Rush also ends when time expires; each clear adds four seconds."
- };
- static readonly string[] Faqs={
- "How do I play?|Place groups in empty cells next to the same color. Let automatic merges make room.",
- "When does a stack clear?|A continuous run of at least eight matching tiles is collected.",
- "Can I stack different colors?|No. Hand groups only go into empty cells. Mixed stacks are starting obstacles.",
- "Why can I not drop here?|The cell is occupied, locked, or an animation is still settling.",
- "How do locks open?|The number shows points still needed. Reach that score or use UNLOCK.",
- "What are mixed starting stacks?|They contain two colors. Only the top matching segment can move during a merge.",
- "How do chains work?|Multiple clears from one move increase the score multiplier to ×2, ×3 and beyond.",
- "How do I win?|Reach the target score. Each mode has twenty levels and saves progress separately.",
- "When do I lose?|When no unlocked empty cell remains after settlement, or the Time Rush clock reaches zero.",
- "Where do coins come from?|The welcome gift, wins, check-in and Lucky Draw. Coins buy power-ups and have no cash value.",
- "Where is my progress?|On this device only. There is no account or cloud sync. Active games are not saved."
- };
- void HelpPanel()
- {
- HelpTab("HOW TO PLAY", false, 228);
- HelpTab("FAQ", true, 522);
- if (helpShowsFaq) BuildFaqList();
- else
- {
- const float rowHeight = 174;
- var c = Content(16 + Steps.Length * rowHeight, 85);
- for (int i = 0; i < Steps.Length; i++)
- {
- float y = 10 + i * rowHeight;
- var parts = Steps[i].Split('|');
- HexUI.Text(c, "Number", (i+1).ToString("00"), 60, y + 38, 76, 53, 35, true);
- LeftText(c, "StepTitle", parts[0], 118, y + 37, 468, 43, 26, true);
- LeftText(c, "StepBody", parts[1], 118, y + 109, 466, 89, 22);
- Hairline(c, 310, y + 165, 552);
- }
- }
- Footer("GOT IT",ClosePanel);
- }
- void HelpTab(string label, bool faq, float x)
- {
- var tab = HexUI.Button(modal, "Tab_" + label, "", x, 332, 282, 65, () =>
- {
- if (helpShowsFaq == faq) return;
- helpShowsFaq = faq;
- Reopen("help");
- }, null);
- bool active = helpShowsFaq == faq;
- tab.targetGraphic = HexUI.Text(tab.transform, "Label", label, 141, 28, 256, 43, 25, false, active ? HexUI.Cream : HexUI.Muted);
- HexUI.Image(tab.transform, "Underline", null, 141, 61, 266, active ? 4 : 1.5f, active ? HexUI.Gold : HexUI.ColorOf("825B59"));
- }
- void BuildFaqList()
- {
- const float questionHeight = 76, answerHeight = 92;
- var c = Content(24 + Faqs.Length * questionHeight + faqOpen.Count(open => open) * answerHeight, 85);
- float y = 10;
- for (int i = 0; i < Faqs.Length; i++)
- {
- int index = i;
- var parts = Faqs[i].Split('|');
- var question = HexUI.Button(c, "FAQ_" + i, "", 310, y + questionHeight / 2, 572, questionHeight, () =>
- {
- float offset = c.anchoredPosition.y;
- faqOpen[index] = !faqOpen[index];
- Reopen("help");
- var list = modal.GetComponentInChildren<ScrollRect>();
- list.content.anchoredPosition = new Vector2(list.content.anchoredPosition.x,
- Mathf.Clamp(offset, 0, Mathf.Max(0, list.content.rect.height - list.viewport.rect.height)));
- }, null);
- question.targetGraphic = LeftText(question.transform, "Question", parts[0], 8, 38, 506, 60, 23);
- HexUI.Text(question.transform, "Toggle", faqOpen[i] ? "−" : "+", 548, 38, 40, 48, 31, false, HexUI.Gold);
- y += questionHeight;
- if (faqOpen[i])
- {
- LeftText(c, "Answer", parts[1], 45, y + 40, 527, 83, 21, false, HexUI.Muted);
- y += answerHeight;
- }
- Hairline(c, 310, y, 552);
- }
- }
- }
- }
|