91 lines
2.4 KiB
C#
91 lines
2.4 KiB
C#
using DonkeysAndDroids;
|
|
using Godot;
|
|
using RobotAndDonkey.Game.Execution.Commands;
|
|
using RobotAndDonkey.Game.Execution.Results;
|
|
|
|
public partial class BufferOverflow : Control, IScreen
|
|
{
|
|
public override void _Ready()
|
|
{
|
|
m_Hand = GetNode<CardRow>("%Hand");
|
|
m_Remove = GetNode<Button>("%Remove");
|
|
m_Remove.Pressed += OnRemovePressed;
|
|
m_Skip = GetNode<Button>("%Skip");
|
|
m_Skip.Pressed += OnSkipPressed;
|
|
m_Hand.Connect(CardRow.SignalName.SelectionChanged, new(this, nameof(OnSelectionChanged)));
|
|
}
|
|
|
|
private void OnSelectionChanged(CardControl[] selection)
|
|
{
|
|
if (selection.Length != 1)
|
|
{
|
|
m_DestroyCardCommand = null;
|
|
return;
|
|
}
|
|
|
|
m_DestroyCardCommand = new(Main.Instance.CurrentRequest.RequestId, m_Hand.OrderedCards.IndexOf(selection[0].Card));
|
|
}
|
|
|
|
private void OnRemovePressed()
|
|
{
|
|
Main.Instance.Execute(m_DestroyCardCommand);
|
|
}
|
|
|
|
private void OnSkipPressed()
|
|
{
|
|
Main.Instance.Execute(m_StopBufferOverflowCommand);
|
|
}
|
|
|
|
public void Deactivate()
|
|
{
|
|
}
|
|
|
|
public void EnableInputs()
|
|
{
|
|
m_Remove.Disabled = false;
|
|
m_Skip.Disabled = false;
|
|
}
|
|
|
|
public void DisableInputs()
|
|
{
|
|
m_Remove.Disabled = true;
|
|
m_Skip.Disabled = true;
|
|
}
|
|
|
|
public void Activate()
|
|
{
|
|
}
|
|
|
|
public bool HandleResult(Result result, Tween tween)
|
|
{
|
|
switch (result)
|
|
{
|
|
case HandResult handResult:
|
|
{
|
|
m_Hand.Configure(handResult.Hand, tween, true, false);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
m_Skip.Disabled = m_StopBufferOverflowCommand == null || !m_StopBufferOverflowCommand.IsValid(Main.Instance.CoreLoop, out _);
|
|
m_Remove.Disabled = m_DestroyCardCommand == null || !m_DestroyCardCommand.IsValid(Main.Instance.CoreLoop, out _);
|
|
}
|
|
|
|
public void Configure(Tween tween)
|
|
{
|
|
m_Hand.Configure(Main.Instance.CoreLoop.Hand, tween, false, false);
|
|
m_StopBufferOverflowCommand = new(Main.Instance.CurrentRequest.RequestId);
|
|
}
|
|
|
|
private DestroyCardCommand m_DestroyCardCommand;
|
|
|
|
private CardRow m_Hand;
|
|
private Button m_Remove;
|
|
private Button m_Skip;
|
|
private StopBufferOverflowCommand m_StopBufferOverflowCommand;
|
|
} |