Merge pull request '[Feature]: Add LoginScene' (!3) from task/td-66-login-maske into trunk
All checks were successful
Quality Check / Linting (push) Successful in 6s
All checks were successful
Quality Check / Linting (push) Successful in 6s
Reviewed-on: #3 Reviewed-by: Snoweuph <snow+git@euph.email>
This commit is contained in:
commit
9ab96afacf
3 changed files with 134 additions and 2 deletions
85
scenes/login.tscn
Normal file
85
scenes/login.tscn
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
[gd_scene load_steps=3 format=3 uid="uid://dtaaw31x3n22f"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://scripts/login/login.gd" id="1_12w35"]
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_d0bbp"]
|
||||||
|
|
||||||
|
[node name="Login" type="Control"]
|
||||||
|
layout_mode = 3
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
|
||||||
|
[node name="Panel" type="Panel" parent="."]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
theme_override_styles/panel = SubResource("StyleBoxFlat_d0bbp")
|
||||||
|
|
||||||
|
[node name="VBoxContainer" type="VBoxContainer" parent="Panel"]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 8
|
||||||
|
anchor_left = 0.5
|
||||||
|
anchor_top = 0.5
|
||||||
|
anchor_right = 0.5
|
||||||
|
anchor_bottom = 0.5
|
||||||
|
offset_left = -150.0
|
||||||
|
offset_top = -108.0
|
||||||
|
offset_right = 150.0
|
||||||
|
offset_bottom = 108.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
theme_override_constants/separation = 16
|
||||||
|
|
||||||
|
[node name="Header" type="RichTextLabel" parent="Panel/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_font_sizes/normal_font_size = 30
|
||||||
|
text = "Login"
|
||||||
|
fit_content = true
|
||||||
|
scroll_active = false
|
||||||
|
autowrap_mode = 0
|
||||||
|
|
||||||
|
[node name="InputContainer" type="VBoxContainer" parent="Panel/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_constants/separation = 8
|
||||||
|
|
||||||
|
[node name="UsernameContainer" type="VBoxContainer" parent="Panel/VBoxContainer/InputContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="UsernameLabel" type="RichTextLabel" parent="Panel/VBoxContainer/InputContainer/UsernameContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Username:
|
||||||
|
"
|
||||||
|
fit_content = true
|
||||||
|
scroll_active = false
|
||||||
|
|
||||||
|
[node name="UsernameInput" type="LineEdit" parent="Panel/VBoxContainer/InputContainer/UsernameContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="PasswordContainer" type="VBoxContainer" parent="Panel/VBoxContainer/InputContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="PaswordLabel" type="RichTextLabel" parent="Panel/VBoxContainer/InputContainer/PasswordContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Password:"
|
||||||
|
fit_content = true
|
||||||
|
scroll_active = false
|
||||||
|
|
||||||
|
[node name="PasswordInput" type="LineEdit" parent="Panel/VBoxContainer/InputContainer/PasswordContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
secret = true
|
||||||
|
|
||||||
|
[node name="Button" type="Button" parent="Panel/VBoxContainer" node_paths=PackedStringArray("username_field", "password_field", "http_request")]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Login"
|
||||||
|
script = ExtResource("1_12w35")
|
||||||
|
username_field = NodePath("../InputContainer/UsernameContainer/UsernameInput")
|
||||||
|
password_field = NodePath("../InputContainer/PasswordContainer/PasswordInput")
|
||||||
|
http_request = NodePath("HTTPRequest")
|
||||||
|
|
||||||
|
[node name="HTTPRequest" type="HTTPRequest" parent="Panel/VBoxContainer/Button"]
|
|
@ -7,6 +7,8 @@
|
||||||
anchors_preset = 15
|
anchors_preset = 15
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
|
offset_left = -1.0
|
||||||
|
offset_right = -1.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
theme = ExtResource("1_6qgep")
|
theme = ExtResource("1_6qgep")
|
||||||
|
@ -30,13 +32,19 @@ clip_contents = false
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_stretch_ratio = 7.45
|
size_flags_stretch_ratio = 7.45
|
||||||
theme_override_font_sizes/normal_font_size = 64
|
theme_override_font_sizes/normal_font_size = 64
|
||||||
text = "Hello World"
|
text = "Epic TD Deluxe"
|
||||||
fit_content = true
|
fit_content = true
|
||||||
scroll_active = false
|
scroll_active = false
|
||||||
autowrap_mode = 0
|
autowrap_mode = 0
|
||||||
|
|
||||||
[node name="Button" type="Button" parent="VBoxContainer"]
|
[node name="Button" type="Button" parent="VBoxContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Theme Test Scene"
|
text = "Login"
|
||||||
|
script = ExtResource("2_c477a")
|
||||||
|
scene_name = "login"
|
||||||
|
|
||||||
|
[node name="Button2" type="Button" parent="VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Testszene"
|
||||||
script = ExtResource("2_c477a")
|
script = ExtResource("2_c477a")
|
||||||
scene_name = "theme_test"
|
scene_name = "theme_test"
|
||||||
|
|
39
scripts/login/login.gd
Normal file
39
scripts/login/login.gd
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
extends Button
|
||||||
|
|
||||||
|
@export var username_field: LineEdit
|
||||||
|
@export var password_field: LineEdit
|
||||||
|
@export var http_request: HTTPRequest
|
||||||
|
var url: String = "http://localhost:8080/api/v1/player/login"
|
||||||
|
var headers = ["Content-Type: application/json"]
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
if not username_field:
|
||||||
|
push_error("No Username Field set")
|
||||||
|
return
|
||||||
|
if not password_field:
|
||||||
|
push_error("No Password Field set")
|
||||||
|
return
|
||||||
|
if not http_request:
|
||||||
|
push_error("No Http Request set")
|
||||||
|
return
|
||||||
|
connect("pressed", login)
|
||||||
|
|
||||||
|
|
||||||
|
func login() -> void:
|
||||||
|
var login_data = {
|
||||||
|
"username": username_field.text,
|
||||||
|
"password": password_field.text,
|
||||||
|
}
|
||||||
|
var json = JSON.stringify(login_data)
|
||||||
|
http_request.connect("request_completed", on_login_response)
|
||||||
|
http_request.request(url, headers, HTTPClient.METHOD_POST, json)
|
||||||
|
|
||||||
|
|
||||||
|
func on_login_response(
|
||||||
|
_result: int,
|
||||||
|
_response_code: int,
|
||||||
|
_headers: PackedStringArray,
|
||||||
|
body: PackedByteArray,
|
||||||
|
) -> void:
|
||||||
|
print(body.get_string_from_utf8())
|
Loading…
Add table
Reference in a new issue