112 lines
3.6 KiB
C++
112 lines
3.6 KiB
C++
// Oleg Petruny proprietary.
|
|
|
|
|
|
#include "WidgetsManager.h"
|
|
|
|
#include "Blueprint/UserWidget.h"
|
|
#include "Components/TextBlock.h"
|
|
#include "Engine/World.h"
|
|
#include "InputMappingContext.h"
|
|
#include "Kismet/GameplayStatics.h"
|
|
#include "UObject/ScriptInterface.h"
|
|
|
|
#include "CustomGameInstanceBase.h"
|
|
#include "Interactable/Interactable.h"
|
|
#include "Interactable/Modificators/InteractableModificator.h"
|
|
#include "InteractableHintWidgetManager.h"
|
|
#include "Widgets/CutsceneSkipWidget.h"
|
|
|
|
void UWidgetsManager::Init()
|
|
{
|
|
if(auto PC = UGameplayStatics::GetPlayerController(GetWorld(), 0))
|
|
{
|
|
for(auto& widget : permaOverlayWidgets)
|
|
{
|
|
if(auto instance = CreateWidget<UUserWidget>(PC, widget))
|
|
{
|
|
permaOverlayWidgetsInstances.Add(instance);
|
|
instance->AddToViewport();
|
|
}
|
|
}
|
|
for(auto& widget : overlayWidgets)
|
|
{
|
|
if(auto instance = CreateWidget<UUserWidget>(PC, widget))
|
|
{
|
|
overlayWidgetsInstances.Add(instance);
|
|
instance->AddToViewport();
|
|
}
|
|
}
|
|
if(auto instance = CreateWidget<UInteractableHintWidgetManager>(PC, interactableHintWidgetManagerClass))
|
|
{
|
|
interactableHintWidgetManager = instance;
|
|
interactableHintWidgetManager->AddToViewport();
|
|
}
|
|
if(auto instance = CreateWidget<UCutsceneSkipWidget>(PC, cutsceneSkipWidgetClass))
|
|
{
|
|
cutsceneSkipWidget = instance;
|
|
cutsceneSkipWidget->SetVisibility(ESlateVisibility::Hidden);
|
|
cutsceneSkipWidget->AddToViewport();
|
|
}
|
|
}
|
|
}
|
|
|
|
void UWidgetsManager::HideWidgets()
|
|
{
|
|
for(auto& widget : overlayWidgetsInstances)
|
|
widget->SetVisibility(ESlateVisibility::Hidden);
|
|
|
|
if(interactableHintWidgetManager)
|
|
interactableHintWidgetManager->Remove(nullptr);
|
|
}
|
|
|
|
void UWidgetsManager::ShowWidgets()
|
|
{
|
|
for(auto& widget : overlayWidgetsInstances)
|
|
widget->SetVisibility(ESlateVisibility::Visible);
|
|
|
|
if(interactableHintWidgetManager)
|
|
interactableHintWidgetManager->Append(nullptr);
|
|
}
|
|
|
|
void UWidgetsManager::UpdateWidgetsOwner()
|
|
{
|
|
if(auto PC = UGameplayStatics::GetPlayerController(GetWorld(), 0))
|
|
{
|
|
for(auto& widget : permaOverlayWidgetsInstances)
|
|
widget->SetOwningPlayer(PC);
|
|
for(auto& widget : overlayWidgetsInstances)
|
|
widget->SetOwningPlayer(PC);
|
|
}
|
|
}
|
|
|
|
void UWidgetsManager::ShowInteractionHints(const UInteractableModificator* modificator)
|
|
{
|
|
if(interactableHintWidgetManager)
|
|
interactableHintWidgetManager->Append(modificator);
|
|
}
|
|
void UWidgetsManager::HideInteractionHints(const UInteractableModificator* modificator)
|
|
{
|
|
if(interactableHintWidgetManager)
|
|
interactableHintWidgetManager->Remove(modificator);
|
|
}
|
|
void UWidgetsManager::AnimateInteractionHint(const UInteractableModificator* modificator, const int32 index, const EInputAnimatedWidgetAnimation animation)
|
|
{
|
|
if(interactableHintWidgetManager)
|
|
interactableHintWidgetManager->AnimateInteractionHint(modificator, index, animation);
|
|
}
|
|
|
|
void UWidgetsManager::EnableCutsceneWidget(FText keyText, FSkipCutsceneDelegate& skipCutsceneDelegate)
|
|
{
|
|
cutsceneSkipWidget->keyText->SetText(keyText);
|
|
cutsceneSkipWidget->skipCutsceneDelegate = skipCutsceneDelegate;
|
|
cutsceneSkipWidget->SetVisibility(ESlateVisibility::Visible);
|
|
}
|
|
void UWidgetsManager::DisableCutsceneWidget()
|
|
{
|
|
cutsceneSkipWidget->SetVisibility(ESlateVisibility::Hidden);
|
|
}
|
|
void UWidgetsManager::AnimateCutsceneWidget(const EInputAnimatedWidgetAnimation animation)
|
|
{
|
|
cutsceneSkipWidget->RunAnimation(animation);
|
|
}
|