UI code reorganizing
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
extends Control
|
||||
|
||||
@onready var submenu = $Submenu
|
||||
@onready var save = $Save
|
||||
@onready var load = $Load
|
||||
@onready var settings = $Settings
|
||||
@onready var menu_button = $MenuButton
|
||||
|
||||
var ui_main
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
|
||||
#Referencing main node
|
||||
ui_main = get_parent()
|
||||
|
||||
reset() #Initial state
|
||||
|
||||
#Connecting signals
|
||||
menu_button.pressed.connect(func():
|
||||
submenu.show()
|
||||
ui_main.masks.mask.show()
|
||||
)
|
||||
submenu.resume.pressed.connect(func():
|
||||
reset()
|
||||
ui_main.masks.mask.hide()
|
||||
)
|
||||
submenu.save.pressed.connect(func(): save.show())
|
||||
submenu.load.pressed.connect(func(): load.show())
|
||||
submenu.settings.pressed.connect(func(): settings.show())
|
||||
submenu.main_menu.pressed.connect(self._on_main_menu_pressed)
|
||||
submenu.quit.pressed.connect(func(): get_tree().quit())
|
||||
|
||||
for i in range(1, Globals.save_slot_count + 1):
|
||||
save.save_slot[i].pressed.connect(self._on_save_slot_pressed.bind(i))
|
||||
load.load_slot[i].pressed.connect(self._on_load_slot_pressed.bind(i))
|
||||
|
||||
|
||||
#Emits save_slot signal
|
||||
func _on_save_slot_pressed(save_slot_number: int):
|
||||
|
||||
var save_slot = save.save_slot[save_slot_number]
|
||||
|
||||
#Asking for confirmation if replacing existing save
|
||||
if save_slot.text != "EMPTY":
|
||||
var lambda = func(): ui_main.save_slot_pressed.emit(save_slot_number)
|
||||
var choice_text = "[center]Replace existing save ?[/center]"
|
||||
ui_main.ask_confirmation(lambda, Callable(), choice_text)
|
||||
else:
|
||||
ui_main.save_slot_pressed.emit(save_slot_number)
|
||||
|
||||
|
||||
#Emits load_slot signal
|
||||
func _on_load_slot_pressed(load_slot_number: int):
|
||||
|
||||
var load_slot = load.load_slot[load_slot_number]
|
||||
|
||||
#Asking for confirmation before loading
|
||||
if load_slot.text != "EMPTY":
|
||||
var lambda = func(): ui_main.load_slot_pressed.emit(load_slot_number)
|
||||
var choice_text = "[center]Load save ? Any unsaved games will be lost.[/center]"
|
||||
ui_main.ask_confirmation(lambda, Callable(), choice_text)
|
||||
else:
|
||||
pass
|
||||
|
||||
|
||||
#Going back to main menu
|
||||
func _on_main_menu_pressed():
|
||||
|
||||
#Asking for confirmation
|
||||
var lambda = func(): ui_main.main_menu_pressed.emit()
|
||||
var choice_text = "[center]Go back to main menu ? Unsaved changes will be lost.[/center]"
|
||||
ui_main.ask_confirmation(lambda, Callable(), choice_text)
|
||||
|
||||
|
||||
#Resets to initial state
|
||||
func reset():
|
||||
show()
|
||||
#Hiding everything except the menu button
|
||||
for node in [submenu, save, load, settings, menu_button]:
|
||||
node.hide()
|
||||
Reference in New Issue
Block a user