diff --git a/client/scenes/AuthScene.tscn b/client/scenes/AuthScene.tscn index ab30395..d0805b1 100644 --- a/client/scenes/AuthScene.tscn +++ b/client/scenes/AuthScene.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=3 format=2] -[ext_resource path="res://scenes/AuthScene.gd" type="Script" id=1] +[ext_resource path="res://scripts/menus/login_form.gd" type="Script" id=1] [ext_resource path="res://scripts/menus/signup_form.gd" type="Script" id=2] [node name="AuthScene" type="Control"] @@ -10,6 +10,10 @@ script = ExtResource( 1 ) __meta__ = { "_edit_use_anchors_": false } +usernamePath = NodePath("UsernameEdit") +passwordPath = NodePath("PasswordEdit") +buttonPath = NodePath("LoginButton") +errorPath = NodePath("ErrorLabel") [node name="SignupDialog" type="WindowDialog" parent="."] anchor_left = 0.5 @@ -142,7 +146,101 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="Button" type="Button" parent="."] +[node name="TitleLabel" type="Label" parent="."] +margin_left = 256.0 +margin_top = 112.0 +margin_right = 768.0 +margin_bottom = 240.0 +text = "Family : WIP" +align = 1 +valign = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="ErrorLabel" type="Label" parent="."] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -72.0 +margin_top = -20.0 +margin_right = 77.0 +margin_bottom = -6.0 +custom_colors/font_color = Color( 1, 0, 0, 1 ) +text = "[ERROR MESSAGE HERE]" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="UsernameLabel" type="Label" parent="."] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -88.0 +margin_top = 4.0 +margin_right = 88.0 +margin_bottom = 18.0 +text = "Email Address" +align = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="UsernameEdit" type="LineEdit" parent="."] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -232.0 +margin_top = 20.0 +margin_right = 232.0 +margin_bottom = 44.0 + +[node name="PasswordLabel" type="Label" parent="."] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -32.0 +margin_top = 60.0 +margin_right = 32.0 +margin_bottom = 74.0 +text = "Password" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="PasswordEdit" type="LineEdit" parent="."] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -232.0 +margin_top = 76.0 +margin_right = 232.0 +margin_bottom = 100.0 +secret = true +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="LoginButton" type="Button" parent="."] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -32.0 +margin_top = 124.0 +margin_right = 32.0 +margin_bottom = 148.0 +text = "Login" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="RegsiterButton" type="Button" parent="."] anchor_left = 1.0 anchor_top = 1.0 anchor_right = 1.0 @@ -150,4 +248,7 @@ anchor_bottom = 1.0 margin_left = -109.0 margin_top = -20.0 text = "Create Account" -[connection signal="button_down" from="Button" to="SignupDialog" method="popup_centered"] +__meta__ = { +"_edit_use_anchors_": false +} +[connection signal="button_down" from="RegsiterButton" to="SignupDialog" method="popup_centered"] diff --git a/client/scripts/menus/login_form.gd b/client/scripts/menus/login_form.gd new file mode 100644 index 0000000..b1eaf0e --- /dev/null +++ b/client/scripts/menus/login_form.gd @@ -0,0 +1,39 @@ +extends Node + +export(NodePath) var usernamePath +export(NodePath) var passwordPath +export(NodePath) var buttonPath +export(NodePath) var errorPath + +var usernameEdit : LineEdit +var passwordEdit : LineEdit +var errorLabel : Label +var button : Button + +func _ready(): + # Get nodes + usernameEdit = get_node(usernamePath) + passwordEdit = get_node(passwordPath) + errorLabel = get_node(errorPath) + button = get_node(buttonPath) + + # Connect submission button + button.connect("button_down", self, "login") + usernameEdit.connect("text_entered", self, "login") + passwordEdit.connect("text_entered", self, "login") + + # Clear error message + errorLabel.text = "" + +func login(_text=""): + var error : NakamaException = yield(ServerConnection.authenticate_async(usernameEdit.text, passwordEdit.text), "completed") + + # Check for error + if error: + passwordEdit.text = "" + errorLabel.add_color_override("font_color", Color.red) + errorLabel.text = error.message + else: + errorLabel.add_color_override("font_color", Color.green) + errorLabel.text = "Logged in successfully!" + print("Logged in successfully!") diff --git a/client/scripts/menus/signup_form.gd b/client/scripts/menus/signup_form.gd index 59f1e6e..d598204 100644 --- a/client/scripts/menus/signup_form.gd +++ b/client/scripts/menus/signup_form.gd @@ -27,21 +27,32 @@ func _ready(): passwordEdit.connect("text_changed", self, "validate_fields") cPasswordEdit.connect("text_changed", self, "validate_fields") + usernameEdit.connect("text_entered", self, "signup") + passwordEdit.connect("text_entered", self, "signup") + cPasswordEdit.connect("text_entered", self, "signup") + # Connect submission button button.connect("button_down", self, "signup") # Clear error message errorLabel.text = "" -func signup(): +func signup(_text=""): + if button.disabled: + return + var error : NakamaException = yield(ServerConnection.signup_async(usernameEdit.text, passwordEdit.text), "completed") # Check for error if error: + passwordEdit.text = "" + cPasswordEdit.text = "" + errorLabel.add_color_override("font_color", Color.red) errorLabel.text = error.message else: + errorLabel.add_color_override("font_color", Color.green) + errorLabel.text = "Signed up successfully!" print("Signed up successfully!") - # Close signup form hide() func validate_fields(_text=""):