test-client-godot/gui_scene/GUI/Settings/Settings.gd

126 lines
No EOL
6.3 KiB
GDScript

extends Container
signal return_pressed
signal font_changed( value )
func _ready():
$Menus/TabContainer/Display/ScrollContainer/VBoxContainer/Fullscreen/CheckBox.pressed = ProjectSettings.get_setting( "display/window/size/fullscreen" )
$Menus/TabContainer/Display/ScrollContainer/VBoxContainer/Borderless/CheckBox.pressed = ProjectSettings.get_setting( "display/window/size/borderless" )
$Menus/TabContainer/Display/ScrollContainer/VBoxContainer/Resizable/CheckBox.pressed = ProjectSettings.get_setting( "display/window/size/resizable" )
$Menus/TabContainer/Display/ScrollContainer/VBoxContainer/CurrentScreen/SpinBox.value = OS.current_screen
$Menus/TabContainer/connexion/v_box_container/h_box_container4/language.add_item("fr")
$Menus/TabContainer/connexion/v_box_container/h_box_container4/language.add_item("en")
load_settings()
func _on_font_size_bar_value_changed(value):
$Menus/TabContainer/Test/ScrollContainer/VBoxContainer/font_size/font_size_value.text = str( value )
$Menus.get_theme().default_font.size = value
emit_signal( "font_changed", value )
func load_settings():
var config_file = ConfigFile.new()
var err = config_file.load( "user://settings.cfg" )
if err == ERR_CANT_OPEN or err == ERR_FILE_NOT_FOUND:
# On suppose que le fichier n'existe pas encore, donc on le crée.
config_file.set_value( "theme", "font_size", 14 )
config_file.save( "user://settings.cfg" )
elif not err == OK:
print("Error code when loading config file: ", err)
global.font_size = config_file.get_value( "theme", "font_size" )
if $Menus.get_theme():
$Menus.get_theme().default_font.size = global.font_size
$Menus/TabContainer/Test/ScrollContainer/VBoxContainer/font_size_bar.value = global.font_size
$Menus/TabContainer/Test/ScrollContainer/VBoxContainer/font_size/font_size_value.text = str( global.font_size )
#var connexion = load("res://assets/Scripts/Config/connexion.gd").new()
var script_connexion = load("res://assets/Scripts/Config/connexion.gd")
var connexion = script_connexion.connexion.new()
var language = connexion.get_language()
$Menus/TabContainer/connexion/v_box_container/h_box_container/register.text = connexion.get_url_register()
$Menus/TabContainer/connexion/v_box_container/h_box_container2/connexion.text = connexion.get_url_login()
$Menus/TabContainer/connexion/v_box_container/h_box_container3/certificate_valid.pressed = connexion.get_valid_certificate()
# language
for i in range(0, $Menus/TabContainer/connexion/v_box_container/h_box_container4/language.get_item_count()):
if $Menus/TabContainer/connexion/v_box_container/h_box_container4/language.get_item_text(i) == language:
$Menus/TabContainer/connexion/v_box_container/h_box_container4/language.select(i)
break
#$Menus/TabContainer/connexion/v_box_container/h_box_container4/language.
#.selected = language
#$Menus/TabContainer/connexion/v_box_container/h_box_container4/language.selected
#func _on_ReturnButton_pressed():
# var config_file = ConfigFile.new()
# var err = config_file.load( "user://settings.cfg" )
# if err:
# print("Error code when loading config file: ", err)
# config_file.set_value("theme", "font_size", $Menus.get_theme().default_font.size)
# config_file.save( "user://settings.cfg" )
# emit_signal( "return_pressed" )
func _on_Title_text_changed(new_text):
# ----------------------------------
# Changing windows title
var new_title = "Khanat"
new_text = new_text.strip_edges()
if not new_text == "":
new_title = new_text
new_title += " (" + String(OS.get_window_size().x) + "x" + String(OS.get_window_size().y) + ")"
OS.set_window_title( new_title )
# ----------------------------------
func _on_Fullscreen_toggled(button_pressed):
if ProjectSettings.has_setting( "display/window/size/fullscreen" ):
ProjectSettings.set_setting("display/window/size/fullscreen", button_pressed)
OS.window_fullscreen = ProjectSettings.get_setting("display/window/size/fullscreen")
func _on_Borderless_toggled(button_pressed):
if ProjectSettings.has_setting( "display/window/size/borderless" ):
ProjectSettings.set_setting("display/window/size/borderless", button_pressed)
OS.window_borderless = ProjectSettings.get_setting("display/window/size/borderless")
func _on_Resizable_toggled(button_pressed):
if ProjectSettings.has_setting( "display/window/size/resizable" ):
ProjectSettings.set_setting("display/window/size/resizable", button_pressed)
OS.window_resizable = ProjectSettings.get_setting("display/window/size/resizable")
# La fonction existe dans la doc mais le moteur lui ne la reconnait pas,
# soit il y a une subtilité quelquepart soit la doc n'est pas à jour.
func _on_AlwaysOnTop_toggled(button_pressed):
# OS.set_window_always_on_top( button_pressed )
pass
func _on_SpinBox_value_changed(value):
OS.current_screen = value
func _on_ApplyButton_pressed():
var config_file = ConfigFile.new()
var err = config_file.load( "user://settings.cfg" )
if err:
print("Error code when loading config file: ", err)
config_file.set_value("theme", "font_size", $Menus.get_theme().default_font.size)
config_file.save( "user://settings.cfg" )
# Save Connexion
var script_connexion = load("res://assets/Scripts/Config/connexion.gd")
var connexion = script_connexion.connexion.new()
connexion.set_url_register($Menus/TabContainer/connexion/v_box_container/h_box_container/register.text)
connexion.set_url_login($Menus/TabContainer/connexion/v_box_container/h_box_container2/connexion.text)
var id = $Menus/TabContainer/connexion/v_box_container/h_box_container4/language.get_selected_id()
var language = $Menus/TabContainer/connexion/v_box_container/h_box_container4/language.get_item_text(id)
connexion.set_language(language)
connexion.set_valid_certificate($Menus/TabContainer/connexion/v_box_container/h_box_container3/certificate_valid.pressed)
connexion.save()
emit_signal( "return_pressed" )
func _on_CancelButton_pressed():
emit_signal( "return_pressed" )
func _unhandled_input(event):
if event is InputEventKey:
if event.pressed and event.scancode == KEY_ESCAPE:
emit_signal( "return_pressed" )