added multiplayer connection. TODO: Sync Inventory values. Disable moving of other color tiles
This commit is contained in:
parent
e8cd148bc7
commit
3de181134d
13 changed files with 360 additions and 67 deletions
50
UI/BuildMenu.gd
Normal file
50
UI/BuildMenu.gd
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
extends Control
|
||||
|
||||
@onready var local_player_insects = $PanelContainer/MarginContainer/VBoxContainer/HBoxContainer2/LocalPlayerInsects
|
||||
@onready var remote_player_insects = $PanelContainer/MarginContainer/VBoxContainer/HBoxContainer2/RemotePlayerInsects
|
||||
|
||||
const INSECT_BUTTON = preload("res://UI/insect_button.tscn")
|
||||
|
||||
const default_insects = {
|
||||
#preload("res://Tile/Prefabs/Bee.tres"): 1,
|
||||
preload("res://Tile/Prefabs/Ant.tres"): 3,
|
||||
preload("res://Tile/Prefabs/Beetle.tres"): 2,
|
||||
preload("res://Tile/Prefabs/Grasshopper.tres"): 3,
|
||||
preload("res://Tile/Prefabs/Spider.tres"): 2,
|
||||
#preload("res://Tile/Prefabs/Ladybug.tres"): 1,
|
||||
#preload("res://Tile/Prefabs/Mosquito.tres"): 1,
|
||||
#preload("res://Tile/Prefabs/Pillbug.tres"): 1
|
||||
}
|
||||
|
||||
@onready var local_bee_button: InsectButton = $PanelContainer/MarginContainer/VBoxContainer/HBoxContainer2/LocalPlayerInsects/BeeButton
|
||||
@onready var remote_bee_button: InsectButton = $PanelContainer/MarginContainer/VBoxContainer/HBoxContainer2/RemotePlayerInsects/BeeButton
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
#var unique_array = default_insects.duplicate().map()
|
||||
local_bee_button.update_color(GameData.is_player_black)
|
||||
remote_bee_button.update_color(!GameData.is_player_black)
|
||||
|
||||
for key in default_insects.keys():
|
||||
#print(default_insects[key])
|
||||
var btn = INSECT_BUTTON.instantiate()
|
||||
btn.insect_resource = key
|
||||
btn.tile_count = default_insects[key]
|
||||
btn.is_black = GameData.is_player_black
|
||||
local_player_insects.add_child(btn)
|
||||
|
||||
for key in default_insects.keys():
|
||||
var btn = INSECT_BUTTON.instantiate()
|
||||
btn.insect_resource = key
|
||||
btn.tile_count = default_insects[key]
|
||||
btn.is_black = !GameData.is_player_black
|
||||
remote_player_insects.add_child(btn)
|
||||
remote_player_insects.move_child(btn, 0)
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
if Input.is_action_just_pressed("deselect_tile"):
|
||||
GameEvents.insect_placement_cancelled.emit()
|
||||
pass
|
||||
pass
|
||||
|
|
@ -12,7 +12,6 @@ custom_minimum_size = Vector2(64, 64)
|
|||
ignore_texture_size = true
|
||||
stretch_mode = 0
|
||||
script = ExtResource("1_scd5m")
|
||||
is_black = null
|
||||
|
||||
[node name="Hex" type="TextureRect" parent="."]
|
||||
texture_filter = 6
|
||||
|
|
|
|||
21
UI/join_menu.gd
Normal file
21
UI/join_menu.gd
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
extends Control
|
||||
|
||||
@onready var lobby_code_input = $PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/LobbyCodeInput
|
||||
|
||||
func _ready():
|
||||
WSClient.lobby_joined.connect(_on_lobby_joined)
|
||||
|
||||
func _on_lobby_joined(lobby: String) -> void:
|
||||
GameData.lobby_code = lobby
|
||||
|
||||
get_tree().change_scene_to_file("res://Multiplayer/Multiplayer.tscn")
|
||||
|
||||
func _process(delta):
|
||||
pass
|
||||
|
||||
func _on_back_button_pressed():
|
||||
get_tree().change_scene_to_file("res://main_menu.tscn")
|
||||
|
||||
func _on_connect_button_pressed():
|
||||
GameData.is_player_black = true
|
||||
WSClient.start(GameData.WEBSOCKET_ENDPOINT, lobby_code_input.text)
|
||||
61
UI/join_menu.tscn
Normal file
61
UI/join_menu.tscn
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://byp1oxm5a86xg"]
|
||||
|
||||
[ext_resource type="Script" path="res://UI/join_menu.gd" id="1_hswn2"]
|
||||
|
||||
[node name="JoinMenu" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_hswn2")
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -115.0
|
||||
offset_top = -76.5
|
||||
offset_right = 115.0
|
||||
offset_bottom = 76.5
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_left = 15
|
||||
theme_override_constants/margin_top = 15
|
||||
theme_override_constants/margin_right = 15
|
||||
theme_override_constants/margin_bottom = 15
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 15
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="LobbyCodeLabel" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Lobby-Code: "
|
||||
|
||||
[node name="LobbyCodeInput" type="LineEdit" parent="PanelContainer/MarginContainer/VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/minimum_character_width = 6
|
||||
max_length = 6
|
||||
shortcut_keys_enabled = false
|
||||
|
||||
[node name="ConnectButton" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Connect"
|
||||
|
||||
[node name="BackButton" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Back to menu"
|
||||
|
||||
[connection signal="pressed" from="PanelContainer/MarginContainer/VBoxContainer/ConnectButton" to="." method="_on_connect_button_pressed"]
|
||||
[connection signal="pressed" from="PanelContainer/MarginContainer/VBoxContainer/BackButton" to="." method="_on_back_button_pressed"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue