Skip to content

Commit 749005a

Browse files
committed
list open matches
formatting create and join matches added refresh button update players when players join - sort of.
1 parent a9274c7 commit 749005a

8 files changed

+382
-92
lines changed

src/nodes/hud/chat/MatchListing.cs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Godot;
2+
using System;
3+
4+
public partial class MatchListing : Button
5+
{
6+
private Label _nameLabel;
7+
private Label _playersLabel;
8+
9+
public override void _Ready()
10+
{
11+
_nameLabel = GetNode<Label>("MarginContainer/HBoxContainer/NameLabel");
12+
_playersLabel = GetNode<Label>("MarginContainer/HBoxContainer/PlayersLabel");
13+
}
14+
15+
public void UpdateInfo(string name, int players)
16+
{
17+
_nameLabel.Text = name;
18+
_playersLabel.Text = $"{players}";
19+
}
20+
}

src/nodes/hud/chat/MatchListing.tscn

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://cmq71hr7i8yac"]
2+
3+
[ext_resource type="Script" path="res://src/nodes/hud/chat/MatchListing.cs" id="1_kokcm"]
4+
5+
[node name="MatchListing" type="Button"]
6+
offset_right = 1378.0
7+
offset_bottom = 60.0
8+
rect_min_size = Vector2(0, 60)
9+
script = ExtResource( "1_kokcm" )
10+
__meta__ = {
11+
"_edit_use_anchors_": false
12+
}
13+
14+
[node name="MarginContainer" type="MarginContainer" parent="."]
15+
anchor_right = 1.0
16+
anchor_bottom = 1.0
17+
mouse_filter = 2
18+
theme_override_constants/margin_right = 4
19+
theme_override_constants/margin_top = 4
20+
theme_override_constants/margin_left = 4
21+
theme_override_constants/margin_bottom = 4
22+
__meta__ = {
23+
"_edit_use_anchors_": false
24+
}
25+
26+
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer"]
27+
offset_left = 4.0
28+
offset_top = 4.0
29+
offset_right = 1374.0
30+
offset_bottom = 56.0
31+
mouse_filter = 2
32+
__meta__ = {
33+
"_edit_use_anchors_": false
34+
}
35+
36+
[node name="NameLabel" type="Label" parent="MarginContainer/HBoxContainer"]
37+
offset_top = 13.0
38+
offset_right = 58.0
39+
offset_bottom = 39.0
40+
text = "Game 1"
41+
42+
[node name="Space" type="Control" parent="MarginContainer/HBoxContainer"]
43+
offset_left = 62.0
44+
offset_right = 1334.0
45+
offset_bottom = 52.0
46+
size_flags_horizontal = 3
47+
48+
[node name="PlayersLabel" type="Label" parent="MarginContainer/HBoxContainer"]
49+
offset_left = 1338.0
50+
offset_top = 13.0
51+
offset_right = 1370.0
52+
offset_bottom = 39.0
53+
text = "1 / 2"
54+
__meta__ = {
55+
"_edit_use_anchors_": false
56+
}

src/nodes/menu/FactionSelectionView.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public partial class FactionSelectionView : PanelContainer
1414

1515
public int LocalPlayerId { get; set; }
1616
public List<string> Players { get; set; }
17+
public int PlayerCount { get; set; }
1718
public string MapName { get; set; }
1819

1920
Dictionary<int, PlayerOption> _options = new Dictionary<int, PlayerOption>();
@@ -28,7 +29,7 @@ public override void _Ready()
2829
_continueButton = GetNode<Button>("CenterContainer/VBoxContainer/HBoxContainer/ContinueButton");
2930
_backButton = GetNode<Button>("CenterContainer/VBoxContainer/HBoxContainer/BackButton");
3031

31-
for (int side = 0; side < Players.Count; side++)
32+
for (int side = 0; side < PlayerCount; side++)
3233
{
3334
var option = _playerOption.Instantiate<PlayerOption>();
3435
option.Connect(nameof(PlayerOption.FactionChanged), new Callable(this, nameof(OnFactionChanged)));
@@ -40,6 +41,16 @@ public override void _Ready()
4041
}
4142
}
4243

