using System; using UnityEngine; using UnityEngine.UI; namespace TowerDevil { public sealed partial class TowerGame { RectTransform sheetBody; Action sheetDismissed; Action refreshMusicSwitch; float bodyY; const int BodyW = 510; void ShowOver() { KeepScene("Over", "breach"); KeepLayer(page, "defendBanner", 44, 374, 662, 115); KeepText(page, "GATE BROKEN", 96, 381, 558, 61, 46); KeepText(page, "THE LORD BELOW IS FREE", 120, 472, 510, 42, 21); var ledger = Panel(page, "Run results", 64, 540, 622, 345, "33251F", "A7824F", 12, "151315").transform; KeepText(ledger, "SCORE", 180, 16, 262, 29, 20).color = Gold; KeepText(ledger, run.Score.ToString("N0"), 36, 46, 550, 66, 51); Solid(ledger, "Rule", 32, 122, 558, 1, Hex("7E5B39")); ResultStat(ledger, 27, "shield", "Night reached", run.Day); ResultStat(ledger, 225, "swords", "Demons slain", run.Kills); ResultStat(ledger, 423, "tower", "Towers forged", run.Forged); Solid(ledger, "Rule", 32, 256, 558, 1, Hex("7E5B39")); DrawPart(ledger, "coins", 40, 273, 51, 49, true); KeepText(ledger, "Coins earned", 105, 266, 171, 32, 19, TextAnchor.MiddleLeft); KeepText(ledger, "+" + run.Earned, 105, 297, 171, 37, 26, TextAnchor.MiddleLeft); DrawPart(ledger, "shard", 332, 273, 49, 49, true); KeepText(ledger, "Soul shards", 399, 266, 173, 32, 19, TextAnchor.MiddleLeft); KeepText(ledger, "+" + run.EarnedShards, 399, 297, 173, 37, 26, TextAnchor.MiddleLeft); InscribedButton(page, run.UsedCoinRevive ? "COIN REVIVE USED" : "REVIVE · 300 COINS", 57, 919, 308, 81, () => Revive(false), enabled: !run.UsedCoinRevive && run.Available >= 300); InscribedButton(page, run.UsedAdRevive ? "AD REVIVE USED" : "REVIVE · WATCH AD", 385, 919, 308, 81, () => Ad(() => Revive(true)), enabled: !run.UsedAdRevive); InscribedButton(page, "TRY AGAIN", 176, 1030, 398, 106, StartGame, primary: true, font: 36); InscribedButton(page, "BACK TO LOBBY", 235, 1156, 280, 70, ShowLobby); } void ResultStat(Transform parent, int x, string icon, string label, int value) { DrawPart(parent, icon, x + 64, 132, 46, 42, true); KeepText(parent, label, x, 178, 172, 30, 19); KeepText(parent, value.ToString("N0"), x, 208, 172, 42, 28); } void Revive(bool ad) { if (run.Revive(ad)) ShowBattle(); } void CloseSheet() { Remove(modal); modal = null; sheetBody = null; sheetDismissed = null; refreshMusicSwitch = null; } void DismissSheet() => (sheetDismissed ?? CloseSheet)(); void FitModalVeil() { var veil = (RectTransform)modal.GetChild(0); Vector2 topLeft = modal.InverseTransformPoint(screen.TransformPoint(new Vector2(screen.rect.xMin, screen.rect.yMax))); Vector2 bottomRight = modal.InverseTransformPoint(screen.TransformPoint(new Vector2(screen.rect.xMax, screen.rect.yMin))); veil.anchoredPosition = topLeft; veil.sizeDelta = new Vector2(bottomRight.x - topLeft.x, topLeft.y - bottomRight.y); } void Sheet(string title, Action contents, string footer = "CLOSE", Action footAction = null, bool closable = true, Action onDismiss = null, string skin = "citadel", int scrollBottomGap = 22) { LoadKeepArt(); OpenKeepVeil(); sheetDismissed = onDismiss; var frameArt = KeepLayer(modal, skin, 43, 144, 664, 1044); frameArt.name = title; float top = -frameArt.rectTransform.anchoredPosition.y; float height = frameArt.rectTransform.rect.height; float titleCenter = top + height * (skin == "citadel" ? .19f : skin == "vault" ? .208f : .20f); float viewTop = titleCenter + 59, footerY = top + height - 170; float viewHeight = footerY - scrollBottomGap - viewTop; KeepText(modal, title, 154, titleCenter - 33, 442, 66, 40); if (closable) ArtButton(modal, "×", "close", 615, (int)titleCenter - 63, 65, 65, DismissSheet); var vp = Box(modal, "Scroll area", (750 - BodyW) / 2, viewTop, BodyW, viewHeight); var scroll = vp.gameObject.AddComponent(); scroll.horizontal = false; scroll.movementType = ScrollRect.MovementType.Clamped; scroll.scrollSensitivity = 34; vp.gameObject.AddComponent(); var surface = vp.gameObject.AddComponent(); surface.color = Color.clear; surface.raycastTarget = true; sheetBody = Box(vp, "Contents", 0, 0, BodyW, viewHeight); scroll.viewport = vp; scroll.content = sheetBody; bodyY = 6; contents(); sheetBody.sizeDelta = new Vector2(BodyW, Mathf.Max(viewHeight, bodyY + 6)); scroll.vertical = bodyY + 6 > viewHeight; Solid(modal, "Footer rule", 123, footerY - 12, 504, 1, Hex("765738")); InscribedButton(modal, footer, 184, footerY, 382, 100, footAction ?? DismissSheet, primary: true, font: 28); } Button InscribedButton(Transform parent, string caption, float x, float y, float w, float h, Action action, bool primary = false, bool enabled = true, int font = 22) { var button = Hotspot(parent, caption, x, y, w, h, action); var face = DrawPart(button.transform, primary ? "play" : "bronze", 0, 0, w, h, true); button.targetGraphic = face; button.transition = Selectable.Transition.ColorTint; var colors = button.colors; colors.pressedColor = Hex("C59A76"); colors.disabledColor = Hex("73665C"); button.colors = colors; button.interactable = enabled; var size = face.rectTransform.sizeDelta; var label = KeepText(face.transform, caption, 12, 2, size.x - 24, size.y - 6, font); label.resizeTextForBestFit = false; float fit = Mathf.Min(1f, (size.x - 28) / Mathf.Max(1, label.preferredWidth)); label.fontSize = Mathf.Max(1, Mathf.FloorToInt(font * fit)); if (!enabled) label.color = Hex("C2AF9A"); return button; } void Note(string value, float height = 78) { KeepText(sheetBody, value, 12, bodyY, BodyW - 24, height, 23, TextAnchor.MiddleLeft).fontStyle = FontStyle.Normal; bodyY += height + 8; } void Stat(string k, string v, string icon = null) { int left = icon == null ? 10 : 61; if (icon != null) DrawPart(sheetBody, icon, 12, bodyY + 6, 38, 40, true); KeepText(sheetBody, k, left, bodyY, 314 - left, 52, 23, TextAnchor.MiddleLeft); KeepText(sheetBody, v, 315, bodyY, BodyW - 325, 52, 24, TextAnchor.MiddleRight).color = Gold; Solid(sheetBody, "Divider", 9, bodyY + 53, BodyW - 18, 1, Hex("634B35")); bodyY += 57; } void Choice(string label, Action action, bool enabled = true) { InscribedButton(sheetBody, label, 42, bodyY, BodyW - 84, 76, action, enabled: enabled); bodyY += 82; } void Product(int tier, int price, Action action, bool enabled) { const int inset = 36, cardWidth = BodyW - 2 * inset; var card = Panel(sheetBody, "Supply", inset, bodyY, cardWidth, 90, "372820", "765739", 8, "1A1717").transform; DrawPart(card, ChestIcons[tier - 1], 12, 8, 65, 74, true); KeepText(card, Rules.ChestNames[tier - 1], 85, 9, 178, 41, 23, TextAnchor.MiddleLeft); KeepText(card, "+" + Rules.ChestMoves[tier - 1] + " moves", 85, 48, 178, 35, 20, TextAnchor.MiddleLeft).color = Gold; InscribedButton(card, price + " COINS", cardWidth - 168, 15, 156, 60, action, enabled: enabled, font: 18); bodyY += 97; } void FeatureStat(string icon, string label, string value) { DrawPart(sheetBody, icon, 21, bodyY + 7, 78, 70, true); KeepText(sheetBody, label, 119, bodyY + 2, BodyW - 147, 32, 19, TextAnchor.MiddleLeft).color = Gold; KeepText(sheetBody, value, 118, bodyY + 32, BodyW - 146, 52, 39, TextAnchor.MiddleLeft); Solid(sheetBody, "Rule", 9, bodyY + 93, BodyW - 18, 1, Hex("8D6B43")); bodyY += 106; } void PauseSheet() { if (animating || run.Phase == Phase.RestChoice) return; OpenCompactMenu("PAUSED", extraHeight: 266); PauseStat(124, "swords", "NIGHT", run.Day.ToString()); PauseStat(293, "crown", "SCORE", run.Score.ToString("N0")); PauseStat(462, "shield", "SEAL", run.Plates + " / " + run.MaxPlates); int towers = 0; foreach (var piece in run.Board) if (piece?.Tower == true) towers++; Solid(modal, "Ledger rule", 130, 545, 490, 1, Hex("705238")); KeepText(modal, "Moves left", 123, 554, 242, 30, 21); KeepText(modal, run.Phase == Phase.Rest ? "Unlimited" : run.Moves.ToString(), 123, 580, 242, 40, 27); KeepText(modal, "Gear on board", 385, 554, 242, 30, 21); KeepText(modal, towers.ToString(), 385, 580, 242, 40, 27); Solid(modal, "Settings rule", 130, 632, 490, 1, Hex("705238")); SettingsRows(645, 78); var resume = ArtButton(modal, "RESUME", "play", 205, 894, 340, 90, CloseSheet); KeepText(resume.transform, "RESUME", 14, 5, 312, 75, 34); var help = LayeredButton(modal, "HOW TO PLAY", "walletPlate", 147, 994, 212, 71, Help); KeepText(help.transform, "HOW TO PLAY", 8, 7, 196, 54, 20); var end = LayeredButton(modal, "END RUN", "walletPlate", 391, 994, 212, 71, ConfirmEndRun); KeepText(end.transform, "END RUN", 8, 7, 196, 54, 20); } void PauseStat(int x, string icon, string caption, string value) { DrawPart(modal, icon, x + 57, 411, 50, 48, true); KeepText(modal, caption, x, 462, 164, 30, 19).color = Gold; KeepText(modal, value, x, 491, 164, 48, 34); } void ConfirmEndRun() { OpenCompactMenu("END THIS RUN?", onDismiss: PauseSheet); DrawPart(modal, "coins", 330, 551, 90, 74, true); KeepText(modal, "Return to your keep and bank this run’s earnings.", 136, 640, 478, 87, 26); InscribedButton(modal, "END RUN & BANK", 194, 755, 362, 94, () => { run.Quit(); ShowLobby(); }, primary: true, font: 27); InscribedButton(modal, "BACK", 267, 866, 216, 66, PauseSheet); } void RestSheet() { Sheet("BOSS SLAIN", () => { FeatureStat("crown", "BOSS DEFEATED", "Night " + run.Day); Note("Take a rest night to rearrange your defence and repair the seal.", 77); Stat("Moves", "Unlimited", "boots"); Stat("New material", "None", "hammer"); Stat("After DONE", "Horde attacks", "swords"); Choice("KEEP FIGHTING", () => { run.ChooseRest(false); ShowBattle(); }); }, "TAKE REST NIGHT", () => { run.ChooseRest(true); ShowBattle(); }, false, skin: "profile"); } void SealSheet() { if (animating) return; bool rest = run.Phase == Phase.Rest; int cost = 500 + 250 * (profile.gateLevel - 1); Sheet("GATE SEAL", () => { FeatureStat("shield", "SEAL INTEGRITY", run.Plates + " / " + run.MaxPlates); Stat("Permanent level", profile.gateLevel + " / 8", "tower"); Stat("Coins", run.Available.ToString(), "coins"); Note(rest ? "Restore two stones or permanently raise the seal limit." : "A rewarded video can mend two stones once per run. Coin repairs and upgrades open on a rest night."); Choice("MEND +2 · 200 COINS", () => { run.Repair(false); RefreshHud(); SealSheet(); }, rest && run.Plates < run.MaxPlates && run.Available >= 200); Choice("MEND +2 · WATCH AD", () => WatchRepairAd(true), run.CanWatchRepairAd); Choice("UPGRADE · " + cost + " COINS", () => { run.UpgradeGate(); RefreshHud(); SealSheet(); }, rest && profile.gateLevel < 8 && run.Available >= cost); }); } void WatchRepairAd(bool returnToSeal) { var damagedRun = run; if (!damagedRun.CanWatchRepairAd) return; Ad(() => { if (run != damagedRun || !run.Repair(true)) return; RefreshHud(); if (returnToSeal) SealSheet(); }); } void GearSheet(int r, int c) { var p = run.Board[r, c]; int index = (int)p.Kind - (int)Kind.Cannon; string[] tips = { "Fires along one side of this row. All targets on that side are hit.", "Fires up or down this lane, including the approach to the board.", "Targets the nearest demon in the surrounding 3 × 3 area.", "Slows every demon on its square by half for one second." }; Sheet(p.Kind.ToString().ToUpperInvariant(), () => { var icon = Image(sheetBody, p.Art, p.Art, (BodyW - 142) / 2, 3, 142, 126); if (pieces.TryGetValue(p, out var figure)) icon.uvRect = figure.uvRect; bodyY = 134; Note(tips[index]); Stat("Tier", p.Tier + " / 3", "tower"); Stat("Damage", Rules.Damage[index, p.Tier - 1].ToString(), "swords"); Stat("Cooldown", Rules.Cooldown[index].ToString("0.00") + " s", "scope"); bodyY += 28; Choice("DEMOLISH · +25 COINS", () => { CloseSheet(); run.Demolish(r, c); PlayBoard(); }); }, "KEEP"); } void Merchant() { if (animating || tutorial >= 0 || run.Phase == Phase.RestChoice) return; Sheet("MERCHANT", () => { FeatureStat("coins", "AVAILABLE COINS", run.Available.ToString("N0")); for (int i = 0; i < 3; i++) { int tier = i + 1; int price = Rules.ChestPrice[i]; Product(tier, price, () => { if (run.BuyChest(tier)) { CloseSheet(); PlayBoard(); Toast("CHEST PURCHASED"); } }, run.CanArrange && run.Available >= price); } bodyY += 16; Choice(run.UsedTowerAd ? "TOWER CLAIMED" : "RANDOM TOWER · WATCH AD", () => Ad(() => { if (run.AdTower()) PlayBoard(); else Toast("NO SPACE FOR A TOWER"); }), run.CanArrange && !run.UsedTowerAd); }, skin: "vault", scrollBottomGap: 6); } static long Now => DateTimeOffset.UtcNow.ToUnixTimeSeconds(); static long WaitForAd(long last) => Math.Max(0, last + 21600 - Now); static string AdLabel(string reward, long wait) => wait == 0 ? reward : "AVAILABLE IN " + TimeSpan.FromSeconds(wait).ToString(@"hh\:mm"); void CoinStore() { Sheet("COIN STORE", () => { FeatureStat("coins", "WALLET BALANCE", profile.coins.ToString("N0")); Choice("CHEST VAULT", Vault); long wait = WaitForAd(profile.lastCoinAd); Choice(AdLabel("WATCH AD · +120 COINS", wait), () => Ad(() => { if (WaitForAd(profile.lastCoinAd) == 0) { profile.lastCoinAd = Now; profile.coins += 120; profile.Record(120, "Rewarded ad"); profile.Save(); } ShowLobby(); CoinStore(); }), wait == 0); Note("Coin packs are a preview in this edition.", 64); if (profile.ledger.Count > 0) { KeepText(sheetBody, "RECENT TRANSACTIONS", 12, bodyY, BodyW - 24, 37, 20, TextAnchor.MiddleLeft).color = Gold; bodyY += 42; } foreach (string entry in profile.ledger) Note(entry, 45); }, skin: "vault"); } void Rank(bool byScore) { DrawRank(byScore, null); var loading = modal; GameCenterRanks.Load(byScore, profile, result => { if (this && loading && modal == loading) DrawRank(byScore, result); }); } void DrawRank(bool byScore, RankResult result) { Sheet(byScore ? "TOTAL SCORE" : "BEST NIGHT", () => { Choice(byScore ? "SHOW BY NIGHT" : "SHOW BY SCORE", () => Rank(!byScore)); if (result == null) { Note("Loading standings…"); return; } if (!string.IsNullOrEmpty(result.error)) { Note(result.error, 108); Choice("RETRY", () => Rank(byScore)); return; } if (result.entries == null || result.entries.Length == 0) { Note("No scores yet. Finish a run to enter the rankings."); return; } foreach (var row in result.entries) { if (row.mine) Panel(sheetBody, "Your standing", 1, bodyY, BodyW - 2, 58, "443122", "AC814D", 5, "2B201B"); if (row.rank == 1) DrawPart(sheetBody, "crown", 9, bodyY + 8, 45, 40, true); else KeepText(sheetBody, row.rank.ToString(), 4, bodyY, 66, 58, 23).color = Gold; var name = KeepText(sheetBody, row.name + (row.mine ? " (you)" : ""), 73, bodyY, 235, 58, 23, TextAnchor.MiddleLeft); name.supportRichText = false; KeepText(sheetBody, (byScore ? "" : "Night ") + row.score.ToString("N0"), 313, bodyY, 183, 58, 23, TextAnchor.MiddleRight).color = Gold; Solid(sheetBody, "Rank rule", 12, bodyY + 58, BodyW - 24, 1, Hex("5E4936")); bodyY += 63; } }, skin: "profile"); } void Help() { Sheet("HOW TO PLAY", () => { for (int i = 0; i < GuideTitle.Length; i++) { DrawPart(sheetBody, GuideIcons[i], 9, bodyY + 2, 44, 46, true); KeepText(sheetBody, (i + 1) + ". " + GuideTitle[i], 67, bodyY, BodyW - 80, 48, 23, TextAnchor.MiddleLeft).color = Gold; bodyY += 50; Note(GuideBody[i], 86); Solid(sheetBody, "Guide rule", 12, bodyY, BodyW - 24, 1, Hex("614831")); bodyY += 14; } Note("A normal demon breaks one seal stone. A Boss reaching the gate breaks the entire seal.", 82); }, "BACK", onDismiss: PauseSheet); } } }