Advertisement
Guest User

Untitled

a guest
Nov 24th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.98 KB | None | 0 0
  1. Myblueprintfunctionlibrary.h:
  2. // Fill out your copyright notice in the Description page of Project Settings.
  3.  
  4. #pragma once
  5.  
  6. #include "CoreMinimal.h"
  7. #include "Kismet/BlueprintFunctionLibrary.h"
  8. #include "Engine/GameEngine.h"
  9.  
  10. #include "MyBlueprintFunctionLibrary.generated.h"
  11.  
  12. UCLASS()
  13. class MP_SK_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
  14. {
  15.     GENERATED_BODY()
  16.  
  17. public:
  18.  
  19.     //const FText& NotString
  20.     UFUNCTION(BlueprintCallable, Category = "Notification")
  21.     static void AddNotificationToScreen(const FText& NotString);
  22.  
  23. };
  24. Myblueprintfunctionlibrary.cpp:
  25. // Fill out your copyright notice in the Description page of Project Settings.
  26.  
  27. #include "MyBlueprintFunctionLibrary.h"
  28. //#include "SNotificationList.h"
  29. #include "Widgets/Notifications/SNotificationList.h"
  30. #include "Runtime/Slate/Public/Framework/Notifications/NotificationManager.h"
  31. //#include "Framework/Notifications/NotificationManager.h"
  32. #include "Engine/GameEngine.h"
  33.  
  34. void UMyBlueprintFunctionLibrary::AddNotificationToScreen(const FText& NotString)
  35. {
  36.  
  37.     UGameEngine* engine = Cast<UGameEngine>(GEngine);
  38.  
  39.     if (engine)
  40.     {
  41.  
  42.         if (!engine->GameViewport->Viewport->IsForegroundWindow())
  43.         {
  44.             //const FText NotText = FText::FromString(NotString);
  45.             //const FText NotificationText = FText::Format(NSLOCTEXT("MixerInteractivityEditor", "DesktopNotificationAlert", "{0}" ), NotText );
  46.             //FNotificationInfo info(FText::FromString("A Notification"));
  47.             FNotificationInfo Info(NotString);
  48.  
  49.             Info.bFireAndForget = true;
  50.             Info.FadeInDuration = 0.2f;
  51.             Info.FadeOutDuration = 1.0f;
  52.             Info.ExpireDuration = 8.0f;
  53.             Info.bUseLargeFont = true;
  54.  
  55.             /* we define our callback lambda
  56.             auto notificationClicked = [](const FGeometry &, const FPointerEvent &) -> FReply
  57.             {
  58.                 // we restore the game window no matter where it is
  59.                 UGameEngine* engine = Cast<UGameEngine>(GEngine);
  60.                 if (engine)
  61.                 {
  62.                     TSharedPtr<SWindow> windowRef = engine->GameViewportWindow.Pin();
  63.                     SWindow* window = windowRef.Get();
  64.                     if (window)
  65.                     {
  66.                         if (window->IsWindowMinimized())
  67.                         {
  68.                             window->Restore();
  69.                             window->ShowWindow();
  70.                         }
  71.  
  72.                         window->BringToFront(true);
  73.                         window->HACK_ForceToFront();
  74.                     }
  75.                 }
  76.  
  77.                 return FReply::Handled();
  78.             };*/
  79.  
  80.             //TSharedPtr<SNotificationItem> item =
  81.             FSlateNotificationManager::Get().AddNotification(Info);
  82.  
  83.             /*
  84.             if (item.IsValid())
  85.             {
  86.                 item.Get()->SetOnMouseButtonDown(FPointerEventHandler::CreateLambda(notificationClicked));
  87.             }
  88.  
  89.             // we force the notification window to the foreground
  90.             TArray<TSharedRef<SWindow>> windows;
  91.             FSlateNotificationManager::Get().GetWindows(windows);
  92.  
  93.             int32 num = windows.Num();
  94.             for (int32 i = 0; i < num; ++i)
  95.             {
  96.                 FSlateNotificationManager::Get().ForceNotificationsInFront(windows[i]);
  97.  
  98.                 SWindow& win = windows[i].Get();
  99.                 win.Restore();
  100.                 win.ShowWindow();
  101.                 win.BringToFront(true);
  102.  
  103.                 win.HACK_ForceToFront();
  104.             }*/
  105.         }
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement