// Oleg Petruny proprietary.


#include "Interactable.h"

#include "Kismet/GameplayStatics.h"

#include "../MainGameModeBase.h"
#include "../Widgets/WidgetsManager.h"
#include "Modificators/InteractableModificator.h"

void AInteractable::BeginPlay()
{
    // FOR ADRESS TO COLOR
    //if(auto m = material.LoadSynchronous())
    //{
    //    if(material->VectorParameterValues.Num() > 0)
    //    {
    //        GEngine->AddOnScreenDebugMessage(5, 5.0f, FColor::Emerald, material->VectorParameterValues[0].ParameterInfo.Name.ToString());
    //    }
    //}

    TArray<UMeshComponent*> meshes;
    GetComponents(meshes);
    for(auto mesh : meshes)
    {
        mesh->CustomDepthStencilValue = 0;
        mesh->CustomDepthStencilWriteMask = ERendererStencilMask::ERSM_Default;
        mesh->SetRenderCustomDepth(true);
    }

    for(auto& modificatorClass : modificatorsClasses)
    {
        _modificators.Add(NewObject<UInteractableModificator>(this, modificatorClass));
    }
}

void AInteractable::_Activate(EActivatorType type)
{
    activated |= static_cast<uint8>(type);
    if(auto WM = AMainGameModeBase::GetWidgetManager())
    {
        for(const auto modificator : _modificators)
        {
            WM->ShowInteractionHints(modificator);
        }
    }

    Activate_Implementation(type);
}

void AInteractable::_Deactivate(EActivatorType type)
{
    activated &= ~static_cast<uint8>(type);
    if(auto WM = AMainGameModeBase::GetWidgetManager())
    {
        WM->HideInteractionHints(type);
    }

    Deactivate_Implementation(type);
}
