ready buttons work

This commit is contained in:
Lexi Quinn 2023-06-07 01:24:11 +10:00
parent d9de0fc45c
commit 305c8d307a
9 changed files with 90 additions and 36 deletions

2
.gitignore vendored
View File

@ -13,3 +13,5 @@ export_presets.cfg
.mono/
data_*/
mono_crash.*.json
Project\ Exports/

View File

@ -1,3 +1,4 @@
class_name PlayerBoard
extends Node2D

Binary file not shown.

View File

@ -51,26 +51,18 @@ position = Vector2(1313, -747)
[node name="LobbyCamera" type="Camera2D" parent="."]
zoom = Vector2(0.225, 0.225)
[node name="Button" type="Button" parent="LobbyCamera"]
offset_left = -155.0
offset_top = -1410.0
offset_right = 149.0
offset_bottom = -1265.0
theme_override_font_sizes/font_size = 100
text = "Ready"
[node name="RichTextLabel" type="RichTextLabel" parent="LobbyCamera"]
offset_left = -2563.0
offset_top = 561.0
offset_right = -1210.0
offset_bottom = 1256.0
theme_override_font_sizes/normal_font_size = 100
fit_content = true
offset_top = 687.0
offset_right = -1417.0
offset_bottom = 1259.0
theme_override_font_sizes/normal_font_size = 50
scroll_following = true
script = ExtResource("4_dww8o")
[node name="LineEdit" type="LineEdit" parent="LobbyCamera"]
offset_left = -2547.0
offset_top = 1276.0
offset_right = -1204.0
offset_right = -1421.0
offset_bottom = 1421.0
theme_override_font_sizes/font_size = 100
theme_override_font_sizes/font_size = 50

View File

@ -1,14 +1,17 @@
[gd_scene load_steps=3 format=3 uid="uid://cpl32lvhwd5da"]
[ext_resource type="Script" path="res://Scripts/PlayerStateMachine/human_controller.gd" id="1_pu5r2"]
[ext_resource type="Script" path="res://Scripts/PlayerStateMachine/human_controller.gd" id="1_4thxs"]
[ext_resource type="Theme" uid="uid://d26ldkm1br1bo" path="res://UI_Theme.tres" id="2_ja0q8"]
[node name="HumanPlayer" type="Node2D"]
script = ExtResource("1_pu5r2")
script = ExtResource("1_4thxs")
[node name="Camera2D" type="Camera2D" parent="."]
visible = false
zoom = Vector2(0.4, 0.4)
[node name="UI" type="Control" parent="."]
visible = false
layout_mode = 3
anchors_preset = 0
offset_right = 40.0
@ -16,6 +19,7 @@ offset_bottom = 40.0
theme = ExtResource("2_ja0q8")
[node name="Cash" type="Label" parent="UI"]
visible = false
layout_mode = 0
offset_left = -561.0
offset_top = -27.0
@ -24,6 +28,7 @@ offset_bottom = -1.0
text = "$100"
[node name="Profit" type="Label" parent="UI"]
visible = false
layout_mode = 0
offset_left = -521.0
offset_top = -27.0
@ -34,6 +39,7 @@ text = "+23
"
[node name="Loss" type="Label" parent="UI"]
visible = false
layout_mode = 0
offset_left = -491.0
offset_top = -27.0
@ -43,6 +49,7 @@ theme_override_colors/font_color = Color(0.909804, 0, 0, 1)
text = "-38"
[node name="Phase" type="Label" parent="UI"]
visible = false
layout_mode = 0
offset_left = -113.0
offset_top = -311.0
@ -50,13 +57,20 @@ offset_right = 103.0
offset_bottom = -285.0
text = "{Management / Shift} Phase"
[node name="Label" type="Label" parent="UI"]
[node name="LobbyReadyButton" type="Button" parent="UI"]
layout_mode = 0
offset_left = -397.0
offset_top = -938.0
offset_right = 401.0
offset_bottom = -798.0
theme_override_font_sizes/font_size = 100
text = "99999999999999"
horizontal_alignment = 1
vertical_alignment = 1
offset_left = -26.0
offset_top = -313.0
offset_right = 30.0
offset_bottom = -282.0
text = "Ready"
[node name="LobbyReadyLabel" type="Label" parent="UI"]
layout_mode = 0
offset_left = 39.0
offset_top = -309.0
offset_right = 79.0
offset_bottom = -283.0
text = "0/4"
[connection signal="pressed" from="UI/LobbyReadyButton" to="." method="_on_lobby_ready_button_pressed"]

View File

@ -1,3 +1,25 @@
class_name HumanController
extends PlayerController
func _ready() -> void:
if not is_multiplayer_authority():
return
$Camera2D.make_current()
$UI.visible = true
@rpc("call_local")
func ready_player():
game.ready_player(own_id)
@rpc("any_peer")
func update_ready_label():
$UI/LobbyReadyLabel.text = str(game.readied_players.size()) + "/" + str(game.players.size())
func _on_lobby_ready_button_pressed() -> void:
rpc("ready_player")
$UI/LobbyReadyButton.visible = false
update_ready_label()

View File

@ -1,2 +1,6 @@
class_name PlayerController
extends Node
var game: Game
var board: PlayerBoard
var own_id: int

View File

@ -20,7 +20,9 @@ const CLIENT_DECK_SAVE_PATH = "user://client_deck.json"
@export var seat3: Node2D
@export var seat4: Node2D
var players = 0
var networked_controllers: Array[HumanController] = []
var players = []
var readied_players = []
var _worker_scene = preload("res://Scenes/worker_card.tscn")
var _client_scene = preload("res://Scenes/client_card.tscn")
@ -72,32 +74,49 @@ func _load_clients():
client_deck.shuffle()
@rpc
@rpc #Called by the network lobby code
func add_player(id: int, username: String, type: PlayerType) -> void:
if players >= 4:
if players.size() > 4:
return
if type == null:
type = PlayerType.HUMAN
var board = _player_scene.instantiate()
match players:
match players.size():
0:
board.position = seat1.position
board.global_position = seat1.position
1:
board.position = seat2.position
board.global_position = seat2.position
2:
board.position = seat3.position
board.global_position = seat3.position
3:
board.position = seat4.position
board.global_position = seat4.position
$Players.add_child(board)
var controller
match type:
PlayerType.HUMAN:
controller = _human_scene.instantiate()
networked_controllers.append(controller)
PlayerType.BOT:
controller = _bot_scene.instantiate()
controller.name = str(id)
controller.set_multiplayer_authority(id)
controller.get_node("UI/Label").text = str(username)
controller.own_id = id
controller.game = self as Game
controller.board = board as PlayerBoard
board.add_child(controller)
players += 1
players.append(id)
for player in networked_controllers:
player.rpc("update_ready_label")
func ready_player(id):
if not readied_players.has(id):
readied_players.append(id)
if readied_players.size() == players.size():
start_game()
for player in networked_controllers:
player.rpc("update_ready_label")
func start_game():
print("Game started!")