1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2026-01-01 10:13:30 +00:00

Cleaned up VM constructors

Fixed rounding issue in dynamic properties
Fixed multiple duplicate dynamic properties being saved in JSON
This commit is contained in:
SpoinkyNL 2016-08-29 21:10:23 +02:00
parent 9225b31212
commit 2ab1c3d94a
21 changed files with 148 additions and 150 deletions

View File

@ -1,6 +1,6 @@
using System.Windows.Media; using System.Windows.Media;
using Artemis.Models.Interfaces;
using Artemis.Profiles.Layers.Models; using Artemis.Profiles.Layers.Models;
using Artemis.ViewModels.Profiles;
using Caliburn.Micro; using Caliburn.Micro;
namespace Artemis.Profiles.Layers.Abstract namespace Artemis.Profiles.Layers.Abstract
@ -10,13 +10,19 @@ namespace Artemis.Profiles.Layers.Abstract
private Brush _brush; private Brush _brush;
private LayerModel _layerModel; private LayerModel _layerModel;
protected LayerPropertiesViewModel(LayerModel layerModel, IDataModel dataModel) protected LayerPropertiesViewModel(LayerEditorViewModel layerEditorViewModel)
{ {
LayerModel = layerModel; LayerEditorViewModel = layerEditorViewModel;
DataModel = dataModel; LayerModel = layerEditorViewModel.ProposedLayer;
Brush = LayerModel.Properties.Brush.Clone(); Brush = LayerModel.Properties.Brush.Clone();
} }
public LayerEditorViewModel LayerEditorViewModel { get; set; }
/// <summary>
/// The proposed brush
/// </summary>
public Brush Brush public Brush Brush
{ {
get { return _brush; } get { return _brush; }
@ -28,6 +34,9 @@ namespace Artemis.Profiles.Layers.Abstract
} }
} }
/// <summary>
/// The proposed layer
/// </summary>
public LayerModel LayerModel public LayerModel LayerModel
{ {
get { return _layerModel; } get { return _layerModel; }
@ -39,8 +48,6 @@ namespace Artemis.Profiles.Layers.Abstract
} }
} }
public IDataModel DataModel { get; set; }
public abstract void ApplyProperties(); public abstract void ApplyProperties();
} }
} }

View File

@ -3,6 +3,7 @@ using System.Windows.Media;
using Artemis.Models.Interfaces; using Artemis.Models.Interfaces;
using Artemis.Profiles.Layers.Abstract; using Artemis.Profiles.Layers.Abstract;
using Artemis.Profiles.Layers.Models; using Artemis.Profiles.Layers.Models;
using Artemis.ViewModels.Profiles;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Artemis.Profiles.Layers.Interfaces namespace Artemis.Profiles.Layers.Interfaces
@ -58,12 +59,9 @@ namespace Artemis.Profiles.Layers.Interfaces
/// <summary> /// <summary>
/// Sets up a viewmodel to accomodate this layerType /// Sets up a viewmodel to accomodate this layerType
/// </summary> /// </summary>
/// <param name="layerEditorViewModel">The layer editor VM this type resides in</param>
/// <param name="layerPropertiesViewModel">The current viewmodel</param> /// <param name="layerPropertiesViewModel">The current viewmodel</param>
/// <param name="layerAnimations"></param> LayerPropertiesViewModel SetupViewModel(LayerEditorViewModel layerEditorViewModel, LayerPropertiesViewModel layerPropertiesViewModel);
/// <param name="dataModel">The datamodel to use in the new viewmodel</param>
/// <param name="proposedLayer">The layer to use in the new viewmodel</param>
LayerPropertiesViewModel SetupViewModel(LayerPropertiesViewModel layerPropertiesViewModel,
List<ILayerAnimation> layerAnimations, IDataModel dataModel, LayerModel proposedLayer);
} }
public enum DrawType public enum DrawType

View File

