Skip to content
This repository was archived by the owner on Dec 13, 2020. It is now read-only.

Commit c6854aa

Browse files
author
Firestack
committed
JSON Breaking change, Added style options!
1.2.0
1 parent 8e64bad commit c6854aa

File tree

7 files changed

+152
-10
lines changed

7 files changed

+152
-10
lines changed

UnityMultiLauncher/App.xaml.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@ protected override void OnStartup(StartupEventArgs e)
1919

2020
// get the current app style (theme and accent) from the application
2121
// you can then use the current theme and custom accent instead set a new theme
22-
Tuple<AppTheme, Accent> appStyle = ThemeManager.DetectAppStyle(Application.Current);
23-
2422
// now set the Green accent and dark theme
25-
ThemeManager.ChangeAppStyle(Application.Current,
26-
ThemeManager.GetAccent(ProgramConfig.conf.AccentColor),
27-
ThemeManager.GetAppTheme("BaseLight")); // or appStyle.Item1
23+
ThemeManager.ChangeAppStyle(Application.Current, ProgramConfig.conf.appStyle.Item2, ProgramConfig.conf.appStyle.Item1);
24+
2825

2926
base.OnStartup(e);
3027
}

UnityMultiLauncher/Models/ConfigLoader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static T LoadConfig<T>(string relPath) where T : Config
3535

3636
public static void SaveConfig(string relPath, object obj)
3737
{
38-
File.WriteAllText(relPath, JsonConvert.SerializeObject(obj));
38+
File.WriteAllText(relPath, JsonConvert.SerializeObject(obj, Formatting.None, new JsonSerializerSettings { }));
3939
}
4040
}
4141
}

UnityMultiLauncher/Models/ProgramConfig.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
using System.Linq;
44
using System.Text;
55
using System.Threading.Tasks;
6-
6+
using System.Windows;
7+
using Newtonsoft.Json;
8+
using MahApps.Metro;
79

810
namespace UnityMultiLauncher
911
{
@@ -33,9 +35,27 @@ public class ProgramConfig : Utility.ConfigLoader.Config
3335

3436
public static string defaultFilename { get { return string.Format("unitymultilauncher.{0}.cfg.json", Environment.UserName); } }
3537

36-
37-
public HashSet<Uri> unityExeLocations = new HashSet<Uri>();
38+
[JsonIgnore]
39+
public Tuple<AppTheme, Accent> appStyle
40+
{
41+
get
42+
{
43+
return Tuple.Create(
44+
ThemeManager.AppThemes.First(theme => theme.Name == appTheme),
45+
ThemeManager.Accents.First(accent => accent.Name == appAccent)
46+
);
47+
}
48+
set
49+
{
50+
appTheme = value.Item1.Name;
51+
appAccent = value.Item2.Name;
52+
}
53+
}
3854

39-
public string AccentColor = "Blue";
55+
public string appTheme = "BaseLight";
56+
57+
public string appAccent = "Blue";
58+
59+
public HashSet<Uri> unityExeLocations = new HashSet<Uri>();
4060
}
4161
}

