Adds all the register steps. Reworks register scene
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
extends ProgressBar
|
||||
|
||||
func set_value_with_tween(v : float) -> void:
|
||||
create_tween().tween_property(self, "value", v, 0.15).set_trans(Tween.TRANS_LINEAR)
|
||||
@@ -2,27 +2,25 @@ 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")
|
||||
preload("res://sources/menus/register/steps/teacher/devices_count_step.tscn")
|
||||
]
|
||||
@onready var parent_steps : Array[PackedScene] = [
|
||||
|
||||
preload("res://sources/menus/register/steps/parent/players_count_step.tscn")
|
||||
]
|
||||
var current_steps : Array[PackedScene]
|
||||
# TODO Change the resource
|
||||
@onready var register_data := UserSettings.new()
|
||||
|
||||
@onready var account_type_step : PackedScene = preload("res://sources/menus/register/steps/account_type_step.tscn")
|
||||
@onready var credential_step : PackedScene = preload("res://sources/menus/register/steps/credentials_step.tscn")
|
||||
@onready var students_step : PackedScene = preload("res://sources/menus/register/steps/teacher/students_count_step.tscn")
|
||||
@onready var player_step : PackedScene = preload("res://sources/menus/register/steps/parent/player_step.tscn")
|
||||
|
||||
var current_steps : Array[Step]
|
||||
|
||||
@onready var register_data := UserSettings.new() # TODO Change the resource
|
||||
@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
|
||||
current_steps = [account_type_step.instantiate()]
|
||||
_go_to_step(progress_bar.value)
|
||||
|
||||
|
||||
@@ -30,19 +28,20 @@ func _go_to_step(step_index: int):
|
||||
|
||||
# Clear the steps
|
||||
for step in steps.get_children(false):
|
||||
step.queue_free()
|
||||
step.completed.disconnect(_on_step_completed)
|
||||
steps.remove_child(step)
|
||||
|
||||
# Instantiate the step
|
||||
var next_step = teacher_steps[step_index].instantiate()
|
||||
next_step.name = str(step_index)
|
||||
next_step.data = register_data
|
||||
var next_step = current_steps[step_index]
|
||||
if not next_step.data:
|
||||
next_step.data = register_data
|
||||
steps.add_child(next_step)
|
||||
|
||||
# Connect the step
|
||||
next_step.completed.connect(_on_step_completed)
|
||||
|
||||
# Handles progress bar
|
||||
progress_bar.value = step_index
|
||||
progress_bar.set_value_with_tween(step_index)
|
||||
|
||||
|
||||
func _on_back_button_pressed():
|
||||
@@ -52,8 +51,57 @@ func _on_back_button_pressed():
|
||||
_go_to_step(progress_bar.value-1)
|
||||
|
||||
|
||||
func _on_step_completed():
|
||||
func _on_step_completed(step : Step, values : Dictionary):
|
||||
|
||||
match step.step_name:
|
||||
"type":
|
||||
# Adds teacher or parent steps
|
||||
if "type" in values:
|
||||
_remove_future_steps()
|
||||
if values["type"] == 0:
|
||||
for scene in teacher_steps:
|
||||
current_steps.append(scene.instantiate())
|
||||
else:
|
||||
for scene in parent_steps:
|
||||
current_steps.append(scene.instantiate())
|
||||
progress_bar.max_value = current_steps.size()
|
||||
"devices":
|
||||
# Adds students steps for teachers
|
||||
if "devices_count" in values:
|
||||
_remove_future_steps()
|
||||
var count = values["devices_count"] as int
|
||||
if count:
|
||||
for device in count:
|
||||
var students_step_scene := students_step.instantiate()
|
||||
students_step_scene.question = students_step_scene.question % (device + 1)
|
||||
current_steps.append(students_step_scene)
|
||||
current_steps.append(credential_step.instantiate())
|
||||
progress_bar.max_value = current_steps.size()
|
||||
"players":
|
||||
# Adds students steps for parents
|
||||
if "students_count" in values:
|
||||
_remove_future_steps()
|
||||
var count = values["students_count"] as int
|
||||
if count:
|
||||
for student in count:
|
||||
var student_step_scene := player_step.instantiate()
|
||||
student_step_scene.question = student_step_scene.question % (student + 1)
|
||||
current_steps.append(student_step_scene)
|
||||
current_steps.append(credential_step.instantiate())
|
||||
progress_bar.max_value = current_steps.size()
|
||||
|
||||
|
||||
if progress_bar.value == current_steps.size()-1:
|
||||
print("Registering complete !")
|
||||
else:
|
||||
_go_to_step(progress_bar.value+1)
|
||||
|
||||
|
||||
func _remove_future_steps():
|
||||
# Free memory
|
||||
for i in current_steps.size():
|
||||
if i > progress_bar.value:
|
||||
current_steps[i].queue_free()
|
||||
|
||||
# Resize the array to remove unwanted steps
|
||||
current_steps.resize(progress_bar.value + 1)
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://b7cfjs2iipagq"]
|
||||
[gd_scene load_steps=8 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"]
|
||||
[ext_resource type="Script" path="res://sources/menus/register/ProgressBar.gd" id="5_6e6tc"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_0rcyk"]
|
||||
border_width_left = 3
|
||||
@@ -57,10 +58,12 @@ 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_font_sizes/font_size = 50
|
||||
theme_override_styles/background = SubResource("StyleBoxFlat_0rcyk")
|
||||
theme_override_styles/fill = SubResource("StyleBoxFlat_bhfkq")
|
||||
step = 1.0
|
||||
value = 50.0
|
||||
max_value = 10.0
|
||||
step = 0.1
|
||||
script = ExtResource("5_6e6tc")
|
||||
|
||||
[node name="Steps" type="Control" parent="."]
|
||||
unique_name_in_owner = true
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
[gd_scene load_steps=8 format=3 uid="uid://c73wkbttv0ou0"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bxd3i06rqpxf0" path="res://sources/menus/register/steps/base_step.tscn" id="1_g51ml"]
|
||||
[ext_resource type="Script" path="res://addons/godot-form-validator/control_validator.gd" id="2_hidu6"]
|
||||
[ext_resource type="Script" path="res://addons/godot-form-validator/rules/required_rule.gd" id="3_54aao"]
|
||||
[ext_resource type="Script" path="res://sources/menus/register/steps/validation/item_list_validator.gd" id="4_bdvqa"]
|
||||
[ext_resource type="Script" path="res://sources/utils/binder/control_binder.gd" id="5_w7o0m"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_kw8sn"]
|
||||
script = ExtResource("3_54aao")
|
||||
fail_message = "A value is required."
|
||||
|
||||
[sub_resource type="Resource" id="Resource_n0ht0"]
|
||||
script = ExtResource("4_bdvqa")
|
||||
validation_order = 1
|
||||
validation_method = 1
|
||||
skip_validation = false
|
||||
rules = Array[Resource("res://addons/godot-form-validator/rules/validator_rule.gd")]([SubResource("Resource_kw8sn")])
|
||||
|
||||
[node name="AccountTypeStep" instance=ExtResource("1_g51ml")]
|
||||
step_name = "type"
|
||||
question = "Choose the type of account"
|
||||
|
||||
[node name="TypeContainer" type="VBoxContainer" parent="FormValidator/FormBinder/FormContainer" index="0"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="TypeSelectError" type="Label" parent="FormValidator/FormBinder/FormContainer/TypeContainer" index="0"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
text = "Test"
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="TypeSelect" type="ItemList" parent="FormValidator/FormBinder/FormContainer/TypeContainer" index="1"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 70
|
||||
auto_height = true
|
||||
item_count = 2
|
||||
item_0/text = "Teacher"
|
||||
item_1/text = "Parent"
|
||||
|
||||
[node name="ControlValidator" type="Node" parent="FormValidator/FormBinder/FormContainer/TypeContainer/TypeSelect" index="1"]
|
||||
script = ExtResource("2_hidu6")
|
||||
validator = SubResource("Resource_n0ht0")
|
||||
|
||||
[node name="ControlBinder" type="Control" parent="FormValidator/FormBinder/FormContainer/TypeContainer/TypeSelect" index="2"]
|
||||
anchors_preset = 0
|
||||
script = ExtResource("5_w7o0m")
|
||||
property_name = "type"
|
||||
@@ -2,19 +2,23 @@
|
||||
extends Control
|
||||
class_name Step
|
||||
|
||||
signal completed
|
||||
signal completed(step : Step, values : Dictionary)
|
||||
|
||||
@onready var question_label : Label = %QuestionLabel
|
||||
@onready var form_validator : FormValidator = %FormValidator
|
||||
@onready var form_binder : FormBinder = %FormBinder
|
||||
@onready var form_container : Control = %FormContainer
|
||||
|
||||
@export var step_name : String
|
||||
@export_multiline var question : String
|
||||
@export var data : Resource
|
||||
|
||||
func _ready():
|
||||
form_binder.read(data)
|
||||
question_label.text = question
|
||||
|
||||
|
||||
# Display error messages
|
||||
func _on_form_validator_control_validated(control, passed, messages):
|
||||
var label = find_child(control.name + "Error", true, false) as Label
|
||||
if not label:
|
||||
@@ -30,6 +34,8 @@ func _on_form_validator_control_validated(control, passed, messages):
|
||||
func _on_validate_button_pressed():
|
||||
# Validate the fields
|
||||
if not form_validator.validate():
|
||||
print(form_validator._control_validator_map)
|
||||
print(form_validator.get_messages())
|
||||
push_warning("Validation failed (" + str(self) + ")")
|
||||
return
|
||||
|
||||
@@ -39,5 +45,5 @@ func _on_validate_button_pressed():
|
||||
return
|
||||
|
||||
# Emit completed signal
|
||||
emit_signal("completed")
|
||||
emit_signal("completed", self, form_binder.values_changed)
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_02ocl")
|
||||
step_name = null
|
||||
question = null
|
||||
|
||||
[node name="RightMargin" type="MarginContainer" parent="."]
|
||||
custom_minimum_size = Vector2(450, 2.08165e-12)
|
||||
@@ -83,7 +85,14 @@ script = ExtResource("2_nw61e")
|
||||
|
||||
[node name="FormBinder" type="Control" parent="FormValidator"]
|
||||
unique_name_in_owner = true
|
||||
anchors_preset = 0
|
||||
layout_mode = 1
|
||||
anchors_preset = 7
|
||||
anchor_left = 0.5
|
||||
anchor_top = 1.0
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
script = ExtResource("3_mk32l")
|
||||
|
||||
[node name="FormContainer" type="VBoxContainer" parent="FormValidator/FormBinder"]
|
||||
|
||||
@@ -40,13 +40,12 @@ skip_validation = false
|
||||
rules = Array[Resource("res://addons/godot-form-validator/rules/validator_rule.gd")]([SubResource("Resource_5jooi"), SubResource("Resource_104uy")])
|
||||
|
||||
[node name="CredentialsStep" instance=ExtResource("1_66bx5")]
|
||||
step_name = "credentials"
|
||||
question = "Enter 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="EmailContainer" type="VBoxContainer" parent="FormValidator/FormBinder/FormContainer" index="0"]
|
||||
layout_mode = 2
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
[gd_scene load_steps=8 format=3 uid="uid://dc4eaxcunpmke"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bxd3i06rqpxf0" path="res://sources/menus/register/steps/base_step.tscn" id="1_ggdon"]
|
||||
[ext_resource type="Script" path="res://addons/godot-form-validator/control_validator.gd" id="2_6d1eh"]
|
||||
[ext_resource type="Script" path="res://addons/godot-form-validator/rules/required_rule.gd" id="3_pj58p"]
|
||||
[ext_resource type="Script" path="res://sources/menus/register/steps/validation/item_list_validator.gd" id="4_fcdvy"]
|
||||
[ext_resource type="Script" path="res://sources/utils/binder/control_binder.gd" id="5_kb1ut"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_kw8sn"]
|
||||
script = ExtResource("3_pj58p")
|
||||
fail_message = "A value is required."
|
||||
|
||||
[sub_resource type="Resource" id="Resource_pdktm"]
|
||||
script = ExtResource("4_fcdvy")
|
||||
validation_order = 1
|
||||
validation_method = 1
|
||||
skip_validation = false
|
||||
rules = Array[Resource("res://addons/godot-form-validator/rules/validator_rule.gd")]([SubResource("Resource_kw8sn")])
|
||||
|
||||
[node name="PlayerStep" instance=ExtResource("1_ggdon")]
|
||||
step_name = ""
|
||||
question = "Enter the informations of player %d"
|
||||
|
||||
[node name="QuestionLabel" parent="PanelContainer/QuestionContainer" index="0"]
|
||||
text = "Enter the informations of student %d"
|
||||
|
||||
[node name="LevelContainer" type="VBoxContainer" parent="FormValidator/FormBinder/FormContainer" index="0"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="LevelSelectError" type="Label" parent="FormValidator/FormBinder/FormContainer/LevelContainer" index="0"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
text = "Test"
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="LevelSelect" type="ItemList" parent="FormValidator/FormBinder/FormContainer/LevelContainer" index="1"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 70
|
||||
auto_height = true
|
||||
item_count = 3
|
||||
item_0/text = "Beginner"
|
||||
item_1/text = "Reviewer"
|
||||
item_2/text = "Adult"
|
||||
|
||||
[node name="ControlValidator" type="Node" parent="FormValidator/FormBinder/FormContainer/LevelContainer/LevelSelect" index="1"]
|
||||
script = ExtResource("2_6d1eh")
|
||||
validator = SubResource("Resource_pdktm")
|
||||
|
||||
[node name="ControlBinder" type="Control" parent="FormValidator/FormBinder/FormContainer/LevelContainer/LevelSelect" index="2"]
|
||||
anchors_preset = 0
|
||||
script = ExtResource("5_kb1ut")
|
||||
property_name = "level"
|
||||
|
||||
[node name="AgeField" type="SpinBox" parent="FormValidator/FormBinder/FormContainer" index="1"]
|
||||
layout_mode = 2
|
||||
min_value = 1.0
|
||||
value = 1.0
|
||||
|
||||
[node name="ControlBinder" type="Control" parent="FormValidator/FormBinder/FormContainer/AgeField" index="2"]
|
||||
anchors_preset = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
script = ExtResource("5_kb1ut")
|
||||
property_name = "age"
|
||||
@@ -0,0 +1,21 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://irtjwltfbatm"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bxd3i06rqpxf0" path="res://sources/menus/register/steps/base_step.tscn" id="1_nli7s"]
|
||||
[ext_resource type="Script" path="res://sources/utils/binder/control_binder.gd" id="2_u3nk8"]
|
||||
|
||||
[node name="PlayersCountStep" instance=ExtResource("1_nli7s")]
|
||||
step_name = "players"
|
||||
question = "Choose the number of players"
|
||||
|
||||
[node name="PlayersCountField" type="SpinBox" parent="FormValidator/FormBinder/FormContainer" index="0"]
|
||||
layout_mode = 2
|
||||
min_value = 1.0
|
||||
max_value = 10.0
|
||||
value = 1.0
|
||||
|
||||
[node name="ControlBinder" type="Control" parent="FormValidator/FormBinder/FormContainer/PlayersCountField" index="2"]
|
||||
anchors_preset = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
script = ExtResource("2_u3nk8")
|
||||
property_name = "students_count"
|
||||
@@ -4,9 +4,8 @@
|
||||
[ext_resource type="Script" path="res://sources/utils/binder/control_binder.gd" id="2_asuou"]
|
||||
|
||||
[node name="DevicesCountStep" instance=ExtResource("1_w3urq")]
|
||||
|
||||
[node name="QuestionLabel" parent="PanelContainer/QuestionContainer" index="0"]
|
||||
text = "Choose the number of devices you are using"
|
||||
step_name = "devices"
|
||||
question = "Choose the number of devices"
|
||||
|
||||
[node name="DevicesCountField" type="SpinBox" parent="FormValidator/FormBinder/FormContainer" index="0"]
|
||||
layout_mode = 2
|
||||
|
||||
@@ -18,9 +18,8 @@ skip_validation = false
|
||||
rules = Array[Resource("res://addons/godot-form-validator/rules/validator_rule.gd")]([SubResource("Resource_kw8sn")])
|
||||
|
||||
[node name="MethodStep" instance=ExtResource("1_ksrhk")]
|
||||
|
||||
[node name="QuestionLabel" parent="PanelContainer/QuestionContainer" index="0"]
|
||||
text = "Choose the education method you are using"
|
||||
step_name = ""
|
||||
question = "Choose the education method"
|
||||
|
||||
[node name="MethodContainer" type="VBoxContainer" parent="FormValidator/FormBinder/FormContainer" index="0"]
|
||||
layout_mode = 2
|
||||
|
||||
@@ -6,9 +6,8 @@
|
||||
|
||||
[node name="StudentsCountStep" instance=ExtResource("1_par6r")]
|
||||
script = ExtResource("2_susi5")
|
||||
|
||||
[node name="QuestionLabel" parent="PanelContainer/QuestionContainer" index="0"]
|
||||
text = "Choose the total number of students"
|
||||
step_name = "students"
|
||||
question = "Choose the number of students on device %d"
|
||||
|
||||
[node name="StudentsCountField" type="SpinBox" parent="FormValidator/FormBinder/FormContainer" index="0"]
|
||||
unique_name_in_owner = true
|
||||
|
||||
@@ -18,6 +18,13 @@ func get_value():
|
||||
return control.value
|
||||
elif control is LineEdit or control is TextEdit:
|
||||
return control.text
|
||||
elif control is ItemList:
|
||||
var selected_indexes = control.get_selected_items()
|
||||
if not selected_indexes or selected_indexes.size() == 0:
|
||||
return null
|
||||
if control.select_mode == ItemList.SELECT_SINGLE:
|
||||
return selected_indexes[0]
|
||||
return selected_indexes
|
||||
|
||||
return null
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ extends Control
|
||||
class_name FormBinder
|
||||
|
||||
@export var data : Resource
|
||||
|
||||
var values_changed: Dictionary = {}
|
||||
var _control_binder_map: Dictionary = {}
|
||||
|
||||
func _ready():
|
||||
@@ -45,7 +47,7 @@ func write() -> bool:
|
||||
|
||||
for control in _control_binder_map.keys():
|
||||
var binder = _control_binder_map[control]
|
||||
|
||||
values_changed[binder.property_name] = binder.get_value()
|
||||
if binder.property_name in data:
|
||||
data.set(binder.property_name, binder.get_value())
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user