2024-07-20 11:20:18 +02:00
|
|
|
class_name RootUI
|
2024-07-09 22:33:38 +02:00
|
|
|
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
|
|
|
|
|
2024-07-20 11:20:18 +02:00
|
|
|
enum ROOT_UI_STATE { MENU, GAME }
|
|
|
|
var _root_ui_state:ROOT_UI_STATE = ROOT_UI_STATE.GAME
|
2024-07-09 22:33:38 +02:00
|
|
|
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)
|
|
|
|
|
2024-08-15 21:10:38 +02:00
|
|
|
player.connect("trigger_message", ui_panels[2]._on_player_trigger_message)
|
|
|
|
|
2024-08-02 01:03:40 +02:00
|
|
|
set_root_ui_state(ROOT_UI_STATE.GAME)
|
2024-07-09 22:33:38 +02:00
|
|
|
|
|
|
|
func activate_ui_panel(ui_panel:Control):
|
|
|
|
for control in ui_panels:
|
|
|
|
if control == ui_panel:
|
|
|
|
control.visible = true
|
|
|
|
else:
|
|
|
|
control.visible = false
|
|
|
|
|
|
|
|
active_ui_panel = ui_panel
|
|
|
|
|
2024-07-20 11:20:18 +02:00
|
|
|
func set_root_ui_state(state:ROOT_UI_STATE):
|
|
|
|
if state == ROOT_UI_STATE.GAME:
|
2024-08-02 00:06:50 +02:00
|
|
|
%GameScene.show()
|
|
|
|
%StartupScene.hide()
|
|
|
|
%GameScene.process_mode = Node.PROCESS_MODE_INHERIT
|
2024-07-20 11:20:18 +02:00
|
|
|
activate_ui_panel(%GameUI)
|
|
|
|
else:
|
2024-08-02 00:06:50 +02:00
|
|
|
%StartupScene.show()
|
|
|
|
%GameScene.hide()
|
2024-07-20 11:20:18 +02:00
|
|
|
%GameMenuUI.hide()
|
2024-08-02 00:06:50 +02:00
|
|
|
%GameScene.process_mode = Node.PROCESS_MODE_DISABLED
|
2024-07-20 11:20:18 +02:00
|
|
|
activate_ui_panel(%MainMenuUI)
|
|
|
|
|
|
|
|
_root_ui_state = state
|
2024-07-09 22:33:38 +02:00
|
|
|
|
|
|
|
func _on_start_game_button_pressed():
|
2024-07-20 11:20:18 +02:00
|
|
|
set_root_ui_state(ROOT_UI_STATE.GAME)
|
2024-07-09 22:33:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _on_quit_button_pressed():
|
|
|
|
get_tree().quit()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_new_game_button_pressed():
|
|
|
|
activate_ui_panel(%NewGameUI)
|
|
|
|
|
|
|
|
|
|
|
|
func _to_main_menu_button_pressed():
|
2024-07-20 11:20:18 +02:00
|
|
|
set_root_ui_state(ROOT_UI_STATE.MENU)
|
2024-07-09 22:33:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _unhandled_input(event):
|
|
|
|
if event.is_action_released("toggle_inventory"):
|
|
|
|
inventory_dialog.open(_all_recipes, player.inventory)
|