BattleView.cs 25 KB

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