SExtBuildProgress.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. // Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
  2. #include "SExtBuildProgress.h"
  3. #include "Widgets/SBoxPanel.h"
  4. #include "Widgets/Notifications/SProgressBar.h"
  5. #include "Widgets/Text/STextBlock.h"
  6. #include "Widgets/Input/SButton.h"
  7. #include "EditorStyleSet.h"
  8. #include "UnrealEdMisc.h"
  9. SBuildProgressWidget::SBuildProgressWidget()
  10. {
  11. }
  12. SBuildProgressWidget::~SBuildProgressWidget()
  13. {
  14. }
  15. SExtBuildProgressWidget::SExtBuildProgressWidget()
  16. {
  17. }
  18. SExtBuildProgressWidget::~SExtBuildProgressWidget()
  19. {
  20. }
  21. void SExtBuildProgressWidget::Construct( const FArguments& InArgs )
  22. {
  23. ChildSlot
  24. [
  25. SNew(SBorder)
  26. .BorderImage(FAppStyle::Get().GetBrush("Brushes.Header"))
  27. .Padding(0.0f)
  28. [
  29. SNew(SVerticalBox)
  30. + SVerticalBox::Slot()
  31. .VAlign(VAlign_Top)
  32. .AutoHeight()
  33. .Padding(10.0f, 10.0f, 10.0f, 2.0f)
  34. [
  35. SNew(STextBlock)
  36. .Text(NSLOCTEXT("BuildProgress", "BuildStatusLabel", "Build Status"))
  37. .Font(FAppStyle::Get().GetFontStyle("HeadingExtraSmall"))
  38. .ColorAndOpacity(FAppStyle::Get().GetSlateColor("Colors.White"))
  39. ]
  40. + SVerticalBox::Slot()
  41. .VAlign(VAlign_Top)
  42. .Padding(10.0f, 2.0f)
  43. [
  44. SNew(SHorizontalBox)
  45. + SHorizontalBox::Slot()
  46. .AutoWidth()
  47. [
  48. SNew(STextBlock)
  49. .Text(this, &SExtBuildProgressWidget::OnGetBuildTimeText)
  50. ]
  51. + SHorizontalBox::Slot()
  52. .AutoWidth()
  53. .Padding(10.0f, 0, 10.0f, 7.0f)
  54. [
  55. SNew(STextBlock)
  56. .Text(this, &SExtBuildProgressWidget::OnGetProgressText)
  57. ]
  58. ]
  59. + SVerticalBox::Slot()
  60. .HAlign(HAlign_Fill)
  61. .VAlign(VAlign_Center)
  62. .AutoHeight()
  63. .Padding(10.0f, 1.0f)
  64. [
  65. SNew(STextBlock)
  66. .Text(NSLOCTEXT("BuildProgress", "BuildProgressLabel", "Build Progress"))
  67. ]
  68. + SVerticalBox::Slot()
  69. .HAlign(HAlign_Fill)
  70. .VAlign(VAlign_Center)
  71. .AutoHeight()
  72. .Padding(10.0f, 7.0f, 10.0f, 7.0f)
  73. [
  74. SNew(SProgressBar)
  75. .Percent(this, &SExtBuildProgressWidget::OnGetProgressFraction)
  76. ]
  77. + SVerticalBox::Slot()
  78. .Padding(15.0f, 10.0f)
  79. .HAlign(HAlign_Right)
  80. .VAlign(VAlign_Bottom)
  81. [
  82. SNew(SButton)
  83. .TextStyle(FAppStyle::Get(), "DialogButtonText")
  84. .Text(NSLOCTEXT("BuildProgress", "StopBuildButtonLabel", "Stop Build"))
  85. .OnClicked(this, &SExtBuildProgressWidget::OnStopBuild)
  86. ]
  87. ]
  88. ];
  89. // Reset progress indicators
  90. BuildStartTime = -1;
  91. bStoppingBuild = false;
  92. SetBuildStatusText( FText::GetEmpty() );
  93. SetBuildProgressPercent( 0, 100 );
  94. }
  95. FText SExtBuildProgressWidget::OnGetProgressText() const
  96. {
  97. return ProgressStatusText;
  98. }
  99. void SExtBuildProgressWidget::UpdateProgressText()
  100. {
  101. if( ProgressNumerator > 0 && ProgressDenominator > 0 )
  102. {
  103. FFormatNamedArguments Args;
  104. Args.Add( TEXT("StatusText"), BuildStatusText );
  105. Args.Add( TEXT("ProgressCompletePercentage"), FText::AsPercent( (float)ProgressNumerator/ProgressDenominator) );
  106. ProgressStatusText = FText::Format( NSLOCTEXT("BuildProgress", "ProgressStatusFormat", "{StatusText} ({ProgressCompletePercentage})"), Args );
  107. }
  108. else
  109. {
  110. ProgressStatusText = BuildStatusText;
  111. }
  112. }
  113. FText SExtBuildProgressWidget::OnGetBuildTimeText() const
  114. {
  115. // Only show a percentage if there is something interesting to report
  116. return BuildStatusTime;
  117. }
  118. TOptional<float> SExtBuildProgressWidget::OnGetProgressFraction() const
  119. {
  120. // Only show a percentage if there is something interesting to report
  121. if( ProgressNumerator > 0 && ProgressDenominator > 0 )
  122. {
  123. return (float)ProgressNumerator/ProgressDenominator;
  124. }
  125. else
  126. {
  127. // Return non-value to indicate marquee mode
  128. // for the progress bar.
  129. return TOptional<float>();
  130. }
  131. }
  132. void SExtBuildProgressWidget::SetBuildType(EBuildType InBuildType)
  133. {
  134. BuildType = InBuildType;
  135. }
  136. FText SExtBuildProgressWidget::BuildElapsedTimeText() const
  137. {
  138. // Display elapsed build time.
  139. return FText::AsTimespan( FDateTime::Now() - BuildStartTime );
  140. }
  141. void SExtBuildProgressWidget::UpdateTime()
  142. {
  143. BuildStatusTime = BuildElapsedTimeText();
  144. }
  145. void SExtBuildProgressWidget::SetBuildStatusText( const FText& StatusText )
  146. {
  147. UpdateTime();
  148. // Only update the text if we haven't canceled the build.
  149. if( !bStoppingBuild )
  150. {
  151. BuildStatusText = StatusText;
  152. UpdateProgressText();
  153. }
  154. }
  155. void SExtBuildProgressWidget::SetBuildProgressPercent( int32 InProgressNumerator, int32 InProgressDenominator )
  156. {
  157. UpdateTime();
  158. // Only update the progress bar if we haven't canceled the build.
  159. if( !bStoppingBuild )
  160. {
  161. ProgressNumerator = InProgressNumerator;
  162. ProgressDenominator = InProgressDenominator;
  163. UpdateProgressText();
  164. }
  165. }
  166. void SExtBuildProgressWidget::MarkBuildStartTime()
  167. {
  168. BuildStartTime = FDateTime::Now();
  169. }
  170. FReply SExtBuildProgressWidget::OnStopBuild()
  171. {
  172. FUnrealEdMisc::Get().SetMapBuildCancelled( true );
  173. SetBuildStatusText( NSLOCTEXT("UnrealEd", "StoppingMapBuild", "Stopping Map Build...") );
  174. bStoppingBuild = true;
  175. return FReply::Handled();
  176. }