ported from perforce
This commit is contained in:
99
DonkeysAndDroids.Godot/Gamble.cs
Normal file
99
DonkeysAndDroids.Godot/Gamble.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using DonkeysAndDroids;
|
||||
using Godot;
|
||||
using RobotAndDonkey.Game;
|
||||
using RobotAndDonkey.Game.Cards;
|
||||
using RobotAndDonkey.Game.Execution.Commands;
|
||||
using RobotAndDonkey.Game.Execution.Results;
|
||||
using RobotAndDonkey.Game.GameState;
|
||||
using RobotAndDonkey.Game.Utils;
|
||||
|
||||
public partial class Gamble : Control, IScreen
|
||||
{
|
||||
public override void _Ready()
|
||||
{
|
||||
m_Patches = GetNode<CardRow>("%Patches");
|
||||
m_Add = GetNode<Button>("%Add");
|
||||
m_Add.Pressed += OnAddPressed;
|
||||
m_Skip = GetNode<Button>("%Skip");
|
||||
m_Skip.Pressed += OnSkipPressed;
|
||||
m_Patches.Connect(CardRow.SignalName.SelectionChanged, new(this, nameof(OnSelectionChanged)));
|
||||
}
|
||||
|
||||
private void OnSelectionChanged(CardControl[] selection)
|
||||
{
|
||||
if (selection.Length != 1)
|
||||
{
|
||||
m_BuyCardsCommand = null;
|
||||
return;
|
||||
}
|
||||
|
||||
m_BuyCardsCommand = new(Main.Instance.CurrentRequest.RequestId, selection.Select(c => m_Patches.OrderedCards.IndexOf(c.Card)).ToArray());
|
||||
}
|
||||
|
||||
private void OnAddPressed()
|
||||
{
|
||||
Main.Instance.Execute(m_BuyCardsCommand);
|
||||
}
|
||||
|
||||
private void OnSkipPressed()
|
||||
{
|
||||
Main.Instance.Execute(m_StopGamblingCommand);
|
||||
}
|
||||
|
||||
public void Deactivate()
|
||||
{
|
||||
}
|
||||
|
||||
public void EnableInputs()
|
||||
{
|
||||
m_Add.Disabled = false;
|
||||
m_Skip.Disabled = false;
|
||||
}
|
||||
|
||||
public void DisableInputs()
|
||||
{
|
||||
m_Add.Disabled = true;
|
||||
m_Skip.Disabled = true;
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
{
|
||||
}
|
||||
|
||||
public bool HandleResult(Result result, Tween tween)
|
||||
{
|
||||
switch (result)
|
||||
{
|
||||
case ShopResult shopResult:
|
||||
{
|
||||
m_Patches.Configure(shopResult.Shop, tween, false, false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
m_Skip.Disabled = m_StopGamblingCommand == null || !m_StopGamblingCommand.IsValid(Main.Instance.CoreLoop, out _);
|
||||
m_Add.Disabled = m_BuyCardsCommand == null || !m_BuyCardsCommand.IsValid(Main.Instance.CoreLoop, out _);
|
||||
}
|
||||
|
||||
public void Configure(List<Card> hand, Tween tween)
|
||||
{
|
||||
m_Patches.Configure(hand, tween, true, false);
|
||||
m_StopGamblingCommand = new(Main.Instance.CurrentRequest.RequestId);
|
||||
}
|
||||
|
||||
private BuyCardsCommand m_BuyCardsCommand;
|
||||
|
||||
private CardRow m_Patches;
|
||||
private Button m_Add;
|
||||
private Button m_Skip;
|
||||
private StopGamblingCommand m_StopGamblingCommand;
|
||||
}
|
||||
Reference in New Issue
Block a user