Add "clear" option for local data

This commit is contained in:
Adrien Ufferte
2026-02-05 11:08:12 +01:00
parent 19d7687d91
commit e7ef6f9e48
6 changed files with 119 additions and 12 deletions
+5
View File
@@ -382,3 +382,8 @@ SYNCHRONIZATION_COMPILE_SERVER_INSTRUCTIONS,Compilation des instructions de sync
SYNCHRONIZATION_SEND_SERVER_INSTRUCTIONS,Envoie des instructions de synchronisation au serveur,Enviar instrucciones de sincronización al servidor,Enviar instruções de sincronização ao servidor
SYNCHRONIZATION_APPLY_LOCAL_INSTRUCTIONS,Application des instructions de synchronisation en local,Aplicar instrucciones de sincronización localmente,Aplicar instruções de sincronização localmente
LOG_TOO_MUCH_ROTATION,Log: Rotation index exceeded 999; continuing with _1000. It is recommended to restart the game,Log: El índice de rotación superó los 999; continuando con _1000. Se recomienda reiniciar el juego,Log: Índice de rotação excedeu 999; continuando com _1000. Recomenda-se reiniciar o jogo
DANGER_ZONE,ZONE DE DANGER,ZONA DE PELIGRO,ZONA DE PERIGO
CLEAR_LOCAL_DATA,Supprimer toutes les données locales,Borrar todos los datos locales,Apagar todos os dados locais
CLEAR_LOCAL_DATA_CONFIRM,cliquez sur OK %d fois pour confirmer,haz clic en OK %d veces para confirmar,clique em OK %d vezes para confirmar
RESTART_APP_REQUIRED,Veuillez fermer l’application et la relancer,Por favor cierre la aplicación y vuelva a abrirla,Por favor, feche o aplicativo e reinicie-o
OK,OK,OK,OK
Can't render this file because it contains an unexpected character in line 349 and column 448.
@@ -2,12 +2,14 @@ class_name DeveloperSettings
extends Control
const LOG_LEVEL_ELEMENT: PackedScene = preload("res://sources/menus/settings/log_level_element.tscn")
const CLEAR_LOCAL_DATA_CONFIRMATIONS: int = 5
static var return_path: String = "res://sources/menus/main/main_menu.tscn"
var filters: Dictionary[int, bool] = {}
var line_steps: PackedInt32Array = [10, 50, 100, 200, 500, 1000, -1] # -1 = all
var loglevel_regex: RegEx
var clear_local_data_confirmations: int = 0
@onready var slider: HSlider = $VBoxContainer/Controls/LineCountSlider
@onready var slider_label: Label = $VBoxContainer/Controls/SliderLabel
@@ -18,6 +20,8 @@ var loglevel_regex: RegEx
@onready var api_path_status_label: Label = $VBoxContainer/ApiPathControls/StatusLabel
@onready var prod_button: Button = $VBoxContainer/ApiPathControls/EnvironmentButtons/ProdButton
@onready var dev_button: Button = $VBoxContainer/ApiPathControls/EnvironmentButtons/DevButton
@onready var clear_local_data_popup: ConfirmPopup = $VBoxContainer/DangerZoneContainer/DangerZoneButtonRow/ClearLocalDataButton/ClearLocalDataPopup
@onready var restart_required_popup: ConfirmPopup = $RestartRequiredPopup
func _ready() -> void:
@@ -124,6 +128,45 @@ func _on_api_path_apply_pressed() -> void:
_update_api_path()
func _on_clear_local_data_button_pressed() -> void:
clear_local_data_confirmations = 0
clear_local_data_popup.content_text = tr("CLEAR_LOCAL_DATA_CONFIRM") % 5
clear_local_data_popup.show()
func _on_clear_local_data_popup_accepted() -> void:
clear_local_data_confirmations += 1
if clear_local_data_confirmations >= CLEAR_LOCAL_DATA_CONFIRMATIONS:
clear_local_data_confirmations = 0
UserDataManager.delete_teacher_data()
UserDataManager.logout()
UserDataManager.clear_all_local_data()
await get_tree().process_frame
get_tree().root.propagate_notification(NOTIFICATION_WM_CLOSE_REQUEST)
await get_tree().process_frame
get_tree().set_auto_accept_quit(true)
get_tree().quit()
await get_tree().process_frame
await get_tree().process_frame
_show_restart_required_popup()
return
clear_local_data_popup.content_text = tr("CLEAR_LOCAL_DATA_CONFIRM") % (5 - clear_local_data_confirmations)
await get_tree().process_frame
clear_local_data_popup.show()
func _on_clear_local_data_popup_refused() -> void:
clear_local_data_confirmations = 0
func _show_restart_required_popup() -> void:
restart_required_popup.content_text = tr("RESTART_APP_REQUIRED")
restart_required_popup.close_on_action = false
restart_required_popup.set_buttons_visible(false)
restart_required_popup.set_buttons_enabled(false)
restart_required_popup.show()
func _on_prod_button_pressed() -> void:
_set_environment(1, "PROD")
+44 -1
View File
@@ -4,6 +4,7 @@
[ext_resource type="Texture2D" uid="uid://wtx3wqs0l4si" path="res://assets/minigames/minigame_ui/graphic/button_back_up.png" id="3_vjlw0"]
[ext_resource type="Texture2D" uid="uid://cbhip35yyqneg" path="res://assets/minigames/minigame_ui/graphic/button_back_down.png" id="4_s0ywi"]
[ext_resource type="Texture2D" uid="uid://tcapan0mj64o" path="res://assets/minigames/minigame_ui/graphic/button_back_disabled.png" id="5_4q33k"]
[ext_resource type="PackedScene" uid="uid://bhdh5xfyauss0" path="res://sources/ui/popup.tscn" id="6_7w7ds"]
[node name="DeveloperSettings" type="Control" unique_id=2110866691]
layout_mode = 3
@@ -130,6 +131,7 @@ layout_mode = 2
size_flags_horizontal = 3
[node name="Filters" type="HBoxContainer" parent="VBoxContainer" unique_id=135854551]
custom_minimum_size = Vector2(1900, 100)
layout_mode = 2
alignment = 1
@@ -143,13 +145,54 @@ layout_mode = 0
offset_left = 30.0
offset_top = 14.0
offset_right = 1930.0
offset_bottom = 1414.0
offset_bottom = 1074.0
size_flags_vertical = 3
placeholder_text = "Placeholder Text
Contains all logs textss"
editable = false
[node name="HSeparator2" type="HSeparator" parent="VBoxContainer" unique_id=722273796]
layout_mode = 2
theme_override_constants/separation = 50
[node name="DangerZoneContainer" type="VBoxContainer" parent="VBoxContainer" unique_id=396337752]
layout_mode = 2
theme_override_constants/separation = 20
[node name="DangerZoneLabel" type="Label" parent="VBoxContainer/DangerZoneContainer" unique_id=484118701]
layout_mode = 2
theme_override_colors/font_color = Color(1, 0, 0, 1)
text = "DANGER_ZONE"
horizontal_alignment = 1
[node name="DangerZoneButtonRow" type="HBoxContainer" parent="VBoxContainer/DangerZoneContainer" unique_id=1713354008]
layout_mode = 2
alignment = 1
[node name="ClearLocalDataButton" type="Button" parent="VBoxContainer/DangerZoneContainer/DangerZoneButtonRow" unique_id=646582562]
layout_mode = 2
theme_override_colors/font_color = Color(1, 0, 0, 1)
text = "CLEAR_LOCAL_DATA"
[node name="ClearLocalDataPopup" parent="VBoxContainer/DangerZoneContainer/DangerZoneButtonRow/ClearLocalDataButton" unique_id=3359874 instance=ExtResource("6_7w7ds")]
unique_name_in_owner = true
visible = false
content_text = "CLEAR_LOCAL_DATA_CONFIRM"
confirm_text_override = "OK"
[node name="HSeparator3" type="HSeparator" parent="VBoxContainer" unique_id=1265768300]
layout_mode = 2
theme_override_constants/separation = 50
[node name="RestartRequiredPopup" parent="." unique_id=263832703 instance=ExtResource("6_7w7ds")]
unique_name_in_owner = true
visible = false
content_text = "RESTART_APP_REQUIRED"
[connection signal="pressed" from="InterfaceLeft/Container/BackButton" to="." method="_on_back_button_pressed"]
[connection signal="pressed" from="VBoxContainer/ApiPathControls/PathRow/ApplyButton" to="." method="_on_api_path_apply_pressed"]
[connection signal="pressed" from="VBoxContainer/ApiPathControls/EnvironmentButtons/ProdButton" to="." method="_on_prod_button_pressed"]
[connection signal="pressed" from="VBoxContainer/ApiPathControls/EnvironmentButtons/DevButton" to="." method="_on_dev_button_pressed"]
[connection signal="pressed" from="VBoxContainer/DangerZoneContainer/DangerZoneButtonRow/ClearLocalDataButton" to="." method="_on_clear_local_data_button_pressed"]
[connection signal="accepted" from="VBoxContainer/DangerZoneContainer/DangerZoneButtonRow/ClearLocalDataButton/ClearLocalDataPopup" to="." method="_on_clear_local_data_popup_accepted"]
[connection signal="refused" from="VBoxContainer/DangerZoneContainer/DangerZoneButtonRow/ClearLocalDataButton/ClearLocalDataPopup" to="." method="_on_clear_local_data_popup_refused"]
@@ -18,7 +18,7 @@ anchor_top = 0.5
anchor_right = 1.0
anchor_bottom = 0.5
offset_top = -900.0
offset_right = -2250.0
offset_right = -2328.0
offset_bottom = -811.0
grow_horizontal = 2
grow_vertical = 2
@@ -37,12 +37,11 @@ tabs_visible = false
[node name="NormalContainer" type="HBoxContainer" parent="TabContainer" unique_id=1506751594]
layout_mode = 2
theme_override_constants/separation = 0
theme_override_constants/separation = 10
metadata/_tab_index = 0
[node name="VSeparator" type="VSeparator" parent="TabContainer/NormalContainer" unique_id=1288223327]
[node name="VSeparator" type="VSeparator" parent="TabContainer/NormalContainer" unique_id=806669186]
layout_mode = 2
theme_override_constants/separation = 25
[node name="CheckBox" type="CheckBox" parent="TabContainer/NormalContainer" unique_id=2014370082]
unique_name_in_owner = true
@@ -50,15 +49,11 @@ layout_mode = 2
size_flags_stretch_ratio = 0.5
button_pressed = true
[node name="VSeparator2" type="VSeparator" parent="TabContainer/NormalContainer" unique_id=863436468]
layout_mode = 2
theme_override_constants/separation = 25
[node name="LogLevel" type="Label" parent="TabContainer/NormalContainer" unique_id=657280463]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 0.3
theme_override_font_sizes/font_size = 70
theme_override_font_sizes/font_size = 50
text = "Trace"
clip_text = true
+15 -2
View File
@@ -8,6 +8,7 @@ signal refused()
@export_multiline var content_text: String = "": set = _set_content_text
@export var confirm_text_override: String = ""
@export var cancel_text_override: String = ""
@export var close_on_action: bool = true
@onready var content_label: Label = %ContentLabel
@onready var confirm_button: Button = %ConfirmButton
@@ -36,11 +37,23 @@ func _set_cancel_text(p_content_text: String) -> void:
cancel_button.text = p_content_text
func set_buttons_visible(is_visible: bool) -> void:
confirm_button.visible = is_visible
cancel_button.visible = is_visible
func set_buttons_enabled(is_enabled: bool) -> void:
confirm_button.disabled = not is_enabled
cancel_button.disabled = not is_enabled
func _on_confirm_button_pressed() -> void:
accepted.emit()
hide()
if close_on_action:
hide()
func _on_cancel_button_pressed() -> void:
refused.emit()
hide()
if close_on_action:
hide()
@@ -77,6 +77,14 @@ func purge_user_folders_if_needed() -> void:
ResourceSaver.save(_device_settings, "user://device_settings.tres")
func clear_all_local_data() -> void:
var error: Error = Utils.clean_dir("user://")
if error != OK:
Log.error("UserDataManager: Could not clean user:// directory. Error: %s" % error_string(error))
return
Log.warn("UserDataManager: All local user data cleared from user://")
func _process(_delta: float) -> void:
if Engine.is_editor_hint():
return # Do nothing in editor mode