diff --git a/Artemis/Artemis/Managers/MainManager.cs b/Artemis/Artemis/Managers/MainManager.cs
index 9c754e270..c266bb4d8 100644
--- a/Artemis/Artemis/Managers/MainManager.cs
+++ b/Artemis/Artemis/Managers/MainManager.cs
@@ -105,16 +105,12 @@ namespace Artemis.Managers
///
/// Loads the last active effect and starts the program
///
- public void EnableProgram()
+ public async void EnableProgram()
{
Logger.Debug("Enabling program");
ProgramEnabled = true;
- LoopManager.StartAsync();
- foreach (var overlayModule in ModuleManager.OverlayModules)
- {
- if (overlayModule.Settings.IsEnabled)
- overlayModule.Enable();
- }
+ await LoopManager.StartAsync();
+
RaiseEnabledChangedEvent(new EnabledChangedEventArgs(ProgramEnabled));
}
diff --git a/Artemis/Artemis/Modules/Abstract/ModuleViewModel.cs b/Artemis/Artemis/Modules/Abstract/ModuleViewModel.cs
index e20501ac8..ff70eba65 100644
--- a/Artemis/Artemis/Modules/Abstract/ModuleViewModel.cs
+++ b/Artemis/Artemis/Modules/Abstract/ModuleViewModel.cs
@@ -68,7 +68,7 @@ namespace Artemis.Modules.Abstract
{
get
{
- if (ModuleModel.IsBoundToProcess || ModuleModel.IsBoundToProcess)
+ if (ModuleModel.IsBoundToProcess || ModuleModel.IsOverlay)
return Settings.IsEnabled;
return _generalSettings.LastModule == ModuleModel.Name;
}
diff --git a/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2Model.cs b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2Model.cs
index 5006d126f..3c7b18606 100644
--- a/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2Model.cs
+++ b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2Model.cs
@@ -59,7 +59,7 @@ namespace Artemis.Modules.Games.EurotruckSimulator2
Settings.Save();
if (!File.Exists(dir + "/plugins/ets2-telemetry-server.dll"))
- PlacePlugins();
+ PlaceTruckSimulatorPlugin(dir, "eurotrucks2.exe");
}
public void FindAtsGameDir()
@@ -76,22 +76,14 @@ namespace Artemis.Modules.Games.EurotruckSimulator2
Settings.Save();
if (!File.Exists(dir + "/plugins/ets2-telemetry-server.dll"))
- PlacePlugins();
+ PlaceTruckSimulatorPlugin(dir, "amtrucks.exe");
}
- public void PlacePlugins()
+ public void PlaceTruckSimulatorPlugin(string path, string game)
{
- var ets2Path = ((EurotruckSimulator2Settings) Settings).Ets2GameDirectory;
- if (!string.IsNullOrEmpty(ets2Path))
- PlaceTruckSimulatorPlugin(ets2Path, "eurotrucks2.exe");
+ if (string.IsNullOrEmpty(path))
+ return;
- var atsPath = ((EurotruckSimulator2Settings) Settings).AtsGameDirectory;
- if (!string.IsNullOrEmpty(atsPath))
- PlaceTruckSimulatorPlugin(atsPath, "amtrucks.exe");
- }
-
- private void PlaceTruckSimulatorPlugin(string path, string game)
- {
// Ensure the selected directory exists
if (!Directory.Exists(path))
{
diff --git a/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2View.xaml b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2View.xaml
index c8c7588cf..281aa5825 100644
--- a/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2View.xaml
+++ b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2View.xaml
@@ -68,7 +68,7 @@
+ cal:Message.Attach="[Event LostFocus] = [Action Ets2PlacePlugin]" />
@@ -80,7 +80,7 @@
+ cal:Message.Attach="[Event LostFocus] = [Action AtsPlacePlugin]" />
diff --git a/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2ViewModel.cs b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2ViewModel.cs
index 8fef6932b..6371900b5 100644
--- a/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2ViewModel.cs
+++ b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2ViewModel.cs
@@ -1,5 +1,4 @@
-using System.IO;
-using System.Windows.Forms;
+using System.Windows.Forms;
using Artemis.Managers;
using Artemis.Modules.Abstract;
using Ninject;
@@ -17,39 +16,48 @@ namespace Artemis.Modules.Games.EurotruckSimulator2
public override bool UsesProfileEditor => true;
- public void PlacePlugins()
- {
- ((EurotruckSimulator2Model) ModuleModel).PlacePlugins();
- }
-
public void Ets2BrowseDirectory()
{
var settings = (EurotruckSimulator2Settings) Settings;
+ var model = (EurotruckSimulator2Model) ModuleModel;
+
var dialog = new FolderBrowserDialog {SelectedPath = settings.Ets2GameDirectory};
var result = dialog.ShowDialog();
if (result != DialogResult.OK)
return;
- settings.Ets2GameDirectory = Path.GetDirectoryName(dialog.SelectedPath);
+ settings.Ets2GameDirectory = dialog.SelectedPath;
NotifyOfPropertyChange(() => Settings);
Settings.Save();
-
- ((EurotruckSimulator2Model) ModuleModel).PlacePlugins();
+ model.PlaceTruckSimulatorPlugin(settings.Ets2GameDirectory, "eurotrucks2.exe");
}
public void AtsBrowseDirectory()
{
var settings = (EurotruckSimulator2Settings) Settings;
+ var model = (EurotruckSimulator2Model)ModuleModel;
+
var dialog = new FolderBrowserDialog {SelectedPath = settings.AtsGameDirectory};
var result = dialog.ShowDialog();
if (result != DialogResult.OK)
return;
- settings.AtsGameDirectory = Path.GetDirectoryName(dialog.SelectedPath);
+ settings.AtsGameDirectory = dialog.SelectedPath;
NotifyOfPropertyChange(() => Settings);
Settings.Save();
+ model.PlaceTruckSimulatorPlugin(settings.Ets2GameDirectory, "amtrucks.exe");
+ }
+
+ public void Ets2PlacePlugin()
+ {
+ var ets2Path = ((EurotruckSimulator2Settings)Settings).Ets2GameDirectory;
+ ((EurotruckSimulator2Model)ModuleModel).PlaceTruckSimulatorPlugin(ets2Path, "eurotrucks2.exe");
+ }
- ((EurotruckSimulator2Model) ModuleModel).PlacePlugins();
+ public void AtsPlacePlugin()
+ {
+ var atsPath = ((EurotruckSimulator2Settings)Settings).AtsGameDirectory;
+ ((EurotruckSimulator2Model)ModuleModel).PlaceTruckSimulatorPlugin(atsPath, "amtrucks.exe");
}
}
}
\ No newline at end of file
diff --git a/Artemis/Artemis/Modules/Overlays/OverlayProfile/OverlayProfileDataModel.cs b/Artemis/Artemis/Modules/Overlays/OverlayProfile/OverlayProfileDataModel.cs
index 7e94aee59..595471b87 100644
--- a/Artemis/Artemis/Modules/Overlays/OverlayProfile/OverlayProfileDataModel.cs
+++ b/Artemis/Artemis/Modules/Overlays/OverlayProfile/OverlayProfileDataModel.cs
@@ -1,5 +1,6 @@
using Artemis.Modules.Abstract;
using Artemis.Modules.General.GeneralProfile;
+using MoonSharp.Interpreter;
namespace Artemis.Modules.Overlays.OverlayProfile
{
@@ -7,9 +8,17 @@ namespace Artemis.Modules.Overlays.OverlayProfile
{
public OverlayProfileDataModel()
{
- GeneralDataModel = new GeneralProfileDataModel();
+ Keyboard = new KbDataModel();
+ Audio = new Audio();
}
- public GeneralProfileDataModel GeneralDataModel { get; set; }
+ public KbDataModel Keyboard { get; set; }
+ public Audio Audio { get; set; }
+ }
+
+ [MoonSharpUserData]
+ public class Audio
+ {
+ public float Volume { get; set; }
}
}
\ No newline at end of file
diff --git a/Artemis/Artemis/Modules/Overlays/OverlayProfile/OverlayProfileModel.cs b/Artemis/Artemis/Modules/Overlays/OverlayProfile/OverlayProfileModel.cs
index 349c7ed6a..2a6c05f2b 100644
--- a/Artemis/Artemis/Modules/Overlays/OverlayProfile/OverlayProfileModel.cs
+++ b/Artemis/Artemis/Modules/Overlays/OverlayProfile/OverlayProfileModel.cs
@@ -1,34 +1,62 @@
using Artemis.DAL;
+using Artemis.Events;
using Artemis.Managers;
using Artemis.Modules.Abstract;
using Artemis.Modules.General.GeneralProfile;
-using Ninject;
+using CSCore.CoreAudioAPI;
namespace Artemis.Modules.Overlays.OverlayProfile
{
public class OverlayProfileModel : ModuleModel
{
- private readonly GeneralProfileModel _generalProfileModule;
+ private AudioEndpointVolume _endPointVolume;
public OverlayProfileModel(DeviceManager deviceManager, LuaManager luaManager,
- [Named(nameof(GeneralProfileModel))] ModuleModel generalProfileModule) : base(deviceManager, luaManager)
+ AudioCaptureManager audioCaptureManager) : base(deviceManager, luaManager)
{
- _generalProfileModule = (GeneralProfileModel) generalProfileModule;
Settings = SettingsProvider.Load();
DataModel = new OverlayProfileDataModel();
+
+ var defaultPlayback = MMDeviceEnumerator.DefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
+ _endPointVolume = AudioEndpointVolume.FromDevice(defaultPlayback);
+ audioCaptureManager.AudioDeviceChanged += OnAudioDeviceChanged;
+
+ Enable();
}
public override string Name => "OverlayProfile";
public override bool IsOverlay => true;
public override bool IsBoundToProcess => false;
+ private void OnAudioDeviceChanged(object sender, AudioDeviceChangedEventArgs e)
+ {
+ _endPointVolume = AudioEndpointVolume.FromDevice(e.DefaultPlayback);
+ }
+
public override void Update()
{
+ if (!Settings.IsEnabled)
+ return;
+
var dataModel = (OverlayProfileDataModel) DataModel;
- if (!_generalProfileModule.IsInitialized)
- _generalProfileModule.Update();
- dataModel.GeneralDataModel = (GeneralProfileDataModel) _generalProfileModule.DataModel;
+ dataModel.Keyboard.NumLock = ((ushort) GeneralProfileModel.GetKeyState(0x90) & 0xffff) != 0;
+ dataModel.Keyboard.CapsLock = ((ushort) GeneralProfileModel.GetKeyState(0x14) & 0xffff) != 0;
+ dataModel.Keyboard.ScrollLock = ((ushort) GeneralProfileModel.GetKeyState(0x91) & 0xffff) != 0;
+
+ if (_endPointVolume != null)
+ dataModel.Audio.Volume = _endPointVolume.GetMasterVolumeLevelScalar();
+ }
+
+ public override void Render(RenderFrame frame, bool keyboardOnly)
+ {
+ if (Settings.IsEnabled)
+ base.Render(frame, keyboardOnly);
+ }
+
+ public override void Dispose()
+ {
+ PreviewLayers = null;
}
}
}
\ No newline at end of file
diff --git a/Artemis/Artemis/Profiles/Layers/Animations/GrowAnimation.cs b/Artemis/Artemis/Profiles/Layers/Animations/GrowAnimation.cs
index 0d5144150..83e9479e8 100644
--- a/Artemis/Artemis/Profiles/Layers/Animations/GrowAnimation.cs
+++ b/Artemis/Artemis/Profiles/Layers/Animations/GrowAnimation.cs
@@ -27,17 +27,17 @@ namespace Artemis.Profiles.Layers.Animations
layerModel.AnimationProgress = progress;
}
- public void Draw(LayerModel layerModel, DrawingContext c)
+ public void Draw(LayerModel layerModel, DrawingContext c, int drawScale)
{
if (layerModel.Brush == null)
return;
// Set up variables for this frame
var rect = layerModel.Properties.Contain
- ? layerModel.LayerRect()
- : layerModel.Properties.PropertiesRect();
+ ? layerModel.LayerRect(drawScale)
+ : layerModel.Properties.PropertiesRect(drawScale);
- var clip = layerModel.LayerRect();
+ var clip = layerModel.LayerRect(drawScale);
// Take an offset of 4 to allow layers to slightly leave their bounds
var progress = (6.0 - layerModel.AnimationProgress)*10.0;
diff --git a/Artemis/Artemis/Profiles/Layers/Animations/NoneAnimation.cs b/Artemis/Artemis/Profiles/Layers/Animations/NoneAnimation.cs
index 0d0e759ea..1defbd18a 100644
--- a/Artemis/Artemis/Profiles/Layers/Animations/NoneAnimation.cs
+++ b/Artemis/Artemis/Profiles/Layers/Animations/NoneAnimation.cs
@@ -12,7 +12,7 @@ namespace Artemis.Profiles.Layers.Animations
{
}
- public void Draw(LayerModel layerModel, DrawingContext c)
+ public void Draw(LayerModel layerModel, DrawingContext c, int drawScale)
{
}
diff --git a/Artemis/Artemis/Profiles/Layers/Animations/PulseAnimation.cs b/Artemis/Artemis/Profiles/Layers/Animations/PulseAnimation.cs
index 669452134..52fbf1d88 100644
--- a/Artemis/Artemis/Profiles/Layers/Animations/PulseAnimation.cs
+++ b/Artemis/Artemis/Profiles/Layers/Animations/PulseAnimation.cs
@@ -27,17 +27,17 @@ namespace Artemis.Profiles.Layers.Animations
layerModel.AnimationProgress = progress;
}
- public void Draw(LayerModel layerModel, DrawingContext c)
+ public void Draw(LayerModel layerModel, DrawingContext c, int drawScale)
{
if (layerModel.Brush == null)
return;
// Set up variables for this frame
var rect = layerModel.Properties.Contain
- ? layerModel.LayerRect()
- : layerModel.Properties.PropertiesRect();
+ ? layerModel.LayerRect(drawScale)
+ : layerModel.Properties.PropertiesRect(drawScale);
- var clip = layerModel.LayerRect();
+ var clip = layerModel.LayerRect(drawScale);
// Can't meddle with the original brush because it's frozen.
var brush = layerModel.Brush.Clone();
diff --git a/Artemis/Artemis/Profiles/Layers/Animations/SlideDownAnimation.cs b/Artemis/Artemis/Profiles/Layers/Animations/SlideDownAnimation.cs
index 81a7cbca8..ed584e6f8 100644
--- a/Artemis/Artemis/Profiles/Layers/Animations/SlideDownAnimation.cs
+++ b/Artemis/Artemis/Profiles/Layers/Animations/SlideDownAnimation.cs
@@ -14,29 +14,29 @@ namespace Artemis.Profiles.Layers.Animations
var progress = layerModel.AnimationProgress;
if (MustExpire(layerModel))
progress = 0;
- progress = progress + layerModel.Properties.AnimationSpeed*2;
+ progress = progress + layerModel.Properties.AnimationSpeed * 2 / 4 * layerModel.LayerType.DrawScale;
// If not previewing, store the animation progress in the actual model for the next frame
if (updateAnimations)
layerModel.AnimationProgress = progress;
}
- public void Draw(LayerModel layerModel, DrawingContext c)
+ public void Draw(LayerModel layerModel, DrawingContext c, int drawScale)
{
if (layerModel.Brush == null)
return;
// Set up variables for this frame
var rect = layerModel.Properties.Contain
- ? layerModel.LayerRect()
- : layerModel.Properties.PropertiesRect();
+ ? layerModel.LayerRect(drawScale)
+ : layerModel.Properties.PropertiesRect(drawScale);
var s1 = new Rect(new Point(rect.X, rect.Y + layerModel.AnimationProgress),
new Size(rect.Width, rect.Height));
- var s2 = new Rect(new Point(s1.X, s1.Y - rect.Height),
+ var s2 = new Rect(new Point(s1.X, s1.Y - rect.Height),
new Size(rect.Width, rect.Height + .5));
- var clip = layerModel.LayerRect();
+ var clip = layerModel.LayerRect(drawScale);
c.PushClip(new RectangleGeometry(clip));
c.DrawRectangle(layerModel.Brush, null, s1);
@@ -46,7 +46,8 @@ namespace Artemis.Profiles.Layers.Animations
public bool MustExpire(LayerModel layer)
{
- return layer.AnimationProgress + layer.Properties.AnimationSpeed*2 >= layer.Properties.Height*4;
+ return layer.AnimationProgress + layer.Properties.AnimationSpeed * 2 >=
+ layer.Properties.Height * layer.LayerType.DrawScale;
}
}
}
\ No newline at end of file
diff --git a/Artemis/Artemis/Profiles/Layers/Animations/SlideLeftAnimation.cs b/Artemis/Artemis/Profiles/Layers/Animations/SlideLeftAnimation.cs
index 8f64ddae0..b8c8bf62d 100644
--- a/Artemis/Artemis/Profiles/Layers/Animations/SlideLeftAnimation.cs
+++ b/Artemis/Artemis/Profiles/Layers/Animations/SlideLeftAnimation.cs
@@ -14,29 +14,29 @@ namespace Artemis.Profiles.Layers.Animations
var progress = layerModel.AnimationProgress;
if (MustExpire(layerModel))
progress = 0;
- progress = progress + layerModel.Properties.AnimationSpeed*2;
+ progress = progress + layerModel.Properties.AnimationSpeed * 2 / 4 * layerModel.LayerType.DrawScale;
// If not previewing, store the animation progress in the actual model for the next frame
if (updateAnimations)
layerModel.AnimationProgress = progress;
}
- public void Draw(LayerModel layerModel, DrawingContext c)
+ public void Draw(LayerModel layerModel, DrawingContext c, int drawScale)
{
if (layerModel.Brush == null)
return;
// Set up variables for this frame
var rect = layerModel.Properties.Contain
- ? layerModel.LayerRect()
- : layerModel.Properties.PropertiesRect();
+ ? layerModel.LayerRect(drawScale)
+ : layerModel.Properties.PropertiesRect(drawScale);
var s1 = new Rect(new Point(rect.X - layerModel.AnimationProgress, rect.Y),
new Size(rect.Width + .5, rect.Height));
var s2 = new Rect(new Point(s1.X + rect.Width, rect.Y),
new Size(rect.Width, rect.Height));
- var clip = layerModel.LayerRect();
+ var clip = layerModel.LayerRect(drawScale);
c.PushClip(new RectangleGeometry(clip));
c.DrawRectangle(layerModel.Brush, null, s1);
@@ -46,7 +46,8 @@ namespace Artemis.Profiles.Layers.Animations
public bool MustExpire(LayerModel layer)
{
- return layer.AnimationProgress + layer.Properties.AnimationSpeed*2 >= layer.Properties.Width*4;
+ return layer.AnimationProgress + layer.Properties.AnimationSpeed * 2 >=
+ layer.Properties.Width * layer.LayerType.DrawScale;
}
}
}
\ No newline at end of file
diff --git a/Artemis/Artemis/Profiles/Layers/Animations/SlideRightAnimation.cs b/Artemis/Artemis/Profiles/Layers/Animations/SlideRightAnimation.cs
index 6f99d7b3e..f9873e037 100644
--- a/Artemis/Artemis/Profiles/Layers/Animations/SlideRightAnimation.cs
+++ b/Artemis/Artemis/Profiles/Layers/Animations/SlideRightAnimation.cs
@@ -14,29 +14,29 @@ namespace Artemis.Profiles.Layers.Animations
var progress = layerModel.AnimationProgress;
if (MustExpire(layerModel))
progress = 0;
- progress = progress + layerModel.Properties.AnimationSpeed*2;
+ progress = progress + layerModel.Properties.AnimationSpeed * 2 / 4 * layerModel.LayerType.DrawScale;
// If not previewing, store the animation progress in the actual model for the next frame
if (updateAnimations)
layerModel.AnimationProgress = progress;
}
- public void Draw(LayerModel layerModel, DrawingContext c)
+ public void Draw(LayerModel layerModel, DrawingContext c, int drawScale)
{
if (layerModel.Brush == null)
return;
// Set up variables for this frame
var rect = layerModel.Properties.Contain
- ? layerModel.LayerRect()
- : layerModel.Properties.PropertiesRect();
+ ? layerModel.LayerRect(drawScale)
+ : layerModel.Properties.PropertiesRect(drawScale);
- var s1 = new Rect(new Point(rect.X + layerModel.AnimationProgress, rect.Y),
+ var s1 = new Rect(new Point(rect.X + layerModel.AnimationProgress, rect.Y),
new Size(rect.Width, rect.Height));
- var s2 = new Rect(new Point(s1.X - rect.Width, rect.Y),
+ var s2 = new Rect(new Point(s1.X - rect.Width, rect.Y),
new Size(rect.Width + .5, rect.Height));
- var clip = layerModel.LayerRect();
+ var clip = layerModel.LayerRect(drawScale);
c.PushClip(new RectangleGeometry(clip));
c.DrawRectangle(layerModel.Brush, null, s1);
@@ -46,7 +46,8 @@ namespace Artemis.Profiles.Layers.Animations
public bool MustExpire(LayerModel layer)
{
- return layer.AnimationProgress + layer.Properties.AnimationSpeed*2 >= layer.Properties.Width*4;
+ return layer.AnimationProgress + layer.Properties.AnimationSpeed * 2 >=
+ layer.Properties.Width * layer.LayerType.DrawScale;
}
}
}
\ No newline at end of file
diff --git a/Artemis/Artemis/Profiles/Layers/Animations/SlideUpAnimation.cs b/Artemis/Artemis/Profiles/Layers/Animations/SlideUpAnimation.cs
index 14de66902..e83c9188a 100644
--- a/Artemis/Artemis/Profiles/Layers/Animations/SlideUpAnimation.cs
+++ b/Artemis/Artemis/Profiles/Layers/Animations/SlideUpAnimation.cs
@@ -14,28 +14,28 @@ namespace Artemis.Profiles.Layers.Animations
var progress = layerModel.AnimationProgress;
if (MustExpire(layerModel))
progress = 0;
- progress = progress + layerModel.Properties.AnimationSpeed*2;
+ progress = progress + layerModel.Properties.AnimationSpeed * 2 / 4 * layerModel.LayerType.DrawScale;
// If not previewing, store the animation progress in the actual model for the next frame
if (updateAnimations)
layerModel.AnimationProgress = progress;
}
- public void Draw(LayerModel layerModel, DrawingContext c)
+ public void Draw(LayerModel layerModel, DrawingContext c, int drawScale)
{
if (layerModel.Brush == null)
return;
// Set up variables for this frame
var rect = layerModel.Properties.Contain
- ? layerModel.LayerRect()
- : layerModel.Properties.PropertiesRect();
+ ? layerModel.LayerRect(drawScale)
+ : layerModel.Properties.PropertiesRect(drawScale);
var s1 = new Rect(new Point(rect.X, rect.Y - layerModel.AnimationProgress),
new Size(rect.Width, rect.Height + .5));
var s2 = new Rect(new Point(s1.X, s1.Y + rect.Height), new Size(rect.Width, rect.Height));
- var clip = layerModel.LayerRect();
+ var clip = layerModel.LayerRect(drawScale);
c.PushClip(new RectangleGeometry(clip));
c.DrawRectangle(layerModel.Brush, null, s1);
@@ -45,7 +45,8 @@ namespace Artemis.Profiles.Layers.Animations
public bool MustExpire(LayerModel layer)
{
- return layer.AnimationProgress + layer.Properties.AnimationSpeed*2 >= layer.Properties.Height*4;
+ return layer.AnimationProgress + layer.Properties.AnimationSpeed * 2 >=
+ layer.Properties.Height * layer.LayerType.DrawScale;
}
}
}
\ No newline at end of file
diff --git a/Artemis/Artemis/Profiles/Layers/Interfaces/ILayerAnimation.cs b/Artemis/Artemis/Profiles/Layers/Interfaces/ILayerAnimation.cs
index f5d1c45c0..60d7c5910 100644
--- a/Artemis/Artemis/Profiles/Layers/Interfaces/ILayerAnimation.cs
+++ b/Artemis/Artemis/Profiles/Layers/Interfaces/ILayerAnimation.cs
@@ -10,7 +10,7 @@ namespace Artemis.Profiles.Layers.Interfaces
string Name { get; }
void Update(LayerModel layerModel, bool updateAnimations);
- void Draw(LayerModel layerModel, DrawingContext c);
+ void Draw(LayerModel layerModel, DrawingContext c, int drawScale);
bool MustExpire(LayerModel layerModel);
}
}
\ No newline at end of file
diff --git a/Artemis/Artemis/Profiles/Layers/Interfaces/ILayerType.cs b/Artemis/Artemis/Profiles/Layers/Interfaces/ILayerType.cs
index 0faba2b3c..82fe9dfe1 100644
--- a/Artemis/Artemis/Profiles/Layers/Interfaces/ILayerType.cs
+++ b/Artemis/Artemis/Profiles/Layers/Interfaces/ILayerType.cs
@@ -3,7 +3,6 @@ using Artemis.Modules.Abstract;
using Artemis.Profiles.Layers.Abstract;
using Artemis.Profiles.Layers.Models;
using Artemis.ViewModels;
-using Artemis.ViewModels.Profiles;
using Newtonsoft.Json;
namespace Artemis.Profiles.Layers.Interfaces
@@ -29,6 +28,12 @@ namespace Artemis.Profiles.Layers.Interfaces
[JsonIgnore]
DrawType DrawType { get; }
+ ///
+ /// Gets the scale on which the layer should be drawn
+ ///
+ [JsonIgnore]
+ int DrawScale { get; }
+
///
/// The the thumbnail for this layer type
///
diff --git a/Artemis/Artemis/Profiles/Layers/Models/LayerConditionModel.cs b/Artemis/Artemis/Profiles/Layers/Models/LayerConditionModel.cs
index e7a02c9d6..71de0a2ce 100644
--- a/Artemis/Artemis/Profiles/Layers/Models/LayerConditionModel.cs
+++ b/Artemis/Artemis/Profiles/Layers/Models/LayerConditionModel.cs
@@ -1,4 +1,5 @@
using System;
+using System.Globalization;
using Artemis.Modules.Abstract;
using Artemis.Utilities;
using DynamicExpresso;
@@ -8,6 +9,7 @@ namespace Artemis.Profiles.Layers.Models
public class LayerConditionModel
{
private readonly Interpreter _interpreter;
+ private object _lastValue;
public LayerConditionModel()
{
@@ -23,39 +25,92 @@ namespace Artemis.Profiles.Layers.Models
{
lock (subject)
{
- if (string.IsNullOrEmpty(Field) || string.IsNullOrEmpty(Value) || string.IsNullOrEmpty(Type))
+ if (string.IsNullOrEmpty(Field) || string.IsNullOrEmpty(Type))
return false;
var inspect = GeneralHelpers.GetPropertyValue(subject, Field);
if (inspect == null)
+ {
+ _lastValue = null;
return false;
-
- // Put the subject in a list, allowing Dynamic Linq to be used.
- if (Type == "String")
- {
- return _interpreter.Eval($"subject.{Field}.ToLower(){Operator}(value)",
- new Parameter("subject", subject.GetType(), subject),
- new Parameter("value", Value.ToLower()));
}
- Parameter rightParam = null;
- switch (Type)
- {
- case "Enum":
- var enumType = GeneralHelpers.GetPropertyValue(subject, Field).GetType();
- rightParam = new Parameter("value", Enum.Parse(enumType, Value));
- break;
- case "Boolean":
- rightParam = new Parameter("value", bool.Parse(Value));
- break;
- case "Int32":
- rightParam = new Parameter("value", int.Parse(Value));
- break;
- }
+ bool returnValue;
+ if (Operator == "changed" || Operator == "decreased" || Operator == "increased")
+ returnValue = EvaluateEventOperator(subject, inspect);
+ else
+ returnValue = EvaluateOperator(subject);
- return _interpreter.Eval($"subject.{Field} {Operator} value",
- new Parameter("subject", subject.GetType(), subject), rightParam);
+ _lastValue = inspect;
+ return returnValue;
}
}
+
+ private bool EvaluateEventOperator(ModuleDataModel subject, object inspect)
+ {
+ // DynamicExpresso doesn't want a null so when it was previously null (should only happen first iteration)
+ // return false since that would be the only possible outcome
+ if (_lastValue == null)
+ return false;
+
+ // Assign the right parameter
+ var rightParam = new Parameter("value", _lastValue);
+
+ // Come up with the proper operator
+ var changeOperator = "";
+ if (Operator == "changed")
+ changeOperator = "!=";
+ else if (Operator == "decreased")
+ changeOperator = "<";
+ else if (Operator == "increased")
+ changeOperator = ">";
+
+ // Evaluate the result and store it
+ var returnValue = _interpreter.Eval($"subject.{Field} {changeOperator} value",
+ new Parameter("subject", subject.GetType(), subject), rightParam);
+
+ // Set the last value to the new value
+ _lastValue = inspect;
+ // Return the evaluated result
+ return returnValue;
+ }
+
+ private bool EvaluateOperator(ModuleDataModel subject)
+ {
+ // Since _lastValue won't be used, rely on Value to not be null
+ if (string.IsNullOrEmpty(Value))
+ return false;
+
+ // Put the subject in a list, allowing Dynamic Linq to be used.
+ if (Type == "String")
+ {
+ return _interpreter.Eval($"subject.{Field}.ToLower(){Operator}(value)",
+ new Parameter("subject", subject.GetType(), subject),
+ new Parameter("value", Value.ToLower()));
+ }
+
+ Parameter rightParam = null;
+ switch (Type)
+ {
+ case "Enum":
+ var enumType = GeneralHelpers.GetPropertyValue(subject, Field).GetType();
+ rightParam = new Parameter("value", Enum.Parse(enumType, Value));
+ break;
+ case "Boolean":
+ rightParam = new Parameter("value", bool.Parse(Value));
+ break;
+ case "Int32":
+ rightParam = new Parameter("value", int.Parse(Value));
+ break;
+ case "Single":
+ // Parse commas as decimals
+ rightParam = new Parameter("value", float.Parse(Value.Replace(",", "."),
+ CultureInfo.InvariantCulture));
+ break;
+ }
+
+ return _interpreter.Eval($"subject.{Field} {Operator} value",
+ new Parameter("subject", subject.GetType(), subject), rightParam);
+ }
}
}
\ No newline at end of file
diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightType.cs b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightType.cs
index 01c4922ee..abfc93d5d 100644
--- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightType.cs
+++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightType.cs
@@ -14,7 +14,6 @@ using Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing;
using Artemis.Properties;
using Artemis.Utilities;
using Artemis.ViewModels;
-using Artemis.ViewModels.Profiles;
using Newtonsoft.Json;
namespace Artemis.Profiles.Layers.Types.AmbientLight
@@ -26,6 +25,7 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight
public string Name => "Keyboard - Ambient Light";
public bool ShowInEdtor => true;
public DrawType DrawType => DrawType.Keyboard;
+ public int DrawScale => 4;
[JsonIgnore] private AmbienceCreatorType? _lastAmbienceCreatorType;
@@ -77,11 +77,7 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight
public void Draw(LayerModel layerModel, DrawingContext c)
{
- var rect = new Rect(layerModel.Properties.X*4,
- layerModel.Properties.Y*4,
- layerModel.Properties.Width*4,
- layerModel.Properties.Height*4);
-
+ var rect = layerModel.LayerRect(DrawScale);
c.DrawRectangle(((AmbientLightPropertiesModel) layerModel.Properties).AmbientLightBrush, null, rect);
}
diff --git a/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioType.cs b/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioType.cs
index 56da983ab..058b2ca65 100644
--- a/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioType.cs
+++ b/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioType.cs
@@ -23,12 +23,10 @@ namespace Artemis.Profiles.Layers.Types.Audio
public class AudioType : ILayerType
{
private readonly AudioCaptureManager _audioCaptureManager;
- private const GeometryCombineMode CombineMode = GeometryCombineMode.Union;
private AudioCapture _audioCapture;
private int _lines;
private LineSpectrum _lineSpectrum;
private List _lineValues;
- private int _drawCount;
public AudioType(AudioCaptureManager audioCaptureManager)
{
@@ -50,6 +48,7 @@ namespace Artemis.Profiles.Layers.Types.Audio
public string Name => "Keyboard - Audio visualization";
public bool ShowInEdtor => true;
public DrawType DrawType => DrawType.Keyboard;
+ public int DrawScale => 4;
public ImageSource DrawThumbnail(LayerModel layer)
{
@@ -66,7 +65,6 @@ namespace Artemis.Profiles.Layers.Types.Audio
public void Draw(LayerModel layerModel, DrawingContext c)
{
- _drawCount++;
if (_lineValues == null)
return;
@@ -178,7 +176,7 @@ namespace Artemis.Profiles.Layers.Types.Audio
// If an animation is present, let it handle the drawing
if (layerModel.LayerAnimation != null && !(layerModel.LayerAnimation is NoneAnimation))
{
- layerModel.LayerAnimation.Draw(layerModel, c);
+ layerModel.LayerAnimation.Draw(layerModel, c, DrawScale);
return;
}
@@ -188,7 +186,7 @@ namespace Artemis.Profiles.Layers.Types.Audio
: new Rect(layerModel.Properties.X*4, layerModel.Properties.Y*4,
layerModel.Properties.Width*4, layerModel.Properties.Height*4);
- var clip = layerModel.LayerRect();
+ var clip = layerModel.LayerRect(DrawScale);
// Can't meddle with the original brush because it's frozen.
var brush = layerModel.Brush.Clone();
diff --git a/Artemis/Artemis/Profiles/Layers/Types/ConicalBrush/ConicalBrushType.cs b/Artemis/Artemis/Profiles/Layers/Types/ConicalBrush/ConicalBrushType.cs
index 347f56c59..cb2e4cff2 100644
--- a/Artemis/Artemis/Profiles/Layers/Types/ConicalBrush/ConicalBrushType.cs
+++ b/Artemis/Artemis/Profiles/Layers/Types/ConicalBrush/ConicalBrushType.cs
@@ -22,6 +22,7 @@ namespace Artemis.Profiles.Layers.Types.ConicalBrush
public string Name => "Conical Brush";
public bool ShowInEdtor => true;
public DrawType DrawType => DrawType.Keyboard;
+ public int DrawScale => 4;
#endregion
@@ -62,15 +63,15 @@ namespace Artemis.Profiles.Layers.Types.ConicalBrush
// If an animation is present, let it handle the drawing
if (layerModel.LayerAnimation != null && !(layerModel.LayerAnimation is NoneAnimation))
{
- layerModel.LayerAnimation.Draw(layerModel, c);
+ layerModel.LayerAnimation.Draw(layerModel, c, DrawScale);
return;
}
// Otherwise draw the rectangle with its layer.AppliedProperties dimensions and brush
Rect rect = layerModel.Properties.Contain
- ? layerModel.LayerRect()
- : new Rect(layerModel.Properties.X * 4, layerModel.Properties.Y * 4,
- layerModel.Properties.Width * 4, layerModel.Properties.Height * 4);
+ ? layerModel.LayerRect(DrawScale)
+ : new Rect(layerModel.Properties.X * DrawScale, layerModel.Properties.Y * DrawScale,
+ layerModel.Properties.Width * DrawScale, layerModel.Properties.Height * DrawScale);
Rect clip = layerModel.LayerRect();
diff --git a/Artemis/Artemis/Profiles/Layers/Types/Folder/FolderType.cs b/Artemis/Artemis/Profiles/Layers/Types/Folder/FolderType.cs
index cfec51a00..10cefce8c 100644
--- a/Artemis/Artemis/Profiles/Layers/Types/Folder/FolderType.cs
+++ b/Artemis/Artemis/Profiles/Layers/Types/Folder/FolderType.cs
@@ -17,6 +17,7 @@ namespace Artemis.Profiles.Layers.Types.Folder
public bool ShowInEdtor => false;
// FolderType pretents to be a keyboard so it's children get drawn
public DrawType DrawType => DrawType.Keyboard;
+ public int DrawScale => 1;
public ImageSource DrawThumbnail(LayerModel layer)
{
diff --git a/Artemis/Artemis/Profiles/Layers/Types/Generic/GenericType.cs b/Artemis/Artemis/Profiles/Layers/Types/Generic/GenericType.cs
index f7ca251d5..c9d205db3 100644
--- a/Artemis/Artemis/Profiles/Layers/Types/Generic/GenericType.cs
+++ b/Artemis/Artemis/Profiles/Layers/Types/Generic/GenericType.cs
@@ -18,6 +18,7 @@ namespace Artemis.Profiles.Layers.Types.Generic
public string Name => "Generic (Logitech)";
public bool ShowInEdtor => false;
public DrawType DrawType => DrawType.Generic;
+ public int DrawScale => 1;
public ImageSource DrawThumbnail(LayerModel layer)
{
@@ -35,12 +36,12 @@ namespace Artemis.Profiles.Layers.Types.Generic
// If an animation is present, let it handle the drawing
if (layerModel.LayerAnimation != null && !(layerModel.LayerAnimation is NoneAnimation))
{
- layerModel.LayerAnimation.Draw(layerModel, c);
+ layerModel.LayerAnimation.Draw(layerModel, c, DrawScale);
return;
}
// Otherwise draw the rectangle with its applied dimensions and brush
- var rect = layerModel.LayerRect();
+ var rect = layerModel.LayerRect(DrawScale);
// Can't meddle with the original brush because it's frozen.
var brush = layerModel.Brush.Clone();
diff --git a/Artemis/Artemis/Profiles/Layers/Types/Headset/HeadsetType.cs b/Artemis/Artemis/Profiles/Layers/Types/Headset/HeadsetType.cs
index 3c99e55f4..e972efe59 100644
--- a/Artemis/Artemis/Profiles/Layers/Types/Headset/HeadsetType.cs
+++ b/Artemis/Artemis/Profiles/Layers/Types/Headset/HeadsetType.cs
@@ -18,6 +18,7 @@ namespace Artemis.Profiles.Layers.Types.Headset
public string Name => "Headset";
public bool ShowInEdtor => false;
public DrawType DrawType => DrawType.Headset;
+ public int DrawScale => 1;
public ImageSource DrawThumbnail(LayerModel layer)
{
@@ -35,12 +36,12 @@ namespace Artemis.Profiles.Layers.Types.Headset
// If an animation is present, let it handle the drawing
if (layerModel.LayerAnimation != null && !(layerModel.LayerAnimation is NoneAnimation))
{
- layerModel.LayerAnimation.Draw(layerModel, c);
+ layerModel.LayerAnimation.Draw(layerModel, c, DrawScale);
return;
}
// Otherwise draw the rectangle with its applied dimensions and brush
- var rect = layerModel.LayerRect();
+ var rect = layerModel.LayerRect(DrawScale);
// Can't meddle with the original brush because it's frozen.
var brush = layerModel.Brush.Clone();
diff --git a/Artemis/Artemis/Profiles/Layers/Types/KeyPress/KeyPressType.cs b/Artemis/Artemis/Profiles/Layers/Types/KeyPress/KeyPressType.cs
index a2a366ec4..f0b463067 100644
--- a/Artemis/Artemis/Profiles/Layers/Types/KeyPress/KeyPressType.cs
+++ b/Artemis/Artemis/Profiles/Layers/Types/KeyPress/KeyPressType.cs
@@ -23,6 +23,7 @@ namespace Artemis.Profiles.Layers.Types.KeyPress
private readonly DeviceManager _deviceManager;
private List _keyPressLayers;
private LayerModel _layerModel;
+ public int DrawScale => 4;
public KeyPressType(DeviceManager deviceManager)
{
diff --git a/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardType.cs b/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardType.cs
index 2ace6c684..60445e83b 100644
--- a/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardType.cs
+++ b/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardType.cs
@@ -15,6 +15,7 @@ namespace Artemis.Profiles.Layers.Types.Keyboard
public string Name => "Keyboard";
public bool ShowInEdtor => true;
public DrawType DrawType => DrawType.Keyboard;
+ public int DrawScale => 4;
public ImageSource DrawThumbnail(LayerModel layer)
{
@@ -39,7 +40,7 @@ namespace Artemis.Profiles.Layers.Types.Keyboard
// If an animation is present, let it handle the drawing
if (layerModel.LayerAnimation != null && !(layerModel.LayerAnimation is NoneAnimation))
{
- layerModel.LayerAnimation.Draw(layerModel, c);
+ layerModel.LayerAnimation.Draw(layerModel, c, DrawScale);
return;
}
@@ -49,7 +50,7 @@ namespace Artemis.Profiles.Layers.Types.Keyboard
: new Rect(layerModel.Properties.X*4, layerModel.Properties.Y*4,
layerModel.Properties.Width*4, layerModel.Properties.Height*4);
- var clip = layerModel.LayerRect();
+ var clip = layerModel.LayerRect(DrawScale);
// Can't meddle with the original brush because it's frozen.
var brush = layerModel.Brush.Clone();
diff --git a/Artemis/Artemis/Profiles/Layers/Types/KeyboardGif/KeyboardGifType.cs b/Artemis/Artemis/Profiles/Layers/Types/KeyboardGif/KeyboardGifType.cs
index ef3e201e2..19c0f5611 100644
--- a/Artemis/Artemis/Profiles/Layers/Types/KeyboardGif/KeyboardGifType.cs
+++ b/Artemis/Artemis/Profiles/Layers/Types/KeyboardGif/KeyboardGifType.cs
@@ -19,6 +19,7 @@ namespace Artemis.Profiles.Layers.Types.KeyboardGif
public string Name => "Keyboard - GIF";
public bool ShowInEdtor => true;
public DrawType DrawType => DrawType.Keyboard;
+ public int DrawScale => 4;
public ImageSource DrawThumbnail(LayerModel layer)
{
diff --git a/Artemis/Artemis/Profiles/Layers/Types/Mouse/MouseType.cs b/Artemis/Artemis/Profiles/Layers/Types/Mouse/MouseType.cs
index 31a2d4fa1..865e4277e 100644
--- a/Artemis/Artemis/Profiles/Layers/Types/Mouse/MouseType.cs
+++ b/Artemis/Artemis/Profiles/Layers/Types/Mouse/MouseType.cs
@@ -18,6 +18,7 @@ namespace Artemis.Profiles.Layers.Types.Mouse
public string Name => "Mouse";
public bool ShowInEdtor => false;
public DrawType DrawType => DrawType.Mouse;
+ public int DrawScale => 1;
public ImageSource DrawThumbnail(LayerModel layer)
{
@@ -37,12 +38,12 @@ namespace Artemis.Profiles.Layers.Types.Mouse
// If an animation is present, let it handle the drawing
if (layerModel.LayerAnimation != null && !(layerModel.LayerAnimation is NoneAnimation))
{
- layerModel.LayerAnimation.Draw(layerModel, c);
+ layerModel.LayerAnimation.Draw(layerModel, c, DrawScale);
return;
}
// Otherwise draw the rectangle with its applied dimensions and brush
- var rect = layerModel.LayerRect();
+ var rect = layerModel.LayerRect(DrawScale);
// Can't meddle with the original brush because it's frozen.
var brush = layerModel.Brush.Clone();
diff --git a/Artemis/Artemis/Profiles/Layers/Types/Mousemat/MousematType.cs b/Artemis/Artemis/Profiles/Layers/Types/Mousemat/MousematType.cs
index f1379e754..6612779eb 100644
--- a/Artemis/Artemis/Profiles/Layers/Types/Mousemat/MousematType.cs
+++ b/Artemis/Artemis/Profiles/Layers/Types/Mousemat/MousematType.cs
@@ -18,6 +18,7 @@ namespace Artemis.Profiles.Layers.Types.Mousemat
public string Name => "Mousemat";
public bool ShowInEdtor => false;
public DrawType DrawType => DrawType.Mousemat;
+ public int DrawScale => 1;
public ImageSource DrawThumbnail(LayerModel layer)
{
@@ -35,12 +36,12 @@ namespace Artemis.Profiles.Layers.Types.Mousemat
// If an animation is present, let it handle the drawing
if (layerModel.LayerAnimation != null && !(layerModel.LayerAnimation is NoneAnimation))
{
- layerModel.LayerAnimation.Draw(layerModel, c);
+ layerModel.LayerAnimation.Draw(layerModel, c, DrawScale);
return;
}
// Otherwise draw the rectangle with its applied dimensions and brush
- var rect = layerModel.LayerRect();
+ var rect = layerModel.LayerRect(1);
// Can't meddle with the original brush because it's frozen.
var brush = layerModel.Brush.Clone();
diff --git a/Artemis/Artemis/ViewModels/LayerEditorViewModel.cs b/Artemis/Artemis/ViewModels/LayerEditorViewModel.cs
index 1c387abe2..8d89ea92b 100644
--- a/Artemis/Artemis/ViewModels/LayerEditorViewModel.cs
+++ b/Artemis/Artemis/ViewModels/LayerEditorViewModel.cs
@@ -42,8 +42,8 @@ namespace Artemis.ViewModels
if (Layer.Properties == null)
Layer.SetupProperties();
- // Setup existing conditions
- var conditions = layer.Properties.Conditions.Select(c => new LayerConditionViewModel(this, c));
+ // Setup existing conditions
+ var conditions = ProposedLayer.Properties.Conditions.Select(c => new LayerConditionViewModel(this, c));
LayerConditionVms = new BindableCollection(conditions);
PropertyChanged += PropertiesViewModelHandler;
@@ -155,6 +155,10 @@ namespace Artemis.ViewModels
EventPropertiesViewModel = ProposedLayer.IsEvent
? new EventPropertiesViewModel(Layer.EventProperties)
: null;
+
+ // The form inside each condition VM changes upon event toggle
+ foreach (var layerConditionViewModel in LayerConditionVms)
+ layerConditionViewModel.SetupPropertyInput();
}
public void AddCondition()
@@ -171,7 +175,7 @@ namespace Artemis.ViewModels
JsonConvert.PopulateObject(JsonConvert.SerializeObject(ProposedLayer), Layer);
Layer.Properties.Conditions.Clear();
foreach (var conditionViewModel in LayerConditionVms)
- Layer.Properties.Conditions.Add(conditionViewModel.LayerConditionModel);
+ Layer.Properties.Conditions.Add(conditionViewModel.ConditionModel);
// TODO: EventPropVM must have layer too
if (EventPropertiesViewModel != null)
@@ -202,7 +206,7 @@ namespace Artemis.ViewModels
ProposedLayer.EventProperties = EventPropertiesViewModel.GetAppliedProperties();
ProposedLayer.Properties.Conditions.Clear();
foreach (var conditionViewModel in LayerConditionVms)
- ProposedLayer.Properties.Conditions.Add(conditionViewModel.LayerConditionModel);
+ ProposedLayer.Properties.Conditions.Add(conditionViewModel.ConditionModel);
// If not a keyboard, ignore size and position
if ((ProposedLayer.LayerType.DrawType != DrawType.Keyboard) || !ProposedLayer.LayerType.ShowInEdtor)
diff --git a/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs b/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs
index 3a899343e..5fbb1bfed 100644
--- a/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs
+++ b/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs
@@ -193,6 +193,8 @@ namespace Artemis.ViewModels
public bool EditorEnabled => SelectedProfile != null && !SelectedProfile.IsDefault &&
_deviceManager.ActiveKeyboard != null;
+ public bool LuaButtonVisible => !_moduleModel.IsOverlay;
+
#endregion
#region Layers
diff --git a/Artemis/Artemis/ViewModels/Profiles/LayerConditionViewModel.cs b/Artemis/Artemis/ViewModels/Profiles/LayerConditionViewModel.cs
index fe8ad7a78..113006d04 100644
--- a/Artemis/Artemis/ViewModels/Profiles/LayerConditionViewModel.cs
+++ b/Artemis/Artemis/ViewModels/Profiles/LayerConditionViewModel.cs
@@ -1,257 +1,254 @@
-using System.ComponentModel;
-using System.Linq;
-using Artemis.Profiles.Layers.Models;
-using Artemis.Utilities;
-using Caliburn.Micro;
-
-namespace Artemis.ViewModels.Profiles
-{
- public sealed class LayerConditionViewModel : Screen
- {
- private readonly NamedOperator[] _boolOperators =
- {
- new NamedOperator("Equal to", "==")
- };
-
- private readonly LayerEditorViewModel _conditionModel;
-
- private readonly NamedOperator[] _int32Operators =
- {
- new NamedOperator("Lower than", "<"),
- new NamedOperator("Lower or equal to", "<="),
- new NamedOperator("Higher than", ">"),
- new NamedOperator("Higher or equal to", ">="),
- new NamedOperator("Equal to", "=="),
- new NamedOperator("Not equal to", "!=")
- };
-
- private readonly NamedOperator[] _operators =
- {
- new NamedOperator("Equal to", "=="),
- new NamedOperator("Not equal to", "!=")
- };
-
- private readonly NamedOperator[] _stringOperators =
- {
- new NamedOperator("Equal to", "=="),
- new NamedOperator("Not equal to", "!="),
- new NamedOperator("Contains", ".Contains"),
- new NamedOperator("Starts with", ".StartsWith"),
- new NamedOperator("Ends with", ".EndsWith")
- };
-
- private bool _enumValueIsVisible;
- private bool _preselecting;
- private GeneralHelpers.PropertyCollection _selectedDataModelProp;
- private string _selectedEnum;
- private NamedOperator _selectedOperator;
- private string _userValue;
- private bool _userValueIsVisible;
-
- public LayerConditionViewModel(LayerEditorViewModel conditionModel, LayerConditionModel layerConditionModel)
- {
- _conditionModel = conditionModel;
- _preselecting = false;
-
- LayerConditionModel = layerConditionModel;
- DataModelProps = conditionModel.DataModelProps;
- Operators = new BindableCollection();
- Enums = new BindableCollection();
-
- PropertyChanged += UpdateModel;
- PropertyChanged += UpdateForm;
-
- PreSelect();
- }
-
- public LayerConditionModel LayerConditionModel { get; set; }
-
- public BindableCollection DataModelProps { get; set; }
-
- public BindableCollection Operators { get; set; }
- public BindableCollection Enums { get; set; }
-
- public string UserValue
- {
- get { return _userValue; }
- set
- {
- if (value == _userValue) return;
- _userValue = value;
- NotifyOfPropertyChange(() => UserValue);
- }
- }
-
- public GeneralHelpers.PropertyCollection SelectedDataModelProp
- {
- get { return _selectedDataModelProp; }
- set
- {
- if (value.Equals(_selectedDataModelProp)) return;
- _selectedDataModelProp = value;
- NotifyOfPropertyChange(() => SelectedDataModelProp);
- }
- }
-
-
- public bool UserValueIsVisible
- {
- get { return _userValueIsVisible; }
- set
- {
- if (value == _userValueIsVisible) return;
- _userValueIsVisible = value;
- NotifyOfPropertyChange(() => UserValueIsVisible);
- }
- }
-
- public bool EnumValueIsVisible
- {
- get { return _enumValueIsVisible; }
- set
- {
- if (value == _enumValueIsVisible) return;
- _enumValueIsVisible = value;
- NotifyOfPropertyChange(() => EnumValueIsVisible);
- }
- }
-
- public NamedOperator SelectedOperator
- {
- get { return _selectedOperator; }
- set
- {
- _selectedOperator = value;
- NotifyOfPropertyChange(() => SelectedOperator);
- }
- }
-
- public string SelectedEnum
- {
- get { return _selectedEnum; }
- set
- {
- if (value == _selectedEnum) return;
- _selectedEnum = value;
- NotifyOfPropertyChange(() => SelectedEnum);
- }
- }
-
- ///
- /// Handles updating the form to match the selected data model property
- ///
- ///
- ///
- private void UpdateForm(object sender, PropertyChangedEventArgs e)
- {
- if (e.PropertyName != "SelectedDataModelProp")
- return;
-
- Operators.Clear();
- Enums.Clear();
- UserValueIsVisible = false;
- EnumValueIsVisible = false;
-
- switch (SelectedDataModelProp.Type)
- {
- case "Int32":
- case "Single":
- Operators.AddRange(_int32Operators);
- UserValueIsVisible = true;
- break;
- case "Boolean":
- Operators.AddRange(_boolOperators);
- Enums.Add("True");
- Enums.Add("False");
- EnumValueIsVisible = true;
- break;
- case "String":
- Operators.AddRange(_stringOperators);
- UserValueIsVisible = true;
- break;
- default:
- Operators.AddRange(_operators);
- UserValueIsVisible = true;
- break;
- }
-
- // Setup Enum selection if needed
- if (SelectedDataModelProp.EnumValues != null)
- {
- Enums.AddRange(SelectedDataModelProp.EnumValues);
- EnumValueIsVisible = true;
- }
-
- SelectedOperator = Operators.First();
- }
-
-
- ///
- /// Handles saving user input to the model
- /// TODO: Data validation?
- ///
- ///
- ///
- private void UpdateModel(object sender, PropertyChangedEventArgs e)
- {
- // Don't mess with model during preselect
- if (_preselecting)
- return;
-
- // Only care about these fields
- if (e.PropertyName != "UserValue" &&
- e.PropertyName != "SelectedOperator" &&
- e.PropertyName != "SelectedDataModelProp" &&
- e.PropertyName != "SelectedEnum")
- return;
-
- LayerConditionModel.Field = SelectedDataModelProp.Path;
- LayerConditionModel.Operator = SelectedOperator.Value;
- LayerConditionModel.Type = SelectedDataModelProp.Type;
-
- if (SelectedDataModelProp.Type == "Enum" || SelectedDataModelProp.Type == "Boolean")
- LayerConditionModel.Value = SelectedEnum;
- else
- LayerConditionModel.Value = UserValue;
-
- UpdateForm(sender, e);
- }
-
- ///
- /// Setup the current UI elements to show the backing model
- ///
- private void PreSelect()
- {
- _preselecting = true;
- SelectedDataModelProp = DataModelProps.FirstOrDefault(m => m.Path == LayerConditionModel.Field);
- SelectedOperator = Operators.FirstOrDefault(o => o.Value == LayerConditionModel.Operator);
- LayerConditionModel.Type = SelectedDataModelProp.Type;
- if (LayerConditionModel.Type == "Enum" || LayerConditionModel.Type == "Boolean")
- SelectedEnum = LayerConditionModel.Value;
- else
- UserValue = LayerConditionModel.Value;
-
- _preselecting = false;
- }
-
- ///
- /// Delete the current model from the parent
- ///
- public void Delete()
- {
- _conditionModel.DeleteCondition(this, LayerConditionModel);
- }
-
- public struct NamedOperator
- {
- public string Display { get; set; }
- public string Value { get; set; }
-
- public NamedOperator(string display, string value)
- {
- Display = display;
- Value = value;
- }
- }
- }
+using System.ComponentModel;
+using System.Linq;
+using Artemis.Profiles.Layers.Models;
+using Artemis.Utilities;
+using Caliburn.Micro;
+
+namespace Artemis.ViewModels.Profiles
+{
+ public sealed class LayerConditionViewModel : Screen
+ {
+ private readonly NamedOperator[] _boolOperators =
+ {
+ new NamedOperator("Equal to", "==")
+ };
+
+ private readonly LayerEditorViewModel _editorViewModel;
+
+ private readonly NamedOperator[] _int32Operators =
+ {
+ new NamedOperator("Lower than", "<"),
+ new NamedOperator("Lower or equal to", "<="),
+ new NamedOperator("Higher than", ">"),
+ new NamedOperator("Higher or equal to", ">="),
+ new NamedOperator("Equal to", "=="),
+ new NamedOperator("Not equal to", "!=")
+ };
+
+ private readonly NamedOperator[] _operators =
+ {
+ new NamedOperator("Equal to", "=="),
+ new NamedOperator("Not equal to", "!=")
+ };
+
+ private readonly NamedOperator[] _stringOperators =
+ {
+ new NamedOperator("Equal to", "=="),
+ new NamedOperator("Not equal to", "!="),
+ new NamedOperator("Contains", ".Contains"),
+ new NamedOperator("Starts with", ".StartsWith"),
+ new NamedOperator("Ends with", ".EndsWith")
+ };
+
+ private bool _enumValueIsVisible;
+ private GeneralHelpers.PropertyCollection _selectedDataModelProp;
+ private string _selectedEnum;
+ private NamedOperator _selectedOperator;
+ private string _userValue;
+ private bool _userValueIsVisible;
+
+ public LayerConditionViewModel(LayerEditorViewModel editorViewModel, LayerConditionModel conditionModel)
+ {
+ _editorViewModel = editorViewModel;
+
+ ConditionModel = conditionModel;
+ DataModelProps = editorViewModel.DataModelProps;
+ Operators = new BindableCollection();
+ Enums = new BindableCollection();
+
+ PropertyChanged += MapViewToModel;
+ MapModelToView();
+ }
+
+ public LayerConditionModel ConditionModel { get; set; }
+
+ public BindableCollection DataModelProps { get; set; }
+
+ public BindableCollection Operators { get; set; }
+ public BindableCollection Enums { get; set; }
+
+ public string UserValue
+ {
+ get { return _userValue; }
+ set
+ {
+ if (value == _userValue) return;
+ _userValue = value;
+ NotifyOfPropertyChange(() => UserValue);
+ }
+ }
+
+ public GeneralHelpers.PropertyCollection SelectedDataModelProp
+ {
+ get { return _selectedDataModelProp; }
+ set
+ {
+ if (value.Equals(_selectedDataModelProp)) return;
+ _selectedDataModelProp = value;
+ SetupPropertyInput();
+ NotifyOfPropertyChange(() => SelectedDataModelProp);
+ }
+ }
+
+ public bool UserValueIsVisible
+ {
+ get { return _userValueIsVisible; }
+ set
+ {
+ if (value == _userValueIsVisible) return;
+ _userValueIsVisible = value;
+ NotifyOfPropertyChange(() => UserValueIsVisible);
+ }
+ }
+
+ public bool EnumValueIsVisible
+ {
+ get { return _enumValueIsVisible; }
+ set
+ {
+ if (value == _enumValueIsVisible) return;
+ _enumValueIsVisible = value;
+ NotifyOfPropertyChange(() => EnumValueIsVisible);
+ }
+ }
+
+ public NamedOperator SelectedOperator
+ {
+ get { return _selectedOperator; }
+ set
+ {
+ _selectedOperator = value;
+ SetupUserValueInput();
+ NotifyOfPropertyChange(() => SelectedOperator);
+ }
+ }
+
+ public string SelectedEnum
+ {
+ get { return _selectedEnum; }
+ set
+ {
+ if (value == _selectedEnum) return;
+ _selectedEnum = value;
+ NotifyOfPropertyChange(() => SelectedEnum);
+ }
+ }
+
+ public void MapModelToView()
+ {
+ PropertyChanged -= MapViewToModel;
+
+ // Select the right property
+ SelectedDataModelProp = DataModelProps.FirstOrDefault(m => m.Path == ConditionModel.Field);
+ // Select the operator
+ SelectedOperator = Operators.FirstOrDefault(o => o.Value == ConditionModel.Operator);
+
+ if (ConditionModel.Type == "Enum" || ConditionModel.Type == "Boolean")
+ SelectedEnum = ConditionModel.Value;
+ else
+ UserValue = ConditionModel.Value;
+
+ PropertyChanged += MapViewToModel;
+ }
+
+ public void MapViewToModel()
+ {
+ ConditionModel.Field = SelectedDataModelProp.Path;
+ ConditionModel.Operator = SelectedOperator.Value;
+ ConditionModel.Type = SelectedDataModelProp.Type;
+
+ if (ConditionModel.Type == "Enum" || ConditionModel.Type == "Boolean")
+ ConditionModel.Value = SelectedEnum;
+ else
+ ConditionModel.Value = UserValue;
+ }
+
+ private void MapViewToModel(object sender, PropertyChangedEventArgs e)
+ {
+ MapViewToModel();
+ }
+
+ public void SetupPropertyInput()
+ {
+ Operators.Clear();
+ Enums.Clear();
+
+ switch (SelectedDataModelProp.Type)
+ {
+ case "Int32":
+ case "Single":
+ Operators.AddRange(_int32Operators);
+ UserValueIsVisible = true;
+ break;
+ case "Boolean":
+ Operators.AddRange(_boolOperators);
+ Enums.Add("True");
+ Enums.Add("False");
+ EnumValueIsVisible = true;
+ break;
+ case "String":
+ Operators.AddRange(_stringOperators);
+ UserValueIsVisible = true;
+ break;
+ default:
+ Operators.AddRange(_operators);
+ UserValueIsVisible = true;
+ break;
+ }
+
+ // Add Changed operator is the type is event
+ if (_editorViewModel.ProposedLayer.IsEvent)
+ {
+ Operators.Add(new NamedOperator("Changed", "changed"));
+ // Also add decreased and increased operator on numbers
+ if (SelectedDataModelProp.Type == "Int32" || SelectedDataModelProp.Type == "Single")
+ {
+ Operators.Add(new NamedOperator("Decreased", "decreased"));
+ Operators.Add(new NamedOperator("Increased", "increased"));
+ }
+ }
+
+ SetupUserValueInput();
+ }
+
+ private void SetupUserValueInput()
+ {
+ UserValueIsVisible = false;
+ EnumValueIsVisible = false;
+
+ if (SelectedOperator.Value == "changed" || SelectedOperator.Value == "decreased" ||
+ SelectedOperator.Value == "increased")
+ return;
+
+ if (SelectedDataModelProp.Type == "Boolean")
+ {
+ EnumValueIsVisible = true;
+ }
+ else if (SelectedDataModelProp.EnumValues != null)
+ {
+ Enums.AddRange(SelectedDataModelProp.EnumValues);
+ EnumValueIsVisible = true;
+ }
+ }
+
+ ///
+ /// Delete the current model from the parent
+ ///
+ public void Delete()
+ {
+ _editorViewModel.DeleteCondition(this, ConditionModel);
+ }
+
+ public struct NamedOperator
+ {
+ public string Display { get; set; }
+ public string Value { get; set; }
+
+ public NamedOperator(string display, string value)
+ {
+ Display = display;
+ Value = value;
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/Artemis/Artemis/Views/LayerEditorView.xaml b/Artemis/Artemis/Views/LayerEditorView.xaml
index 8c7adca13..772c9630a 100644
--- a/Artemis/Artemis/Views/LayerEditorView.xaml
+++ b/Artemis/Artemis/Views/LayerEditorView.xaml
@@ -7,7 +7,7 @@
xmlns:utilities="clr-namespace:Artemis.Utilities"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
- Title="Artemis | Edit Layer" Height="820" Width="630"
+ Title="Artemis | Edit Layer" Height="860" Width="630"
xmlns:cal="http://www.caliburnproject.org"
xmlns:converters="clr-namespace:Artemis.Utilities.Converters"
xmlns:models="clr-namespace:Artemis.Profiles.Layers.Models"
diff --git a/Artemis/Artemis/Views/ProfileEditorView.xaml b/Artemis/Artemis/Views/ProfileEditorView.xaml
index 7c138d830..313a3eadf 100644
--- a/Artemis/Artemis/Views/ProfileEditorView.xaml
+++ b/Artemis/Artemis/Views/ProfileEditorView.xaml
@@ -156,7 +156,8 @@