diff --git a/menu/Menu.gd b/menu/Menu.gd index 999c1eb..7c0c03d 100644 --- a/menu/Menu.gd +++ b/menu/Menu.gd @@ -3,14 +3,31 @@ extends Control signal play_pressed() +var username_regex + + +var username: String: + get: + return Singletons.username + set(value): + value = value.strip_escapes() + value = value.to_lower() + value = username_regex.sub(value, "-", true) + Singletons.username = value + var caret = $Content/Inputs/NameInput.caret_column + $Content/Inputs/NameInput.text = value + $Content/Inputs/NameInput.caret_column = caret + %PlayButton.disabled = len(value) <= 0 + + func play(): print("Player ", Singletons.username, " started playing!") emit_signal("play_pressed") -func _on_name_input_text_changed(): - Singletons.username = $Content/Inputs/NameInput.text - %PlayButton.disabled = false +func _on_name_input_text_changed(new_text): + if username != $Content/Inputs/NameInput.text: + username = $Content/Inputs/NameInput.text func _on_fetched_scores(): @@ -19,5 +36,7 @@ func _on_fetched_scores(): func _ready(): + username_regex = RegEx.new() + username_regex.compile("[^a-z0-9]") $"/root/BaseScene/ScoreboardContainer".connect("fetched_scores", _on_fetched_scores) $"/root/BaseScene/ScoreboardContainer".fetch_scores(false) diff --git a/menu/Menu.tscn b/menu/Menu.tscn index fc9c59e..afda128 100644 --- a/menu/Menu.tscn +++ b/menu/Menu.tscn @@ -52,7 +52,7 @@ layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 6 -[node name="NameInput" type="TextEdit" parent="Content/Inputs"] +[node name="NameInput" type="LineEdit" parent="Content/Inputs"] custom_minimum_size = Vector2(140, 28) layout_mode = 1 anchors_preset = 15 diff --git a/menu/menu_theme.tres b/menu/menu_theme.tres index 957e457..155baa1 100644 --- a/menu/menu_theme.tres +++ b/menu/menu_theme.tres @@ -1,4 +1,4 @@ -[gd_resource type="Theme" load_steps=11 format=3 uid="uid://c5a1nyqumj46j"] +[gd_resource type="Theme" load_steps=13 format=3 uid="uid://c5a1nyqumj46j"] [ext_resource type="FontFile" uid="uid://dvfq5l72ynw4s" path="res://assets/pixel_operator.ttf" id="1_tst0x"] @@ -49,6 +49,21 @@ corner_detail = 2 shadow_color = Color(1, 1, 1, 1) anti_aliasing = false +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_06vbp"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_0e8xu"] +bg_color = Color(0.156863, 0.207843, 0.25098, 1) +border_width_left = 2 +border_width_top = 2 +border_width_right = 2 +border_width_bottom = 2 +border_color = Color(0.388235, 0.670588, 0.247059, 1) +corner_radius_top_left = 2 +corner_radius_top_right = 2 +corner_radius_bottom_right = 2 +corner_radius_bottom_left = 2 +anti_aliasing = false + [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_20p1w"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jo6pk"] @@ -88,6 +103,10 @@ Label/colors/font_color = Color(1, 1, 1, 1) Label/constants/line_spacing = 2 Label/font_sizes/font_size = 16 Label/fonts/font = ExtResource("1_tst0x") +LineEdit/font_sizes/font_size = 16 +LineEdit/fonts/font = ExtResource("1_tst0x") +LineEdit/styles/focus = SubResource("StyleBoxEmpty_06vbp") +LineEdit/styles/normal = SubResource("StyleBoxFlat_0e8xu") TextEdit/font_sizes/font_size = 16 TextEdit/fonts/font = ExtResource("1_tst0x") TextEdit/styles/focus = SubResource("StyleBoxEmpty_20p1w")