Skip to content

Commit d096dc6

Browse files
author
Alexandru Macocian
committed
Multi-account management.
Split settings into multiple categories.
1 parent 071007c commit d096dc6

37 files changed

+1292
-124
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System;
2+
using System.ComponentModel;
3+
using System.Globalization;
4+
using System.Windows;
5+
using System.Windows.Controls;
6+
using System.Windows.Interactivity;
7+
using System.Windows.Media;
8+
9+
namespace Daybreak.Behaviors
10+
{
11+
public class ScaleFontWithSize : Behavior<TextBlock>
12+
{
13+
public static readonly DependencyProperty MaxFontSizeProperty = DependencyProperty.Register("MaxFontSize", typeof(double), typeof(ScaleFontWithSize), new PropertyMetadata(12d));
14+
15+
public double MaxFontSize
16+
{
17+
get
18+
{
19+
return (double)this.GetValue(MaxFontSizeProperty);
20+
}
21+
set
22+
{
23+
this.SetValue(MaxFontSizeProperty, value);
24+
}
25+
}
26+
27+
protected override void OnAttached()
28+
{
29+
base.OnAttached();
30+
this.AssociatedObject.SizeChanged += (_, __) => this.CalculateFontSize();
31+
DependencyPropertyDescriptor.FromProperty(
32+
TextBlock.TextProperty, typeof(TextBlock)).AddValueChanged(this.AssociatedObject, (_, __) => this.CalculateFontSize());
33+
DependencyPropertyDescriptor.FromProperty(
34+
TextBlock.FontSizeProperty, typeof(TextBlock)).AddValueChanged(this.AssociatedObject, (_, __) => this.CalculateFontSize());
35+
}
36+
37+
private void CalculateFontSize()
38+
{
39+
var textMeasurement = this.MeasureText(this.AssociatedObject.FontSize);
40+
var maximumTextMeasurement = this.MeasureText(this.MaxFontSize);
41+
var desiredWidthFontSize = this.MaxFontSize;
42+
var desiredHeightFontSize = this.MaxFontSize;
43+
44+
if (Math.Round(textMeasurement.Height) != Math.Round(this.AssociatedObject.ActualHeight))
45+
{
46+
47+
var scale = this.AssociatedObject.ActualHeight / maximumTextMeasurement.Height;
48+
desiredHeightFontSize = (this.MaxFontSize * scale) - 1;
49+
desiredHeightFontSize = desiredHeightFontSize <= this.MaxFontSize ? desiredHeightFontSize : this.MaxFontSize;
50+
}
51+
52+
if (Math.Round(textMeasurement.Width) != Math.Round(this.AssociatedObject.ActualWidth))
53+
{
54+
var scale = this.AssociatedObject.ActualWidth / maximumTextMeasurement.Width;
55+
desiredWidthFontSize = (this.MaxFontSize * scale) - 1;
56+
desiredWidthFontSize = desiredWidthFontSize <= this.MaxFontSize ? desiredWidthFontSize : this.MaxFontSize;
57+
58+
}
59+
60+
var desiredFontSize = Math.Min(desiredHeightFontSize, desiredWidthFontSize);
61+
62+
if ((int)desiredFontSize != (int)this.AssociatedObject.FontSize && desiredFontSize > 0)
63+
{
64+
this.AssociatedObject.FontSize = desiredFontSize;
65+
return;
66+
}
67+
}
68+
69+
private Size MeasureText(double fontSize)
70+
{
71+
var formattedText = new FormattedText(this.AssociatedObject.Text, CultureInfo.CurrentUICulture,
72+
FlowDirection.LeftToRight,
73+
new Typeface(this.AssociatedObject.FontFamily, this.AssociatedObject.FontStyle, this.AssociatedObject.FontWeight, this.AssociatedObject.FontStretch),
74+
fontSize, Brushes.Black, VisualTreeHelper.GetDpi(this.AssociatedObject).PixelsPerDip);
75+
76+
return new Size(formattedText.Width, formattedText.Height);
77+
}
78+
}
79+
}

Daybreak/Configuration/ApplicationConfiguration.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Newtonsoft.Json;
1+
using Daybreak.Models;
2+
using Newtonsoft.Json;
3+
using System.Collections.Generic;
24

