summaryrefslogtreecommitdiff
path: root/UI
diff options
context:
space:
mode:
Diffstat (limited to 'UI')
-rw-r--r--UI/Camera.gd29
-rw-r--r--UI/Lobby.tscn94
-rw-r--r--UI/PlayersList.tscn10
-rw-r--r--UI/PlayersListItem.tscn1
-rw-r--r--UI/Start.gd (renamed from UI/Lobby.gd)4
-rw-r--r--UI/Start.tscn60
-rw-r--r--UI/lobby.gd85
-rw-r--r--UI/lobby_theme.tres19
-rw-r--r--UI/players_list.gd3
9 files changed, 265 insertions, 40 deletions
diff --git a/UI/Camera.gd b/UI/Camera.gd
index 4e02662..8f075cd 100644
--- a/UI/Camera.gd
+++ b/UI/Camera.gd
@@ -14,12 +14,13 @@ var drag_anchor = Vector2.ZERO
func _input(event):
if event.is_action("camera_zoom_out"):
- var new_zoom = max(zoom.x - zoom_step, zoom_min)
- zoom = Vector2(new_zoom, new_zoom)
+ var min_zoom_min = limit_right / (get_viewport_rect().size.x / zoom.x)
+ if min_zoom_min >= 1.0:
+ var new_zoom = max(zoom.x - zoom_step, zoom_min)
+ zoom = Vector2(new_zoom, new_zoom)
if event.is_action("camera_zoom_in"):
var new_zoom = min(zoom.x + zoom_step, zoom_max)
zoom = Vector2(new_zoom, new_zoom)
- #global_position -= (global_position + (get_viewport_rect().size/2) - get_global_mouse_position())
if event.is_action_pressed("camera_drag"):
is_in_drag_mode = true
@@ -30,11 +31,29 @@ func _input(event):
func _process(_delta):
if is_in_drag_mode:
- global_position += drag_anchor - get_global_mouse_position()
+ set_new_position(global_position + drag_anchor - get_global_mouse_position())
var direction_h = Input.get_axis("ui_left", "ui_right")
var direction_v = Input.get_axis("ui_up", "ui_down")
- global_position += Vector2(direction_h * speed, direction_v * speed)
+
+ if direction_h != 0 or direction_v != 0:
+ set_new_position(global_position + Vector2(direction_h * speed, direction_v * speed))
+
+
+func set_new_position(new_position: Vector2):
+ new_position.x = clamp(
+ new_position.x,
+ limit_left,
+ limit_right - (get_viewport_rect().size.x / zoom.x)
+ )
+
+ new_position.y = clamp(
+ new_position.y,
+ limit_top,
+ limit_bottom - (get_viewport_rect().size.y / zoom.y)
+ )
+
+ global_position = new_position
func get_rect():
diff --git a/UI/Lobby.tscn b/UI/Lobby.tscn
index 4060f88..4cf9a8b 100644
--- a/UI/Lobby.tscn
+++ b/UI/Lobby.tscn
@@ -1,6 +1,7 @@
-[gd_scene load_steps=2 format=3 uid="uid://bcbxer883ygg7"]
+[gd_scene load_steps=3 format=3 uid="uid://r45j806p4a74"]
-[ext_resource type="Script" path="res://UI/Lobby.gd" id="1_f10dr"]
+[ext_resource type="Script" path="res://UI/lobby.gd" id="1_mm4gt"]
+[ext_resource type="Theme" uid="uid://bt84t61hrvoyn" path="res://UI/lobby_theme.tres" id="2_syjfh"]
[node name="Lobby" type="Control"]
layout_mode = 3
@@ -9,52 +10,91 @@ anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
-script = ExtResource("1_f10dr")
+script = ExtResource("1_mm4gt")
-[node name="CenterContainer" type="CenterContainer" parent="."]
+[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
+theme_override_constants/margin_left = 4
+theme_override_constants/margin_top = 4
+theme_override_constants/margin_right = 4
+theme_override_constants/margin_bottom = 4
-[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
+[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
layout_mode = 2
-[node name="Name" type="TextEdit" parent="CenterContainer/VBoxContainer"]
-unique_name_in_owner = true
-custom_minimum_size = Vector2(0, 50)
+[node name="CenterContainer" type="CenterContainer" parent="MarginContainer/VBoxContainer"]
+layout_mode = 2
+size_flags_vertical = 3
+
+[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer/CenterContainer"]
+layout_mode = 2
+size_flags_vertical = 3
+theme_override_constants/separation = 32
+
+[node name="PanelContainer" type="PanelContainer" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer"]
layout_mode = 2
-placeholder_text = "Name"
+size_flags_horizontal = 3
-[node name="Host" type="Button" parent="CenterContainer/VBoxContainer"]
+[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer/PanelContainer"]
+layout_mode = 2
+theme_override_constants/margin_left = 4
+theme_override_constants/margin_top = 4
+theme_override_constants/margin_right = 4
+theme_override_constants/margin_bottom = 4
+
+[node name="PlayersList" type="VBoxContainer" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer/PanelContainer/MarginContainer"]
unique_name_in_owner = true
+custom_minimum_size = Vector2(0, 100)
+layout_mode = 2
+
+[node name="Control" type="MarginContainer" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer/PanelContainer/MarginContainer/PlayersList"]
+layout_mode = 2
+
+[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer/PanelContainer/MarginContainer/PlayersList/Control"]
layout_mode = 2
-theme_override_font_sizes/font_size = 24
-text = "Host"
+text = "A"
-[node name="IP" type="TextEdit" parent="CenterContainer/VBoxContainer"]
+[node name="Control2" type="MarginContainer" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer/PanelContainer/MarginContainer/PlayersList"]
+layout_mode = 2
+
+[node name="Label2" type="Label" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer/PanelContainer/MarginContainer/PlayersList/Control2"]
+layout_mode = 2
+text = "B"
+
+[node name="Maps" type="VBoxContainer" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer"]
unique_name_in_owner = true
-custom_minimum_size = Vector2(150, 50)
layout_mode = 2
-size_flags_vertical = 3
-theme_override_font_sizes/font_size = 18
-placeholder_text = "Join IP"
+size_flags_horizontal = 3
+theme = ExtResource("2_syjfh")
+
+[node name="MapButton" type="Button" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer/Maps"]
+layout_mode = 2
+toggle_mode = true
+text = "Wintermaul"
+
+[node name="MapButton2" type="Button" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer/Maps"]
+layout_mode = 2
+toggle_mode = true
+text = "Squares"
-[node name="Port" type="TextEdit" parent="CenterContainer/VBoxContainer"]
+[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/VBoxContainer"]
+layout_mode = 2
+size_flags_horizontal = 8
+
+[node name="StartButton" type="Button" parent="MarginContainer/VBoxContainer/VBoxContainer"]
unique_name_in_owner = true
-custom_minimum_size = Vector2(150, 50)
layout_mode = 2
-size_flags_vertical = 3
-theme_override_font_sizes/font_size = 18
-placeholder_text = "Host&Join Port"
+text = "Start"
-[node name="Join" type="Button" parent="CenterContainer/VBoxContainer"]
+[node name="CancelButton" type="Button" parent="MarginContainer/VBoxContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
-theme_override_font_sizes/font_size = 24
-text = "Join"
+text = "Cancel"
-[connection signal="pressed" from="CenterContainer/VBoxContainer/Host" to="." method="_on_host_pressed"]
-[connection signal="pressed" from="CenterContainer/VBoxContainer/Join" to="." method="_on_join_pressed"]
+[connection signal="pressed" from="MarginContainer/VBoxContainer/VBoxContainer/StartButton" to="." method="_on_start_button_pressed"]
+[connection signal="pressed" from="MarginContainer/VBoxContainer/VBoxContainer/CancelButton" to="." method="_on_cancel_button_pressed"]
diff --git a/UI/PlayersList.tscn b/UI/PlayersList.tscn
index 12bdf37..f3bde9b 100644
--- a/UI/PlayersList.tscn
+++ b/UI/PlayersList.tscn
@@ -19,16 +19,16 @@ theme_override_constants/margin_bottom = 8
unique_name_in_owner = true
layout_mode = 2
-[node name="PlayersListItem" parent="MarginContainer/List" instance=ExtResource("2_ug8m7")]
+[node name="Header" parent="MarginContainer/List" instance=ExtResource("2_ug8m7")]
layout_mode = 2
-[node name="ID" parent="MarginContainer/List/PlayersListItem/HBoxContainer" index="0"]
+[node name="ID" parent="MarginContainer/List/Header/HBoxContainer" index="0"]
text = "ID"
-[node name="Score" parent="MarginContainer/List/PlayersListItem/HBoxContainer" index="2"]
+[node name="Score" parent="MarginContainer/List/Header/HBoxContainer" index="2"]
text = "Score"
-[node name="Indicator" parent="MarginContainer/List/PlayersListItem" index="1"]
+[node name="Indicator" parent="MarginContainer/List/Header" index="1"]
visible = false
-[editable path="MarginContainer/List/PlayersListItem"]
+[editable path="MarginContainer/List/Header"]
diff --git a/UI/PlayersListItem.tscn b/UI/PlayersListItem.tscn
index 53b98f9..36a934b 100644
--- a/UI/PlayersListItem.tscn
+++ b/UI/PlayersListItem.tscn
@@ -15,6 +15,7 @@ layout_mode = 2
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
+mouse_filter = 1
text = "1"
horizontal_alignment = 1
clip_text = true
diff --git a/UI/Lobby.gd b/UI/Start.gd
index ba76ecc..c9a0342 100644
--- a/UI/Lobby.gd
+++ b/UI/Start.gd
@@ -26,10 +26,10 @@ func get_port():
func _on_host_pressed() -> void:
Client.player.username = %Name.text
Network.host_game(get_port())
- get_tree().change_scene_to_file("res://Stages/world.tscn")
+ get_tree().change_scene_to_file("res://UI/Lobby.tscn")
func _on_join_pressed() -> void:
Client.player.username = %Name.text
Network.join_game(get_ip(), get_port())
- get_tree().change_scene_to_file("res://Stages/world.tscn")
+ get_tree().change_scene_to_file("res://UI/Lobby.tscn")
diff --git a/UI/Start.tscn b/UI/Start.tscn
new file mode 100644
index 0000000..b85d869
--- /dev/null
+++ b/UI/Start.tscn
@@ -0,0 +1,60 @@
+[gd_scene load_steps=2 format=3 uid="uid://bcbxer883ygg7"]
+
+[ext_resource type="Script" path="res://UI/Start.gd" id="1_h1h6c"]
+
+[node name="Start" 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_h1h6c")
+
+[node name="CenterContainer" type="CenterContainer" parent="."]
+layout_mode = 1
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
+
+[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
+layout_mode = 2
+
+[node name="Name" type="TextEdit" parent="CenterContainer/VBoxContainer"]
+unique_name_in_owner = true
+custom_minimum_size = Vector2(0, 50)
+layout_mode = 2
+placeholder_text = "Name"
+
+[node name="Host" type="Button" parent="CenterContainer/VBoxContainer"]
+unique_name_in_owner = true
+layout_mode = 2
+theme_override_font_sizes/font_size = 24
+text = "Host"
+
+[node name="IP" type="TextEdit" parent="CenterContainer/VBoxContainer"]
+unique_name_in_owner = true
+custom_minimum_size = Vector2(150, 50)
+layout_mode = 2
+size_flags_vertical = 3
+theme_override_font_sizes/font_size = 18
+placeholder_text = "Join IP"
+
+[node name="Port" type="TextEdit" parent="CenterContainer/VBoxContainer"]
+unique_name_in_owner = true
+custom_minimum_size = Vector2(150, 50)
+layout_mode = 2
+size_flags_vertical = 3
+theme_override_font_sizes/font_size = 18
+placeholder_text = "Host&Join Port"
+
+[node name="Join" type="Button" parent="CenterContainer/VBoxContainer"]
+unique_name_in_owner = true
+layout_mode = 2
+theme_override_font_sizes/font_size = 24
+text = "Join"
+
+[connection signal="pressed" from="CenterContainer/VBoxContainer/Host" to="." method="_on_host_pressed"]
+[connection signal="pressed" from="CenterContainer/VBoxContainer/Join" to="." method="_on_join_pressed"]
diff --git a/UI/lobby.gd b/UI/lobby.gd
new file mode 100644
index 0000000..86bfa4c
--- /dev/null
+++ b/UI/lobby.gd
@@ -0,0 +1,85 @@
+extends Control
+
+
+signal joined
+
+var current_map_idx := 0
+
+@onready var list: VBoxContainer = %PlayersList
+
+
+func _ready() -> void:
+ if not multiplayer.is_server():
+ %StartButton.visible = false
+ %StartButton.queue_free()
+
+ %PlayersList.remove_child(%PlayersList.get_child(0))
+ %PlayersList.remove_child(%PlayersList.get_child(0))
+
+ if multiplayer.is_server():
+ set_map.rpc(current_map_idx)
+ joined.connect(func():
+ set_map.rpc(current_map_idx)
+ )
+ for idx in %Maps.get_child_count():
+ %Maps.get_child(idx).pressed.connect(func():
+ current_map_idx = idx
+ set_map.rpc(idx)
+ )
+ if not multiplayer.is_server():
+ set_map(0)
+ for node: Control in %Maps.get_children():
+ node.mouse_filter = Control.MOUSE_FILTER_IGNORE
+
+ Network.players_changed.connect(update_players)
+ update_players()
+
+ multiplayer.peer_disconnected.connect(remove_player)
+
+
+func update_players():
+ for id in Network.get_ordered_player_ids():
+ var player: Player = Network.get_player(id)
+
+ var control: Control = list.get_node_or_null(str(id))
+ if not control:
+ control = MarginContainer.new()
+ control.name = str(id)
+ var label = Label.new()
+ label.add_theme_color_override("font_color", player.get_color())
+ if id == multiplayer.get_unique_id():
+ label.add_theme_color_override("font_outline_color", Color(0.75, 0.75, 0.75, 0.75))
+ label.add_theme_constant_override("outline_size", 10)
+ control.add_child(label)
+ list.add_child(control)
+ joined.emit()
+
+ control.get_child(0).text = str(player.username)
+ control.get_child(0).tooltip_text = str(id)
+ list.move_child(control, Network.get_ordered_player_ids().find(id) + 1)
+
+
+func remove_player(id):
+ list.remove_child(list.get_node(str(id)))
+
+
+func _on_start_button_pressed() -> void:
+ start.rpc()
+
+
+func _on_cancel_button_pressed() -> void:
+ multiplayer.multiplayer_peer.close()
+ get_tree().change_scene_to_file("res://UI/Start.tscn")
+
+
+@rpc("authority", "call_local")
+func start():
+ get_tree().change_scene_to_file("res://Stages/Wintermaul.tscn")
+
+
+@rpc("authority", "call_local")
+func set_map(index: int):
+ for node: Button in %Maps.get_children():
+ node.add_theme_color_override("font_color", Color(1.0, 1.0, 1.0, 0.5))
+
+ %Maps.get_child(index).add_theme_color_override("font_color", Color(1.0, 1.0, 1.0, 1.0))
diff --git a/UI/lobby_theme.tres b/UI/lobby_theme.tres
new file mode 100644
index 0000000..f983c2f
--- /dev/null
+++ b/UI/lobby_theme.tres
@@ -0,0 +1,19 @@
+[gd_resource type="Theme" load_steps=3 format=3 uid="uid://bt84t61hrvoyn"]
+
+[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_vhn61"]
+content_margin_left = 4.0
+content_margin_top = 4.0
+content_margin_right = 4.0
+content_margin_bottom = 4.0
+bg_color = Color(0, 0, 0, 1)
+
+[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_4s0gx"]
+content_margin_left = 4.0
+content_margin_top = 4.0
+content_margin_right = 4.0
+content_margin_bottom = 4.0
+bg_color = Color(0, 0, 0, 1)
+
+[resource]
+Button/styles/disabled = SubResource("StyleBoxFlat_vhn61")
+Button/styles/normal = SubResource("StyleBoxFlat_4s0gx")
diff --git a/UI/players_list.gd b/UI/players_list.gd
index 6cfd26c..598d7ad 100644
--- a/UI/players_list.gd
+++ b/UI/players_list.gd
@@ -26,8 +26,9 @@ func update_players():
list.add_child(control)
control.get_node("%ID").text = str(player.username)
+ control.get_node("%ID").tooltip_text = str(id)
control.get_node("%Score").text = str(player.score)
- #list.move_child(control, Network.get_ordered_player_ids().find(id) + 1)
+ list.move_child(control, Network.get_ordered_player_ids().find(id) + 1)
func remove_player(id):