Skip to content

Commit

Permalink
Added a settings window, display the version in the main window title
Browse files Browse the repository at this point in the history
  • Loading branch information
LaughingLeader committed Nov 25, 2019
1 parent 8843ac7 commit 9778327
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 17 deletions.
31 changes: 26 additions & 5 deletions DivinityModManagerCore/Models/DivinityModManagerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,49 @@
using System.Linq;
using System.Reactive.Linq;
using Newtonsoft.Json;
using System.Runtime.Serialization;
using System.Windows.Input;

namespace DivinityModManager.Models
{
[JsonObject(MemberSerialization.OptIn)]
[DataContract]
public class DivinityModManagerSettings : ReactiveObject
{
private string gameDataPath = "";

[JsonProperty]
[DataMember]
public string GameDataPath
{
get => gameDataPath;
set { this.RaiseAndSetIfChanged(ref gameDataPath, value); }
set
{
if (value != gameDataPath) CanSaveSettings = true;
this.RaiseAndSetIfChanged(ref gameDataPath, value);
}
}

private string loadOrderPath = "";

[JsonProperty]
[DataMember]
public string LoadOrderPath
{
get => loadOrderPath;
set { this.RaiseAndSetIfChanged(ref loadOrderPath, value); }
set
{
if (value != loadOrderPath) CanSaveSettings = true;
this.RaiseAndSetIfChanged(ref loadOrderPath, value);
}
}

public ICommand SaveSettingsCommand { get; set; }

private bool canSaveSettings = false;

public bool CanSaveSettings
{
get => canSaveSettings;
set { this.RaiseAndSetIfChanged(ref canSaveSettings, value); }
}

}
}
27 changes: 27 additions & 0 deletions DivinityModManagerGUI_WPF/Controls/UnfocusableTextBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Input;

namespace DivinityModManager.Controls
{
public partial class UnfocusableTextBox : TextBox
{
public UnfocusableTextBox()
{
//InitializeComponent();
}

protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if (e.Key == Key.Return)
{
Keyboard.ClearFocus();
}
}
}
}
15 changes: 13 additions & 2 deletions DivinityModManagerGUI_WPF/DivinityModManagerGUI_WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
Expand All @@ -24,9 +25,8 @@
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationRevision>5</ApplicationRevision>
<ApplicationVersion>1.1.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
Expand Down Expand Up @@ -108,13 +108,17 @@
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="WpfAutoGrid, Version=1.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\WpfAutoGrid.1.4.0.0\lib\net45\WpfAutoGrid.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Controls\AutoGrayableImage.cs" />
<Compile Include="Controls\UnfocusableTextBox.cs" />
<Compile Include="Converters\ModIsAvailableConverter.cs" />
<Compile Include="ViewModels\ConflictCheckerWindowViewModel.cs" />
<Compile Include="ViewModels\MainWindowViewModel.cs" />
Expand All @@ -124,6 +128,9 @@
<Compile Include="Views\HorizontalModLayout.xaml.cs">
<DependentUpon>HorizontalModLayout.xaml</DependentUpon>
</Compile>
<Compile Include="Views\SettingsWindow.xaml.cs">
<DependentUpon>SettingsWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Views\VerticalModLayout.xaml.cs">
<DependentUpon>VerticalModLayout.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -152,6 +159,10 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="Views\SettingsWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\VerticalModLayout.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
4 changes: 2 additions & 2 deletions DivinityModManagerGUI_WPF/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.5")]
[assembly: AssemblyFileVersion("1.1.0.5")]
19 changes: 15 additions & 4 deletions DivinityModManagerGUI_WPF/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ override public void Drop(IDropInfo dropInfo)