35
namespace Daybreak.Configuration
46
{
@@ -8,16 +10,12 @@ public sealed class ApplicationConfiguration
810
public string GamePath { get; set; }
911
[JsonProperty("ToolboxPath")]
1012
public string ToolboxPath { get; set; }
11-
[JsonProperty("CharacterName")]
12-
public string CharacterName { get; set; }
1313
[JsonProperty("LeftBrowserDefault")]
1414
public string LeftBrowserDefault { get; set; }
1515
[JsonProperty("RightBrowserDefault")]
1616
public string RightBrowserDefault { get; set; }
17-
[JsonProperty("ProtectedUsername")]
18-
public string ProtectedUsername { get; set; }
19-
[JsonProperty("ProtectedPassword")]
20-
public string ProtectedPassword { get; set; }
17+
[JsonProperty("ProtectedLoginCredentials")]
18+
public List<ProtectedLoginCredentials> ProtectedLoginCredentials { get; set; }
2119
[JsonProperty("AddressBarReadonly")]
2220
public bool AddressBarReadonly { get; set; } = true;
2321
[JsonProperty("ExperimentalFeatures")]

Daybreak/Configuration/ProjectConfiguration.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using Daybreak.Services.Updater;
1010
using Daybreak.Services.ViewManagement;
1111
using Daybreak.Views;
12-
using Microsoft.Web.WebView2.Core;
1312
using Slim;
1413
using System.Extensions;
1514

@@ -50,6 +49,9 @@ public static void RegisterViews(IViewProducer viewProducer)
5049
viewProducer.RegisterView<SettingsView>();
5150
viewProducer.RegisterView<AskUpdateView>();
5251
viewProducer.RegisterView<UpdateView>();
52+
viewProducer.RegisterView<SettingsCategoryView>();
53+
viewProducer.RegisterView<AccountsView>();
54+
viewProducer.RegisterView<ExperimentalSettingsView>();
5355
}
5456
}
5557
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<UserControl x:Class="Daybreak.Controls.AccountTemplate"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:Daybreak.Controls"
7+
x:Name="_this"
8+
mc:Ignorable="d"
9+
xmlns:converters="clr-namespace:Daybreak.Converters"
10+
d:DesignHeight="450" d:DesignWidth="800">
11+
<UserControl.Resources>
12+
<ResourceDictionary>
13+
<converters:InverseBooleanConverter x:Key="InverseBooleanConverter"></converters:InverseBooleanConverter>
14+
</ResourceDictionary>
15+
</UserControl.Resources>
16+
<Grid>
17+
<Grid.ColumnDefinitions>
18+
<ColumnDefinition Width="*"></ColumnDefinition>
19+
<ColumnDefinition Width="auto"></ColumnDefinition>
20+
</Grid.ColumnDefinitions>
21+
<Grid HorizontalAlignment="Stretch">
22+
<Grid.RowDefinitions>
23+
<RowDefinition Height="auto"></RowDefinition>
24+
<RowDefinition Height="auto"></RowDefinition>
25+
<RowDefinition Height="auto"></RowDefinition>
26+
</Grid.RowDefinitions>
27+
<Grid.ColumnDefinitions>
28+
<ColumnDefinition Width="auto"></ColumnDefinition>
29+
<ColumnDefinition Width="*"></ColumnDefinition>
30+
</Grid.ColumnDefinitions>
31+
<TextBlock FontSize="16" Text="Username:" Foreground="White" Margin="5" Grid.Row="0" HorizontalAlignment="Right"></TextBlock>
32+
<TextBlock FontSize="16" Text="Password:" Foreground="White" Margin="5" Grid.Row="1" HorizontalAlignment="Right"></TextBlock>
33+
<TextBlock FontSize="16" Text="Character name:" Foreground="White" Margin="5" Grid.Row="2" HorizontalAlignment="Right"></TextBlock>
34+
<TextBox Text="{Binding ElementName=_this, Path=Username, Mode=TwoWay}" Foreground="White" Background="Transparent"
35+
BorderThickness="1" HorizontalAlignment="Stretch" Grid.Row="0" Grid.Column="1"
36+
FontSize="16" TextChanged="UsernameTextbox_TextChanged" Margin="5"></TextBox>
37+
<PasswordBox x:Name="PasswordBox" Foreground="White" Background="Transparent"
38+
BorderThickness="1" HorizontalAlignment="Stretch" Grid.Row="1" Grid.Column="1"
39+
FontSize="16" PasswordChanged="Passwordbox_PasswordChanged" Margin="5"></PasswordBox>
40+
<TextBox Text="{Binding ElementName=_this, Path=CharacterName, Mode=TwoWay}" Foreground="White" Background="Transparent"
41+
BorderThickness="1" HorizontalAlignment="Stretch" Grid.Row="2" Grid.Column="1"
42+
FontSize="16" TextChanged="CharacterNameTextbox_TextChanged" Margin="5"></TextBox>
43+
</Grid>
44+
<local:BinButton Grid.Column="2" Height="30" Width="30" Foreground="White" VerticalAlignment="Top" Margin="5, 15, 5, 5"
45+
Clicked="BinButton_Clicked"></local:BinButton>
46+
<local:StarGlyph Grid.Column="2" Height="30" Width="30" Foreground="White" VerticalAlignment="Top" Margin="5, 55, 5, 5"
47+
Clicked="StarGlyph_Clicked" IsEnabled="{Binding ElementName=_this, Path=IsDefault, Mode=OneWay, Converter={StaticResource InverseBooleanConverter}}"></local:StarGlyph>
48+
</Grid>
49+
</UserControl>
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using Daybreak.Models;
2+
using System;
3+
using System.Extensions;
4+
using System.Windows;
5+
using System.Windows.Controls;
6+
using System.Windows.Extensions;
7+
8+
namespace Daybreak.Controls
9+
{
10+
/// <summary>
11+
/// Interaction logic for AccountTemplate.xaml
12+
/// </summary>
13+
public partial class AccountTemplate : UserControl
14+
{
15+
public static readonly DependencyProperty UsernameProperty = DependencyPropertyExtensions.Register<AccountTemplate, string>(nameof(Username));
16+
public static readonly DependencyProperty CharacterNameProperty = DependencyPropertyExtensions.Register<AccountTemplate, string>(nameof(CharacterName));
17+
public static readonly DependencyProperty PasswordProperty = DependencyPropertyExtensions.Register<AccountTemplate, string>(nameof(Password));
18+
public static readonly DependencyProperty IsDefaultProperty = DependencyPropertyExtensions.Register<AccountTemplate, bool>(nameof(IsDefault));
19+
20+
21+
public event EventHandler RemoveClicked;
22+
public event EventHandler DefaultClicked;
23+
24+
public string Username
25+
{
26+
get => this.GetTypedValue<string>(UsernameProperty);
27+
set => this.SetValue(UsernameProperty, value);
28+
}
29+
public string Password
30+
{
31+
get => this.GetTypedValue<string>(PasswordProperty);
32+
set => this.SetValue(PasswordProperty, value);
33+
}
34+
public string CharacterName
35+
{
36+
get => this.GetTypedValue<string>(CharacterNameProperty);
37+
set => this.SetValue(CharacterNameProperty, value);
38+
}
39+
public bool IsDefault
40+
{
41+
get => this.GetTypedValue<bool>(IsDefaultProperty);
42+
set => this.SetValue(IsDefaultProperty, value);
43+
}
44+
45+
public AccountTemplate()
46+
{
47+
this.InitializeComponent();
48+
this.DataContextChanged += AccountTemplate_DataContextChanged;
49+
}
50+
51+
private void AccountTemplate_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
52+
{
53+
if (e.NewValue is LoginCredentials loginCredentials)
54+
{
55+
this.PasswordBox.Password = loginCredentials.Password;
56+
this.Username = loginCredentials.Username;
57+
this.CharacterName = loginCredentials.CharacterName;
58+
this.IsDefault = loginCredentials.Default;
59+
}
60+
}
61+
62+
private void BinButton_Clicked(object sender, EventArgs e)
63+
{
64+
this.RemoveClicked?.Invoke(this, e);
65+
}
66+
67+
private void UsernameTextbox_TextChanged(object sender, EventArgs e)
68+
{
69+
this.Username = sender.As<TextBox>()?.Text;
70+
}
71+
72+
private void CharacterNameTextbox_TextChanged(object sender, EventArgs e)
73+
{
74+
this.CharacterName = sender.As<TextBox>()?.Text;
75+
}
76+
77+
private void Passwordbox_PasswordChanged(object sender, EventArgs e)
78+
{
79+
this.Password = sender.As<PasswordBox>()?.Password;
80+
}
81+
82+
private void StarGlyph_Clicked(object sender, EventArgs e)
83+
{
84+
this.DefaultClicked?.Invoke(this, e);
85+
}
86+
}
87+
}

