66#include " Components/CanvasPanelSlot.h"
77
88UBH_BackgroundService::UBH_BackgroundService ()
9- : Settings(nullptr ), GameRecorder(nullptr ), InputComponent( nullptr )
9+ : Settings(nullptr ), GameRecorder(nullptr )
1010{
11- static ConstructorHelpers::FClassFinder<UUserWidget> WidgetClassFinder (TEXT (" /BetaHubBugReporter/BugReportForm" ));
12- if (WidgetClassFinder.Succeeded ())
13- {
14- ReportFormWidgetClass = WidgetClassFinder.Class ;
15- }
16- else
17- {
18- UE_LOG (LogTemp, Error, TEXT (" Failed to find widget class at specified path." ));
19- }
11+ Settings = GetMutableDefault<UBH_PluginSettings>();
12+ ReportFormWidgetClass = Settings->ReportFormWidgetClass ;
2013}
2114
2215void UBH_BackgroundService::StartService ()
2316{
24- Settings = GetMutableDefault<UBH_PluginSettings>();
2517 GameRecorder = NewObject<UBH_GameRecorder>(this );
2618 LogCapture = new UBH_LogCapture ();
2719
@@ -51,9 +43,9 @@ void UBH_BackgroundService::RetryInitializeService()
5143{
5244 UE_LOG (LogTemp, Warning, TEXT (" Retrying to initialize service." ));
5345
54- if (GEngine-> GameViewport -> GetWorld ())
46+ if (GetWorld ())
5547 {
56- if (GEngine && GEngine->GameViewport )
48+ if (GEngine && GEngine->GameViewport && GEngine-> GameViewport -> Viewport )
5749 {
5850 // Viewport is now available, clear the timer and initialize the service
5951 GetWorld ()->GetTimerManager ().ClearTimer (TimerHandle);
@@ -72,68 +64,12 @@ void UBH_BackgroundService::RetryInitializeService()
7264void UBH_BackgroundService::InitializeService ()
7365{
7466 GameRecorder->StartRecording (Settings->MaxRecordedFrames , Settings->MaxRecordingDuration );
75-
76- if (Settings && Settings->bEnableShortcut )
77- {
78- UE_LOG (LogTemp, Log, TEXT (" Shortcut is enabled." ));
79-
80- if (GEngine && GEngine->GameViewport )
81- {
82- UWorld* World = GEngine->GameViewport ->GetWorld ();
83- if (World)
84- {
85- APlayerController* PlayerController = World->GetFirstPlayerController ();
86- if (PlayerController)
87- {
88- InputComponent = NewObject<UInputComponent>(PlayerController);
89- InputComponent->RegisterComponent ();
90- InputComponent->BindKey (Settings->ShortcutKey , IE_Pressed, this , &UBH_BackgroundService::HandleInput);
91- PlayerController->PushInputComponent (InputComponent);
92- }
93- else
94- {
95- UE_LOG (LogTemp, Error, TEXT (" PlayerController is null." ));
96- }
97- }
98- else
99- {
100- UE_LOG (LogTemp, Error, TEXT (" World is null." ));
101-
102- }
103- }
104- else
105- {
106- UE_LOG (LogTemp, Error, TEXT (" GameViewport is null." ));
107- }
108- }
109- else
110- {
111- UE_LOG (LogTemp, Warning, TEXT (" Shortcut is disabled." ));
112- }
11367}
11468
11569void UBH_BackgroundService::StopService ()
11670{
11771 GLog->RemoveOutputDevice (LogCapture);
11872 delete LogCapture;
119-
120- if (InputComponent)
121- {
122- if (GEngine && GEngine->GameViewport )
123- {
124- UWorld* World = GEngine->GameViewport ->GetWorld ();
125- if (World)
126- {
127- APlayerController* PlayerController = World->GetFirstPlayerController ();
128- if (PlayerController)
129- {
130- PlayerController->PopInputComponent (InputComponent);
131- }
132- }
133- }
134- InputComponent->DestroyComponent ();
135- InputComponent = nullptr ;
136- }
13773
13874 if (GameRecorder)
13975 {
@@ -196,9 +132,3 @@ UBH_GameRecorder* UBH_BackgroundService::GetGameRecorder()
196132{
197133 return GameRecorder;
198134}
199-
200- void UBH_BackgroundService::HandleInput ()
201- {
202- // trigger delegate
203- OnTriggerFormKeyPressed.Broadcast ();
204- }
0 commit comments