92 lines
3.0 KiB
C#
92 lines
3.0 KiB
C#
using Godot;
|
|
using System.Linq;
|
|
|
|
public partial class StageGUI : Control
|
|
{
|
|
[Signal]
|
|
public delegate void OnCharacterSelectionMadeEventHandler(Player player);
|
|
|
|
private GameManager _gameManager;
|
|
|
|
public override void _Ready()
|
|
{
|
|
_gameManager = GetTree().Root.GetNode<GameManager>("Main/GameManager");
|
|
}
|
|
|
|
public void OnCharacterSelect(Player player)
|
|
{
|
|
if (_gameManager.IsGameOver)
|
|
return;
|
|
|
|
var wheel1 = GetNode<TextureRect>("CharacterSelect/Wheel");
|
|
var wheel2 = GetNode<TextureRect>("CharacterSelect/Wheel2");
|
|
|
|
if (player == _gameManager.Players.ElementAt(0))
|
|
{
|
|
wheel1.FocusMode = FocusModeEnum.All;
|
|
wheel1.GrabFocus();
|
|
wheel1.Visible = true;
|
|
}
|
|
else if (player == _gameManager.Players.ElementAt(1))
|
|
{
|
|
wheel2.FocusMode = FocusModeEnum.All;
|
|
wheel2.GrabFocus();
|
|
wheel2.Visible = true;
|
|
}
|
|
player.IsSelectingCharacter = true;
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
var playersCurrentlySelecting = _gameManager.Players.Where(x => x.IsSelectingCharacter);
|
|
foreach (var player in playersCurrentlySelecting)
|
|
{
|
|
if (player == _gameManager.Players.ElementAt(0))
|
|
{
|
|
if (Input.IsActionJustPressed("p1_right"))
|
|
_gameManager.SetToNextCharacter(_gameManager.Players.ElementAt(0));
|
|
if (Input.IsActionJustPressed("p1_left"))
|
|
_gameManager.SetToPreviousCharacter(_gameManager.Players.ElementAt(0));
|
|
|
|
if (Input.IsActionJustPressed("p1_fire"))
|
|
{
|
|
GD.Print("Selected character");
|
|
_gameManager.Players.ElementAt(0).IsSelectingCharacter = false;
|
|
var wheel1 = GetNode<TextureRect>("CharacterSelect/Wheel");
|
|
wheel1.Hide();
|
|
EmitSignal(SignalName.OnCharacterSelectionMade, _gameManager.Players.ElementAt(0));
|
|
}
|
|
}
|
|
|
|
if (player == _gameManager.Players.ElementAt(1))
|
|
{
|
|
if (Input.IsActionJustPressed("p2_right"))
|
|
_gameManager.SetToNextCharacter(_gameManager.Players.ElementAt(1));
|
|
if (Input.IsActionJustPressed("p2_left"))
|
|
_gameManager.SetToPreviousCharacter(_gameManager.Players.ElementAt(1));
|
|
|
|
if (Input.IsActionJustPressed("p2_fire"))
|
|
{
|
|
GD.Print("Selected character");
|
|
_gameManager.Players.ElementAt(1).IsSelectingCharacter = false;
|
|
var wheel2 = GetNode<TextureRect>("CharacterSelect/Wheel2");
|
|
wheel2.Hide();
|
|
EmitSignal(SignalName.OnCharacterSelectionMade, _gameManager.Players.ElementAt(1));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnFirstPlayerCharacterSelect()
|
|
{
|
|
var player = _gameManager.Players.ElementAt(0);
|
|
OnCharacterSelect(player);
|
|
}
|
|
|
|
private void OnSecondPlayerCharacterSelect()
|
|
{
|
|
var player = _gameManager.Players.ElementAt(1);
|
|
OnCharacterSelect(player);
|
|
}
|
|
}
|