diff --git a/Artemis/Artemis/App.config b/Artemis/Artemis/App.config index 81ce6d60e..9c9c880e7 100644 --- a/Artemis/Artemis/App.config +++ b/Artemis/Artemis/App.config @@ -224,7 +224,7 @@ TypeWave - Logitech G910 RGB + True @@ -238,6 +238,12 @@ False + + True + + + True + diff --git a/Artemis/Artemis/Managers/EffectManager.cs b/Artemis/Artemis/Managers/EffectManager.cs index 15107b191..6f899fdda 100644 --- a/Artemis/Artemis/Managers/EffectManager.cs +++ b/Artemis/Artemis/Managers/EffectManager.cs @@ -12,6 +12,8 @@ namespace Artemis.Managers { private readonly IEventAggregator _events; private readonly MainManager _mainManager; + private bool _clearing; + private EffectModel _pauseEffect; public EffectManager(MainManager mainManager, IEventAggregator events) { @@ -23,7 +25,6 @@ namespace Artemis.Managers public List EffectModels { get; set; } public EffectModel ActiveEffect { get; private set; } - public EffectModel PauseEffect { get; private set; } public IEnumerable EnabledOverlays { @@ -83,27 +84,27 @@ namespace Artemis.Managers private void ChangeEffectWithPause(EffectModel effectModel) { - if (PauseEffect != null) + if (_pauseEffect != null) return; - PauseEffect = effectModel; + _pauseEffect = effectModel; _mainManager.Pause(); - _mainManager.PauseCallback += MainManagerOnPauseCallback; + _mainManager.PauseCallback += ChangeEffectPauseCallback; } - private void MainManagerOnPauseCallback() + private void ChangeEffectPauseCallback() { // Change effect logic ActiveEffect?.Dispose(); - ActiveEffect = PauseEffect; + ActiveEffect = _pauseEffect; ActiveEffect.Enable(); // Let the ViewModels know _events.PublishOnUIThread(new ActiveEffectChanged(ActiveEffect.Name)); - PauseEffect = null; _mainManager.Unpause(); + _pauseEffect = null; if (ActiveEffect is GameModel) return; @@ -118,18 +119,32 @@ namespace Artemis.Managers /// public void ClearEffect() { + if (_clearing) + return; + // Don't mess with the ActiveEffect if in the process of changing the effect. - if (PauseEffect != null) + if (_pauseEffect != null) return; if (ActiveEffect == null) return; + _clearing = true; + + _mainManager.Pause(); + _mainManager.PauseCallback += ClearEffectPauseCallback; + } + + private void ClearEffectPauseCallback() + { ActiveEffect.Dispose(); ActiveEffect = null; General.Default.LastEffect = null; General.Default.Save(); + + _clearing = false; + _mainManager.Unpause(); } /// diff --git a/Artemis/Artemis/Managers/KeyboardManager.cs b/Artemis/Artemis/Managers/KeyboardManager.cs index f17687b39..3097b4c05 100644 --- a/Artemis/Artemis/Managers/KeyboardManager.cs +++ b/Artemis/Artemis/Managers/KeyboardManager.cs @@ -9,6 +9,7 @@ namespace Artemis.Managers public class KeyboardManager { private readonly MainManager _mainManager; + private KeyboardProvider _pauseKeyboard; public KeyboardManager(MainManager mainManager) { @@ -19,29 +20,41 @@ namespace Artemis.Managers public List KeyboardProviders { get; set; } public KeyboardProvider ActiveKeyboard { get; set; } - public bool LoadLastKeyboard() + /// + /// Enables the last keyboard according to the settings file + /// + public void EnableLastKeyboard() { + if (General.Default.LastKeyboard == null) + return; + if (General.Default.LastKeyboard == "") + return; + var keyboard = KeyboardProviders.FirstOrDefault(k => k.Name == General.Default.LastKeyboard); - return ChangeKeyboard(keyboard ?? KeyboardProviders.First()); + EnableKeyboard(keyboard); } - public bool ChangeKeyboard(KeyboardProvider keyboardProvider) + /// + /// Enables the given keyboard + /// + /// + public void EnableKeyboard(KeyboardProvider keyboardProvider) { + ReleaseActiveKeyboard(); + if (keyboardProvider == null) - return false; + return; if (ActiveKeyboard != null) if (keyboardProvider.Name == ActiveKeyboard.Name) - return true; - - ReleaseActiveKeyboard(); + return; // Disable everything if there's no active keyboard found if (!keyboardProvider.CanEnable()) { MessageBox.Show(keyboardProvider.CantEnableText, "Artemis (╯°□°)╯︵ ┻━┻", MessageBoxButtons.OK, MessageBoxIcon.Warning); - return false; + return; } ActiveKeyboard = keyboardProvider; @@ -49,10 +62,11 @@ namespace Artemis.Managers General.Default.LastKeyboard = ActiveKeyboard.Name; General.Default.Save(); - - return true; } + /// + /// Releases the active keyboard + /// public void ReleaseActiveKeyboard() { if (ActiveKeyboard == null) @@ -61,5 +75,20 @@ namespace Artemis.Managers ActiveKeyboard.Disable(); ActiveKeyboard = null; } + + /// + /// Changes the active keyboard + /// + /// + public void ChangeKeyboard(KeyboardProvider keyboardProvider) + { + if (keyboardProvider == ActiveKeyboard) + return; + + General.Default.LastKeyboard = keyboardProvider?.Name; + General.Default.Save(); + + _mainManager.Restart(); + } } } \ No newline at end of file diff --git a/Artemis/Artemis/Managers/MainManager.cs b/Artemis/Artemis/Managers/MainManager.cs index 9e0ca8ef4..762a8823e 100644 --- a/Artemis/Artemis/Managers/MainManager.cs +++ b/Artemis/Artemis/Managers/MainManager.cs @@ -16,6 +16,7 @@ namespace Artemis.Managers private readonly int _fps; private bool _paused; + private bool _restarting; public MainManager(IEventAggregator events) { @@ -78,7 +79,8 @@ namespace Artemis.Managers return true; // Only continue if a keyboard was loaded - if (!KeyboardManager.LoadLastKeyboard()) + KeyboardManager.EnableLastKeyboard(); + if (KeyboardManager.ActiveKeyboard == null) return false; Running = true; @@ -128,6 +130,41 @@ namespace Artemis.Managers PauseCallback = null; } + public void Shutdown() + { + Stop(); + ProcessWorker.CancelAsync(); + GameStateWebServer.Stop(); + } + + public void Restart() + { + if (_restarting) + return; + if (!Running) + { + Start(); + return; + } + + _restarting = true; + + UpdateWorker.RunWorkerCompleted += FinishRestart; + Stop(); + } + + public void FinishRestart(object sender, RunWorkerCompletedEventArgs e) + { + UpdateWorker.RunWorkerCompleted -= FinishRestart; + + if (e.Error != null) + return; + + Start(); + + _restarting = false; + } + /// /// Loads the last active effect and starts the program /// @@ -148,13 +185,6 @@ namespace Artemis.Managers Events.PublishOnUIThread(new ToggleEnabled(ProgramEnabled)); } - public void Shutdown() - { - Stop(); - ProcessWorker.CancelAsync(); - GameStateWebServer.Stop(); - } - #region Workers private void UpdateWorker_DoWork(object sender, DoWorkEventArgs e) diff --git a/Artemis/Artemis/Settings/General.Designer.cs b/Artemis/Artemis/Settings/General.Designer.cs index 86d434e1e..93f796c4e 100644 --- a/Artemis/Artemis/Settings/General.Designer.cs +++ b/Artemis/Artemis/Settings/General.Designer.cs @@ -1,98 +1,122 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Artemis.Settings { - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] - internal sealed partial class General : global::System.Configuration.ApplicationSettingsBase { - - private static General defaultInstance = ((General)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new General()))); - - public static General Default { - get { - return defaultInstance; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("TypeWave")] - public string LastEffect { - get { - return ((string)(this["LastEffect"])); - } - set { - this["LastEffect"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("Logitech G910 RGB")] - public string LastKeyboard { - get { - return ((string)(this["LastKeyboard"])); - } - set { - this["LastKeyboard"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("True")] - public bool EnablePointersUpdate { - get { - return ((bool)(this["EnablePointersUpdate"])); - } - set { - this["EnablePointersUpdate"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("51364")] - public int GamestatePort { - get { - return ((int)(this["GamestatePort"])); - } - set { - this["GamestatePort"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("True")] - public bool Autorun { - get { - return ((bool)(this["Autorun"])); - } - set { - this["Autorun"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("False")] - public bool Suspended { - get { - return ((bool)(this["Suspended"])); - } - set { - this["Suspended"] = value; - } - } - } -} +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Artemis.Settings { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] + internal sealed partial class General : global::System.Configuration.ApplicationSettingsBase { + + private static General defaultInstance = ((General)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new General()))); + + public static General Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("TypeWave")] + public string LastEffect { + get { + return ((string)(this["LastEffect"])); + } + set { + this["LastEffect"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string LastKeyboard { + get { + return ((string)(this["LastKeyboard"])); + } + set { + this["LastKeyboard"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool EnablePointersUpdate { + get { + return ((bool)(this["EnablePointersUpdate"])); + } + set { + this["EnablePointersUpdate"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("51364")] + public int GamestatePort { + get { + return ((int)(this["GamestatePort"])); + } + set { + this["GamestatePort"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool Autorun { + get { + return ((bool)(this["Autorun"])); + } + set { + this["Autorun"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool Suspended { + get { + return ((bool)(this["Suspended"])); + } + set { + this["Suspended"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool ShowOnStartup { + get { + return ((bool)(this["ShowOnStartup"])); + } + set { + this["ShowOnStartup"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool CheckForUpdates { + get { + return ((bool)(this["CheckForUpdates"])); + } + set { + this["CheckForUpdates"] = value; + } + } + } +} diff --git a/Artemis/Artemis/Settings/General.settings b/Artemis/Artemis/Settings/General.settings index 316fbf0d1..975d221fa 100644 --- a/Artemis/Artemis/Settings/General.settings +++ b/Artemis/Artemis/Settings/General.settings @@ -1,26 +1,30 @@ - - - - - - - TypeWave - - - Logitech G910 RGB - - - True - - - 51364 - - - True - - - False - - + + + + + + TypeWave + + + + + + True + + + 51364 + + + True + + + False + + + True + + + True + + \ No newline at end of file diff --git a/Artemis/Artemis/Settings/GeneralSettings.cs b/Artemis/Artemis/Settings/GeneralSettings.cs index b46e6d97d..3283a0119 100644 --- a/Artemis/Artemis/Settings/GeneralSettings.cs +++ b/Artemis/Artemis/Settings/GeneralSettings.cs @@ -38,6 +38,26 @@ namespace Artemis.Settings } } + public bool CheckForUpdates + { + get { return General.Default.CheckForUpdates; } + set + { + if (General.Default.CheckForUpdates == value) return; + General.Default.CheckForUpdates = value; + } + } + + public bool ShowOnStartup + { + get { return General.Default.ShowOnStartup; } + set + { + if (General.Default.ShowOnStartup == value) return; + General.Default.ShowOnStartup = value; + } + } + private void ApplyGamestatePort() { // TODO: Restart Gamestate server with new port @@ -71,6 +91,8 @@ namespace Artemis.Settings GamestatePort = 51364; EnablePointersUpdate = true; Autorun = true; + CheckForUpdates = true; + ShowOnStartup = true; SaveSettings(); } diff --git a/Artemis/Artemis/ViewModels/Flyouts/FlyoutSettingsViewModel.cs b/Artemis/Artemis/ViewModels/Flyouts/FlyoutSettingsViewModel.cs index f7b4802c1..cd55b25e8 100644 --- a/Artemis/Artemis/ViewModels/Flyouts/FlyoutSettingsViewModel.cs +++ b/Artemis/Artemis/ViewModels/Flyouts/FlyoutSettingsViewModel.cs @@ -38,7 +38,15 @@ namespace Artemis.ViewModels.Flyouts public MainManager MainManager { get; set; } public BindableCollection KeyboardProviders - => new BindableCollection(MainManager.KeyboardManager.KeyboardProviders.Select(k => k.Name)); + { + get + { + var collection = new BindableCollection(MainManager.KeyboardManager.KeyboardProviders + .Select(k => k.Name)); + collection.Insert(0, "None"); + return collection; + } + } public string SelectedKeyboardProvider { @@ -52,7 +60,8 @@ namespace Artemis.ViewModels.Flyouts return; MainManager.KeyboardManager.ChangeKeyboard( - MainManager.KeyboardManager.KeyboardProviders.First(k => k.Name == _selectedKeyboardProvider)); + MainManager.KeyboardManager.KeyboardProviders.FirstOrDefault( + k => k.Name == _selectedKeyboardProvider)); } } @@ -99,7 +108,9 @@ namespace Artemis.ViewModels.Flyouts protected override void HandleOpen() { - SelectedKeyboardProvider = MainManager.KeyboardManager.ActiveKeyboard?.Name; + SelectedKeyboardProvider = MainManager.KeyboardManager.ActiveKeyboard != null + ? MainManager.KeyboardManager.ActiveKeyboard.Name + : "None"; } } } \ No newline at end of file diff --git a/Artemis/Artemis/ViewModels/ShellViewModel.cs b/Artemis/Artemis/ViewModels/ShellViewModel.cs index c545250c1..3f0a2602b 100644 --- a/Artemis/Artemis/ViewModels/ShellViewModel.cs +++ b/Artemis/Artemis/ViewModels/ShellViewModel.cs @@ -47,5 +47,10 @@ namespace Artemis.ViewModels { Flyouts.First().IsOpen = !Flyouts.First().IsOpen; } + + public void CloseSettings() + { + Flyouts.First().IsOpen = false; + } } } \ No newline at end of file diff --git a/Artemis/Artemis/Views/ShellView.xaml b/Artemis/Artemis/Views/ShellView.xaml index 36ddcfe35..de8d4ae0d 100644 --- a/Artemis/Artemis/Views/ShellView.xaml +++ b/Artemis/Artemis/Views/ShellView.xaml @@ -62,7 +62,7 @@ - +