Add interface sound feedback
This commit is contained in:
+29
-33
@@ -6,8 +6,8 @@ const AUTH_REGISTER_URL := "https://pauth.ranaze.com/api/Auth/register"
|
||||
|
||||
var main: Control
|
||||
var auth_panel: PanelContainer
|
||||
var login_tab: Button
|
||||
var register_tab: Button
|
||||
var auth_prompt_label: Label
|
||||
var switch_mode_button: Button
|
||||
var login_fields: VBoxContainer
|
||||
var register_fields: VBoxContainer
|
||||
var username_input: LineEdit
|
||||
@@ -54,30 +54,11 @@ func _ready() -> void:
|
||||
Style.set_label(title, 34, Style.TEXT)
|
||||
content.add_child(title)
|
||||
|
||||
var subtitle := Label.new()
|
||||
subtitle.text = "Sign in or create an account to start studying."
|
||||
subtitle.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
subtitle.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
Style.set_label(subtitle, 16, Style.MUTED)
|
||||
content.add_child(subtitle)
|
||||
|
||||
var tabs := HBoxContainer.new()
|
||||
tabs.add_theme_constant_override("separation", 8)
|
||||
content.add_child(tabs)
|
||||
|
||||
login_tab = Button.new()
|
||||
login_tab.text = "Log In"
|
||||
login_tab.custom_minimum_size = Vector2(0, 44)
|
||||
login_tab.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
login_tab.pressed.connect(func(): _set_auth_mode("login"))
|
||||
tabs.add_child(login_tab)
|
||||
|
||||
register_tab = Button.new()
|
||||
register_tab.text = "Create Account"
|
||||
register_tab.custom_minimum_size = Vector2(0, 44)
|
||||
register_tab.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
register_tab.pressed.connect(func(): _set_auth_mode("register"))
|
||||
tabs.add_child(register_tab)
|
||||
auth_prompt_label = Label.new()
|
||||
auth_prompt_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
auth_prompt_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
Style.set_label(auth_prompt_label, 16, Style.MUTED)
|
||||
content.add_child(auth_prompt_label)
|
||||
|
||||
login_fields = VBoxContainer.new()
|
||||
login_fields.add_theme_constant_override("separation", 10)
|
||||
@@ -122,6 +103,16 @@ func _ready() -> void:
|
||||
Style.set_label(error_label, 15, Style.RED)
|
||||
content.add_child(error_label)
|
||||
|
||||
var switch_spacer := Control.new()
|
||||
switch_spacer.custom_minimum_size = Vector2(0, 8)
|
||||
content.add_child(switch_spacer)
|
||||
|
||||
switch_mode_button = Button.new()
|
||||
switch_mode_button.custom_minimum_size = Vector2(0, 46)
|
||||
Style.style_chip(switch_mode_button, Style.CYAN)
|
||||
switch_mode_button.pressed.connect(_toggle_auth_mode)
|
||||
content.add_child(switch_mode_button)
|
||||
|
||||
var spacer_bottom := Control.new()
|
||||
spacer_bottom.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
add_child(spacer_bottom)
|
||||
@@ -165,18 +156,22 @@ func _set_auth_mode(next_mode: String) -> void:
|
||||
return
|
||||
login_fields.visible = auth_mode == "login"
|
||||
register_fields.visible = auth_mode == "register"
|
||||
auth_panel.custom_minimum_size.y = 470 if auth_mode == "login" else 650
|
||||
auth_panel.custom_minimum_size.y = 535 if auth_mode == "login" else 650
|
||||
if auth_mode == "login":
|
||||
Style.style_primary_button(login_tab)
|
||||
Style.style_chip(register_tab, Style.CYAN)
|
||||
auth_prompt_label.text = "Log in to continue studying."
|
||||
switch_mode_button.text = "Create new account"
|
||||
username_input.grab_focus()
|
||||
else:
|
||||
Style.style_chip(login_tab, Style.CYAN)
|
||||
Style.style_primary_button(register_tab)
|
||||
auth_prompt_label.text = "Create your account"
|
||||
switch_mode_button.text = "Already have an account? Log in"
|
||||
registration_username_input.grab_focus()
|
||||
_clear_messages()
|
||||
|
||||
|
||||
func _toggle_auth_mode() -> void:
|
||||
_set_auth_mode("register" if auth_mode == "login" else "login")
|
||||
|
||||
|
||||
func _on_login_pressed() -> void:
|
||||
_send_login(username_input.text.strip_edges(), password_input.text, false)
|
||||
|
||||
@@ -236,6 +231,7 @@ func _on_login_request_completed(result: int, response_code: int, _headers: Pack
|
||||
String(response.get("exp", ""))
|
||||
)
|
||||
QuestionBankService.load_questions_from_api()
|
||||
UISoundService.play_sound("correct")
|
||||
password_input.text = ""
|
||||
registration_password_input.text = ""
|
||||
registration_confirm_input.text = ""
|
||||
@@ -309,8 +305,7 @@ func _set_busy(is_busy: bool) -> void:
|
||||
return
|
||||
login_button.disabled = is_busy
|
||||
register_button.disabled = is_busy
|
||||
login_tab.disabled = is_busy
|
||||
register_tab.disabled = is_busy
|
||||
switch_mode_button.disabled = is_busy
|
||||
username_input.editable = not is_busy
|
||||
password_input.editable = not is_busy
|
||||
registration_username_input.editable = not is_busy
|
||||
@@ -344,5 +339,6 @@ func _clear_messages() -> void:
|
||||
|
||||
|
||||
func _show_error(message: String) -> void:
|
||||
UISoundService.play_sound("error")
|
||||
success_label.text = ""
|
||||
error_label.text = message
|
||||
|
||||
Reference in New Issue
Block a user