Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
FeedbackContext.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
6#include "Containers/StringFwd.h"
7#include "Containers/UnrealString.h"
8#include "CoreGlobals.h"
9#include "CoreTypes.h"
10#include "HAL/CriticalSection.h"
11#include "HAL/PlatformCrt.h"
12#include "Internationalization/Text.h"
13#include "Misc/OutputDevice.h"
14#include "Misc/ScopeLock.h"
15#include "Misc/SlowTask.h"
16#include "Misc/SlowTaskStack.h"
17#include "Templates/SharedPointer.h"
18#include "Templates/UniquePtr.h"
19#include "Templates/UnrealTemplate.h"
20
22class SBuildProgressWidget;
23struct FSlowTask;
24
25/** A context for displaying modal warning messages. */
27 : public FOutputDevice
28{
29public:
30 virtual void Serialize(const TCHAR* V, ELogVerbosity::Type Verbosity, const FName& Category) override;
31 virtual void Serialize(const TCHAR* V, ELogVerbosity::Type Verbosity, const FName& Category, double Time) override;
32 virtual void SerializeRecord(const UE::FLogRecord& Record) override;
33
34 /** Ask the user a binary question, returning their answer */
35 virtual bool YesNof( const FText& Question );
36
37 /**
38 * Whether or not the user has canceled out of the progress dialog
39 * (i.e. the ongoing slow task or the last one that ran).
40 * The user cancel flag is reset when starting a new root slow task.
41 */
42 virtual bool ReceivedUserCancel() { return false; }
43
44 /** Public const access to the current state of the scope stack */
46 {
47 return ScopeStack;
48 }
49
50 /**** Legacy API - not deprecated as it's still in heavy use, but superceded by FScopedSlowTask ****/
51 void BeginSlowTask( const FText& Task, bool ShowProgressDialog, bool bShowCancelButton=false );
52 void UpdateProgress( int32 Numerator, int32 Denominator );
53 void StatusUpdate( int32 Numerator, int32 Denominator, const FText& StatusText );
54 void StatusForceUpdate( int32 Numerator, int32 Denominator, const FText& StatusText );
56 /**** end legacy API ****/
57
58protected:
59
60 /**
61 * Called to create a slow task
62 */
63 virtual void StartSlowTask( const FText& Task, bool bShowCancelButton=false )
64 {
65 GIsSlowTask = true;
66 }
67
68 /**
69 * Called to destroy a slow task
70 */
71 virtual void FinalizeSlowTask( )
72 {
73 GIsSlowTask = false;
74 }
75
76 /**
77 * Called when some progress has occurred
78 * @param TotalProgressInterp [0..1] Value indicating the total progress of the slow task
79 * @param DisplayMessage The message to display on the slow task
80 */
81 virtual void ProgressReported( const float TotalProgressInterp, FText DisplayMessage ) {}
82
83 /** Called to check whether we are playing in editor when starting a slow task */
84 virtual bool IsPlayingInEditor() const;
85
86 void FormatLine(FStringBuilderBase& Out, const TCHAR* V, ELogVerbosity::Type Verbosity, const FName& Category, double Time, ELogVerbosity::Type* OutVerbosity = nullptr) const;
87 void FormatRecordLine(FStringBuilderBase& Out, const UE::FLogRecord& Record, ELogVerbosity::Type* OutVerbosity = nullptr) const;
88
89public:
90 virtual FContextSupplier* GetContext() const { return nullptr; }
91 virtual void SetContext(FContextSupplier* InContext) {}
92
93 /** Shows/Closes Special Build Progress dialogs */
94 virtual TWeakPtr<class SBuildProgressWidget> ShowBuildProgressWindow() {return TWeakPtr<class SBuildProgressWidget>();}
95 virtual void CloseBuildProgressWindow() {}
96
98
101
102 /** Gets warnings history */
103 void GetWarnings(TArray<FString>& OutWarnings) const
104 {
105 FScopeLock WarningsAndErrorsLock(&WarningsAndErrorsCritical);
106 OutWarnings = Warnings;
107 }
108 int32 GetNumWarnings() const
109 {
110 return Warnings.Num();
111 }
112
113 /** Gets errors history */
114 void GetErrors(TArray<FString>& OutErrors) const
115 {
116 FScopeLock WarningsAndErrorsLock(&WarningsAndErrorsCritical);
117 OutErrors = Errors;
118 }
119 int32 GetNumErrors() const
120 {
121 return Errors.Num();
122 }
123
124 /** Gets all errors and warnings and clears the history */
125 void GetErrorsAndWarningsAndEmpty(TArray<FString>& OutWarningsAndErrors)
126 {
127 FScopeLock WarningsAndErrorsLock(&WarningsAndErrorsCritical);
128 OutWarningsAndErrors = MoveTemp(Errors);
129 OutWarningsAndErrors += MoveTemp(Warnings);
130 }
131 /** Clears all history */
133 {
134 FScopeLock WarningsAndErrorsLock(&WarningsAndErrorsCritical);
135 Errors.Empty();
136 Warnings.Empty();
137 }
138
139private:
140 void AddToHistory(const TCHAR* V, ELogVerbosity::Type Verbosity, const FName& Category, double Time);
141 void AddRecordToHistory(const UE::FLogRecord& Record);
142
145
146 /** Warnings history */
148 /** Errors history */
150 /** Guard for the errors and warnings history */
152
153protected:
154
155 friend FSlowTask;
156
157 /** Stack of pointers to feedback scopes that are currently open */
159
160 /**
161 * Points to the ScopeStack above when initialized - this is because Slate wants a TSharedPtr,
162 * but we don't want to allocate
163 */
165
167 {
168 if (!ScopeStackSharedPtr)
169 {
170 ScopeStackSharedPtr = MakeShareable(const_cast<FSlowTaskStack*>(&ScopeStack), [](FSlowTaskStack*){});
171 }
172 return ScopeStackSharedPtr;
173 }
174
176
177 /** Ask that the UI be updated as a result of the scope stack changing */
178 void RequestUpdateUI(bool bForceUpdate = false);
179
180 /** Update the UI as a result of the scope stack changing */
181 void UpdateUI();
182
183 /**
184 * Adds a new warning message to warnings history.
185 * @param InWarning Warning message
186 */
187 void AddWarning(const FString& InWarning)
188 {
189 FScopeLock WarningsAndErrorsLock(&WarningsAndErrorsCritical);
190 Warnings.Add(InWarning);
191 }
192 void AddWarning(FString&& InWarning)
193 {
194 FScopeLock WarningsAndErrorsLock(&WarningsAndErrorsCritical);
195 Warnings.Add(MoveTemp(InWarning));
196 }
197
198 /**
199 * Adds a new error message to errors history.
200 * @param InWarning Error message
201 */
202 void AddError(const FString& InError)
203 {
204 FScopeLock WarningsAndErrorsLock(&WarningsAndErrorsCritical);
205 Errors.Add(InError);
206 }
207 void AddError(FString&& InError)
208 {
209 FScopeLock WarningsAndErrorsLock(&WarningsAndErrorsCritical);
210 Errors.Add(MoveTemp(InError));
211 }
212};
bool GIsSlowTask
#define FORCEINLINE
Definition Platform.h:644
FWindowsCriticalSection FCriticalSection
void AddToHistory(const TCHAR *V, ELogVerbosity::Type Verbosity, const FName &Category, double Time)
virtual void SetContext(FContextSupplier *InContext)
virtual void SerializeRecord(const UE::FLogRecord &Record) override
FCriticalSection WarningsAndErrorsCritical
virtual FContextSupplier * GetContext() const
FSlowTaskStack ScopeStack
virtual void Serialize(const TCHAR *V, ELogVerbosity::Type Verbosity, const FName &Category) override
virtual void FinalizeSlowTask()
FORCEINLINE const FSlowTaskStack & GetScopeStack() const
virtual ~FFeedbackContext()
virtual bool ReceivedUserCancel()
void AddRecordToHistory(const UE::FLogRecord &Record)
virtual bool IsPlayingInEditor() const
virtual void CloseBuildProgressWindow()
TSharedPtr< FSlowTaskStack > ScopeStackSharedPtr
virtual bool YesNof(const FText &Question)
FFeedbackContext(const FFeedbackContext &)
void FormatLine(FStringBuilderBase &Out, const TCHAR *V, ELogVerbosity::Type Verbosity, const FName &Category, double Time, ELogVerbosity::Type *OutVerbosity=nullptr) const
void UpdateProgress(int32 Numerator, int32 Denominator)
const TSharedPtr< FSlowTaskStack > & GetScopeStackSharedPtr() const
void StatusUpdate(int32 Numerator, int32 Denominator, const FText &StatusText)
void GetErrorsAndWarningsAndEmpty(TArray< FString > &OutWarningsAndErrors)
void GetErrors(TArray< FString > &OutErrors) const
void GetWarnings(TArray< FString > &OutWarnings) const
void AddError(const FString &InError)
virtual void StartSlowTask(const FText &Task, bool bShowCancelButton=false)
TArray< FString > Warnings
void RequestUpdateUI(bool bForceUpdate=false)
FFeedbackContext & operator=(const FFeedbackContext &)
void BeginSlowTask(const FText &Task, bool ShowProgressDialog, bool bShowCancelButton=false)
void AddWarning(const FString &InWarning)
void FormatRecordLine(FStringBuilderBase &Out, const UE::FLogRecord &Record, ELogVerbosity::Type *OutVerbosity=nullptr) const
TArray< FString > Errors
virtual void ProgressReported(const float TotalProgressInterp, FText DisplayMessage)
void AddError(FString &&InError)
void AddWarning(FString &&InWarning)
virtual TWeakPtr< class SBuildProgressWidget > ShowBuildProgressWindow()
virtual void Serialize(const TCHAR *V, ELogVerbosity::Type Verbosity, const FName &Category, double Time) override
int32 GetNumWarnings() const
TArray< TUniquePtr< FSlowTask > > LegacyAPIScopes
void StatusForceUpdate(int32 Numerator, int32 Denominator, const FText &StatusText)
int32 GetNumErrors() const
UE_NODISCARD_CTOR FScopeLock(FCriticalSection *InSynchObject)
Definition ScopeLock.h:35
Definition Text.h:357
Definition Vector.h:40