From 59ee063e5c6962f412e474ece4b94f1bcecf1d4b Mon Sep 17 00:00:00 2001 From: ChaoticByte Date: Thu, 7 Aug 2025 16:53:16 +0200 Subject: [PATCH] Auto-submit text and remove button, code improvements --- scenes/main.tscn | 13 +------------ src/global/CoreGameplayManager.gd | 2 +- src/ui/main.gd | 12 ++---------- src/ui/notification_container.gd | 13 ++++--------- 4 files changed, 8 insertions(+), 32 deletions(-) diff --git a/scenes/main.tscn b/scenes/main.tscn index 4f6fc1c..effdcbc 100644 --- a/scenes/main.tscn +++ b/scenes/main.tscn @@ -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"] diff --git a/src/global/CoreGameplayManager.gd b/src/global/CoreGameplayManager.gd index b96a0ce..fa8074c 100644 --- a/src/global/CoreGameplayManager.gd +++ b/src/global/CoreGameplayManager.gd @@ -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() diff --git a/src/ui/main.gd b/src/ui/main.gd index 04a4f7a..b608e66 100644 --- a/src/ui/main.gd +++ b/src/ui/main.gd @@ -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() diff --git a/src/ui/notification_container.gd b/src/ui/notification_container.gd index ca3c14a..ebbefe8 100644 --- a/src/ui/notification_container.gd +++ b/src/ui/notification_container.gd @@ -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()