From 99e1eabee96f46871dac516f000113396c7af32b Mon Sep 17 00:00:00 2001 From: Terry Hearst Date: Thu, 7 Mar 2024 23:14:05 -0500 Subject: [PATCH] Add menu option for entering custom words --- src/custom_setup.gd | 41 ++++++++ src/custom_setup.tscn | 213 ++++++++++++++++++++++++++++++++++++++++++ src/menu.gd | 5 + src/menu.tscn | 16 ++++ 4 files changed, 275 insertions(+) create mode 100644 src/custom_setup.gd create mode 100644 src/custom_setup.tscn diff --git a/src/custom_setup.gd b/src/custom_setup.gd new file mode 100644 index 0000000..bea0861 --- /dev/null +++ b/src/custom_setup.gd @@ -0,0 +1,41 @@ +extends Control + + +@onready var future_label: Label = %FutureLabel + +@onready var info_text: Label = %InfoText +@onready var info_text_animation: AnimationPlayer = %InfoTextAnimation +@onready var line_edit: LineEdit = %LineEdit + + + +func _ready() -> void: + if Global.allow_future: + future_label.hide() + line_edit.grab_focus() + + +func _on_back_button_pressed() -> void: + var error := get_tree().change_scene_to_file("res://src/menu.tscn") + assert(not error) + + +func _on_submit_button_pressed() -> void: + var word := line_edit.text.strip_edges() + var success := Global.parse_custom(word) + if success: + Global.game_mode = Global.GameMode.CUSTOM + var error := get_tree().change_scene_to_file("res://src/main.tscn") + assert(not error) + else: + show_error("Invalid word, code, or date") + + +func _on_line_edit_text_submitted(_new_text: String) -> void: + _on_submit_button_pressed() + + +func show_error(text: String): + info_text.text = text + info_text_animation.stop() + info_text_animation.play("ErrorMessage") diff --git a/src/custom_setup.tscn b/src/custom_setup.tscn new file mode 100644 index 0000000..f4be533 --- /dev/null +++ b/src/custom_setup.tscn @@ -0,0 +1,213 @@ +[gd_scene load_steps=11 format=3 uid="uid://bfj75uia2h1dg"] + +[ext_resource type="Script" path="res://src/custom_setup.gd" id="1_8hjff"] +[ext_resource type="FontFile" uid="uid://b7jasa607pvfx" path="res://fonts/Louis George Cafe Bold.ttf" id="2_f84gm"] + +[sub_resource type="FontFile" id="1"] +fallbacks = Array[Font]([ExtResource("2_f84gm")]) +cache/0/96/0/ascent = 0.0 +cache/0/96/0/descent = 0.0 +cache/0/96/0/underline_position = 0.0 +cache/0/96/0/underline_thickness = 0.0 +cache/0/96/0/scale = 1.0 +cache/0/96/0/kerning_overrides/96/0 = Vector2(0, 0) +cache/0/96/0/kerning_overrides/16/0 = Vector2(0, 0) +cache/0/96/0/kerning_overrides/64/0 = Vector2(0, 0) +cache/0/16/0/ascent = 0.0 +cache/0/16/0/descent = 0.0 +cache/0/16/0/underline_position = 0.0 +cache/0/16/0/underline_thickness = 0.0 +cache/0/16/0/scale = 1.0 +cache/0/16/0/kerning_overrides/96/0 = Vector2(0, 0) +cache/0/16/0/kerning_overrides/16/0 = Vector2(0, 0) +cache/0/16/0/kerning_overrides/64/0 = Vector2(0, 0) +cache/0/64/0/ascent = 0.0 +cache/0/64/0/descent = 0.0 +cache/0/64/0/underline_position = 0.0 +cache/0/64/0/underline_thickness = 0.0 +cache/0/64/0/scale = 1.0 +cache/0/64/0/kerning_overrides/96/0 = Vector2(0, 0) +cache/0/64/0/kerning_overrides/16/0 = Vector2(0, 0) +cache/0/64/0/kerning_overrides/64/0 = Vector2(0, 0) + +[sub_resource type="LabelSettings" id="LabelSettings_ea50h"] +font_size = 64 + +[sub_resource type="LabelSettings" id="LabelSettings_6at68"] +font_size = 24 + +[sub_resource type="LabelSettings" id="LabelSettings_fyik7"] +font_size = 18 +font_color = Color(1, 1, 1, 0.462745) + +[sub_resource type="FontFile" id="FontFile_rxf5o"] +fallbacks = Array[Font]([ExtResource("2_f84gm")]) +subpixel_positioning = 0 +msdf_pixel_range = 14 +msdf_size = 128 +cache/0/16/0/ascent = 0.0 +cache/0/16/0/descent = 0.0 +cache/0/16/0/underline_position = 0.0 +cache/0/16/0/underline_thickness = 0.0 +cache/0/16/0/scale = 1.0 +cache/0/16/0/kerning_overrides/16/0 = Vector2(0, 0) +cache/0/16/0/kerning_overrides/24/0 = Vector2(0, 0) +cache/0/24/0/ascent = 0.0 +cache/0/24/0/descent = 0.0 +cache/0/24/0/underline_position = 0.0 +cache/0/24/0/underline_thickness = 0.0 +cache/0/24/0/scale = 1.0 +cache/0/24/0/kerning_overrides/16/0 = Vector2(0, 0) +cache/0/24/0/kerning_overrides/24/0 = Vector2(0, 0) + +[sub_resource type="LabelSettings" id="LabelSettings_4n5sv"] +font_size = 24 +font_color = Color(1, 0.309804, 0.309804, 1) + +[sub_resource type="Animation" id="3"] +resource_name = "ErrorMessage" +length = 6.0 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("InfoText:modulate") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 5, 6), +"transitions": PackedFloat32Array(1, 1, 1), +"update": 0, +"values": [Color(1, 1, 1, 1), Color(1, 1, 1, 1), Color(1, 1, 1, 0)] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("InfoText:position") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0, 0.15, 0.35, 0.6), +"transitions": PackedFloat32Array(1, 0.5, -2, -2), +"update": 0, +"values": [Vector2(0, 0), Vector2(8, 0), Vector2(-8, 0), Vector2(0, 0)] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_qsyqi"] +_data = { +"ErrorMessage": SubResource("3") +} + +[node name="CustomSetup" 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_8hjff") + +[node name="C" type="CenterContainer" parent="."] +layout_mode = 0 +anchor_right = 1.0 +anchor_bottom = 1.0 + +[node name="V" type="VBoxContainer" parent="C"] +layout_mode = 2 +theme_override_constants/separation = 64 + +[node name="Title" type="Label" parent="C/V"] +layout_mode = 2 +theme_override_fonts/font = SubResource("1") +text = "Setup Custom" +label_settings = SubResource("LabelSettings_ea50h") +horizontal_alignment = 1 + +[node name="Help" type="VBoxContainer" parent="C/V"] +layout_mode = 2 +theme_override_constants/separation = 15 + +[node name="Header" type="Label" parent="C/V/Help"] +layout_mode = 2 +text = "Enter one of the following:" +horizontal_alignment = 1 + +[node name="Options" type="VBoxContainer" parent="C/V/Help"] +layout_mode = 2 + +[node name="WordLabel" type="Label" parent="C/V/Help/Options"] +layout_mode = 2 +text = "A five letter word, e.g. \"APPLE\"" +label_settings = SubResource("LabelSettings_6at68") +horizontal_alignment = 1 + +[node name="CodeLabel" type="Label" parent="C/V/Help/Options"] +layout_mode = 2 +text = "An encoded word, e.g. \"a00d57a\"" +label_settings = SubResource("LabelSettings_6at68") +horizontal_alignment = 1 + +[node name="DateLabel" type="Label" parent="C/V/Help/Options"] +layout_mode = 2 +text = "A date in YYYY-MM-DD format, e.g. +\"2024-01-23\"" +label_settings = SubResource("LabelSettings_6at68") +horizontal_alignment = 1 + +[node name="FutureLabel" type="Label" parent="C/V/Help/Options"] +unique_name_in_owner = true +layout_mode = 2 +text = "This date must not be in the future" +label_settings = SubResource("LabelSettings_fyik7") +horizontal_alignment = 1 + +[node name="Submission" type="VBoxContainer" parent="C/V"] +layout_mode = 2 +theme_override_constants/separation = 8 + +[node name="InfoTextHolder" type="Control" parent="C/V/Submission"] +custom_minimum_size = Vector2(0, 28) +layout_mode = 2 + +[node name="InfoText" type="Label" parent="C/V/Submission/InfoTextHolder"] +unique_name_in_owner = true +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_colors/font_color = Color(1, 0.309804, 0.309804, 1) +theme_override_fonts/font = SubResource("FontFile_rxf5o") +label_settings = SubResource("LabelSettings_4n5sv") +horizontal_alignment = 1 + +[node name="InfoTextAnimation" type="AnimationPlayer" parent="C/V/Submission/InfoTextHolder"] +unique_name_in_owner = true +libraries = { +"": SubResource("AnimationLibrary_qsyqi") +} + +[node name="LineEdit" type="LineEdit" parent="C/V/Submission"] +unique_name_in_owner = true +custom_minimum_size = Vector2(500, 0) +layout_mode = 2 +theme_override_font_sizes/font_size = 24 +placeholder_text = "word, code, or date" + +[node name="SubmitButton" type="Button" parent="C/V/Submission"] +custom_minimum_size = Vector2(200, 0) +layout_mode = 2 +size_flags_horizontal = 4 +focus_mode = 0 +text = "Submit" + +[node name="BackButton" type="Button" parent="C/V"] +custom_minimum_size = Vector2(200, 0) +layout_mode = 2 +size_flags_horizontal = 4 +focus_mode = 0 +text = "Back" + +[connection signal="text_submitted" from="C/V/Submission/LineEdit" to="." method="_on_line_edit_text_submitted"] +[connection signal="pressed" from="C/V/Submission/SubmitButton" to="." method="_on_submit_button_pressed"] +[connection signal="pressed" from="C/V/BackButton" to="." method="_on_back_button_pressed"] diff --git a/src/menu.gd b/src/menu.gd index c61e6cd..d66b42c 100644 --- a/src/menu.gd +++ b/src/menu.gd @@ -22,6 +22,11 @@ func _on_RandomButton_pressed() -> void: assert(not error) +func _on_custom_button_pressed() -> void: + var error := get_tree().change_scene_to_file("res://src/custom_setup.tscn") + assert(not error) + + func _on_CreditsButton_pressed() -> void: credits.show() diff --git a/src/menu.tscn b/src/menu.tscn index 4f6860c..6889772 100644 --- a/src/menu.tscn +++ b/src/menu.tscn @@ -124,6 +124,21 @@ text = "Different every time" label_settings = SubResource("LabelSettings_cdviw") horizontal_alignment = 1 +[node name="V3" type="VBoxContainer" parent="C/V/V2"] +custom_minimum_size = Vector2(310, 0) +layout_mode = 2 + +[node name="CustomButton" type="Button" parent="C/V/V2/V3"] +layout_mode = 2 +text = "Custom Gordle" + +[node name="Label" type="Label" parent="C/V/V2/V3"] +layout_mode = 2 +theme_override_fonts/font = SubResource("2") +text = "Choose your own word" +label_settings = SubResource("LabelSettings_cdviw") +horizontal_alignment = 1 + [node name="CreditsButton" type="Button" parent="C/V/V2"] layout_mode = 2 text = "Licenses" @@ -243,6 +258,7 @@ text = "Back" [connection signal="pressed" from="C/V/V2/V/DailyButton" to="." method="_on_DailyButton_pressed"] [connection signal="pressed" from="C/V/V2/V2/RandomButton" to="." method="_on_RandomButton_pressed"] +[connection signal="pressed" from="C/V/V2/V3/CustomButton" to="." method="_on_custom_button_pressed"] [connection signal="pressed" from="C/V/V2/CreditsButton" to="." method="_on_CreditsButton_pressed"] [connection signal="pressed" from="C/V/V2/QuitButton" to="." method="_on_QuitButton_pressed"] [connection signal="pressed" from="Credits/M/V/CreditsBackButton" to="." method="_on_CreditsBackButton_pressed"]