From b01ab9b135e893d2582aa8da33420c50f5054269 Mon Sep 17 00:00:00 2001 From: Robert Beekman Date: Sun, 8 May 2016 00:53:56 +0200 Subject: [PATCH] Moving to Ninject dependency injection WIP --- Artemis/Artemis/App.config | 59 ++++++++++---- Artemis/Artemis/Artemis.csproj | 11 +-- Artemis/Artemis/ArtemisBootstrapper.cs | 3 +- Artemis/Artemis/DAL/ProfileProvider.cs | 4 +- .../BindableSelectedItemBehavior.cs | 2 +- Artemis/Artemis/Managers/EffectManager.cs | 30 +++---- Artemis/Artemis/Managers/KeyboardManager.cs | 17 ++-- Artemis/Artemis/Managers/MainManager.cs | 78 ++++++++++--------- Artemis/Artemis/Models/EffectModel.cs | 5 +- Artemis/Artemis/Models/GameModel.cs | 3 +- Artemis/Artemis/Models/OverlayModel.cs | 16 +--- .../Profiles/LayerDynamicPropertiesModel.cs | 4 +- .../Models/Profiles/LayerPropertiesModel.cs | 8 +- .../AmbientLightningEffectModel.cs | 16 ++-- .../AmbientLightningEffectViewModel.cs | 23 +++--- .../Effects/AmbientLightning/ScreenCapture.cs | 2 +- .../AudioVisualizer/AudioVisualizerModel.cs | 13 ++-- .../AudioVisualizerViewModel.cs | 22 +++--- .../Modules/Effects/Debug/DebugEffectModel.cs | 5 +- .../Effects/Debug/DebugEffectViewModel.cs | 30 +++---- .../ProfilePreview/ProfilePreviewModel.cs | 7 +- .../Modules/Effects/TypeHole/TypeHoleModel.cs | 40 ---------- .../Effects/TypeHole/TypeHoleView.xaml | 49 ------------ .../Effects/TypeHole/TypeHoleView.xaml.cs | 15 ---- .../Effects/TypeHole/TypeHoleViewModel.cs | 28 ------- .../Modules/Effects/TypeWave/TypeWaveModel.cs | 7 +- .../Effects/TypeWave/TypeWaveViewModel.cs | 20 ++--- .../Games/CounterStrike/CounterStrikeModel.cs | 5 +- .../CounterStrike/CounterStrikeViewModel.cs | 16 ++-- .../Artemis/Modules/Games/Dota2/Dota2Model.cs | 37 +++++---- .../Modules/Games/Dota2/Dota2ViewModel.cs | 10 ++- .../Games/RocketLeague/RocketLeagueModel.cs | 5 +- .../RocketLeague/RocketLeagueViewModel.cs | 15 ++-- .../Games/TheDivision/TheDivisionModel.cs | 15 ++-- .../Games/TheDivision/TheDivisionViewModel.cs | 14 ++-- .../Modules/Games/Witcher3/Witcher3Model.cs | 7 +- .../Games/Witcher3/Witcher3ViewModel.cs | 16 ++-- .../Overlays/VolumeDisplay/VolumeDisplay.cs | 12 +-- .../VolumeDisplay/VolumeDisplayModel.cs | 7 +- .../VolumeDisplay/VolumeDisplayViewModel.cs | 12 +-- .../Artemis/NinjectModules/ArtemisModules.cs | 8 +- Artemis/Artemis/NinjectModules/BaseModules.cs | 20 +++++ Artemis/Artemis/Properties/Annotations.cs | 2 +- .../Artemis/Services/MetroDialogService.cs | 1 - Artemis/Artemis/Utilities/GeneralHelpers.cs | 4 +- Artemis/Artemis/Utilities/LayerDrawer.cs | 11 +-- .../ViewModels/Abstract/BaseViewModel.cs | 8 ++ .../ViewModels/Abstract/EffectViewModel.cs | 19 +++-- .../ViewModels/Abstract/GameViewModel.cs | 33 ++++---- .../ViewModels/Abstract/OverlayViewModel.cs | 9 ++- .../Artemis/ViewModels/EffectsViewModel.cs | 31 ++------ .../Flyouts/FlyoutSettingsViewModel.cs | 13 ++-- Artemis/Artemis/ViewModels/GamesViewModel.cs | 30 +------ .../LayerEditor/LayerEditorViewModel.cs | 28 +++---- .../Artemis/ViewModels/OverlaysViewModel.cs | 18 ++--- .../ViewModels/ProfileEditorViewModel.cs | 11 ++- Artemis/Artemis/ViewModels/ShellViewModel.cs | 41 ++++------ .../Artemis/ViewModels/SystemTrayViewModel.cs | 22 ++++-- .../Artemis/ViewModels/WelcomeViewModel.cs | 7 +- Artemis/Artemis/packages.config | 1 + 60 files changed, 454 insertions(+), 551 deletions(-) delete mode 100644 Artemis/Artemis/Modules/Effects/TypeHole/TypeHoleModel.cs delete mode 100644 Artemis/Artemis/Modules/Effects/TypeHole/TypeHoleView.xaml delete mode 100644 Artemis/Artemis/Modules/Effects/TypeHole/TypeHoleView.xaml.cs delete mode 100644 Artemis/Artemis/Modules/Effects/TypeHole/TypeHoleViewModel.cs create mode 100644 Artemis/Artemis/NinjectModules/BaseModules.cs create mode 100644 Artemis/Artemis/ViewModels/Abstract/BaseViewModel.cs diff --git a/Artemis/Artemis/App.config b/Artemis/Artemis/App.config index c2fc93200..9c4523b0b 100644 --- a/Artemis/Artemis/App.config +++ b/Artemis/Artemis/App.config @@ -2,21 +2,50 @@ - -
-
-
-
-
-
-
-
-
-
-
-
-
-
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 948cf327a..a42fa0f09 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -308,7 +308,6 @@ - TypeWave.settings True @@ -372,6 +371,7 @@ + @@ -416,13 +416,13 @@ + - @@ -452,9 +452,6 @@ AudioVisualizerView.xaml - - TypeHoleView.xaml - TypeWaveView.xaml @@ -621,10 +618,6 @@ Designer MSBuild:Compile - - Designer - MSBuild:Compile - Designer MSBuild:Compile diff --git a/Artemis/Artemis/ArtemisBootstrapper.cs b/Artemis/Artemis/ArtemisBootstrapper.cs index 31c692957..719f7fcb8 100644 --- a/Artemis/Artemis/ArtemisBootstrapper.cs +++ b/Artemis/Artemis/ArtemisBootstrapper.cs @@ -6,6 +6,7 @@ using System.Reflection; using System.Windows; using System.Windows.Controls; using System.Windows.Forms; +using Artemis.NinjectModules; using Artemis.ViewModels; using Caliburn.Micro; using Ninject; @@ -72,7 +73,7 @@ namespace Artemis protected override void Configure() { - _kernel = new StandardKernel(); + _kernel = new StandardKernel(new BaseModules(), new ArtemisModules(), new ManagerModules()); _kernel.Bind().To().InSingletonScope(); _kernel.Bind().To().InSingletonScope(); } diff --git a/Artemis/Artemis/DAL/ProfileProvider.cs b/Artemis/Artemis/DAL/ProfileProvider.cs index 0324a344a..2b770e74e 100644 --- a/Artemis/Artemis/DAL/ProfileProvider.cs +++ b/Artemis/Artemis/DAL/ProfileProvider.cs @@ -47,7 +47,7 @@ namespace Artemis.DAL if (!Directory.Exists(path)) Directory.CreateDirectory(path); - var serializer = new XmlSerializer(typeof (ProfileModel)); + var serializer = new XmlSerializer(typeof(ProfileModel)); using (var file = new StreamWriter(path + $@"\{prof.Name}.xml")) { serializer.Serialize(file, prof); @@ -64,7 +64,7 @@ namespace Artemis.DAL // Parse the JSON files into objects and add them if they are valid // TODO: Invalid file handling - var deserializer = new XmlSerializer(typeof (ProfileModel)); + var deserializer = new XmlSerializer(typeof(ProfileModel)); foreach (var path in profilePaths) { using (var file = new StreamReader(path)) diff --git a/Artemis/Artemis/ItemBehaviours/BindableSelectedItemBehavior.cs b/Artemis/Artemis/ItemBehaviours/BindableSelectedItemBehavior.cs index ffb3687ad..595e9e503 100644 --- a/Artemis/Artemis/ItemBehaviours/BindableSelectedItemBehavior.cs +++ b/Artemis/Artemis/ItemBehaviours/BindableSelectedItemBehavior.cs @@ -39,7 +39,7 @@ namespace Artemis.ItemBehaviours } public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register("SelectedItem", - typeof (object), typeof (BindableSelectedItemBehavior), new UIPropertyMetadata(null, OnSelectedItemChanged)); + typeof(object), typeof(BindableSelectedItemBehavior), new UIPropertyMetadata(null, OnSelectedItemChanged)); private static void OnSelectedItemChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { diff --git a/Artemis/Artemis/Managers/EffectManager.cs b/Artemis/Artemis/Managers/EffectManager.cs index 5444454e7..a53ef614a 100644 --- a/Artemis/Artemis/Managers/EffectManager.cs +++ b/Artemis/Artemis/Managers/EffectManager.cs @@ -7,6 +7,7 @@ using Artemis.Models; using Artemis.Modules.Effects.ProfilePreview; using Artemis.Settings; using Caliburn.Micro; +using Ninject; using NLog; using LogManager = NLog.LogManager; @@ -16,21 +17,22 @@ namespace Artemis.Managers { private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private readonly IEventAggregator _events; - private readonly MainManager _mainManager; private EffectModel _activeEffect; private bool _clearing; - public EffectManager(MainManager mainManager, IEventAggregator events) + public EffectManager(IEventAggregator events) { Logger.Info("Intializing EffectManager"); - _mainManager = mainManager; _events = events; EffectModels = new List(); - ProfilePreviewModel = new ProfilePreviewModel(_mainManager); + //ProfilePreviewModel = new ProfilePreviewModel(MainManager.Value); Logger.Info("Intialized EffectManager"); } + [Inject] + public Lazy MainManager { get; set; } + public EffectModel PauseEffect { get; set; } /// @@ -107,14 +109,14 @@ namespace Artemis.Managers Logger.Debug("Changing effect to: {0}, force: {1}", effectModel?.Name, force); // If the main manager is running, pause it and safely change the effect - if (_mainManager.Running) + if (MainManager.Value.Running) { ChangeEffectWithPause(effectModel); return; } // If it's not running start it, and let the next recursion handle changing the effect - _mainManager.Start(effectModel); + MainManager.Value.Start(effectModel); } private void ChangeEffectWithPause(EffectModel effectModel) @@ -137,13 +139,13 @@ namespace Artemis.Managers Logger.Debug("Changing effect with pause: {0}", effectModel?.Name); PauseEffect = effectModel; - _mainManager.Pause(); - _mainManager.PauseCallback += ChangeEffectPauseCallback; + MainManager.Value.Pause(); + MainManager.Value.PauseCallback += ChangeEffectPauseCallback; } private void ChangeEffectPauseCallback() { - _mainManager.PauseCallback -= ChangeEffectPauseCallback; + MainManager.Value.PauseCallback -= ChangeEffectPauseCallback; // Change effect logic ActiveEffect?.Dispose(); @@ -151,7 +153,7 @@ namespace Artemis.Managers ActiveEffect = PauseEffect; ActiveEffect?.Enable(); - _mainManager.Unpause(); + MainManager.Value.Unpause(); PauseEffect = null; Logger.Debug("Finishing change effect with pause"); @@ -180,13 +182,13 @@ namespace Artemis.Managers _clearing = true; Logger.Debug("Clearing active effect"); - _mainManager.Pause(); - _mainManager.PauseCallback += ClearEffectPauseCallback; + MainManager.Value.Pause(); + MainManager.Value.PauseCallback += ClearEffectPauseCallback; } private void ClearEffectPauseCallback() { - _mainManager.PauseCallback -= ClearEffectPauseCallback; + MainManager.Value.PauseCallback -= ClearEffectPauseCallback; if (PauseEffect != null) { Logger.Debug("Cancelling clearing effect"); @@ -202,7 +204,7 @@ namespace Artemis.Managers _clearing = false; Logger.Debug("Finishing clearing active effect"); - _mainManager.Unpause(); + MainManager.Value.Unpause(); } /// diff --git a/Artemis/Artemis/Managers/KeyboardManager.cs b/Artemis/Artemis/Managers/KeyboardManager.cs index 3b6d6288a..03450ac35 100644 --- a/Artemis/Artemis/Managers/KeyboardManager.cs +++ b/Artemis/Artemis/Managers/KeyboardManager.cs @@ -1,9 +1,11 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Artemis.Events; using Artemis.KeyboardProviders; using Artemis.Settings; using Caliburn.Micro; +using Ninject; using NLog; using LogManager = NLog.LogManager; @@ -13,18 +15,21 @@ namespace Artemis.Managers { private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private readonly IEventAggregator _events; - private readonly MainManager _mainManager; private KeyboardProvider _activeKeyboard; - public KeyboardManager(MainManager mainManager, IEventAggregator events) + public KeyboardManager(IEventAggregator events) { Logger.Info("Intializing KeyboardManager"); - _mainManager = mainManager; + _events = events; KeyboardProviders = ProviderHelper.GetKeyboardProviders(); + Logger.Info("Intialized KeyboardManager"); } + [Inject] + public Lazy MainManager { get; set; } + public List KeyboardProviders { get; set; } public KeyboardProvider ActiveKeyboard @@ -74,7 +79,7 @@ namespace Artemis.Managers // Disable everything if there's no active keyboard found if (!keyboardProvider.CanEnable()) { - _mainManager.DialogService.ShowErrorMessageBox(keyboardProvider.CantEnableText); + MainManager.Value.DialogService.ShowErrorMessageBox(keyboardProvider.CantEnableText); General.Default.LastKeyboard = null; General.Default.Save(); return; @@ -116,7 +121,7 @@ namespace Artemis.Managers General.Default.Save(); Logger.Debug("Restarting for keyboard change"); - _mainManager.Restart(); + MainManager.Value.Restart(); } } } \ No newline at end of file diff --git a/Artemis/Artemis/Managers/MainManager.cs b/Artemis/Artemis/Managers/MainManager.cs index 88351ed71..8bb4fc7d8 100644 --- a/Artemis/Artemis/Managers/MainManager.cs +++ b/Artemis/Artemis/Managers/MainManager.cs @@ -1,4 +1,5 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Threading; @@ -8,7 +9,9 @@ using Artemis.Services; using Artemis.Utilities.GameState; using Artemis.Utilities.Keyboard; using Artemis.Utilities.LogitechDll; +using Artemis.ViewModels; using Caliburn.Micro; +using Ninject; using NLog; using LogManager = NLog.LogManager; @@ -19,23 +22,26 @@ namespace Artemis.Managers public delegate void PauseCallbackHandler(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + private readonly EffectManager _effectManager; + private readonly IEventAggregator _events; private readonly int _fps; + private readonly KeyboardManager _keyboardManager; private bool _paused; private bool _restarting; - public MainManager(IEventAggregator events, MetroDialogService dialogService) + public MainManager(IEventAggregator events, KeyboardManager keyboardManager, EffectManager effectManager) { Logger.Info("Intializing MainManager"); - Events = events; - DialogService = dialogService; + _events = events; + _keyboardManager = keyboardManager; + _effectManager = effectManager; + _fps = 25; - KeyboardManager = new KeyboardManager(this, Events); - EffectManager = new EffectManager(this, Events); + //DialogService = dialogService; KeyboardHook = new KeyboardHook(); - _fps = 25; UpdateWorker = new BackgroundWorker {WorkerSupportsCancellation = true}; ProcessWorker = new BackgroundWorker {WorkerSupportsCancellation = true}; @@ -62,18 +68,18 @@ namespace Artemis.Managers Logger.Info("Intialized MainManager"); } + [Inject] + public Lazy ShellViewModel { get; set; } + public PipeServer PipeServer { get; set; } public BackgroundWorker UpdateWorker { get; set; } public BackgroundWorker ProcessWorker { get; set; } - public KeyboardManager KeyboardManager { get; set; } - public EffectManager EffectManager { get; set; } + public MetroDialogService DialogService { get; set; } public KeyboardHook KeyboardHook { get; set; } public GameStateWebServer GameStateWebServer { get; set; } - public IEventAggregator Events { get; set; } - public MetroDialogService DialogService { get; set; } public bool ProgramEnabled { get; private set; } public bool Suspended { get; set; } @@ -98,13 +104,13 @@ namespace Artemis.Managers return true; // Only continue if a keyboard was loaded - KeyboardManager.EnableLastKeyboard(); - if (KeyboardManager.ActiveKeyboard == null) + _keyboardManager.EnableLastKeyboard(); + if (_keyboardManager.ActiveKeyboard == null) return false; Running = true; if (effect != null) - EffectManager.ChangeEffect(effect); + _effectManager.ChangeEffect(effect); // Start the update worker if (!UpdateWorker.IsBusy) @@ -130,7 +136,7 @@ namespace Artemis.Managers private void FinishStop(object sender, RunWorkerCompletedEventArgs e) { UpdateWorker.RunWorkerCompleted -= FinishStop; - KeyboardManager.ReleaseActiveKeyboard(); + _keyboardManager.ReleaseActiveKeyboard(); Running = false; Logger.Debug("Stopped MainManager"); @@ -192,8 +198,8 @@ namespace Artemis.Managers { Logger.Debug("Enabling program"); ProgramEnabled = true; - Start(EffectManager.GetLastEffect()); - Events.PublishOnUIThread(new ToggleEnabled(ProgramEnabled)); + Start(_effectManager.GetLastEffect()); + _events.PublishOnUIThread(new ToggleEnabled(ProgramEnabled)); } /// @@ -204,7 +210,7 @@ namespace Artemis.Managers Logger.Debug("Disabling program"); Stop(); ProgramEnabled = false; - Events.PublishOnUIThread(new ToggleEnabled(ProgramEnabled)); + _events.PublishOnUIThread(new ToggleEnabled(ProgramEnabled)); } #region Workers @@ -223,12 +229,12 @@ namespace Artemis.Managers } // Stop if no keyboard/effect are present - if (KeyboardManager.ActiveKeyboard == null || EffectManager.ActiveEffect == null) + if (_keyboardManager.ActiveKeyboard == null || _effectManager.ActiveEffect == null) { Thread.Sleep(1000/_fps); Logger.Debug("No active effect/keyboard, stopping"); - if (EffectManager.PauseEffect != null) + if (_effectManager.PauseEffect != null) { PauseCallback?.Invoke(); Thread.Sleep(1000/_fps); @@ -239,7 +245,7 @@ namespace Artemis.Managers } // Don't stop when the effect is still initialized, just skip this frame - if (!EffectManager.ActiveEffect.Initialized) + if (!_effectManager.ActiveEffect.Initialized) { Thread.Sleep(1000/_fps); continue; @@ -248,28 +254,28 @@ namespace Artemis.Managers sw.Start(); // Update the current effect - if (EffectManager.ActiveEffect.Initialized) - EffectManager.ActiveEffect.Update(); + if (_effectManager.ActiveEffect.Initialized) + _effectManager.ActiveEffect.Update(); // Get ActiveEffect's bitmap - var bitmap = EffectManager.ActiveEffect.Initialized - ? EffectManager.ActiveEffect.GenerateBitmap() + var bitmap = _effectManager.ActiveEffect.Initialized + ? _effectManager.ActiveEffect.GenerateBitmap() : null; // Draw enabled overlays on top - foreach (var overlayModel in EffectManager.EnabledOverlays) + foreach (var overlayModel in _effectManager.EnabledOverlays) { overlayModel.Update(); bitmap = bitmap != null ? overlayModel.GenerateBitmap(bitmap) : overlayModel.GenerateBitmap(); } // If it exists, send bitmap to the device - if (bitmap != null && KeyboardManager.ActiveKeyboard != null) + if (bitmap != null && _keyboardManager.ActiveKeyboard != null) { - KeyboardManager.ActiveKeyboard.DrawBitmap(bitmap); + _keyboardManager.ActiveKeyboard.DrawBitmap(bitmap); // debugging TODO: Disable when window isn't shown - Events.PublishOnUIThread(new ChangeBitmap(bitmap)); + _events.PublishOnUIThread(new ChangeBitmap(bitmap)); } // Sleep according to time left this frame @@ -302,23 +308,23 @@ namespace Artemis.Managers var runningProcesses = Process.GetProcesses(); // If the currently active effect is a disabled game, get rid of it. - if (EffectManager.ActiveEffect != null) - EffectManager.DisableInactiveGame(); + if (_effectManager.ActiveEffect != null) + _effectManager.DisableInactiveGame(); // If the currently active effect is a no longer running game, get rid of it. - var activeGame = EffectManager.ActiveEffect as GameModel; + var activeGame = _effectManager.ActiveEffect as GameModel; if (activeGame != null) if (!runningProcesses.Any(p => p.ProcessName == activeGame.ProcessName && p.HasExited == false)) - EffectManager.DisableGame(activeGame); + _effectManager.DisableGame(activeGame); // Look for running games, stopping on the first one that's found. - var newGame = EffectManager.EnabledGames + var newGame = _effectManager.EnabledGames .FirstOrDefault( g => runningProcesses.Any(p => p.ProcessName == g.ProcessName && p.HasExited == false)); // If it's not already enabled, do so. - if (newGame != null && EffectManager.ActiveEffect != newGame) - EffectManager.ChangeEffect(newGame); + if (newGame != null && _effectManager.ActiveEffect != newGame) + _effectManager.ChangeEffect(newGame); Thread.Sleep(1000); } diff --git a/Artemis/Artemis/Models/EffectModel.cs b/Artemis/Artemis/Models/EffectModel.cs index 13f01a478..dd6436d27 100644 --- a/Artemis/Artemis/Models/EffectModel.cs +++ b/Artemis/Artemis/Models/EffectModel.cs @@ -10,12 +10,15 @@ namespace Artemis.Models public bool Initialized; + protected KeyboardManager KeyboardManager; + public MainManager MainManager; public string Name; - protected EffectModel(MainManager mainManager) + protected EffectModel(MainManager mainManager, KeyboardManager keyboardManager) { MainManager = mainManager; + KeyboardManager = keyboardManager; } public abstract void Dispose(); diff --git a/Artemis/Artemis/Models/GameModel.cs b/Artemis/Artemis/Models/GameModel.cs index ab209277e..327fcecf8 100644 --- a/Artemis/Artemis/Models/GameModel.cs +++ b/Artemis/Artemis/Models/GameModel.cs @@ -6,7 +6,8 @@ namespace Artemis.Models { public abstract class GameModel : EffectModel { - protected GameModel(MainManager mainManager, GameSettings settings) : base(mainManager) + protected GameModel(MainManager mainManager, KeyboardManager keyboardManager, GameSettings settings) + : base(mainManager, keyboardManager) { Settings = settings; } diff --git a/Artemis/Artemis/Models/OverlayModel.cs b/Artemis/Artemis/Models/OverlayModel.cs index 1020acb1c..c5a1670a4 100644 --- a/Artemis/Artemis/Models/OverlayModel.cs +++ b/Artemis/Artemis/Models/OverlayModel.cs @@ -8,7 +8,8 @@ namespace Artemis.Models private bool _enabled; public string ProcessName; - protected OverlayModel(MainManager mainManager) : base(mainManager) + protected OverlayModel(MainManager mainManager, KeyboardManager keyboardManager) + : base(mainManager, keyboardManager) { } @@ -28,19 +29,6 @@ namespace Artemis.Models } } - public void SetEnabled(bool enabled) - { - if (Enabled == enabled) - return; - - if (enabled) - Enable(); - else - Dispose(); - - Enabled = enabled; - } - public abstract Bitmap GenerateBitmap(Bitmap bitmap); } } \ No newline at end of file diff --git a/Artemis/Artemis/Models/Profiles/LayerDynamicPropertiesModel.cs b/Artemis/Artemis/Models/Profiles/LayerDynamicPropertiesModel.cs index 7466d184b..c6bd07882 100644 --- a/Artemis/Artemis/Models/Profiles/LayerDynamicPropertiesModel.cs +++ b/Artemis/Artemis/Models/Profiles/LayerDynamicPropertiesModel.cs @@ -47,8 +47,8 @@ namespace Artemis.Models.Profiles if (layerProp == null || userProp == null) return; - var percentage = ToDouble(gameProperty) / percentageSource; - + var percentage = ToDouble(gameProperty)/percentageSource; + // Opacity requires some special treatment as it causes an exception if it's < 0.0 or > 1.0 if (LayerProperty == "Opacity") { diff --git a/Artemis/Artemis/Models/Profiles/LayerPropertiesModel.cs b/Artemis/Artemis/Models/Profiles/LayerPropertiesModel.cs index 0e0f40065..4427cb7e5 100644 --- a/Artemis/Artemis/Models/Profiles/LayerPropertiesModel.cs +++ b/Artemis/Artemis/Models/Profiles/LayerPropertiesModel.cs @@ -5,10 +5,10 @@ using System.Xml.Serialization; namespace Artemis.Models.Profiles { - [XmlInclude(typeof (SolidColorBrush))] - [XmlInclude(typeof (LinearGradientBrush))] - [XmlInclude(typeof (RadialGradientBrush))] - [XmlInclude(typeof (MatrixTransform))] + [XmlInclude(typeof(SolidColorBrush))] + [XmlInclude(typeof(LinearGradientBrush))] + [XmlInclude(typeof(RadialGradientBrush))] + [XmlInclude(typeof(MatrixTransform))] public class LayerPropertiesModel { public int X { get; set; } diff --git a/Artemis/Artemis/Modules/Effects/AmbientLightning/AmbientLightningEffectModel.cs b/Artemis/Artemis/Modules/Effects/AmbientLightning/AmbientLightningEffectModel.cs index 27140f257..9b921ae96 100644 --- a/Artemis/Artemis/Modules/Effects/AmbientLightning/AmbientLightningEffectModel.cs +++ b/Artemis/Artemis/Modules/Effects/AmbientLightning/AmbientLightningEffectModel.cs @@ -20,8 +20,8 @@ namespace Artemis.Modules.Effects.AmbientLightning private ScreenCapture _screenCapturer; private KeyboardRectangle _topRect; - public AmbientLightningEffectModel(MainManager mainManager, AmbientLightningEffectSettings settings) - : base(mainManager) + public AmbientLightningEffectModel(MainManager mainManager, KeyboardManager keyboardManager, + AmbientLightningEffectSettings settings) : base(mainManager, keyboardManager) { Name = "Ambient Lightning"; Settings = settings; @@ -49,9 +49,9 @@ namespace Artemis.Modules.Effects.AmbientLightning _colors = new List(); _screenCapturer = new ScreenCapture(); - _topRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, 0, new List(), - LinearGradientMode.Horizontal) {Height = MainManager.KeyboardManager.ActiveKeyboard.Height*Scale/2}; - _botRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, 0, new List(), + _topRect = new KeyboardRectangle(KeyboardManager.ActiveKeyboard, 0, 0, new List(), + LinearGradientMode.Horizontal) {Height = KeyboardManager.ActiveKeyboard.Height*Scale/2}; + _botRect = new KeyboardRectangle(KeyboardManager.ActiveKeyboard, 0, 0, new List(), LinearGradientMode.Horizontal); Initialized = true; @@ -102,8 +102,8 @@ namespace Artemis.Modules.Effects.AmbientLightning } // Put the resulting colors in 6 rectangles, their size differs per keyboard - var rectWidth = MainManager.KeyboardManager.ActiveKeyboard.Width/3*Scale; - var rectHeight = MainManager.KeyboardManager.ActiveKeyboard.Height/2*Scale; + var rectWidth = KeyboardManager.ActiveKeyboard.Width/3*Scale; + var rectHeight = KeyboardManager.ActiveKeyboard.Height/2*Scale; for (var row = 0; row < 2; row++) { for (var column = 0; column < 3; column++) @@ -116,7 +116,7 @@ namespace Artemis.Modules.Effects.AmbientLightning public override Bitmap GenerateBitmap() { - var bitmap = MainManager.KeyboardManager.ActiveKeyboard.KeyboardBitmap(Scale); + var bitmap = KeyboardManager.ActiveKeyboard.KeyboardBitmap(Scale); using (var g = Graphics.FromImage(bitmap)) { var i = 0; diff --git a/Artemis/Artemis/Modules/Effects/AmbientLightning/AmbientLightningEffectViewModel.cs b/Artemis/Artemis/Modules/Effects/AmbientLightning/AmbientLightningEffectViewModel.cs index 484318838..a92ecd540 100644 --- a/Artemis/Artemis/Modules/Effects/AmbientLightning/AmbientLightningEffectViewModel.cs +++ b/Artemis/Artemis/Modules/Effects/AmbientLightning/AmbientLightningEffectViewModel.cs @@ -5,25 +5,20 @@ using Caliburn.Micro; namespace Artemis.Modules.Effects.AmbientLightning { - internal class AmbientLightningEffectViewModel : EffectViewModel, IHandle + public sealed class AmbientLightningEffectViewModel : EffectViewModel, IHandle { - public AmbientLightningEffectViewModel(MainManager mainManager) + public AmbientLightningEffectViewModel(MainManager mainManager, KeyboardManager keyboardManager, + EffectManager effectManager, IEventAggregator events) + : base( + mainManager, effectManager, + new AmbientLightningEffectModel(mainManager, keyboardManager, new AmbientLightningEffectSettings())) { - // Subscribe to main model - MainManager = mainManager; - MainManager.Events.Subscribe(this); + DisplayName = "Ambient Lightning"; - // Settings are loaded from file by class - EffectSettings = new AmbientLightningEffectSettings(); - - // Create effect model and add it to MainManager - EffectModel = new AmbientLightningEffectModel(mainManager, (AmbientLightningEffectSettings) EffectSettings); - MainManager.EffectManager.EffectModels.Add(EffectModel); + events.Subscribe(this); + EffectManager.EffectModels.Add(EffectModel); } - - public static string Name => "Ambient Lightning"; - public void Handle(ActiveEffectChanged message) { NotifyOfPropertyChange(() => EffectEnabled); diff --git a/Artemis/Artemis/Modules/Effects/AmbientLightning/ScreenCapture.cs b/Artemis/Artemis/Modules/Effects/AmbientLightning/ScreenCapture.cs index 5cb2ed972..3e88771e3 100644 --- a/Artemis/Artemis/Modules/Effects/AmbientLightning/ScreenCapture.cs +++ b/Artemis/Artemis/Modules/Effects/AmbientLightning/ScreenCapture.cs @@ -18,10 +18,10 @@ namespace Artemis.Modules.Effects.AmbientLightning internal class ScreenCapture : IDisposable { private readonly Device _device; + private readonly OutputDuplication _duplicatedOutput; private readonly Factory1 _factory; private readonly Texture2D _screenTexture; private DataStream _dataStream; - private readonly OutputDuplication _duplicatedOutput; private Resource _screenResource; private Surface _screenSurface; diff --git a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerModel.cs b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerModel.cs index db31d2341..019f93abe 100644 --- a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerModel.cs +++ b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerModel.cs @@ -22,7 +22,8 @@ namespace Artemis.Modules.Effects.AudioVisualizer private int _sensitivity; private IWaveIn _waveIn; - public AudioVisualizerModel(MainManager mainManager, AudioVisualizerSettings settings) : base(mainManager) + public AudioVisualizerModel(MainManager mainManager, KeyboardManager keyboardManager, + AudioVisualizerSettings settings) : base(mainManager, keyboardManager) { Settings = settings; Name = "Audiovisualizer"; @@ -57,7 +58,7 @@ namespace Artemis.Modules.Effects.AudioVisualizer public override void Enable() { Initialized = false; - Lines = MainManager.KeyboardManager.ActiveKeyboard.Width; + Lines = KeyboardManager.ActiveKeyboard.Width; // TODO: Device selection SelectedDeviceId = new MMDeviceEnumerator() @@ -69,7 +70,7 @@ namespace Artemis.Modules.Effects.AudioVisualizer for (var i = 0; i < Lines; i++) { SoundRectangles.Add(new KeyboardRectangle( - MainManager.KeyboardManager.ActiveKeyboard, + KeyboardManager.ActiveKeyboard, 0, 0, new List { ColorHelpers.ToDrawingColor(Settings.TopColor), @@ -121,7 +122,7 @@ namespace Artemis.Modules.Effects.AudioVisualizer // Apply Sensitivity setting height = height*_sensitivity; var keyboardHeight = - (int) Math.Round(MainManager.KeyboardManager.ActiveKeyboard.Height/100.00*height*Scale); + (int) Math.Round(KeyboardManager.ActiveKeyboard.Height/100.00*height*Scale); if (keyboardHeight > SoundRectangles[i].Height) SoundRectangles[i].Height = keyboardHeight; else @@ -131,7 +132,7 @@ namespace Artemis.Modules.Effects.AudioVisualizer SoundRectangles[i].Width = Scale; if (_fromBottom) - SoundRectangles[i].Y = MainManager.KeyboardManager.ActiveKeyboard.Height*Scale - + SoundRectangles[i].Y = KeyboardManager.ActiveKeyboard.Height*Scale - SoundRectangles[i].Height; } _generating = false; @@ -145,7 +146,7 @@ namespace Artemis.Modules.Effects.AudioVisualizer // Lock the _spectrumData array while busy with it _generating = true; - var bitmap = MainManager.KeyboardManager.ActiveKeyboard.KeyboardBitmap(Scale); + var bitmap = KeyboardManager.ActiveKeyboard.KeyboardBitmap(Scale); using (var g = Graphics.FromImage(bitmap)) { foreach (var soundRectangle in SoundRectangles) diff --git a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerViewModel.cs b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerViewModel.cs index bece0a893..74c6cc0fa 100644 --- a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerViewModel.cs +++ b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerViewModel.cs @@ -5,24 +5,20 @@ using Caliburn.Micro; namespace Artemis.Modules.Effects.AudioVisualizer { - public class AudioVisualizerViewModel : EffectViewModel, IHandle + public sealed class AudioVisualizerViewModel : EffectViewModel, IHandle { - public AudioVisualizerViewModel(MainManager mainManager) + public AudioVisualizerViewModel(MainManager mainManager, KeyboardManager keyboardManager, + EffectManager effectManager, IEventAggregator events) + : base( + mainManager, effectManager, + new AudioVisualizerModel(mainManager, keyboardManager, new AudioVisualizerSettings())) { - // Subscribe to main model - MainManager = mainManager; - MainManager.Events.Subscribe(this); + DisplayName = "Audio Visualization"; - // Settings are loaded from file by class - EffectSettings = new AudioVisualizerSettings(); - - // Create effect model and add it to MainManager - EffectModel = new AudioVisualizerModel(mainManager, (AudioVisualizerSettings) EffectSettings); - MainManager.EffectManager.EffectModels.Add(EffectModel); + events.Subscribe(this); + EffectManager.EffectModels.Add(EffectModel); } - public static string Name => "Audio Visualizer"; - public void Handle(ActiveEffectChanged message) { NotifyOfPropertyChange(() => EffectEnabled); diff --git a/Artemis/Artemis/Modules/Effects/Debug/DebugEffectModel.cs b/Artemis/Artemis/Modules/Effects/Debug/DebugEffectModel.cs index d8e6fc79f..fcc29f84a 100644 --- a/Artemis/Artemis/Modules/Effects/Debug/DebugEffectModel.cs +++ b/Artemis/Artemis/Modules/Effects/Debug/DebugEffectModel.cs @@ -10,7 +10,8 @@ namespace Artemis.Modules.Effects.Debug // TODO: Remove internal class DebugEffectModel : EffectModel { - public DebugEffectModel(MainManager mainManager, DebugEffectSettings settings) : base(mainManager) + public DebugEffectModel(MainManager mainManager, KeyboardManager keyboardManager, DebugEffectSettings settings) + : base(mainManager, keyboardManager) { Name = "Debug Effect"; Settings = settings; @@ -33,7 +34,7 @@ namespace Artemis.Modules.Effects.Debug { Initialized = false; - KeyboardRectangle = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, 0, new List + KeyboardRectangle = new KeyboardRectangle(KeyboardManager.ActiveKeyboard, 0, 0, new List { Color.Red, Color.OrangeRed, diff --git a/Artemis/Artemis/Modules/Effects/Debug/DebugEffectViewModel.cs b/Artemis/Artemis/Modules/Effects/Debug/DebugEffectViewModel.cs index 9c5434ee0..ede2f75a0 100644 --- a/Artemis/Artemis/Modules/Effects/Debug/DebugEffectViewModel.cs +++ b/Artemis/Artemis/Modules/Effects/Debug/DebugEffectViewModel.cs @@ -1,9 +1,6 @@ using System; using System.Drawing.Drawing2D; -using System.Drawing.Imaging; -using System.IO; using System.Windows.Media; -using System.Windows.Media.Imaging; using Artemis.Events; using Artemis.Managers; using Artemis.Utilities; @@ -12,30 +9,25 @@ using Caliburn.Micro; namespace Artemis.Modules.Effects.Debug { - internal class DebugEffectViewModel : EffectViewModel, IHandle, IHandle + internal sealed class DebugEffectViewModel : EffectViewModel, IHandle, IHandle { private ImageSource _imageSource; private string _selectedRectangleType; - public DebugEffectViewModel(MainManager mainManager) + public DebugEffectViewModel(MainManager mainManager, KeyboardManager keyboardManager, + EffectManager effectManager, IEventAggregator events) + : base( + mainManager, effectManager, + new DebugEffectModel(mainManager, keyboardManager, new DebugEffectSettings())) { - // Subscribe to main model - MainManager = mainManager; - MainManager.Events.Subscribe(this); + DisplayName = "Debug Effect"; - // Settings are loaded from file by class - EffectSettings = new DebugEffectSettings(); - - // Create effect model and add it to MainManager - EffectModel = new DebugEffectModel(mainManager, (DebugEffectSettings) EffectSettings); - MainManager.EffectManager.EffectModels.Add(EffectModel); + events.Subscribe(this); + EffectManager.EffectModels.Add(EffectModel); } - - public static string Name => "Debug Effect"; - public BindableCollection RectangleTypes - => new BindableCollection(Enum.GetNames(typeof (LinearGradientMode))); + => new BindableCollection(Enum.GetNames(typeof(LinearGradientMode))); public string SelectedRectangleType { @@ -47,7 +39,7 @@ namespace Artemis.Modules.Effects.Debug NotifyOfPropertyChange(() => SelectedRectangleType); ((DebugEffectSettings) EffectSettings).Type = - (LinearGradientMode) Enum.Parse(typeof (LinearGradientMode), value); + (LinearGradientMode) Enum.Parse(typeof(LinearGradientMode), value); } } diff --git a/Artemis/Artemis/Modules/Effects/ProfilePreview/ProfilePreviewModel.cs b/Artemis/Artemis/Modules/Effects/ProfilePreview/ProfilePreviewModel.cs index ece8fae49..e79ca39f9 100644 --- a/Artemis/Artemis/Modules/Effects/ProfilePreview/ProfilePreviewModel.cs +++ b/Artemis/Artemis/Modules/Effects/ProfilePreview/ProfilePreviewModel.cs @@ -10,7 +10,8 @@ namespace Artemis.Modules.Effects.ProfilePreview { private readonly ProfilePreviewDataModel _previewDataModel; - public ProfilePreviewModel(MainManager mainManager) : base(mainManager) + public ProfilePreviewModel(MainManager mainManager, KeyboardManager keyboardManager) + : base(mainManager, keyboardManager) { Name = "Profile Preview"; _previewDataModel = new ProfilePreviewDataModel(); @@ -40,12 +41,12 @@ namespace Artemis.Modules.Effects.ProfilePreview public override Bitmap GenerateBitmap() { - var bitmap = MainManager.KeyboardManager.ActiveKeyboard.KeyboardBitmap(4); + var bitmap = KeyboardManager.ActiveKeyboard.KeyboardBitmap(4); if (SelectedProfile == null) return bitmap; - var keyboardRect = MainManager.KeyboardManager.ActiveKeyboard.KeyboardRectangle(4); + var keyboardRect = KeyboardManager.ActiveKeyboard.KeyboardRectangle(4); var image = SelectedProfile.GenerateBitmap(keyboardRect, _previewDataModel, true); // Draw on top of everything else diff --git a/Artemis/Artemis/Modules/Effects/TypeHole/TypeHoleModel.cs b/Artemis/Artemis/Modules/Effects/TypeHole/TypeHoleModel.cs deleted file mode 100644 index ea6779209..000000000 --- a/Artemis/Artemis/Modules/Effects/TypeHole/TypeHoleModel.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Drawing; -using Artemis.Managers; -using Artemis.Models; - -namespace Artemis.Modules.Effects.TypeHole -{ - public class TypeHoleModel : EffectModel - { - public TypeHoleModel(MainManager mainManager) : base(mainManager) - { - Name = "TypeHole"; - Initialized = false; - } - - public override void Dispose() - { - Initialized = false; - - // Disable logic - } - - public override void Enable() - { - Initialized = false; - - // Enable logic - - Initialized = true; - } - - public override void Update() - { - } - - public override Bitmap GenerateBitmap() - { - return null; - } - } -} \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/TypeHole/TypeHoleView.xaml b/Artemis/Artemis/Modules/Effects/TypeHole/TypeHoleView.xaml deleted file mode 100644 index 9b7a587e4..000000000 --- a/Artemis/Artemis/Modules/Effects/TypeHole/TypeHoleView.xaml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/TypeHole/TypeHoleView.xaml.cs b/Artemis/Artemis/Modules/Effects/TypeHole/TypeHoleView.xaml.cs deleted file mode 100644 index 34c16616a..000000000 --- a/Artemis/Artemis/Modules/Effects/TypeHole/TypeHoleView.xaml.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Windows.Controls; - -namespace Artemis.Modules.Effects.TypeHole -{ - /// - /// Interaction logic for TypeHoleView.xaml - /// - public partial class TypeHoleView : UserControl - { - public TypeHoleView() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/TypeHole/TypeHoleViewModel.cs b/Artemis/Artemis/Modules/Effects/TypeHole/TypeHoleViewModel.cs deleted file mode 100644 index 943548af3..000000000 --- a/Artemis/Artemis/Modules/Effects/TypeHole/TypeHoleViewModel.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Artemis.Events; -using Artemis.Managers; -using Artemis.ViewModels.Abstract; -using Caliburn.Micro; - -namespace Artemis.Modules.Effects.TypeHole -{ - public class TypeHoleViewModel : EffectViewModel, IHandle - { - public TypeHoleViewModel(MainManager mainManager) - { - // Subscribe to main model - MainManager = mainManager; - MainManager.Events.Subscribe(this); - - // Create effect model and add it to MainManager - EffectModel = new TypeHoleModel(mainManager); - MainManager.EffectManager.EffectModels.Add(EffectModel); - } - - public static string Name => "Type Holes (NYI)"; - - public void Handle(ActiveEffectChanged message) - { - NotifyOfPropertyChange(() => EffectEnabled); - } - } -} \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/TypeWave/TypeWaveModel.cs b/Artemis/Artemis/Modules/Effects/TypeWave/TypeWaveModel.cs index 22f115f0e..329fa03f7 100644 --- a/Artemis/Artemis/Modules/Effects/TypeWave/TypeWaveModel.cs +++ b/Artemis/Artemis/Modules/Effects/TypeWave/TypeWaveModel.cs @@ -16,7 +16,8 @@ namespace Artemis.Modules.Effects.TypeWave private readonly List _waves; private Color _randomColor; - public TypeWaveModel(MainManager mainManager, TypeWaveSettings settings) : base(mainManager) + public TypeWaveModel(MainManager mainManager, KeyboardManager keyboardManager, TypeWaveSettings settings) + : base(mainManager, keyboardManager) { Name = "TypeWave"; _waves = new List(); @@ -96,7 +97,7 @@ namespace Artemis.Modules.Effects.TypeWave if (_waves.Count == 0) return null; - var bitmap = MainManager.KeyboardManager.ActiveKeyboard.KeyboardBitmap(Scale); + var bitmap = KeyboardManager.ActiveKeyboard.KeyboardBitmap(Scale); using (var g = Graphics.FromImage(bitmap)) { g.Clear(Color.Transparent); @@ -113,7 +114,7 @@ namespace Artemis.Modules.Effects.TypeWave _waves[i].Size, _waves[i].Size); Color fillColor; - if (MainManager.KeyboardManager.ActiveKeyboard is CorsairRGB) + if (KeyboardManager.ActiveKeyboard is CorsairRGB) fillColor = Color.Black; else fillColor = Color.Transparent; diff --git a/Artemis/Artemis/Modules/Effects/TypeWave/TypeWaveViewModel.cs b/Artemis/Artemis/Modules/Effects/TypeWave/TypeWaveViewModel.cs index c8dde369b..2e42d55a8 100644 --- a/Artemis/Artemis/Modules/Effects/TypeWave/TypeWaveViewModel.cs +++ b/Artemis/Artemis/Modules/Effects/TypeWave/TypeWaveViewModel.cs @@ -5,24 +5,18 @@ using Caliburn.Micro; namespace Artemis.Modules.Effects.TypeWave { - public class TypeWaveViewModel : EffectViewModel, IHandle + public sealed class TypeWaveViewModel : EffectViewModel, IHandle { - public TypeWaveViewModel(MainManager mainManager) + public TypeWaveViewModel(MainManager mainManager, KeyboardManager keyboardManager, EffectManager effectManager, + IEventAggregator events) + : base(mainManager, effectManager, new TypeWaveModel(mainManager, keyboardManager, new TypeWaveSettings())) { - // Subscribe to main model - MainManager = mainManager; - MainManager.Events.Subscribe(this); + DisplayName = "Type Waves"; - // Settings are loaded from file by class - EffectSettings = new TypeWaveSettings(); - - // Create effect model and add it to MainManager - EffectModel = new TypeWaveModel(mainManager, (TypeWaveSettings) EffectSettings); - MainManager.EffectManager.EffectModels.Add(EffectModel); + events.Subscribe(this); + EffectManager.EffectModels.Add(EffectModel); } - public static string Name => "Type Waves"; - public void Handle(ActiveEffectChanged message) { NotifyOfPropertyChange(() => EffectEnabled); diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs index bae1671bc..d243f1e23 100644 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs +++ b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs @@ -8,7 +8,8 @@ namespace Artemis.Modules.Games.CounterStrike { public class CounterStrikeModel : GameModel { - public CounterStrikeModel(MainManager mainManager, CounterStrikeSettings settings) : base(mainManager, settings) + public CounterStrikeModel(MainManager mainManager, CounterStrikeSettings settings, + KeyboardManager keyboardManager) : base(mainManager, keyboardManager, settings) { Name = "CounterStrike"; ProcessName = "csgo"; @@ -49,7 +50,7 @@ namespace Artemis.Modules.Games.CounterStrike if (Profile == null || GameDataModel == null) return null; - var keyboardRect = MainManager.KeyboardManager.ActiveKeyboard.KeyboardRectangle(Scale); + var keyboardRect = KeyboardManager.ActiveKeyboard.KeyboardRectangle(Scale); return Profile.GenerateBitmap(keyboardRect, GameDataModel); } diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeViewModel.cs b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeViewModel.cs index 073a75145..b2157259d 100644 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeViewModel.cs +++ b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeViewModel.cs @@ -6,19 +6,21 @@ using Artemis.ViewModels.Abstract; namespace Artemis.Modules.Games.CounterStrike { - public class CounterStrikeViewModel : GameViewModel + public sealed class CounterStrikeViewModel : GameViewModel { - public CounterStrikeViewModel(MainManager mainManager) - : base(mainManager, new CounterStrikeModel(mainManager, new CounterStrikeSettings())) + public CounterStrikeViewModel(MainManager mainManager, EffectManager effectManager, + KeyboardManager keyboardManager) + : base( + mainManager, effectManager, + new CounterStrikeModel(mainManager, new CounterStrikeSettings(), keyboardManager)) { + DisplayName = "CS:GO"; + // Create effect model and add it to MainManager - MainManager.EffectManager.EffectModels.Add(GameModel); + EffectManager.EffectModels.Add(GameModel); PlaceConfigFile(); } - public static string Name => "CS:GO"; - public string Content => "Counter-Strike: GO Content"; - public void BrowseDirectory() { var dialog = new FolderBrowserDialog {SelectedPath = ((CounterStrikeSettings) GameSettings).GameDirectory}; diff --git a/Artemis/Artemis/Modules/Games/Dota2/Dota2Model.cs b/Artemis/Artemis/Modules/Games/Dota2/Dota2Model.cs index bd99b08c2..788a8df5b 100644 --- a/Artemis/Artemis/Modules/Games/Dota2/Dota2Model.cs +++ b/Artemis/Artemis/Modules/Games/Dota2/Dota2Model.cs @@ -15,12 +15,15 @@ namespace Artemis.Modules.Games.Dota2 { internal class Dota2Model : GameModel { + private readonly KeyboardManager _keyboardManager; private KeyboardRegion _abilityKeys; private KeyboardRegion _keyPad; private KeyboardRegion _topRow; - public Dota2Model(MainManager mainManager, Dota2Settings settings) : base(mainManager, settings) + public Dota2Model(MainManager mainManager, KeyboardManager keyboardManager, Dota2Settings settings) + : base(mainManager, keyboardManager, settings) { + _keyboardManager = keyboardManager; Name = "Dota2"; ProcessName = "dota2"; Settings = settings; @@ -40,35 +43,35 @@ namespace Artemis.Modules.Games.Dota2 public override void Enable() { Initialized = false; - _topRow = MainManager.KeyboardManager.ActiveKeyboard.KeyboardRegions.First(r => r.RegionName == "TopRow"); - _keyPad = MainManager.KeyboardManager.ActiveKeyboard.KeyboardRegions.First(r => r.RegionName == "NumPad"); - _abilityKeys = MainManager.KeyboardManager.ActiveKeyboard.KeyboardRegions.First(r => r.RegionName == "QWER"); - HealthRectangle = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard + _topRow = _keyboardManager.ActiveKeyboard.KeyboardRegions.First(r => r.RegionName == "TopRow"); + _keyPad = _keyboardManager.ActiveKeyboard.KeyboardRegions.First(r => r.RegionName == "NumPad"); + _abilityKeys = _keyboardManager.ActiveKeyboard.KeyboardRegions.First(r => r.RegionName == "QWER"); + HealthRectangle = new KeyboardRectangle(_keyboardManager.ActiveKeyboard , 0 , _topRow.BottomRight.Y*Scale , new List() , LinearGradientMode.Horizontal) {Height = Scale, ContainedBrush = false}; - ManaRectangle = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard + ManaRectangle = new KeyboardRectangle(_keyboardManager.ActiveKeyboard , 0 , (_topRow.BottomRight.Y + 1)*Scale , new List() , LinearGradientMode.Horizontal) {Height = Scale, ContainedBrush = false}; - EventRectangle = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard + EventRectangle = new KeyboardRectangle(_keyboardManager.ActiveKeyboard , 0 , _topRow.TopLeft.X + 3 , new List() , LinearGradientMode.Horizontal) { - Height = MainManager.KeyboardManager.ActiveKeyboard.Height*Scale - Scale + Height = _keyboardManager.ActiveKeyboard.Height*Scale - Scale , - Width = MainManager.KeyboardManager.ActiveKeyboard.Width*Scale - Scale - 12 + Width = _keyboardManager.ActiveKeyboard.Width*Scale - Scale - 12 }; - DayCycleRectangle = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard + DayCycleRectangle = new KeyboardRectangle(_keyboardManager.ActiveKeyboard , _keyPad.TopLeft.X*Scale , _keyPad.TopLeft.Y*Scale , new List() @@ -96,7 +99,7 @@ namespace Artemis.Modules.Games.Dota2 case "3": //League of Legends for (var i = 0; i < AbilityKeysRectangles.Length; i++) { - AbilityKeysRectangles[i] = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, + AbilityKeysRectangles[i] = new KeyboardRectangle(_keyboardManager.ActiveKeyboard, (_abilityKeys.TopLeft.X + i)*Scale - 2, _abilityKeys.TopLeft.Y*Scale, new List(), @@ -108,7 +111,7 @@ namespace Artemis.Modules.Games.Dota2 } break; case "2": - AbilityKeysRectangles[0] = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, + AbilityKeysRectangles[0] = new KeyboardRectangle(_keyboardManager.ActiveKeyboard, _abilityKeys.TopLeft.X*Scale - 2, _abilityKeys.TopLeft.Y*Scale, new List(), @@ -117,7 +120,7 @@ namespace Artemis.Modules.Games.Dota2 Height = Scale, Width = Scale }; - AbilityKeysRectangles[1] = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, + AbilityKeysRectangles[1] = new KeyboardRectangle(_keyboardManager.ActiveKeyboard, (_abilityKeys.TopLeft.X + 2)*Scale - 2, _abilityKeys.TopLeft.Y*Scale, new List(), @@ -126,7 +129,7 @@ namespace Artemis.Modules.Games.Dota2 Height = Scale, Width = Scale }; - AbilityKeysRectangles[2] = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, + AbilityKeysRectangles[2] = new KeyboardRectangle(_keyboardManager.ActiveKeyboard, (_abilityKeys.TopLeft.X + 3)*Scale - 2, _abilityKeys.TopLeft.Y*Scale, new List(), @@ -135,7 +138,7 @@ namespace Artemis.Modules.Games.Dota2 Height = Scale, Width = Scale }; - AbilityKeysRectangles[3] = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, + AbilityKeysRectangles[3] = new KeyboardRectangle(_keyboardManager.ActiveKeyboard, (_abilityKeys.TopLeft.X + 3)*Scale - 2, (_abilityKeys.TopLeft.Y + 1)*Scale, new List(), @@ -149,7 +152,7 @@ namespace Artemis.Modules.Games.Dota2 case "5": //Smite for (var i = 0; i < AbilityKeysRectangles.Length; i++) { - AbilityKeysRectangles[i] = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, + AbilityKeysRectangles[i] = new KeyboardRectangle(_keyboardManager.ActiveKeyboard, (_abilityKeys.TopLeft.X + i)*Scale - 3, (_abilityKeys.TopLeft.Y - 1)*Scale, new List(), @@ -294,7 +297,7 @@ namespace Artemis.Modules.Games.Dota2 public override Bitmap GenerateBitmap() { - var bitmap = MainManager.KeyboardManager.ActiveKeyboard.KeyboardBitmap(Scale); + var bitmap = _keyboardManager.ActiveKeyboard.KeyboardBitmap(Scale); using (var g = Graphics.FromImage(bitmap)) { diff --git a/Artemis/Artemis/Modules/Games/Dota2/Dota2ViewModel.cs b/Artemis/Artemis/Modules/Games/Dota2/Dota2ViewModel.cs index 471932e65..cc8630665 100644 --- a/Artemis/Artemis/Modules/Games/Dota2/Dota2ViewModel.cs +++ b/Artemis/Artemis/Modules/Games/Dota2/Dota2ViewModel.cs @@ -7,12 +7,14 @@ using Caliburn.Micro; namespace Artemis.Modules.Games.Dota2 { - public class Dota2ViewModel : GameViewModel + public sealed class Dota2ViewModel : GameViewModel { - public Dota2ViewModel(MainManager mainManager) - : base(mainManager, new Dota2Model(mainManager, new Dota2Settings())) + public Dota2ViewModel(MainManager mainManager, EffectManager effectManager, KeyboardManager keyboardManager) + : base(mainManager, effectManager, new Dota2Model(mainManager, keyboardManager, new Dota2Settings())) { - MainManager.EffectManager.EffectModels.Add(GameModel); + DisplayName = "Dota 2"; + + EffectManager.EffectModels.Add(GameModel); PlaceConfigFile(); } diff --git a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs index fdccbda9a..4d56a630c 100644 --- a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs +++ b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs @@ -15,7 +15,8 @@ namespace Artemis.Modules.Games.RocketLeague private Memory _memory; private GamePointersCollection _pointer; - public RocketLeagueModel(MainManager mainManager, RocketLeagueSettings settings) : base(mainManager, settings) + public RocketLeagueModel(MainManager mainManager, KeyboardManager keyboardManager, RocketLeagueSettings settings) + : base(mainManager, keyboardManager, settings) { Name = "RocketLeague"; ProcessName = "RocketLeague"; @@ -72,7 +73,7 @@ namespace Artemis.Modules.Games.RocketLeague if (Profile == null || GameDataModel == null) return null; - var keyboardRect = MainManager.KeyboardManager.ActiveKeyboard.KeyboardRectangle(Scale); + var keyboardRect = KeyboardManager.ActiveKeyboard.KeyboardRectangle(Scale); return Profile.GenerateBitmap(keyboardRect, GameDataModel); } } diff --git a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueViewModel.cs b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueViewModel.cs index 317bb51b5..3c1f6881c 100644 --- a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueViewModel.cs +++ b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueViewModel.cs @@ -7,19 +7,22 @@ using Newtonsoft.Json; namespace Artemis.Modules.Games.RocketLeague { - public class RocketLeagueViewModel : GameViewModel + public sealed class RocketLeagueViewModel : GameViewModel { private string _versionText; - public RocketLeagueViewModel(MainManager mainManager) - : base(mainManager, new RocketLeagueModel(mainManager, new RocketLeagueSettings())) + public RocketLeagueViewModel(MainManager mainManager, KeyboardManager keyboardManager, + EffectManager effectManager) + : base( + mainManager, effectManager, + new RocketLeagueModel(mainManager, keyboardManager, new RocketLeagueSettings())) { - MainManager.EffectManager.EffectModels.Add(GameModel); + DisplayName = "Rocket League"; + + EffectManager.EffectModels.Add(GameModel); SetVersionText(); } - public static string Name => "Rocket League"; - public string VersionText { get { return _versionText; } diff --git a/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionModel.cs b/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionModel.cs index 5b39771fd..bd290e195 100644 --- a/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionModel.cs +++ b/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionModel.cs @@ -12,6 +12,7 @@ namespace Artemis.Modules.Games.TheDivision { public class TheDivisionModel : GameModel { + private readonly KeyboardManager _keyboardManager; private Wave _ammoWave; private TheDivisionDataModel _dataModel; private KeyboardRectangle _hpRect; @@ -22,8 +23,10 @@ namespace Artemis.Modules.Games.TheDivision private StickyValue _stickyHp; private int _trans; - public TheDivisionModel(MainManager mainManager, TheDivisionSettings settings) : base(mainManager, settings) + public TheDivisionModel(MainManager mainManager, KeyboardManager keyboardManager, TheDivisionSettings settings) + : base(mainManager, keyboardManager, settings) { + _keyboardManager = keyboardManager; Name = "TheDivision"; ProcessName = "TheDivision"; Scale = 4; @@ -47,7 +50,7 @@ namespace Artemis.Modules.Games.TheDivision Initialized = false; _ammoWave = new Wave(new Point(30, 14), 0, Color.Transparent); - _hpRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 3*Scale, 0*Scale, + _hpRect = new KeyboardRectangle(_keyboardManager.ActiveKeyboard, 3*Scale, 0*Scale, new List(), LinearGradientMode.Horizontal) { @@ -57,7 +60,7 @@ namespace Artemis.Modules.Games.TheDivision ContainedBrush = false }; - _p2 = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0*Scale, 1*Scale, + _p2 = new KeyboardRectangle(_keyboardManager.ActiveKeyboard, 0*Scale, 1*Scale, new List(), LinearGradientMode.Horizontal) { @@ -66,7 +69,7 @@ namespace Artemis.Modules.Games.TheDivision Rotate = true, ContainedBrush = false }; - _p3 = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0*Scale, 3*Scale, + _p3 = new KeyboardRectangle(_keyboardManager.ActiveKeyboard, 0*Scale, 3*Scale, new List(), LinearGradientMode.Horizontal) { @@ -75,7 +78,7 @@ namespace Artemis.Modules.Games.TheDivision Rotate = true, ContainedBrush = false }; - _p4 = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0*Scale, 5*Scale, + _p4 = new KeyboardRectangle(_keyboardManager.ActiveKeyboard, 0*Scale, 5*Scale, new List(), LinearGradientMode.Horizontal) { @@ -204,7 +207,7 @@ namespace Artemis.Modules.Games.TheDivision public override Bitmap GenerateBitmap() { - var bitmap = MainManager.KeyboardManager.ActiveKeyboard.KeyboardBitmap(Scale); + var bitmap = _keyboardManager.ActiveKeyboard.KeyboardBitmap(Scale); using (var g = Graphics.FromImage(bitmap)) { g.Clear(Color.Transparent); diff --git a/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionViewModel.cs b/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionViewModel.cs index b3b132f58..ee0e75534 100644 --- a/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionViewModel.cs +++ b/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionViewModel.cs @@ -3,14 +3,16 @@ using Artemis.ViewModels.Abstract; namespace Artemis.Modules.Games.TheDivision { - public class TheDivisionViewModel : GameViewModel + public sealed class TheDivisionViewModel : GameViewModel { - public TheDivisionViewModel(MainManager mainManager) - : base(mainManager, new TheDivisionModel(mainManager, new TheDivisionSettings())) + public TheDivisionViewModel(MainManager mainManager, EffectManager effectManager, + KeyboardManager keyboardManager) + : base( + mainManager, effectManager, + new TheDivisionModel(mainManager, keyboardManager, new TheDivisionSettings())) { - MainManager.EffectManager.EffectModels.Add(GameModel); + DisplayName = "The Division"; + EffectManager.EffectModels.Add(GameModel); } - - public static string Name => "The Division"; } } \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/Witcher3/Witcher3Model.cs b/Artemis/Artemis/Modules/Games/Witcher3/Witcher3Model.cs index 693429d74..45725fcb7 100644 --- a/Artemis/Artemis/Modules/Games/Witcher3/Witcher3Model.cs +++ b/Artemis/Artemis/Modules/Games/Witcher3/Witcher3Model.cs @@ -18,7 +18,8 @@ namespace Artemis.Modules.Games.Witcher3 private KeyboardRectangle _signRect; private string _witcherSettings; - public Witcher3Model(MainManager mainManager, Witcher3Settings settings) : base(mainManager, settings) + public Witcher3Model(MainManager mainManager, KeyboardManager keyboardManager, Witcher3Settings settings) + : base(mainManager, keyboardManager, settings) { Name = "Witcher3"; ProcessName = "witcher3"; @@ -44,7 +45,7 @@ namespace Artemis.Modules.Games.Witcher3 { Initialized = false; - _signRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, 0, new List(), + _signRect = new KeyboardRectangle(KeyboardManager.ActiveKeyboard, 0, 0, new List(), LinearGradientMode.Horizontal) { Rotate = true, @@ -106,7 +107,7 @@ namespace Artemis.Modules.Games.Witcher3 public override Bitmap GenerateBitmap() { - var bitmap = MainManager.KeyboardManager.ActiveKeyboard.KeyboardBitmap(Scale); + var bitmap = KeyboardManager.ActiveKeyboard.KeyboardBitmap(Scale); using (var g = Graphics.FromImage(bitmap)) { g.Clear(Color.Transparent); diff --git a/Artemis/Artemis/Modules/Games/Witcher3/Witcher3ViewModel.cs b/Artemis/Artemis/Modules/Games/Witcher3/Witcher3ViewModel.cs index f52a6f269..d4f38ba61 100644 --- a/Artemis/Artemis/Modules/Games/Witcher3/Witcher3ViewModel.cs +++ b/Artemis/Artemis/Modules/Games/Witcher3/Witcher3ViewModel.cs @@ -10,19 +10,13 @@ using Artemis.ViewModels.Abstract; namespace Artemis.Modules.Games.Witcher3 { - public class Witcher3ViewModel : GameViewModel + public sealed class Witcher3ViewModel : GameViewModel { - public Witcher3ViewModel(MainManager mainManager) - : base(mainManager, new Witcher3Model(mainManager, new Witcher3Settings())) + public Witcher3ViewModel(MainManager mainManager, KeyboardManager keyboardManager, EffectManager effectManager) + : base(mainManager, effectManager, new Witcher3Model(mainManager, keyboardManager, new Witcher3Settings())) { - MainManager = mainManager; - - // Settings are loaded from file by class - GameSettings = new Witcher3Settings(); - - // Create effect model and add it to MainManager - GameModel = new Witcher3Model(mainManager, (Witcher3Settings) GameSettings); - MainManager.EffectManager.EffectModels.Add(GameModel); + DisplayName = "The Witcher 3"; + EffectManager.EffectModels.Add(GameModel); } public static string Name => "The Witcher 3"; diff --git a/Artemis/Artemis/Modules/Overlays/VolumeDisplay/VolumeDisplay.cs b/Artemis/Artemis/Modules/Overlays/VolumeDisplay/VolumeDisplay.cs index b055bdf5d..94d59408c 100644 --- a/Artemis/Artemis/Modules/Overlays/VolumeDisplay/VolumeDisplay.cs +++ b/Artemis/Artemis/Modules/Overlays/VolumeDisplay/VolumeDisplay.cs @@ -9,16 +9,16 @@ namespace Artemis.Modules.Overlays.VolumeDisplay { public class VolumeBar { - public VolumeBar(MainManager mainManager, VolumeDisplaySettings settings) + private readonly KeyboardManager _keyboardManager; + + public VolumeBar(KeyboardManager keyboardManager, VolumeDisplaySettings settings) { - MainManager = mainManager; + _keyboardManager = keyboardManager; Settings = settings; Transparancy = 255; Scale = 4; } - public MainManager MainManager { get; set; } - public VolumeDisplaySettings Settings { get; set; } public int Scale { get; set; } @@ -30,14 +30,14 @@ namespace Artemis.Modules.Overlays.VolumeDisplay public void Draw(Graphics g) { - var volumeRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, 0, new List + var volumeRect = new KeyboardRectangle(_keyboardManager.ActiveKeyboard, 0, 0, new List { ColorHelpers.ToDrawingColor(Settings.MainColor), ColorHelpers.ToDrawingColor(Settings.SecondaryColor) }, LinearGradientMode.Horizontal) { - Width = (int) (MainManager.KeyboardManager.ActiveKeyboard.Width*Scale/100.00*Volume), + Width = (int) (_keyboardManager.ActiveKeyboard.Width*Scale/100.00*Volume), ContainedBrush = false }; volumeRect.Draw(g); diff --git a/Artemis/Artemis/Modules/Overlays/VolumeDisplay/VolumeDisplayModel.cs b/Artemis/Artemis/Modules/Overlays/VolumeDisplay/VolumeDisplayModel.cs index 75593f596..3dcd7897b 100644 --- a/Artemis/Artemis/Modules/Overlays/VolumeDisplay/VolumeDisplayModel.cs +++ b/Artemis/Artemis/Modules/Overlays/VolumeDisplay/VolumeDisplayModel.cs @@ -9,13 +9,14 @@ namespace Artemis.Modules.Overlays.VolumeDisplay { public class VolumeDisplayModel : OverlayModel { - public VolumeDisplayModel(MainManager mainManager, VolumeDisplaySettings settings) : base(mainManager) + public VolumeDisplayModel(MainManager mainManager, KeyboardManager keyboardManager, + VolumeDisplaySettings settings) : base(mainManager, keyboardManager) { Settings = settings; Name = "VolumeDisplay"; Enabled = Settings.Enabled; - VolumeDisplay = new VolumeBar(mainManager, settings); + VolumeDisplay = new VolumeBar(keyboardManager, settings); } public VolumeBar VolumeDisplay { get; set; } @@ -63,7 +64,7 @@ namespace Artemis.Modules.Overlays.VolumeDisplay public override Bitmap GenerateBitmap() { - return GenerateBitmap(MainManager.KeyboardManager.ActiveKeyboard.KeyboardBitmap(4)); + return GenerateBitmap(KeyboardManager.ActiveKeyboard.KeyboardBitmap(4)); } public override Bitmap GenerateBitmap(Bitmap bitmap) diff --git a/Artemis/Artemis/Modules/Overlays/VolumeDisplay/VolumeDisplayViewModel.cs b/Artemis/Artemis/Modules/Overlays/VolumeDisplay/VolumeDisplayViewModel.cs index dd4d30a82..53113e6cb 100644 --- a/Artemis/Artemis/Modules/Overlays/VolumeDisplay/VolumeDisplayViewModel.cs +++ b/Artemis/Artemis/Modules/Overlays/VolumeDisplay/VolumeDisplayViewModel.cs @@ -3,18 +3,20 @@ using Artemis.ViewModels.Abstract; namespace Artemis.Modules.Overlays.VolumeDisplay { - public class VolumeDisplayViewModel : OverlayViewModel + public sealed class VolumeDisplayViewModel : OverlayViewModel { - public VolumeDisplayViewModel(MainManager mainManager) + public VolumeDisplayViewModel(MainManager mainManager, KeyboardManager keyboardManager, + EffectManager effectManager) + : base(mainManager, effectManager) { - MainManager = mainManager; + DisplayName = "Volume Display"; // Settings are loaded from file by class OverlaySettings = new VolumeDisplaySettings(); // Create effect model and add it to MainManager - OverlayModel = new VolumeDisplayModel(mainManager, (VolumeDisplaySettings) OverlaySettings); - MainManager.EffectManager.EffectModels.Add(OverlayModel); + OverlayModel = new VolumeDisplayModel(mainManager, keyboardManager, (VolumeDisplaySettings) OverlaySettings); + EffectManager.EffectModels.Add(OverlayModel); } } } \ No newline at end of file diff --git a/Artemis/Artemis/NinjectModules/ArtemisModules.cs b/Artemis/Artemis/NinjectModules/ArtemisModules.cs index 3a37d773e..cc9350970 100644 --- a/Artemis/Artemis/NinjectModules/ArtemisModules.cs +++ b/Artemis/Artemis/NinjectModules/ArtemisModules.cs @@ -1,5 +1,4 @@ -using Artemis.Modules.Effects.AmbientLightning; -using Artemis.Modules.Effects.AudioVisualizer; +using Artemis.Modules.Effects.AudioVisualizer; using Artemis.Modules.Effects.Debug; using Artemis.Modules.Effects.TypeWave; using Artemis.Modules.Games.CounterStrike; @@ -19,10 +18,11 @@ namespace Artemis.NinjectModules public override void Load() { // Effects - //Bind().To().InSingletonScope(); + Bind().To(); // TODO: Needed? Bind().To().InSingletonScope(); Bind().To().InSingletonScope(); Bind().To().InSingletonScope(); + //Bind().To().InSingletonScope(); // Games Bind().To(typeof(GameViewModel<>)); // TODO: Needed? @@ -33,8 +33,8 @@ namespace Artemis.NinjectModules Bind>().To().InSingletonScope(); // Overlays + Bind().To(); // TODO: Needed? Bind().To().InSingletonScope(); - } } } \ No newline at end of file diff --git a/Artemis/Artemis/NinjectModules/BaseModules.cs b/Artemis/Artemis/NinjectModules/BaseModules.cs new file mode 100644 index 000000000..bf5285b21 --- /dev/null +++ b/Artemis/Artemis/NinjectModules/BaseModules.cs @@ -0,0 +1,20 @@ +using Artemis.ViewModels; +using Artemis.ViewModels.Abstract; +using Caliburn.Micro; +using Ninject.Modules; + +namespace Artemis.NinjectModules +{ + internal class BaseModules : NinjectModule + { + public override void Load() + { + // ViewModels + Bind().To().InSingletonScope(); + + Bind().To().InSingletonScope(); + Bind().To().InSingletonScope(); + Bind().To().InSingletonScope(); + } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Properties/Annotations.cs b/Artemis/Artemis/Properties/Annotations.cs index 44f2183f1..97e4559c6 100644 --- a/Artemis/Artemis/Properties/Annotations.cs +++ b/Artemis/Artemis/Properties/Annotations.cs @@ -344,7 +344,7 @@ namespace Artemis.Annotations /// /// [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] - [BaseTypeRequired(typeof (Attribute))] + [BaseTypeRequired(typeof(Attribute))] public sealed class BaseTypeRequiredAttribute : Attribute { public BaseTypeRequiredAttribute([NotNull] Type baseType) diff --git a/Artemis/Artemis/Services/MetroDialogService.cs b/Artemis/Artemis/Services/MetroDialogService.cs index 661eff7f7..953a134ab 100644 --- a/Artemis/Artemis/Services/MetroDialogService.cs +++ b/Artemis/Artemis/Services/MetroDialogService.cs @@ -23,7 +23,6 @@ using System.Linq; using System.Threading.Tasks; using System.Windows; -using Artemis.ViewModels; using Caliburn.Micro; using MahApps.Metro.Controls; using MahApps.Metro.Controls.Dialogs; diff --git a/Artemis/Artemis/Utilities/GeneralHelpers.cs b/Artemis/Artemis/Utilities/GeneralHelpers.cs index 6477febef..5003a40c1 100644 --- a/Artemis/Artemis/Utilities/GeneralHelpers.cs +++ b/Artemis/Artemis/Utilities/GeneralHelpers.cs @@ -66,7 +66,7 @@ namespace Artemis.Utilities if (ReferenceEquals(source, null)) return default(T); - var serializer = new XmlSerializer(typeof (T)); + var serializer = new XmlSerializer(typeof(T)); Stream stream = new MemoryStream(); using (stream) { @@ -87,7 +87,7 @@ namespace Artemis.Utilities } public static List GenerateTypeMap(object o) => GenerateTypeMap(o.GetType().GetProperties()); - public static List GenerateTypeMap() => GenerateTypeMap(typeof (T).GetProperties()); + public static List GenerateTypeMap() => GenerateTypeMap(typeof(T).GetProperties()); private static List GenerateTypeMap(IEnumerable getProperties, string path = "") diff --git a/Artemis/Artemis/Utilities/LayerDrawer.cs b/Artemis/Artemis/Utilities/LayerDrawer.cs index fa17e851c..adf8373d6 100644 --- a/Artemis/Artemis/Utilities/LayerDrawer.cs +++ b/Artemis/Artemis/Utilities/LayerDrawer.cs @@ -130,12 +130,13 @@ namespace Artemis.Utilities c.DrawImage(ImageUtilities.BitmapToBitmapImage(Resources.folder), thumbnailRect); else if (_layerModel.LayerType == LayerType.Headset) c.DrawImage(ImageUtilities.BitmapToBitmapImage(Resources.headset), thumbnailRect); - else if(_layerModel.LayerType == LayerType.Mouse) + else if (_layerModel.LayerType == LayerType.Mouse) c.DrawImage(ImageUtilities.BitmapToBitmapImage(Resources.mouse), thumbnailRect); - else if(_layerModel.LayerType == LayerType.KeyboardGif) + else if (_layerModel.LayerType == LayerType.KeyboardGif) c.DrawImage(ImageUtilities.BitmapToBitmapImage(Resources.gif), thumbnailRect); - else if(_layerModel.LayerType == LayerType.Keyboard && _layerModel.UserProps.Brush != null) - c.DrawRectangle(_layerModel.UserProps.Brush, new Pen(new SolidColorBrush(Colors.White), 1), thumbnailRect); + else if (_layerModel.LayerType == LayerType.Keyboard && _layerModel.UserProps.Brush != null) + c.DrawRectangle(_layerModel.UserProps.Brush, new Pen(new SolidColorBrush(Colors.White), 1), + thumbnailRect); } var image = new DrawingImage(visual.Drawing); @@ -176,7 +177,7 @@ namespace Artemis.Utilities return; if (!File.Exists(_layerModel.GifFile)) return; - + if (_layerModel.GifFile != _gifSource || _gifSource == null) { _gifImage = new GifImage(_layerModel.GifFile); diff --git a/Artemis/Artemis/ViewModels/Abstract/BaseViewModel.cs b/Artemis/Artemis/ViewModels/Abstract/BaseViewModel.cs new file mode 100644 index 000000000..f515e2f65 --- /dev/null +++ b/Artemis/Artemis/ViewModels/Abstract/BaseViewModel.cs @@ -0,0 +1,8 @@ +using Caliburn.Micro; + +namespace Artemis.ViewModels.Abstract +{ + public abstract class BaseViewModel : Conductor.Collection.OneActive + { + } +} \ No newline at end of file diff --git a/Artemis/Artemis/ViewModels/Abstract/EffectViewModel.cs b/Artemis/Artemis/ViewModels/Abstract/EffectViewModel.cs index 06ed6c995..23d2d6b87 100644 --- a/Artemis/Artemis/ViewModels/Abstract/EffectViewModel.cs +++ b/Artemis/Artemis/ViewModels/Abstract/EffectViewModel.cs @@ -6,11 +6,18 @@ namespace Artemis.ViewModels.Abstract { public abstract class EffectViewModel : Screen { + protected readonly EffectModel EffectModel; private EffectSettings _effectSettings; private bool _showDisabledPopup; + protected EffectManager EffectManager; + protected MainManager MainManager; - public EffectModel EffectModel { get; set; } - public MainManager MainManager { get; set; } + protected EffectViewModel(MainManager mainManager, EffectManager effectManager, EffectModel effectModel) + { + MainManager = mainManager; + EffectManager = effectManager; + EffectModel = effectModel; + } public EffectSettings EffectSettings { @@ -23,7 +30,7 @@ namespace Artemis.ViewModels.Abstract } } - public bool EffectEnabled => MainManager.EffectManager.ActiveEffect == EffectModel; + public bool EffectEnabled => EffectManager.ActiveEffect == EffectModel; public bool ShowDisabledPopup { @@ -46,9 +53,9 @@ namespace Artemis.ViewModels.Abstract } if (EffectEnabled) - MainManager.EffectManager.ClearEffect(); + EffectManager.ClearEffect(); else - MainManager.EffectManager.ChangeEffect(EffectModel); + EffectManager.ChangeEffect(EffectModel); } public void SaveSettings() @@ -58,7 +65,7 @@ namespace Artemis.ViewModels.Abstract return; // Restart the effect if it's currently running to apply settings. - MainManager.EffectManager.ChangeEffect(EffectModel, true); + EffectManager.ChangeEffect(EffectModel, true); } public async void ResetSettings() diff --git a/Artemis/Artemis/ViewModels/Abstract/GameViewModel.cs b/Artemis/Artemis/ViewModels/Abstract/GameViewModel.cs index 7518f20d9..1534e592d 100644 --- a/Artemis/Artemis/ViewModels/Abstract/GameViewModel.cs +++ b/Artemis/Artemis/ViewModels/Abstract/GameViewModel.cs @@ -15,14 +15,16 @@ namespace Artemis.ViewModels.Abstract private bool _editorShown; private GameSettings _gameSettings; private EffectModel _lastEffect; + protected EffectManager EffectManager; - protected GameViewModel(MainManager mainManager, GameModel gameModel) + protected GameViewModel(MainManager mainManager, EffectManager effectManager, GameModel gameModel) { MainManager = mainManager; + EffectManager = effectManager; GameModel = gameModel; GameSettings = gameModel.Settings; - ProfileEditor = new ProfileEditorViewModel(MainManager, GameModel); + //ProfileEditor = new ProfileEditorViewModel(MainManager, GameModel); GameModel.Profile = ProfileEditor.SelectedProfile; ProfileEditor.PropertyChanged += ProfileUpdater; } @@ -43,7 +45,7 @@ namespace Artemis.ViewModels.Abstract } } - public bool GameEnabled => MainManager.EffectManager.ActiveEffect == GameModel; + public bool GameEnabled => EffectManager.ActiveEffect == GameModel; public void ToggleEffect() { @@ -57,14 +59,15 @@ namespace Artemis.ViewModels.Abstract return; // Restart the game if it's currently running to apply settings. - MainManager.EffectManager.ChangeEffect(GameModel, true); + EffectManager.ChangeEffect(GameModel, true); } public async void ResetSettings() { - var resetConfirm = await - MainManager.DialogService.ShowQuestionMessageBox("Reset effect settings", - "Are you sure you wish to reset this effect's settings? \nAny changes you made will be lost."); + var resetConfirm = + await + MainManager.DialogService.ShowQuestionMessageBox("Reset effect settings", + "Are you sure you wish to reset this effect's settings? \nAny changes you made will be lost."); if (!resetConfirm.Value) return; @@ -106,11 +109,11 @@ namespace Artemis.ViewModels.Abstract if (enable) { // Store the current effect so it can be restored later - if (!(MainManager.EffectManager.ActiveEffect is ProfilePreviewModel)) - _lastEffect = MainManager.EffectManager.ActiveEffect; + if (!(EffectManager.ActiveEffect is ProfilePreviewModel)) + _lastEffect = EffectManager.ActiveEffect; - MainManager.EffectManager.ProfilePreviewModel.SelectedProfile = ProfileEditor.SelectedProfile; - MainManager.EffectManager.ChangeEffect(MainManager.EffectManager.ProfilePreviewModel); + EffectManager.ProfilePreviewModel.SelectedProfile = ProfileEditor.SelectedProfile; + EffectManager.ChangeEffect(EffectManager.ProfilePreviewModel); } else { @@ -120,12 +123,12 @@ namespace Artemis.ViewModels.Abstract var gameModel = _lastEffect as GameModel; if (gameModel != null) if (!gameModel.Enabled) - MainManager.EffectManager.GetLastEffect(); + EffectManager.GetLastEffect(); else - MainManager.EffectManager.ChangeEffect(_lastEffect, true); + EffectManager.ChangeEffect(_lastEffect, true); } else - MainManager.EffectManager.ClearEffect(); + EffectManager.ClearEffect(); } _editorShown = enable; @@ -137,7 +140,7 @@ namespace Artemis.ViewModels.Abstract return; GameModel.Profile = ProfileEditor.SelectedProfile; - MainManager.EffectManager.ProfilePreviewModel.SelectedProfile = ProfileEditor.SelectedProfile; + EffectManager.ProfilePreviewModel.SelectedProfile = ProfileEditor.SelectedProfile; } } diff --git a/Artemis/Artemis/ViewModels/Abstract/OverlayViewModel.cs b/Artemis/Artemis/ViewModels/Abstract/OverlayViewModel.cs index 50b25b728..906429892 100644 --- a/Artemis/Artemis/ViewModels/Abstract/OverlayViewModel.cs +++ b/Artemis/Artemis/ViewModels/Abstract/OverlayViewModel.cs @@ -6,10 +6,17 @@ namespace Artemis.ViewModels.Abstract { public abstract class OverlayViewModel : Screen { + protected readonly EffectManager EffectManager; + protected readonly MainManager MainManager; private OverlaySettings _overlaySettings; + protected OverlayViewModel(MainManager mainManager, EffectManager effectManager) + { + EffectManager = effectManager; + MainManager = mainManager; + } + public OverlayModel OverlayModel { get; set; } - public MainManager MainManager { get; set; } public OverlaySettings OverlaySettings { diff --git a/Artemis/Artemis/ViewModels/EffectsViewModel.cs b/Artemis/Artemis/ViewModels/EffectsViewModel.cs index 04ba0d33e..a67b8fa97 100644 --- a/Artemis/Artemis/ViewModels/EffectsViewModel.cs +++ b/Artemis/Artemis/ViewModels/EffectsViewModel.cs @@ -1,38 +1,23 @@ -using Artemis.Managers; -using Artemis.Modules.Effects.AudioVisualizer; -using Artemis.Modules.Effects.Debug; -using Artemis.Modules.Effects.TypeHole; -using Artemis.Modules.Effects.TypeWave; -using Caliburn.Micro; +using Artemis.ViewModels.Abstract; namespace Artemis.ViewModels { - public class EffectsViewModel : Conductor.Collection.OneActive + public sealed class EffectsViewModel : BaseViewModel { - private readonly AudioVisualizerViewModel _audioVisualizerVm; - private readonly DebugEffectViewModel _debugVm; - private readonly TypeHoleViewModel _typeHoleVm; - private readonly TypeWaveViewModel _typeWaveVm; - //private readonly AmbientLightningEffectViewModel _ambientLightningVm; + private readonly EffectViewModel[] _effectViewModels; - public EffectsViewModel(MainManager mainManager) + public EffectsViewModel(EffectViewModel[] effectViewModels) { - _typeWaveVm = new TypeWaveViewModel(mainManager) {DisplayName = "Type Waves"}; - //_typeHoleVm = new TypeHoleViewModel(MainManager) {DisplayName = "Type Holes (NYI)"}; - _audioVisualizerVm = new AudioVisualizerViewModel(mainManager) {DisplayName = "Audio Visualization"}; - //_ambientLightningVm = new AmbientLightningEffectViewModel(mainManager) {DisplayName = "Ambient Lightning"}; - _debugVm = new DebugEffectViewModel(mainManager) {DisplayName = "Debug Effect"}; + DisplayName = "Effects"; + _effectViewModels = effectViewModels; } protected override void OnActivate() { base.OnActivate(); - ActivateItem(_typeWaveVm); - //ActivateItem(_typeHoleVm); - ActivateItem(_audioVisualizerVm); - //ActivateItem(_ambientLightningVm); - ActivateItem(_debugVm); + foreach (var effectViewModel in _effectViewModels) + ActivateItem(effectViewModel); } } } \ No newline at end of file diff --git a/Artemis/Artemis/ViewModels/Flyouts/FlyoutSettingsViewModel.cs b/Artemis/Artemis/ViewModels/Flyouts/FlyoutSettingsViewModel.cs index 28761244d..8e2bf907c 100644 --- a/Artemis/Artemis/ViewModels/Flyouts/FlyoutSettingsViewModel.cs +++ b/Artemis/Artemis/ViewModels/Flyouts/FlyoutSettingsViewModel.cs @@ -10,18 +10,20 @@ namespace Artemis.ViewModels.Flyouts { public class FlyoutSettingsViewModel : FlyoutBaseViewModel, IHandle, IHandle { + private readonly KeyboardManager _keyboardManager; private string _activeEffectName; private GeneralSettings _generalSettings; private string _selectedKeyboardProvider; - public FlyoutSettingsViewModel(MainManager mainManager) + public FlyoutSettingsViewModel(MainManager mainManager, KeyboardManager keyboardManager, IEventAggregator events) { + _keyboardManager = keyboardManager; MainManager = mainManager; Header = "Settings"; Position = Position.Right; GeneralSettings = new GeneralSettings(); - MainManager.Events.Subscribe(this); + events.Subscribe(this); } public GeneralSettings GeneralSettings @@ -41,8 +43,7 @@ namespace Artemis.ViewModels.Flyouts { get { - var collection = new BindableCollection(MainManager.KeyboardManager.KeyboardProviders - .Select(k => k.Name)); + var collection = new BindableCollection(_keyboardManager.KeyboardProviders.Select(k => k.Name)); collection.Insert(0, "None"); return collection; } @@ -59,8 +60,8 @@ namespace Artemis.ViewModels.Flyouts if (value == null) return; - MainManager.KeyboardManager.ChangeKeyboard( - MainManager.KeyboardManager.KeyboardProviders.FirstOrDefault( + _keyboardManager.ChangeKeyboard( + _keyboardManager.KeyboardProviders.FirstOrDefault( k => k.Name == _selectedKeyboardProvider)); } } diff --git a/Artemis/Artemis/ViewModels/GamesViewModel.cs b/Artemis/Artemis/ViewModels/GamesViewModel.cs index 1e6429098..063a01cb0 100644 --- a/Artemis/Artemis/ViewModels/GamesViewModel.cs +++ b/Artemis/Artemis/ViewModels/GamesViewModel.cs @@ -1,39 +1,17 @@ -using Artemis.Managers; -using Artemis.Modules.Games.CounterStrike; -using Artemis.Modules.Games.Dota2; -using Artemis.Modules.Games.RocketLeague; -using Artemis.Modules.Games.TheDivision; -using Artemis.Modules.Games.Witcher3; -using Caliburn.Micro; +using Artemis.ViewModels.Abstract; namespace Artemis.ViewModels { - public class GamesViewModel : Conductor.Collection.OneActive + public sealed class GamesViewModel : BaseViewModel { - private readonly CounterStrikeViewModel _counterStrikeVm; - private readonly TheDivisionViewModel _divisionVm; - private readonly Dota2ViewModel _dota2Vm; - private readonly RocketLeagueViewModel _rocketLeagueVm; - private readonly Witcher3ViewModel _witcher3Vm; - - public GamesViewModel(MainManager mainManager) + public GamesViewModel() { - _rocketLeagueVm = new RocketLeagueViewModel(mainManager) {DisplayName = "Rocket League"}; - _counterStrikeVm = new CounterStrikeViewModel(mainManager) {DisplayName = "CS:GO"}; - _dota2Vm = new Dota2ViewModel(mainManager) {DisplayName = "Dota 2"}; - _witcher3Vm = new Witcher3ViewModel(mainManager) {DisplayName = "The Witcher 3"}; - _divisionVm = new TheDivisionViewModel(mainManager) {DisplayName = "The Division"}; + DisplayName = "Games"; } protected override void OnActivate() { base.OnActivate(); - - ActivateItem(_rocketLeagueVm); - ActivateItem(_counterStrikeVm); - ActivateItem(_dota2Vm); - ActivateItem(_witcher3Vm); - ActivateItem(_divisionVm); } } } \ No newline at end of file diff --git a/Artemis/Artemis/ViewModels/LayerEditor/LayerEditorViewModel.cs b/Artemis/Artemis/ViewModels/LayerEditor/LayerEditorViewModel.cs index 3f3218ecb..a2163d458 100644 --- a/Artemis/Artemis/ViewModels/LayerEditor/LayerEditorViewModel.cs +++ b/Artemis/Artemis/ViewModels/LayerEditor/LayerEditorViewModel.cs @@ -17,13 +17,13 @@ namespace Artemis.ViewModels.LayerEditor public class LayerEditorViewModel : Screen { private readonly KeyboardProvider _activeKeyboard; + private readonly MetroDialogService _dialogService; private readonly BackgroundWorker _previewWorker; private readonly bool _wasEnabled; private LayerModel _layer; + private LayerType _layerType; private LayerModel _proposedLayer; private LayerPropertiesModel _proposedProperties; - private LayerType _layerType; - private MetroDialogService _dialogService; public LayerEditorViewModel(KeyboardProvider activeKeyboard, LayerModel layer) { @@ -52,7 +52,7 @@ namespace Artemis.ViewModels.LayerEditor PropertyChanged += GridDisplayHandler; PreSelect(); } - + public LayerDynamicPropertiesViewModel OpacityProperties { get; set; } public LayerDynamicPropertiesViewModel WidthProperties { get; set; } @@ -126,6 +126,17 @@ namespace Artemis.ViewModels.LayerEditor } } + public LayerType LayerType + { + get { return _layerType; } + set + { + if (value == _layerType) return; + _layerType = value; + NotifyOfPropertyChange(() => LayerType); + } + } + private void PreviewWorkerOnDoWork(object sender, DoWorkEventArgs doWorkEventArgs) { while (!_previewWorker.CancellationPending) @@ -141,17 +152,6 @@ namespace Artemis.ViewModels.LayerEditor LayerType = Layer.LayerType; } - public LayerType LayerType - { - get { return _layerType; } - set - { - if (value == _layerType) return; - _layerType = value; - NotifyOfPropertyChange(() => LayerType); - } - } - private void GridDisplayHandler(object sender, PropertyChangedEventArgs e) { if (e.PropertyName != "LayerType") diff --git a/Artemis/Artemis/ViewModels/OverlaysViewModel.cs b/Artemis/Artemis/ViewModels/OverlaysViewModel.cs index 22beca4ad..8c8c18dc3 100644 --- a/Artemis/Artemis/ViewModels/OverlaysViewModel.cs +++ b/Artemis/Artemis/ViewModels/OverlaysViewModel.cs @@ -1,29 +1,29 @@ using Artemis.Managers; using Artemis.Modules.Overlays.VolumeDisplay; -using Caliburn.Micro; +using Artemis.ViewModels.Abstract; namespace Artemis.ViewModels { - public class OverlaysViewModel : Conductor.Collection.OneActive + public sealed class OverlaysViewModel : BaseViewModel { private readonly MainManager _mainManager; + private readonly OverlayViewModel[] _overlayViewModels; private VolumeDisplayViewModel _volumeDisplayVm; - public OverlaysViewModel(MainManager mainManager) + public OverlaysViewModel(MainManager mainManager, OverlayViewModel[] overlayViewModels) { + DisplayName = "Overlays"; + _mainManager = mainManager; + _overlayViewModels = overlayViewModels; } protected override void OnActivate() { base.OnActivate(); - Items.Clear(); - - // This VM appears to be going out of scope, so recreating it every time just to be sure. - _volumeDisplayVm = new VolumeDisplayViewModel(_mainManager) {DisplayName = "Volume Display"}; - ActivateItem(_volumeDisplayVm); - ActiveItem = _volumeDisplayVm; + foreach (var overlayViewModel in _overlayViewModels) + ActivateItem(overlayViewModel); } } } \ No newline at end of file diff --git a/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs b/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs index 8b23c5e9f..034acde6e 100644 --- a/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs +++ b/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs @@ -19,9 +19,10 @@ using MahApps.Metro; namespace Artemis.ViewModels { - public class ProfileEditorViewModel : Screen, IHandle + public sealed class ProfileEditorViewModel : Screen, IHandle { private readonly GameModel _gameModel; + private readonly KeyboardManager _keyboardManager; private readonly MainManager _mainManager; private DateTime _downTime; private LayerModel _draggingLayer; @@ -34,14 +35,16 @@ namespace Artemis.ViewModels private LayerModel _selectedLayer; private ProfileModel _selectedProfile; - public ProfileEditorViewModel(MainManager mainManager, GameModel gameModel) + public ProfileEditorViewModel(MainManager mainManager, KeyboardManager keyboardManager, GameModel gameModel, + IEventAggregator events) { _mainManager = mainManager; + _keyboardManager = keyboardManager; _gameModel = gameModel; Profiles = new BindableCollection(); Layers = new BindableCollection(); - _mainManager.Events.Subscribe(this); + events.Subscribe(this); PropertyChanged += PropertyChangeHandler; LoadProfiles(); @@ -177,7 +180,7 @@ namespace Artemis.ViewModels public bool CanAddLayer => _selectedProfile != null; public bool CanRemoveLayer => _selectedProfile != null && _selectedLayer != null; - private KeyboardProvider ActiveKeyboard => _mainManager.KeyboardManager.ActiveKeyboard; + private KeyboardProvider ActiveKeyboard => _keyboardManager.ActiveKeyboard; /// /// Handles chaning the active keyboard, updating the preview image and profiles collection diff --git a/Artemis/Artemis/ViewModels/ShellViewModel.cs b/Artemis/Artemis/ViewModels/ShellViewModel.cs index c3455df20..67e0b79b9 100644 --- a/Artemis/Artemis/ViewModels/ShellViewModel.cs +++ b/Artemis/Artemis/ViewModels/ShellViewModel.cs @@ -1,49 +1,36 @@ using System.Linq; -using Artemis.Managers; -using Artemis.Services; +using Artemis.ViewModels.Abstract; using Artemis.ViewModels.Flyouts; using Caliburn.Micro; +using Ninject; namespace Artemis.ViewModels { public sealed class ShellViewModel : Conductor.Collection.OneActive { - private readonly EffectsViewModel _effectsVm; - private readonly GamesViewModel _gamesVm; - private readonly OverlaysViewModel _overlaysVm; - private readonly WelcomeViewModel _welcomeVm; + private readonly BaseViewModel[] _viewModels; - public ShellViewModel() + public ShellViewModel(BaseViewModel[] viewModels, IKernel kernel) { - var dialogService = new MetroDialogService(this); - IEventAggregator events = new EventAggregator(); + _viewModels = viewModels; - MainManager = new MainManager(events, dialogService); + // Setup UI DisplayName = "Artemis"; - - _welcomeVm = new WelcomeViewModel {DisplayName = "Welcome"}; - _effectsVm = new EffectsViewModel(MainManager) {DisplayName = "Effects"}; - _gamesVm = new GamesViewModel(MainManager) {DisplayName = "Games"}; - _overlaysVm = new OverlaysViewModel(MainManager) {DisplayName = "Overlays"}; - - Flyouts.Add(new FlyoutSettingsViewModel(MainManager)); + Flyouts = new BindableCollection + { + kernel.Get() + }; } - public IObservableCollection Flyouts { get; set; } = - new BindableCollection(); - - public MainManager MainManager { get; set; } + public IObservableCollection Flyouts { get; set; } protected override void OnActivate() { base.OnActivate(); + foreach (var screen in _viewModels) + ActivateItem(screen); - ActivateItem(_welcomeVm); - ActivateItem(_effectsVm); - ActivateItem(_gamesVm); - ActivateItem(_overlaysVm); - - ActiveItem = _welcomeVm; + ActiveItem = _viewModels.FirstOrDefault(); } public void Settings() diff --git a/Artemis/Artemis/ViewModels/SystemTrayViewModel.cs b/Artemis/Artemis/ViewModels/SystemTrayViewModel.cs index 7034ca255..7142b3872 100644 --- a/Artemis/Artemis/ViewModels/SystemTrayViewModel.cs +++ b/Artemis/Artemis/ViewModels/SystemTrayViewModel.cs @@ -1,6 +1,7 @@ using System; using System.Windows; using Artemis.Events; +using Artemis.Managers; using Artemis.Settings; using Artemis.Utilities; using Caliburn.Micro; @@ -10,25 +11,30 @@ namespace Artemis.ViewModels public class SystemTrayViewModel : Screen, IHandle { private readonly ShellViewModel _shellViewModel; - private readonly IWindowManager _windowManager; private string _activeIcon; private bool _checkedForUpdate; private bool _enabled; private string _toggleText; - public SystemTrayViewModel(IWindowManager windowManager, ShellViewModel shellViewModel) + public SystemTrayViewModel(IWindowManager windowManager, IEventAggregator events, ShellViewModel shellViewModel, + MainManager mainManager) { _windowManager = windowManager; _shellViewModel = shellViewModel; - _shellViewModel.MainManager.Events.Subscribe(this); - _shellViewModel.MainManager.EnableProgram(); _checkedForUpdate = false; + MainManager = mainManager; + + events.Subscribe(this); + MainManager.EnableProgram(); + if (General.Default.ShowOnStartup) ShowWindow(); } + public MainManager MainManager { get; set; } + public bool CanShowWindow => !_shellViewModel.IsActive; public bool CanHideWindow => _shellViewModel.IsActive; @@ -76,9 +82,9 @@ namespace Artemis.ViewModels public void ToggleEnabled() { if (Enabled) - _shellViewModel.MainManager.DisableProgram(); + MainManager.DisableProgram(); else - _shellViewModel.MainManager.EnableProgram(); + MainManager.EnableProgram(); } protected override void OnActivate() @@ -104,7 +110,7 @@ namespace Artemis.ViewModels return; _checkedForUpdate = true; - Updater.CheckForUpdate(_shellViewModel.MainManager.DialogService); + Updater.CheckForUpdate(MainManager.DialogService); } @@ -121,7 +127,7 @@ namespace Artemis.ViewModels public void ExitApplication() { - _shellViewModel.MainManager.Shutdown(); + MainManager.Shutdown(); Application.Current.Shutdown(); // Sometimes you need to be rough. diff --git a/Artemis/Artemis/ViewModels/WelcomeViewModel.cs b/Artemis/Artemis/ViewModels/WelcomeViewModel.cs index 522ccfbfe..9b91abe16 100644 --- a/Artemis/Artemis/ViewModels/WelcomeViewModel.cs +++ b/Artemis/Artemis/ViewModels/WelcomeViewModel.cs @@ -3,8 +3,13 @@ using Caliburn.Micro; namespace Artemis.ViewModels { - public class WelcomeViewModel : Screen + public sealed class WelcomeViewModel : Screen { + public WelcomeViewModel() + { + DisplayName = "Welcome"; + } + public void NavigateTo(string url) { Process.Start(new ProcessStartInfo(url)); diff --git a/Artemis/Artemis/packages.config b/Artemis/Artemis/packages.config index 4aa4622c8..4a02c761e 100644 --- a/Artemis/Artemis/packages.config +++ b/Artemis/Artemis/packages.config @@ -1,4 +1,5 @@  +