public class MainWindowViewModel : BaseHistoryViewModel
{
public string Title => "Divinity Mod Manager 1.0.0.0";
public string Title => "Divinity Mod Manager " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

protected SourceCache<DivinityModData, string> mods = new SourceCache<DivinityModData, string>(m => m.UUID);

Expand Down Expand Up @@ -214,6 +214,7 @@ public void AddMods(IEnumerable<DivinityModData> newMods)

private bool LoadSettings()
{
bool loaded = false;
string settingsFile = @"Data\settings.json";
try
{
Expand All @@ -223,6 +224,7 @@ private bool LoadSettings()
{
var fileText = reader.ReadToEnd();
Settings = JsonConvert.DeserializeObject<DivinityModManagerSettings>(fileText);
loaded = Settings != null;
}
}
}
Expand All @@ -231,16 +233,23 @@ private bool LoadSettings()
Trace.WriteLine($"Error loading settings at '{settingsFile}': {ex.ToString()}");
Settings = null;
}


if (Settings == null)
{
Settings = new DivinityModManagerSettings();
SaveSettings();
}
else

if (Settings.SaveSettingsCommand == null)
{
return true;
var canSaveSettings = Settings.WhenAnyValue(m => m.CanSaveSettings);
Settings.SaveSettingsCommand = ReactiveCommand.Create(SaveSettings, canSaveSettings);
}
return false;

if (loaded) Settings.CanSaveSettings = false;

return loaded;
}

public bool SaveSettings()
Expand All @@ -253,6 +262,8 @@ public bool SaveSettings()

string contents = JsonConvert.SerializeObject(Settings, Newtonsoft.Json.Formatting.Indented);
File.WriteAllText(settingsFile, contents);
StatusText = $"Saved settings to {settingsFile}";
Settings.CanSaveSettings = false;
return true;
}
catch (Exception ex)
Expand Down
9 changes: 6 additions & 3 deletions DivinityModManagerGUI_WPF/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Menu x:Name="TopMenuBar">
<MenuItem Header="Tools">
<MenuItem x:Name="ConflictCheckerMenuItem" Header="Conflict Checker" />
<Menu x:Name="TopMenuBar" Padding="2">
<MenuItem Header="Settings">
<MenuItem x:Name="Settings_Preferences_MenuItem" Header="Preferences" Click="Settings_Preferences_MenuItem_Click" />
</MenuItem>
<!--<MenuItem Header="Tools">
<MenuItem x:Name="ConflictCheckerMenuItem" Header="Conflict Checker" />
</MenuItem>-->
</Menu>
<Grid Grid.Row="1" Margin="4">
<Grid.ColumnDefinitions>
Expand Down
31 changes: 30 additions & 1 deletion DivinityModManagerGUI_WPF/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public partial class MainWindow : ReactiveWindow<MainWindowViewModel>
private ConflictCheckerWindow conflictCheckerWindow;
public ConflictCheckerWindow ConflictCheckerWindow => conflictCheckerWindow;

private SettingsWindow settingsWindow;
public SettingsWindow SettingsWindow => settingsWindow;

public MainWindow()
{
InitializeComponent();
Expand All @@ -105,6 +108,9 @@ public MainWindow()

self = this;

settingsWindow = new SettingsWindow();
SettingsWindow.Hide();

ViewModel = new MainWindowViewModel();

this.OneWayBind(ViewModel,
Expand All @@ -127,7 +133,7 @@ public MainWindow()
this.Bind(ViewModel, vm => vm.SelectedModOrderIndex, view => view.OrdersComboBox.SelectedIndex).DisposeWith(ViewModel.Disposables);

//Menu Items
this.OneWayBind(ViewModel, vm => vm.OpenConflictCheckerCommand, view => view.ConflictCheckerMenuItem.Command).DisposeWith(ViewModel.Disposables);
//this.OneWayBind(ViewModel, vm => vm.OpenConflictCheckerCommand, view => view.ConflictCheckerMenuItem.Command).DisposeWith(ViewModel.Disposables);

DataContext = ViewModel;

Expand Down Expand Up @@ -177,5 +183,28 @@ private void ComboBox_KeyDown_LoseFocus(object sender, KeyEventArgs e)
e.Handled = true;
}
}