@ -1,4 +1,5 @@
using System.ComponentModel; using System;
using System.ComponentModel;
using Artemis.Models.Interfaces; using Artemis.Models.Interfaces;
using Artemis.Utilities; using Artemis.Utilities;
@ -62,8 +63,11 @@ namespace Artemis.Profiles.Layers.Models
private void ApplyWidth(LayerPropertiesModel properties, float percentage) private void ApplyWidth(LayerPropertiesModel properties, float percentage)
{ {
var newWidth = percentage*(float) properties.Width; var newWidth = Math.Round(percentage*(float) properties.Width, 2);
var difference = properties.Width - newWidth; var difference = properties.Width - newWidth;
if (newWidth < 0)
newWidth = 0;
properties.Width = newWidth; properties.Width = newWidth;
// Apply the right to left option // Apply the right to left option
@ -73,8 +77,11 @@ namespace Artemis.Profiles.Layers.Models
private void ApplyHeight(LayerPropertiesModel properties, float percentage) private void ApplyHeight(LayerPropertiesModel properties, float percentage)
{ {
var newHeight = percentage*(float) properties.Height; var newHeight = Math.Round(percentage*(float) properties.Height, 2);
var difference = properties.Height - newHeight; var difference = properties.Height - newHeight;
if (newHeight < 0)
newHeight = 0;
properties.Height = newHeight; properties.Height = newHeight;
if (LayerPropertyOptions == LayerPropertyOptions.Downwards) if (LayerPropertyOptions == LayerPropertyOptions.Downwards)

View File

@ -1,12 +1,11 @@
using Artemis.Models.Interfaces; using Artemis.Profiles.Layers.Abstract;
using Artemis.Profiles.Layers.Abstract; using Artemis.ViewModels.Profiles;
using Artemis.Profiles.Layers.Models;
namespace Artemis.Profiles.Layers.Types.Audio namespace Artemis.Profiles.Layers.Types.Audio
{ {
public class AudioPropertiesViewModel : LayerPropertiesViewModel public class AudioPropertiesViewModel : LayerPropertiesViewModel
{ {
public AudioPropertiesViewModel(LayerModel layerModel, IDataModel dataModel) : base(layerModel, dataModel) public AudioPropertiesViewModel(LayerEditorViewModel editorVm) : base(editorVm)
{ {
} }

View File

@ -12,6 +12,7 @@ using Artemis.Profiles.Layers.Interfaces;
using Artemis.Profiles.Layers.Models; using Artemis.Profiles.Layers.Models;
using Artemis.Properties; using Artemis.Properties;
using Artemis.Utilities; using Artemis.Utilities;
using Artemis.ViewModels.Profiles;
using NAudio.CoreAudioApi; using NAudio.CoreAudioApi;
using NAudio.Wave; using NAudio.Wave;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -119,12 +120,12 @@ namespace Artemis.Profiles.Layers.Types.Audio
}; };
} }
public LayerPropertiesViewModel SetupViewModel(LayerPropertiesViewModel layerPropertiesViewModel, public LayerPropertiesViewModel SetupViewModel(LayerEditorViewModel layerEditorViewModel,
List<ILayerAnimation> layerAnimations, IDataModel dataModel, LayerModel proposedLayer) LayerPropertiesViewModel layerPropertiesViewModel)
{ {
if (layerPropertiesViewModel is AudioPropertiesViewModel) if (layerPropertiesViewModel is AudioPropertiesViewModel)
return layerPropertiesViewModel; return layerPropertiesViewModel;
return new AudioPropertiesViewModel(proposedLayer, dataModel); return new AudioPropertiesViewModel(layerEditorViewModel);
} }
private void ApplyVertical(AudioPropertiesModel settings) private void ApplyVertical(AudioPropertiesModel settings)

View File

@ -1,12 +1,11 @@
using Artemis.Models.Interfaces; using Artemis.Profiles.Layers.Abstract;
using Artemis.Profiles.Layers.Abstract; using Artemis.ViewModels.Profiles;
using Artemis.Profiles.Layers.Models;
namespace Artemis.Profiles.Layers.Types.Folder namespace Artemis.Profiles.Layers.Types.Folder
{ {
public class FolderPropertiesViewModel : LayerPropertiesViewModel public class FolderPropertiesViewModel : LayerPropertiesViewModel
{ {
public FolderPropertiesViewModel(LayerModel layerModel, IDataModel dataModel) : base(layerModel, dataModel) public FolderPropertiesViewModel(LayerEditorViewModel editorVm) : base(editorVm)
{ {
} }

View File

@ -7,6 +7,7 @@ using Artemis.Profiles.Layers.Interfaces;
using Artemis.Profiles.Layers.Models; using Artemis.Profiles.Layers.Models;
using Artemis.Properties; using Artemis.Properties;
using Artemis.Utilities; using Artemis.Utilities;
using Artemis.ViewModels.Profiles;
namespace Artemis.Profiles.Layers.Types.Folder namespace Artemis.Profiles.Layers.Types.Folder
{ {
@ -44,12 +45,12 @@ namespace Artemis.Profiles.Layers.Types.Folder
layerModel.Properties = new SimplePropertiesModel(layerModel.Properties); layerModel.Properties = new SimplePropertiesModel(layerModel.Properties);
} }
public LayerPropertiesViewModel SetupViewModel(LayerPropertiesViewModel layerPropertiesViewModel, public LayerPropertiesViewModel SetupViewModel(LayerEditorViewModel layerEditorViewModel,
List<ILayerAnimation> layerAnimations, IDataModel dataModel, LayerModel proposedLayer) LayerPropertiesViewModel layerPropertiesViewModel)
{ {
if (layerPropertiesViewModel is FolderPropertiesViewModel) if (layerPropertiesViewModel is FolderPropertiesViewModel)
return layerPropertiesViewModel; return layerPropertiesViewModel;
return new FolderPropertiesViewModel(proposedLayer, dataModel); return new FolderPropertiesViewModel(layerEditorViewModel);
} }
} }
} }

View File

@ -1,10 +1,6 @@
using System.Collections.Generic; using System.Linq;
using System.Linq;
using Artemis.Models.Interfaces;
using Artemis.Profiles.Layers.Abstract; using Artemis.Profiles.Layers.Abstract;
using Artemis.Profiles.Layers.Interfaces; using Artemis.Profiles.Layers.Interfaces;
using Artemis.Profiles.Layers.Models;
using Artemis.Utilities;
using Artemis.ViewModels.Profiles; using Artemis.ViewModels.Profiles;
using Caliburn.Micro; using Caliburn.Micro;
@ -14,16 +10,14 @@ namespace Artemis.Profiles.Layers.Types.Generic
{ {
private ILayerAnimation _selectedLayerAnimation; private ILayerAnimation _selectedLayerAnimation;
public GenericPropertiesViewModel(LayerModel layerModel, IDataModel dataModel, public GenericPropertiesViewModel(LayerEditorViewModel editorVm) : base(editorVm)
IEnumerable<ILayerAnimation> layerAnimations) : base(layerModel, dataModel)
{ {
LayerAnimations = new BindableCollection<ILayerAnimation>(layerAnimations); LayerAnimations = new BindableCollection<ILayerAnimation>(editorVm.Animations);
OpacityProperties = new LayerDynamicPropertiesViewModel("Opacity", OpacityProperties = new LayerDynamicPropertiesViewModel("Opacity", editorVm);
new BindableCollection<GeneralHelpers.PropertyCollection>(GeneralHelpers.GenerateTypeMap(dataModel)),
layerModel.Properties);
SelectedLayerAnimation = LayerAnimations.FirstOrDefault(l => l.Name == layerModel.LayerAnimation?.Name) ?? SelectedLayerAnimation =
LayerAnimations.First(l => l.Name == "None"); LayerAnimations.FirstOrDefault(l => l.Name == editorVm.ProposedLayer.LayerAnimation?.Name) ??
LayerAnimations.First(l => l.Name == "None");
} }
public BindableCollection<ILayerAnimation> LayerAnimations { get; set; } public BindableCollection<ILayerAnimation> LayerAnimations { get; set; }

View File

@ -9,6 +9,7 @@ using Artemis.Profiles.Layers.Interfaces;
using Artemis.Profiles.Layers.Models; using Artemis.Profiles.Layers.Models;
using Artemis.Properties; using Artemis.Properties;
using Artemis.Utilities; using Artemis.Utilities;
using Artemis.ViewModels.Profiles;
namespace Artemis.Profiles.Layers.Types.Generic namespace Artemis.Profiles.Layers.Types.Generic
{ {
@ -85,12 +86,12 @@ namespace Artemis.Profiles.Layers.Types.Generic
layerModel.Properties.DynamicProperties.FirstOrDefault(d => d.LayerProperty == "Width")); layerModel.Properties.DynamicProperties.FirstOrDefault(d => d.LayerProperty == "Width"));
} }
public LayerPropertiesViewModel SetupViewModel(LayerPropertiesViewModel layerPropertiesViewModel, public LayerPropertiesViewModel SetupViewModel(LayerEditorViewModel layerEditorViewModel,
List<ILayerAnimation> layerAnimations, IDataModel dataModel, LayerModel proposedLayer) LayerPropertiesViewModel layerPropertiesViewModel)
{ {
if (layerPropertiesViewModel is GenericPropertiesViewModel) if (layerPropertiesViewModel is GenericPropertiesViewModel)
return layerPropertiesViewModel; return layerPropertiesViewModel;
return new GenericPropertiesViewModel(proposedLayer, dataModel, layerAnimations); return new GenericPropertiesViewModel(layerEditorViewModel);
} }
} }
} }

