// Oleg Petruny proprietary.

#pragma once

#include "UObject/Object.h"

#include "CutsceneManager.generated.h"

DECLARE_DYNAMIC_DELEGATE(FCutsceneEndCallback);

UCLASS(BlueprintType)
class UCutsceneManager : public UObject
{
    GENERATED_BODY()

public:
    UCutsceneManager();

    UFUNCTION(BlueprintCallable)
    void EnqueueSequence(class ULevelSequence* sequence, FCutsceneEndCallback endCallback);

    UFUNCTION(BlueprintCallable)
    void SkipSequence();

    UFUNCTION(BlueprintCallable)
    void ClearQueue();

    UFUNCTION(BlueprintCallable)
    void LockCallback(bool lock);

private:
    void PlayNextSequence();
    UFUNCTION()
    void OnSequenceEnd();
    void OnFirstCutsceneInit();

    void OnInputHold();
    void OnInputUnhold();

    class ULevelSequencePlayer* sequencePlayer = nullptr;
    class ALevelSequenceActor* sequencePlayerActor = nullptr;
    TQueue<class ULevelSequence*> nextSequences;
    FCriticalSection sequencesLock;
    TQueue<FCutsceneEndCallback> endCallbacks;
    FCriticalSection callbacksLock;

    class APlayerBase* lastPlayer = nullptr;
    TSoftObjectPtr<class UInputMappingContext> context;
    TPair<int32, int32> handlers;

    bool lockCallback = false;
    bool lastlySkipped = false;
    bool holding = false;
};
