// Project Lab - NHTV Igad

#pragma once

#include "GameFramework/PlayerController.h"
#include "PlayerControllerBase.h"
#include "MenuController.generated.h"

UCLASS()
class UNREALPROJECT_API AMenuController : public APlayerControllerBase
{
	GENERATED_BODY()

public:
	AMenuController(const FObjectInitializer& ObjectInitializer);
	
	virtual void BeginPlay() override;
	virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
	virtual void NotifyLoadedWorld(FName WorldPackageName, bool bFinalDest) override;
	virtual void Destroyed() override;

	virtual void PreClientTravel(const FString& PendingURL, ETravelType TravelType, bool bIsSeamlessTravel) override;
	virtual void SeamlessTravelFrom(class APlayerController* OldPC) override;
	virtual void SeamlessTravelTo(class APlayerController* NewPC) override;

	virtual void OnLearnSkill(class UBaseSkillObject* object);
	virtual void OnUnlearnSkill(class UBaseSkillObject* object);
	virtual void OnEnterLobby();

	UFUNCTION(Server, WithValidation, Reliable)
	virtual void SetSetupState(const FPlayerSetupState& state);
	virtual void OnRep_PlayerState() override;

	void SwitchToMenu();

	UPROPERTY(BlueprintReadOnly)
	class UMenuScreen* mainMenu;
	UPROPERTY(BlueprintReadOnly)
	class ULobbyMenu* lobbyMenu;
	UPROPERTY(BlueprintReadOnly)
	class USkillTreeWidget* skillTree;

	UFUNCTION(BlueprintCallable, Category = "PIE")
	bool WorldIsPIE() const;

private:
	UFUNCTION(Server, WithValidation, Reliable)
	void m_OnClientInitialized();

	void m_OnInviteAccepted(bool success, const FOnlineSessionSearchResult& result);
	UFUNCTION()
	void m_OnSessionJoined(int32 result);

	void m_AutoRequestTeam();
	FTimerHandle m_teamRequestTimer;

	// Called when the splash screens end
	UFUNCTION()
	void m_OnSplashScreenEnded();
	// Called when the start prompt closes
	UFUNCTION()
	void m_OnStartPromptClosed();

	UPROPERTY()
	class USplashScreen* m_splash;
	UPROPERTY()
	class UStartPromptScreen* m_startScreen;

	// True if we are currently in the lobby screen, this can be checked if it is set before the menu widgets are created
	bool m_inLobby;
};
