Feature: inform user when login failed
This commit is contained in:
@@ -115,8 +115,8 @@ __meta__ = {
|
||||
|
||||
[node name="CreateRoomDialog" type="PopupPanel" parent="."]
|
||||
visible = true
|
||||
margin_right = 900.0
|
||||
margin_bottom = 569.0
|
||||
margin_right = 930.0
|
||||
margin_bottom = 580.0
|
||||
custom_styles/panel = SubResource( 1 )
|
||||
popup_exclusive = true
|
||||
__meta__ = {
|
||||
@@ -125,13 +125,19 @@ __meta__ = {
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="CreateRoomDialog"]
|
||||
visible = false
|
||||
margin_right = 900.0
|
||||
margin_bottom = 569.0
|
||||
margin_right = 930.0
|
||||
margin_bottom = 580.0
|
||||
texture = ExtResource( 7 )
|
||||
|
||||
[node name="VoxContainer" type="VBoxContainer" parent="CreateRoomDialog"]
|
||||
margin_right = 900.0
|
||||
margin_bottom = 569.0
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
margin_left = -465.0
|
||||
margin_top = -290.0
|
||||
margin_right = 465.0
|
||||
margin_bottom = 290.0
|
||||
custom_constants/separation = 50
|
||||
alignment = 1
|
||||
__meta__ = {
|
||||
@@ -139,22 +145,22 @@ __meta__ = {
|
||||
}
|
||||
|
||||
[node name="GameRuleContainer" type="HBoxContainer" parent="CreateRoomDialog/VoxContainer"]
|
||||
margin_top = 92.0
|
||||
margin_right = 900.0
|
||||
margin_bottom = 197.0
|
||||
margin_top = 97.0
|
||||
margin_right = 930.0
|
||||
margin_bottom = 202.0
|
||||
alignment = 1
|
||||
|
||||
[node name="GameRuleLabel" type="Label" parent="CreateRoomDialog/VoxContainer/GameRuleContainer"]
|
||||
margin_left = 58.0
|
||||
margin_right = 330.0
|
||||
margin_left = 73.0
|
||||
margin_right = 345.0
|
||||
margin_bottom = 105.0
|
||||
custom_fonts/font = SubResource( 2 )
|
||||
custom_colors/font_color = Color( 0, 0, 0, 1 )
|
||||
text = "玩 法"
|
||||
|
||||
[node name="GameRuleChoice" type="OptionButton" parent="CreateRoomDialog/VoxContainer/GameRuleContainer"]
|
||||
margin_left = 338.0
|
||||
margin_right = 842.0
|
||||
margin_left = 353.0
|
||||
margin_right = 857.0
|
||||
margin_bottom = 105.0
|
||||
rect_min_size = Vector2( 504, 0 )
|
||||
theme = SubResource( 5 )
|
||||
@@ -169,23 +175,23 @@ custom_colors/font_color_pressed = Color( 0, 0, 0, 1 )
|
||||
align = 1
|
||||
|
||||
[node name="PasswdContainer" type="HBoxContainer" parent="CreateRoomDialog/VoxContainer"]
|
||||
margin_top = 247.0
|
||||
margin_right = 900.0
|
||||
margin_bottom = 352.0
|
||||
margin_top = 252.0
|
||||
margin_right = 930.0
|
||||
margin_bottom = 357.0
|
||||
custom_constants/separation = 20
|
||||
alignment = 1
|
||||
|
||||
[node name="PasswordLabel" type="Label" parent="CreateRoomDialog/VoxContainer/PasswdContainer"]
|
||||
margin_left = 44.0
|
||||
margin_right = 332.0
|
||||
margin_left = 59.0
|
||||
margin_right = 347.0
|
||||
margin_bottom = 105.0
|
||||
custom_fonts/font = SubResource( 9 )
|
||||
custom_colors/font_color = Color( 0, 0, 0, 1 )
|
||||
text = "房间密码"
|
||||
|
||||
[node name="PasswordEdit" type="LineEdit" parent="CreateRoomDialog/VoxContainer/PasswdContainer"]
|
||||
margin_left = 352.0
|
||||
margin_right = 856.0
|
||||
margin_left = 367.0
|
||||
margin_right = 871.0
|
||||
margin_bottom = 105.0
|
||||
custom_styles/focus = SubResource( 6 )
|
||||
custom_styles/normal = SubResource( 7 )
|
||||
@@ -197,21 +203,21 @@ expand_to_text_length = true
|
||||
clear_button_enabled = true
|
||||
|
||||
[node name="ButtonContainer" type="HBoxContainer" parent="CreateRoomDialog/VoxContainer"]
|
||||
margin_top = 402.0
|
||||
margin_right = 900.0
|
||||
margin_bottom = 477.0
|
||||
margin_top = 407.0
|
||||
margin_right = 930.0
|
||||
margin_bottom = 482.0
|
||||
custom_constants/separation = 20
|
||||
alignment = 1
|
||||
|
||||
[node name="ConfirmButton" type="TextureButton" parent="CreateRoomDialog/VoxContainer/ButtonContainer"]
|
||||
margin_left = 219.0
|
||||
margin_right = 440.0
|
||||
margin_left = 234.0
|
||||
margin_right = 455.0
|
||||
margin_bottom = 75.0
|
||||
texture_normal = ExtResource( 5 )
|
||||
|
||||
[node name="CancelButton" type="TextureButton" parent="CreateRoomDialog/VoxContainer/ButtonContainer"]
|
||||
margin_left = 460.0
|
||||
margin_right = 681.0
|
||||
margin_left = 475.0
|
||||
margin_right = 696.0
|
||||
margin_bottom = 75.0
|
||||
texture_normal = ExtResource( 6 )
|
||||
|
||||
|
||||
@@ -4,14 +4,20 @@ extends Node2D
|
||||
# Declare member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = "text"
|
||||
var username
|
||||
var password
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
$LoginHTTPRequest.connect("request_completed", self, "on_login_request_completed")
|
||||
$RegisterHTTPRequest.connect("request_completed", self, "on_register_request_completed")
|
||||
|
||||
|
||||
|
||||
$RegisterFailedPanel/VBoxContainer/HBoxContainer/ConfirmButton.connect("pressed", self, "_on_register_failed_confirm_pressed")
|
||||
$LoginFailedPanel/HBoxContainer/HBoxContainer/ConfirmButton.connect("pressed", self, "_on_login_failed_confirm_pressed")
|
||||
$NetWorkErrDialog/HBoxContainer/HBoxContainer/ConfirmButton.connect("pressed", self, "_on_network_err_confirm_pressed")
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
# pass
|
||||
@@ -21,9 +27,12 @@ func _ready():
|
||||
func send_login():
|
||||
var use_ssl = true
|
||||
var headers = ["Content-Type: application/json"]
|
||||
var dict = {"username":$LoginPanel/VBoxContainer/GridContainer/UsernameEdit.text,
|
||||
"password":$LoginPanel/VBoxContainer/GridContainer/PasswordEdit.text,}
|
||||
var username = $LoginPanel/VBoxContainer/GridContainer/UsernameEdit.text
|
||||
var password = $LoginPanel/VBoxContainer/GridContainer/PasswordEdit.text
|
||||
var dict = {"username":username,
|
||||
"password":password,}
|
||||
var data = to_json(dict)
|
||||
save_username(username, password)
|
||||
$LoginHTTPRequest.request(Constants.HTTP.LOGIN_URL, headers, use_ssl, HTTPClient.METHOD_POST, data)
|
||||
|
||||
|
||||
@@ -32,19 +41,22 @@ func send_signup():
|
||||
if $RegisterDialog/VBoxContainer/GridContainer/GenderContainer/MaleCheckBox.pressed:
|
||||
gender = Message.gender.MALE
|
||||
var use_ssl = true
|
||||
username = $RegisterDialog/VBoxContainer/GridContainer/UsernameEdit.text
|
||||
password = $RegisterDialog/VBoxContainer/GridContainer/PasswordEdit.text
|
||||
var headers = ["Content-Type: application/json"]
|
||||
var dict = {"username":$RegisterDialog/VBoxContainer/GridContainer/UsernameEdit.text,
|
||||
"password":$RegisterDialog/VBoxContainer/GridContainer/PasswordEdit.text,
|
||||
var dict = {"username":username,
|
||||
"password":password,
|
||||
"nickname":$RegisterDialog/VBoxContainer/GridContainer/NicknameEdit.text,
|
||||
"gender":gender,}
|
||||
var data = to_json(dict)
|
||||
$LoginHTTPRequest.request(Constants.HTTP.REGISTER_URL, headers, use_ssl, HTTPClient.METHOD_POST, data)
|
||||
$RegisterHTTPRequest.request(Constants.HTTP.REGISTER_URL, headers, use_ssl, HTTPClient.METHOD_POST, data)
|
||||
|
||||
|
||||
|
||||
func on_login_request_completed(result, response_code, headers, body):
|
||||
if result!=HTTPRequest.RESULT_SUCCESS:
|
||||
print_debug("http response error when login")
|
||||
show_network_err_panel()
|
||||
return
|
||||
var json = JSON.parse(body.get_string_from_utf8())
|
||||
var res = json.result
|
||||
@@ -55,19 +67,25 @@ func on_login_request_completed(result, response_code, headers, body):
|
||||
#TODO: switch scene
|
||||
else:
|
||||
print_debug("login failed")
|
||||
show_wrong_pass_panel()
|
||||
|
||||
|
||||
|
||||
func on_register_request_completed(result, response_code, headers, body):
|
||||
if result!=HTTPRequest.RESULT_SUCCESS:
|
||||
print_debug("http response error when sign up")
|
||||
show_network_err_panel()
|
||||
return
|
||||
var json = JSON.parse(body.get_string_from_utf8())
|
||||
var res = json.result
|
||||
if res["success"] == true:
|
||||
Global.my_user_id = res["user_id"]
|
||||
print_debug("sign up success, userID: ", res["user_id"])
|
||||
save_username(username, password)
|
||||
Global.my_user_id = res["user_id"]
|
||||
get_tree().change_scene("res://Hall.tscn")
|
||||
else:
|
||||
print_debug("sign up failed")
|
||||
show_exist_username_panel()
|
||||
|
||||
func _on_RegisterConfirmButton_pressed():
|
||||
#TODO:check text em
|
||||
@@ -90,14 +108,59 @@ func _on_LoginConfirmButton_pressed():
|
||||
# inform not enough info
|
||||
return
|
||||
send_login()
|
||||
|
||||
|
||||
func save_username(username, password):
|
||||
var save_game = File.new()
|
||||
var user_dict = {
|
||||
"username" :username,
|
||||
"password" :password,
|
||||
}
|
||||
save_game.open("user://username.save", File.WRITE)
|
||||
save_game.store_string(to_json(user_dict))
|
||||
save_game.close()
|
||||
|
||||
func get_username():
|
||||
var save_game = File.new()
|
||||
save_game.open("user://username.save", File.READ)
|
||||
var content = save_game.get_as_text()
|
||||
return content
|
||||
|
||||
|
||||
func _on_LoginButton_pressed():
|
||||
# $LoginPanel.popup_centered()
|
||||
var content = get_username()
|
||||
print_debug("read username from config:", content)
|
||||
if content != "":
|
||||
var j = JSON.parse(content)
|
||||
var user = j.result["username"]
|
||||
var passwd = j.result["password"]
|
||||
$LoginPanel/VBoxContainer/GridContainer/UsernameEdit.text = user
|
||||
$LoginPanel/VBoxContainer/GridContainer/PasswordEdit.text = passwd
|
||||
$LoginPanel.popup_centered_ratio(0.6)
|
||||
|
||||
func _on_SignupButton_pressed():
|
||||
# $RegisterDialog.popup_centered()
|
||||
$RegisterDialog.popup_centered_ratio(0.6)
|
||||
|
||||
func _on_register_failed_confirm_pressed():
|
||||
$RegisterFailedPanel.hide()
|
||||
|
||||
func _on_network_err_confirm_pressed():
|
||||
$NetWorkErrDialog.hide()
|
||||
|
||||
func _on_login_failed_confirm_pressed():
|
||||
$LoginFailedPanel.hide()
|
||||
|
||||
func show_exist_username_panel():
|
||||
$RegisterFailedPanel.popup_centered()
|
||||
|
||||
func show_wrong_pass_panel():
|
||||
$LoginFailedPanel.popup_centered()
|
||||
|
||||
func show_network_err_panel():
|
||||
$NetWorkErrDialog.popup_centered()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+111
-29
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=29 format=2]
|
||||
[gd_scene load_steps=30 format=2]
|
||||
|
||||
[ext_resource path="res://Asset/LoginBackgounnd.png" type="Texture" id=1]
|
||||
[ext_resource path="res://Asset/Font/SourceHanSansSC-Normal.otf" type="DynamicFontData" id=2]
|
||||
@@ -71,10 +71,14 @@ texture = ExtResource( 6 )
|
||||
region_rect = Rect2( 0, 0, 640, 569 )
|
||||
|
||||
[sub_resource type="DynamicFont" id=16]
|
||||
size = 48
|
||||
size = 72
|
||||
font_data = ExtResource( 2 )
|
||||
|
||||
[sub_resource type="DynamicFont" id=17]
|
||||
[sub_resource type="StyleBoxTexture" id=17]
|
||||
texture = ExtResource( 6 )
|
||||
region_rect = Rect2( 0, 0, 640, 569 )
|
||||
|
||||
[sub_resource type="DynamicFont" id=18]
|
||||
size = 48
|
||||
font_data = ExtResource( 2 )
|
||||
|
||||
@@ -117,7 +121,6 @@ margin_bottom = 85.0
|
||||
texture_normal = ExtResource( 3 )
|
||||
|
||||
[node name="RegisterDialog" type="PopupDialog" parent="."]
|
||||
visible = true
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
@@ -270,7 +273,6 @@ __meta__ = {
|
||||
}
|
||||
|
||||
[node name="LoginPanel" type="PopupDialog" parent="."]
|
||||
visible = true
|
||||
margin_right = 800.0
|
||||
margin_bottom = 500.0
|
||||
custom_styles/panel = SubResource( 13 )
|
||||
@@ -359,48 +361,128 @@ texture_normal = ExtResource( 11 )
|
||||
|
||||
[node name="RegisterHTTPRequest" type="HTTPRequest" parent="."]
|
||||
|
||||
[node name="LoginFailedPanel" type="PopupPanel" parent="."]
|
||||
margin_right = 16.0
|
||||
margin_bottom = 16.0
|
||||
[node name="LoginFailedPanel" type="PopupDialog" parent="."]
|
||||
margin_right = 700.0
|
||||
margin_bottom = 500.0
|
||||
custom_styles/panel = SubResource( 15 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="HBoxContainer" type="VBoxContainer" parent="LoginFailedPanel"]
|
||||
margin_right = 221.0
|
||||
margin_bottom = 153.0
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
margin_left = -288.0
|
||||
margin_top = -115.0
|
||||
margin_right = 288.0
|
||||
margin_bottom = 115.0
|
||||
custom_constants/separation = 50
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Label" type="Label" parent="LoginFailedPanel/HBoxContainer"]
|
||||
margin_right = 221.0
|
||||
margin_bottom = 70.0
|
||||
margin_right = 576.0
|
||||
margin_bottom = 105.0
|
||||
custom_fonts/font = SubResource( 16 )
|
||||
custom_colors/font_color = Color( 0, 0, 0, 1 )
|
||||
text = "登陆失败"
|
||||
text = "用户名或密码错误"
|
||||
|
||||
[node name="ConfirmButton" type="TextureButton" parent="LoginFailedPanel/HBoxContainer"]
|
||||
margin_top = 78.0
|
||||
margin_right = 221.0
|
||||
margin_bottom = 153.0
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="LoginFailedPanel/HBoxContainer"]
|
||||
margin_top = 155.0
|
||||
margin_right = 576.0
|
||||
margin_bottom = 230.0
|
||||
alignment = 1
|
||||
|
||||
[node name="ConfirmButton" type="TextureButton" parent="LoginFailedPanel/HBoxContainer/HBoxContainer"]
|
||||
margin_left = 177.0
|
||||
margin_right = 398.0
|
||||
margin_bottom = 75.0
|
||||
texture_normal = ExtResource( 11 )
|
||||
|
||||
[node name="RegisterFailedPanel" type="PopupPanel" parent="."]
|
||||
margin_right = 16.0
|
||||
margin_bottom = 16.0
|
||||
[node name="NetWorkErrDialog" type="PopupDialog" parent="."]
|
||||
margin_right = 700.0
|
||||
margin_bottom = 500.0
|
||||
custom_styles/panel = SubResource( 15 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="HBoxContainer" type="VBoxContainer" parent="NetWorkErrDialog"]
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
margin_left = -288.0
|
||||
margin_top = -115.0
|
||||
margin_right = 288.0
|
||||
margin_bottom = 115.0
|
||||
custom_constants/separation = 50
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Label" type="Label" parent="NetWorkErrDialog/HBoxContainer"]
|
||||
margin_right = 576.0
|
||||
margin_bottom = 105.0
|
||||
custom_fonts/font = SubResource( 16 )
|
||||
custom_colors/font_color = Color( 0, 0, 0, 1 )
|
||||
text = "网络错误"
|
||||
align = 1
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="NetWorkErrDialog/HBoxContainer"]
|
||||
margin_top = 155.0
|
||||
margin_right = 576.0
|
||||
margin_bottom = 230.0
|
||||
alignment = 1
|
||||
|
||||
[node name="ConfirmButton" type="TextureButton" parent="NetWorkErrDialog/HBoxContainer/HBoxContainer"]
|
||||
margin_left = 177.0
|
||||
margin_right = 398.0
|
||||
margin_bottom = 75.0
|
||||
texture_normal = ExtResource( 11 )
|
||||
|
||||
[node name="RegisterFailedPanel" type="PopupDialog" parent="."]
|
||||
margin_right = 500.0
|
||||
margin_bottom = 400.0
|
||||
custom_styles/panel = SubResource( 17 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="RegisterFailedPanel"]
|
||||
margin_right = 221.0
|
||||
margin_bottom = 153.0
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
margin_left = -168.0
|
||||
margin_top = -87.5
|
||||
margin_right = 168.0
|
||||
margin_bottom = 87.5
|
||||
custom_constants/separation = 30
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Label" type="Label" parent="RegisterFailedPanel/VBoxContainer"]
|
||||
margin_right = 221.0
|
||||
margin_right = 336.0
|
||||
margin_bottom = 70.0
|
||||
custom_fonts/font = SubResource( 17 )
|
||||
custom_fonts/font = SubResource( 18 )
|
||||
custom_colors/font_color = Color( 0, 0, 0, 1 )
|
||||
text = "注册失败"
|
||||
text = "该用户名已存在"
|
||||
|
||||
[node name="ConfirmButton" type="TextureButton" parent="RegisterFailedPanel/VBoxContainer"]
|
||||
margin_top = 78.0
|
||||
margin_right = 221.0
|
||||
margin_bottom = 153.0
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="RegisterFailedPanel/VBoxContainer"]
|
||||
margin_top = 100.0
|
||||
margin_right = 336.0
|
||||
margin_bottom = 175.0
|
||||
alignment = 1
|
||||
|
||||
[node name="ConfirmButton" type="TextureButton" parent="RegisterFailedPanel/VBoxContainer/HBoxContainer"]
|
||||
margin_left = 57.0
|
||||
margin_right = 278.0
|
||||
margin_bottom = 75.0
|
||||
texture_normal = ExtResource( 11 )
|
||||
[connection signal="pressed" from="HBoxContainer/LoginButton" to="." method="_on_LoginButton_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/SignupButton" to="." method="_on_SignupButton_pressed"]
|
||||
|
||||
Reference in New Issue
Block a user