private void MenuItem_Click(object sender, RoutedEventArgs e)
{

}

private void Settings_Preferences_MenuItem_Click(object sender, RoutedEventArgs e)
{
if(!SettingsWindow.IsVisible)
{
if (SettingsWindow == null)
{
settingsWindow = new SettingsWindow();
}
SettingsWindow.Init(this.ViewModel.Settings);
SettingsWindow.Show();
settingsWindow.Owner = this;
}
else
{
SettingsWindow.Hide();
}
}
}
}
44 changes: 44 additions & 0 deletions DivinityModManagerGUI_WPF/Views/SettingsWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<reactiveui:ReactiveWindow x:Class="DivinityModManager.Views.SettingsWindow"
x:TypeArguments="data:DivinityModManagerSettings"
xmlns:reactiveui="http://reactiveui.net"
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:DivinityModManager.Views"
xmlns:c="clr-namespace:DivinityModManager.Controls"
xmlns:conv="clr-namespace:DivinityModManager.Converters"
xmlns:vm="clr-namespace:DivinityModManager.ViewModels"
xmlns:data="clr-namespace:DivinityModManager.Models;assembly=DivinityModManagerCore"
xmlns:dd="urn:gong-wpf-dragdrop"
xmlns:autogrid="clr-namespace:WpfAutoGrid;assembly=WpfAutoGrid"
mc:Ignorable="d"
Title="Preferences" Height="450" Width="600">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TabControl>
<TabItem Header="General">
<autogrid:AutoGrid
ColumnCount="2"
Columns="auto,*"
ChildMargin="2"
Margin="20"
RowHeight="*"
RowCount="3"
Rows="auto,auto"
>
<Label Content="Game Data Path:" ToolTip="The path to the DOS2DE Data folder, for loading editor mods.&#x0a;Example: Divinity Original Sin 2/DefEd/Data"/>
<c:UnfocusableTextBox Text="{Binding GameDataPath, UpdateSourceTrigger=PropertyChanged, FallbackValue='Path'}" TextAlignment="Left" VerticalAlignment="Center" />
<Label Content="Saved Load Orders Path:" ToolTip="The folder to save and load load orders to." />
<c:UnfocusableTextBox Text="{Binding LoadOrderPath, UpdateSourceTrigger=PropertyChanged, FallbackValue='Load Order'}" TextAlignment="Left" VerticalAlignment="Center" />
</autogrid:AutoGrid>
</TabItem>
</TabControl>
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="10">
<Button x:Name="SaveSettingsButton" Content="Save" Padding="20,2" Command="{Binding SaveSettingsCommand}" />
</StackPanel>
</Grid>
</reactiveui:ReactiveWindow>
45 changes: 45 additions & 0 deletions DivinityModManagerGUI_WPF/Views/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using DivinityModManager.Models;
using DivinityModManager.Util;
using DivinityModManager.ViewModels;
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Reactive.Disposables;
using DynamicData;
using DynamicData.Binding;
using System.Diagnostics;
using System.Globalization;

namespace DivinityModManager.Views
{
/// <summary>
/// Interaction logic for SettingsWindow.xaml
/// </summary>
public partial class SettingsWindow : ReactiveWindow<DivinityModManagerSettings>
{
public SettingsWindow()
{
InitializeComponent();
}

public void Init(DivinityModManagerSettings vm)
{
ViewModel = vm;
DataContext = ViewModel;

this.OneWayBind(ViewModel, x => x.SaveSettingsCommand, view => view.SaveSettingsButton.Command);
}
}
}
1 change: 1 addition & 0 deletions DivinityModManagerGUI_WPF/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net472" />
<package id="System.Threading.Tasks.Extensions" version="4.5.3" targetFramework="net472" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
<package id="WpfAutoGrid" version="1.4.0.0" targetFramework="net472" />
</packages>

0 comments on commit 9778327

Please sign in to comment.