2014-03-14 14:13:41 -04:00
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
# include "TaskBrowserPrivatePCH.h"
# include "STaskComplete.h"
# include "STaskBrowser.h"
# define LOCTEXT_NAMESPACE "STaskComplete"
//////////////////////////////////////////////////////////////////////////
// STaskComplete
/**
* Construct the widget
*
* @ param InArgs A declaration from which to construct the widget
*/
void STaskComplete : : Construct ( const FArguments & InArgs )
{
WidgetWindow = InArgs . _WidgetWindow ;
ResolutionData = InArgs . _ResolutionData ;
// HACK Convert our const array to a slate usable local type, and set the default selection if it's available
TSharedPtr < FString > ResolutionSelection = NULL ;
const FString DefaultResolution ( TEXT ( " Code/Content Change " ) ) ; // Not localized, intentionally
for ( int32 iResolution = 0 ; iResolution < InArgs . _ResolutionValues - > Num ( ) ; iResolution + + )
{
2014-03-15 01:14:25 -04:00
const FString & ResolutionValue = ( * InArgs . _ResolutionValues ) [ iResolution ] ;
TSharedPtr < FString > ResolutionOption = MakeShareable ( new FString ( ResolutionValue ) ) ;
if ( ResolutionValue = = DefaultResolution )
2014-03-14 14:13:41 -04:00
{
ResolutionSelection = ResolutionOption ;
}
ResolutionOptions . Add ( ResolutionOption ) ;
}
// Standard paddings
const FMargin ButtonPadding ( 8 , 4 ) ; // Padding around the button text
const FMargin SmallPadding ( 0 , 0 , 12 , 0 ) ; // Padding to the right of the field's text
const FMargin TopPadding ( 0 , 20 , 0 , 5 ) ;
const FMargin NormalPadding ( 0 , 0 , 0 , 5 ) ;
const FMargin BottomPadding ( 0 , 20 , 0 , 0 ) ;
this - > ChildSlot
[
SNew ( SBorder )
. BorderImage ( FEditorStyle : : GetBrush ( " ToolPanel.GroupBorder " ) )
[
SNew ( SVerticalBox )
+ SVerticalBox : : Slot ( )
. FillHeight ( 1.0f )
[
SNew ( SVerticalBox )
+ SVerticalBox : : Slot ( )
. AutoHeight ( )
. Padding ( TopPadding )
[
SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
. HAlign ( HAlign_Right )
. VAlign ( VAlign_Center )
. Padding ( SmallPadding )
. FillWidth ( 0.18f )
[
2014-04-23 18:06:41 -04:00
SNew ( STextBlock ) . Text ( LOCTEXT ( " Resolution " , " Resolution " ) )
2014-03-14 14:13:41 -04:00
]
+ SHorizontalBox : : Slot ( )
. FillWidth ( 0.33f )
[
SAssignNew ( Resolution , STextComboBox )
. OptionsSource ( & ResolutionOptions )
]
+ SHorizontalBox : : Slot ( ) // Dummy box
. FillWidth ( 0.49f )
]
+ SVerticalBox : : Slot ( )
. Padding ( NormalPadding )
. FillHeight ( 1.0f )
[
SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
. HAlign ( HAlign_Right )
. VAlign ( VAlign_Top )
. Padding ( SmallPadding )
. FillWidth ( 0.18f )
[
2014-04-23 18:06:41 -04:00
SNew ( STextBlock ) . Text ( LOCTEXT ( " Comments " , " Comments " ) )
2014-03-14 14:13:41 -04:00
]
+ SHorizontalBox : : Slot ( )
. FillWidth ( 0.82f )
[
SAssignNew ( Comments , SEditableTextBox )
]
]
+ SVerticalBox : : Slot ( )
. AutoHeight ( )
. Padding ( NormalPadding )
[
SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
. HAlign ( HAlign_Right )
. VAlign ( VAlign_Center )
. Padding ( SmallPadding )
. FillWidth ( 0.184f )
[
2014-04-23 18:06:41 -04:00
SNew ( STextBlock ) . Text ( LOCTEXT ( " Changelist " , " Changelist " ) )
2014-03-14 14:13:41 -04:00
]
+ SHorizontalBox : : Slot ( )
. FillWidth ( 0.17f )
[
SAssignNew ( Changelist , SEditableTextBox )
]
+ SHorizontalBox : : Slot ( )
. HAlign ( HAlign_Right )
. VAlign ( VAlign_Center )
. Padding ( SmallPadding )
. FillWidth ( 0.408f )
[
2014-04-23 18:06:41 -04:00
SNew ( STextBlock ) . Text ( LOCTEXT ( " TimeToComplete " , " Time to complete (hours) " ) )
2014-03-14 14:13:41 -04:00
]
+ SHorizontalBox : : Slot ( )
. FillWidth ( 0.08f )
[
SAssignNew ( Time , SEditableTextBox )
]
+ SHorizontalBox : : Slot ( ) // Dummy box
. FillWidth ( 0.158f )
]
+ SVerticalBox : : Slot ( )
. AutoHeight ( )
. HAlign ( HAlign_Right )
. VAlign ( VAlign_Bottom )
[
SNew ( SUniformGridPanel )
. SlotPadding ( FEditorStyle : : GetMargin ( " StandardDialog.SlotPadding " ) )
. MinDesiredSlotWidth ( FEditorStyle : : GetFloat ( " StandardDialog.MinDesiredSlotWidth " ) )
. MinDesiredSlotHeight ( FEditorStyle : : GetFloat ( " StandardDialog.MinDesiredSlotHeight " ) )
+ SUniformGridPanel : : Slot ( 0 , 0 )
[
SAssignNew ( OK , SButton )
. ContentPadding ( FEditorStyle : : GetMargin ( " StandardDialog.ContentPadding " ) )
. HAlign ( HAlign_Center )
. OnClicked ( this , & STaskComplete : : OnOKClicked )
[
2014-04-23 18:06:41 -04:00
SNew ( STextBlock ) . Text ( LOCTEXT ( " OK " , " OK " ) )
2014-03-14 14:13:41 -04:00
]
]
+ SUniformGridPanel : : Slot ( 1 , 0 )
[
SAssignNew ( Cancel , SButton )
. ContentPadding ( FEditorStyle : : GetMargin ( " StandardDialog.ContentPadding " ) )
. HAlign ( HAlign_Center )
. OnClicked ( this , & STaskComplete : : OnCancelClicked )
[
2014-04-23 18:06:41 -04:00
SNew ( STextBlock ) . Text ( LOCTEXT ( " Cancel " , " Cancel " ) )
2014-03-14 14:13:41 -04:00
]
]
]
]
]
] ;
// If we found our preferred selection choice, pick it
if ( ResolutionSelection . IsValid ( ) )
{
Resolution - > SetSelectedItem ( ResolutionSelection ) ;
}
}
FReply STaskComplete : : OnOKClicked ( )
{
// Make sure the user entered something for each
TSharedPtr < FString > ResolutionSelection = Resolution - > GetSelectedItem ( ) ;
if ( ( ! ResolutionSelection . IsValid ( ) | | ResolutionSelection - > Len ( ) = = 0 ) | |
( Comments - > GetText ( ) . IsEmpty ( ) ) | |
( Changelist - > GetText ( ) . IsNumeric ( ) = = false ) | |
( Time - > GetText ( ) . IsNumeric ( ) = = false ) )
{
// At least one field is empty, so notify the user and veto the OK button event
FMessageDialog : : Open ( EAppMsgType : : Ok , NSLOCTEXT ( " UnrealEd " , " TaskBrowser_Error_NeedValidDataToMarkComplete " , " Sorry, the task cannot be marked as complete until you've entered valid information for all of the fields. Please complete the form before pressing the OK button. " ) ) ;
}
else
{
// Store data from controls
ResolutionData - > ResolutionType = * ResolutionSelection . Get ( ) ;
ResolutionData - > Comments = Comments - > GetText ( ) . ToString ( ) ;
ResolutionData - > ChangelistNumber = FCString : : Atoi ( * Changelist - > GetText ( ) . ToString ( ) ) ;
ResolutionData - > HoursToComplete = static_cast < double > ( FCString : : Atof ( * Time - > GetText ( ) . ToString ( ) ) ) ;
// Close the window
if ( WidgetWindow . IsValid ( ) )
{
WidgetWindow . Pin ( ) - > RequestDestroyWindow ( ) ;
}
}
return FReply : : Handled ( ) ;
}
FReply STaskComplete : : OnCancelClicked ( )
{
// Close the window
if ( WidgetWindow . IsValid ( ) )
{
WidgetWindow . Pin ( ) - > RequestDestroyWindow ( ) ;
}
return FReply : : Handled ( ) ;
}
# undef LOCTEXT_NAMESPACE