42 lines
1.3 KiB
GDScript
42 lines
1.3 KiB
GDScript
extends Button
|
|
|
|
@onready var button = $"."
|
|
@onready var main_menu = $".."
|
|
var world_scene = preload("res://scenes/world.tscn")
|
|
|
|
func _ready():
|
|
enable()
|
|
|
|
func enable():
|
|
$".".pressed.connect(self._button_pressed)
|
|
|
|
func disable():
|
|
$".".pressed.disconnect()
|
|
|
|
func _button_pressed():
|
|
if ("quit" in name):
|
|
get_tree().quit()
|
|
elif ("new_world" in name):
|
|
get_tree().change_scene_to_packed(world_scene)
|
|
World.new_world()
|
|
elif ("load_world" in name):
|
|
var world_scene_instance = world_scene.instantiate();
|
|
world_scene_instance.name = "world"
|
|
var to_remove = $"/root/Main menu"
|
|
get_tree().root.add_child(world_scene_instance)
|
|
get_tree().root.remove_child(to_remove)
|
|
World.load_world("world")
|
|
elif ("save_world" in name):
|
|
World.save_world()
|
|
elif ("save_exit" in name):
|
|
World.save_world()
|
|
#get_tree().change_scene_to_file("res://scenes/UI/main_menu.tscn")
|
|
var to_remove = $"/root/world"
|
|
get_tree().root.add_child(load("res://scenes/UI/main_menu.tscn").instantiate())
|
|
get_tree().root.remove_child(to_remove)
|
|
elif ("exit_nosave" in name):
|
|
#get_tree().change_scene_to_file("res://scenes/UI/main_menu.tscn")
|
|
var to_remove = $"/root/world"
|
|
get_tree().root.add_child(load("res://scenes/UI/main_menu.tscn").instantiate())
|
|
get_tree().root.remove_child(to_remove)
|