using Godot; using System; using System.IO; public partial class Setting : Control { private GlobalManager global = GlobalManager.Instance; private readonly IConfigManager config = GlobalManager.Instance.ConfigManager; private int font_size; private LineEdit fontOut = null!; // Called when the node enters the scene tree for the first time. public override void _Ready() { fontOut = GetNode("%FontSize"); font_size = config.GetValue("font_size"); GetNode("%FontSizeBar") .Value = font_size; fontOut.Text = font_size.ToString(); GetNode("%LineEdit_ServerIP") .Text = config.GetValue("server_addr"); GetNode("%LineEdit_UserName") .Text = config.GetValue("user_name"); } // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(double delta) { } private void OnBack() { global.GotoScene("res://Main.tscn", null); } private void OnSave() { global.SaveConfig(); } void OnNameChanged(string Value) { config.SetValue("user_name", Value); } private void OnServerUrlChanged(string Value) { config.SetValue("server_url", Value); } private void OnFontSizeChanged(float Value) { font_size = (int)Value; config.SetValue("font_size", font_size); global.GlobalThemeConfigFlush(); fontOut.Text = font_size.ToString(); } private static void OnClearData() { // ProjectSettings.GlobalizePath("user://"); // DirAccess.CopyAbsolute("res://userdata", "user://"); } private static void OnClearUserData() { string path = ProjectSettings.GlobalizePath("user://"); // DirAccess dirAccess = DirAccess.Open(path); // dirAccess.Remove(path); if (DirAccess.RemoveAbsolute(path) != Error.Ok) { FormattableString msg = $"Failed to delete user data at {path}"; OS.Alert(msg.ToString(), "Error"); } } private static void OnGetSettingsFile() { string path = ProjectSettings.GlobalizePath(GlobalManager.ConfigPath); OS.ShellOpen(Path.GetDirectoryName(path)); } private static void OnGetCacheDir() { OS.Alert(OS.GetCacheDir(), "Cache Dir"); } private static void OnGetConfigDir() { OS.Alert(OS.GetConfigDir(), "Config Dir"); } private static void OnGetDataDir() { OS.Alert(OS.GetDataDir(), "Data Dir"); } private static void OnGetUserDataDir() { OS.Alert(OS.GetUserDataDir(), "User Data Dir"); } private static void ChangeLangZHCN(bool _) => TranslationServer.SetLocale("zh_CN"); private static void ChangeLangEN(bool _) => TranslationServer.SetLocale("en"); }