View File

@ -1,10 +1,6 @@
using System.Collections.Generic; using System.Linq;
using System.Linq;
using Artemis.Models.Interfaces;
using Artemis.Profiles.Layers.Abstract; using Artemis.Profiles.Layers.Abstract;
using Artemis.Profiles.Layers.Interfaces; using Artemis.Profiles.Layers.Interfaces;
using Artemis.Profiles.Layers.Models;
using Artemis.Utilities;
using Artemis.ViewModels.Profiles; using Artemis.ViewModels.Profiles;
using Caliburn.Micro; using Caliburn.Micro;
@ -14,16 +10,14 @@ namespace Artemis.Profiles.Layers.Types.Headset
{ {
private ILayerAnimation _selectedLayerAnimation; private ILayerAnimation _selectedLayerAnimation;
public HeadsetPropertiesViewModel(LayerModel layerModel, IDataModel dataModel, public HeadsetPropertiesViewModel(LayerEditorViewModel editorVm) : base(editorVm)
IEnumerable<ILayerAnimation> layerAnimations) : base(layerModel, dataModel)
{ {
LayerAnimations = new BindableCollection<ILayerAnimation>(layerAnimations); LayerAnimations = new BindableCollection<ILayerAnimation>(editorVm.Animations);
OpacityProperties = new LayerDynamicPropertiesViewModel("Opacity", OpacityProperties = new LayerDynamicPropertiesViewModel("Opacity", editorVm);
new BindableCollection<GeneralHelpers.PropertyCollection>(GeneralHelpers.GenerateTypeMap(dataModel)),
layerModel.Properties);
SelectedLayerAnimation = LayerAnimations.FirstOrDefault(l => l.Name == layerModel.LayerAnimation?.Name) ?? SelectedLayerAnimation =
LayerAnimations.First(l => l.Name == "None"); LayerAnimations.FirstOrDefault(l => l.Name == editorVm.ProposedLayer.LayerAnimation?.Name) ??
LayerAnimations.First(l => l.Name == "None");
} }
public BindableCollection<ILayerAnimation> LayerAnimations { get; set; } public BindableCollection<ILayerAnimation> LayerAnimations { get; set; }

View File

@ -9,6 +9,7 @@ using Artemis.Profiles.Layers.Interfaces;
using Artemis.Profiles.Layers.Models; using Artemis.Profiles.Layers.Models;
using Artemis.Properties; using Artemis.Properties;
using Artemis.Utilities; using Artemis.Utilities;
using Artemis.ViewModels.Profiles;
namespace Artemis.Profiles.Layers.Types.Headset namespace Artemis.Profiles.Layers.Types.Headset
{ {
@ -83,12 +84,12 @@ namespace Artemis.Profiles.Layers.Types.Headset
layerModel.Properties.DynamicProperties.FirstOrDefault(d => d.LayerProperty == "Width")); layerModel.Properties.DynamicProperties.FirstOrDefault(d => d.LayerProperty == "Width"));
} }
public LayerPropertiesViewModel SetupViewModel(LayerPropertiesViewModel layerPropertiesViewModel, public LayerPropertiesViewModel SetupViewModel(LayerEditorViewModel layerEditorViewModel,
List<ILayerAnimation> layerAnimations, IDataModel dataModel, LayerModel proposedLayer) LayerPropertiesViewModel layerPropertiesViewModel)
{ {
if (layerPropertiesViewModel is HeadsetPropertiesViewModel) if (layerPropertiesViewModel is HeadsetPropertiesViewModel)
return layerPropertiesViewModel; return layerPropertiesViewModel;
return new HeadsetPropertiesViewModel(proposedLayer, dataModel, layerAnimations); return new HeadsetPropertiesViewModel(layerEditorViewModel);
} }
} }
} }

