// Fill out your copyright notice in the Description page of Project Settings.


#include "MainMenuWidget.h"

#include "Components/Button.h"
#include "MainMenuPlayerController.h"

void UMainMenuWidget::NativeConstruct()
{
	Super::NativeConstruct();

	if (PlayButton)
	{
		PlayButton->OnClicked.AddDynamic(this, &UMainMenuWidget::HandlePlayClicked);
	}

	if (QuitButton)
	{
		QuitButton->OnClicked.AddDynamic(this, &UMainMenuWidget::HandleQuitClicked);
	}

	if (SettingsButton)
	{
		SettingsButton->OnClicked.AddDynamic(this, &UMainMenuWidget::HandleSettingsClicked);
	}

}

void UMainMenuWidget::HandlePlayClicked()
{
	if (AMainMenuPlayerController* Controller = GetOwningPlayer<AMainMenuPlayerController>())
	{
		Controller->StartGame();
	}
}

void UMainMenuWidget::HandleQuitClicked()
{
	if (AMainMenuPlayerController* Controller = GetOwningPlayer<AMainMenuPlayerController>())
	{
		Controller->QuitGame();
	}
}

void UMainMenuWidget::HandleSettingsClicked()
{
	if (AMainMenuPlayerController* Controller = GetOwningPlayer<AMainMenuPlayerController>())
	{
		Controller->OpenSettings();
	}
}
