diff --git a/DivinityModManagerCore/Models/DivinityModManagerSettings.cs b/DivinityModManagerCore/Models/DivinityModManagerSettings.cs index c7a058d9..83c380e1 100644 --- a/DivinityModManagerCore/Models/DivinityModManagerSettings.cs +++ b/DivinityModManagerCore/Models/DivinityModManagerSettings.cs @@ -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); } + } + } } diff --git a/DivinityModManagerGUI_WPF/Controls/UnfocusableTextBox.cs b/DivinityModManagerGUI_WPF/Controls/UnfocusableTextBox.cs new file mode 100644 index 00000000..9f8f5fee --- /dev/null +++ b/DivinityModManagerGUI_WPF/Controls/UnfocusableTextBox.cs @@ -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(); + } + } + } +} diff --git a/DivinityModManagerGUI_WPF/DivinityModManagerGUI_WPF.csproj b/DivinityModManagerGUI_WPF/DivinityModManagerGUI_WPF.csproj index 62ca3bb6..d9365db8 100644 --- a/DivinityModManagerGUI_WPF/DivinityModManagerGUI_WPF.csproj +++ b/DivinityModManagerGUI_WPF/DivinityModManagerGUI_WPF.csproj @@ -14,6 +14,7 @@ 4 true true + false publish\ true Disk @@ -24,9 +25,8 @@ false false true - 0 + 5 1.1.0.%2a - false false true @@ -108,6 +108,9 @@ + + ..\packages\WpfAutoGrid.1.4.0.0\lib\net45\WpfAutoGrid.dll + @@ -115,6 +118,7 @@ Designer + @@ -124,6 +128,9 @@ HorizontalModLayout.xaml + + SettingsWindow.xaml + VerticalModLayout.xaml @@ -152,6 +159,10 @@ MainWindow.xaml Code + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/DivinityModManagerGUI_WPF/Properties/AssemblyInfo.cs b/DivinityModManagerGUI_WPF/Properties/AssemblyInfo.cs index a066a1e3..15986d94 100644 --- a/DivinityModManagerGUI_WPF/Properties/AssemblyInfo.cs +++ b/DivinityModManagerGUI_WPF/Properties/AssemblyInfo.cs @@ -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")] diff --git a/DivinityModManagerGUI_WPF/ViewModels/MainWindowViewModel.cs b/DivinityModManagerGUI_WPF/ViewModels/MainWindowViewModel.cs index 118aeac9..dd7b5ace 100644 --- a/DivinityModManagerGUI_WPF/ViewModels/MainWindowViewModel.cs +++ b/DivinityModManagerGUI_WPF/ViewModels/MainWindowViewModel.cs @@ -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 mods = new SourceCache(m => m.UUID); @@ -214,6 +214,7 @@ public void AddMods(IEnumerable newMods) private bool LoadSettings() { + bool loaded = false; string settingsFile = @"Data\settings.json"; try { @@ -223,6 +224,7 @@ private bool LoadSettings() { var fileText = reader.ReadToEnd(); Settings = JsonConvert.DeserializeObject(fileText); + loaded = Settings != null; } } } @@ -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() @@ -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) diff --git a/DivinityModManagerGUI_WPF/Views/MainWindow.xaml b/DivinityModManagerGUI_WPF/Views/MainWindow.xaml index d4d569a9..0f785979 100644 --- a/DivinityModManagerGUI_WPF/Views/MainWindow.xaml +++ b/DivinityModManagerGUI_WPF/Views/MainWindow.xaml @@ -43,10 +43,13 @@ - - - + + + + diff --git a/DivinityModManagerGUI_WPF/Views/MainWindow.xaml.cs b/DivinityModManagerGUI_WPF/Views/MainWindow.xaml.cs index 0955c7a5..3341ae7b 100644 --- a/DivinityModManagerGUI_WPF/Views/MainWindow.xaml.cs +++ b/DivinityModManagerGUI_WPF/Views/MainWindow.xaml.cs @@ -83,6 +83,9 @@ public partial class MainWindow : ReactiveWindow private ConflictCheckerWindow conflictCheckerWindow; public ConflictCheckerWindow ConflictCheckerWindow => conflictCheckerWindow; + private SettingsWindow settingsWindow; + public SettingsWindow SettingsWindow => settingsWindow; + public MainWindow() { InitializeComponent(); @@ -105,6 +108,9 @@ public MainWindow() self = this; + settingsWindow = new SettingsWindow(); + SettingsWindow.Hide(); + ViewModel = new MainWindowViewModel(); this.OneWayBind(ViewModel, @@ -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; @@ -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(); + } + } } } diff --git a/DivinityModManagerGUI_WPF/Views/SettingsWindow.xaml b/DivinityModManagerGUI_WPF/Views/SettingsWindow.xaml new file mode 100644 index 00000000..3a3ee81a --- /dev/null +++ b/DivinityModManagerGUI_WPF/Views/SettingsWindow.xaml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + +