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

Wintersday preparation #457

Merged
merged 1 commit into from
Nov 2, 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
3 changes: 3 additions & 0 deletions Daybreak/Configuration/Options/ThemeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ public sealed class ThemeOptions

[OptionName(Name = "Blur Background", Description = "If true, the background image will be blurred")]
public bool BackgroundBlur { get; set; } = false;

[OptionName(Name = "Wintersday Mode", Description = "If true, Daybreak will apply a Wintersday theme")]
public bool WintersdayMode { get; set; } = false;
}
7 changes: 3 additions & 4 deletions Daybreak/Configuration/ProjectConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Daybreak.Services.ApplicationLauncher;
using Daybreak.Services.Bloogum;
using Daybreak.Services.BuildTemplates;
using Daybreak.Services.Credentials;
using Daybreak.Services.IconRetrieve;
Expand Down Expand Up @@ -97,8 +96,8 @@ public override void RegisterResolvers(IServiceManager serviceManager)
.WithMessageHandler(this.SetupLoggingAndMetrics<ApplicationUpdater>)
.WithDefaultRequestHeadersSetup(this.SetupDaybreakUserAgent)
.Build()
.RegisterHttpClient<BloogumClient>()
.WithMessageHandler(this.SetupLoggingAndMetrics<BloogumClient>)
.RegisterHttpClient<OnlinePictureClient>()
.WithMessageHandler(this.SetupLoggingAndMetrics<OnlinePictureClient>)
.WithDefaultRequestHeadersSetup(this.SetupChromeImpersonationUserAgent)
.Build()
.RegisterHttpClient<GraphClient>()
Expand Down Expand Up @@ -213,7 +212,7 @@ public override void RegisterServices(IServiceCollection services)
services.AddScoped<ICredentialManager, CredentialManager>();
services.AddScoped<IApplicationLauncher, ApplicationLauncher>();
services.AddScoped<IScreenshotProvider, ScreenshotProvider>();
services.AddScoped<IBloogumClient, BloogumClient>();
services.AddScoped<IOnlinePictureClient, OnlinePictureClient>();
services.AddScoped<IApplicationUpdater, ApplicationUpdater>();
services.AddScoped<IBuildTemplateManager, BuildTemplateManager>();
services.AddScoped<IIconCache, IconCache>();
Expand Down
109 changes: 109 additions & 0 deletions Daybreak/Controls/SnowfallOverlay.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<UserControl x:Class="Daybreak.Controls.SnowfallOverlay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Daybreak.Controls"
xmlns:effects="clr-namespace:System.Windows.Media.Extensions.Effects;assembly=WpfExtended"
mc:Ignorable="d"
Loaded="UserControl_Loaded"
Unloaded="UserControl_Unloaded"
x:Name="_this"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Effect>
<BlurEffect
KernelType="Box"
Radius="2"/>
</UserControl.Effect>
<UserControl.Triggers>
<EventTrigger RoutedEvent="UserControl.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="_this"
Storyboard.TargetProperty="Time"
From="0"
To="200"
Duration="4:0:0"
RepeatBehavior="Forever"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</UserControl.Triggers>
<Grid>
<Grid>
<Grid.Background>
<ImageBrush x:Name="Host1"
TileMode="Tile"
ViewportUnits="Absolute"
Viewport="0, 0, 100, 100">
<ImageBrush.RelativeTransform>
<TransformGroup>
<TranslateTransform x:Name="SnowfallTransform1" X="0" Y="{Binding ElementName=_this, Path=Time, Mode=OneWay}" />
<ScaleTransform ScaleX="{Binding ElementName=_this, Path=FlakeSize1, Mode=OneWay}" ScaleY="{Binding ElementName=_this, Path=FlakeSize1, Mode=OneWay}" />
</TransformGroup>
</ImageBrush.RelativeTransform>
</ImageBrush>
</Grid.Background>
</Grid>
<Grid>
<Grid.Background>
<ImageBrush x:Name="Host2"
TileMode="Tile"
ViewportUnits="Absolute"
Viewport="0, 0, 100, 100">
<ImageBrush.RelativeTransform>
<TransformGroup>
<TranslateTransform x:Name="SnowfallTransform2" X="0" Y="{Binding ElementName=_this, Path=Time, Mode=OneWay}" />
<ScaleTransform ScaleX="{Binding ElementName=_this, Path=FlakeSize2, Mode=OneWay}" ScaleY="{Binding ElementName=_this, Path=FlakeSize2, Mode=OneWay}" />
</TransformGroup>
</ImageBrush.RelativeTransform>
</ImageBrush>
</Grid.Background>
</Grid>
<Grid>
<Grid.Background>
<ImageBrush x:Name="Host3"
TileMode="Tile"
ViewportUnits="Absolute"
Viewport="0, 0, 100, 100">
<ImageBrush.RelativeTransform>
<TransformGroup>
<TranslateTransform x:Name="SnowfallTransform3" X="0" Y="{Binding ElementName=_this, Path=Time, Mode=OneWay}" />
<ScaleTransform ScaleX="{Binding ElementName=_this, Path=FlakeSize3, Mode=OneWay}" ScaleY="{Binding ElementName=_this, Path=FlakeSize3, Mode=OneWay}" />
</TransformGroup>
</ImageBrush.RelativeTransform>
</ImageBrush>
</Grid.Background>
</Grid>
<Grid>
<Grid.Background>
<ImageBrush x:Name="Host4"
TileMode="Tile"
ViewportUnits="Absolute"
Viewport="0, 0, 100, 100">
<ImageBrush.RelativeTransform>
<TransformGroup>
<TranslateTransform x:Name="SnowfallTransform4" X="0" Y="{Binding ElementName=_this, Path=Time, Mode=OneWay}" />
<ScaleTransform ScaleX="{Binding ElementName=_this, Path=FlakeSize4, Mode=OneWay}" ScaleY="{Binding ElementName=_this, Path=FlakeSize4, Mode=OneWay}" />
</TransformGroup>
</ImageBrush.RelativeTransform>
</ImageBrush>
</Grid.Background>
</Grid>
<Grid>
<Grid.Background>
<ImageBrush x:Name="Host5"
TileMode="Tile"
ViewportUnits="Absolute"
Viewport="0, 0, 100, 100">
<ImageBrush.RelativeTransform>
<TransformGroup>
<TranslateTransform x:Name="SnowfallTransform5" X="0" Y="{Binding ElementName=_this, Path=Time, Mode=OneWay}" />
<ScaleTransform ScaleX="{Binding ElementName=_this, Path=FlakeSize5, Mode=OneWay}" ScaleY="{Binding ElementName=_this, Path=FlakeSize5, Mode=OneWay}" />
</TransformGroup>
</ImageBrush.RelativeTransform>
</ImageBrush>
</Grid.Background>
</Grid>
</Grid>
</UserControl>
122 changes: 122 additions & 0 deletions Daybreak/Controls/SnowfallOverlay.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Extensions;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace Daybreak.Controls;
/// <summary>
/// Interaction logic for SnowfallOverlay.xaml
/// </summary>
public partial class SnowfallOverlay : UserControl
{
private static readonly double[] Frequencies = new double[] { 0.5, 0.1, 5, 1 };
private static readonly double[] Amplitudes = new double[] { 1, 0.1, 0.1, 0.2 };
private static readonly double Divisor = Amplitudes.Sum();

[GenerateDependencyProperty]
private double flakeSize1;
[GenerateDependencyProperty]
private double flakeSize2;
[GenerateDependencyProperty]
private double flakeSize3;
[GenerateDependencyProperty]
private double flakeSize4;
[GenerateDependencyProperty]
private double flakeSize5;
[GenerateDependencyProperty]
private double time;

[GenerateDependencyProperty]
private double windStrength1;
[GenerateDependencyProperty]
private double windStrength2;
[GenerateDependencyProperty]
private double windStrength3;
[GenerateDependencyProperty]
private double windStrength4;
[GenerateDependencyProperty]
private double windStrength5;

[GenerateDependencyProperty]
private double baseWind1;
[GenerateDependencyProperty]
private double baseWind2;
[GenerateDependencyProperty]
private double baseWind3;
[GenerateDependencyProperty]
private double baseWind4;
[GenerateDependencyProperty]
private double baseWind5;

private CancellationTokenSource? tokenSource;

public SnowfallOverlay()
{
this.InitializeComponent();
this.InitializeImages();
}

private void InitializeImages()
{
using var snowTexture1 = this.GetType().Assembly.GetManifestResourceStream("Daybreak.Resources.Snow1.png");
using var snowTexture2 = this.GetType().Assembly.GetManifestResourceStream("Daybreak.Resources.Snow2.png");
using var snowTexture3 = this.GetType().Assembly.GetManifestResourceStream("Daybreak.Resources.Snow3.png");
using var snowTexture4 = this.GetType().Assembly.GetManifestResourceStream("Daybreak.Resources.Snow4.png");
var bitmap1 = BitmapFactory.FromStream(snowTexture1);
var bitmap2 = BitmapFactory.FromStream(snowTexture2);
var bitmap3 = BitmapFactory.FromStream(snowTexture3);
var bitmap4 = BitmapFactory.FromStream(snowTexture4);
this.Host1.ImageSource = bitmap4;
this.Host2.ImageSource = bitmap3;
this.Host3.ImageSource = bitmap2;
this.Host4.ImageSource = bitmap1;
this.Host5.ImageSource = bitmap1;
}

private async void SimulateWind(CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
{
var time = this.Time;
this.SnowfallTransform1.X += this.BaseWind1 + this.GetNoise(time) * this.WindStrength1;
this.SnowfallTransform2.X += this.BaseWind2 + this.GetNoise(time - 0.02) * this.WindStrength2;
this.SnowfallTransform3.X += this.BaseWind3 + this.GetNoise(time - 0.03) * this.WindStrength3;
this.SnowfallTransform4.X += this.BaseWind4 + this.GetNoise(time - 0.05) * this.WindStrength4;
this.SnowfallTransform5.X += this.BaseWind5 + this.GetNoise(time - 0.08) * this.WindStrength5;
await Task.Delay(16, cancellationToken).ConfigureAwait(true);
}
}

private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
this.tokenSource?.Dispose();
this.tokenSource = new CancellationTokenSource();
this.SimulateWind(this.tokenSource.Token);
}

