Files
Fortis/Source/FORTIS_Taktika/Public/ResComFloorManager.h
T
2024-04-09 01:20:23 +05:00

124 lines
3.3 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "ResComLevelPackLoader.h"
#include "Engine/LevelStreaming.h"
#include "Kismet/GameplayStatics.h"
#include "ResComApartmentManager.h"
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "ResComFloorManager.generated.h"
/*Single-cast delegate declaration. No parameters*/
DECLARE_DYNAMIC_DELEGATE(FOnPreview);
DECLARE_DYNAMIC_DELEGATE(FOnShouldBeVisible);
DECLARE_DYNAMIC_DELEGATE(FOnShouldBeLoaded);
DECLARE_DYNAMIC_DELEGATE(FOnLoaded);
UENUM(BlueprintType)
enum Enum_LevelType
{
preview UMETA(DisplayName = "preview"),
visible UMETA(DisplayName = "visible"),
loaded UMETA(DisplayName = "loaded"),
};
USTRUCT(BlueprintType)
struct FFloorLevelStreaming
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite)
ULevelStreaming* level = nullptr;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TEnumAsByte<Enum_LevelType> type;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 depth = 0;
};
USTRUCT(BlueprintType)
struct FFloorPack
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FApartmentLocation location;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<FFloorLevelStreaming> levels;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool loaded = false;
bool IsLoaded()
{
loaded = false;
for (auto& level : levels)
{
if (!IsValid(level.level))
return loaded;
if (!(level.level->IsLevelVisible()))
return loaded;
}
loaded = true;
return loaded;
}
};
UCLASS()
class FORTIS_TAKTIKA_API AResComFloorManager : public AActor
{
GENERATED_BODY()
protected:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<FFloorPack> packs;
private:
UFUNCTION()
void OnLevelPreview();
UFUNCTION()
void OnLevelVisible();
UFUNCTION()
void OnLevelLoaded();
bool GetPack(FApartmentLocation loc, FFloorPack *& pack);
public:
// Sets default values for this actor's properties
AResComFloorManager();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
UFUNCTION(BlueprintCallable, Category = "StreamingLevel")
TArray<ULevelStreaming*> GetStreamingLevels(const UObject* WorldContextObject);
UPROPERTY()
FOnPreview OnPreview;
UPROPERTY()
FOnShouldBeVisible OnShouldBeVisible;
UPROPERTY()
FOnShouldBeLoaded OnShouldBeLoaded;
UPROPERTY()
FOnLoaded OnLoaded;
UFUNCTION(BlueprintCallable, Category = "Pack")
void AddLevelToPack(FApartmentLocation loc, FFloorLevelStreaming level);
UFUNCTION(BlueprintCallable, Category = "Pack")
bool GetPack(FApartmentLocation loc, FFloorPack& pack) const;
UFUNCTION(BlueprintCallable, Category = "Pack")
void AddPack(const FFloorPack& pack);
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UFUNCTION(BlueprintCallable, Category="Pack")
//bool LoadPack(FApartmentLocation loc, const FOnPreview& delegatePreview, const FOnShouldBeVisible& delegateShouldBeVisible, const FOnShouldBeLoaded& delegateShouldBeLoaded);
bool LoadPack(FApartmentLocation loc, const FOnLoaded& delegateOnLoaded);
UFUNCTION(BlueprintCallable, Category = "Pack")
bool UnloadPack(FApartmentLocation loc, const FOnPreview& delegatePreview, const FOnShouldBeVisible& delegateShouldBeVisible, const FOnShouldBeLoaded& delegateShouldBeLoaded);
};