test-client-godot/scenes/GUI/Settings/Settings.gd
2020-05-02 20:52:28 +02:00

90 lines
3.7 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
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("[res://scenes/GUI/Settings/Settings.gd:load_settings] 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 )
func _on_ReturnButton_pressed():
var config_file = ConfigFile.new()
var err = config_file.load( "user://settings.cfg" )
if err:
print("[res://scenes/GUI/Settings/Settings.gd:_on_ReturnButton_pressed] 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_FluteButton_pressed():
pass # Replace with function body.