Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Myblueprintfunctionlibrary.h:
- // Fill out your copyright notice in the Description page of Project Settings.
- #pragma once
- #include "CoreMinimal.h"
- #include "Kismet/BlueprintFunctionLibrary.h"
- #include "Engine/GameEngine.h"
- #include "MyBlueprintFunctionLibrary.generated.h"
- UCLASS()
- class MP_SK_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
- {
- GENERATED_BODY()
- public:
- //const FText& NotString
- UFUNCTION(BlueprintCallable, Category = "Notification")
- static void AddNotificationToScreen(const FText& NotString);
- };
- Myblueprintfunctionlibrary.cpp:
- // Fill out your copyright notice in the Description page of Project Settings.
- #include "MyBlueprintFunctionLibrary.h"
- //#include "SNotificationList.h"
- #include "Widgets/Notifications/SNotificationList.h"
- #include "Runtime/Slate/Public/Framework/Notifications/NotificationManager.h"
- //#include "Framework/Notifications/NotificationManager.h"
- #include "Engine/GameEngine.h"
- void UMyBlueprintFunctionLibrary::AddNotificationToScreen(const FText& NotString)
- {
- UGameEngine* engine = Cast<UGameEngine>(GEngine);
- if (engine)
- {
- if (!engine->GameViewport->Viewport->IsForegroundWindow())
- {
- //const FText NotText = FText::FromString(NotString);
- //const FText NotificationText = FText::Format(NSLOCTEXT("MixerInteractivityEditor", "DesktopNotificationAlert", "{0}" ), NotText );
- //FNotificationInfo info(FText::FromString("A Notification"));
- FNotificationInfo Info(NotString);
- Info.bFireAndForget = true;
- Info.FadeInDuration = 0.2f;
- Info.FadeOutDuration = 1.0f;
- Info.ExpireDuration = 8.0f;
- Info.bUseLargeFont = true;
- /* we define our callback lambda
- auto notificationClicked = [](const FGeometry &, const FPointerEvent &) -> FReply
- {
- // we restore the game window no matter where it is
- UGameEngine* engine = Cast<UGameEngine>(GEngine);
- if (engine)
- {
- TSharedPtr<SWindow> windowRef = engine->GameViewportWindow.Pin();
- SWindow* window = windowRef.Get();
- if (window)
- {
- if (window->IsWindowMinimized())
- {
- window->Restore();
- window->ShowWindow();
- }
- window->BringToFront(true);
- window->HACK_ForceToFront();
- }
- }
- return FReply::Handled();
- };*/
- //TSharedPtr<SNotificationItem> item =
- FSlateNotificationManager::Get().AddNotification(Info);
- /*
- if (item.IsValid())
- {
- item.Get()->SetOnMouseButtonDown(FPointerEventHandler::CreateLambda(notificationClicked));
- }
- // we force the notification window to the foreground
- TArray<TSharedRef<SWindow>> windows;
- FSlateNotificationManager::Get().GetWindows(windows);
- int32 num = windows.Num();
- for (int32 i = 0; i < num; ++i)
- {
- FSlateNotificationManager::Get().ForceNotificationsInFront(windows[i]);
- SWindow& win = windows[i].Get();
- win.Restore();
- win.ShowWindow();
- win.BringToFront(true);
- win.HACK_ForceToFront();
- }*/
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement