BattleView.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace TowerDevil
  6. {
  7. public sealed partial class TowerGame
  8. {
  9. RectTransform tiles, monsters, fx, shieldPips, guide, actionArea;
  10. RectTransform hud, boardStage, battleFooter, fieldClip;
  11. CourtyardBackdrop courtyard;
  12. PieceShadows pieceShadows;
  13. readonly Dictionary<string, Sprite> courtSprites = new Dictionary<string, Sprite>();
  14. GateFractures gateFractures;
  15. Vector2 fractureOrigin;
  16. BattleEffects battleEffects;
  17. IronPanel turnDot, turnStrip;
  18. readonly Dictionary<Piece, RawImage> pieces = new Dictionary<Piece, RawImage>();
  19. readonly Dictionary<Foe, FoeView> foes = new Dictionary<Foe, FoeView>();
  20. readonly List<Foe> gone = new List<Foe>();
  21. readonly Queue<BoardFrame> frames = new Queue<BoardFrame>();
  22. Text movesLabel, sealLabel, nightLabel, coinLabel, shardLabel, turnLabel, waveLabel, waitLabel, leftLabel;
  23. RectTransform waveFill;
  24. bool animating, assaultTint;
  25. float nextAttack = -1, tickRemainder, forecastTime;
  26. int lastPlates = -1, lastMaxPlates = -1, lastDay = -1;
  27. Phase lastPhase;
  28. Coroutine playback;
  29. static readonly string[] GuideTitle = { "DRAG TO SWAP", "THREE IN A LINE", "FORGE A STRONGER TOWER",
  30. "GOLD MAKES CHESTS", "LET THEM COME" };
  31. static readonly string[] GuideBody = {
  32. "Drag a piece onto a neighbouring square to spend one move.",
  33. "Match stone, wood, crystal or ice to forge its tower. Watch where the pieces fall.",
  34. "Line up three towers of the same kind and tier to upgrade one.",
  35. "Match three gold piles for a chest. Tap it for moves, or line up three chests to upgrade.",
  36. "Finish arranging the board, then call the horde. Your towers fire automatically."
  37. };
  38. void StartGame()
  39. {
  40. profile.played = true;
  41. profile.Save();
  42. AttachRun(new Run(profile, System.Environment.TickCount));
  43. tutorial = profile.tutorialDone ? -1 : 0;
  44. ShowBattle();
  45. }
  46. void AttachRun(Run next)
  47. {
  48. if (playback != null)
  49. {
  50. StopCoroutine(playback);
  51. playback = null;
  52. }
  53. frames.Clear();
  54. animating = false;
  55. tickRemainder = 0;
  56. if (run != null)
  57. {
  58. run.Fired -= OnFire;
  59. run.Hit -= OnHit;
  60. run.StruckGate -= OnGateHit;
  61. run.BoardChanged -= frames.Enqueue;
  62. }
  63. run = next;
  64. run.Fired += OnFire;
  65. run.Hit += OnHit;
  66. run.StruckGate += OnGateHit;
  67. run.BoardChanged += frames.Enqueue;
  68. }
  69. #if UNITY_EDITOR
  70. public void EditorReview()
  71. {
  72. // This fixture never writes to the player's local profile.
  73. profile = new Profile { played = true, tutorialDone = true, auth = "guest" };
  74. var review = new Run(profile, 404);
  75. review.SetReviewBoard();
  76. profile.shards = 0;
  77. AttachRun(review);
  78. tutorial = -1;
  79. ShowBattle();
  80. }
  81. #endif
  82. void ShowBattle()
  83. {
  84. battleFooter = null;
  85. NewPage("Run");
  86. pieces.Clear();
  87. foes.Clear();
  88. motionTime = 0;
  89. gateHitTime = -1;
  90. nextMotionSeed = 0;
  91. lastPlates = -1;
  92. guide = null;
  93. if (courtSprites.Count == 0)
  94. foreach (var sprite in Resources.LoadAll<Sprite>("DevilArt/Courtyard"))
  95. courtSprites.Add(sprite.name, sprite);
  96. courtyard = Box(page, "Basalt courtyard", 0, 0, 1000, 1334).gameObject.AddComponent<CourtyardBackdrop>();
  97. courtyard.SetPainting(Art("Courtyard/backdrop"));
  98. gateFractures = Box(courtyard.transform, "Gate fractures", 0, 0, 0, 0).gameObject.AddComponent<GateFractures>();
  99. gateFractures.raycastTarget = false;
  100. boardStage = Box(page, "Battlefield", 0, 0, BoardLayout.Width, BoardLayout.Height);
  101. shieldPips = Box(boardStage, "Seal stones", 230, -92, 290, 35);
  102. turnStrip = Round(boardStage, "Turn strip", 33, -47, 684, 33, "261D20", "75605A", 16, "171114");
  103. assaultTint = false;
  104. turnDot = Round(turnStrip.transform, "Phase light", 20, 11, 12, 12, "A4F09D", "366439", 6, "5FC56F");
  105. turnLabel = Label(turnStrip.transform, "YOUR TURN", 46, 0, 223, 33, 17, Ink);
  106. waitLabel = Label(turnStrip.transform, "", 247, 0, 418, 33, 16, Hex("FFDA89"), TextAnchor.MiddleRight);
  107. var pieceWindow = Box(boardStage, "Piece viewport", 0, -10, BoardLayout.Width, BoardLayout.Height + 27);
  108. pieceWindow.gameObject.AddComponent<RectMask2D>();
  109. pieceShadows = Box(pieceWindow, "Contact shadows", 0, 10, BoardLayout.Width, BoardLayout.Height)
  110. .gameObject.AddComponent<PieceShadows>();
  111. pieceShadows.raycastTarget = false;
  112. pieceShadows.Bind(pieces);
  113. tiles = Box(pieceWindow, "Pieces", 0, 10, BoardLayout.Width, BoardLayout.Height);
  114. fieldClip = Box(boardStage, "Visible battlefield", 0, -15, 750, 850);
  115. fieldClip.gameObject.AddComponent<RectMask2D>();
  116. monsters = Box(fieldClip, "Horde", 0, 15, 750, 1334);
  117. fx = Box(boardStage, "Effects", 0, 0, 750, 1334);
  118. battleEffects = fx.gameObject.AddComponent<BattleEffects>();
  119. battleEffects.raycastTarget = false;
  120. var input = Solid(boardStage, "Board input", 0, 0, BoardLayout.Width, BoardLayout.Height, Color.clear, true)
  121. .gameObject.AddComponent<BoardInput>();
  122. input.Game = this;
  123. BuildBattleHud();
  124. battleFooter = Box(page, "Battle footer", 0, 1221, 750, 113);
  125. waveLabel = Label(battleFooter, "", 26, 0, 125, 35, 17, Ink);
  126. Round(battleFooter, "Wave track", 145, 13, 454, 10, "3A292C", "49353A", 5, "2A1C20");
  127. waveFill = Round(battleFooter, "Wave progress", 145, 13, 1, 10, "FFD473", "CD8D34", 5, "E59B38").rectTransform;
  128. leftLabel = Label(battleFooter, "", 606, 0, 116, 35, 17, Muted, TextAnchor.MiddleRight);
  129. actionArea = Box(battleFooter, "Actions", 0, 41, 750, 64);
  130. SideAction("SHOP", "shop", 20, Merchant);
  131. SideAction("MENU", "menu", 544, PauseSheet);
  132. Fit();
  133. lastDay = run.Day;
  134. lastPhase = run.Phase;
  135. forecastTime = 6;
  136. DrawBoard(run.Board);
  137. RebuildAction();
  138. RefreshHud();
  139. DrawGuide();
  140. }
  141. void FitBattle(float safeHeight)
  142. {
  143. float extra = Mathf.Max(0, safeHeight - 1334);
  144. float boardY = 460 - extra * .19f;
  145. hud.anchoredPosition = new Vector2(0, extra * .5f);
  146. boardStage.anchoredPosition = new Vector2(0, -boardY);
  147. battleFooter.anchoredPosition = new Vector2(0, -1221 - extra * .5f);
  148. float laneEnd = -battleFooter.anchoredPosition.y - boardY;
  149. fieldClip.sizeDelta = new Vector2(750, laneEnd + 15);
  150. Vector2 topLeft = page.InverseTransformPoint(screen.TransformPoint(new Vector2(screen.rect.xMin, screen.rect.yMax)));
  151. Vector2 bottomRight = page.InverseTransformPoint(screen.TransformPoint(new Vector2(screen.rect.xMax, screen.rect.yMin)));
  152. float visibleWidth = 2 * Mathf.Max(375 - topLeft.x, bottomRight.x - 375) + 2;
  153. float width = Mathf.Max(1000, visibleWidth);
  154. var painting = courtyard.rectTransform;
  155. painting.anchoredPosition = new Vector2(375 - width * .5f, topLeft.y);
  156. painting.sizeDelta = new Vector2(width, topLeft.y - bottomRight.y);
  157. courtyard.Fit(topLeft.y + 138 - extra * .5f, topLeft.y + boardY - 66, visibleWidth);
  158. courtyard.RegisterFractures(gateFractures.rectTransform);
  159. fractureOrigin = gateFractures.rectTransform.anchoredPosition;
  160. }
  161. static IronPanel Round(Transform parent, string name, float x, float y, float w, float h, string face,
  162. string rim, float radius, string lower = null)
  163. {
  164. var plate = Panel(parent, name, x, y, w, h, face, rim, radius, lower);
  165. plate.rounded = true;
  166. plate.stroke = 2;
  167. return plate;
  168. }
  169. void BuildBattleHud()
  170. {
  171. hud = Box(page, "Warden HUD", 0, 0, 750, 118);
  172. Round(hud, "Portrait setting", 15, 1, 44, 42, "39251C", "F4B943", 14, "170F0D");
  173. Image(hud, "Warden portrait", "av_" + profile.avatar, 17, 2, 39, 39);
  174. var name = Label(hud, profile.name, 71, 0, 325, 43, 22, Ink);
  175. name.resizeTextForBestFit = true;
  176. name.resizeTextMinSize = 15;
  177. name.resizeTextMaxSize = 22;
  178. coinLabel = WalletPill("Gold", "ui_coin", 450, 94, "70404B", "FFCE65");
  179. shardLabel = WalletPill("Shards", "ui_gem", 554, 83, "34627C", "79D6FF");
  180. var pause = Round(hud, "Pause bezel", 693, 1, 46, 41, "22171C", "804452", 14, "120D10");
  181. for (int i = 0; i < 2; i++)
  182. Solid(pause.transform, "Pause bar", 17 + i * 9, 12, 5, 15, Ink);
  183. Hotspot(hud, "Pause battle", 674, 0, 74, 49, PauseSheet);
  184. movesLabel = StatCard("MOVES", 15, "FF7964", "B82E23", "F8AA91", "A33D2C", Color.white);
  185. sealLabel = StatCard("SEAL", 255, "FFDA5E", "C48812", "FFE49B", "BE8D29", Hex("442C0C"));
  186. nightLabel = StatCard("NIGHT", 497, "67C8FC", "1B67AC", "96D5FE", "357CAA", Color.white);
  187. Hotspot(hud, "Seal details", 255, 49, 230, 69, SealSheet);
  188. }
  189. Text WalletPill(string name, string icon, float x, float w, string border, string accent)
  190. {
  191. var pill = Round(hud, name, x, 1, w, 41, "21171A", border, 22, "0F0B10");
  192. var symbol = Image(pill.transform, icon, icon, 14, 10, 21, 21);
  193. symbol.uvRect = name == "Gold" ? new Rect(.17f, .17f, .66f, .66f) : new Rect(.20f, .18f, .6f, .64f);
  194. symbol.color = Hex(accent);
  195. var label = Label(pill.transform, "", 37, 0, w - 45, 41, 22, Hex(accent), TextAnchor.MiddleCenter);
  196. label.resizeTextForBestFit = true;
  197. label.resizeTextMinSize = 12;
  198. label.resizeTextMaxSize = 22;
  199. return label;
  200. }
  201. Text StatCard(string caption, float x, string hi, string lo, string rim, string inset, Color ink)
  202. {
  203. Round(hud, caption + " shadow", x, 53, 232, 68, "28171B", "241418", 21, "100B0E");
  204. var card = Round(hud, caption + " card", x, 49, 232, 68, hi, rim, 21, lo);
  205. card.stroke = 3;
  206. var badge = Round(card.transform, "Icon well", 15, 15, 40, 38, inset, inset, 12);
  207. if (caption == "SEAL")
  208. {
  209. Shield(badge.transform, 11, 9, 18, 19, "77501D", "513714");
  210. }
  211. else if (caption == "MOVES")
  212. Label(badge.transform, "⇄", 0, -1, 40, 38, 26, ink, TextAnchor.MiddleCenter);
  213. else
  214. {
  215. for (int i = 0; i < 8; i++)
  216. {
  217. var ray = Solid(badge.transform, "Sun ray", 20, 19, 3, 11, ink).rectTransform;
  218. ray.pivot = new Vector2(.5f, 0);
  219. ray.localRotation = Quaternion.Euler(0, 0, i * 45);
  220. }
  221. Round(badge.transform, "Sun", 13, 12, 14, 14, "FFF0D6", "FFF0D6", 7);
  222. }
  223. var value = Label(card.transform, "", 70, 4, 150, 34, 30, ink);
  224. Label(card.transform, caption, 71, 38, 145, 23, 14, ink);
  225. return value;
  226. }
  227. static void Shield(Transform parent, float x, float y, float width, float height, string top, string bottom)
  228. {
  229. var icon = Box(parent, "Seal stone", x, y, width, height).gameObject.AddComponent<SealIcon>();
  230. icon.raycastTarget = false;
  231. icon.top = Hex(top);
  232. icon.bottom = Hex(bottom);
  233. }
  234. void SideAction(string label, string glyph, float x, System.Action callback)
  235. {
  236. var button = ButtonAt(actionArea, label, x, 0, 186, 62, callback, false, 18);
  237. StyleBattleButton(button, false);
  238. var caption = button.GetComponentInChildren<Text>().rectTransform;
  239. caption.anchoredPosition = new Vector2(58, -2);
  240. caption.sizeDelta = new Vector2(96, 58);
  241. Image(button.transform, label + " icon", "ui_" + glyph, 40, 18, 27, 27).color = Ink;
  242. }
  243. void StyleBattleButton(Button button, bool primary)
  244. {
  245. var plate = (IronPanel)button.targetGraphic;
  246. plate.rounded = true;
  247. plate.bevel = 19;
  248. plate.stroke = 3;
  249. plate.top = Hex(primary ? "FFDC77" : "482932");
  250. plate.bottom = Hex(primary ? "E89B22" : "2E1821");
  251. plate.border = Hex(primary ? "FFECBD" : "845060");
  252. }
  253. void RebuildAction()
  254. {
  255. var previous = actionArea.Find("Primary");
  256. if (previous)
  257. Remove((RectTransform)previous);
  258. string caption = run.Phase == Phase.Assault ? "HORDE ATTACKING"
  259. : run.Phase == Phase.Rest ? "DONE"
  260. : "LET THEM COME";
  261. var b = ButtonAt(actionArea, caption, 219, 0, 312, 62, BeginAttack, true, 23, run.CanArrange);
  262. StyleBattleButton(b, true);
  263. b.name = "Primary";
  264. var captionText = b.GetComponentInChildren<Text>();
  265. captionText.font = sans;
  266. var label = captionText.rectTransform;
  267. label.anchoredPosition = new Vector2(52, -2);
  268. label.sizeDelta = new Vector2(247, 58);
  269. Image(b.transform, "Sword", "ui_sword", 27, 15, 32, 32).color = Hex("342315");
  270. }
  271. void BeginAttack()
  272. {
  273. if (modal != null || animating || tutorial >= 0 || !run.BeginAttack())
  274. return;
  275. nextAttack = -1;
  276. RefreshHud();
  277. RebuildAction();
  278. }
  279. public void TrySwap(int r, int c, int nr, int nc)
  280. {
  281. if (!CanUseBoard || !run.Swap(r, c, nr, nc))
  282. return;
  283. Sound(tapSound);
  284. if (tutorial == 0)
  285. {
  286. tutorial = 1;
  287. DrawGuide();
  288. }
  289. PlayBoard();
  290. }
  291. public void TapCell(int r, int c)
  292. {
  293. if (!CanUseBoard || tutorial >= 0 || !Run.Inside(r, c))
  294. return;
  295. if (run.OpenChest(r, c))
  296. {
  297. Sound(forgeSound);
  298. PlayBoard();
  299. }
  300. else if (run.Board[r, c]?.Tower == true)
  301. GearSheet(r, c);
  302. }
  303. void PlayBoard()
  304. {
  305. nextAttack = -1;
  306. if (!animating && frames.Count > 0)
  307. playback = StartCoroutine(AnimateBoard());
  308. else
  309. RefreshHud();
  310. }
  311. static Vector2 SetRegion(RawImage image, Sprite sprite, bool flip)
  312. {
  313. Texture2D texture = sprite.texture;
  314. Rect crop = sprite.rect;
  315. var uv = new Rect(crop.x / texture.width, crop.y / texture.height,
  316. crop.width / texture.width, crop.height / texture.height);
  317. if (flip)
  318. uv = new Rect(uv.xMax, uv.y, -uv.width, uv.height);
  319. image.texture = texture;
  320. image.uvRect = uv;
  321. return crop.size;
  322. }
  323. void SetPieceArt(RawImage image, Piece piece, bool firing = false)
  324. {
  325. // The painted cannon points right at rest. A shot sets its actual facing;
  326. // board re-layouts retain that facing until the next shot.
  327. bool flip = piece.Kind == Kind.Cannon && (firing ? !piece.Reversed : image.uvRect.width < 0);
  328. Vector2 size = SetRegion(image, courtSprites[piece.Art], flip);
  329. image.name = piece.Art;
  330. float footprint = piece.Kind switch {
  331. Kind.Stone => .70f, Kind.Ice => .74f, Kind.Gold => .80f, Kind.Ballista => .91f,
  332. Kind.Frost => .90f, Kind.Cannon => .86f, Kind.Arrow => .86f, _ => .77f
  333. };
  334. float span = BoardLayout.FrontCell * (footprint + .035f * (piece.Tier - 1));
  335. image.rectTransform.sizeDelta = size * (span / Mathf.Max(size.x, size.y));
  336. }
  337. void DrawBoard(Piece[,] cells, Dictionary<RectTransform, Vector2> previous = null)
  338. {
  339. var used = new HashSet<Piece>();
  340. for (int r = 0; r < 6; r++)
  341. for (int c = 0; c < 6; c++)
  342. {
  343. Piece p = cells[r, c];
  344. if (p == null)
  345. continue;
  346. used.Add(p);
  347. if (!pieces.TryGetValue(p, out var image))
  348. {
  349. image = Box(tiles, p.Art, 0, 0, 0, 0).gameObject.AddComponent<RawImage>();
  350. image.raycastTarget = false;
  351. image.rectTransform.pivot = new Vector2(.5f, 0);
  352. pieces.Add(p, image);
  353. }
  354. SetPieceArt(image, p);
  355. var rt = image.rectTransform;
  356. var center = BoardLayout.Center(r, c);
  357. var end = center + Vector2.down * (BoardLayout.Depth(r) * .42f);
  358. rt.localScale = Vector3.one * (BoardLayout.Size(r) / BoardLayout.FrontCell);
  359. rt.SetAsLastSibling();
  360. if (previous != null && !previous.ContainsKey(rt))
  361. previous[rt] = end + Vector2.up * BoardLayout.Size(r) * .72f;
  362. rt.anchoredPosition = end;
  363. image.color = Color.white;
  364. }
  365. var removed = new List<Piece>();
  366. foreach (var pair in pieces)
  367. if (!used.Contains(pair.Key))
  368. {
  369. Remove(pair.Value.rectTransform);
  370. removed.Add(pair.Key);
  371. }
  372. foreach (var key in removed)
  373. pieces.Remove(key);
  374. pieceShadows.SetVerticesDirty();
  375. }
  376. void LateUpdate()
  377. {
  378. if (route == "Run" && pieceShadows && (animating || held || run.Phase == Phase.Assault))
  379. pieceShadows.SetVerticesDirty();
  380. }
  381. void UpdateRun()
  382. {
  383. if (modal != null) return;
  384. motionTime += Time.deltaTime;
  385. battleEffects.Advance(Time.deltaTime);
  386. ShakeGate();
  387. if (animating) return;
  388. if (run.Phase == Phase.Plan && tutorial < 0 && run.Moves == 0)
  389. {
  390. if (nextAttack < 0)
  391. nextAttack = .9f;
  392. nextAttack -= Time.deltaTime;
  393. if (nextAttack <= 0)
  394. BeginAttack();
  395. }
  396. if (forecastTime > 0)
  397. {
  398. forecastTime -= Time.deltaTime;
  399. if (forecastTime <= 0)
  400. RefreshHud();
  401. }
  402. if (run.Phase == Phase.Assault)
  403. {
  404. tickRemainder += Mathf.Min(Time.deltaTime, .1f);
  405. while (tickRemainder >= 1f / 30)
  406. {
  407. run.Tick(1f / 30);
  408. tickRemainder -= 1f / 30;
  409. }
  410. DrawFoes();
  411. RefreshHud();
  412. }
  413. else if (foes.Count != 0)
  414. DrawFoes();
  415. if (run.Phase != Phase.Assault && gateHitTime > 0 && motionTime < gateHitTime + .28f)
  416. return;
  417. if (run.Phase == Phase.Over)
  418. {
  419. ShowOver();
  420. return;
  421. }
  422. if (run.Phase == Phase.RestChoice)
  423. {
  424. RestSheet();
  425. return;
  426. }
  427. if (lastDay != run.Day || lastPhase != run.Phase)
  428. {
  429. if (lastDay != run.Day)
  430. {
  431. forecastTime = 6;
  432. Toast(run.Day % 10 == 0 ? "BOSS NIGHT" : "NIGHT " + run.Day);
  433. DrawBoard(run.Board);
  434. }
  435. lastDay = run.Day;
  436. lastPhase = run.Phase;
  437. RebuildAction();
  438. RefreshHud();
  439. }
  440. }
  441. Vector2 Feet(Foe f)
  442. {
  443. var at = BoardLayout.Center(f.Row, f.Col);
  444. if (f.Row >= Foe.RunwayStart)
  445. {
  446. float laneDepth = fieldClip.sizeDelta.y - 15 - BoardLayout.Height;
  447. at.y = -BoardLayout.Height - laneDepth * (f.Row - Foe.RunwayStart) / (Foe.RunwayEnd - Foe.RunwayStart);
  448. }
  449. return at;
  450. }
  451. void RefreshHud()
  452. {
  453. if (route != "Run")
  454. return;
  455. movesLabel.text = run.Phase == Phase.Rest ? "∞" : run.Moves.ToString();
  456. sealLabel.text = run.Plates.ToString();
  457. nightLabel.text = run.Day.ToString();
  458. coinLabel.text = run.Available.ToString();
  459. shardLabel.text = profile.shards.ToString();
  460. turnLabel.text = run.Phase == Phase.Assault ? "THE HORDE"
  461. : run.Phase == Phase.Rest ? "REST NIGHT"
  462. : run.Moves == 0 ? "MOVES SPENT" : "YOUR TURN";
  463. string fc = forecastTime > 0 ? run.Forecast : "";
  464. waitLabel.text = fc != "" && run.Phase == Phase.Plan ? fc
  465. : run.Phase == Phase.Assault ? run.Remaining + " LEFT"
  466. : run.Phase == Phase.Rest ? "FREE MOVES · NO REFILL"
  467. : run.Moves + " MOVES · " + run.Remaining + " DEMONS WAIT";
  468. bool attacking = run.Phase == Phase.Assault;
  469. if (assaultTint != attacking)
  470. {
  471. assaultTint = attacking;
  472. turnDot.top = Hex(attacking ? "FF7A64" : "A4F09D");
  473. turnDot.bottom = Hex(attacking ? "E1483E" : "5FC56F");
  474. turnStrip.top = Hex(attacking ? "541D26" : "24171B");
  475. turnDot.SetVerticesDirty();
  476. turnStrip.SetVerticesDirty();
  477. }
  478. waveLabel.text = "WAVE " + run.Day;
  479. leftLabel.text = run.Remaining + " left";
  480. waveFill.sizeDelta = new Vector2(454 * (1 - (float)run.Remaining / Mathf.Max(1, run.WaveTotal)), 10);
  481. if (lastPlates != run.Plates || lastMaxPlates != run.MaxPlates)
  482. {
  483. foreach (Transform child in shieldPips)
  484. {
  485. child.gameObject.SetActive(false);
  486. Destroy(child.gameObject);
  487. }
  488. gateFractures.SetDamage(run.Plates, run.MaxPlates);
  489. float pitch = Mathf.Min(39, 282f / run.MaxPlates);
  490. for (int i = 0; i < run.MaxPlates; i++)
  491. {
  492. bool intact = i < run.Plates;
  493. Shield(shieldPips, 145 + (i - run.MaxPlates * .5f) * pitch + 3, 0, pitch - 6, 34,
  494. intact ? "FFE798" : "605359", intact ? "EF992D" : "392B33");
  495. }
  496. lastPlates = run.Plates;
  497. lastMaxPlates = run.MaxPlates;
  498. }
  499. }
  500. void DrawGuide()
  501. {
  502. Remove(guide);
  503. guide = null;
  504. if (tutorial < 0)
  505. return;
  506. guide = Panel(boardStage, "Guide", 35, -267, 680, 207, "211B1C", "C29157", 10).rectTransform;
  507. Label(guide, (tutorial + 1) + " / 5 " + GuideTitle[tutorial], 20, 10, 530, 43, 23, Gold);
  508. Label(guide, GuideBody[tutorial], 20, 53, 640, 69, 23, Ink, TextAnchor.MiddleLeft, false, false);
  509. ButtonAt(guide, "SKIP", 544, 10, 115, 44, FinishGuide, false, 17);
  510. if (tutorial == 0)
  511. Label(guide, "Make a swap on the board.", 20, 135, 630, 45, 19, Muted);
  512. else
  513. ButtonAt(guide, tutorial == 4 ? "DEFEND" : "NEXT", 400, 138, 260, 52,
  514. () =>
  515. {
  516. if (++tutorial == 5)
  517. FinishGuide();
  518. else
  519. DrawGuide();
  520. },
  521. true, 20);
  522. }
  523. void FinishGuide()
  524. {
  525. tutorial = -1;
  526. profile.tutorialDone = true;
  527. profile.Save();
  528. DrawGuide();
  529. }
  530. }
  531. }