feat: more admin controls, new icons, MSAA...
- fixed scaling viewport
This commit is contained in:
@@ -6,6 +6,8 @@ public partial class AdminControls : HBoxContainer
|
||||
{
|
||||
[Export] public Button BecomeAdmin;
|
||||
[Export] public Button StartTournament;
|
||||
[Export] public Label Label;
|
||||
[Export] public Slider Timeout;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -17,6 +19,31 @@ public partial class AdminControls : HBoxContainer
|
||||
{
|
||||
StartTournament.Hide();
|
||||
}
|
||||
|
||||
if (!Connection.Instance.IsAdmin)
|
||||
{
|
||||
Label.Hide();
|
||||
Timeout.Hide();
|
||||
}
|
||||
|
||||
Timeout.Value = Connection.Instance.CurrentWaitTimeout;
|
||||
var time = Connection.Instance.CurrentWaitTimeout.ToString();
|
||||
if (time.Length > 3)
|
||||
{
|
||||
time = time.Substring(0, 3);
|
||||
}
|
||||
|
||||
Label.Text = "Wait To Move: " + time + "s ";
|
||||
Timeout.ValueChanged += value =>
|
||||
{
|
||||
Connection.Instance.SetTournamentWait((float)value);
|
||||
var time = Connection.Instance.CurrentWaitTimeout.ToString();
|
||||
if (time.Length > 3)
|
||||
{
|
||||
time = time.Substring(0, 3);
|
||||
}
|
||||
Label.Text = "Wait To Move: " + time + "s ";
|
||||
};
|
||||
|
||||
BecomeAdmin.Pressed += ShowAuthPopup;
|
||||
}
|
||||
@@ -119,5 +146,7 @@ public partial class AdminControls : HBoxContainer
|
||||
{
|
||||
StartTournament.Show();
|
||||
}
|
||||
Label.Show();
|
||||
Timeout.Show();
|
||||
}
|
||||
}
|
||||
|
||||
18
scripts/BackButton.cs
Normal file
18
scripts/BackButton.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class BackButton : TextureButton
|
||||
{
|
||||
private const string BRACKET_SCENE_PATH = "res://scenes/bracket_view.tscn";
|
||||
|
||||
public override void _Pressed()
|
||||
{
|
||||
TransitionToBracket();
|
||||
base._Pressed();
|
||||
}
|
||||
|
||||
private void TransitionToBracket()
|
||||
{
|
||||
GetTree().ChangeSceneToFile(BRACKET_SCENE_PATH);
|
||||
}
|
||||
}
|
||||
1
scripts/BackButton.cs.uid
Normal file
1
scripts/BackButton.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b3q4gq63qmx23
|
||||
@@ -4,8 +4,6 @@ using System.Collections.Generic;
|
||||
|
||||
public partial class BoardScreen : Node2D {
|
||||
|
||||
[Export] public BaseButton BackButton;
|
||||
|
||||
private const string RED_CHIP_PATH = "res://scenes/red_chip.tscn";
|
||||
private const string YELLOW_CHIP_PATH = "res://scenes/yellow_chip.tscn";
|
||||
private const string BRACKET_SCENE_PATH = "res://scenes/bracket_view.tscn";
|
||||
@@ -15,6 +13,9 @@ public partial class BoardScreen : Node2D {
|
||||
private const int CHIP_X_OFF = -(CHIP_SIZE + CHIP_PADDING) * 7 / 2 + (CHIP_SIZE + CHIP_PADDING) / 2;
|
||||
private const int Y_OFF = 300;
|
||||
private const int CARD_CENTER_X_DEFAULT = -536;
|
||||
private const double MOVE_TIMEOUT_BEFORE_PLACE = 1.0f;
|
||||
|
||||
private double currentTimeout = 0.0f;
|
||||
|
||||
private PackedScene redChip;
|
||||
private PackedScene ylwChip;
|
||||
@@ -23,6 +24,8 @@ public partial class BoardScreen : Node2D {
|
||||
private Node2D player2Card;
|
||||
private MatchData matchData;
|
||||
|
||||
private List<(string, int)> moves;
|
||||
|
||||
private RigidBody2D[,] chips = new RigidBody2D[6, 7]; // 6 rows 7 cols | 0, 0 is top left
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
@@ -40,19 +43,35 @@ public partial class BoardScreen : Node2D {
|
||||
matchData = Connection.Instance.CurrentObservingMatch;
|
||||
player1Card.GetNode<Label>("Name").Text = matchData.player1;
|
||||
player2Card.GetNode<Label>("Name").Text = matchData.player2;
|
||||
|
||||
GetNode<TextureButton>("BracketButton").Pressed += TransitionToBracket;
|
||||
|
||||
|
||||
Connection.Instance.OnObserveWin += ObserveWin;
|
||||
Connection.Instance.OnObserveDraw += ObserveDraw;
|
||||
Connection.Instance.OnObserveTerminated += ObserveTerminated;
|
||||
Connection.Instance.OnObserveMove += ObserveMove;
|
||||
Connection.Instance.OnTournamentEnd += ShowTournamentScoreboard;
|
||||
}
|
||||
|
||||
BackButton.Pressed += () =>
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Connection.Instance.PreviousMoves.Count != 0 && currentTimeout <= 0.0f)
|
||||
{
|
||||
TransitionToBracket();
|
||||
};
|
||||
var move = Connection.Instance.PreviousMoves[0];
|
||||
Connection.Instance.PreviousMoves.RemoveAt(0);
|
||||
if (move.Item1 == matchData.player1)
|
||||
{
|
||||
spawnRed(move.Item2);
|
||||
}
|
||||
else
|
||||
{
|
||||
spawnYellow(move.Item2);
|
||||
}
|
||||
|
||||
currentTimeout = MOVE_TIMEOUT_BEFORE_PLACE;
|
||||
}
|
||||
else if (currentTimeout >= 0.0f)
|
||||
{
|
||||
currentTimeout -= delta;
|
||||
}
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
@@ -66,52 +85,41 @@ public partial class BoardScreen : Node2D {
|
||||
|
||||
private void ObserveMove(string username, int column)
|
||||
{
|
||||
if (username == matchData.player1)
|
||||
{
|
||||
spawnRed(column);
|
||||
}
|
||||
else
|
||||
{
|
||||
spawnYellow(column);
|
||||
}
|
||||
Connection.Instance.PreviousMoves.Add((username, column));
|
||||
}
|
||||
|
||||
private void ObserveWin(string winner)
|
||||
{
|
||||
var popup = new Popup();
|
||||
popup.AlwaysOnTop = true;
|
||||
popup.PopupCentered();
|
||||
popup.Size = new Vector2I(128, 128);
|
||||
var text = new Label();
|
||||
text.Text = winner + " wins!";
|
||||
popup.AddChild(text);
|
||||
GetTree().Root.AddChild(popup);
|
||||
TransitionToBracket();
|
||||
PopupMessage(winner + " wins!");
|
||||
}
|
||||
|
||||
private void ObserveDraw()
|
||||
{
|
||||
var popup = new Popup();
|
||||
popup.AlwaysOnTop = true;
|
||||
popup.PopupCentered();
|
||||
popup.Size = new Vector2I(128, 128);
|
||||
var text = new Label();
|
||||
text.Text = "Draw!";
|
||||
popup.AddChild(text);
|
||||
GetTree().Root.AddChild(popup);
|
||||
TransitionToBracket();
|
||||
PopupMessage("Draw!");
|
||||
}
|
||||
|
||||
private void ObserveTerminated()
|
||||
{
|
||||
PopupMessage("Match Terminated");
|
||||
}
|
||||
|
||||
private void PopupMessage(string message)
|
||||
{
|
||||
var popup = new Popup();
|
||||
popup.AlwaysOnTop = true;
|
||||
popup.PopupCentered();
|
||||
popup.Size = new Vector2I(128, 128);
|
||||
popup.Size = new Vector2I(200, 100);
|
||||
var text = new Label();
|
||||
text.Text = "Match Terminated";
|
||||
text.Text = message;
|
||||
popup.AddChild(text);
|
||||
text.GrowHorizontal = Control.GrowDirection.Both;
|
||||
text.GrowVertical = Control.GrowDirection.Both;
|
||||
text.HorizontalAlignment = HorizontalAlignment.Center;
|
||||
text.VerticalAlignment = VerticalAlignment.Center;
|
||||
text.AnchorsPreset = (int) Control.LayoutPreset.FullRect;
|
||||
popup.InitialPosition = Window.WindowInitialPosition.CenterMainWindowScreen;
|
||||
GetTree().Root.AddChild(popup);
|
||||
popup.Show();
|
||||
TransitionToBracket();
|
||||
}
|
||||
|
||||
@@ -153,33 +161,6 @@ public partial class BoardScreen : Node2D {
|
||||
GetTree().ChangeSceneToFile(BRACKET_SCENE_PATH);
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta) {
|
||||
/*
|
||||
if(p1 != null) {
|
||||
Label username = player1Card.GetNode<Label>("Name");
|
||||
username.Text = p1.username;
|
||||
|
||||
if(p1.isReady) {
|
||||
Label status = player1Card.GetNode<Label>("Status");
|
||||
status.Text = "Ready!";
|
||||
status.AddThemeColorOverride("font_color", Colors.LimeGreen);
|
||||
}
|
||||
}
|
||||
|
||||
if(p2 != null) {
|
||||
Label username = player2Card.GetNode<Label>("Name");
|
||||
username.Text = p2.username;
|
||||
|
||||
if(p2.isReady) {
|
||||
Label status = player2Card.GetNode<Label>("Status");
|
||||
status.Text = "Ready!";
|
||||
status.AddThemeColorOverride("font_color", Colors.LimeGreen);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
* Determines if the column can have a new chip placed
|
||||
* Will return -1 if invalid
|
||||
|
||||
@@ -6,7 +6,8 @@ public partial class BracketScene : Control
|
||||
{
|
||||
[Export] public Tree Players;
|
||||
[Export] public Tree Matches;
|
||||
[Export] public Texture2D JoinButton;
|
||||
[Export] public Texture2D WatchButton;
|
||||
[Export] public Texture2D TerminateKickButton;
|
||||
private const string BOARD_SCENE_PATH = "res://scenes/game.tscn";
|
||||
|
||||
private List<PlayerData> _playerList;
|
||||
@@ -26,6 +27,7 @@ public partial class BracketScene : Control
|
||||
Matches.SetColumnTitle(2, "Yellow");
|
||||
Matches.HideRoot = true;
|
||||
Matches.ButtonClicked += WatchGame;
|
||||
Matches.ButtonClicked += TerminateGame;
|
||||
|
||||
Connection.Instance.OnUpdatedPlayers += UpdatePlayers;
|
||||
Connection.Instance.OnUpdatedMatches += UpdateMatches;
|
||||
@@ -52,7 +54,7 @@ public partial class BracketScene : Control
|
||||
item.SetText(2, playerList[i].isPlaying ? "Yes" : "No");
|
||||
if (Connection.Instance.IsAdmin)
|
||||
{
|
||||
item.AddButton(0, JoinButton, i, false, "Kick"); // TODO
|
||||
item.AddButton(0, TerminateKickButton, i, false, "Kick"); // TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,7 +70,11 @@ public partial class BracketScene : Control
|
||||
item.SetText(0, matchList[i].matchId.ToString());
|
||||
item.SetText(1, matchList[i].player1);
|
||||
item.SetText(2, matchList[i].player2);
|
||||
item.AddButton(0, JoinButton, i, false, "Watch");
|
||||
item.AddButton(0, WatchButton, item.GetButtonCount(0), false, "Watch");
|
||||
if (Connection.Instance.IsAdmin)
|
||||
{
|
||||
item.AddButton(0, TerminateKickButton, item.GetButtonCount(0), false, "Terminate");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,6 +94,14 @@ public partial class BracketScene : Control
|
||||
}
|
||||
}
|
||||
|
||||
private void TerminateGame(TreeItem item, long column, long id, long mouseButtonIndex)
|
||||
{
|
||||
if (mouseButtonIndex == 1 && column == 0 && id - 1 > 0 && _matchList[(int) id - 1] != null)
|
||||
{
|
||||
Connection.Instance.TerminateGame(_matchList[(int) id - 1].matchId);
|
||||
}
|
||||
}
|
||||
|
||||
private void TransitionToBoard()
|
||||
{
|
||||
GetTree().ChangeSceneToFile(BOARD_SCENE_PATH);
|
||||
|
||||
@@ -41,7 +41,9 @@ public partial class Connection : Node
|
||||
public bool IsAdmin { get; private set; }
|
||||
public bool IsPlayer { get; private set; }
|
||||
public bool ActiveTournament { get; private set; }
|
||||
|
||||
public List<(string, int)> PreviousMoves { get; private set; } = new List<(string, int)>();
|
||||
public double CurrentWaitTimeout { get; private set; } = 5.0;
|
||||
|
||||
|
||||
public MatchData CurrentObservingMatch { get; private set; }
|
||||
|
||||
@@ -218,15 +220,16 @@ public partial class Connection : Node
|
||||
SendCommand("TOURNAMENT", "START");
|
||||
}
|
||||
|
||||
public void TerminateGame()
|
||||
public void TerminateGame(int matchID)
|
||||
{
|
||||
if (!IsAdmin) return;
|
||||
SendCommand("GAME", "TERMINATE");
|
||||
SendCommand("GAME", "TERMINATE:" + matchID);
|
||||
}
|
||||
|
||||
public void SetTournamentWait(float waitTime)
|
||||
{
|
||||
if (!IsAdmin) return;
|
||||
CurrentWaitTimeout = waitTime;
|
||||
SendCommand("TOURNAMENT", "WAIT:" + waitTime);
|
||||
}
|
||||
|
||||
@@ -305,6 +308,7 @@ public partial class Connection : Node
|
||||
if (body == "AUTH:ACK")
|
||||
{
|
||||
IsAdmin = true;
|
||||
SetTournamentWait(5.0f);
|
||||
OnBecomeAdmin?.Invoke();
|
||||
}
|
||||
|
||||
@@ -465,8 +469,24 @@ public partial class Connection : Node
|
||||
OnUpdatedMatches?.Invoke(matches);
|
||||
break;
|
||||
case "WATCH":
|
||||
string[] game = segments[2].Split(",");
|
||||
CurrentObservingMatch = new MatchData(int.Parse(game[0]), game[1], game[2]);
|
||||
CurrentObservingMatch = null;
|
||||
PreviousMoves.Clear();
|
||||
string[] activeMatchData = segments[2].Split("|");
|
||||
if (activeMatchData.IsEmpty())
|
||||
{
|
||||
string[] matchData = segments[2].Split(',');
|
||||
CurrentObservingMatch = new MatchData(int.Parse(matchData[0]), matchData[1], matchData[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] matchData = activeMatchData[0].Split(',');
|
||||
CurrentObservingMatch = new MatchData(int.Parse(matchData[0]), matchData[1], matchData[2]);
|
||||
for (int i = 1; i < activeMatchData.Length; i++)
|
||||
{
|
||||
string[] moveData = activeMatchData[i].Split(',');
|
||||
PreviousMoves.Add((moveData[0], int.Parse(moveData[1])));
|
||||
}
|
||||
}
|
||||
OnWatchGameAck?.Invoke();
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user