using Godot;
using System;

public partial class main_menu : Control
{
	// Called when the node enters the scene tree for the first time.
	private input_menu _inputMenu;
	private ship_choice _shipChoice;
	private VBoxContainer _layout;
	
	public override void _Ready()
	{
		
		//input file handling
		GD.Print(FileAccess.FileExists("user://config/input.cfg"));
		if (!FileAccess.FileExists("user://config/input.cfg"))
		{
			//GD.Print("No user input.cfg found — copying default config.");
			var src = FileAccess.Open("res://config/input.cfg", FileAccess.ModeFlags.Read);
			var dst = FileAccess.Open("user://config/input.cfg", FileAccess.ModeFlags.Write);
			
			//GD.Print("Contents of default input.cfg:\n", src.GetAsText());
			
			dst.StoreString(src.GetAsText());
			src.Close();
			dst.Close();
		}

		
		
		_inputMenu = GetNode<input_menu>("InputMenu");
		_shipChoice = GetNode<ship_choice>("ShipChoice");
		_layout = GetNode<VBoxContainer>("CanvasLayer/CenterContainer/Layout");
		
		//Connecting Buttons
		GetNode<Button>("CanvasLayer/CenterContainer/Layout/StartButton").Pressed += OnStartButtonPressed;
		GetNode<Button>("CanvasLayer/CenterContainer/Layout/ExitButton").Pressed += OnExitButtonPressed;
		GetNode<Button>("CanvasLayer/CenterContainer/Layout/InputButton").Pressed += OnInputButtonPressed;
		
	}
	
	private void OnStartButtonPressed()
	{
		_layout.Hide();
		_shipChoice.Show();
	}

	private void OnExitButtonPressed()
	{
		GetTree().Quit();
	}

	private void OnInputButtonPressed()
	{
		_inputMenu.ShowInputPanel();
	}

	// Called every frame. 'delta' has been the elapsed time since the previous frame.
	public override void _Process(double delta)
	{
	}
}
