1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Restructured all normal effects to Ninject, only games/profiles left to do.

This commit is contained in:
SpoinkyNL 2016-05-08 22:28:10 +02:00
parent f25dc00c16
commit 39362abb47
27 changed files with 193 additions and 165 deletions

View File

@ -132,6 +132,10 @@
<HintPath>..\packages\Caliburn.Micro.3.0.1\lib\net45\Caliburn.Micro.Platform.Core.dll</HintPath> <HintPath>..\packages\Caliburn.Micro.3.0.1\lib\net45\Caliburn.Micro.Platform.Core.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="Castle.Core, Version=3.2.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.3.2.0\lib\net45\Castle.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="ColorBox, Version=1.1.0.0, Culture=neutral, PublicKeyToken=f971124b2576acfc, processorArchitecture=MSIL"> <Reference Include="ColorBox, Version=1.1.0.0, Culture=neutral, PublicKeyToken=f971124b2576acfc, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>lib\ColorBox.dll</HintPath> <HintPath>lib\ColorBox.dll</HintPath>
@ -175,6 +179,10 @@
<HintPath>..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll</HintPath> <HintPath>..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="Ninject.Extensions.Factory, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
<HintPath>..\packages\Ninject.Extensions.Factory.3.2.1.0\lib\net45-full\Ninject.Extensions.Factory.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Ninject.Extensions.Logging, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL"> <Reference Include="Ninject.Extensions.Logging, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
<HintPath>..\packages\Ninject.Extensions.Logging.3.2.3.0\lib\net45-full\Ninject.Extensions.Logging.dll</HintPath> <HintPath>..\packages\Ninject.Extensions.Logging.3.2.3.0\lib\net45-full\Ninject.Extensions.Logging.dll</HintPath>
<Private>True</Private> <Private>True</Private>
@ -274,6 +282,7 @@
<Compile Include="Events\ToggleEnabled.cs" /> <Compile Include="Events\ToggleEnabled.cs" />
<Compile Include="Events\ActiveEffectChanged.cs" /> <Compile Include="Events\ActiveEffectChanged.cs" />
<Compile Include="Events\ChangeBitmap.cs" /> <Compile Include="Events\ChangeBitmap.cs" />
<Compile Include="InjectionFactories\IProfileEditorViewModelFactory.cs" />
<Compile Include="ItemBehaviours\BindableSelectedItemBehavior.cs" /> <Compile Include="ItemBehaviours\BindableSelectedItemBehavior.cs" />
<Compile Include="KeyboardProviders\Corsair\CorsairRGB.cs" /> <Compile Include="KeyboardProviders\Corsair\CorsairRGB.cs" />
<Compile Include="KeyboardProviders\KeyboardProvider.cs" /> <Compile Include="KeyboardProviders\KeyboardProvider.cs" />
@ -379,9 +388,9 @@
<Compile Include="Modules\Overlays\VolumeDisplay\VolumeDisplaySettings.cs" /> <Compile Include="Modules\Overlays\VolumeDisplay\VolumeDisplaySettings.cs" />
<Compile Include="Modules\Games\RocketLeague\RocketLeagueSettings.cs" /> <Compile Include="Modules\Games\RocketLeague\RocketLeagueSettings.cs" />
<Compile Include="Modules\Effects\TypeWave\TypeWaveSettings.cs" /> <Compile Include="Modules\Effects\TypeWave\TypeWaveSettings.cs" />
<Compile Include="NinjectModules\ArtemisModules.cs" /> <Compile Include="InjectionModules\ArtemisModules.cs" />
<Compile Include="NinjectModules\BaseModules.cs" /> <Compile Include="InjectionModules\BaseModules.cs" />
<Compile Include="NinjectModules\ManagerModules.cs" /> <Compile Include="InjectionModules\ManagerModules.cs" />
<Compile Include="Properties\Annotations.cs" /> <Compile Include="Properties\Annotations.cs" />
<Compile Include="Properties\Resources.Designer.cs"> <Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>

View File

@ -6,7 +6,7 @@ using System.Reflection;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Forms; using System.Windows.Forms;
using Artemis.NinjectModules; using Artemis.InjectionModules;
using Artemis.ViewModels; using Artemis.ViewModels;
using Caliburn.Micro; using Caliburn.Micro;
using Ninject; using Ninject;

View File

@ -0,0 +1,13 @@
using Artemis.Managers;
using Artemis.Models;
using Artemis.ViewModels;
using Caliburn.Micro;
namespace Artemis.InjectionFactories
{
public interface IProfileEditorViewModelFactory
{
ProfileEditorViewModel CreateProfileEditorViewModel(IEventAggregator events, MainManager mainManager,
GameModel gameModel);
}
}

View File

