Skip to content

Commit

Permalink
Release 0.9.9.17 (#592)
Browse files Browse the repository at this point in the history
* Setup release 0.9.9.17

* Save extracted minimap window position (#591)

Closes #590

* Add ability to pin minimap to screen
Closes #585

* Fix ObjectDisposedException
Closes #589
  • Loading branch information
AlexMacocian authored Feb 18, 2024
1 parent 2863032 commit 3d9106a
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 14 deletions.
16 changes: 16 additions & 0 deletions Daybreak/Configuration/Options/MinimapWindowOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Daybreak.Attributes;

namespace Daybreak.Configuration.Options;

[OptionsIgnore]
[OptionsName(Name = "Minimap Window")]
[OptionsSynchronizationIgnore]
public sealed class MinimapWindowOptions
{
public double X { get; set; }
public double Y { get; set; }
public double Width { get; set; }
public double Height { get; set; }
public double DpiX { get; set; }
public double DpiY { get; set; }
}
1 change: 1 addition & 0 deletions Daybreak/Configuration/ProjectConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ public override void RegisterOptions(IOptionsProducer optionsProducer)
optionsProducer.RegisterOptions<CredentialManagerOptions>();
optionsProducer.RegisterOptions<LaunchConfigurationServiceOptions>();
optionsProducer.RegisterOptions<DirectSongOptions>();
optionsProducer.RegisterOptions<MinimapWindowOptions>();
}

public override void RegisterNotificationHandlers(INotificationHandlerProducer notificationHandlerProducer)
Expand Down
20 changes: 20 additions & 0 deletions Daybreak/Controls/Glyphs/PinGlyph.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<UserControl x:Class="Daybreak.Controls.Glyphs.PinGlyph"
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.Glyphs"
x:Name="_this"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Viewbox>
<Grid>
<Path Fill="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}"
Data="m15.0058,27.53079a1,1 0 0 1 -0.71,-0.29l-11.53,-11.53a1,1 0 0 1 0,-1.42l1.52,-1.51a6.06,6.06 0 0 1 6.37,-1.43l5.41,-5.41l-0.94,-0.94a1,1 0 0 1 0,-1.41l3.29,-3.3a1,1 0 0 1 1.41,0l9.89,9.89a1,1 0 0 1 0,1.41l-3.3,3.29a1,1 0 0 1 -1.41,0l-0.94,-0.94l-5.41,5.41a6.08,6.08 0 0 1 -1.43,6.37l-1.51,1.52a1,1 0 0 1 -0.71,0.29zm-10.12,-12.53l10.12,10.12l0.81,-0.81a4.12,4.12 0 0 0 0.77,-4.75a1,1 0 0 1 0.18,-1.15l6.59,-6.59a1,1 0 0 1 1.42,0l0.94,0.94l1.88,-1.88l-8.47,-8.47l-1.88,1.88l0.94,0.94a1,1 0 0 1 0,1.42l-6.59,6.59a1,1 0 0 1 -1.15,0.18a4.12,4.12 0 0 0 -4.75,0.77l-0.81,0.81z"/>
<Path Fill="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}"
Data="m1.0058,30.00079a1,1 0 0 1 -0.71,-0.29a1,1 0 0 1 0,-1.42l8.24,-8.23a1,1 0 0 1 1.41,1.41l-8.23,8.24a1,1 0 0 1 -0.71,0.29z"/>
<Path Fill="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}"
Data="m24.0658,13.53079a1,1 0 0 1 -0.71,-0.29l-2.47,-2.47a1,1 0 1 1 1.42,-1.42l2.47,2.47a1,1 0 0 1 0,1.42a1,1 0 0 1 -0.71,0.29z"/>
</Grid>
</Viewbox>
</UserControl>
13 changes: 13 additions & 0 deletions Daybreak/Controls/Glyphs/PinGlyph.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Windows.Controls;

namespace Daybreak.Controls.Glyphs;
/// <summary>
/// Interaction logic for PinGlyph.xaml
/// </summary>
public partial class PinGlyph : UserControl
{
public PinGlyph()
{
this.InitializeComponent();
}
}
2 changes: 1 addition & 1 deletion Daybreak/Daybreak.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<LangVersion>preview</LangVersion>
<ApplicationIcon>Daybreak.ico</ApplicationIcon>
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
<Version>0.9.9.16</Version>
<Version>0.9.9.17</Version>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<UserSecretsId>cfb2a489-db80-448d-a969-80270f314c46</UserSecretsId>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
Expand Down
62 changes: 62 additions & 0 deletions Daybreak/Launch/MinimapWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<mah:MetroWindow x:Class="Daybreak.Launch.MinimapWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Daybreak.Launch"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:buttons="clr-namespace:Daybreak.Controls.Buttons"
xmlns:glyphs="clr-namespace:Daybreak.Controls.Glyphs"
xmlns:launch="clr-namespace:Daybreak.Launch"
mc:Ignorable="d"
WindowStyle="None"
ResizeMode="CanResize"
ShowTitleBar="False"
ShowMaxRestoreButton="True"
ShowIconOnTitleBar="False"
ShowMinButton="True"
ShowSystemMenu="False"
ShowSystemMenuOnRightClick="False"
ShowInTaskbar="True"
ShowCloseButton="True"
Title="Daybreak Minimap"
Topmost="{Binding ElementName=_this, Path=Pinned, Mode=OneWay}"
x:Name="_this"
Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Rectangle Height="30"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Grid.Row="0"
MouseLeftButtonDown="Grid_MouseLeftButtonDown" />
<buttons:HighlightButton Height="30"
Width="50"
Margin="0, 0, 140, 0"
HighlightColor="LightGray"
HorizontalAlignment="Right"
Clicked="HighlightButton_Clicked"
Cursor="Arrow"
ToolTip="Pin Topmost">
<buttons:HighlightButton.ButtonContent>
<Grid>
<glyphs:PinGlyph Foreground="{StaticResource MahApps.Brushes.ThemeForeground}"
Height="15"/>
<Line X1="21"
X2="31"
Y1="10"
Y2="20"
StrokeThickness="1"
Stroke="{StaticResource MahApps.Brushes.ThemeForeground}"
Visibility="{Binding Path=Pinned, RelativeSource={RelativeSource AncestorType={x:Type launch:MinimapWindow}}, Converter={StaticResource BooleanToVisibilityConverter}}"/>
</Grid>

</buttons:HighlightButton.ButtonContent>
</buttons:HighlightButton>
<ContentPresenter Grid.Row="1"
Content="{Binding ElementName=_this, Path=Content, Mode=OneWay}"/>
</Grid>
</mah:MetroWindow>
34 changes: 34 additions & 0 deletions Daybreak/Launch/MinimapWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using MahApps.Metro.Controls;
using System.Windows;
using System.Windows.Extensions;

namespace Daybreak.Launch;
/// <summary>
/// Interaction logic for MinimapWindow.xaml
/// </summary>
public partial class MinimapWindow : MetroWindow
{
[GenerateDependencyProperty]
private bool pinned = false;
[GenerateDependencyProperty]
private FrameworkElement content = default!;

public MinimapWindow()
{
this.InitializeComponent();
}

private void Grid_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (e.ChangedButton is System.Windows.Input.MouseButton.Left)
{
e.Handled = true;
this.DragMove();
}
}

private void HighlightButton_Clicked(object sender, System.EventArgs e)
{
this.Pinned = !this.Pinned;
}
}
51 changes: 41 additions & 10 deletions Daybreak/Views/FocusView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Daybreak.Configuration.Options;
using Daybreak.Launch;
using Daybreak.Models;
using Daybreak.Models.Builds;
using Daybreak.Models.Guildwars;
Expand All @@ -9,6 +10,7 @@
using Daybreak.Services.Navigation;
using Daybreak.Services.Notifications;
using Daybreak.Services.Scanner;
using Daybreak.Services.Screens;
using Daybreak.Views.Trade;
using MahApps.Metro.Controls;
using Microsoft.Extensions.Logging;
Expand All @@ -23,7 +25,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Extensions;
using System.Windows.Media.Animation;
using System.Windows.Media;
using Position = Daybreak.Models.Guildwars.Position;

