FateforgeChoices.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using System.Linq;
  2. using TMPro;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace Fateforge
  6. {
  7. public sealed partial class FateforgeApp
  8. {
  9. enum ChoicePrompt { Pick, Burn, Skip }
  10. ChoicePrompt choicePrompt;
  11. int selectedElixir = -1;
  12. float acceptPrimaryAfter;
  13. Button choiceBack;
  14. void ResetChoice()
  15. {
  16. choicePrompt = ChoicePrompt.Pick;
  17. selectedElixir = -1;
  18. if (choiceBack)
  19. {
  20. choiceBack.gameObject.SetActive(false);
  21. Destroy(choiceBack.gameObject);
  22. choiceBack = null;
  23. }
  24. }
  25. void RenderPurchase() => RenderChoices(false);
  26. void RenderReward() => RenderChoices(true);
  27. void RenderChoices(bool free)
  28. {
  29. ClearMarketDock();
  30. Ui.Clear(view.market);
  31. var purchase = Game.State.purchase;
  32. bool elixirs = free || purchase.kind == "booster";
  33. bool burn = !free && purchase.kind == "burn";
  34. float w = view.market.rect.width, h = view.market.rect.height;
  35. view.marketTitle.text = free ? EnglishCopy.AGiftFromFate : elixirs ? EnglishCopy.ChooseAnElixir
  36. : burn ? EnglishCopy.ChooseACardToBurn : EnglishCopy.ChooseACard;
  37. bool selected = elixirs ? selectedElixir >= 0 : purchase.selected >= 0;
  38. if (choicePrompt != ChoicePrompt.Pick)
  39. {
  40. bool skipping = choicePrompt == ChoicePrompt.Skip;
  41. view.marketTitle.text = skipping ? EnglishCopy.SkipThisPurchase : EnglishCopy.BurnThisCard;
  42. if (!skipping)
  43. {
  44. var card = Game.State.cards.First(c => c.id == purchase.selected);
  45. Icon(view.market, card.symbol, 0, h * .08f, w * .3f, h * .44f);
  46. }
  47. Ui.Text(view.market, "Confirmation", skipping ? EnglishCopy.YourPaymentWillNotBeRefunded
  48. : EnglishCopy.ThisPermanentlyRemovesTheSelectedCardFrom, 0, skipping ? h*.2f : h*.54f, w-54, h*.38f, 30, view.theme);
  49. }
  50. else if (elixirs)
  51. {
  52. var items = free ? Game.State.choices : purchase.choices.Select(c => c.ToItem()).ToList();
  53. float pitch = w / items.Count;
  54. for (int i = 0; i < items.Count; i++)
  55. {
  56. int index = i;
  57. var item = items[i];
  58. float width = pitch - 8;
  59. var tile = ChoiceTile((free ? "Reward_" : "Choose_") + i,
  60. (i - (items.Count-1)*.5f) * pitch, 6, width, h-12, selectedElixir == i,
  61. () => { selectedElixir = index; RenderChoices(free); });
  62. Icon(tile, "market_elixir", 0, h*.04f, width*.75f, h*.28f);
  63. if (item.family >= 0)
  64. Ui.Glyph(tile, "Direction", (UiGlyph.Shape)item.family, 0, h*.32f, 50, h*.15f, view.theme.gold);
  65. else Icon(tile, item.symbol, 0, h*.32f, 54, h*.15f);
  66. Ui.Text(tile, "ElixirName", view.art.ItemName(item), 0, h*.48f, width-16, h*.25f, 27, view.theme);
  67. string gain = item.family >= 0 ? "+" + English.Multiplier(item.amount) + " multiplier"
  68. : "+" + English.Number(item.amount * 100) + "% points";
  69. Ui.Text(tile, "Gain", gain, 0, h*.73f, width-14, h*.20f, 24, view.theme).color = view.theme.gold;
  70. }
  71. }
  72. else
  73. {
  74. float width = w/2-8, height = h/2-9;
  75. for (int i = 0; i < purchase.candidates.Count; i++)
  76. {
  77. int id = purchase.candidates[i];
  78. var card = Game.State.cards.FirstOrDefault(c => c.id == id);
  79. if (card == null) continue;
  80. var tile = ChoiceTile("Candidate_" + id, (i%2-.5f)*w/2, (i/2)*(height+6)+5,
  81. width, height, purchase.selected == id, () => {
  82. if (Game.SelectPurchaseCard(id)) { Save(); RenderPurchase(); }
  83. });
  84. Icon(tile, card.symbol, -width*.17f, height*.09f, width*.49f, height*.78f);
  85. Ui.Text(tile, "Value", English.Number(Fateforge.Game.ValueOf(card.symbol)+card.growth),
  86. width*.25f, height*.10f, width*.4f, height*.46f, 34, view.theme);
  87. if (!string.IsNullOrEmpty(card.sticker))
  88. Icon(tile, card.sticker, width*.25f, height*.55f, 52, height*.35f);
  89. }
  90. }
  91. string primary = choicePrompt == ChoicePrompt.Skip ? English.Skip : burn ? EnglishCopy.Burn
  92. : elixirs ? EnglishCopy.Take : "Apply";
  93. Ui.Place((RectTransform)view.collect.transform, free ? 0 : 83, 0, free ? 400 : 340, 64);
  94. Ui.Label(view.collect, primary);
  95. view.collect.interactable = selected || choicePrompt == ChoicePrompt.Skip;
  96. if (free) return;
  97. if (!choiceBack)
  98. {
  99. choiceBack = ActionButton(view.dock, "ChoiceBack", "", -181, 0, 154, 64, SecondaryChoice, false);
  100. ConsoleFace.Fit(choiceBack.targetGraphic, view.cabinet, 10);
  101. }
  102. Ui.Label(choiceBack, choicePrompt == ChoicePrompt.Pick ? English.Skip : "Back");
  103. }
  104. Transform ChoiceTile(string name, float x, float y, float w, float h, bool selected, System.Action choose)
  105. {
  106. var tile = Ui.Button(view.market, name, "", x, y, w, h, view.theme, choose);
  107. var plate = (Image)tile.targetGraphic;
  108. plate.sprite = selected ? view.theme.secondarySprite : view.theme.marketTileSprite;
  109. if (selected)
  110. {
  111. var ring = Ui.Image(Ui.Rect(tile.transform,"Selected",0,0,w,h),view.theme.dialogSprite,view.theme.gold);
  112. Ui.Stretch(ring.rectTransform); ring.type=Image.Type.Sliced; ring.fillCenter=false; ring.pixelsPerUnitMultiplier=2.8f;
  113. }
  114. return tile.transform;
  115. }
  116. void SecondaryChoice()
  117. {
  118. if (Game.State.stage != Stage.Purchase) return;
  119. choicePrompt = choicePrompt == ChoicePrompt.Pick ? ChoicePrompt.Skip : ChoicePrompt.Pick;
  120. acceptPrimaryAfter = 0;
  121. RenderPurchase();
  122. }
  123. void CommitCabinetChoice()
  124. {
  125. if (!view.collect.interactable) return;
  126. acceptPrimaryAfter = Time.unscaledTime + .28f;
  127. if (Game.State.stage == Stage.Reward)
  128. {
  129. if (Game.ChooseReward(selectedElixir)) StageChanged();
  130. return;
  131. }
  132. var purchase = Game.State.purchase;
  133. if (choicePrompt == ChoicePrompt.Skip) { if (Game.SkipPurchase()) StageChanged(); return; }
  134. if (purchase.kind == "burn" && choicePrompt == ChoicePrompt.Pick)
  135. { choicePrompt = ChoicePrompt.Burn; RenderPurchase(); return; }
  136. if (Game.ConfirmPurchase(selectedElixir)) StageChanged();
  137. }
  138. }
  139. }