@ -8,32 +8,28 @@ using Artemis.Modules.Games.TheDivision;
using Artemis.Modules.Games.Witcher3; using Artemis.Modules.Games.Witcher3;
using Artemis.Modules.Overlays.VolumeDisplay; using Artemis.Modules.Overlays.VolumeDisplay;
using Artemis.ViewModels.Abstract; using Artemis.ViewModels.Abstract;
using Caliburn.Micro;
using Ninject.Modules; using Ninject.Modules;
namespace Artemis.NinjectModules namespace Artemis.InjectionModules
{ {
public class ArtemisModules : NinjectModule public class ArtemisModules : NinjectModule
{ {
public override void Load() public override void Load()
{ {
// Effects // Effects
Bind<Screen>().To<EffectViewModel>(); // TODO: Needed?
Bind<EffectViewModel>().To<AudioVisualizerViewModel>().InSingletonScope(); Bind<EffectViewModel>().To<AudioVisualizerViewModel>().InSingletonScope();
Bind<EffectViewModel>().To<DebugEffectViewModel>().InSingletonScope(); Bind<EffectViewModel>().To<DebugEffectViewModel>().InSingletonScope();
Bind<EffectViewModel>().To<TypeWaveViewModel>().InSingletonScope(); Bind<EffectViewModel>().To<TypeWaveViewModel>().InSingletonScope();
//Bind<EffectViewModel>().To<AmbientLightningEffectViewModel>().InSingletonScope(); //Bind<EffectViewModel>().To<AmbientLightningEffectViewModel>().InSingletonScope();
// Games // Games
Bind<Screen>().To(typeof(GameViewModel<>)); // TODO: Needed? Bind<GameViewModel>().To<CounterStrikeViewModel>().InSingletonScope();
Bind<GameViewModel<CounterStrikeDataModel>>().To<CounterStrikeViewModel>().InSingletonScope(); Bind<GameViewModel>().To<Dota2ViewModel>().InSingletonScope();
Bind<GameViewModel<Dota2DataModel>>().To<Dota2ViewModel>().InSingletonScope(); Bind<GameViewModel>().To<RocketLeagueViewModel>().InSingletonScope();
Bind<GameViewModel<RocketLeagueDataModel>>().To<RocketLeagueViewModel>().InSingletonScope(); Bind<GameViewModel>().To<TheDivisionViewModel>().InSingletonScope();
Bind<GameViewModel<TheDivisionDataModel>>().To<TheDivisionViewModel>().InSingletonScope(); Bind<GameViewModel>().To<Witcher3ViewModel>().InSingletonScope();
Bind<GameViewModel<Witcher3DataModel>>().To<Witcher3ViewModel>().InSingletonScope();
// Overlays // Overlays
Bind<Screen>().To<OverlayViewModel>(); // TODO: Needed?
Bind<OverlayViewModel>().To<VolumeDisplayViewModel>().InSingletonScope(); Bind<OverlayViewModel>().To<VolumeDisplayViewModel>().InSingletonScope();
} }
} }

View File

@ -1,9 +1,12 @@
using Artemis.ViewModels; using Artemis.InjectionFactories;
using Artemis.Modules.Effects.ProfilePreview;
using Artemis.ViewModels;
using Artemis.ViewModels.Abstract; using Artemis.ViewModels.Abstract;
using Caliburn.Micro; using Caliburn.Micro;
using Ninject.Extensions.Factory;
using Ninject.Modules; using Ninject.Modules;
namespace Artemis.NinjectModules namespace Artemis.InjectionModules
{ {
internal class BaseModules : NinjectModule internal class BaseModules : NinjectModule
{ {
@ -11,10 +14,14 @@ namespace Artemis.NinjectModules
{ {
// ViewModels // ViewModels
Bind<IScreen>().To<ShellViewModel>().InSingletonScope(); Bind<IScreen>().To<ShellViewModel>().InSingletonScope();
Bind<IProfileEditorViewModelFactory>().ToFactory();
Bind<BaseViewModel>().To<EffectsViewModel>().InSingletonScope(); Bind<BaseViewModel>().To<EffectsViewModel>().InSingletonScope();
Bind<BaseViewModel>().To<GamesViewModel>().InSingletonScope(); Bind<BaseViewModel>().To<GamesViewModel>().InSingletonScope();
Bind<BaseViewModel>().To<OverlaysViewModel>().InSingletonScope(); Bind<BaseViewModel>().To<OverlaysViewModel>().InSingletonScope();
// Models
Bind<ProfilePreviewModel>().ToSelf().InSingletonScope();
} }
} }
} }

View File

@ -1,7 +1,7 @@
using Artemis.Managers; using Artemis.Managers;
using Ninject.Modules; using Ninject.Modules;
namespace Artemis.NinjectModules namespace Artemis.InjectionModules
{ {
internal class ManagerModules : NinjectModule internal class ManagerModules : NinjectModule
{ {

View File

@ -18,23 +18,19 @@ namespace Artemis.Managers
{ {
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly IEventAggregator _events; private readonly IEventAggregator _events;
private readonly KeyboardManager _keyboardManager;
private EffectModel _activeEffect; private EffectModel _activeEffect;
public EffectManager(IEventAggregator events) public EffectManager(IEventAggregator events, KeyboardManager keyboardManager)
{ {
Logger.Info("Intializing EffectManager"); Logger.Info("Intializing EffectManager");
_events = events; _events = events;
_keyboardManager = keyboardManager;
EffectModels = new List<EffectModel>(); EffectModels = new List<EffectModel>();
//ProfilePreviewModel = new ProfilePreviewModel(MainManager.Value);
Logger.Info("Intialized EffectManager"); Logger.Info("Intialized EffectManager");
} }
/// <summary>
/// Used by ViewModels to show a preview of the profile currently being edited
/// </summary>
public ProfilePreviewModel ProfilePreviewModel { get; set; }
/// <summary> /// <summary>
/// Holds all the effects the program has /// Holds all the effects the program has
/// </summary> /// </summary>
@ -81,15 +77,20 @@ namespace Artemis.Managers
/// <summary> /// <summary>
/// Disables the current effect and changes it to the provided effect. /// Disables the current effect and changes it to the provided effect.
/// </summary> /// </summary>
/// <param name="effectModel"></param> /// <param name="effectModel">The effect to activate</param>
/// <param name="force">Changes the effect, even if it's already running (effectively restarting it)</param> /// <param name="loopManager">Optionally pass the LoopManager to automatically start it, if it's not running.</param>
public void ChangeEffect(EffectModel effectModel) public void ChangeEffect(EffectModel effectModel, LoopManager loopManager = null)
{ {
if (effectModel == null) if (effectModel == null)
throw new ArgumentNullException(nameof(effectModel)); throw new ArgumentNullException(nameof(effectModel));
if (effectModel is OverlayModel) if (effectModel is OverlayModel)
throw new ArgumentException("Can't set an Overlay effect as the active effect"); throw new ArgumentException("Can't set an Overlay effect as the active effect");
if (_keyboardManager.ActiveKeyboard == null)
_keyboardManager.EnableLastKeyboard();
lock (_keyboardManager.ActiveKeyboard)
{
// Game models are only used if they are enabled // Game models are only used if they are enabled
var gameModel = effectModel as GameModel; var gameModel = effectModel as GameModel;
if (gameModel != null) if (gameModel != null)
@ -118,6 +119,12 @@ namespace Artemis.Managers
General.Default.LastEffect = ActiveEffect?.Name; General.Default.LastEffect = ActiveEffect?.Name;
General.Default.Save(); General.Default.Save();
} }
}
if (loopManager != null && !loopManager.Running)
{
loopManager.Start();
}
Logger.Debug($"Changed active effect to: {effectModel.Name}"); Logger.Debug($"Changed active effect to: {effectModel.Name}");
} }
@ -127,6 +134,8 @@ namespace Artemis.Managers
/// Clears the current effect /// Clears the current effect
/// </summary> /// </summary>
public void ClearEffect() public void ClearEffect()
{
lock (_keyboardManager.ActiveKeyboard)
{ {
lock (ActiveEffect) lock (ActiveEffect)
{ {
@ -136,6 +145,7 @@ namespace Artemis.Managers
General.Default.LastEffect = null; General.Default.LastEffect = null;
General.Default.Save(); General.Default.Save();
} }
}
Logger.Debug("Cleared active effect"); Logger.Debug("Cleared active effect");
} }

View File

@ -45,7 +45,18 @@ namespace Artemis.Managers
public void Start() public void Start()
{ {
Logger.Debug("Starting LoopManager"); Logger.Debug("Starting LoopManager");
// Setup
if (_keyboardManager.ActiveKeyboard == null)
_keyboardManager.EnableLastKeyboard();
if (_effectManager.ActiveEffect == null)
{
var lastEffect = _effectManager.GetLastEffect();
if (lastEffect == null)
return;
_effectManager.ChangeEffect(lastEffect);
}
Running = true; Running = true;
} }
@ -55,7 +66,7 @@ namespace Artemis.Managers
Logger.Debug("Stopping LoopManager"); Logger.Debug("Stopping LoopManager");
Running = false; Running = false;
// Shut down _keyboardManager.ReleaseActiveKeyboard();
} }
private void Render(object sender, ElapsedEventArgs e) private void Render(object sender, ElapsedEventArgs e)
@ -63,11 +74,6 @@ namespace Artemis.Managers
if (!Running) if (!Running)
return; return;
// Lock both the active keyboard and active effect so they will not change while rendering.
lock (_keyboardManager.ActiveKeyboard)
{
lock (_effectManager.ActiveEffect)
{
// Stop if no active keyboard/efffect // Stop if no active keyboard/efffect
if (_keyboardManager.ActiveKeyboard == null || _effectManager.ActiveEffect == null) if (_keyboardManager.ActiveKeyboard == null || _effectManager.ActiveEffect == null)
{ {
@ -78,6 +84,11 @@ namespace Artemis.Managers
return; return;
} }
// Lock both the active keyboard and active effect so they will not change while rendering.
lock (_keyboardManager.ActiveKeyboard)
{
lock (_effectManager.ActiveEffect)
{
// Skip frame if effect is still initializing // Skip frame if effect is still initializing
if (_effectManager.ActiveEffect.Initialized == false) if (_effectManager.ActiveEffect.Initialized == false)
return; return;

View File

@ -65,7 +65,7 @@ namespace Artemis.Managers
public Lazy<ShellViewModel> ShellViewModel { get; set; } public Lazy<ShellViewModel> ShellViewModel { get; set; }
public ILogger Logger { get; } public ILogger Logger { get; }
private LoopManager LoopManager { get; } public LoopManager LoopManager { get; }
public KeyboardManager KeyboardManager { get; set; } public KeyboardManager KeyboardManager { get; set; }
public EffectManager EffectManager { get; set; } public EffectManager EffectManager { get; set; }
@ -81,55 +81,13 @@ namespace Artemis.Managers
public void Dispose() public void Dispose()
{ {
Logger.Debug("Shutting down MainManager"); Logger.Debug("Shutting down MainManager");
Stop(); LoopManager.Stop();
ProcessWorker.CancelAsync(); ProcessWorker.CancelAsync();
ProcessWorker.CancelAsync(); ProcessWorker.CancelAsync();
GameStateWebServer.Stop(); GameStateWebServer.Stop();
PipeServer.Stop(); PipeServer.Stop();
} }
/// <summary>
/// Take control of the keyboard and start sending data to it
/// </summary>
/// <returns>Whether starting was successful or not</returns>
public bool Start(EffectModel effect = null)
{
Logger.Debug("Starting MainManager");
// Can't take control when not enabled
if (!ProgramEnabled)
return false;
// Do nothing if already running
if (Running)
return true;
// Only continue if a keyboard was loaded
KeyboardManager.EnableLastKeyboard();
if (KeyboardManager.ActiveKeyboard == null)
return false;
Running = true;
if (effect != null)
EffectManager.ChangeEffect(effect);
LoopManager.Start();
return Running;
}
/// <summary>
/// Releases control of the keyboard and stop sending data to it
/// </summary>
public void Stop()
{
if (!Running)
return;
Logger.Debug("Stopping MainManager");
LoopManager.Stop();
}
/// <summary> /// <summary>
/// Loads the last active effect and starts the program /// Loads the last active effect and starts the program
/// </summary> /// </summary>
@ -137,7 +95,7 @@ namespace Artemis.Managers
{ {
Logger.Debug("Enabling program"); Logger.Debug("Enabling program");
ProgramEnabled = true; ProgramEnabled = true;
Start(EffectManager.GetLastEffect()); LoopManager.Start();
_events.PublishOnUIThread(new ToggleEnabled(ProgramEnabled)); _events.PublishOnUIThread(new ToggleEnabled(ProgramEnabled));
} }
@ -147,7 +105,7 @@ namespace Artemis.Managers
public void DisableProgram() public void DisableProgram()
{ {
Logger.Debug("Disabling program"); Logger.Debug("Disabling program");
Stop(); LoopManager.Stop();
ProgramEnabled = false; ProgramEnabled = false;
_events.PublishOnUIThread(new ToggleEnabled(ProgramEnabled)); _events.PublishOnUIThread(new ToggleEnabled(ProgramEnabled));
} }

View File

@ -7,6 +7,7 @@ namespace Artemis.Models
public abstract class EffectModel : IDisposable public abstract class EffectModel : IDisposable
{ {
public delegate void SettingsUpdateHandler(EffectSettings settings); public delegate void SettingsUpdateHandler(EffectSettings settings);
public bool Initialized; public bool Initialized;
public MainManager MainManager; public MainManager MainManager;
public string Name; public string Name;

View File

@ -6,7 +6,7 @@ namespace Artemis.Models
{ {
public abstract class GameModel : EffectModel public abstract class GameModel : EffectModel
{ {
protected GameModel(MainManager mainManager, GameSettings settings): base(mainManager) protected GameModel(MainManager mainManager, GameSettings settings) : base(mainManager)
{ {
Settings = settings; Settings = settings;
} }

View File

@ -8,7 +8,7 @@ namespace Artemis.Models
private bool _enabled; private bool _enabled;
public string ProcessName; public string ProcessName;
protected OverlayModel(MainManager mainManager): base(mainManager) protected OverlayModel(MainManager mainManager) : base(mainManager)
{ {
} }

View File

@ -10,7 +10,7 @@ namespace Artemis.Modules.Effects.ProfilePreview
{ {
private readonly ProfilePreviewDataModel _previewDataModel; private readonly ProfilePreviewDataModel _previewDataModel;
public ProfilePreviewModel(MainManager main) : base(main) public ProfilePreviewModel(MainManager mainManager) : base(mainManager)
{ {
Name = "Profile Preview"; Name = "Profile Preview";
_previewDataModel = new ProfilePreviewDataModel(); _previewDataModel = new ProfilePreviewDataModel();

View File

@ -1,15 +1,17 @@
using System.IO; using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
using Artemis.InjectionFactories;
using Artemis.Managers; using Artemis.Managers;
using Artemis.Properties; using Artemis.Properties;
using Artemis.ViewModels.Abstract; using Artemis.ViewModels.Abstract;
using Caliburn.Micro;
namespace Artemis.Modules.Games.CounterStrike namespace Artemis.Modules.Games.CounterStrike
{ {
public sealed class CounterStrikeViewModel : GameViewModel<CounterStrikeDataModel> public sealed class CounterStrikeViewModel : GameViewModel
{ {
public CounterStrikeViewModel(MainManager main) public CounterStrikeViewModel(MainManager main, IEventAggregator events, IProfileEditorViewModelFactory pFactory)
: base(main, new CounterStrikeModel(main, new CounterStrikeSettings())) : base(main, new CounterStrikeModel(main, new CounterStrikeSettings()), events, pFactory)
{ {
DisplayName = "CS:GO"; DisplayName = "CS:GO";

View File

@ -1,5 +1,6 @@
using System.IO; using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
using Artemis.InjectionFactories;
using Artemis.Managers; using Artemis.Managers;
using Artemis.Properties; using Artemis.Properties;
using Artemis.ViewModels.Abstract; using Artemis.ViewModels.Abstract;
@ -7,9 +8,10 @@ using Caliburn.Micro;
namespace Artemis.Modules.Games.Dota2 namespace Artemis.Modules.Games.Dota2
{ {
public sealed class Dota2ViewModel : GameViewModel<Dota2DataModel> public sealed class Dota2ViewModel : GameViewModel
{ {
public Dota2ViewModel(MainManager main) : base(main, new Dota2Model(main, new Dota2Settings())) public Dota2ViewModel(MainManager main, IEventAggregator events, IProfileEditorViewModelFactory pFactory)
: base(main, new Dota2Model(main, new Dota2Settings()), events, pFactory)
{ {
DisplayName = "Dota 2"; DisplayName = "Dota 2";

View File

@ -1,18 +1,20 @@
using Artemis.Managers; using Artemis.InjectionFactories;
using Artemis.Managers;
using Artemis.Settings; using Artemis.Settings;
using Artemis.Utilities; using Artemis.Utilities;
using Artemis.Utilities.Memory; using Artemis.Utilities.Memory;
using Artemis.ViewModels.Abstract; using Artemis.ViewModels.Abstract;
using Caliburn.Micro;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Artemis.Modules.Games.RocketLeague namespace Artemis.Modules.Games.RocketLeague
{ {
public sealed class RocketLeagueViewModel : GameViewModel<RocketLeagueDataModel> public sealed class RocketLeagueViewModel : GameViewModel
{ {
private string _versionText; private string _versionText;
public RocketLeagueViewModel(MainManager main) public RocketLeagueViewModel(MainManager main, IEventAggregator events, IProfileEditorViewModelFactory pFactory)
: base(main, new RocketLeagueModel(main, new RocketLeagueSettings())) : base(main, new RocketLeagueModel(main, new RocketLeagueSettings()), events, pFactory)
{ {
DisplayName = "Rocket League"; DisplayName = "Rocket League";

View File

@ -1,12 +1,14 @@
using Artemis.Managers; using Artemis.InjectionFactories;
using Artemis.Managers;
using Artemis.ViewModels.Abstract; using Artemis.ViewModels.Abstract;
using Caliburn.Micro;
namespace Artemis.Modules.Games.TheDivision namespace Artemis.Modules.Games.TheDivision
{ {
public sealed class TheDivisionViewModel : GameViewModel<TheDivisionDataModel> public sealed class TheDivisionViewModel : GameViewModel
{ {
public TheDivisionViewModel(MainManager main) public TheDivisionViewModel(MainManager main, IEventAggregator events, IProfileEditorViewModelFactory pFactory)
: base(main, new TheDivisionModel(main, new TheDivisionSettings())) : base(main, new TheDivisionModel(main, new TheDivisionSettings()), events, pFactory)
{ {
DisplayName = "The Division"; DisplayName = "The Division";
MainManager.EffectManager.EffectModels.Add(GameModel); MainManager.EffectManager.EffectModels.Add(GameModel);

View File

@ -3,16 +3,19 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using Artemis.InjectionFactories;
using Artemis.Managers; using Artemis.Managers;
using Artemis.Models.Interfaces; using Artemis.Models.Interfaces;
using Artemis.Properties; using Artemis.Properties;
using Artemis.ViewModels.Abstract; using Artemis.ViewModels.Abstract;
using Caliburn.Micro;
namespace Artemis.Modules.Games.Witcher3 namespace Artemis.Modules.Games.Witcher3
{ {
public sealed class Witcher3ViewModel : GameViewModel<Witcher3DataModel> public sealed class Witcher3ViewModel : GameViewModel
{ {
public Witcher3ViewModel(MainManager main) : base(main, new Witcher3Model(main, new Witcher3Settings())) public Witcher3ViewModel(MainManager main, IEventAggregator events, IProfileEditorViewModelFactory pFactory)
: base(main, new Witcher3Model(main, new Witcher3Settings()), events, pFactory)
{ {
DisplayName = "The Witcher 3"; DisplayName = "The Witcher 3";
MainManager.EffectManager.EffectModels.Add(GameModel); MainManager.EffectManager.EffectModels.Add(GameModel);

View File

@ -5,7 +5,7 @@ namespace Artemis.Modules.Overlays.VolumeDisplay
{ {
public sealed class VolumeDisplayViewModel : OverlayViewModel public sealed class VolumeDisplayViewModel : OverlayViewModel
{ {
public VolumeDisplayViewModel(MainManager mainManager): base(mainManager) public VolumeDisplayViewModel(MainManager mainManager) : base(mainManager)
{ {
DisplayName = "Volume Display"; DisplayName = "Volume Display";

View File

@ -53,7 +53,7 @@ namespace Artemis.ViewModels.Abstract
if (EffectEnabled) if (EffectEnabled)
MainManager.EffectManager.ClearEffect(); MainManager.EffectManager.ClearEffect();
else else
MainManager.EffectManager.ChangeEffect(EffectModel); MainManager.EffectManager.ChangeEffect(EffectModel, MainManager.LoopManager);
} }
public void SaveSettings() public void SaveSettings()

View File

@ -1,14 +1,16 @@
using System.ComponentModel; using System.ComponentModel;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Artemis.InjectionFactories;
using Artemis.Managers; using Artemis.Managers;
using Artemis.Models; using Artemis.Models;
using Artemis.Modules.Effects.ProfilePreview; using Artemis.Modules.Effects.ProfilePreview;
using Caliburn.Micro; using Caliburn.Micro;
using Ninject;
namespace Artemis.ViewModels.Abstract namespace Artemis.ViewModels.Abstract
{ {
public abstract class GameViewModel<T> : Screen public abstract class GameViewModel : Screen
{ {
private bool _doActivate; private bool _doActivate;
@ -16,18 +18,26 @@ namespace Artemis.ViewModels.Abstract
private GameSettings _gameSettings; private GameSettings _gameSettings;
private EffectModel _lastEffect; private EffectModel _lastEffect;
protected GameViewModel(MainManager mainManager, GameModel gameModel) protected GameViewModel(MainManager mainManager, GameModel gameModel, IEventAggregator events,
IProfileEditorViewModelFactory pFactory)
{ {
MainManager = mainManager; MainManager = mainManager;
GameModel = gameModel; GameModel = gameModel;
Events = events;
PFactory = pFactory;
GameSettings = gameModel.Settings; GameSettings = gameModel.Settings;
//ProfileEditor = new ProfileEditorViewModel<T>(MainManager, GameModel); ProfileEditor = PFactory.CreateProfileEditorViewModel(Events, mainManager, gameModel);
GameModel.Profile = ProfileEditor.SelectedProfile; GameModel.Profile = ProfileEditor.SelectedProfile;
ProfileEditor.PropertyChanged += ProfileUpdater; ProfileEditor.PropertyChanged += ProfileUpdater;
} }
public ProfileEditorViewModel<T> ProfileEditor { get; set; } [Inject]
public ProfilePreviewModel ProfilePreviewModel { get; set; }
public IEventAggregator Events { get; set; }
public IProfileEditorViewModelFactory PFactory { get; set; }
public ProfileEditorViewModel ProfileEditor { get; set; }
public GameModel GameModel { get; set; } public GameModel GameModel { get; set; }
public MainManager MainManager { get; set; } public MainManager MainManager { get; set; }
@ -57,7 +67,7 @@ namespace Artemis.ViewModels.Abstract
return; return;
// Restart the game if it's currently running to apply settings. // Restart the game if it's currently running to apply settings.
MainManager.EffectManager.ChangeEffect(GameModel); MainManager.EffectManager.ChangeEffect(GameModel, MainManager.LoopManager);
} }
public async void ResetSettings() public async void ResetSettings()
@ -110,8 +120,8 @@ namespace Artemis.ViewModels.Abstract
if (!(MainManager.EffectManager.ActiveEffect is ProfilePreviewModel)) if (!(MainManager.EffectManager.ActiveEffect is ProfilePreviewModel))
_lastEffect = MainManager.EffectManager.ActiveEffect; _lastEffect = MainManager.EffectManager.ActiveEffect;
MainManager.EffectManager.ProfilePreviewModel.SelectedProfile = ProfileEditor.SelectedProfile; ProfilePreviewModel.SelectedProfile = ProfileEditor.SelectedProfile;
MainManager.EffectManager.ChangeEffect(MainManager.EffectManager.ProfilePreviewModel); MainManager.EffectManager.ChangeEffect(ProfilePreviewModel, MainManager.LoopManager);
} }
else else
{ {
@ -123,7 +133,7 @@ namespace Artemis.ViewModels.Abstract
if (!gameModel.Enabled) if (!gameModel.Enabled)
MainManager.EffectManager.GetLastEffect(); MainManager.EffectManager.GetLastEffect();
else else
MainManager.EffectManager.ChangeEffect(_lastEffect); MainManager.EffectManager.ChangeEffect(_lastEffect, MainManager.LoopManager);
} }
else else
MainManager.EffectManager.ClearEffect(); MainManager.EffectManager.ClearEffect();
@ -138,7 +148,7 @@ namespace Artemis.ViewModels.Abstract
return; return;
GameModel.Profile = ProfileEditor.SelectedProfile; GameModel.Profile = ProfileEditor.SelectedProfile;
MainManager.EffectManager.ProfilePreviewModel.SelectedProfile = ProfileEditor.SelectedProfile; ProfilePreviewModel.SelectedProfile = ProfileEditor.SelectedProfile;
} }
} }

View File

@ -4,14 +4,20 @@ namespace Artemis.ViewModels
{ {
public sealed class GamesViewModel : BaseViewModel public sealed class GamesViewModel : BaseViewModel
{ {
public GamesViewModel() private readonly GameViewModel[] _gameViewModels;
public GamesViewModel(GameViewModel[] gameViewModels)
{ {
DisplayName = "Games"; DisplayName = "Games";
_gameViewModels = gameViewModels;
} }
protected override void OnActivate() protected override void OnActivate()
{ {
base.OnActivate(); base.OnActivate();
foreach (var gameViewModel in _gameViewModels)
ActivateItem(gameViewModel);
} }
} }
} }

View File

@ -6,7 +6,7 @@ using Caliburn.Micro;
namespace Artemis.ViewModels.LayerEditor namespace Artemis.ViewModels.LayerEditor
{ {
public class LayerConditionViewModel<T> : Screen public class LayerConditionViewModel : Screen
{ {
private readonly NamedOperator[] _boolOperators = private readonly NamedOperator[] _boolOperators =
{ {
@ -14,7 +14,7 @@ namespace Artemis.ViewModels.LayerEditor
new NamedOperator("False", "== False") new NamedOperator("False", "== False")
}; };
private readonly LayerEditorViewModel<T> _conditionModel; private readonly LayerEditorViewModel _conditionModel;
private readonly NamedOperator[] _int32Operators = private readonly NamedOperator[] _int32Operators =
{ {
@ -39,7 +39,7 @@ namespace Artemis.ViewModels.LayerEditor
private string _userValue; private string _userValue;
private bool _userValueIsVisible; private bool _userValueIsVisible;
public LayerConditionViewModel(LayerEditorViewModel<T> conditionModel, LayerConditionModel layerConditionModel, public LayerConditionViewModel(LayerEditorViewModel conditionModel, LayerConditionModel layerConditionModel,
BindableCollection<GeneralHelpers.PropertyCollection> dataModelProps) BindableCollection<GeneralHelpers.PropertyCollection> dataModelProps)
{ {
_conditionModel = conditionModel; _conditionModel = conditionModel;

View File

@ -14,7 +14,7 @@ using Screen = Caliburn.Micro.Screen;
namespace Artemis.ViewModels.LayerEditor namespace Artemis.ViewModels.LayerEditor
{ {
public class LayerEditorViewModel<T> : Screen public class LayerEditorViewModel : Screen
{ {
private readonly KeyboardProvider _activeKeyboard; private readonly KeyboardProvider _activeKeyboard;
private readonly MetroDialogService _dialogService; private readonly MetroDialogService _dialogService;
@ -37,10 +37,10 @@ namespace Artemis.ViewModels.LayerEditor
Layer.Enabled = false; Layer.Enabled = false;
DataModelProps = new BindableCollection<GeneralHelpers.PropertyCollection>(); DataModelProps = new BindableCollection<GeneralHelpers.PropertyCollection>();
ProposedProperties = new LayerPropertiesModel(); ProposedProperties = new LayerPropertiesModel();
DataModelProps.AddRange(GeneralHelpers.GenerateTypeMap<T>()); //DataModelProps.AddRange(GeneralHelpers.GenerateTypeMap<T>());
LayerConditionVms = LayerConditionVms =
new BindableCollection<LayerConditionViewModel<T>>( new BindableCollection<LayerConditionViewModel>(
layer.LayerConditions.Select(c => new LayerConditionViewModel<T>(this, c, DataModelProps))); layer.LayerConditions.Select(c => new LayerConditionViewModel(this, c, DataModelProps)));
HeightProperties = new LayerDynamicPropertiesViewModel("Height", DataModelProps, layer); HeightProperties = new LayerDynamicPropertiesViewModel("Height", DataModelProps, layer);
WidthProperties = new LayerDynamicPropertiesViewModel("Width", DataModelProps, layer); WidthProperties = new LayerDynamicPropertiesViewModel("Width", DataModelProps, layer);
OpacityProperties = new LayerDynamicPropertiesViewModel("Opacity", DataModelProps, layer); OpacityProperties = new LayerDynamicPropertiesViewModel("Opacity", DataModelProps, layer);
@ -63,7 +63,7 @@ namespace Artemis.ViewModels.LayerEditor
public BindableCollection<string> LayerTypes => new BindableCollection<string>(); public BindableCollection<string> LayerTypes => new BindableCollection<string>();
public BindableCollection<LayerConditionViewModel<T>> LayerConditionVms { get; set; } public BindableCollection<LayerConditionViewModel> LayerConditionVms { get; set; }
public LayerModel Layer public LayerModel Layer
{ {
@ -166,7 +166,7 @@ namespace Artemis.ViewModels.LayerEditor
{ {
var condition = new LayerConditionModel(); var condition = new LayerConditionModel();
Layer.LayerConditions.Add(condition); Layer.LayerConditions.Add(condition);
LayerConditionVms.Add(new LayerConditionViewModel<T>(this, condition, DataModelProps)); LayerConditionVms.Add(new LayerConditionViewModel(this, condition, DataModelProps));
} }
public void Apply() public void Apply()
@ -180,7 +180,7 @@ namespace Artemis.ViewModels.LayerEditor
_dialogService.ShowErrorMessageBox("Couldn't find or access the provided GIF file."); _dialogService.ShowErrorMessageBox("Couldn't find or access the provided GIF file.");
} }
public void DeleteCondition(LayerConditionViewModel<T> layerConditionViewModel, public void DeleteCondition(LayerConditionViewModel layerConditionViewModel,
LayerConditionModel layerConditionModel) LayerConditionModel layerConditionModel)
{ {
LayerConditionVms.Remove(layerConditionViewModel); LayerConditionVms.Remove(layerConditionViewModel);

View File

@ -19,15 +19,14 @@ using MahApps.Metro;
namespace Artemis.ViewModels namespace Artemis.ViewModels
{ {
public sealed class ProfileEditorViewModel<T> : Screen, IHandle<ActiveKeyboardChanged> public sealed class ProfileEditorViewModel : Screen, IHandle<ActiveKeyboardChanged>
{ {
private readonly GameModel _gameModel; private readonly GameModel _gameModel;
private readonly KeyboardManager _keyboardManager;
private readonly MainManager _mainManager; private readonly MainManager _mainManager;
private DateTime _downTime; private DateTime _downTime;
private LayerModel _draggingLayer; private LayerModel _draggingLayer;
private Point? _draggingLayerOffset; private Point? _draggingLayerOffset;
private LayerEditorViewModel<T> _editorVm; private LayerEditorViewModel _editorVm;
private Cursor _keyboardPreviewCursor; private Cursor _keyboardPreviewCursor;
private BindableCollection<LayerModel> _layers; private BindableCollection<LayerModel> _layers;
private BindableCollection<ProfileModel> _profiles; private BindableCollection<ProfileModel> _profiles;
@ -35,11 +34,9 @@ namespace Artemis.ViewModels
private LayerModel _selectedLayer; private LayerModel _selectedLayer;
private ProfileModel _selectedProfile; private ProfileModel _selectedProfile;
public ProfileEditorViewModel(MainManager mainManager, KeyboardManager keyboardManager, GameModel gameModel, public ProfileEditorViewModel(IEventAggregator events, MainManager mainManager, GameModel gameModel)
IEventAggregator events)
{ {
_mainManager = mainManager; _mainManager = mainManager;
_keyboardManager = keyboardManager;
_gameModel = gameModel; _gameModel = gameModel;
Profiles = new BindableCollection<ProfileModel>(); Profiles = new BindableCollection<ProfileModel>();
@ -50,10 +47,6 @@ namespace Artemis.ViewModels
LoadProfiles(); LoadProfiles();
} }
public ProfileEditorViewModel()
{
}
public BindableCollection<ProfileModel> Profiles public BindableCollection<ProfileModel> Profiles
{ {
get { return _profiles; } get { return _profiles; }
@ -180,7 +173,7 @@ namespace Artemis.ViewModels
public bool CanAddLayer => _selectedProfile != null; public bool CanAddLayer => _selectedProfile != null;
public bool CanRemoveLayer => _selectedProfile != null && _selectedLayer != null; public bool CanRemoveLayer => _selectedProfile != null && _selectedLayer != null;
private KeyboardProvider ActiveKeyboard => _keyboardManager.ActiveKeyboard; private KeyboardProvider ActiveKeyboard => _mainManager.KeyboardManager.ActiveKeyboard;
/// <summary> /// <summary>
/// Handles chaning the active keyboard, updating the preview image and profiles collection /// Handles chaning the active keyboard, updating the preview image and profiles collection
@ -265,7 +258,7 @@ namespace Artemis.ViewModels
public void LayerEditor(LayerModel layer) public void LayerEditor(LayerModel layer)
{ {
IWindowManager manager = new WindowManager(); IWindowManager manager = new WindowManager();
_editorVm = new LayerEditorViewModel<T>(ActiveKeyboard, layer); _editorVm = new LayerEditorViewModel(ActiveKeyboard, layer);
dynamic settings = new ExpandoObject(); dynamic settings = new ExpandoObject();
settings.Title = "Artemis | Edit " + layer.Name; settings.Title = "Artemis | Edit " + layer.Name;

View File

@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="Caliburn.Micro" version="3.0.1" targetFramework="net452" /> <package id="Caliburn.Micro" version="3.0.1" targetFramework="net452" />
<package id="Caliburn.Micro.Core" version="3.0.1" targetFramework="net452" /> <package id="Caliburn.Micro.Core" version="3.0.1" targetFramework="net452" />
<package id="Castle.Core" version="3.2.0" targetFramework="net452" />
<package id="Colore" version="4.0.0" targetFramework="net452" /> <package id="Colore" version="4.0.0" targetFramework="net452" />
<package id="CUE.NET" version="1.0.2.2" targetFramework="net452" /> <package id="CUE.NET" version="1.0.2.2" targetFramework="net452" />
<package id="Extended.Wpf.Toolkit" version="2.7" targetFramework="net452" /> <package id="Extended.Wpf.Toolkit" version="2.7" targetFramework="net452" />
@ -13,6 +15,7 @@
<package id="NAudio" version="1.7.3" targetFramework="net452" /> <package id="NAudio" version="1.7.3" targetFramework="net452" />
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net452" /> <package id="Newtonsoft.Json" version="8.0.3" targetFramework="net452" />
<package id="Ninject" version="3.2.2.0" targetFramework="net452" /> <package id="Ninject" version="3.2.2.0" targetFramework="net452" />
<package id="Ninject.Extensions.Factory" version="3.2.1.0" targetFramework="net452" />
<package id="Ninject.Extensions.Logging" version="3.2.3.0" targetFramework="net452" /> <package id="Ninject.Extensions.Logging" version="3.2.3.0" targetFramework="net452" />
<package id="Ninject.Extensions.Logging.nlog4" version="3.2.3.0" targetFramework="net452" /> <package id="Ninject.Extensions.Logging.nlog4" version="3.2.3.0" targetFramework="net452" />
<package id="NLog" version="4.3.3" targetFramework="net452" /> <package id="NLog" version="4.3.3" targetFramework="net452" />