View File

@ -1,12 +1,11 @@
using Artemis.Models.Interfaces; using Artemis.Profiles.Layers.Abstract;
using Artemis.Profiles.Layers.Abstract; using Artemis.ViewModels.Profiles;
using Artemis.Profiles.Layers.Models;
namespace Artemis.Profiles.Layers.Types.KeyPress namespace Artemis.Profiles.Layers.Types.KeyPress
{ {
public class KeyPressPropertiesViewModel : LayerPropertiesViewModel public class KeyPressPropertiesViewModel : LayerPropertiesViewModel
{ {
public KeyPressPropertiesViewModel(LayerModel layerModel, IDataModel dataModel) : base(layerModel, dataModel) public KeyPressPropertiesViewModel(LayerEditorViewModel editorVm) : base(editorVm)
{ {
} }

View File

@ -13,6 +13,7 @@ using Artemis.Profiles.Layers.Models;
using Artemis.Properties; using Artemis.Properties;
using Artemis.Utilities; using Artemis.Utilities;
using Artemis.Utilities.Keyboard; using Artemis.Utilities.Keyboard;
using Artemis.ViewModels.Profiles;
namespace Artemis.Profiles.Layers.Types.KeyPress namespace Artemis.Profiles.Layers.Types.KeyPress
{ {
@ -89,12 +90,12 @@ namespace Artemis.Profiles.Layers.Types.KeyPress
layerModel.Properties = new KeyPressPropertiesModel(layerModel.Properties); layerModel.Properties = new KeyPressPropertiesModel(layerModel.Properties);
} }
public LayerPropertiesViewModel SetupViewModel(LayerPropertiesViewModel layerPropertiesViewModel, public LayerPropertiesViewModel SetupViewModel(LayerEditorViewModel layerEditorViewModel,
List<ILayerAnimation> layerAnimations, IDataModel dataModel, LayerModel proposedLayer) LayerPropertiesViewModel layerPropertiesViewModel)
{ {
if (layerPropertiesViewModel is KeyPressPropertiesViewModel) if (layerPropertiesViewModel is KeyPressPropertiesViewModel)
return layerPropertiesViewModel; return layerPropertiesViewModel;
return new KeyPressPropertiesViewModel(proposedLayer, dataModel); return new KeyPressPropertiesViewModel(layerEditorViewModel);
} }
private void KeyboardHookOnKeyDownCallback(KeyEventArgs e) private void KeyboardHookOnKeyDownCallback(KeyEventArgs e)

View File

@ -1,10 +1,7 @@
using System.Collections.Generic; using System.Linq;
using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using Artemis.Models.Interfaces;
using Artemis.Profiles.Layers.Abstract; using Artemis.Profiles.Layers.Abstract;
using Artemis.Profiles.Layers.Interfaces; using Artemis.Profiles.Layers.Interfaces;
using Artemis.Profiles.Layers.Models;
using Artemis.Utilities; using Artemis.Utilities;
using Artemis.ViewModels.Profiles; using Artemis.ViewModels.Profiles;
using Caliburn.Micro; using Caliburn.Micro;
@ -16,19 +13,17 @@ namespace Artemis.Profiles.Layers.Types.Keyboard
private bool _isGif; private bool _isGif;
private ILayerAnimation _selectedLayerAnimation; private ILayerAnimation _selectedLayerAnimation;
public KeyboardPropertiesViewModel(LayerModel layerModel, IDataModel dataModel, public KeyboardPropertiesViewModel(LayerEditorViewModel editorVm) : base(editorVm)
IEnumerable<ILayerAnimation> layerAnimations) : base(layerModel, dataModel)
{ {
LayerAnimations = new BindableCollection<ILayerAnimation>(layerAnimations); LayerAnimations = new BindableCollection<ILayerAnimation>(editorVm.Animations);
var dataModelProps = HeightProperties = new LayerDynamicPropertiesViewModel("Height", editorVm);
new BindableCollection<GeneralHelpers.PropertyCollection>(GeneralHelpers.GenerateTypeMap(dataModel)); WidthProperties = new LayerDynamicPropertiesViewModel("Width", editorVm);
HeightProperties = new LayerDynamicPropertiesViewModel("Height", dataModelProps, layerModel.Properties); OpacityProperties = new LayerDynamicPropertiesViewModel("Opacity", editorVm);
WidthProperties = new LayerDynamicPropertiesViewModel("Width", dataModelProps, layerModel.Properties);
OpacityProperties = new LayerDynamicPropertiesViewModel("Opacity", dataModelProps, layerModel.Properties);
SelectedLayerAnimation = LayerAnimations.FirstOrDefault(l => l.Name == layerModel.LayerAnimation?.Name) ?? SelectedLayerAnimation =
LayerAnimations.First(l => l.Name == "None"); LayerAnimations.FirstOrDefault(l => l.Name == editorVm.ProposedLayer.LayerAnimation?.Name) ??
LayerAnimations.First(l => l.Name == "None");
} }
public bool ShowGif => IsGif; public bool ShowGif => IsGif;

View File

@ -6,6 +6,7 @@ using Artemis.Profiles.Layers.Abstract;
using Artemis.Profiles.Layers.Animations; using Artemis.Profiles.Layers.Animations;
using Artemis.Profiles.Layers.Interfaces; using Artemis.Profiles.Layers.Interfaces;
using Artemis.Profiles.Layers.Models; using Artemis.Profiles.Layers.Models;
using Artemis.ViewModels.Profiles;
namespace Artemis.Profiles.Layers.Types.Keyboard namespace Artemis.Profiles.Layers.Types.Keyboard
{ {
@ -82,12 +83,12 @@ namespace Artemis.Profiles.Layers.Types.Keyboard
layerModel.Properties = new KeyboardPropertiesModel(layerModel.Properties); layerModel.Properties = new KeyboardPropertiesModel(layerModel.Properties);
} }
public LayerPropertiesViewModel SetupViewModel(LayerPropertiesViewModel layerPropertiesViewModel, public LayerPropertiesViewModel SetupViewModel(LayerEditorViewModel layerEditorViewModel,
List<ILayerAnimation> layerAnimations, IDataModel dataModel, LayerModel proposedLayer) LayerPropertiesViewModel layerPropertiesViewModel)
{ {
var model = layerPropertiesViewModel as KeyboardPropertiesViewModel; var model = layerPropertiesViewModel as KeyboardPropertiesViewModel;
if (model == null) if (model == null)
return new KeyboardPropertiesViewModel(proposedLayer, dataModel, layerAnimations) return new KeyboardPropertiesViewModel(layerEditorViewModel)
{ {
IsGif = false IsGif = false
}; };

View File

@ -10,6 +10,7 @@ using Artemis.Profiles.Layers.Models;
using Artemis.Profiles.Layers.Types.Keyboard; using Artemis.Profiles.Layers.Types.Keyboard;
using Artemis.Properties; using Artemis.Properties;
using Artemis.Utilities; using Artemis.Utilities;
using Artemis.ViewModels.Profiles;
namespace Artemis.Profiles.Layers.Types.KeyboardGif namespace Artemis.Profiles.Layers.Types.KeyboardGif
{ {
@ -76,12 +77,12 @@ namespace Artemis.Profiles.Layers.Types.KeyboardGif
layerModel.Properties = new KeyboardPropertiesModel(layerModel.Properties); layerModel.Properties = new KeyboardPropertiesModel(layerModel.Properties);
} }
public LayerPropertiesViewModel SetupViewModel(LayerPropertiesViewModel layerPropertiesViewModel, public LayerPropertiesViewModel SetupViewModel(LayerEditorViewModel layerEditorViewModel,
List<ILayerAnimation> layerAnimations, IDataModel dataModel, LayerModel proposedLayer) LayerPropertiesViewModel layerPropertiesViewModel)
{ {
var model = layerPropertiesViewModel as KeyboardPropertiesViewModel; var model = layerPropertiesViewModel as KeyboardPropertiesViewModel;
if (model == null) if (model == null)
return new KeyboardPropertiesViewModel(proposedLayer, dataModel, layerAnimations) return new KeyboardPropertiesViewModel(layerEditorViewModel)
{ {
IsGif = true IsGif = true
}; };

View File

@ -1,10 +1,6 @@
using System.Collections.Generic; using System.Linq;
using System.Linq;
using Artemis.Models.Interfaces;
using Artemis.Profiles.Layers.Abstract; using Artemis.Profiles.Layers.Abstract;
using Artemis.Profiles.Layers.Interfaces; using Artemis.Profiles.Layers.Interfaces;
using Artemis.Profiles.Layers.Models;
using Artemis.Utilities;
using Artemis.ViewModels.Profiles; using Artemis.ViewModels.Profiles;
using Caliburn.Micro; using Caliburn.Micro;
@ -14,16 +10,14 @@ namespace Artemis.Profiles.Layers.Types.Mouse
{ {
private ILayerAnimation _selectedLayerAnimation; private ILayerAnimation _selectedLayerAnimation;
public MousePropertiesViewModel(LayerModel layerModel, IDataModel dataModel, public MousePropertiesViewModel(LayerEditorViewModel editorVm) : base(editorVm)
IEnumerable<ILayerAnimation> layerAnimations) : base(layerModel, dataModel)
{ {
LayerAnimations = new BindableCollection<ILayerAnimation>(layerAnimations); LayerAnimations = new BindableCollection<ILayerAnimation>(editorVm.Animations);
OpacityProperties = new LayerDynamicPropertiesViewModel("Opacity", OpacityProperties = new LayerDynamicPropertiesViewModel("Opacity", editorVm);
new BindableCollection<GeneralHelpers.PropertyCollection>(GeneralHelpers.GenerateTypeMap(dataModel)),
layerModel.Properties);
SelectedLayerAnimation = LayerAnimations.FirstOrDefault(l => l.Name == layerModel.LayerAnimation?.Name) ?? SelectedLayerAnimation =
LayerAnimations.First(l => l.Name == "None"); LayerAnimations.FirstOrDefault(l => l.Name == editorVm.ProposedLayer.LayerAnimation?.Name) ??
LayerAnimations.First(l => l.Name == "None");
} }
public BindableCollection<ILayerAnimation> LayerAnimations { get; set; } public BindableCollection<ILayerAnimation> LayerAnimations { get; set; }

View File

@ -9,6 +9,7 @@ using Artemis.Profiles.Layers.Interfaces;
using Artemis.Profiles.Layers.Models; using Artemis.Profiles.Layers.Models;
using Artemis.Properties; using Artemis.Properties;
using Artemis.Utilities; using Artemis.Utilities;
using Artemis.ViewModels.Profiles;
namespace Artemis.Profiles.Layers.Types.Mouse namespace Artemis.Profiles.Layers.Types.Mouse
{ {
@ -85,12 +86,12 @@ namespace Artemis.Profiles.Layers.Types.Mouse
layerModel.Properties.DynamicProperties.FirstOrDefault(d => d.LayerProperty == "Width")); layerModel.Properties.DynamicProperties.FirstOrDefault(d => d.LayerProperty == "Width"));
} }
public LayerPropertiesViewModel SetupViewModel(LayerPropertiesViewModel layerPropertiesViewModel, public LayerPropertiesViewModel SetupViewModel(LayerEditorViewModel layerEditorViewModel,
List<ILayerAnimation> layerAnimations, IDataModel dataModel, LayerModel proposedLayer) LayerPropertiesViewModel layerPropertiesViewModel)
{ {
if (layerPropertiesViewModel is MousePropertiesViewModel) if (layerPropertiesViewModel is MousePropertiesViewModel)
return layerPropertiesViewModel; return layerPropertiesViewModel;
return new MousePropertiesViewModel(proposedLayer, dataModel, layerAnimations); return new MousePropertiesViewModel(layerEditorViewModel);
} }
} }
} }

View File

@ -48,14 +48,13 @@ namespace Artemis.ViewModels.Profiles
private string _userValue; private string _userValue;
private bool _userValueIsVisible; private bool _userValueIsVisible;
public LayerConditionViewModel(LayerEditorViewModel conditionModel, LayerConditionModel layerConditionModel, public LayerConditionViewModel(LayerEditorViewModel conditionModel, LayerConditionModel layerConditionModel)
BindableCollection<GeneralHelpers.PropertyCollection> dataModelProps)
{ {
_conditionModel = conditionModel; _conditionModel = conditionModel;
_preselecting = false; _preselecting = false;
LayerConditionModel = layerConditionModel; LayerConditionModel = layerConditionModel;
DataModelProps = dataModelProps; DataModelProps = conditionModel.DataModelProps;
Operators = new BindableCollection<NamedOperator>(); Operators = new BindableCollection<NamedOperator>();
Enums = new BindableCollection<string>(); Enums = new BindableCollection<string>();

View File

@ -9,6 +9,7 @@ namespace Artemis.ViewModels.Profiles
{ {
public sealed class LayerDynamicPropertiesViewModel : PropertyChangedBase public sealed class LayerDynamicPropertiesViewModel : PropertyChangedBase
{ {
private readonly LayerEditorViewModel _layerEditorViewModel;
private readonly string _property; private readonly string _property;
private BindableCollection<LayerPropertyOptions> _layerPropertyOptions; private BindableCollection<LayerPropertyOptions> _layerPropertyOptions;
private LayerPropertyType _layerPropertyType; private LayerPropertyType _layerPropertyType;
@ -19,15 +20,19 @@ namespace Artemis.ViewModels.Profiles
private bool _sourcesIsVisible; private bool _sourcesIsVisible;
private bool _userSourceIsVisible; private bool _userSourceIsVisible;
public LayerDynamicPropertiesViewModel(string property, public LayerDynamicPropertiesViewModel(string property, LayerEditorViewModel layerEditorViewModel)
BindableCollection<GeneralHelpers.PropertyCollection> dataModelProps,
LayerPropertiesModel layerPropertiesModel)
{ {
_property = property; _property = property;
_layerEditorViewModel = layerEditorViewModel;
// Look for the existing property model // Look for the existing property model
Proposed = new DynamicPropertiesModel(); Proposed = new DynamicPropertiesModel();
var original = layerPropertiesModel.DynamicProperties.FirstOrDefault(lp => lp.LayerProperty == _property); var original = layerEditorViewModel
.ProposedLayer
.Properties
.DynamicProperties
.FirstOrDefault(lp => lp.LayerProperty == _property);
if (original == null) if (original == null)
{ {
Proposed.LayerProperty = property; Proposed.LayerProperty = property;
@ -37,7 +42,7 @@ namespace Artemis.ViewModels.Profiles
Proposed = GeneralHelpers.Clone(original); Proposed = GeneralHelpers.Clone(original);
PropertyChanged += OnPropertyChanged; PropertyChanged += OnPropertyChanged;
SetupControls(dataModelProps); SetupControls();
} }
public LayerPropertyType LayerPropertyType public LayerPropertyType LayerPropertyType
@ -129,14 +134,15 @@ namespace Artemis.ViewModels.Profiles
} }
} }
public bool ControlsEnabled => SelectedTarget.Display != "None" && SelectedTarget.Path != null; public bool ControlsEnabled => (SelectedTarget.Display != "None") && (SelectedTarget.Path != null);
public BindableCollection<GeneralHelpers.PropertyCollection> Targets { get; set; } public BindableCollection<GeneralHelpers.PropertyCollection> Targets { get; set; }
public BindableCollection<GeneralHelpers.PropertyCollection> Sources { get; set; } public BindableCollection<GeneralHelpers.PropertyCollection> Sources { get; set; }
private void SetupControls(BindableCollection<GeneralHelpers.PropertyCollection> dataModelProps) private void SetupControls()
{ {
var dataModelProps = _layerEditorViewModel.DataModelProps;
Name = _property + ":"; Name = _property + ":";
// Populate target combobox // Populate target combobox
@ -144,11 +150,11 @@ namespace Artemis.ViewModels.Profiles
{ {
new GeneralHelpers.PropertyCollection {Display = "None"} new GeneralHelpers.PropertyCollection {Display = "None"}
}; };
Targets.AddRange(dataModelProps.Where(p => p.Type == "Int32" || p.Type == "Single")); Targets.AddRange(dataModelProps.Where(p => (p.Type == "Int32") || (p.Type == "Single")));
// Populate sources combobox // Populate sources combobox
Sources = new BindableCollection<GeneralHelpers.PropertyCollection>(); Sources = new BindableCollection<GeneralHelpers.PropertyCollection>();
Sources.AddRange(dataModelProps.Where(p => p.Type == "Int32" || p.Type == "Single")); Sources.AddRange(dataModelProps.Where(p => (p.Type == "Int32") || (p.Type == "Single")));
// Preselect according to the model // Preselect according to the model
SelectedTarget = dataModelProps.FirstOrDefault(p => p.Path == Proposed.GameProperty); SelectedTarget = dataModelProps.FirstOrDefault(p => p.Path == Proposed.GameProperty);
@ -208,12 +214,13 @@ namespace Artemis.ViewModels.Profiles
public void Apply(LayerModel layerModel) public void Apply(LayerModel layerModel)
{ {
var original = layerModel.Properties.DynamicProperties.FirstOrDefault(lp => lp.LayerProperty == _property); var proposedProperties = _layerEditorViewModel.ProposedLayer.Properties;
if (original != null) proposedProperties.DynamicProperties = proposedProperties
layerModel.Properties.DynamicProperties.Remove(original); .DynamicProperties
.Where(p => p.LayerProperty != _property).ToList();
if (!Proposed.GameProperty.IsNullOrEmpty()) if (!Proposed.GameProperty.IsNullOrEmpty())
layerModel.Properties.DynamicProperties.Add(Proposed); proposedProperties.DynamicProperties.Add(Proposed);
} }
} }
} }

View File

@ -10,57 +10,53 @@ using Artemis.Profiles.Layers.Models;
using Artemis.Profiles.Layers.Types.Keyboard; using Artemis.Profiles.Layers.Types.Keyboard;
using Artemis.Profiles.Layers.Types.KeyboardGif; using Artemis.Profiles.Layers.Types.KeyboardGif;
using Artemis.Services; using Artemis.Services;
using Artemis.Utilities;
using Artemis.ViewModels.Profiles.Events; using Artemis.ViewModels.Profiles.Events;
using Caliburn.Micro; using Caliburn.Micro;
using Newtonsoft.Json; using Newtonsoft.Json;
using Ninject; using Ninject;
using NuGet; using static Artemis.Utilities.GeneralHelpers;
namespace Artemis.ViewModels.Profiles namespace Artemis.ViewModels.Profiles
{ {
public sealed class LayerEditorViewModel : Screen public sealed class LayerEditorViewModel : Screen
{ {
private readonly IDataModel _dataModel;
private readonly List<ILayerAnimation> _layerAnimations;
private EventPropertiesViewModel _eventPropertiesViewModel; private EventPropertiesViewModel _eventPropertiesViewModel;
private LayerModel _layer; private LayerModel _layer;
private LayerPropertiesViewModel _layerPropertiesViewModel; private LayerPropertiesViewModel _layerPropertiesViewModel;
private LayerModel _proposedLayer; private LayerModel _proposedLayer;
private ILayerType _selectedLayerType; private ILayerType _selectedLayerType;
public LayerEditorViewModel(IDataModel dataModel, LayerModel layer, IEnumerable<ILayerType> layerTypes, public LayerEditorViewModel(LayerModel layer, IDataModel dataModel, IEnumerable<ILayerType> types,
List<ILayerAnimation> layerAnimations) List<ILayerAnimation> animations)
{ {
_dataModel = dataModel;
_layerAnimations = layerAnimations;
LayerTypes = new BindableCollection<ILayerType>(layerTypes);
DataModelProps = new BindableCollection<GeneralHelpers.PropertyCollection>(
GeneralHelpers.GenerateTypeMap(dataModel));
Layer = layer; Layer = layer;
ProposedLayer = GeneralHelpers.Clone(layer); ProposedLayer = Clone(layer);
ProposedLayer.Children.Clear(); DataModel = DataModel;
Types = new BindableCollection<ILayerType>(types);
Animations = animations;
DataModelProps = new BindableCollection<PropertyCollection>(GenerateTypeMap(dataModel));
if (Layer.Properties == null) if (Layer.Properties == null)
Layer.SetupProperties(); Layer.SetupProperties();
LayerConditionVms = new BindableCollection<LayerConditionViewModel>( // Setup existing conditions
layer.Properties.Conditions.Select(c => new LayerConditionViewModel(this, c, DataModelProps))); var conditions = layer.Properties.Conditions.Select(c => new LayerConditionViewModel(this, c));
LayerConditionVms = new BindableCollection<LayerConditionViewModel>(conditions);
PropertyChanged += PropertiesViewModelHandler; PropertyChanged += PropertiesViewModelHandler;
// Setup existiing properties
PreSelect(); PreSelect();
} }
public object DataModel { get; set; }
public bool ModelChanged { get; set; }
[Inject] [Inject]
public MetroDialogService DialogService { get; set; } public MetroDialogService DialogService { get; set; }
public BindableCollection<ILayerType> LayerTypes { get; set; } public BindableCollection<ILayerType> Types { get; set; }
public BindableCollection<GeneralHelpers.PropertyCollection> DataModelProps { get; set; } public BindableCollection<PropertyCollection> DataModelProps { get; set; }
public BindableCollection<LayerConditionViewModel> LayerConditionVms { get; set; } public BindableCollection<LayerConditionViewModel> LayerConditionVms { get; set; }
public bool KeyboardGridIsVisible => ProposedLayer.LayerType is KeyboardType; public bool KeyboardGridIsVisible => ProposedLayer.LayerType is KeyboardType;
public bool GifGridIsVisible => ProposedLayer.LayerType is KeyboardGifType; public bool GifGridIsVisible => ProposedLayer.LayerType is KeyboardGifType;
@ -76,6 +72,8 @@ namespace Artemis.ViewModels.Profiles
} }
} }
public List<ILayerAnimation> Animations { get; set; }
public LayerModel ProposedLayer public LayerModel ProposedLayer
{ {
get { return _proposedLayer; } get { return _proposedLayer; }
@ -122,7 +120,7 @@ namespace Artemis.ViewModels.Profiles
public void PreSelect() public void PreSelect()
{ {
SelectedLayerType = LayerTypes.FirstOrDefault(t => t.Name == ProposedLayer.LayerType.Name); SelectedLayerType = Types.FirstOrDefault(t => t.Name == ProposedLayer.LayerType.Name);
ToggleIsEvent(); ToggleIsEvent();
} }
@ -142,8 +140,7 @@ namespace Artemis.ViewModels.Profiles
} }
// Let the layer type handle the viewmodel setup // Let the layer type handle the viewmodel setup
LayerPropertiesViewModel = ProposedLayer.LayerType.SetupViewModel(LayerPropertiesViewModel, _layerAnimations, LayerPropertiesViewModel = ProposedLayer.LayerType.SetupViewModel(this, LayerPropertiesViewModel);
_dataModel, ProposedLayer);
if (oldBrush != null) if (oldBrush != null)
ProposedLayer.Properties.Brush = oldBrush; ProposedLayer.Properties.Brush = oldBrush;
@ -161,22 +158,23 @@ namespace Artemis.ViewModels.Profiles
public void AddCondition() public void AddCondition()
{ {
var condition = new LayerConditionModel(); var condition = new LayerConditionModel();
LayerConditionVms.Add(new LayerConditionViewModel(this, condition, DataModelProps)); LayerConditionVms.Add(new LayerConditionViewModel(this, condition));
} }
public void Apply() public void Apply()
{ {
LayerPropertiesViewModel?.ApplyProperties(); LayerPropertiesViewModel?.ApplyProperties();
Layer.Properties.DynamicProperties.Clear();
Layer.Properties.Conditions.Clear();
JsonConvert.PopulateObject(JsonConvert.SerializeObject(ProposedLayer), Layer); JsonConvert.PopulateObject(JsonConvert.SerializeObject(ProposedLayer), Layer);
foreach (var conditionViewModel in LayerConditionVms)
Layer.Properties.Conditions.Add(conditionViewModel.LayerConditionModel);
// TODO: EventPropVM must have layer too // TODO: EventPropVM must have layer too
if (EventPropertiesViewModel != null) if (EventPropertiesViewModel != null)
Layer.EventProperties = EventPropertiesViewModel.GetAppliedProperties(); Layer.EventProperties = EventPropertiesViewModel.GetAppliedProperties();
Layer.Properties.Conditions.Clear();
foreach (var conditionViewModel in LayerConditionVms)
Layer.Properties.Conditions.Add(conditionViewModel.LayerConditionModel);
// Don't bother checking for a GIF path unless the type is GIF // Don't bother checking for a GIF path unless the type is GIF
if (!(Layer.LayerType is KeyboardGifType)) if (!(Layer.LayerType is KeyboardGifType))
return; return;
@ -214,7 +212,7 @@ namespace Artemis.ViewModels.Profiles
// Ignore the children, can't just temporarily add them to the proposed layer because // Ignore the children, can't just temporarily add them to the proposed layer because
// that would upset the child layers' relations (sounds like an episode of Dr. Phil amirite?) // that would upset the child layers' relations (sounds like an episode of Dr. Phil amirite?)
var currentObj = GeneralHelpers.Clone(Layer); var currentObj = Clone(Layer);
currentObj.Children.Clear(); currentObj.Children.Clear();
var current = JsonConvert.SerializeObject(currentObj, Formatting.Indented); var current = JsonConvert.SerializeObject(currentObj, Formatting.Indented);
var proposed = JsonConvert.SerializeObject(ProposedLayer, Formatting.Indented); var proposed = JsonConvert.SerializeObject(ProposedLayer, Formatting.Indented);