Small refactor and add animations for info text
This commit is contained in:
parent
a9da1e6f3f
commit
af1aa840ca
2 changed files with 135 additions and 62 deletions
60
src/main.gd
60
src/main.gd
|
@ -4,7 +4,7 @@ extends Control
|
|||
const letter_count := 5
|
||||
const guess_count := 6
|
||||
|
||||
const Letter = preload("res://src/letter.tscn")
|
||||
const Letter := preload("res://src/letter.tscn")
|
||||
|
||||
@export var color_incorrect: Color = Color()
|
||||
@export var color_misplaced: Color = Color()
|
||||
|
@ -19,17 +19,27 @@ var current_guess: int
|
|||
var ended: bool
|
||||
var input_guess: String
|
||||
|
||||
@onready var error_text_color_default = $C/V/ErrorText.label_settings.font_color
|
||||
@onready var title: Label = %Title
|
||||
@onready var letter_grid: GridContainer = %LetterGrid
|
||||
@onready var info_text: Label = %InfoText
|
||||
|
||||
@onready var keyboard_vbox: VBoxContainer = %KeyboardVBox
|
||||
@onready var guess_button: Button = %GuessButton
|
||||
@onready var backspace_button: Button = %ButtonBksp
|
||||
|
||||
@onready var info_text_animation: AnimationPlayer = %InfoTextAnimation
|
||||
|
||||
@onready var error_text_color_default := info_text.label_settings.font_color
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
$C/V/LetterGrid.columns = letter_count
|
||||
letter_grid.columns = letter_count
|
||||
for _i in range(guess_count):
|
||||
var letter_array := []
|
||||
for _j in range(letter_count):
|
||||
var letter := Letter.instantiate()
|
||||
letter_array.append(letter)
|
||||
$C/V/LetterGrid.add_child(letter)
|
||||
letter_grid.add_child(letter)
|
||||
letters.append(letter_array)
|
||||
|
||||
var random_seed = null
|
||||
|
@ -40,9 +50,9 @@ func _ready() -> void:
|
|||
current_time["second"] = 0
|
||||
random_seed = Time.get_unix_time_from_datetime_dict(current_time)
|
||||
|
||||
$C/V/Title.text = "Daily " + $C/V/Title.text
|
||||
title.text = "Daily " + title.text
|
||||
else:
|
||||
$C/V/Title.text = "Random " + $C/V/Title.text
|
||||
title.text = "Random " + title.text
|
||||
|
||||
target_word = Global.generate_word(letter_count, random_seed)
|
||||
current_guess = 0
|
||||
|
@ -50,7 +60,7 @@ func _ready() -> void:
|
|||
|
||||
for i in range(0, 26):
|
||||
var letter := char("A".unicode_at(0) + i)
|
||||
var keyboard_button: Button = $C/V/V.find_child("Button" + letter)
|
||||
var keyboard_button: Button = keyboard_vbox.find_child("Button" + letter)
|
||||
keyboard_buttons[letter] = keyboard_button
|
||||
var error := keyboard_button.connect("pressed", Callable(self, "type_letter").bind(letter))
|
||||
assert(not error)
|
||||
|
@ -109,7 +119,7 @@ func guess_entered() -> void:
|
|||
for letter in target_word:
|
||||
letters_remaining.append(letter)
|
||||
|
||||
hide_error()
|
||||
hide_info()
|
||||
|
||||
# Mark all greens
|
||||
for i in range(letter_count):
|
||||
|
@ -161,28 +171,34 @@ func guess_entered() -> void:
|
|||
input_guess = ""
|
||||
|
||||
if ended:
|
||||
$C/V/V/GuessButton.disabled = true
|
||||
guess_button.disabled = true
|
||||
for letter in keyboard_buttons:
|
||||
keyboard_buttons[letter].disabled = true
|
||||
$C/V/V/HRow3/ButtonBksp.disabled = true
|
||||
backspace_button.disabled = true
|
||||
if won:
|
||||
show_error("Congrats! You won!", Color(0.4, 0.9, 0.6))
|
||||
show_info("Congrats! You won!", Color(0.4, 0.9, 0.6))
|
||||
else:
|
||||
show_error("Game Over. The word was %s" % target_word, error_text_color_default)
|
||||
show_info("Game Over. The word was %s" % target_word, error_text_color_default)
|
||||
|
||||
|
||||
func show_error(text: String, color = null):
|
||||
$C/V/ErrorText.text = text
|
||||
if typeof(color) == TYPE_COLOR:
|
||||
$ErrorFadeOut.stop()
|
||||
$C/V/ErrorText.label_settings.font_color = color
|
||||
else:
|
||||
$ErrorFadeOut.play("ErrorFadeOut")
|
||||
func show_error(text: String):
|
||||
info_text.text = text
|
||||
info_text.label_settings.font_color = error_text_color_default
|
||||
info_text_animation.stop()
|
||||
info_text_animation.play("ErrorMessage")
|
||||
info_text.show()
|
||||
|
||||
|
||||
func hide_error():
|
||||
$C/V/ErrorText.text = ""
|
||||
$ErrorFadeOut.stop()
|
||||
func show_info(text: String, color: Color):
|
||||
info_text_animation.play("RESET")
|
||||
info_text.text = text
|
||||
info_text.label_settings.font_color = color
|
||||
info_text.show()
|
||||
|
||||
|
||||
func hide_info():
|
||||
info_text_animation.play("RESET")
|
||||
info_text.hide()
|
||||
|
||||
|
||||
func _on_MenuButton_pressed() -> void:
|
||||
|
|
137
src/main.tscn
137
src/main.tscn
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=10 format=3 uid="uid://busmmqyj42lv5"]
|
||||
[gd_scene load_steps=11 format=3 uid="uid://busmmqyj42lv5"]
|
||||
|
||||
[ext_resource type="FontFile" uid="uid://b7jasa607pvfx" path="res://fonts/Louis George Cafe Bold.ttf" id="1"]
|
||||
[ext_resource type="Script" path="res://src/main.gd" id="2"]
|
||||
|
@ -62,12 +62,12 @@ cache/0/36/0/kerning_overrides/16/0 = Vector2(0, 0)
|
|||
cache/0/36/0/kerning_overrides/36/0 = Vector2(0, 0)
|
||||
|
||||
[sub_resource type="Animation" id="3"]
|
||||
resource_name = "ErrorFadeOut"
|
||||
resource_name = "ErrorMessage"
|
||||
length = 6.0
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("C/V/ErrorText:modulate")
|
||||
tracks/0/path = NodePath("C/V/InfoTextHolder/InfoText:modulate")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
|
@ -76,10 +76,51 @@ tracks/0/keys = {
|
|||
"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("C/V/InfoTextHolder/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="Animation" id="Animation_weygv"]
|
||||
resource_name = "RESET"
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("C/V/InfoTextHolder/InfoText:modulate")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Color(1, 1, 1, 1)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("C/V/InfoTextHolder/InfoText:position")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_qsyqi"]
|
||||
_data = {
|
||||
"ErrorFadeOut": SubResource("3")
|
||||
"ErrorMessage": SubResource("3"),
|
||||
"RESET": SubResource("Animation_weygv")
|
||||
}
|
||||
|
||||
[node name="Main" type="Control"]
|
||||
|
@ -104,6 +145,7 @@ layout_mode = 2
|
|||
theme_override_constants/separation = 20
|
||||
|
||||
[node name="Title" type="Label" parent="C/V"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_fonts/font = SubResource("1")
|
||||
text = "Gordle"
|
||||
|
@ -111,197 +153,211 @@ label_settings = SubResource("LabelSettings_h2dux")
|
|||
horizontal_alignment = 1
|
||||
|
||||
[node name="LetterGrid" type="GridContainer" parent="C/V"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
theme_override_constants/h_separation = 8
|
||||
theme_override_constants/v_separation = 8
|
||||
columns = 5
|
||||
|
||||
[node name="ErrorText" type="Label" parent="C/V"]
|
||||
[node name="InfoTextHolder" type="Control" parent="C/V"]
|
||||
custom_minimum_size = Vector2(0, 28)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="InfoText" type="Label" parent="C/V/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("2")
|
||||
label_settings = SubResource("LabelSettings_81m3s")
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="V" type="VBoxContainer" parent="C/V"]
|
||||
[node name="KeyboardVBox" type="VBoxContainer" parent="C/V"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
[node name="HRow1" type="HBoxContainer" parent="C/V/V"]
|
||||
[node name="HRow1" type="HBoxContainer" parent="C/V/KeyboardVBox"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
|
||||
[node name="ButtonQ" type="Button" parent="C/V/V/HRow1"]
|
||||
[node name="ButtonQ" type="Button" parent="C/V/KeyboardVBox/HRow1"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "Q"
|
||||
|
||||
[node name="ButtonW" type="Button" parent="C/V/V/HRow1"]
|
||||
[node name="ButtonW" type="Button" parent="C/V/KeyboardVBox/HRow1"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "W"
|
||||
|
||||
[node name="ButtonE" type="Button" parent="C/V/V/HRow1"]
|
||||
[node name="ButtonE" type="Button" parent="C/V/KeyboardVBox/HRow1"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "E"
|
||||
|
||||
[node name="ButtonR" type="Button" parent="C/V/V/HRow1"]
|
||||
[node name="ButtonR" type="Button" parent="C/V/KeyboardVBox/HRow1"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "R"
|
||||
|
||||
[node name="ButtonT" type="Button" parent="C/V/V/HRow1"]
|
||||
[node name="ButtonT" type="Button" parent="C/V/KeyboardVBox/HRow1"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "T"
|
||||
|
||||
[node name="ButtonY" type="Button" parent="C/V/V/HRow1"]
|
||||
[node name="ButtonY" type="Button" parent="C/V/KeyboardVBox/HRow1"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "Y"
|
||||
|
||||
[node name="ButtonU" type="Button" parent="C/V/V/HRow1"]
|
||||
[node name="ButtonU" type="Button" parent="C/V/KeyboardVBox/HRow1"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "U"
|
||||
|
||||
[node name="ButtonI" type="Button" parent="C/V/V/HRow1"]
|
||||
[node name="ButtonI" type="Button" parent="C/V/KeyboardVBox/HRow1"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "I"
|
||||
|
||||
[node name="ButtonO" type="Button" parent="C/V/V/HRow1"]
|
||||
[node name="ButtonO" type="Button" parent="C/V/KeyboardVBox/HRow1"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "O"
|
||||
|
||||
[node name="ButtonP" type="Button" parent="C/V/V/HRow1"]
|
||||
[node name="ButtonP" type="Button" parent="C/V/KeyboardVBox/HRow1"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "P"
|
||||
|
||||
[node name="HRow2" type="HBoxContainer" parent="C/V/V"]
|
||||
[node name="HRow2" type="HBoxContainer" parent="C/V/KeyboardVBox"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
|
||||
[node name="ButtonA" type="Button" parent="C/V/V/HRow2"]
|
||||
[node name="ButtonA" type="Button" parent="C/V/KeyboardVBox/HRow2"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "A"
|
||||
|
||||
[node name="ButtonS" type="Button" parent="C/V/V/HRow2"]
|
||||
[node name="ButtonS" type="Button" parent="C/V/KeyboardVBox/HRow2"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "S"
|
||||
|
||||
[node name="ButtonD" type="Button" parent="C/V/V/HRow2"]
|
||||
[node name="ButtonD" type="Button" parent="C/V/KeyboardVBox/HRow2"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "D"
|
||||
|
||||
[node name="ButtonF" type="Button" parent="C/V/V/HRow2"]
|
||||
[node name="ButtonF" type="Button" parent="C/V/KeyboardVBox/HRow2"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "F"
|
||||
|
||||
[node name="ButtonG" type="Button" parent="C/V/V/HRow2"]
|
||||
[node name="ButtonG" type="Button" parent="C/V/KeyboardVBox/HRow2"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "G"
|
||||
|
||||
[node name="ButtonH" type="Button" parent="C/V/V/HRow2"]
|
||||
[node name="ButtonH" type="Button" parent="C/V/KeyboardVBox/HRow2"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "H"
|
||||
|
||||
[node name="ButtonJ" type="Button" parent="C/V/V/HRow2"]
|
||||
[node name="ButtonJ" type="Button" parent="C/V/KeyboardVBox/HRow2"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "J"
|
||||
|
||||
[node name="ButtonK" type="Button" parent="C/V/V/HRow2"]
|
||||
[node name="ButtonK" type="Button" parent="C/V/KeyboardVBox/HRow2"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "K"
|
||||
|
||||
[node name="ButtonL" type="Button" parent="C/V/V/HRow2"]
|
||||
[node name="ButtonL" type="Button" parent="C/V/KeyboardVBox/HRow2"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "L"
|
||||
|
||||
[node name="HRow3" type="HBoxContainer" parent="C/V/V"]
|
||||
[node name="HRow3" type="HBoxContainer" parent="C/V/KeyboardVBox"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
|
||||
[node name="ButtonZ" type="Button" parent="C/V/V/HRow3"]
|
||||
[node name="ButtonZ" type="Button" parent="C/V/KeyboardVBox/HRow3"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "Z"
|
||||
|
||||
[node name="ButtonX" type="Button" parent="C/V/V/HRow3"]
|
||||
[node name="ButtonX" type="Button" parent="C/V/KeyboardVBox/HRow3"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "X"
|
||||
|
||||
[node name="ButtonC" type="Button" parent="C/V/V/HRow3"]
|
||||
[node name="ButtonC" type="Button" parent="C/V/KeyboardVBox/HRow3"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "C"
|
||||
|
||||
[node name="ButtonV" type="Button" parent="C/V/V/HRow3"]
|
||||
[node name="ButtonV" type="Button" parent="C/V/KeyboardVBox/HRow3"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "V"
|
||||
|
||||
[node name="ButtonB" type="Button" parent="C/V/V/HRow3"]
|
||||
[node name="ButtonB" type="Button" parent="C/V/KeyboardVBox/HRow3"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "B"
|
||||
|
||||
[node name="ButtonN" type="Button" parent="C/V/V/HRow3"]
|
||||
[node name="ButtonN" type="Button" parent="C/V/KeyboardVBox/HRow3"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "N"
|
||||
|
||||
[node name="ButtonM" type="Button" parent="C/V/V/HRow3"]
|
||||
[node name="ButtonM" type="Button" parent="C/V/KeyboardVBox/HRow3"]
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "M"
|
||||
|
||||
[node name="ButtonBksp" type="Button" parent="C/V/V/HRow3"]
|
||||
[node name="ButtonBksp" type="Button" parent="C/V/KeyboardVBox/HRow3"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(50, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "bksp"
|
||||
|
||||
[node name="GuessButton" type="Button" parent="C/V/V"]
|
||||
[node name="GuessButton" type="Button" parent="C/V/KeyboardVBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
focus_mode = 0
|
||||
|
@ -321,11 +377,12 @@ grow_horizontal = 0
|
|||
theme_override_font_sizes/font_size = 16
|
||||
text = "Menu"
|
||||
|
||||
[node name="ErrorFadeOut" type="AnimationPlayer" parent="."]
|
||||
[node name="InfoTextAnimation" type="AnimationPlayer" parent="."]
|
||||
unique_name_in_owner = true
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_qsyqi")
|
||||
}
|
||||
|
||||
[connection signal="pressed" from="C/V/V/HRow3/ButtonBksp" to="." method="_on_ButtonBksp_pressed"]
|
||||
[connection signal="pressed" from="C/V/V/GuessButton" to="." method="_on_GuessButton_pressed"]
|
||||
[connection signal="pressed" from="C/V/KeyboardVBox/HRow3/ButtonBksp" to="." method="_on_ButtonBksp_pressed"]
|
||||
[connection signal="pressed" from="C/V/KeyboardVBox/GuessButton" to="." method="_on_GuessButton_pressed"]
|
||||
[connection signal="pressed" from="MenuButton" to="." method="_on_MenuButton_pressed"]
|
||||
|
|
Loading…
Reference in a new issue