You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.2 KiB
50 lines
1.2 KiB
public partial class LoadSaveMenu : MarginContainer |
|
{ |
|
const string SAVES_FOLDER = "user://saves/"; |
|
|
|
[Export] public FileDialog LoadFileDialog { get; set; } |
|
[Export] public FileDialog SaveFileDialog { get; set; } |
|
|
|
[Export] public Label Filename { get; set; } |
|
[Export] public Label LastSaved { get; set; } |
|
|
|
public override void _EnterTree() |
|
{ |
|
DirAccess.MakeDirAbsolute(SAVES_FOLDER); |
|
LoadFileDialog.RootSubfolder = SAVES_FOLDER; |
|
SaveFileDialog.RootSubfolder = SAVES_FOLDER; |
|
} |
|
|
|
|
|
public void OnLoadPressed() |
|
{ |
|
LoadFileDialog.Popup(); |
|
} |
|
|
|
public void OnOverwriteSavePressed() |
|
{ |
|
OnSaveFileDialogSelected(Filename.Text); |
|
} |
|
|
|
public void OnCreateSavePressed() |
|
{ |
|
SaveFileDialog.Popup(); |
|
} |
|
|
|
|
|
public void OnLoadFileDialogSelected(string path) |
|
{ |
|
Game.LocalWorkshop.LoadFromFile(path); |
|
Filename.Text = path; |
|
var time = FileAccess.GetModifiedTime(path); |
|
var date = DateTimeOffset.FromUnixTimeSeconds((long)time).LocalDateTime; |
|
LastSaved.Text = date.ToString("yyyy-MM-dd HH:mm:ss"); |
|
} |
|
|
|
public void OnSaveFileDialogSelected(string path) |
|
{ |
|
Game.LocalWorkshop.SaveToFile(path); |
|
Filename.Text = path; |
|
LastSaved.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
|
} |
|
}
|
|
|