Files
zfxaction25/DonkeysAndDroids.Godot/Improve.cs
2026-04-19 00:43:27 +02:00

150 lines
4.8 KiB
C#

using DonkeysAndDroids;
using Godot;
using RobotAndDonkey.Game.Cards;
using RobotAndDonkey.Game.Execution.Commands;
using System.Collections.Generic;
using System.Linq;
using RobotAndDonkey.Game.Data;
using RobotAndDonkey.Game.Execution.Results;
public partial class Improve : Control, IScreen
{
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
m_ShopCards = GetNode<CardRow>("%Shop");
m_Deck = GetNode<CardRow>("%Deck");
m_BuyButton = GetNode<Button>("%BuyButton");
m_CosmicRaysButton = GetNode<Button>("%CosmicRaysButton");
m_RerollButton = GetNode<Button>("%RerollButton");
m_BufferOverflowButton = GetNode<Button>("%BufferOverflowButton");
m_SkipButton = GetNode<Button>("%SkipButton");
m_BuyButton.Disabled = true;
m_BuyButton.Pressed += OnBuyButtonPressed;
m_CosmicRaysButton.Pressed += OnCosmicRaysButtonPressed;
m_RerollButton.Pressed += OnRerollButtonPressed;
m_BufferOverflowButton.Pressed += OnBufferOverflowButtonPressed;
m_SkipButton.Pressed += OnSkipButtonPressed;
m_ShopCards.Connect(CardRow.SignalName.SelectionChanged, new(this, nameof(OnPatchSelectionChanged)));
}
private void UpdateButtonTexts()
{
m_CosmicRaysButton.Text = $"Cosmic Rays\n({Balancing.Instance.GambleEnergyCost} energy)";
m_RerollButton.Text = $"Reroll ({Balancing.Instance.GetRerollEnergyCost(Main.Instance.CoreLoop.RerollCount)} energy)";
m_BufferOverflowButton.Text = $"Buffer Overflow\n({Balancing.Instance.BufferOverflowEnergyCost} energy)";
}
public void Deactivate()
{
}
public void EnableInputs()
{
m_ShopCards.Disabled = false;
Deck.Disabled = false;
m_BuyButton.Disabled = false;
m_CosmicRaysButton.Disabled = !Main.Instance.CoreLoop.CanGamble;
m_RerollButton.Disabled = false;
m_BufferOverflowButton.Disabled = !Main.Instance.CoreLoop.CanBufferOverflow;
m_SkipButton.Disabled = false;
UpdateButtonTexts();
}
public void DisableInputs()
{
m_ShopCards.Disabled = true;
Deck.Disabled = true;
m_BuyButton.Disabled = true;
m_CosmicRaysButton.Disabled = true;
m_RerollButton.Disabled = true;
m_BufferOverflowButton.Disabled = true;
m_SkipButton.Disabled = true;
}
public void Activate()
{
}
private void OnPatchSelectionChanged(CardControl[] selection)
{
var cost = selection.Sum(c => c.Card.ShopCost);
m_BuyButton.Disabled = cost == 0 || cost > Main.Instance.CoreLoop.Currency.Energy;
m_BuyButton.Text = $"Buy ({cost} energy)";
}
private void OnBuyButtonPressed()
{
var cards = m_ShopCards.SelectedCardIndices.ToArray();
Main.Instance.Execute(new BuyCardsCommand(Main.Instance.CurrentRequest.RequestId, cards));
m_BuyButton.Text = "Buy";
m_BuyButton.Disabled = true;
}
private void OnCosmicRaysButtonPressed()
{
Main.Instance.Execute(new StartGamblingCommand(Main.Instance.CurrentRequest.RequestId));
}
private void OnRerollButtonPressed()
{
Main.Instance.Execute(new RerollCommand(Main.Instance.CurrentRequest.RequestId));
}
private void OnBufferOverflowButtonPressed()
{
Main.Instance.Execute(new StartBufferOverflowCommand(Main.Instance.CurrentRequest.RequestId));
}
private void OnSkipButtonPressed()
{
Main.Instance.Execute(new PreviewProgramCommand(Main.Instance.CurrentRequest.RequestId));
}
public void Configure(IReadOnlyList<Card> shop, IReadOnlyList<Card> patches, Tween tween)
{
m_ShopCards.Configure(shop, tween, false, false);
Deck.Configure(CardRow.GetSortedCards(patches), tween, false, false);
}
public bool HandleResult(Result result, Tween tween)
{
switch (result)
{
case ShopResult shopResult:
{
m_ShopCards.Configure(shopResult.Shop, tween, false, false);
return true;
}
case DeckResult deckResult:
{
Deck.Configure(CardRow.GetSortedCards(deckResult.Deck), tween, false, false);
return true;
}
case ModifyCardResult modifyCardResult:
{
Deck.ModifyCard(modifyCardResult.Card, modifyCardResult.Modifier, tween);
return true;
}
}
return false;
}
public override void _Process(double delta)
{
}
public CardRow Deck => m_Deck;
private CardRow m_Deck;
private CardRow m_ShopCards;
private Button m_BuyButton;
private Button m_CosmicRaysButton;
private Button m_RerollButton;
private Button m_BufferOverflowButton;
private Button m_SkipButton;
}