Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Human-readable game "Timestamp". #1226

Merged
merged 2 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<local:BooleanToVisibilityConverter x:Key="BooleanFalseToVisibilityConverter" local:trueValue="Collapsed" local:falseValue="Visible"/>
<local:ByteArrayConverter x:Key="byteArrayConverter"/>
<local:ByteGUIDArrayConverter x:Key="byteGUIDArrayConverter"/>
<local:TimestampDateTimeConverter x:Key="TimestampDateTimeConverter"/>
</UserControl.Resources>

<StackPanel>
Expand Down Expand Up @@ -125,7 +126,19 @@
<TextBox Grid.Row="14" Grid.Column="1" Margin="3" Text="{Binding GeneralInfo.LicenseCRC32, StringFormat={}{0:X8}}"/>

<TextBlock Grid.Row="15" Grid.Column="0" Margin="3">Timestamp</TextBlock>
<TextBox Grid.Row="15" Grid.Column="1" Margin="3" Text="{Binding GeneralInfo.Timestamp}"/>
<TextBox Grid.Row="15" Grid.Column="1" Margin="3" IsReadOnly="True"
Text="{Binding GeneralInfo.Timestamp, Mode=OneWay, Converter={StaticResource TimestampDateTimeConverter}}"
ToolTip="{Binding GeneralInfo.Timestamp, Mode=OneWay, Converter={StaticResource TimestampDateTimeConverter}, ConverterParameter=GMT}"
ToolTipService.InitialShowDelay="250">
<TextBox.Background>
<VisualBrush AlignmentX="Right" AlignmentY="Center" Stretch="None">
<VisualBrush.Visual>
<Label Content="(local time, hover to see GMT+0)"
Foreground="Gray" FontStyle="Italic" Margin="0,0,5,0"/>
</VisualBrush.Visual>
</VisualBrush>
</TextBox.Background>
</TextBox>

<TextBlock Grid.Row="16" Grid.Column="0" Margin="3">Display name</TextBlock>
<local:UndertaleStringReference Grid.Row="16" Grid.Column="1" Margin="3" ObjectReference="{Binding GeneralInfo.DisplayName}"/>
Expand Down
25 changes: 25 additions & 0 deletions UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -36,4 +37,28 @@ private void SyncRoomList_Click(object sender, RoutedEventArgs e)
roomOrder.Add(new UndertaleResourceById<UndertaleRoom, UndertaleChunkROOM>() { Resource = room });
}
}

public class TimestampDateTimeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is not ulong timestamp)
return "(error)";
DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeSeconds((long)timestamp);
if (parameter is string par && par == "GMT")
return "GMT+0: " + dateTimeOffset.UtcDateTime.ToString();
else
return dateTimeOffset.LocalDateTime.ToString();
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is not string dateTimeStr)
return new ValidationResult(false, "The value is not a string.");
if (!DateTime.TryParse(dateTimeStr, out DateTime dateTime))
return new ValidationResult(false, "Invalid date time format.");

return (ulong)(new DateTimeOffset(dateTime).ToUnixTimeSeconds());
}
}
}