Auto-submit text and remove button, code improvements

This commit is contained in:
ChaoticByte 2025-08-07 16:53:16 +02:00
parent 0f6d4c6c75
commit 59ee063e5c
No known key found for this signature in database
4 changed files with 8 additions and 32 deletions

View file

@ -180,17 +180,6 @@ offset_bottom = 320.0
alignment = 1
keep_editing_on_text_submit = true
[node name="SubmitButton" type="Button" parent="."]
unique_name_in_owner = true
layout_mode = 2
anchor_left = 0.5
anchor_right = 0.5
offset_left = -40.0
offset_top = 344.0
offset_right = 40.0
offset_bottom = 376.0
text = "Submit"
[node name="SettingsMenu" parent="." instance=ExtResource("8_85g3d")]
unique_name_in_owner = true
visible = false
@ -214,6 +203,7 @@ offset_right = 32.0
offset_bottom = -33.7
grow_horizontal = 2
grow_vertical = 0
focus_mode = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_ya4ey")
script = ExtResource("11_ya4ey")
@ -228,4 +218,3 @@ vertical_alignment = 1
[connection signal="pressed" from="ShowSettingsButton" to="." method="_on_settings_button_pressed"]
[connection signal="pressed" from="ShowPhrasesButton" to="." method="_on_show_phrases_button_pressed"]
[connection signal="text_changed" from="AnswerInput" to="." method="_on_answer_input_text_changed"]
[connection signal="pressed" from="SubmitButton" to="." method="_on_submit_button_pressed"]

View file

@ -46,7 +46,7 @@ func next_phrase() -> void:
current_status = STATUS_PLEASE_REPEAT
return
# find the half of phrases that were repeated longest ago
var i_max = max(1, len(last_played_phrases) / 2)
var i_max = max(1, roundi(float(len(last_played_phrases)) / 2))
var phrases_played_longest_ago = last_played_phrases.slice(0, i_max)
# pick random phrase
var phrase = phrases_played_longest_ago.pick_random()

View file

@ -2,7 +2,6 @@ extends Control
func _ready() -> void:
CoreGameplayManager.next_phrase()
%SubmitButton.hide()
%AnswerInput.hide()
func _on_settings_button_pressed() -> void:
@ -24,17 +23,10 @@ func _process(_delta: float) -> void:
else:
%CurrentPhrase.text = ""
%AnswerInput.hide()
%SubmitButton.hide()
if last_known_status != CoreGameplayManager.current_status:
last_known_status = CoreGameplayManager.current_status
%CurrentStatus.text = last_known_status
func _on_submit_button_pressed() -> void:
if CoreGameplayManager.answer(%AnswerInput.text):
%AnswerInput.clear()
func _on_answer_input_text_changed(new_text: String) -> void:
if new_text.to_lower() == CoreGameplayManager.current_phrase.to_lower():
%SubmitButton.show()
else:
%SubmitButton.hide()
if CoreGameplayManager.answer(new_text):
%AnswerInput.clear()

View file

@ -1,6 +1,5 @@
extends PanelContainer
var showing_notification: bool = false
var notification_started: int = 0 # in ms
var current_notification_timeout: int = 0 # in ms
@ -9,18 +8,14 @@ func _ready() -> void:
func _process(_delta: float) -> void:
var t = Time.get_ticks_msec()
if showing_notification:
if visible:
if t - notification_started > current_notification_timeout:
showing_notification = false
hide()
else:
var n = NotificationQueue.get_next() # [text, timeout] or null
if n != null:
showing_notification = true
notification_started = t
$Label.text = n[0]
current_notification_timeout = n[1]
#
if not showing_notification and visible:
hide()
elif showing_notification and not visible:
show()
show()
grab_focus()