namespace Daybreak.Views;
Expand All @@ -46,7 +48,9 @@ public partial class FocusView : UserControl
private readonly IGuildwarsMemoryCache guildwarsMemoryCache;
private readonly IExperienceCalculator experienceCalculator;
private readonly IViewManager viewManager;
private readonly IScreenManager screenManager;
private readonly ILiveUpdateableOptions<FocusViewOptions> liveUpdateableOptions;
private readonly ILiveUpdateableOptions<MinimapWindowOptions> minimapWindowOptions;
private readonly ILogger<FocusView> logger;

[GenerateDependencyProperty]
Expand Down Expand Up @@ -88,7 +92,7 @@ public partial class FocusView : UserControl
[GenerateDependencyProperty]
private bool minimapExtracted;

private MetroWindow? minimapWindow;
private MinimapWindow? minimapWindow;
private bool browserMaximized = false;
private bool minimapMaximized = false;
private bool inventoryMaximized = false;
Expand All @@ -101,7 +105,9 @@ public FocusView(
IGuildwarsMemoryCache guildwarsMemoryCache,
IExperienceCalculator experienceCalculator,
IViewManager viewManager,
IScreenManager screenManager,
ILiveUpdateableOptions<FocusViewOptions> liveUpdateableOptions,
ILiveUpdateableOptions<MinimapWindowOptions> minimapWindowOptions,
ILogger<FocusView> logger)
{
this.notificationService = notificationService.ThrowIfNull();
Expand All @@ -110,7 +116,9 @@ public FocusView(
this.guildwarsMemoryCache = guildwarsMemoryCache.ThrowIfNull();
this.experienceCalculator = experienceCalculator.ThrowIfNull();
this.viewManager = viewManager.ThrowIfNull();
this.screenManager = screenManager.ThrowIfNull();
this.liveUpdateableOptions = liveUpdateableOptions.ThrowIfNull();
this.minimapWindowOptions = minimapWindowOptions.ThrowIfNull();
this.logger = logger.ThrowIfNull();

this.InitializeComponent();
Expand Down Expand Up @@ -777,16 +785,28 @@ private void MinimapExtractButton_Clicked(object sender, EventArgs e)

this.minimapWindow = new()
{
ShowTitleBar = true,
ShowMaxRestoreButton = true,
ShowIconOnTitleBar = false,
ShowMinButton = true,
ShowSystemMenu = false,
ShowSystemMenuOnRightClick = false,
ShowInTaskbar = true,
ShowCloseButton = true
Resources = this.Resources
};

var minimapWindowOptions = this.minimapWindowOptions.Value.ThrowIfNull();
var dpiScale = VisualTreeHelper.GetDpi(this.minimapWindow);
var minimapSize = new Rect
{
X = minimapWindowOptions.X * dpiScale.DpiScaleX / minimapWindowOptions.DpiX,
Y = minimapWindowOptions.Y * dpiScale.DpiScaleY / minimapWindowOptions.DpiY,
Width = minimapWindowOptions.Width * dpiScale.DpiScaleX / minimapWindowOptions.DpiX,
Height = minimapWindowOptions.Height * dpiScale.DpiScaleY / minimapWindowOptions.DpiY
};

if (minimapSize.Width > 0 && minimapSize.Height > 0 &&
this.screenManager.Screens.Any(s => s.Size.Contains(minimapSize) || s.Size.IntersectsWith(minimapSize)))
{
this.minimapWindow.Left = minimapSize.Left;
this.minimapWindow.Top = minimapSize.Top;
this.minimapWindow.Width = minimapSize.Width;
this.minimapWindow.Height = minimapSize.Height;
}

this.minimapWindow.Closed += this.MinimapWindow_Closed;
this.MinimapExtracted = true;
this.MinimapVisible = false;
Expand All @@ -808,6 +828,17 @@ private void MinimapWindow_Closed(object? sender, EventArgs e)
return;
}

var options = this.minimapWindowOptions.Value.ThrowIfNull();
var dpiScale = VisualTreeHelper.GetDpi(this.minimapWindow);
options.X = this.minimapWindow.Left;
options.Y = this.minimapWindow.Top;
options.Width = this.minimapWindow.Width;
options.Height = this.minimapWindow.Height;
options.DpiX = dpiScale.DpiScaleX;
options.DpiY = dpiScale.DpiScaleY;

this.minimapWindowOptions.UpdateOption();

this.MinimapExtracted = false;
this.MinimapVisible = this.liveUpdateableOptions.Value.MinimapComponentVisible;
this.minimapWindow.Close();
Expand Down
6 changes: 3 additions & 3 deletions Daybreak/Views/LauncherView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ private void RetrieveLaunchConfigurations()
this.LatestConfiguration = this.LaunchConfigurations.FirstOrDefault(c => c.Configuration?.Equals(latestLaunchConfiguration) is true);
}

private async void PeriodicallyCheckSelectedConfigState()
private async Task PeriodicallyCheckSelectedConfigState()
{
while (!this.cancellationTokenSource.IsCancellationRequested)
{
if (!this.launching)
{
await this.SetLaunchButtonState();
await this.Dispatcher.InvokeAsync(this.SetLaunchButtonState);
}

await Task.Delay(TimeSpan.FromSeconds(1), this.cancellationTokenSource.Token);
Expand All @@ -116,7 +116,7 @@ private void StartupView_Loaded(object sender, RoutedEventArgs e)
}

this.RetrieveLaunchConfigurations();
this.PeriodicallyCheckSelectedConfigState();
new TaskFactory().StartNew(this.PeriodicallyCheckSelectedConfigState, this.cancellationTokenSource.Token, TaskCreationOptions.LongRunning, TaskScheduler.Current);
}

private void StartupView_Unloaded(object sender, RoutedEventArgs e)
Expand Down

0 comments on commit 3d9106a

Please sign in to comment.