Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
qhy040404 committed Nov 25, 2024
1 parent de9dec9 commit 3922a29
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,37 @@ private WishCountdowns GetWishCountdownsCore()
{
foreach (uint avatarId in gachaEvent.UpOrangeList)
{
if (!AvatarIds.IsStandardWish(avatarId) && ids.Add(avatarId))
if (!AvatarIds.IsStandardWish(avatarId))
{
orangeAvatarCountdowns.Insert(0, new(context.GetAvatar(avatarId).ToItem<Item>(), gachaEvent));
Countdown countdown;
if (ids.Add(avatarId))
{
countdown = new(context.GetAvatar(avatarId).ToItem<Item>());
orangeAvatarCountdowns.Insert(0, countdown);
}
else
{
countdown = orangeAvatarCountdowns.Single(c => c.Item.Id == avatarId);
}

countdown.Histories.Add(new(gachaEvent));
}
}

foreach (uint avatarId in gachaEvent.UpPurpleList)
{
Countdown countdown;
if (ids.Add(avatarId))
{
purpleAvatarCountdowns.Insert(0, new(context.GetAvatar(avatarId).ToItem<Item>(), gachaEvent));
countdown = new(context.GetAvatar(avatarId).ToItem<Item>());
purpleAvatarCountdowns.Insert(0, countdown);
}
else
{
countdown = purpleAvatarCountdowns.Single(c => c.Item.Id == avatarId);
}

countdown.Histories.Add(new(gachaEvent));
}

continue;
Expand All @@ -86,18 +105,37 @@ private WishCountdowns GetWishCountdownsCore()
{
foreach (uint weaponId in gachaEvent.UpOrangeList)
{
if (!WeaponIds.IsStandardWish(weaponId) && ids.Add(weaponId))
if (!WeaponIds.IsStandardWish(weaponId))
{
orangeWeaponCountdowns.Insert(0, new(context.GetWeapon(weaponId).ToItem<Item>(), gachaEvent));
Countdown countdown;
if (ids.Add(weaponId))
{
countdown = new(context.GetWeapon(weaponId).ToItem<Item>());
orangeWeaponCountdowns.Insert(0, countdown);
}
else
{
countdown = orangeWeaponCountdowns.Single(c => c.Item.Id == weaponId);
}

countdown.Histories.Add(new(gachaEvent));
}
}

foreach (uint weaponId in gachaEvent.UpPurpleList)
{
Countdown countdown;
if (ids.Add(weaponId))
{
purpleWeaponCountdowns.Insert(0, new(context.GetWeapon(weaponId).ToItem<Item>(), gachaEvent));
countdown = new(context.GetWeapon(weaponId).ToItem<Item>());
purpleWeaponCountdowns.Insert(0, countdown);
}
else
{
countdown = purpleWeaponCountdowns.Single(c => c.Item.Id == weaponId);
}

countdown.Histories.Add(new(gachaEvent));
}

continue;
Expand All @@ -107,38 +145,77 @@ private WishCountdowns GetWishCountdownsCore()
{
foreach (uint itemId in gachaEvent.UpOrangeList)
{
if (!(AvatarIds.IsStandardWish(itemId) || WeaponIds.IsStandardWish(itemId)) && ids.Add(itemId))
if (!(AvatarIds.IsStandardWish(itemId) || WeaponIds.IsStandardWish(itemId)))
{
Countdown countdown;
switch (itemId.StringLength())
{
case 8U:
orangeAvatarCountdowns.Insert(0, new(context.GetAvatar(itemId).ToItem<Item>(), gachaEvent));
if (ids.Add(itemId))
{
countdown = new(context.GetAvatar(itemId).ToItem<Item>());
orangeAvatarCountdowns.Insert(0, countdown);
}
else
{
countdown = orangeAvatarCountdowns.Single(c => c.Item.Id == itemId);
}

break;
case 5U:
orangeWeaponCountdowns.Insert(0, new(context.GetWeapon(itemId).ToItem<Item>(), gachaEvent));
if (ids.Add(itemId))
{
countdown = new(context.GetWeapon(itemId).ToItem<Item>());
orangeWeaponCountdowns.Insert(0, countdown);
}
else
{
countdown = orangeWeaponCountdowns.Single(c => c.Item.Id == itemId);
}

break;
default:
throw HutaoException.NotSupported();
}

countdown.Histories.Add(new(gachaEvent));
}
}

foreach (uint itemId in gachaEvent.UpPurpleList)
{
if (ids.Add(itemId))
Countdown countdown;
switch (itemId.StringLength())
{
switch (itemId.StringLength())
{
case 8U:
purpleAvatarCountdowns.Insert(0, new(context.GetAvatar(itemId).ToItem<Item>(), gachaEvent));
break;
case 5U:
purpleWeaponCountdowns.Insert(0, new(context.GetWeapon(itemId).ToItem<Item>(), gachaEvent));
break;
default:
throw HutaoException.NotSupported();
}
case 8U:
if (ids.Add(itemId))
{
countdown = new(context.GetAvatar(itemId).ToItem<Item>());
purpleAvatarCountdowns.Insert(0, countdown);
}
else
{
countdown = purpleAvatarCountdowns.Single(c => c.Item.Id == itemId);
}

break;
case 5U:
if (ids.Add(itemId))
{
countdown = new(context.GetWeapon(itemId).ToItem<Item>());
purpleWeaponCountdowns.Insert(0, countdown);
}
else
{
countdown = purpleWeaponCountdowns.Single(c => c.Item.Id == itemId);
}

break;
default:
throw HutaoException.NotSupported();
}

countdown.Histories.Add(new(gachaEvent));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,46 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:shuxc="using:Snap.Hutao.UI.Xaml.Control"
xmlns:shuxcc="using:Snap.Hutao.UI.Xaml.Control.Card"
xmlns:shuxci="using:Snap.Hutao.UI.Xaml.Control.Image"
xmlns:shvg="using:Snap.Hutao.ViewModel.GachaLog"
cw:Effects.Shadow="{ThemeResource CompatCardShadow}"
mc:Ignorable="d">

<UserControl.Resources>
<DataTemplate x:Key="CountdownHistoryTemplate" x:DataType="shvg:CountdownHistory">
<Grid ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>

<Grid Grid.Column="0" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Style="{StaticResource BaseTextBlockStyle}"
Text="{Binding FormattedVersionOrder}"/>
<TextBlock
Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Style="{StaticResource BaseTextBlockStyle}"
Text="{Binding FormattedTime}"/>
</Grid>

<shuxci:CachedImage
Grid.Column="1"
Width="320"
CornerRadius="{ThemeResource ControlCornerRadius}"
Source="{Binding Banner}"/>
</Grid>
</DataTemplate>

<DataTemplate x:Key="CountdownTemplate" x:DataType="shvg:Countdown">
<Grid
Margin="8,0,8,4"
Expand All @@ -21,6 +56,7 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>

<shuxcc:VerticalCard Width="66">
Expand Down Expand Up @@ -67,8 +103,30 @@
Opacity="0.6"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{Binding FormattedVersionOrder}"/>

</Grid>

<Button
Grid.Column="2"
MinWidth="32"
MinHeight="32"
Padding="0"
VerticalAlignment="Bottom"
Content="&#xE81C;"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
Style="{ThemeResource SettingButtonStyle}">
<Button.Flyout>
<Flyout
FlyoutPresenterStyle="{ThemeResource FlyoutPresenterPadding16And10Style}"
Placement="Right"
ShouldConstrainToRootBounds="False">
<ListView
ItemContainerStyle="{ThemeResource NoneSelectionListViewItemStyle}"
ItemTemplate="{StaticResource CountdownHistoryTemplate}"
ItemsSource="{x:Bind Histories, Mode=OneWay}"
SelectionMode="None"/>
</Flyout>
</Button.Flyout>
</Button>
</Grid>
</DataTemplate>
</UserControl.Resources>
Expand Down
26 changes: 14 additions & 12 deletions src/Snap.Hutao/Snap.Hutao/ViewModel/GachaLog/Countdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,35 @@
// Licensed under the MIT license.

using Snap.Hutao.Model;
using Snap.Hutao.Model.Metadata;

namespace Snap.Hutao.ViewModel.GachaLog;

internal sealed class Countdown
{
public Countdown(Item item, GachaEvent gachaEvent)
public Countdown(Item item)
{
Item = item;
LastTime = gachaEvent.To;

FormattedVersionOrder = $"{gachaEvent.Version} {(gachaEvent.Order is 1 ? SH.ViewModelGachaLogCountdownOrderUp : SH.ViewModelGachaLogCountdownOrderDown)}";

int cdDays = (int)(DateTimeOffset.Now - LastTime).TotalDays;
FormattedCountdown = cdDays > 0 ? SH.FormatViewModelGachaLogCountdownLastTimeDelta(cdDays) : SH.FormatViewModelGachaLogCountdownCurrentWishDelta(-cdDays);
}

public string FormattedLastTime
{
get => LastTime <= DateTimeOffset.Now ? SH.FormatViewModelGachaLogCountdownLastTime(LastTime) : SH.ViewModelGachaLogCountdownCurrentWish;
}

public string FormattedVersionOrder { get; set; }
public string FormattedVersionOrder { get => Histories.First().FormattedVersionOrder; }

public string FormattedCountdown
{
get
{
int cdDays = (int)(DateTimeOffset.Now - LastTime).TotalDays;
return cdDays > 0 ? SH.FormatViewModelGachaLogCountdownLastTimeDelta(cdDays) : SH.FormatViewModelGachaLogCountdownCurrentWishDelta(-cdDays);
}
}

public string FormattedCountdown { get; set; }
public Item Item { get; }

public Item Item { get; set; }
public List<CountdownHistory> Histories { get; set; } = [];

internal DateTimeOffset LastTime { get; set; }
internal DateTimeOffset LastTime { get => Histories.First().LastTime; }
}
25 changes: 25 additions & 0 deletions src/Snap.Hutao/Snap.Hutao/ViewModel/GachaLog/CountdownHistory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.

using Snap.Hutao.Model.Metadata;

namespace Snap.Hutao.ViewModel.GachaLog;

internal sealed class CountdownHistory
{
public CountdownHistory(GachaEvent gachaEvent)
{
LastTime = gachaEvent.To;
FormattedTime = $"{gachaEvent.To:yyyy-MM-dd}";
FormattedVersionOrder = $"{gachaEvent.Version} {(gachaEvent.Order is 1 ? SH.ViewModelGachaLogCountdownOrderUp : SH.ViewModelGachaLogCountdownOrderDown)}";
Banner = gachaEvent.Banner;
}

public string FormattedTime { get; }

public string FormattedVersionOrder { get; }

public Uri Banner { get; }

internal DateTimeOffset LastTime { get; }
}

0 comments on commit 3922a29

Please sign in to comment.