2016-12-08 08:52:44 -05:00
|
|
|
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
|
2014-09-02 19:28:15 -04:00
|
|
|
|
|
|
|
|
#include "DateTimeStructCustomization.h"
|
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340)
#lockdown Nick.Penwarden
#rb none
==========================
MAJOR FEATURES + CHANGES
==========================
Change 3209340 on 2016/11/23 by Ben.Marsh
Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h.
Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms.
* Every header now includes everything it needs to compile.
* There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first.
* There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h.
* Every .cpp file includes its matching .h file first.
* This helps validate that each header is including everything it needs to compile.
* No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more.
* You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there.
* There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible.
* No engine code explicitly includes a precompiled header any more.
* We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies.
* PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files.
Tool used to generate this transform is at Engine\Source\Programs\IncludeTool.
[CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
|
|
|
#include "Widgets/DeclarativeSyntaxSupport.h"
|
|
|
|
|
#include "Engine/GameViewportClient.h"
|
|
|
|
|
#include "PropertyHandle.h"
|
|
|
|
|
#include "Widgets/Input/SEditableTextBox.h"
|
|
|
|
|
#include "DetailWidgetRow.h"
|
2016-09-21 18:16:12 -04:00
|
|
|
#include "InternationalizationSettingsModel.h"
|
2014-09-02 19:28:15 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#define LOCTEXT_NAMESPACE "DateTimeStructCustomization"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* IDetailCustomization interface
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void FDateTimeStructCustomization::CustomizeChildren( TSharedRef<IPropertyHandle> StructPropertyHandle, class IDetailChildrenBuilder& StructBuilder, IPropertyTypeCustomizationUtils& StructCustomizationUtils )
|
|
|
|
|
{
|
|
|
|
|
/* do nothing */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FDateTimeStructCustomization::CustomizeHeader( TSharedRef<IPropertyHandle> StructPropertyHandle, class FDetailWidgetRow& HeaderRow, IPropertyTypeCustomizationUtils& StructCustomizationUtils )
|
|
|
|
|
{
|
|
|
|
|
PropertyHandle = StructPropertyHandle;
|
|
|
|
|
|
|
|
|
|
HeaderRow
|
|
|
|
|
.NameContent()
|
|
|
|
|
[
|
|
|
|
|
StructPropertyHandle->CreatePropertyNameWidget()
|
|
|
|
|
]
|
|
|
|
|
.ValueContent()
|
|
|
|
|
.MaxDesiredWidth(0.0f)
|
|
|
|
|
.MinDesiredWidth(125.0f)
|
|
|
|
|
[
|
|
|
|
|
SNew(SEditableTextBox)
|
|
|
|
|
.ClearKeyboardFocusOnCommit(false)
|
|
|
|
|
.IsEnabled(!PropertyHandle->IsEditConst())
|
|
|
|
|
.ForegroundColor(this, &FDateTimeStructCustomization::HandleTextBoxForegroundColor)
|
|
|
|
|
.OnTextChanged(this, &FDateTimeStructCustomization::HandleTextBoxTextChanged)
|
|
|
|
|
.OnTextCommitted(this, &FDateTimeStructCustomization::HandleTextBoxTextCommited)
|
|
|
|
|
.SelectAllTextOnCommit(true)
|
|
|
|
|
.Text(this, &FDateTimeStructCustomization::HandleTextBoxText)
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 18:16:12 -04:00
|
|
|
FDateTimeStructCustomization::FDateTimeStructCustomization()
|
|
|
|
|
: InputValid(true)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-09-02 19:28:15 -04:00
|
|
|
|
|
|
|
|
/* FDateTimeStructCustomization callbacks
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
FSlateColor FDateTimeStructCustomization::HandleTextBoxForegroundColor( ) const
|
|
|
|
|
{
|
|
|
|
|
if (InputValid)
|
|
|
|
|
{
|
2014-11-18 09:57:20 -05:00
|
|
|
static const FName InvertedForegroundName("InvertedForeground");
|
|
|
|
|
return FEditorStyle::GetSlateColor(InvertedForegroundName);
|
2014-09-02 19:28:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FLinearColor::Red;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FText FDateTimeStructCustomization::HandleTextBoxText( ) const
|
|
|
|
|
{
|
|
|
|
|
TArray<void*> RawData;
|
|
|
|
|
PropertyHandle->AccessRawData(RawData);
|
2016-09-21 18:16:12 -04:00
|
|
|
|
2014-09-02 19:28:15 -04:00
|
|
|
if (RawData.Num() != 1)
|
|
|
|
|
{
|
|
|
|
|
return LOCTEXT("MultipleValues", "Multiple Values");
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-11 18:17:51 -04:00
|
|
|
auto DateTimePtr = static_cast<FDateTime*>(RawData[0]);
|
|
|
|
|
if (!DateTimePtr)
|
|
|
|
|
{
|
|
|
|
|
return FText::GetEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 18:16:12 -04:00
|
|
|
return FText::FromString(ToDateTimeZoneString(*DateTimePtr));
|
2014-09-02 19:28:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FDateTimeStructCustomization::HandleTextBoxTextChanged( const FText& NewText )
|
|
|
|
|
{
|
|
|
|
|
FDateTime DateTime;
|
2016-09-21 18:16:12 -04:00
|
|
|
InputValid = ParseDateTimeZone(NewText.ToString(), DateTime);
|
2014-09-02 19:28:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FDateTimeStructCustomization::HandleTextBoxTextCommited( const FText& NewText, ETextCommit::Type CommitInfo )
|
|
|
|
|
{
|
|
|
|
|
FDateTime ParsedDateTime;
|
2016-09-21 18:16:12 -04:00
|
|
|
|
|
|
|
|
InputValid = ParseDateTimeZone(NewText.ToString(), ParsedDateTime);
|
2014-12-03 06:31:35 -05:00
|
|
|
if (InputValid && PropertyHandle.IsValid())
|
2014-09-02 19:28:15 -04:00
|
|
|
{
|
|
|
|
|
TArray<void*> RawData;
|
|
|
|
|
PropertyHandle->AccessRawData(RawData);
|
|
|
|
|
|
2014-12-03 06:31:35 -05:00
|
|
|
PropertyHandle->NotifyPreChange();
|
2014-09-02 19:28:15 -04:00
|
|
|
for (auto RawDataInstance : RawData)
|
|
|
|
|
{
|
|
|
|
|
*(FDateTime*)RawDataInstance = ParsedDateTime;
|
|
|
|
|
}
|
2014-12-03 06:31:35 -05:00
|
|
|
PropertyHandle->NotifyPostChange();
|
2015-07-31 08:28:58 -04:00
|
|
|
PropertyHandle->NotifyFinishedChangingProperties();
|
2014-09-02 19:28:15 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-09-21 18:16:12 -04:00
|
|
|
int32 FDateTimeStructCustomization::GetLocalTimezone()
|
|
|
|
|
{
|
|
|
|
|
const UInternationalizationSettingsModel* const InternationalizationSettingsModel = GetDefault<UInternationalizationSettingsModel>();
|
|
|
|
|
if (!InternationalizationSettingsModel)
|
|
|
|
|
{
|
|
|
|
|
return TIMEZONE_UTC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return InternationalizationSettingsModel->GetTimezoneValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool FDateTimeStructCustomization::ParseDateTimeZone(const FString& DateTimeZoneString, FDateTime& OutDateTime)
|
|
|
|
|
{
|
|
|
|
|
static FString Delimiter = FString(TEXT(" "));
|
|
|
|
|
|
|
|
|
|
// Split our DatetimeZone string into a date and a timezone marker
|
|
|
|
|
FString DateString;
|
|
|
|
|
FString TimezoneString;
|
|
|
|
|
if (!DateTimeZoneString.Split(Delimiter, &DateString, &TimezoneString, ESearchCase::CaseSensitive, ESearchDir::FromEnd))
|
|
|
|
|
{
|
|
|
|
|
DateString = DateTimeZoneString;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Trim surrounding whitespace
|
|
|
|
|
DateString = DateString.TrimTrailing().Trim();
|
|
|
|
|
TimezoneString = TimezoneString.TrimTrailing().Trim();
|
|
|
|
|
|
|
|
|
|
// Validate date
|
|
|
|
|
FDateTime LocalizedDate;
|
|
|
|
|
if (DateString.IsEmpty() || !FDateTime::Parse(DateString, LocalizedDate))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Validate timezone marker
|
|
|
|
|
if (TimezoneString.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
// If no timezone is present, we assume the user's preferred timezone
|
|
|
|
|
OutDateTime = ConvertTime(LocalizedDate, GetLocalTimezone(), TIMEZONE_UTC);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fail if timezone string isn't numeric
|
|
|
|
|
if (!TimezoneString.IsNumeric())
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convert timezone into int
|
|
|
|
|
int32 Timezone = FCString::Atoi(*TimezoneString);
|
|
|
|
|
Timezone = ConvertShortTimezone(Timezone);
|
|
|
|
|
|
|
|
|
|
// Check for timezones in the full-format HHMM, ex: -0500, +1345, etc
|
|
|
|
|
const int32 TimezoneHour = Timezone / 100;
|
|
|
|
|
const bool bHasValidMinuteOffset = ((FMath::Abs(Timezone) % 100) % 15 == 0);
|
|
|
|
|
const bool bIsTimezoneHourValid = (TimezoneHour >= -12 && TimezoneHour <= 14);
|
|
|
|
|
if (bHasValidMinuteOffset && bIsTimezoneHourValid)
|
|
|
|
|
{
|
|
|
|
|
OutDateTime = ConvertTime(LocalizedDate, Timezone, TIMEZONE_UTC);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Not a valid time
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FDateTime FDateTimeStructCustomization::ConvertTime(const FDateTime& InDate, int32 InTimezone, int32 OutTimezone)
|
|
|
|
|
{
|
|
|
|
|
if (InTimezone == OutTimezone)
|
|
|
|
|
{
|
|
|
|
|
return InDate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Timezone Hour ranges go from -12 to +14 from UTC
|
|
|
|
|
// Convert from whole-hour to the full-format HHMM (-5 -> -0500, 0 -> +0000, etc)
|
|
|
|
|
InTimezone = ConvertShortTimezone(InTimezone);
|
|
|
|
|
OutTimezone = ConvertShortTimezone(OutTimezone);
|
|
|
|
|
|
|
|
|
|
// Extract timezone minutes
|
|
|
|
|
const int32 InTimezoneMinutes = (FMath::Abs(InTimezone) % 100);
|
|
|
|
|
const int32 OutTimezoneMinutes = (FMath::Abs(OutTimezone) % 100);
|
|
|
|
|
|
|
|
|
|
// Calculate our Minutes difference
|
|
|
|
|
const int32 MinutesDifference = OutTimezoneMinutes - InTimezoneMinutes;
|
|
|
|
|
|
|
|
|
|
// Calculate our Hours difference
|
|
|
|
|
const int64 HoursDifference = (OutTimezone / 100) - (InTimezone / 100);
|
|
|
|
|
|
|
|
|
|
return FDateTime(InDate + FTimespan(HoursDifference, MinutesDifference, 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FString FDateTimeStructCustomization::ToDateTimeZoneString(const FDateTime& UTCDate)
|
|
|
|
|
{
|
|
|
|
|
const int32 DisplayTimezone = GetLocalTimezone();
|
|
|
|
|
const FDateTime LocalTime = ConvertTime(UTCDate, TIMEZONE_UTC, DisplayTimezone);
|
|
|
|
|
return FString::Printf(TEXT("%s %s%0.4d"), *LocalTime.ToString(), (DisplayTimezone >= 0 ? TEXT("+") : TEXT("")), DisplayTimezone);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int32 FDateTimeStructCustomization::ConvertShortTimezone(int32 ShortTimezone)
|
|
|
|
|
{
|
|
|
|
|
// Convert timezones from short-format into long format, -5 -> -0500
|
|
|
|
|
// Timezone Hour ranges go from -12 to +14 from UTC
|
|
|
|
|
if (ShortTimezone >= -12 && ShortTimezone <= 14)
|
|
|
|
|
{
|
|
|
|
|
return ShortTimezone * 100;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Not a short-form timezone
|
|
|
|
|
return ShortTimezone;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-02 19:28:15 -04:00
|
|
|
#undef LOCTEXT_NAMESPACE
|