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.
72 lines
2.5 KiB
72 lines
2.5 KiB
class_name EscapeMenuWorld |
|
extends CenterContainer |
|
|
|
@onready var save_file_dialog : FileDialog = %SaveFileDialog |
|
@onready var load_file_dialog : FileDialog = %LoadFileDialog |
|
|
|
@onready var filename_label : Label = %Filename |
|
@onready var playtime_label : Label = %Playtime |
|
@onready var last_saved_label : Label = %LastSaved |
|
|
|
@onready var quick_save_button : Button = %QuickSave |
|
@onready var save_as_button : Button = %SaveAs |
|
@onready var load_from_button : Button = %LoadFrom |
|
|
|
var current_world : String |
|
|
|
func _ready() -> void: |
|
# Hide "Quick Save" button until world is loaded/saved, and `current_world` is set. |
|
quick_save_button.visible = false |
|
save_as_button.text = "Save World As..." |
|
|
|
DirAccess.make_dir_recursive_absolute(World.WORLDS_DIR) |
|
var global_path := ProjectSettings.globalize_path(World.WORLDS_DIR) |
|
save_file_dialog.current_path = global_path |
|
load_file_dialog.current_path = global_path |
|
|
|
# this.GetClient().StatusChanged += OnStatusChanged; |
|
|
|
func _process(delta: float) -> void: |
|
var playtime := Game.WORLD.playtime |
|
var seconds := floori(playtime ) % 60 |
|
var minutes := floori(playtime / 60 ) % 60 |
|
var hours := floori(playtime / (60 * 60) ) % 24 |
|
var days := floori(playtime / (60 * 60 * 24)) |
|
|
|
var str = "" |
|
if days > 0: str += "%dd " % days |
|
str += "%02dh %02dm %02ds" % [ hours, minutes, seconds ] |
|
playtime_label.text = str |
|
|
|
|
|
func _on_quick_save_pressed() -> void: |
|
_on_save_file_dialog_file_selected(current_world) |
|
|
|
func _on_save_as_pressed() -> void: |
|
save_file_dialog.invalidate() |
|
save_file_dialog.popup_centered() |
|
func _on_save_file_dialog_file_selected(path: String) -> void: |
|
Game.WORLD.save(path) |
|
current_world = path |
|
filename_label.text = path.get_file() |
|
last_saved_label.text = _unix_time_to_string(Game.WORLD.last_saved) |
|
quick_save_button.visible = true |
|
save_as_button.text = "Save As..." |
|
|
|
func _on_load_from_pressed() -> void: |
|
load_file_dialog.invalidate() |
|
load_file_dialog.popup_centered() |
|
func _on_load_file_dialog_file_selected(path: String) -> void: |
|
var world := World.load(path) |
|
if not world: return |
|
Game.INSTANCE.change_world(world) |
|
|
|
current_world = path |
|
filename_label.text = path.get_file() |
|
last_saved_label.text = _unix_time_to_string(world.last_saved) |
|
quick_save_button.visible = true |
|
save_as_button.text = "Save As..." |
|
|
|
func _unix_time_to_string(time: int) -> String: |
|
var d := Time.get_datetime_dict_from_unix_time(time) |
|
return "%04d-%02d-%02d %02d:%02d" % [ d.year, d.month, d.day, d.hour, d.minute ]
|
|
|