Skip to content

Commit 18b776c

Browse files
added settings dialog
1 parent cce4cc1 commit 18b776c

12 files changed

Lines changed: 187 additions & 25 deletions

.idea/.idea.MoSpeedUI/.idea/avalonia.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AdvancedSettings.axaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private async void UpdateBtn_OnClick(object? sender, RoutedEventArgs e)
4848
{
4949
UpdateBtn.IsEnabled = false;
5050
string tmpDir = Path.Join(Path.GetTempPath(), Path.GetRandomFileName());
51-
string basePath = MainWindow.AppConfiguration.MoSpeedPath.Replace("\\dist", "\\").Replace("/dist", "/");
51+
string basePath = Shared.AppConfiguration.MoSpeedPath.Replace("\\dist", "\\").Replace("/dist", "/");
5252
Directory.CreateDirectory(tmpDir);
5353
string outputPath = Path.Join(tmpDir, "mospeed.zip");
5454
try
@@ -104,7 +104,7 @@ await Task.Run(() =>
104104
}
105105
var sBox = MessageBoxManager.GetMessageBoxCustom(new MessageBoxCustomParams
106106
{
107-
ContentMessage = Lang.Resources.MSDownloadSuccess + $" {MainWindow.AppConfiguration.MoSpeedPath}",
107+
ContentMessage = Lang.Resources.MSDownloadSuccess + $" {Shared.AppConfiguration.MoSpeedPath}",
108108
ButtonDefinitions = new List<ButtonDefinition>
109109
{
110110
new ButtonDefinition { Name = "Ok" }

CompilerWindow.axaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ private async void Compile(CancellationToken token)
5050
{
5151
bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
5252
Process mospeed = new();
53-
mospeed.StartInfo.WorkingDirectory = MainWindow.AppConfiguration.MoSpeedPath;
54-
mospeed.StartInfo.FileName = MainWindow.AppConfiguration.JavaPath;
53+
mospeed.StartInfo.WorkingDirectory = Shared.AppConfiguration.MoSpeedPath;
54+
mospeed.StartInfo.FileName = Shared.AppConfiguration.JavaPath;
5555
mospeed.StartInfo.UseShellExecute = false;
5656
mospeed.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
5757
if (isWindows)

Configuration.cs

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,63 @@
1+
using System.ComponentModel; // Notwendig für INotifyPropertyChanged
12
using System.Xml.Serialization;
23

3-
namespace MoSpeedUI;
4-
5-
public class Configuration
4+
namespace MoSpeedUI
65
{
7-
[XmlElement("mospeed")]
8-
public string MoSpeedPath { get; set; }
9-
[XmlElement("javapath")]
10-
public string JavaPath { get; set; }
11-
[XmlElement("logodec")]
12-
public bool LogoDecoration { get; set; } = true;
6+
public class Configuration : INotifyPropertyChanged
7+
{
8+
// Das PropertyChanged Event für die Bindungen
9+
public event PropertyChangedEventHandler PropertyChanged;
10+
11+
private string _moSpeedPath;
12+
private string _javaPath;
13+
private bool _logoDecoration = true;
14+
15+
[XmlElement("mospeed")]
16+
public string MoSpeedPath
17+
{
18+
get => _moSpeedPath;
19+
set
20+
{
21+
if (_moSpeedPath != value)
22+
{
23+
_moSpeedPath = value;
24+
OnPropertyChanged(nameof(MoSpeedPath));
25+
}
26+
}
27+
}
28+
29+
[XmlElement("javapath")]
30+
public string JavaPath
31+
{
32+
get => _javaPath;
33+
set
34+
{
35+
if (_javaPath != value)
36+
{
37+
_javaPath = value;
38+
OnPropertyChanged(nameof(JavaPath));
39+
}
40+
}
41+
}
42+
43+
[XmlElement("logodec")]
44+
public bool LogoDecoration
45+
{
46+
get => _logoDecoration;
47+
set
48+
{
49+
if (_logoDecoration != value)
50+
{
51+
_logoDecoration = value;
52+
OnPropertyChanged(nameof(LogoDecoration));
53+
}
54+
}
55+
}
56+
57+
// Methode zum Auslösen des PropertyChanged-Events
58+
protected void OnPropertyChanged(string propertyName)
59+
{
60+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
61+
}
62+
}
1363
}

Lang/Resources.Designer.cs

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lang/Resources.de.resx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,19 @@
296296
<data name="Settings" xml:space="preserve">
297297
<value>App Einstellungen</value>
298298
</data>
299+
<data name="MSPathSetting" xml:space="preserve">
300+
<value>MoSpeed Pfad</value>
301+
</data>
302+
<data name="SettingsNoCheck" xml:space="preserve">
303+
<value>Achtung: Pfade werden nicht auf Korrektheit überprüft! Einstellungen werden nach schließen automatisch gespeichert.</value>
304+
</data>
305+
<data name="JavaPathSetting" xml:space="preserve">
306+
<value>Java-Pfad</value>
307+
</data>
308+
<data name="LogoDecorationSetting" xml:space="preserve">
309+
<value>Logodekorationen</value>
310+
</data>
311+
<data name="LogoDecorationSettingTT" xml:space="preserve">
312+
<value>Wenn aktiv, passt sich das Logo für bestimmte Events an, wie zum Beispiel Weihnachten.</value>
313+
</data>
299314
</root>

Lang/Resources.resx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,19 @@
303303
<data name="Settings" xml:space="preserve">
304304
<value>App Setttings</value>
305305
</data>
306+
<data name="MSPathSetting" xml:space="preserve">
307+
<value>MoSpeed Path</value>
308+
</data>
309+
<data name="SettingsNoCheck" xml:space="preserve">
310+
<value>Note: Paths will not be checked for validity! Settings will be saved upon closing automatically.</value>
311+
</data>
312+
<data name="JavaPathSetting" xml:space="preserve">
313+
<value>Java path</value>
314+
</data>
315+
<data name="LogoDecorationSetting" xml:space="preserve">
316+
<value>Logo decorations</value>
317+
</data>
318+
<data name="LogoDecorationSettingTT" xml:space="preserve">
319+
<value>If checked, the logo will change for special events such as Christmas.</value>
320+
</data>
306321
</root>

MainWindow.axaml.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ public partial class MainWindow : Window
3838
public static readonly string ConfigFolder = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),"MoSpeedUI.config");
3939
public static readonly string ConfigFile = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),"MoSpeedUI.config","config.xml");
4040
public static readonly CompileConfig CompileConfig = new();
41-
public static Configuration AppConfiguration = new();
42-
4341
public MainWindow()
4442
{
4543
InitializeComponent();
@@ -141,7 +139,7 @@ public MainWindow()
141139

142140
private void ApplyConfig()
143141
{
144-
if (AppConfiguration.LogoDecoration)
142+
if (Shared.AppConfiguration.LogoDecoration)
145143
{
146144
DateTime dt = DateTime.Today;
147145
if (dt.Month == 6)
@@ -159,6 +157,11 @@ private void ApplyConfig()
159157
MoSpeedLogo.Source =
160158
new Bitmap(AssetLoader.Open(new Uri("avares://MoSpeedUI/Assets/Images/mospeed_halloween.png")));
161159
}
160+
else
161+
{
162+
MoSpeedLogo.Source =
163+
new Bitmap(AssetLoader.Open(new Uri("avares://MoSpeedUI/Assets/Images/mospeed.png")));
164+
}
162165
}
163166
}
164167
private void ReadConfig()
@@ -169,12 +172,12 @@ private void ReadConfig()
169172
bool redoConfig = false;
170173
XmlSerializer ser = new XmlSerializer(typeof(Configuration));
171174
StreamReader r = new StreamReader(ConfigFile);
172-
AppConfiguration = (Configuration)ser.Deserialize(r)!;
175+
Shared.AppConfiguration = (Configuration)ser.Deserialize(r)!;
173176
r.Close();
174-
foreach(PropertyDescriptor descriptor in TypeDescriptor.GetProperties(AppConfiguration))
177+
foreach(PropertyDescriptor descriptor in TypeDescriptor.GetProperties(Shared.AppConfiguration))
175178
{
176179
string name = descriptor.Name;
177-
object? value = descriptor.GetValue(AppConfiguration);
180+
object? value = descriptor.GetValue(Shared.AppConfiguration);
178181
Console.WriteLine("{0}={1}", name, value);
179182
if (Equals(value, descriptor.GetValue(propConfig)))
180183
{
@@ -184,7 +187,7 @@ private void ReadConfig()
184187
}
185188
if (redoConfig)
186189
{
187-
SetupWindow.RegenerateConfig(AppConfiguration);
190+
SetupWindow.RegenerateConfig(Shared.AppConfiguration);
188191
}
189192
}
190193
catch (Exception e)
@@ -346,7 +349,7 @@ private async void CompileBtn_OnClick(object? sender, RoutedEventArgs e)
346349

347350
/*private async Task<bool> CheckForJava()
348351
{
349-
if (AppConfiguration.SkipJavaCheck)
352+
if (Shared.AppConfiguration.SkipJavaCheck)
350353
{
351354
return true;
352355
}
@@ -404,8 +407,8 @@ private async void CompileBtn_OnClick(object? sender, RoutedEventArgs e)
404407
}
405408
if (res == Lang.Resources.Ignore)
406409
{
407-
AppConfiguration.SkipJavaCheck = true;
408-
SetupWindow.RegenerateConfig(AppConfiguration);
410+
Shared.AppConfiguration.SkipJavaCheck = true;
411+
SetupWindow.RegenerateConfig(Shared.AppConfiguration);
409412
return true;
410413
}
411414
return true;
@@ -425,8 +428,8 @@ private async void CompileBtn_OnClick(object? sender, RoutedEventArgs e)
425428
var res = await box.ShowAsPopupAsync(this);
426429
if (res == Lang.Resources.Ignore)
427430
{
428-
AppConfiguration.SkipJavaCheck = true;
429-
SetupWindow.RegenerateConfig(AppConfiguration);
431+
Shared.AppConfiguration.SkipJavaCheck = true;
432+
SetupWindow.RegenerateConfig(Shared.AppConfiguration);
430433
return true;
431434
}
432435
return false;
@@ -559,5 +562,7 @@ private void AboutLink_OnPointerPressed(object? sender, PointerPressedEventArgs
559562

560563
private void SettingsLink_OnPointerPressed(object? sender, PointerPressedEventArgs e)
561564
{
565+
new SettingsDialog().ShowDialog(this);
566+
ApplyConfig();
562567
}
563568
}

SettingsDialog.axaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Window xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
6+
x:Class="MoSpeedUI.SettingsDialog"
7+
xmlns:lang="clr-namespace:MoSpeedUI.Lang"
8+
xmlns:moSpeedUi="clr-namespace:MoSpeedUI"
9+
Title="{x:Static lang:Resources.Settings}">
10+
<StackPanel Margin="8">
11+
<TextBlock FontWeight="Medium" FontSize="24" Text="{x:Static lang:Resources.Settings}"/>
12+
<TextBlock FontWeight="450" FontSize="12" Text="{x:Static lang:Resources.SettingsNoCheck}"/>
13+
<Label Content="{x:Static lang:Resources.MSPathSetting}"/>
14+
<TextBox x:Name="MSPath" Watermark="{x:Static lang:Resources.FndMSWm}"/>
15+
<Label Content="{x:Static lang:Resources.JavaPathSetting}"/>
16+
<TextBox x:Name="JavaPath" Watermark="java"/>
17+
<CheckBox x:Name="LogoDec" Content="{x:Static lang:Resources.LogoDecorationSetting}" ToolTip.Tip="{x:Static lang:Resources.LogoDecorationSettingTT}" />
18+
</StackPanel>
19+
</Window>

SettingsDialog.axaml.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Avalonia;
2+
using Avalonia.Controls;
3+
using Avalonia.Data;
4+
using Avalonia.Markup.Xaml;
5+
using Avalonia.OpenGL;
6+
7+
namespace MoSpeedUI;
8+
9+
public partial class SettingsDialog : Window
10+
{
11+
public SettingsDialog()
12+
{
13+
InitializeComponent();
14+
this.SizeToContent = SizeToContent.WidthAndHeight;
15+
this.DataContext = Shared.AppConfiguration;
16+
MSPath.Bind(TextBox.TextProperty, new Binding(nameof(Shared.AppConfiguration.MoSpeedPath)) { Mode = BindingMode.TwoWay });
17+
JavaPath.Bind(TextBox.TextProperty, new Binding(nameof(Shared.AppConfiguration.JavaPath)) { Mode = BindingMode.TwoWay });
18+
LogoDec.Bind(CheckBox.IsCheckedProperty, new Binding(nameof(Shared.AppConfiguration.LogoDecoration)) { Mode = BindingMode.TwoWay });
19+
this.Closing += (_, _) =>
20+
{
21+
SetupWindow.RegenerateConfig(Shared.AppConfiguration);
22+
};
23+
}
24+
}

0 commit comments

Comments
 (0)