Auto-submit text and remove button, code improvements
This commit is contained in:
parent
0f6d4c6c75
commit
59ee063e5c
4 changed files with 8 additions and 32 deletions
|
@ -180,17 +180,6 @@ offset_bottom = 320.0
|
||||||
alignment = 1
|
alignment = 1
|
||||||
keep_editing_on_text_submit = true
|
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")]
|
[node name="SettingsMenu" parent="." instance=ExtResource("8_85g3d")]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
visible = false
|
visible = false
|
||||||
|
@ -214,6 +203,7 @@ offset_right = 32.0
|
||||||
offset_bottom = -33.7
|
offset_bottom = -33.7
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
|
focus_mode = 2
|
||||||
theme_override_styles/panel = SubResource("StyleBoxFlat_ya4ey")
|
theme_override_styles/panel = SubResource("StyleBoxFlat_ya4ey")
|
||||||
script = ExtResource("11_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="ShowSettingsButton" to="." method="_on_settings_button_pressed"]
|
||||||
[connection signal="pressed" from="ShowPhrasesButton" to="." method="_on_show_phrases_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="text_changed" from="AnswerInput" to="." method="_on_answer_input_text_changed"]
|
||||||
[connection signal="pressed" from="SubmitButton" to="." method="_on_submit_button_pressed"]
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ func next_phrase() -> void:
|
||||||
current_status = STATUS_PLEASE_REPEAT
|
current_status = STATUS_PLEASE_REPEAT
|
||||||
return
|
return
|
||||||
# find the half of phrases that were repeated longest ago
|
# 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)
|
var phrases_played_longest_ago = last_played_phrases.slice(0, i_max)
|
||||||
# pick random phrase
|
# pick random phrase
|
||||||
var phrase = phrases_played_longest_ago.pick_random()
|
var phrase = phrases_played_longest_ago.pick_random()
|
||||||
|
|
|
@ -2,7 +2,6 @@ extends Control
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
CoreGameplayManager.next_phrase()
|
CoreGameplayManager.next_phrase()
|
||||||
%SubmitButton.hide()
|
|
||||||
%AnswerInput.hide()
|
%AnswerInput.hide()
|
||||||
|
|
||||||
func _on_settings_button_pressed() -> void:
|
func _on_settings_button_pressed() -> void:
|
||||||
|
@ -24,17 +23,10 @@ func _process(_delta: float) -> void:
|
||||||
else:
|
else:
|
||||||
%CurrentPhrase.text = ""
|
%CurrentPhrase.text = ""
|
||||||
%AnswerInput.hide()
|
%AnswerInput.hide()
|
||||||
%SubmitButton.hide()
|
|
||||||
if last_known_status != CoreGameplayManager.current_status:
|
if last_known_status != CoreGameplayManager.current_status:
|
||||||
last_known_status = CoreGameplayManager.current_status
|
last_known_status = CoreGameplayManager.current_status
|
||||||
%CurrentStatus.text = last_known_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:
|
func _on_answer_input_text_changed(new_text: String) -> void:
|
||||||
if new_text.to_lower() == CoreGameplayManager.current_phrase.to_lower():
|
if CoreGameplayManager.answer(new_text):
|
||||||
%SubmitButton.show()
|
%AnswerInput.clear()
|
||||||
else:
|
|
||||||
%SubmitButton.hide()
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
extends PanelContainer
|
extends PanelContainer
|
||||||
|
|
||||||
var showing_notification: bool = false
|
|
||||||
var notification_started: int = 0 # in ms
|
var notification_started: int = 0 # in ms
|
||||||
var current_notification_timeout: int = 0 # in ms
|
var current_notification_timeout: int = 0 # in ms
|
||||||
|
|
||||||
|
@ -9,18 +8,14 @@ func _ready() -> void:
|
||||||
|
|
||||||
func _process(_delta: float) -> void:
|
func _process(_delta: float) -> void:
|
||||||
var t = Time.get_ticks_msec()
|
var t = Time.get_ticks_msec()
|
||||||
if showing_notification:
|
if visible:
|
||||||
if t - notification_started > current_notification_timeout:
|
if t - notification_started > current_notification_timeout:
|
||||||
showing_notification = false
|
hide()
|
||||||
else:
|
else:
|
||||||
var n = NotificationQueue.get_next() # [text, timeout] or null
|
var n = NotificationQueue.get_next() # [text, timeout] or null
|
||||||
if n != null:
|
if n != null:
|
||||||
showing_notification = true
|
|
||||||
notification_started = t
|
notification_started = t
|
||||||
$Label.text = n[0]
|
$Label.text = n[0]
|
||||||
current_notification_timeout = n[1]
|
current_notification_timeout = n[1]
|
||||||
#
|
|
||||||
if not showing_notification and visible:
|
|
||||||
hide()
|
|
||||||
elif showing_notification and not visible:
|
|
||||||
show()
|
show()
|
||||||
|
grab_focus()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue