1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 21:38:38 +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>
<Private>True</Private>
</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">
<SpecificVersion>False</SpecificVersion>
<HintPath>lib\ColorBox.dll</HintPath>
@ -175,6 +179,10 @@
<HintPath>..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll</HintPath>
<Private>True</Private>
</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">
<HintPath>..\packages\Ninject.Extensions.Logging.3.2.3.0\lib\net45-full\Ninject.Extensions.Logging.dll</HintPath>
<Private>True</Private>
@ -274,6 +282,7 @@
<Compile Include="Events\ToggleEnabled.cs" />
<Compile Include="Events\ActiveEffectChanged.cs" />
<Compile Include="Events\ChangeBitmap.cs" />
<Compile Include="InjectionFactories\IProfileEditorViewModelFactory.cs" />
<Compile Include="ItemBehaviours\BindableSelectedItemBehavior.cs" />
<Compile Include="KeyboardProviders\Corsair\CorsairRGB.cs" />
<Compile Include="KeyboardProviders\KeyboardProvider.cs" />
@ -379,9 +388,9 @@
<Compile Include="Modules\Overlays\VolumeDisplay\VolumeDisplaySettings.cs" />
<Compile Include="Modules\Games\RocketLeague\RocketLeagueSettings.cs" />
<Compile Include="Modules\Effects\TypeWave\TypeWaveSettings.cs" />
<Compile Include="NinjectModules\ArtemisModules.cs" />
<Compile Include="NinjectModules\BaseModules.cs" />
<Compile Include="NinjectModules\ManagerModules.cs" />
<Compile Include="InjectionModules\ArtemisModules.cs" />
<Compile Include="InjectionModules\BaseModules.cs" />
<Compile Include="InjectionModules\ManagerModules.cs" />
<Compile Include="Properties\Annotations.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>

View File