Daybreak/Controls/AddButton.xaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<UserControl x:Class="Daybreak.Controls.AddButton"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:Daybreak.Controls"
7+
mc:Ignorable="d"
8+
x:Name="_this"
9+
d:DesignHeight="450" d:DesignWidth="800">
10+
<Viewbox>
11+
<Grid>
12+
<Ellipse x:Name="BackgroundEllipse" Fill="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}" Visibility="Visible" Opacity="0.1" />
13+
<Path Data="m13,26a13,13 0 1 1 13,-13a13,13 0 0 1 -13,13zm0,-24a11,11 0 1 0 11,11a11,11 0 0 0 -11,-11z"
14+
Fill="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}"></Path>
15+
<Path Data="m13,20a1,1 0 0 1 -1,-1l0,-12a1,1 0 0 1 2,0l0,12a1,1 0 0 1 -1,1z"
16+
Fill="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}"></Path>
17+
<Path Data="m19,14l-12,0a1,1 0 0 1 0,-2l12,0a1,1 0 0 1 0,2z"
18+
Fill="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}"></Path>
19+
<Ellipse Fill="Transparent" MouseEnter="Ellipse_MouseEnter" MouseLeave="Ellipse_MouseLeave" MouseLeftButtonDown="Ellipse_MouseLeftButtonDown"></Ellipse>
20+
</Grid>
21+
</Viewbox>
22+
</UserControl>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Windows.Controls;
3+
using System.Windows.Input;
4+
5+
namespace Daybreak.Controls
6+
{
7+
/// <summary>
8+
/// Interaction logic for AddButton.xaml
9+
/// </summary>
10+
public partial class AddButton : UserControl
11+
{
12+
public event EventHandler Clicked;
13+
14+
public AddButton()
15+
{
16+
InitializeComponent();
17+
}
18+
19+
private void Ellipse_MouseEnter(object sender, MouseEventArgs e)
20+
{
21+
this.BackgroundEllipse.Opacity = 0.6;
22+
}
23+
24+
private void Ellipse_MouseLeave(object sender, MouseEventArgs e)
25+
{
26+
this.BackgroundEllipse.Opacity = 0;
27+
}
28+
29+
private void Ellipse_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
30+
{
31+
if (e.ChangedButton == MouseButton.Left)
32+
{
33+
Clicked?.Invoke(this, e);
34+
}
35+
}
36+
}
37+
}