UnityMultiLauncher/UnityMultiLauncher.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
<Compile Include="Models\ConfigLoader.cs" />
9898
<Compile Include="Models\ProgramConfig.cs" />
9999
<Compile Include="Models\Utility.cs" />
100+
<Compile Include="ViewModels\StyleViewModel.cs" />
100101
<Compile Include="ViewModels\UnityViewModel.cs" />
101102
<Compile Include="ViewModels\Utils\ViewCommand.cs" />
102103
<Compile Include="ViewModels\Utils\ViewModel.cs" />
@@ -108,6 +109,7 @@
108109
<DependentUpon>App.xaml</DependentUpon>
109110
<SubType>Code</SubType>
110111
</Compile>
112+
<Compile Include="ViewModels\UtilViewModel.cs" />
111113
<Compile Include="Views\MainWindow.xaml.cs">
112114
<DependentUpon>MainWindow.xaml</DependentUpon>
113115
<SubType>Code</SubType>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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 MahApps.Metro;
8+
using UnityMultiLauncher.ViewModels.Utils;
9+
10+
namespace UnityMultiLauncher.ViewModels
11+
{
12+
class StyleViewModel : ViewModel
13+
{
14+
public IEnumerable<string> appTheme
15+
{
16+
get
17+
{
18+
return ThemeManager.AppThemes.Select(theme => theme.Name);
19+
}
20+
}
21+
22+
public IEnumerable<string> appAccent
23+
{
24+
get
25+
{
26+
return ThemeManager.Accents.Select(accent => accent.Name);
27+
}
28+
}
29+
30+
public Tuple<AppTheme, Accent> cTheme
31+
{
32+
get
33+
{
34+
return ThemeManager.DetectAppStyle(Application.Current);
35+
}
36+
set
37+
{
38+
ThemeManager.ChangeAppStyle(Application.Current, value.Item2, value.Item1);
39+
//ThemeManager.GetAccent(ProgramConfig.conf.AccentColor), ThemeManager.GetAppTheme("BaseLight")
40+
ProgramConfig.conf.appStyle = value;
41+
ProgramConfig.conf.Save();
42+
}
43+
}
44+
45+
public int appThemeSelected
46+
{
47+
get
48+
{
49+
return appTheme.ToList().IndexOf(cTheme.Item1.Name);
50+
}
51+
set
52+
{
53+
cTheme = Tuple.Create(
54+
ThemeManager.GetAppTheme(appTheme.ToList()[value]),
55+
ThemeManager.GetAccent(appAccent.ToList()[appAccentSelected])
56+
);
57+
}
58+
}
59+
60+
public int appAccentSelected
61+
{
62+
get
63+
{
64+
return appAccent.ToList().IndexOf(cTheme.Item2.Name);
65+
}
66+
set
67+
{
68+
cTheme = Tuple.Create(
69+
ThemeManager.GetAppTheme(appTheme.ToList()[appThemeSelected]),
70+
ThemeManager.GetAccent(appAccent.ToList()[value])
71+
);
72+
}
73+
}
74+
}
75+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using UnityMultiLauncher.ViewModels.Utils;
7+
8+
namespace UnityMultiLauncher.ViewModels
9+
{
10+
public class UtilViewModel : Utils.ViewModel
11+
{
12+
protected void ToggleFlyout(object param)
13+
{
14+
if (param is MahApps.Metro.Controls.Flyout)
15+
{
16+
var fl = (param as MahApps.Metro.Controls.Flyout);
17+
fl.IsOpen = !fl.IsOpen;
18+
}
19+
20+
}
21+
22+
23+
public Utils.ViewCommand OpenFlyout
24+
{
25+
get
26+
{
27+
return GetProperty() as ViewCommand ?? SetProperty(new ViewCommand(ToggleFlyout));
28+
}
29+
}
30+
}
31+
}

UnityMultiLauncher/Views/MainWindow.xaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,32 @@
1111
Width="800" >
1212
<Controls:MetroWindow.Resources>
1313
<VM:UnityViewModel x:Key="unity"/>
14+
<VM:UtilViewModel x:Key="util"/>
15+
<VM:StyleViewModel x:Key="stylevm"></VM:StyleViewModel>
1416
<Converter:UnityUriToUnityVersion x:Key="uriToVersion"/>
1517
</Controls:MetroWindow.Resources>
1618

1719
<Controls:MetroWindow.RightWindowCommands>
1820
<Controls:WindowCommands>
1921
<Button Content="Add Unity Executable" Command="{Binding addUnityVersion, Mode=OneWay, Source={StaticResource unity}}" CommandParameter="{Binding ElementName=metroWindow, Mode=OneWay}" />
22+
<Button Content="Settings" Command="{Binding Source={StaticResource util}, Path=OpenFlyout}" CommandParameter="{Binding ElementName=SettingsFlyout, Mode=OneWay}"></Button>
2023
</Controls:WindowCommands>
2124
</Controls:MetroWindow.RightWindowCommands>
2225

26+
<Controls:MetroWindow.Flyouts>
27+
<Controls:FlyoutsControl>
28+
<Controls:Flyout x:Name="SettingsFlyout" Header="Settings" Position="Right" IsOpen="False" HorizontalAlignment="Left" Margin="0" Padding="10,70,50,0" >
29+
<StackPanel>
30+
<Label>App Theme</Label>
31+
<ComboBox ItemsSource="{Binding appTheme, Source={StaticResource stylevm}}" SelectedIndex="{Binding appThemeSelected, Source={StaticResource stylevm}}" ></ComboBox>
32+
<Label>App Accent</Label>
33+
<ComboBox ItemsSource="{Binding appAccent, Source={StaticResource stylevm}}" SelectedIndex="{Binding appAccentSelected, Source={StaticResource stylevm}}" ></ComboBox>
34+
</StackPanel>
35+
36+
</Controls:Flyout>
37+
</Controls:FlyoutsControl>
38+
</Controls:MetroWindow.Flyouts>
39+
2340
<Grid>
2441
<Grid.RowDefinitions>
2542
<RowDefinition Height="Auto" />

0 commit comments

Comments
 (0)