feat: most of BracketScene done, need admin auth
This commit is contained in:
@@ -4,15 +4,31 @@ using System.Collections.Generic;
|
||||
|
||||
public partial class BracketScene : Control
|
||||
{
|
||||
[Export] public Tree players;
|
||||
[Export] public Tree Players;
|
||||
[Export] public Tree Matches;
|
||||
[Export] public Texture2D JoinButton;
|
||||
[Export] public PackedScene BoardScene;
|
||||
|
||||
private List<PlayerData> _playerList;
|
||||
private List<MatchData> _matchList;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
players.SetColumnTitle(0, "Name");
|
||||
players.SetColumnTitle(1, "Ready");
|
||||
players.SetColumnTitle(2, "Playing");
|
||||
Players.SetColumnTitle(0, "Name");
|
||||
Players.SetColumnTitle(1, "Ready");
|
||||
Players.SetColumnTitle(2, "Playing");
|
||||
Players.HideRoot = true;
|
||||
Players.ButtonClicked += KickPlayer;
|
||||
|
||||
|
||||
Matches.SetColumnTitle(0, "Match");
|
||||
Matches.SetColumnTitle(1, "Red");
|
||||
Matches.SetColumnTitle(2, "Yellow");
|
||||
Matches.HideRoot = true;
|
||||
Matches.ButtonClicked += WatchGame;
|
||||
|
||||
Connection.Instance.OnUpdatedPlayers += UpdatePlayers;
|
||||
Connection.Instance.OnUpdatedMatches += UpdateMatches;
|
||||
Connection.Instance.OnBecomeAdmin += BecomeAdmin;
|
||||
Connection.Instance.OnWatchGameAck += TransitionToBoard;
|
||||
}
|
||||
@@ -20,19 +36,59 @@ public partial class BracketScene : Control
|
||||
public override void _ExitTree()
|
||||
{
|
||||
Connection.Instance.OnUpdatedPlayers -= UpdatePlayers;
|
||||
Connection.Instance.OnUpdatedMatches -= UpdateMatches;
|
||||
Connection.Instance.OnBecomeAdmin -= BecomeAdmin;
|
||||
Connection.Instance.OnWatchGameAck -= TransitionToBoard;
|
||||
}
|
||||
|
||||
private void UpdatePlayers(List<PlayerData> playerList)
|
||||
{
|
||||
players.Clear();
|
||||
foreach (var playerData in playerList)
|
||||
Players.Clear();
|
||||
_playerList = playerList;
|
||||
var root = Players.CreateItem();
|
||||
for (int i = 0; i < _playerList.Count; i++)
|
||||
{
|
||||
var item = players.CreateItem();
|
||||
item.SetText(0, playerData.username);
|
||||
item.SetText(1, playerData.isReady ? "Yes" : "No");
|
||||
item.SetText(2, playerData.isPlaying ? "Yes" : "No");
|
||||
var item = Players.CreateItem(root);
|
||||
item.SetText(0, playerList[i].username);
|
||||
item.SetText(1, playerList[i].isReady ? "Yes" : "No");
|
||||
item.SetText(2, playerList[i].isPlaying ? "Yes" : "No");
|
||||
if (Connection.Instance.IsAdmin)
|
||||
{
|
||||
item.AddButton(0, JoinButton, i, false, "Kick"); // TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateMatches(List<MatchData> matchList)
|
||||
{
|
||||
Matches.Clear();
|
||||
_matchList = matchList;
|
||||
var root = Matches.CreateItem();
|
||||
for (int i = 0; i < matchList.Count; i++)
|
||||
{
|
||||
var item = Matches.CreateItem(root);
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
private void WatchGame(TreeItem item, long column, long id, long mouseButtonIndex)
|
||||
{
|
||||
if (mouseButtonIndex == 1 && column == 0)
|
||||
{
|
||||
Connection.Instance.SendWatchGame(_matchList[(int) id].matchId);
|
||||
}
|
||||
}
|
||||
|
||||
private void KickPlayer(TreeItem item, long column, long id, long mouseButtonIndex)
|
||||
{
|
||||
if (mouseButtonIndex == 1 && column == 0)
|
||||
{
|
||||
Connection.Instance.KickPlayer(_playerList[(int) id].username);
|
||||
}
|
||||
}
|
||||
|
||||
private void BecomeAdmin()
|
||||
{
|
||||
@@ -42,5 +98,7 @@ public partial class BracketScene : Control
|
||||
private void TransitionToBoard()
|
||||
{
|
||||
// TODO
|
||||
GD.Print("Watch game worked!");
|
||||
GetTree().ChangeSceneToPacked(BoardScene);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user