private void UserControl_Unloaded(object sender, RoutedEventArgs e)
{
this.tokenSource?.Dispose();
this.tokenSource = default;
}

private double GetNoise(double source)
{
var returnValue = 0d;
for(var i = 0; i < Frequencies.Length; i++)
{
var f = Frequencies[i];
var a = Amplitudes[i];
returnValue += a * Math.Sin(f * source * Math.PI * 2);
}

return returnValue / Divisor;
}
}
16 changes: 12 additions & 4 deletions Daybreak/Daybreak.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<LangVersion>preview</LangVersion>
<ApplicationIcon>Daybreak.ico</ApplicationIcon>
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
<Version>0.9.8.134</Version>
<Version>0.9.8.135</Version>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<UserSecretsId>cfb2a489-db80-448d-a969-80270f314c46</UserSecretsId>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
Expand All @@ -23,6 +23,10 @@
<None Remove="Resources\NotifyClose.wav" />
<None Remove="Resources\NotifyError.wav" />
<None Remove="Resources\NotifyInformation.wav" />
<None Remove="Resources\Snow1.png" />
<None Remove="Resources\Snow2.png" />
<None Remove="Resources\Snow3.png" />
<None Remove="Resources\Snow4.png" />
<None Remove="Services\Drawing\Resources\Bag.svg" />
<None Remove="Services\Drawing\Resources\CircledStar.svg" />
<None Remove="Services\Drawing\Resources\Dungeon.svg" />
Expand All @@ -41,6 +45,10 @@
<EmbeddedResource Include="Resources\NotifyClose.wav" />
<EmbeddedResource Include="Resources\NotifyError.wav" />
<EmbeddedResource Include="Resources\NotifyInformation.wav" />
<EmbeddedResource Include="Resources\Snow1.png" />
<EmbeddedResource Include="Resources\Snow2.png" />
<EmbeddedResource Include="Resources\Snow3.png" />
<EmbeddedResource Include="Resources\Snow4.png" />
<EmbeddedResource Include="Services\Drawing\Resources\Bag.svg" />
<EmbeddedResource Include="Services\Drawing\Resources\CircledStar.svg" />
<EmbeddedResource Include="Services\Drawing\Resources\Dungeon.svg" />
Expand Down Expand Up @@ -92,20 +100,20 @@
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2088.41" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.75" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.77" />
<PackageReference Include="NAudio" Version="2.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Plumsy" Version="1.1.0" />
<PackageReference Include="securifybv.ShellLink" Version="0.1.0" />
<PackageReference Include="Slim" Version="1.9.2" />
<PackageReference Include="Svg" Version="3.4.4" />
<PackageReference Include="Svg" Version="3.4.5" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="System.Reflection.Metadata" Version="7.0.2" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
<PackageReference Include="SystemExtensions.NetCore" Version="1.0.1" />
<PackageReference Include="SystemExtensions.NetStandard" Version="1.6.2" />
<PackageReference Include="SystemExtensions.NetStandard.DependencyInjection" Version="1.3.1" />
<PackageReference Include="WpfExtended" Version="0.7.3" />
<PackageReference Include="WpfExtended" Version="0.7.7" />
<PackageReference Include="WpfExtended.SourceGeneration" Version="0.1.2" />
<PackageReference Include="WpfScreenHelper" Version="2.1.0" />
<PackageReference Include="WriteableBitmapEx" Version="1.6.8" />
Expand Down
31 changes: 26 additions & 5 deletions Daybreak/Launch/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</Style>
</ResourceDictionary>
</Window.Resources>
<Grid Background="Transparent">
<Grid Background="Black">
<Grid.RowDefinitions>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
Expand All @@ -72,11 +72,32 @@
<effects:ContrastAdjust Brightness="0.01"
Contrast="1.3" />
</Border.Effect>
<Border Effect="{Binding ElementName=_this, Path=BlurBackground, Mode=OneWay, Converter={StaticResource BooleanToEffectConverter}, ConverterParameter={StaticResource BlurEffect}}">
<Border Effect="{Binding ElementName=_this, Path=PaintifyBackground, Mode=OneWay, Converter={StaticResource BooleanToEffectConverter}, ConverterParameter={StaticResource PaintifyEffect}}">
<controls:ImageViewer x:Name="ImageViewer" />
<Grid>
<Border Effect="{Binding ElementName=_this, Path=BlurBackground, Mode=OneWay, Converter={StaticResource BooleanToEffectConverter}, ConverterParameter={StaticResource BlurEffect}}">
<Border Effect="{Binding ElementName=_this, Path=PaintifyBackground, Mode=OneWay, Converter={StaticResource BooleanToEffectConverter}, ConverterParameter={StaticResource PaintifyEffect}}">
<controls:ImageViewer x:Name="ImageViewer" />
</Border>
</Border>
</Border>
<controls:SnowfallOverlay
Visibility="{Binding ElementName=_this, Path=WintersdayMode, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}"
Opacity="0.4"
BaseWind1="0.000074"
BaseWind2="0.000087"
BaseWind3="0.000073"
BaseWind4="0.000065"
BaseWind5="0.000062"
WindStrength1="0.0005"
WindStrength2="0.001"
WindStrength3="0.0008"
WindStrength4="0.0007"
WindStrength5="0.0006"
FlakeSize1="14"
FlakeSize2="6"
FlakeSize3="4.6"
FlakeSize4="3.2"
FlakeSize5="2.1">
</controls:SnowfallOverlay>
</Grid>
</Border>
<Rectangle Fill="Transparent"
MouseDown="Window_MouseLeftButtonDown"
Expand Down
5 changes: 3 additions & 2 deletions Daybreak/Launch/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Daybreak.Configuration.Options;
using Daybreak.Services.Bloogum;
using Daybreak.Services.IconRetrieve;
using Daybreak.Services.Menu;
using Daybreak.Services.Navigation;
using Daybreak.Services.Options;
Expand Down Expand Up @@ -55,6 +53,8 @@ public partial class MainWindow : MetroWindow
private bool paintifyBackground;
[GenerateDependencyProperty]
private bool blurBackground;
[GenerateDependencyProperty]
private bool wintersdayMode;

public event EventHandler<MainWindow>? WindowParametersChanged;

Expand Down Expand Up @@ -125,6 +125,7 @@ private void ThemeOptionsChanged()
{
this.PaintifyBackground = this.themeOptions.Value.BackgroundPaintify;
this.BlurBackground = this.themeOptions.Value.BackgroundBlur;
this.WintersdayMode = this.themeOptions.Value.WintersdayMode;
}

private void SetupImageCycle()
Expand Down
Binary file added Daybreak/Resources/Snow1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Daybreak/Resources/Snow2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Daybreak/Resources/Snow3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Daybreak/Resources/Snow4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading