GASATHON/Project/Source/Gasa/Game/GasaPlayerController.h

178 lines
5.6 KiB
C
Raw Permalink Normal View History

2024-04-12 13:10:06 -07:00
#pragma once
2024-04-12 13:30:01 -07:00
#include "GasaCommon.h"
#include "GasaPlayerState.h"
#include "Networking/GasaNetLibrary.h"
#include "Engine/Engine.h"
2024-04-12 14:53:47 -07:00
#include "GameFramework/PlayerController.h"
2024-04-12 13:30:01 -07:00
2024-04-12 13:10:06 -07:00
#include "GasaPlayerController.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnGasaPlayerControllerSig, AGasaPlayerController*, PC);
2024-04-12 13:10:06 -07:00
UCLASS(Blueprintable)
class GASA_API AGasaPlayerController : public APlayerController
{
GENERATED_BODY()
protected:
friend void AGasaPlayerState::ClientInitialize(AController* NewOwner);
2024-04-12 13:10:06 -07:00
public:
UFUNCTION()
void OnSeamlessTravelStart();
#pragma region Camera
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TObjectPtr<ACameraMount> Cam;
#pragma endregion Camera
// This will be implemented in the base until it needs to be lifted into an abstraction.
#if 0
#pragma region Highlighting
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Highlighting")
EHighlight HighlightState;
UFUNCTION(BlueprintCallable, Category="Highlighting")
void SetHighlight( EHighlight Desired );
2024-04-12 13:30:01 -07:00
UFUNCTION(BlueprintCallable, Category="Highlighting")
FORCEINLINE void Highlight() { SetHighlight(EHighlight::Enabled); };
UFUNCTION(BlueprintCallable, Category="Highlighting")
FORCEINLINE void Dehighlight() { SetHighlight(EHighlight::Disabled); };
#pragma endregion Highlighting
#endif
#pragma region GameFramework
UPROPERTY(BlueprintAssignable)
FOnGasaPlayerControllerSig Event_NetOwner_OnGameFrameworkInitialized;
UPROPERTY(BlueprintAssignable)
FOnGasaPlayerControllerSig Event_NetOwner_OnReady;
UPROPERTY(BlueprintAssignable)
FOnPawnSig Event_OnPawnPossessed;
UPROPERTY(Replicated, VisibleAnywhere)
bool bNetOwner_GameFrameworkInitialized = false;
UPROPERTY(VisibleAnywhere, Category = "Game Framework")
bool bNetOwnerReady = false;
void Client_CheckIfOwnerReady();
UFUNCTION()
void NetOwner_OnReady();
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, meta = (DisplayName = "NetOwner: On Ready"))
void BP_NetOwner_OnReady();
UFUNCTION()
void OnGameFrameworkInitialized();
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, meta=(DisplayName = "On Game Framework Initialized"))
void BP_OnGameFrameworkInitialized();
UFUNCTION()
void OnPawnReady();
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, meta=(DisplayName = "On Pawn Ready"))
void BP_OnPawnReady();
UFUNCTION()
void Server_SetupOnPawnReadyBinds(APawn* PawnToBindTo);
UFUNCTION()
void Server_SetNetOwner_GameFrameworkInitialized();
UFUNCTION(Server, Reliable)
void ServerRPC_R_NotifyOwningClientReady();
UFUNCTION(Server, Reliable)
void ServerRPC_R_SetNetOwner_GameFrameworkInitialized();
#pragma endregion GameFramework
2024-04-12 14:53:47 -07:00
#pragma region Input
2024-04-12 19:05:09 -07:00
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
TObjectPtr<AGasaCharacter> HoverPrev;
2024-04-12 19:05:09 -07:00
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
TObjectPtr<AGasaCharacter> HoverCurr;
2024-04-12 19:05:09 -07:00
2024-04-12 14:53:47 -07:00
UPROPERTY(EditAnywhere, Category="Input")
2024-04-12 13:30:01 -07:00
TObjectPtr<UInputMappingContext> IMC;
2024-04-12 14:53:47 -07:00
UPROPERTY(EditAnywhere, Category="Input")
TObjectPtr<UInputAction> IA_Move;
2024-04-13 08:56:19 -07:00
void Move(FInputActionValue const& ActionValue);
2024-04-12 14:53:47 -07:00
#pragma endregion Input
2024-04-12 13:10:06 -07:00
#pragma region NetSlime
// NetSlime interface is generated by GasaGen/GasaGen_NetSlime.cpp
FORCEINLINE ENetworkMode GetNetworkMode() const { return Gasa::GetNetworkMode( this ); }
FORCEINLINE bool IsClient() const { return Gasa::IsClient( this ); }
FORCEINLINE bool IsListenServer() const { return Gasa::IsListenServer( this ); }
FORCEINLINE bool IsNetOwner() const { return Gasa::IsNetOwner( this ); }
FORCEINLINE bool IsServer() const { return Gasa::IsServer( this ); }
FORCEINLINE bool IsSimulatedProxy() const { return Gasa::IsSimulatedProxy( this ); }
FORCEINLINE void NetLog(
FString Message,
EGasaVerbosity Verbosity = EGasaVerbosity::Log,
FLogCategoryBase& Category = LogGasaNet,
bool DumpStack = false,
int32 Line = __builtin_LINE(),
ANSICHAR const* File = __builtin_FILE(),
ANSICHAR const* Func = __builtin_FUNCTION()
)
{
Gasa::NetLog( this, Message, Verbosity, Category, DumpStack, Line, File, Func );
}
#pragma endregion NetSlime
2024-04-12 14:53:47 -07:00
AGasaPlayerController();
inline AGasaPlayerState* GetPlayerState();
#pragma region PlayerController
bool CanRestartPlayer() override;
void ClientSetHUD_Implementation(TSubclassOf<AHUD> NewHUDClass) override;
void ClientUpdateLevelStreamingStatus_Implementation(FName PackageName, bool bNewShouldBeLoaded, bool bNewShouldBeVisible, bool bNewShouldBlockOnLoad, int32 LODIndex, FNetLevelVisibilityTransactionId TransactionId, bool bNewShouldBlockOnUnload) override;
2024-04-12 19:05:09 -07:00
void PlayerTick(float DeltaTime) override;
void PostSeamlessTravel() override;
2024-04-12 14:53:47 -07:00
void SetupInputComponent() override;
void SpawnDefaultHUD() override;
2024-04-12 14:53:47 -07:00
#pragma endregion PlayerController
#pragma region Controller
void OnPossess(APawn* InPawn) override;
void OnRep_Pawn() override;
void OnUnPossess() override;
#pragma endregion Controller
2024-04-12 14:53:47 -07:00
#pragma region Actor
2024-04-12 13:30:01 -07:00
void BeginPlay() override;
void PostInitializeComponents() override;
void Tick(float DeltaSeconds) override;
2024-04-12 14:53:47 -07:00
#pragma endregion Actor
#pragma region UObject
void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
#pragma endregion UObject
2024-04-12 13:10:06 -07:00
};
namespace Gasa
{
inline
AGasaPlayerController* GetPrimaryPlayerController(UObject* Context)
{
UWorld* World = GEngine->GetWorldFromContextObject(Context, EGetWorldErrorMode::LogAndReturnNull);
if (World == nullptr)
{
Log("World is null... are you running in a proper context?", ELogV::Error);
return nullptr;
}
return Cast<AGasaPlayerController>(World->GetFirstPlayerController());
}
}