44+
public void UpdatePlayers(List<string> players)
45+
{
46+
Players = players;
47+
48+
foreach (PlayerOption option in _container.GetChildren())
49+
{
50+
option.UpdatePlayers(players);
51+
}
52+
}
53+
4354
public void ChangeFaction(int side, int index)
4455
{
4556
_options[side].ChangeFaction(index);

src/nodes/menu/LobbyView.cs

+52-5
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,39 @@
44

55
public partial class LobbyView : Control
66
{
7+
[Signal] public delegate void MatchSelected(string matchId);
78
[Signal] public delegate void MessageSubmitted(string message);
89
[Signal] public delegate void ScenarioSelected(string mapName);
10+
[Signal] public delegate void RefreshButtonPressed();
911
[Signal] public delegate void JoinButtonPressed();
12+
[Signal] public delegate void CreateButtonPressed();
13+
[Signal] public delegate void QueueButtonPressed();
1014
[Signal] public delegate void BackButtonPressed();
1115
[Signal] public delegate void CancelButtonPressed();
1216

1317
[Export] private PackedScene ChatMessageView;
18+
[Export] private PackedScene MatchListing;
1419

1520
private VBoxContainer _userListContainer;
21+
private VBoxContainer _matchListContainer;
1622
private VBoxContainer _messages;
1723
private LineEdit _input;
1824

1925
private OptionButton _scenarioOptions;
26+
private Button _queueButton;
2027
private Button _joinButton;
2128
private Label _infoLabel;
2229

2330
public override void _Ready()
2431
{
2532
_userListContainer = GetNode<VBoxContainer>("PanelContainer/HBoxContainer/VBoxContainer2/Panel/VBoxContainer/UserList");
33+
_matchListContainer = GetNode<VBoxContainer>("PanelContainer/HBoxContainer/VBoxContainer/Panel2/MarginContainer/MatchList");
34+
2635
_messages = GetNode<VBoxContainer>("PanelContainer/HBoxContainer/VBoxContainer/Panel/MarginContainer/Messages");
2736
_input = GetNode<LineEdit>("PanelContainer/HBoxContainer/VBoxContainer/HBoxContainer/LineEdit");
2837

29-
_joinButton = GetNode<Button>("PanelContainer/HBoxContainer/VBoxContainer2/HBoxContainer/JoinButton");
38+
_queueButton = GetNode<Button>("PanelContainer/HBoxContainer/VBoxContainer2/HBoxContainer/QueueButton");
39+
_joinButton = GetNode<Button>("PanelContainer/HBoxContainer/VBoxContainer2/JoinButton");
3040
_infoLabel = GetNode<Label>("PanelContainer/HBoxContainer/VBoxContainer2/Label");
3141
_scenarioOptions = GetNode<OptionButton>("PanelContainer/HBoxContainer/VBoxContainer2/MapOptionButton");
3242

@@ -39,19 +49,37 @@ public override void _Ready()
3949
OnMapOptionButtonItemSelected(0);
4050
}
4151

42-
public void UpdateInfo(string text)
52+
public void UpdateInfoLabel(string text)
4353
{
4454
_infoLabel.Text = text;
4555
}
4656

47-
public void DisableJoinButton()
57+
public void UpdateMatchList(IApiMatchList matchList)
58+
{
59+
foreach (Node child in _matchListContainer.GetChildren())
60+
{
61+
_matchListContainer.RemoveChild(child);
62+
child.QueueFree();
63+
}
64+
65+
foreach (var match in matchList.Matches)
66+
{
67+
var listing = MatchListing.Instantiate<MatchListing>();
68+
listing.Connect("pressed", new Callable(this, nameof(OnMatchSelected)), new Godot.Collections.Array() { match.MatchId });
69+
_matchListContainer.AddChild(listing);
70+
71+
listing.UpdateInfo(match.MatchId, match.Size);
72+
}
73+
}
74+
75+
public void DisableQueueButton()
4876
{
49-
_joinButton.Disabled = true;
77+
_queueButton.Disabled = true;
5078
}
5179

5280
public void EnableJoinButton()
5381
{
54-
_joinButton.Disabled = false;
82+
_queueButton.Disabled = false;
5583
}
5684

5785
public void UpdateUsers(string username, List<IUserPresence> users)
@@ -93,10 +121,29 @@ public void NewMessage(string username, string message, string time)
93121
}
94122
}
95123

124+
private void OnMatchSelected(string matchId)
125+
{
126+
EmitSignal(nameof(MatchSelected), matchId);
127+
}
128+
129+
private void OnRefreshButtonPressed()
130+
{
131+
EmitSignal(nameof(RefreshButtonPressed));
132+
}
133+
96134
private void OnJoinButtonPressed()
97135
{
98136
EmitSignal(nameof(JoinButtonPressed));
99137
}
138+
private void OnCreateButtonPressed()
139+
{
140+
EmitSignal(nameof(CreateButtonPressed));
141+
}
142+
143+
private void OnQueueButtonPressed()
144+
{
145+
EmitSignal(nameof(QueueButtonPressed));
146+
}
100147

101148
private void OnCancelButtonPressed()
102149
{

0 commit comments

Comments
 (0)