Adds steps logic for the register form.
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
extends Resource
|
||||
class_name RegisterQuestion
|
||||
|
||||
var txt : String
|
||||
@@ -0,0 +1,79 @@
|
||||
extends Control
|
||||
|
||||
@onready var teacher_steps : Array[PackedScene] = [
|
||||
preload("res://sources/menus/register/steps/teacher/method_step.tscn"),
|
||||
preload("res://sources/menus/register/steps/teacher/devices_count_step.tscn"),
|
||||
preload("res://sources/menus/register/steps/teacher/students_count_step.tscn"),
|
||||
preload("res://sources/menus/register/steps/credentials_step.tscn")
|
||||
]
|
||||
@onready var parent_steps : Array[PackedScene] = [
|
||||
|
||||
]
|
||||
var current_steps : Array[PackedScene]
|
||||
# TODO Change the resource
|
||||
@onready var register_data := UserSettings.new()
|
||||
@onready var progress_bar := %ProgressBar
|
||||
@onready var steps := %Steps
|
||||
|
||||
func _ready():
|
||||
current_steps = teacher_steps
|
||||
|
||||
# Handles the progress bar
|
||||
progress_bar.value = 0
|
||||
progress_bar.max_value = current_steps.size()
|
||||
|
||||
# Load new step
|
||||
_go_to_step(progress_bar.value)
|
||||
|
||||
|
||||
func _go_to_step(step_index: int):
|
||||
var next_step
|
||||
|
||||
# Check if step is already instantiated
|
||||
for step in steps.get_children(false):
|
||||
step.hide()
|
||||
|
||||
if step.name == str(progress_bar.value):
|
||||
step.completed.disconnect(_on_step_completed)
|
||||
pass
|
||||
|
||||
if step.name == str(step_index):
|
||||
next_step = step
|
||||
|
||||
# Instantiate the step
|
||||
if not next_step:
|
||||
next_step = teacher_steps[step_index].instantiate()
|
||||
next_step.name = str(step_index)
|
||||
next_step.object = register_data
|
||||
steps.add_child(next_step)
|
||||
else:
|
||||
next_step.show()
|
||||
|
||||
# Connect the step
|
||||
next_step.completed.connect(_on_step_completed)
|
||||
|
||||
# Handles progress bar
|
||||
progress_bar.value = step_index
|
||||
|
||||
|
||||
func _reset_steps():
|
||||
progress_bar.value = 0
|
||||
progress_bar.max_value = 0
|
||||
|
||||
for step in steps.get_children(false):
|
||||
step.queue_free()
|
||||
|
||||
|
||||
func _on_back_button_pressed():
|
||||
if progress_bar.value == 0:
|
||||
print("Back to title screen")
|
||||
# get_tree().change_scene_to_file()
|
||||
else:
|
||||
_go_to_step(progress_bar.value-1)
|
||||
|
||||
|
||||
func _on_step_completed():
|
||||
if progress_bar.value == current_steps.size()-1:
|
||||
print("Registering complete !")
|
||||
else:
|
||||
_go_to_step(progress_bar.value+1)
|
||||
@@ -0,0 +1,75 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://b7cfjs2iipagq"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://wtx3wqs0l4si" path="res://assets/minigames/minigame_ui/graphic/button_back_up.png" id="1_g16n6"]
|
||||
[ext_resource type="Script" path="res://sources/menus/register/register_screen.gd" id="1_the3k"]
|
||||
[ext_resource type="Texture2D" uid="uid://cbhip35yyqneg" path="res://assets/minigames/minigame_ui/graphic/button_back_down.png" id="2_ufjlu"]
|
||||
[ext_resource type="Texture2D" uid="uid://tcapan0mj64o" path="res://assets/minigames/minigame_ui/graphic/button_back_disabled.png" id="3_svtfb"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_0rcyk"]
|
||||
border_width_left = 3
|
||||
border_width_top = 3
|
||||
border_width_right = 3
|
||||
border_width_bottom = 3
|
||||
expand_margin_top = 3.0
|
||||
expand_margin_bottom = 3.0
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_bhfkq"]
|
||||
bg_color = Color(0, 0.607843, 0.831373, 1)
|
||||
|
||||
[node name="RegisterScreen" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_the3k")
|
||||
|
||||
[node name="ProgressBarContainer" type="MarginContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 10
|
||||
anchor_right = 1.0
|
||||
offset_bottom = 256.0
|
||||
grow_horizontal = 2
|
||||
theme_override_constants/margin_left = 25
|
||||
theme_override_constants/margin_top = 50
|
||||
theme_override_constants/margin_right = 231
|
||||
theme_override_constants/margin_bottom = 50
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="ProgressBarContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 50
|
||||
|
||||
[node name="BackButton" type="TextureButton" parent="ProgressBarContainer/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(156, 156)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 0
|
||||
texture_normal = ExtResource("1_g16n6")
|
||||
texture_pressed = ExtResource("2_ufjlu")
|
||||
texture_disabled = ExtResource("3_svtfb")
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="ProgressBar" type="ProgressBar" parent="ProgressBarContainer/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 4
|
||||
theme_override_colors/font_color = Color(0, 0, 0, 0)
|
||||
theme_override_colors/font_outline_color = Color(0, 0, 0, 0)
|
||||
theme_override_styles/background = SubResource("StyleBoxFlat_0rcyk")
|
||||
theme_override_styles/fill = SubResource("StyleBoxFlat_bhfkq")
|
||||
step = 1.0
|
||||
value = 50.0
|
||||
|
||||
[node name="Steps" type="Control" parent="."]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 1
|
||||
anchor_top = 0.142222
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
metadata/_edit_use_anchors_ = true
|
||||
|
||||
[connection signal="pressed" from="ProgressBarContainer/HBoxContainer/BackButton" to="." method="_on_back_button_pressed"]
|
||||
@@ -0,0 +1,68 @@
|
||||
@tool
|
||||
extends Control
|
||||
class_name Step
|
||||
|
||||
signal completed
|
||||
|
||||
const checked_properties := [
|
||||
"value",
|
||||
"text"
|
||||
]
|
||||
|
||||
@onready var question_label : Label = %QuestionLabel
|
||||
@onready var form_validator : FormValidator = %FormValidator
|
||||
@onready var form_container : Control = %FormContainer
|
||||
|
||||
@export var question_txt : String
|
||||
@export var object : Resource
|
||||
|
||||
func _ready():
|
||||
if question_txt:
|
||||
question_label.text = question_txt
|
||||
|
||||
_fill_form()
|
||||
|
||||
|
||||
func _fill_form():
|
||||
if not object:
|
||||
return
|
||||
|
||||
for node in form_container.get_children(false):
|
||||
if node.name in object:
|
||||
for property_name in checked_properties:
|
||||
if property_name in node:
|
||||
node.set(property_name, object.get(node.name))
|
||||
else:
|
||||
push_warning("Property not found in object for node: " + node.name + ". All nodes inside FormContainer must reflects a property from the resource.")
|
||||
|
||||
|
||||
func _write_object() -> bool:
|
||||
if not object:
|
||||
return false
|
||||
|
||||
for node in form_container.get_children(false):
|
||||
var value
|
||||
if node.name in object:
|
||||
for property_name in checked_properties:
|
||||
if property_name in node:
|
||||
value = node.get(property_name)
|
||||
|
||||
if value:
|
||||
object.set(node.name, value)
|
||||
else:
|
||||
return false
|
||||
|
||||
return true
|
||||
|
||||
|
||||
func _on_validate_button_pressed():
|
||||
|
||||
print(form_validator.validate())
|
||||
|
||||
# Writes data in object
|
||||
if _write_object():
|
||||
# Emit completed signal
|
||||
emit_signal("completed")
|
||||
else:
|
||||
# TODO Show error message
|
||||
print("Please fill all the fields")
|
||||
@@ -0,0 +1,101 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://bxd3i06rqpxf0"]
|
||||
|
||||
[ext_resource type="Script" path="res://sources/menus/register/steps/base_step.gd" id="1_02ocl"]
|
||||
[ext_resource type="Script" path="res://addons/godot-form-validator/form_validator.gd" id="2_jbdsv"]
|
||||
|
||||
[node name="BaseRegisterForm" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_02ocl")
|
||||
|
||||
[node name="RightMargin" type="MarginContainer" parent="."]
|
||||
custom_minimum_size = Vector2(450, 2.08165e-12)
|
||||
layout_mode = 1
|
||||
anchors_preset = 11
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -450.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 2.0
|
||||
mouse_filter = 2
|
||||
theme_override_constants/margin_left = 50
|
||||
theme_override_constants/margin_top = 50
|
||||
theme_override_constants/margin_right = 50
|
||||
theme_override_constants/margin_bottom = 50
|
||||
|
||||
[node name="RightContainer" type="VBoxContainer" parent="RightMargin"]
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
alignment = 2
|
||||
|
||||
[node name="ValidateButton" type="Button" parent="RightMargin/RightContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 70
|
||||
text = "Next"
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 5
|
||||
anchor_left = 0.5
|
||||
anchor_right = 0.5
|
||||
offset_left = -775.0
|
||||
offset_right = 775.0
|
||||
offset_bottom = 502.0
|
||||
grow_horizontal = 2
|
||||
|
||||
[node name="QuestionContainer" type="MarginContainer" parent="PanelContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_left = 25
|
||||
theme_override_constants/margin_right = 25
|
||||
|
||||
[node name="QuestionLabel" type="Label" parent="PanelContainer/QuestionContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(1500, 500)
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 1
|
||||
theme_override_font_sizes/font_size = 70
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
autowrap_mode = 2
|
||||
|
||||
[node name="FormValidator" type="Control" parent="."]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 1
|
||||
anchors_preset = 7
|
||||
anchor_left = 0.5
|
||||
anchor_top = 1.0
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -20.0
|
||||
offset_top = -40.0
|
||||
offset_right = 20.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
script = ExtResource("2_jbdsv")
|
||||
auto_validate = true
|
||||
|
||||
[node name="FormContainer" type="VBoxContainer" parent="FormValidator"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(1624, 812)
|
||||
layout_mode = 1
|
||||
anchors_preset = 7
|
||||
anchor_left = 0.5
|
||||
anchor_top = 1.0
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -812.0
|
||||
offset_top = -812.0
|
||||
offset_right = 812.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
theme_override_constants/separation = 25
|
||||
alignment = 1
|
||||
|
||||
[connection signal="pressed" from="RightMargin/RightContainer/ValidateButton" to="." method="_on_validate_button_pressed"]
|
||||
@@ -0,0 +1,13 @@
|
||||
extends Step
|
||||
|
||||
|
||||
@onready var password := %password
|
||||
@onready var password_confirm := %password_confirm
|
||||
|
||||
func _on_validate_button_pressed():
|
||||
|
||||
if password.text != password_confirm.text:
|
||||
print("Make sure the password is the same in both fields")
|
||||
return
|
||||
|
||||
super._on_validate_button_pressed()
|
||||
@@ -0,0 +1,54 @@
|
||||
[gd_scene load_steps=10 format=3 uid="uid://cwqcybk5tvbly"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bxd3i06rqpxf0" path="res://sources/menus/register/steps/base_step.tscn" id="1_66bx5"]
|
||||
[ext_resource type="Script" path="res://sources/menus/register/steps/credentials_step.gd" id="2_uwjaa"]
|
||||
[ext_resource type="Script" path="res://addons/godot-form-validator/control_validator.gd" id="3_hblcf"]
|
||||
[ext_resource type="Script" path="res://addons/godot-form-validator/rules/required_rule.gd" id="4_4ltsd"]
|
||||
[ext_resource type="Script" path="res://addons/godot-form-validator/rules/email_rule.gd" id="5_cnymo"]
|
||||
[ext_resource type="Script" path="res://addons/godot-form-validator/validators/line_edit_validator.gd" id="6_viaho"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_os08u"]
|
||||
script = ExtResource("4_4ltsd")
|
||||
fail_message = "A value is required."
|
||||
|
||||
[sub_resource type="Resource" id="Resource_j7vhe"]
|
||||
script = ExtResource("5_cnymo")
|
||||
fail_message = "Value must be a valid email address."
|
||||
|
||||
[sub_resource type="Resource" id="Resource_84kj5"]
|
||||
script = ExtResource("6_viaho")
|
||||
validation_order = 1
|
||||
validation_method = 0
|
||||
skip_validation = false
|
||||
rules = Array[Resource("res://addons/godot-form-validator/rules/validator_rule.gd")]([SubResource("Resource_os08u"), SubResource("Resource_j7vhe")])
|
||||
|
||||
[node name="CredentialsStep" instance=ExtResource("1_66bx5")]
|
||||
script = ExtResource("2_uwjaa")
|
||||
question_txt = "Fill in your credentials"
|
||||
|
||||
[node name="ValidateButton" parent="RightMargin/RightContainer" index="0"]
|
||||
text = "Validate"
|
||||
|
||||
[node name="QuestionLabel" parent="PanelContainer/QuestionContainer" index="0"]
|
||||
text = "Fill in your credentials"
|
||||
|
||||
[node name="email" type="LineEdit" parent="FormValidator/FormContainer" index="0"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 70
|
||||
placeholder_text = "Email"
|
||||
|
||||
[node name="ControlValidator" type="Node" parent="FormValidator/FormContainer/email" index="0"]
|
||||
script = ExtResource("3_hblcf")
|
||||
validator = SubResource("Resource_84kj5")
|
||||
|
||||
[node name="password" type="LineEdit" parent="FormValidator/FormContainer" index="1"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 70
|
||||
placeholder_text = "Password"
|
||||
|
||||
[node name="password_confirm" type="LineEdit" parent="FormValidator/FormContainer" index="2"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 70
|
||||
placeholder_text = "Confirm password"
|
||||
@@ -0,0 +1,20 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://do5e7c1oxkn5g"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bxd3i06rqpxf0" path="res://sources/menus/register/steps/base_step.tscn" id="1_w3urq"]
|
||||
|
||||
[node name="DevicesCountStep" instance=ExtResource("1_w3urq")]
|
||||
question_txt = "Choose the number of devices you are using"
|
||||
|
||||
[node name="QuestionLabel" parent="PanelContainer/QuestionContainer" index="0"]
|
||||
text = "Choose the number of devices you are using"
|
||||
|
||||
[node name="FormContainer" parent="." index="2"]
|
||||
offset_left = -812.0
|
||||
offset_top = -812.0
|
||||
offset_right = 812.0
|
||||
|
||||
[node name="devices_count" type="SpinBox" parent="FormContainer" index="0"]
|
||||
layout_mode = 2
|
||||
min_value = 1.0
|
||||
max_value = 90.0
|
||||
value = 1.0
|
||||
@@ -0,0 +1,19 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://buhnx0oblueuq"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bxd3i06rqpxf0" path="res://sources/menus/register/steps/base_step.tscn" id="1_ksrhk"]
|
||||
|
||||
[node name="MethodStep" instance=ExtResource("1_ksrhk")]
|
||||
question_txt = "Choose the education method you are using"
|
||||
|
||||
[node name="QuestionLabel" parent="PanelContainer/QuestionContainer" index="0"]
|
||||
text = "Choose the education method you are using"
|
||||
|
||||
[node name="method" type="ItemList" parent="FormContainer" index="0"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/h_separation = 25
|
||||
theme_override_constants/v_separation = 25
|
||||
theme_override_font_sizes/font_size = 70
|
||||
auto_height = true
|
||||
item_count = 2
|
||||
item_0/text = "Complete"
|
||||
item_1/text = "App Only"
|
||||
@@ -0,0 +1,15 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://cyhoa68y1yyyg"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bxd3i06rqpxf0" path="res://sources/menus/register/steps/base_step.tscn" id="1_par6r"]
|
||||
|
||||
[node name="StudentsCountStep" instance=ExtResource("1_par6r")]
|
||||
question_txt = "Choose the total number of students"
|
||||
|
||||
[node name="QuestionLabel" parent="PanelContainer/QuestionContainer" index="0"]
|
||||
text = "Choose the total number of students"
|
||||
|
||||
[node name="students_count" type="SpinBox" parent="FormContainer" index="0"]
|
||||
layout_mode = 2
|
||||
min_value = 1.0
|
||||
max_value = 90.0
|
||||
value = 1.0
|
||||
Reference in New Issue
Block a user