92 lines
2.3 KiB
C#
92 lines
2.3 KiB
C#
using Godot;
|
|
using System;
|
|
|
|
public partial class Setting : Control
|
|
{
|
|
Global global;
|
|
int font_size;
|
|
LineEdit fontOut;
|
|
|
|
// Called when the node enters the scene tree for the first time.
|
|
public override void _Ready()
|
|
{
|
|
global = GetNode<Global>("/root/Global");
|
|
fontOut = GetNode<LineEdit>("BoxContainer/MarginContainer5/HBoxContainer/FontSize");
|
|
font_size = (int)global.GlobalConfigDict["font_size"];
|
|
GetNode<HSlider>("BoxContainer/MarginContainer6/FontSizeBar")
|
|
.Value = font_size;
|
|
fontOut.Text = font_size.ToString();
|
|
|
|
FillingData();
|
|
}
|
|
private void FillingData()
|
|
{
|
|
GetNode<LineEdit>("BoxContainer/MarginContainer2/Server/LineEdit")
|
|
.Text = global.GlobalConfigDict["server_url"].ToString();
|
|
GetNode<LineEdit>("BoxContainer/MarginContainer3/Name/LineEdit")
|
|
.Text = global.GlobalConfigDict["user_name"].ToString();
|
|
}
|
|
|
|
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
public override void _Process(double delta)
|
|
{
|
|
}
|
|
|
|
private void OnBack() {
|
|
global.SaveConfig();
|
|
global.GotoScene("res://Main.tscn", null);
|
|
}
|
|
|
|
void OnNameChanged(string Value)
|
|
{
|
|
global.GlobalConfigDict["user_name"] = Value;
|
|
// global.ConfigFlush();
|
|
}
|
|
|
|
private void OnServerUrlChanged(string Value)
|
|
{
|
|
global.GlobalConfigDict["server_url"] = Value;
|
|
// global.ConfigFlush();
|
|
}
|
|
|
|
private void OnFontSizeChanged(float Value)
|
|
{
|
|
font_size = (int)Value;
|
|
global.GlobalConfigDict["font_size"] = font_size;
|
|
global.ConfigFlush();
|
|
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 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");
|
|
}
|
|
}
|