Daybreak/Controls/AvatarGlyph.xaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<UserControl x:Class="Daybreak.Controls.AvatarGlyph"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:Daybreak.Controls"
7+
mc:Ignorable="d"
8+
x:Name="_this"
9+
d:DesignHeight="450" d:DesignWidth="800">
10+
<Viewbox>
11+
<Grid>
12+
<Path Fill="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}"
13+
Data="m5.7,104.4c10.6,-10.6 24.6,-16.4 39.6,-16.4s29,5.8 39.6,16.4l5.7,-5.7c-12.1,-12 -28.2,-18.7 -45.3,-18.7s-33.2,6.7 -45.3,18.7l5.7,5.7z"></Path>
14+
<Path Fill="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}"
15+
Data="m11.3,34c0,18.7 15.3,34 34,34s34,-15.3 34,-34s-15.3,-34 -34,-34s-34,15.3 -34,34zm60,0c0,14.3 -11.7,26 -26,26s-26,-11.7 -26,-26s11.7,-26 26,-26s26,11.7 26,26z"></Path>
16+
</Grid>
17+
</Viewbox>
18+
</UserControl>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Imaging;
13+
using System.Windows.Navigation;
14+
using System.Windows.Shapes;
15+
16+
namespace Daybreak.Controls
17+
{
18+
/// <summary>
19+
/// Interaction logic for AvatarGlyph.xaml
20+
/// </summary>
21+
public partial class AvatarGlyph : UserControl
22+
{
23+
public AvatarGlyph()
24+
{
25+
InitializeComponent();
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)