67 lines
1.5 KiB
GDScript
67 lines
1.5 KiB
GDScript
extends CanvasLayer
|
|
|
|
@onready var ui_panels:Array = [ %MainMenuUI, %NewGameUI, %GameUI, %GameMenuUI ]
|
|
@onready var active_ui_panel:Control = null
|
|
|
|
@onready var player = %Player
|
|
@onready var inventory_dialog:InventoryDialog = %InventoryDialog
|
|
|
|
var _all_recipes:Array[Recipe] = []
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
for file in DirAccess.get_files_at("res://data/recipes"):
|
|
var resource_file = "res://data/recipes/" + file
|
|
var recipe:Recipe = load(resource_file) as Recipe
|
|
_all_recipes.append(recipe)
|
|
|
|
activate_ui_panel(%GameUI)
|
|
|
|
|
|
func activate_ui_panel(ui_panel:Control):
|
|
for control in ui_panels:
|
|
if control == ui_panel:
|
|
control.visible = true
|
|
else:
|
|
control.visible = false
|
|
|
|
if not %GameUI.visible:
|
|
%World.process_mode = Node.PROCESS_MODE_DISABLED
|
|
else:
|
|
%World.process_mode = Node.PROCESS_MODE_INHERIT
|
|
|
|
active_ui_panel = ui_panel
|
|
|
|
|
|
func _on_start_game_button_pressed():
|
|
activate_ui_panel(%GameUI)
|
|
|
|
|
|
func _on_quit_button_pressed():
|
|
get_tree().quit()
|
|
|
|
|
|
|
|
func _on_new_game_button_pressed():
|
|
activate_ui_panel(%NewGameUI)
|
|
|
|
|
|
func _to_main_menu_button_pressed():
|
|
activate_ui_panel(%MainMenuUI)
|
|
|
|
|
|
func _unhandled_key_input(event:InputEvent):
|
|
if active_ui_panel != %GameUI:
|
|
return
|
|
|
|
var key_event:InputEventKey = event as InputEventKey
|
|
|
|
if key_event and key_event.pressed and key_event.get_keycode_with_modifiers() == KEY_ESCAPE:
|
|
activate_ui_panel(%GameMenuUI)
|
|
|
|
|
|
func _unhandled_input(event):
|
|
if event.is_action_released("toggle_inventory"):
|
|
inventory_dialog.open(_all_recipes, player.inventory)
|