@ -6,7 +6,7 @@ using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using Artemis.NinjectModules;
using Artemis.InjectionModules;
using Artemis.ViewModels;
using Caliburn.Micro;
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.Overlays.VolumeDisplay;
using Artemis.ViewModels.Abstract;
using Caliburn.Micro;
using Ninject.Modules;
namespace Artemis.NinjectModules
namespace Artemis.InjectionModules
{
public class ArtemisModules : NinjectModule
{
public override void Load()
{
// Effects
Bind<Screen>().To<EffectViewModel>(); // TODO: Needed?
Bind<EffectViewModel>().To<AudioVisualizerViewModel>().InSingletonScope();
Bind<EffectViewModel>().To<DebugEffectViewModel>().InSingletonScope();
Bind<EffectViewModel>().To<TypeWaveViewModel>().InSingletonScope();
//Bind<EffectViewModel>().To<AmbientLightningEffectViewModel>().InSingletonScope();
// Games
Bind<Screen>().To(typeof(GameViewModel<>)); // TODO: Needed?
Bind<GameViewModel<CounterStrikeDataModel>>().To<CounterStrikeViewModel>().InSingletonScope();
Bind<GameViewModel<Dota2DataModel>>().To<Dota2ViewModel>().InSingletonScope();
Bind<GameViewModel<RocketLeagueDataModel>>().To<RocketLeagueViewModel>().InSingletonScope();
Bind<GameViewModel<TheDivisionDataModel>>().To<TheDivisionViewModel>().InSingletonScope();
Bind<GameViewModel<Witcher3DataModel>>().To<Witcher3ViewModel>().InSingletonScope();
Bind<GameViewModel>().To<CounterStrikeViewModel>().InSingletonScope();
Bind<GameViewModel>().To<Dota2ViewModel>().InSingletonScope();
Bind<GameViewModel>().To<RocketLeagueViewModel>().InSingletonScope();
Bind<GameViewModel>().To<TheDivisionViewModel>().InSingletonScope();
Bind<GameViewModel>().To<Witcher3ViewModel>().InSingletonScope();
// Overlays
Bind<Screen>().To<OverlayViewModel>(); // TODO: Needed?
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 Caliburn.Micro;
using Ninject.Extensions.Factory;
using Ninject.Modules;
namespace Artemis.NinjectModules
namespace Artemis.InjectionModules
{
internal class BaseModules : NinjectModule
{
@ -11,10 +14,14 @@ namespace Artemis.NinjectModules
{
// ViewModels
Bind<IScreen>().To<ShellViewModel>().InSingletonScope();
Bind<IProfileEditorViewModelFactory>().ToFactory();
Bind<BaseViewModel>().To<EffectsViewModel>().InSingletonScope();
Bind<BaseViewModel>().To<GamesViewModel>().InSingletonScope();
Bind<BaseViewModel>().To<OverlaysViewModel>().InSingletonScope();
// Models
Bind<ProfilePreviewModel>().ToSelf().InSingletonScope();
}
}
}

View File

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

View File

@ -18,23 +18,19 @@ namespace Artemis.Managers
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly IEventAggregator _events;
private readonly KeyboardManager _keyboardManager;
private EffectModel _activeEffect;
public EffectManager(IEventAggregator events)
public EffectManager(IEventAggregator events, KeyboardManager keyboardManager)
{
Logger.Info("Intializing EffectManager");
_events = events;
_keyboardManager = keyboardManager;
EffectModels = new List<EffectModel>();
//ProfilePreviewModel = new ProfilePreviewModel(MainManager.Value);
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>
/// Holds all the effects the program has
/// </summary>
@ -81,42 +77,53 @@ namespace Artemis.Managers
/// <summary>
/// Disables the current effect and changes it to the provided effect.
/// </summary>
/// <param name="effectModel"></param>
/// <param name="force">Changes the effect, even if it's already running (effectively restarting it)</param>
public void ChangeEffect(EffectModel effectModel)
/// <param name="effectModel">The effect to activate</param>
/// <param name="loopManager">Optionally pass the LoopManager to automatically start it, if it's not running.</param>
public void ChangeEffect(EffectModel effectModel, LoopManager loopManager = null)
{
if (effectModel == null)
throw new ArgumentNullException(nameof(effectModel));
if (effectModel is OverlayModel)
throw new ArgumentException("Can't set an Overlay effect as the active effect");
// Game models are only used if they are enabled
var gameModel = effectModel as GameModel;
if (gameModel != null)
if (!gameModel.Enabled)
return;
if (_keyboardManager.ActiveKeyboard == null)
_keyboardManager.EnableLastKeyboard();
var wasNull = false;
if (ActiveEffect == null)
lock (_keyboardManager.ActiveKeyboard)
{
wasNull = true;
ActiveEffect = effectModel;
// Game models are only used if they are enabled
var gameModel = effectModel as GameModel;
if (gameModel != null)
if (!gameModel.Enabled)
return;
var wasNull = false;
if (ActiveEffect == null)
{
wasNull = true;
ActiveEffect = effectModel;
}
lock (ActiveEffect)
{
if (!wasNull)
ActiveEffect.Dispose();
ActiveEffect = effectModel;
ActiveEffect.Enable();
if (ActiveEffect is GameModel || ActiveEffect is ProfilePreviewModel)
return;
// Non-game effects are stored as the new LastEffect.
General.Default.LastEffect = ActiveEffect?.Name;
General.Default.Save();
}
}
lock (ActiveEffect)
if (loopManager != null && !loopManager.Running)
{
if (!wasNull)
ActiveEffect.Dispose();
ActiveEffect = effectModel;
ActiveEffect.Enable();
if (ActiveEffect is GameModel || ActiveEffect is ProfilePreviewModel)
return;
// Non-game effects are stored as the new LastEffect.
General.Default.LastEffect = ActiveEffect?.Name;
General.Default.Save();
loopManager.Start();
}
Logger.Debug($"Changed active effect to: {effectModel.Name}");
@ -128,13 +135,16 @@ namespace Artemis.Managers
/// </summary>
public void ClearEffect()
{
lock (ActiveEffect)
lock (_keyboardManager.ActiveKeyboard)
{
ActiveEffect.Dispose();
ActiveEffect = null;
lock (ActiveEffect)
{
ActiveEffect.Dispose();
ActiveEffect = null;
General.Default.LastEffect = null;
General.Default.Save();
General.Default.LastEffect = null;
General.Default.Save();
}
}
Logger.Debug("Cleared active effect");

View File

@ -107,7 +107,7 @@ namespace Artemis.Managers
{
if (ActiveKeyboard == null)
return;
ActiveKeyboard.Disable();
ActiveKeyboard = null;
}

View File

@ -45,7 +45,18 @@ namespace Artemis.Managers
public void Start()
{
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;
}
@ -55,7 +66,7 @@ namespace Artemis.Managers
Logger.Debug("Stopping LoopManager");
Running = false;
// Shut down
_keyboardManager.ReleaseActiveKeyboard();
}
private void Render(object sender, ElapsedEventArgs e)
@ -63,21 +74,21 @@ namespace Artemis.Managers
if (!Running)
return;
// Stop if no active keyboard/efffect
if (_keyboardManager.ActiveKeyboard == null || _effectManager.ActiveEffect == null)
{
Logger.Debug("No active keyboard/effect, stopping. " +
$"Keyboard={_keyboardManager.ActiveKeyboard?.Name}, " +
$"effect={_effectManager.ActiveEffect?.Name}");
Stop();
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
if (_keyboardManager.ActiveKeyboard == null || _effectManager.ActiveEffect == null)
{
Logger.Debug("No active keyboard/effect, stopping. " +
$"Keyboard={_keyboardManager.ActiveKeyboard?.Name}, " +
$"effect={_effectManager.ActiveEffect?.Name}");
Stop();
return;
}
// Skip frame if effect is still initializing
if (_effectManager.ActiveEffect.Initialized == false)
return;

View File

@ -65,7 +65,7 @@ namespace Artemis.Managers
public Lazy<ShellViewModel> ShellViewModel { get; set; }
public ILogger Logger { get; }
private LoopManager LoopManager { get; }
public LoopManager LoopManager { get; }
public KeyboardManager KeyboardManager { get; set; }
public EffectManager EffectManager { get; set; }
@ -81,55 +81,13 @@ namespace Artemis.Managers
public void Dispose()
{
Logger.Debug("Shutting down MainManager");
Stop();
LoopManager.Stop();
ProcessWorker.CancelAsync();
ProcessWorker.CancelAsync();
GameStateWebServer.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>
/// Loads the last active effect and starts the program
/// </summary>
@ -137,7 +95,7 @@ namespace Artemis.Managers
{
Logger.Debug("Enabling program");
ProgramEnabled = true;
Start(EffectManager.GetLastEffect());
LoopManager.Start();
_events.PublishOnUIThread(new ToggleEnabled(ProgramEnabled));
}
@ -147,7 +105,7 @@ namespace Artemis.Managers
public void DisableProgram()
{
Logger.Debug("Disabling program");
Stop();
LoopManager.Stop();
ProgramEnabled = false;
_events.PublishOnUIThread(new ToggleEnabled(ProgramEnabled));
}

View File

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

View File

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

View File

@ -8,7 +8,7 @@ namespace Artemis.Models
private bool _enabled;
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;
public ProfilePreviewModel(MainManager main) : base(main)
public ProfilePreviewModel(MainManager mainManager) : base(mainManager)
{
Name = "Profile Preview";
_previewDataModel = new ProfilePreviewDataModel();

View File

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

View File

@ -1,5 +1,6 @@
using System.IO;
using System.Windows.Forms;
using Artemis.InjectionFactories;
using Artemis.Managers;
using Artemis.Properties;
using Artemis.ViewModels.Abstract;
@ -7,9 +8,10 @@ using Caliburn.Micro;
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";

View File

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

View File

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

View File

@ -3,16 +3,19 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using Artemis.InjectionFactories;
using Artemis.Managers;
using Artemis.Models.Interfaces;
using Artemis.Properties;
using Artemis.ViewModels.Abstract;
using Caliburn.Micro;
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";
MainManager.EffectManager.EffectModels.Add(GameModel);

View File

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

View File

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

View File

@ -1,14 +1,16 @@
using System.ComponentModel;
using System.Threading;
using System.Threading.Tasks;
using Artemis.InjectionFactories;
using Artemis.Managers;
using Artemis.Models;
using Artemis.Modules.Effects.ProfilePreview;
using Caliburn.Micro;
using Ninject;
namespace Artemis.ViewModels.Abstract
{
public abstract class GameViewModel<T> : Screen
public abstract class GameViewModel : Screen
{
private bool _doActivate;
@ -16,18 +18,26 @@ namespace Artemis.ViewModels.Abstract
private GameSettings _gameSettings;
private EffectModel _lastEffect;
protected GameViewModel(MainManager mainManager, GameModel gameModel)
protected GameViewModel(MainManager mainManager, GameModel gameModel, IEventAggregator events,
IProfileEditorViewModelFactory pFactory)
{
MainManager = mainManager;
GameModel = gameModel;
Events = events;
PFactory = pFactory;
GameSettings = gameModel.Settings;
//ProfileEditor = new ProfileEditorViewModel<T>(MainManager, GameModel);
ProfileEditor = PFactory.CreateProfileEditorViewModel(Events, mainManager, gameModel);
GameModel.Profile = ProfileEditor.SelectedProfile;
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 MainManager MainManager { get; set; }
@ -57,7 +67,7 @@ namespace Artemis.ViewModels.Abstract
return;
// 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()
@ -110,8 +120,8 @@ namespace Artemis.ViewModels.Abstract
if (!(MainManager.EffectManager.ActiveEffect is ProfilePreviewModel))
_lastEffect = MainManager.EffectManager.ActiveEffect;
MainManager.EffectManager.ProfilePreviewModel.SelectedProfile = ProfileEditor.SelectedProfile;
MainManager.EffectManager.ChangeEffect(MainManager.EffectManager.ProfilePreviewModel);
ProfilePreviewModel.SelectedProfile = ProfileEditor.SelectedProfile;
MainManager.EffectManager.ChangeEffect(ProfilePreviewModel, MainManager.LoopManager);
}
else
{
@ -123,7 +133,7 @@ namespace Artemis.ViewModels.Abstract
if (!gameModel.Enabled)
MainManager.EffectManager.GetLastEffect();
else
MainManager.EffectManager.ChangeEffect(_lastEffect);
MainManager.EffectManager.ChangeEffect(_lastEffect, MainManager.LoopManager);
}
else
MainManager.EffectManager.ClearEffect();
@ -138,7 +148,7 @@ namespace Artemis.ViewModels.Abstract
return;
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 GamesViewModel()
private readonly GameViewModel[] _gameViewModels;
public GamesViewModel(GameViewModel[] gameViewModels)
{
DisplayName = "Games";
_gameViewModels = gameViewModels;
}
protected override void OnActivate()
{
base.OnActivate();
foreach (var gameViewModel in _gameViewModels)
ActivateItem(gameViewModel);
}
}
}

View File

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

View File

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

View File

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

View File

@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Caliburn.Micro" 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="CUE.NET" version="1.0.2.2" 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="Newtonsoft.Json" version="8.0.3" 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.nlog4" version="3.2.3.0" targetFramework="net452" />
<package id="NLog" version="4.3.3" targetFramework="net452" />