diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index aea85129f..abe4a03ae 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -120,6 +120,10 @@ + + ..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll + True + ..\packages\Autofac.4.0.0-rc1-177\lib\net45\Autofac.dll True @@ -148,6 +152,10 @@ ..\packages\CUE.NET.1.0.2.2\lib\net45\CUE.NET.dll True + + ..\packages\ExpressionEvaluator.2.0.4.0\lib\net40\ExpressionEvaluator.dll + True + ..\packages\Hardcodet.NotifyIcon.Wpf.1.0.5\lib\net451\Hardcodet.Wpf.TaskbarNotification.dll True diff --git a/Artemis/Artemis/Models/Profiles/LayerConditionModel.cs b/Artemis/Artemis/Models/Profiles/LayerConditionModel.cs index e6956c274..35ed776cc 100644 --- a/Artemis/Artemis/Models/Profiles/LayerConditionModel.cs +++ b/Artemis/Artemis/Models/Profiles/LayerConditionModel.cs @@ -1,7 +1,7 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq.Dynamic; using Artemis.Models.Interfaces; +using Artemis.Utilities; namespace Artemis.Models.Profiles { @@ -16,19 +16,17 @@ namespace Artemis.Models.Profiles { if (string.IsNullOrEmpty(Field) || string.IsNullOrEmpty(Value) || string.IsNullOrEmpty(Type)) return false; - try - { - // Put the subject in a list, allowing Dynamic Linq to be used. - var subjectList = new List {(T) subject}; - var res = Type == "String" - ? subjectList.Where($"{Field}.ToLower() {Operator} @0", Value.ToLower()).Any() - : subjectList.Where($"{Field} {Operator} {Value}").Any(); - return res; - } - catch (NullReferenceException) - { + + var inspect = GeneralHelpers.GetPropertyValue(subject, Field); + if (inspect == null) return false; - } + + // Put the subject in a list, allowing Dynamic Linq to be used. + var subjectList = new List {(T) subject}; + var res = Type == "String" + ? subjectList.Where($"{Field}.ToLower() {Operator} @0", Value.ToLower()).Any() + : subjectList.Where($"{Field} {Operator} {Value}").Any(); + return res; } } } \ No newline at end of file diff --git a/Artemis/Artemis/Models/Profiles/ProfileModel.cs b/Artemis/Artemis/Models/Profiles/ProfileModel.cs index 97e11a05b..829620054 100644 --- a/Artemis/Artemis/Models/Profiles/ProfileModel.cs +++ b/Artemis/Artemis/Models/Profiles/ProfileModel.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Windows.Media; namespace Artemis.Models.Profiles { @@ -7,11 +8,13 @@ namespace Artemis.Models.Profiles public ProfileModel() { Layers = new List(); + DrawingVisual = new DrawingVisual(); } public string Name { get; set; } public string KeyboardName { get; set; } public string GameName { get; set; } + public DrawingVisual DrawingVisual { get; set; } public List Layers { get; set; } diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs index cabeb1b4f..f74078fc9 100644 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs +++ b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs @@ -1,11 +1,11 @@ using System.Drawing; using System.Windows.Media; -using System.Windows.Media.Imaging; using Artemis.Managers; using Artemis.Models; using Artemis.Utilities; using Artemis.Utilities.GameState; using Newtonsoft.Json; +using Color = System.Windows.Media.Color; namespace Artemis.Modules.Games.CounterStrike { @@ -52,24 +52,32 @@ namespace Artemis.Modules.Games.CounterStrike public override Bitmap GenerateBitmap() { - var keyboardRect = MainManager.KeyboardManager.ActiveKeyboard.KeyboardRectangle(Scale); + if (Profile == null || GameDataModel == null) + return null; - var visual = new DrawingVisual(); - using (var drawingContext = visual.RenderOpen()) + var keyboardRect = MainManager.KeyboardManager.ActiveKeyboard.KeyboardRectangle(Scale); + Bitmap bitmap = null; + Profile.DrawingVisual.Dispatcher.Invoke(delegate { - // Setup the DrawingVisual's size - drawingContext.PushClip(new RectangleGeometry(keyboardRect)); - drawingContext.DrawRectangle(new SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 0, 0, 0)), null, keyboardRect); + var visual = new DrawingVisual(); + using (var drawingContext = visual.RenderOpen()) + { + // Setup the DrawingVisual's size + drawingContext.PushClip(new RectangleGeometry(keyboardRect)); + drawingContext.DrawRectangle(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)), + null, keyboardRect); - // Draw the layers - foreach (var layerModel in Profile.Layers) - layerModel.Draw(GameDataModel, drawingContext); + // Draw the layers + foreach (var layerModel in Profile.Layers) + layerModel.Draw(GameDataModel, drawingContext); - // Remove the clip - drawingContext.Pop(); - } + // Remove the clip + drawingContext.Pop(); + } - return ImageUtilities.DrawinVisualToBitmap(visual, keyboardRect); + bitmap = ImageUtilities.DrawinVisualToBitmap(visual, keyboardRect); + }); + return bitmap; } public void HandleGameData(object sender, GameDataReceivedEventArgs e) diff --git a/Artemis/Artemis/Utilities/GeneralHelpers.cs b/Artemis/Artemis/Utilities/GeneralHelpers.cs index fed6fa746..d426f7732 100644 --- a/Artemis/Artemis/Utilities/GeneralHelpers.cs +++ b/Artemis/Artemis/Utilities/GeneralHelpers.cs @@ -55,6 +55,19 @@ namespace Artemis.Utilities } } + public static object GetPropertyValue(object o, string path) + { + var propertyNames = path.Split('.'); + var value = o.GetType().GetProperty(propertyNames[0]).GetValue(o, null); + + if (propertyNames.Length == 1 || value == null) + return value; + else + { + return GetPropertyValue(value, path.Replace(propertyNames[0] + ".", "")); + } + } + public static List GenerateTypeMap(object o) => GenerateTypeMap(o.GetType().GetProperties()); public static List GenerateTypeMap() => GenerateTypeMap(typeof (T).GetProperties()); @@ -66,11 +79,11 @@ namespace Artemis.Utilities { var friendlyName = Empty; if (propertyInfo.PropertyType.Name == "Int32") - friendlyName = "(Number) "; + friendlyName = "(Number)"; else if (propertyInfo.PropertyType.Name == "String") - friendlyName = "(Text) "; + friendlyName = "(Text)"; if (propertyInfo.PropertyType.BaseType?.Name == "Enum") - friendlyName = "(Choice) "; + friendlyName = "(Choice)"; var parent = new PropertyCollection { diff --git a/Artemis/Artemis/Utilities/LayerDrawer.cs b/Artemis/Artemis/Utilities/LayerDrawer.cs index 0ef333be6..bc1bd322c 100644 --- a/Artemis/Artemis/Utilities/LayerDrawer.cs +++ b/Artemis/Artemis/Utilities/LayerDrawer.cs @@ -25,8 +25,6 @@ namespace Artemis.Utilities { if (_layerModel.LayerCalculatedProperties.Brush == null) return; - if (!_layerModel.LayerCalculatedProperties.Brush.IsFrozen) - return; // Set up variables for this frame _rectangle = new Rect(_layerModel.LayerCalculatedProperties.X*Scale, @@ -95,13 +93,15 @@ namespace Artemis.Utilities public void DrawRectangle(DrawingContext c) { - c.DrawRectangle(_layerModel.LayerCalculatedProperties.Brush, null, _rectangle); + _layerModel.LayerCalculatedProperties.Brush.Dispatcher.Invoke( + () => c.DrawRectangle(_layerModel.LayerCalculatedProperties.Brush, null, _rectangle)); } public void DrawEllipse(DrawingContext c) { - c.DrawEllipse(_layerModel.LayerCalculatedProperties.Brush, null, - new Point(_rectangle.Width/2, _rectangle.Height/2), _rectangle.Width, _rectangle.Height); + _layerModel.LayerCalculatedProperties.Brush.Dispatcher.Invoke( + () => c.DrawEllipse(_layerModel.LayerCalculatedProperties.Brush, null, + new Point(_rectangle.Width/2, _rectangle.Height/2), _rectangle.Width, _rectangle.Height)); } public void DrawGif(DrawingContext bmp) diff --git a/Artemis/Artemis/ViewModels/LayerEditorViewModel.cs b/Artemis/Artemis/ViewModels/LayerEditorViewModel.cs index 03f5e7556..0bfe25831 100644 --- a/Artemis/Artemis/ViewModels/LayerEditorViewModel.cs +++ b/Artemis/Artemis/ViewModels/LayerEditorViewModel.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel; +using System.Diagnostics; using System.Linq; using System.Threading; using System.Windows; @@ -35,11 +36,10 @@ namespace Artemis.ViewModels new BindableCollection>( layer.LayerConditions.Select(c => new LayerConditionViewModel(this, c, DataModelProps))); - _previewWorker = new BackgroundWorker(); - _previewWorker.WorkerSupportsCancellation = true; + _previewWorker = new BackgroundWorker {WorkerSupportsCancellation = true}; _previewWorker.DoWork += PreviewWorkerOnDoWork; _previewWorker.RunWorkerAsync(); - + PreSelect(); } @@ -75,8 +75,6 @@ namespace Artemis.ViewModels { get { - // For the preview, put the proposed properties into the calculated properties - _layer.LayerCalculatedProperties = ProposedProperties; var keyboardRect = _activeKeyboard.KeyboardRectangle(4); var visual = new DrawingVisual(); @@ -103,7 +101,7 @@ namespace Artemis.ViewModels while (!_previewWorker.CancellationPending) { NotifyOfPropertyChange(() => LayerImage); - Thread.Sleep(1000/25); + Thread.Sleep(1000 / 25); } } diff --git a/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs b/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs index eab915654..46ed9870e 100644 --- a/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs +++ b/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs @@ -44,10 +44,6 @@ namespace Artemis.ViewModels { if (Equals(value, _selectedProfileModel)) return; _selectedProfileModel = value; - foreach (var layerModel in SelectedProfileModel.Layers) - { - layerModel.LayerUserProperties.Brush?.Freeze(); - } NotifyOfPropertyChange(); } } diff --git a/Artemis/Artemis/Views/LayerEditorView.xaml b/Artemis/Artemis/Views/LayerEditorView.xaml index 6ac31bc7c..4d984ee2a 100644 --- a/Artemis/Artemis/Views/LayerEditorView.xaml +++ b/Artemis/Artemis/Views/LayerEditorView.xaml @@ -48,21 +48,12 @@ - - - + - +