| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- using System.Linq;
- using TMPro;
- using UnityEngine;
- using UnityEngine.UI;
- namespace Fateforge
- {
- public sealed partial class FateforgeApp
- {
- enum ChoicePrompt { Pick, Burn, Skip }
- ChoicePrompt choicePrompt;
- int selectedElixir = -1;
- float acceptPrimaryAfter;
- Button choiceBack;
- void ResetChoice()
- {
- choicePrompt = ChoicePrompt.Pick;
- selectedElixir = -1;
- if (choiceBack)
- {
- choiceBack.gameObject.SetActive(false);
- Destroy(choiceBack.gameObject);
- choiceBack = null;
- }
- }
- void RenderPurchase() => RenderChoices(false);
- void RenderReward() => RenderChoices(true);
- void RenderChoices(bool free)
- {
- ClearMarketDock();
- Ui.Clear(view.market);
- var purchase = Game.State.purchase;
- bool elixirs = free || purchase.kind == "booster";
- bool burn = !free && purchase.kind == "burn";
- float w = view.market.rect.width, h = view.market.rect.height;
- view.marketTitle.text = free ? EnglishCopy.AGiftFromFate : elixirs ? EnglishCopy.ChooseAnElixir
- : burn ? EnglishCopy.ChooseACardToBurn : EnglishCopy.ChooseACard;
- bool selected = elixirs ? selectedElixir >= 0 : purchase.selected >= 0;
- if (choicePrompt != ChoicePrompt.Pick)
- {
- bool skipping = choicePrompt == ChoicePrompt.Skip;
- view.marketTitle.text = skipping ? EnglishCopy.SkipThisPurchase : EnglishCopy.BurnThisCard;
- if (!skipping)
- {
- var card = Game.State.cards.First(c => c.id == purchase.selected);
- Icon(view.market, card.symbol, 0, h * .08f, w * .3f, h * .44f);
- }
- Ui.Text(view.market, "Confirmation", skipping ? EnglishCopy.YourPaymentWillNotBeRefunded
- : EnglishCopy.ThisPermanentlyRemovesTheSelectedCardFrom, 0, skipping ? h*.2f : h*.54f, w-54, h*.38f, 30, view.theme);
- }
- else if (elixirs)
- {
- var items = free ? Game.State.choices : purchase.choices.Select(c => c.ToItem()).ToList();
- float pitch = w / items.Count;
- for (int i = 0; i < items.Count; i++)
- {
- int index = i;
- var item = items[i];
- float width = pitch - 8;
- var tile = ChoiceTile((free ? "Reward_" : "Choose_") + i,
- (i - (items.Count-1)*.5f) * pitch, 6, width, h-12, selectedElixir == i,
- () => { selectedElixir = index; RenderChoices(free); });
- Icon(tile, "market_elixir", 0, h*.04f, width*.75f, h*.28f);
- if (item.family >= 0)
- Ui.Glyph(tile, "Direction", (UiGlyph.Shape)item.family, 0, h*.32f, 50, h*.15f, view.theme.gold);
- else Icon(tile, item.symbol, 0, h*.32f, 54, h*.15f);
- Ui.Text(tile, "ElixirName", view.art.ItemName(item), 0, h*.48f, width-16, h*.25f, 27, view.theme);
- string gain = item.family >= 0 ? "+" + English.Multiplier(item.amount) + " multiplier"
- : "+" + English.Number(item.amount * 100) + "% points";
- Ui.Text(tile, "Gain", gain, 0, h*.73f, width-14, h*.20f, 24, view.theme).color = view.theme.gold;
- }
- }
- else
- {
- float width = w/2-8, height = h/2-9;
- for (int i = 0; i < purchase.candidates.Count; i++)
- {
- int id = purchase.candidates[i];
- var card = Game.State.cards.FirstOrDefault(c => c.id == id);
- if (card == null) continue;
- var tile = ChoiceTile("Candidate_" + id, (i%2-.5f)*w/2, (i/2)*(height+6)+5,
- width, height, purchase.selected == id, () => {
- if (Game.SelectPurchaseCard(id)) { Save(); RenderPurchase(); }
- });
- Icon(tile, card.symbol, -width*.17f, height*.09f, width*.49f, height*.78f);
- Ui.Text(tile, "Value", English.Number(Fateforge.Game.ValueOf(card.symbol)+card.growth),
- width*.25f, height*.10f, width*.4f, height*.46f, 34, view.theme);
- if (!string.IsNullOrEmpty(card.sticker))
- Icon(tile, card.sticker, width*.25f, height*.55f, 52, height*.35f);
- }
- }
- string primary = choicePrompt == ChoicePrompt.Skip ? English.Skip : burn ? EnglishCopy.Burn
- : elixirs ? EnglishCopy.Take : "Apply";
- Ui.Place((RectTransform)view.collect.transform, free ? 0 : 83, 0, free ? 400 : 340, 64);
- Ui.Label(view.collect, primary);
- view.collect.interactable = selected || choicePrompt == ChoicePrompt.Skip;
- if (free) return;
- if (!choiceBack)
- {
- choiceBack = ActionButton(view.dock, "ChoiceBack", "", -181, 0, 154, 64, SecondaryChoice, false);
- ConsoleFace.Fit(choiceBack.targetGraphic, view.cabinet, 10);
- }
- Ui.Label(choiceBack, choicePrompt == ChoicePrompt.Pick ? English.Skip : "Back");
- }
- Transform ChoiceTile(string name, float x, float y, float w, float h, bool selected, System.Action choose)
- {
- var tile = Ui.Button(view.market, name, "", x, y, w, h, view.theme, choose);
- var plate = (Image)tile.targetGraphic;
- plate.sprite = selected ? view.theme.secondarySprite : view.theme.marketTileSprite;
- if (selected)
- {
- var ring = Ui.Image(Ui.Rect(tile.transform,"Selected",0,0,w,h),view.theme.dialogSprite,view.theme.gold);
- Ui.Stretch(ring.rectTransform); ring.type=Image.Type.Sliced; ring.fillCenter=false; ring.pixelsPerUnitMultiplier=2.8f;
- }
- return tile.transform;
- }
- void SecondaryChoice()
- {
- if (Game.State.stage != Stage.Purchase) return;
- choicePrompt = choicePrompt == ChoicePrompt.Pick ? ChoicePrompt.Skip : ChoicePrompt.Pick;
- acceptPrimaryAfter = 0;
- RenderPurchase();
- }
- void CommitCabinetChoice()
- {
- if (!view.collect.interactable) return;
- acceptPrimaryAfter = Time.unscaledTime + .28f;
- if (Game.State.stage == Stage.Reward)
- {
- if (Game.ChooseReward(selectedElixir)) StageChanged();
- return;
- }
- var purchase = Game.State.purchase;
- if (choicePrompt == ChoicePrompt.Skip) { if (Game.SkipPurchase()) StageChanged(); return; }
- if (purchase.kind == "burn" && choicePrompt == ChoicePrompt.Pick)
- { choicePrompt = ChoicePrompt.Burn; RenderPurchase(); return; }
- if (Game.ConfirmPurchase(selectedElixir)) StageChanged();
- }
- }
- }
|