1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +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 Artemis.Models.Interfaces;
using Artemis.Profiles.Layers.Models;
using Artemis.ViewModels.Profiles;
using Caliburn.Micro;
namespace Artemis.Profiles.Layers.Abstract
@ -10,13 +10,19 @@ namespace Artemis.Profiles.Layers.Abstract
private Brush _brush;
private LayerModel _layerModel;
protected LayerPropertiesViewModel(LayerModel layerModel, IDataModel dataModel)
protected LayerPropertiesViewModel(LayerEditorViewModel layerEditorViewModel)
{
LayerModel = layerModel;
DataModel = dataModel;
LayerEditorViewModel = layerEditorViewModel;
LayerModel = layerEditorViewModel.ProposedLayer;
Brush = LayerModel.Properties.Brush.Clone();
}
public LayerEditorViewModel LayerEditorViewModel { get; set; }
/// <summary>
/// The proposed brush
/// </summary>
public Brush Brush
{
get { return _brush; }
@ -28,6 +34,9 @@ namespace Artemis.Profiles.Layers.Abstract
}
}
/// <summary>
/// The proposed layer
/// </summary>
public LayerModel LayerModel
{
get { return _layerModel; }
@ -39,8 +48,6 @@ namespace Artemis.Profiles.Layers.Abstract
}
}
public IDataModel DataModel { get; set; }
public abstract void ApplyProperties();
}
}

View File

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

View File

@ -1,4 +1,5 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using Artemis.Models.Interfaces;
using Artemis.Utilities;
@ -62,8 +63,11 @@ namespace Artemis.Profiles.Layers.Models
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;
if (newWidth < 0)
newWidth = 0;
properties.Width = newWidth;
// Apply the right to left option
@ -73,8 +77,11 @@ namespace Artemis.Profiles.Layers.Models
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;
if (newHeight < 0)
newHeight = 0;
properties.Height = newHeight;
if (LayerPropertyOptions == LayerPropertyOptions.Downwards)

View File

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

View File

@ -1,12 +1,11 @@
using Artemis.Models.Interfaces;
using Artemis.Profiles.Layers.Abstract;
using Artemis.Profiles.Layers.Models;
using Artemis.Profiles.Layers.Abstract;
using Artemis.ViewModels.Profiles;
namespace Artemis.Profiles.Layers.Types.Folder
{
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.Properties;
using Artemis.Utilities;
using Artemis.ViewModels.Profiles;
namespace Artemis.Profiles.Layers.Types.Folder
{
@ -44,12 +45,12 @@ namespace Artemis.Profiles.Layers.Types.Folder
layerModel.Properties = new SimplePropertiesModel(layerModel.Properties);
}
public LayerPropertiesViewModel SetupViewModel(LayerPropertiesViewModel layerPropertiesViewModel,
List<ILayerAnimation> layerAnimations, IDataModel dataModel, LayerModel proposedLayer)
public LayerPropertiesViewModel SetupViewModel(LayerEditorViewModel layerEditorViewModel,
LayerPropertiesViewModel layerPropertiesViewModel)
{
if (layerPropertiesViewModel is FolderPropertiesViewModel)
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 Artemis.Models.Interfaces;
using System.Linq;
using Artemis.Profiles.Layers.Abstract;
using Artemis.Profiles.Layers.Interfaces;
using Artemis.Profiles.Layers.Models;
using Artemis.Utilities;
using Artemis.ViewModels.Profiles;
using Caliburn.Micro;
@ -14,16 +10,14 @@ namespace Artemis.Profiles.Layers.Types.Generic
{
private ILayerAnimation _selectedLayerAnimation;
public GenericPropertiesViewModel(LayerModel layerModel, IDataModel dataModel,
IEnumerable<ILayerAnimation> layerAnimations) : base(layerModel, dataModel)
public GenericPropertiesViewModel(LayerEditorViewModel editorVm) : base(editorVm)
{
LayerAnimations = new BindableCollection<ILayerAnimation>(layerAnimations);
OpacityProperties = new LayerDynamicPropertiesViewModel("Opacity",
new BindableCollection<GeneralHelpers.PropertyCollection>(GeneralHelpers.GenerateTypeMap(dataModel)),
layerModel.Properties);
LayerAnimations = new BindableCollection<ILayerAnimation>(editorVm.Animations);
OpacityProperties = new LayerDynamicPropertiesViewModel("Opacity", editorVm);
SelectedLayerAnimation = LayerAnimations.FirstOrDefault(l => l.Name == layerModel.LayerAnimation?.Name) ??
LayerAnimations.First(l => l.Name == "None");
SelectedLayerAnimation =
LayerAnimations.FirstOrDefault(l => l.Name == editorVm.ProposedLayer.LayerAnimation?.Name) ??
LayerAnimations.First(l => l.Name == "None");
}
public BindableCollection<ILayerAnimation> LayerAnimations { get; set; }

View File

@ -9,6 +9,7 @@ using Artemis.Profiles.Layers.Interfaces;
using Artemis.Profiles.Layers.Models;
using Artemis.Properties;
using Artemis.Utilities;
using Artemis.ViewModels.Profiles;
namespace Artemis.Profiles.Layers.Types.Generic
{
@ -85,12 +86,12 @@ namespace Artemis.Profiles.Layers.Types.Generic
layerModel.Properties.DynamicProperties.FirstOrDefault(d => d.LayerProperty == "Width"));
}
public LayerPropertiesViewModel SetupViewModel(LayerPropertiesViewModel layerPropertiesViewModel,
List<ILayerAnimation> layerAnimations, IDataModel dataModel, LayerModel proposedLayer)
public LayerPropertiesViewModel SetupViewModel(LayerEditorViewModel layerEditorViewModel,
LayerPropertiesViewModel layerPropertiesViewModel)
{
if (layerPropertiesViewModel is GenericPropertiesViewModel)
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 Artemis.Models.Interfaces;
using System.Linq;
using Artemis.Profiles.Layers.Abstract;
using Artemis.Profiles.Layers.Interfaces;
using Artemis.Profiles.Layers.Models;
using Artemis.Utilities;
using Artemis.ViewModels.Profiles;
using Caliburn.Micro;
@ -14,16 +10,14 @@ namespace Artemis.Profiles.Layers.Types.Headset
{
private ILayerAnimation _selectedLayerAnimation;
public HeadsetPropertiesViewModel(LayerModel layerModel, IDataModel dataModel,
IEnumerable<ILayerAnimation> layerAnimations) : base(layerModel, dataModel)
public HeadsetPropertiesViewModel(LayerEditorViewModel editorVm) : base(editorVm)
{
LayerAnimations = new BindableCollection<ILayerAnimation>(layerAnimations);
OpacityProperties = new LayerDynamicPropertiesViewModel("Opacity",
new BindableCollection<GeneralHelpers.PropertyCollection>(GeneralHelpers.GenerateTypeMap(dataModel)),
layerModel.Properties);
LayerAnimations = new BindableCollection<ILayerAnimation>(editorVm.Animations);
OpacityProperties = new LayerDynamicPropertiesViewModel("Opacity", editorVm);
SelectedLayerAnimation = LayerAnimations.FirstOrDefault(l => l.Name == layerModel.LayerAnimation?.Name) ??
LayerAnimations.First(l => l.Name == "None");
SelectedLayerAnimation =
LayerAnimations.FirstOrDefault(l => l.Name == editorVm.ProposedLayer.LayerAnimation?.Name) ??
LayerAnimations.First(l => l.Name == "None");
}
public BindableCollection<ILayerAnimation> LayerAnimations { get; set; }

View File

@ -9,6 +9,7 @@ using Artemis.Profiles.Layers.Interfaces;
using Artemis.Profiles.Layers.Models;
using Artemis.Properties;
using Artemis.Utilities;
using Artemis.ViewModels.Profiles;
namespace Artemis.Profiles.Layers.Types.Headset
{
@ -83,12 +84,12 @@ namespace Artemis.Profiles.Layers.Types.Headset
layerModel.Properties.DynamicProperties.FirstOrDefault(d => d.LayerProperty == "Width"));
}
public LayerPropertiesViewModel SetupViewModel(LayerPropertiesViewModel layerPropertiesViewModel,
List<ILayerAnimation> layerAnimations, IDataModel dataModel, LayerModel proposedLayer)
public LayerPropertiesViewModel SetupViewModel(LayerEditorViewModel layerEditorViewModel,
LayerPropertiesViewModel layerPropertiesViewModel)
{
if (layerPropertiesViewModel is HeadsetPropertiesViewModel)
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.Models;
using Artemis.Profiles.Layers.Abstract;
using Artemis.ViewModels.Profiles;
namespace Artemis.Profiles.Layers.Types.KeyPress
{
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.Utilities;
using Artemis.Utilities.Keyboard;
using Artemis.ViewModels.Profiles;
namespace Artemis.Profiles.Layers.Types.KeyPress
{
@ -89,12 +90,12 @@ namespace Artemis.Profiles.Layers.Types.KeyPress
layerModel.Properties = new KeyPressPropertiesModel(layerModel.Properties);
}
public LayerPropertiesViewModel SetupViewModel(LayerPropertiesViewModel layerPropertiesViewModel,
List<ILayerAnimation> layerAnimations, IDataModel dataModel, LayerModel proposedLayer)
public LayerPropertiesViewModel SetupViewModel(LayerEditorViewModel layerEditorViewModel,
LayerPropertiesViewModel layerPropertiesViewModel)
{
if (layerPropertiesViewModel is KeyPressPropertiesViewModel)
return layerPropertiesViewModel;
return new KeyPressPropertiesViewModel(proposedLayer, dataModel);
return new KeyPressPropertiesViewModel(layerEditorViewModel);
}
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 Artemis.Models.Interfaces;
using Artemis.Profiles.Layers.Abstract;
using Artemis.Profiles.Layers.Interfaces;
using Artemis.Profiles.Layers.Models;
using Artemis.Utilities;
using Artemis.ViewModels.Profiles;
using Caliburn.Micro;
@ -16,19 +13,17 @@ namespace Artemis.Profiles.Layers.Types.Keyboard
private bool _isGif;
private ILayerAnimation _selectedLayerAnimation;
public KeyboardPropertiesViewModel(LayerModel layerModel, IDataModel dataModel,
IEnumerable<ILayerAnimation> layerAnimations) : base(layerModel, dataModel)
public KeyboardPropertiesViewModel(LayerEditorViewModel editorVm) : base(editorVm)
{
LayerAnimations = new BindableCollection<ILayerAnimation>(layerAnimations);
LayerAnimations = new BindableCollection<ILayerAnimation>(editorVm.Animations);
var dataModelProps =
new BindableCollection<GeneralHelpers.PropertyCollection>(GeneralHelpers.GenerateTypeMap(dataModel));
HeightProperties = new LayerDynamicPropertiesViewModel("Height", dataModelProps, layerModel.Properties);
WidthProperties = new LayerDynamicPropertiesViewModel("Width", dataModelProps, layerModel.Properties);
OpacityProperties = new LayerDynamicPropertiesViewModel("Opacity", dataModelProps, layerModel.Properties);
HeightProperties = new LayerDynamicPropertiesViewModel("Height", editorVm);
WidthProperties = new LayerDynamicPropertiesViewModel("Width", editorVm);
OpacityProperties = new LayerDynamicPropertiesViewModel("Opacity", editorVm);
SelectedLayerAnimation = LayerAnimations.FirstOrDefault(l => l.Name == layerModel.LayerAnimation?.Name) ??
LayerAnimations.First(l => l.Name == "None");
SelectedLayerAnimation =
LayerAnimations.FirstOrDefault(l => l.Name == editorVm.ProposedLayer.LayerAnimation?.Name) ??
LayerAnimations.First(l => l.Name == "None");
}
public bool ShowGif => IsGif;

View File

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

View File

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

View File

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

View File

@ -9,6 +9,7 @@ using Artemis.Profiles.Layers.Interfaces;
using Artemis.Profiles.Layers.Models;
using Artemis.Properties;
using Artemis.Utilities;
using Artemis.ViewModels.Profiles;
namespace Artemis.Profiles.Layers.Types.Mouse
{
@ -85,12 +86,12 @@ namespace Artemis.Profiles.Layers.Types.Mouse
layerModel.Properties.DynamicProperties.FirstOrDefault(d => d.LayerProperty == "Width"));
}
public LayerPropertiesViewModel SetupViewModel(LayerPropertiesViewModel layerPropertiesViewModel,
List<ILayerAnimation> layerAnimations, IDataModel dataModel, LayerModel proposedLayer)
public LayerPropertiesViewModel SetupViewModel(LayerEditorViewModel layerEditorViewModel,
LayerPropertiesViewModel layerPropertiesViewModel)
{
if (layerPropertiesViewModel is MousePropertiesViewModel)
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 bool _userValueIsVisible;
public LayerConditionViewModel(LayerEditorViewModel conditionModel, LayerConditionModel layerConditionModel,
BindableCollection<GeneralHelpers.PropertyCollection> dataModelProps)
public LayerConditionViewModel(LayerEditorViewModel conditionModel, LayerConditionModel layerConditionModel)
{
_conditionModel = conditionModel;
_preselecting = false;
LayerConditionModel = layerConditionModel;
DataModelProps = dataModelProps;
DataModelProps = conditionModel.DataModelProps;
Operators = new BindableCollection<NamedOperator>();
Enums = new BindableCollection<string>();

View File

@ -9,6 +9,7 @@ namespace Artemis.ViewModels.Profiles
{
public sealed class LayerDynamicPropertiesViewModel : PropertyChangedBase
{
private readonly LayerEditorViewModel _layerEditorViewModel;
private readonly string _property;
private BindableCollection<LayerPropertyOptions> _layerPropertyOptions;
private LayerPropertyType _layerPropertyType;
@ -19,15 +20,19 @@ namespace Artemis.ViewModels.Profiles
private bool _sourcesIsVisible;
private bool _userSourceIsVisible;
public LayerDynamicPropertiesViewModel(string property,
BindableCollection<GeneralHelpers.PropertyCollection> dataModelProps,
LayerPropertiesModel layerPropertiesModel)
public LayerDynamicPropertiesViewModel(string property, LayerEditorViewModel layerEditorViewModel)
{
_property = property;
_layerEditorViewModel = layerEditorViewModel;
// Look for the existing property model
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)
{
Proposed.LayerProperty = property;
@ -37,7 +42,7 @@ namespace Artemis.ViewModels.Profiles
Proposed = GeneralHelpers.Clone(original);
PropertyChanged += OnPropertyChanged;
SetupControls(dataModelProps);
SetupControls();
}
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> Sources { get; set; }
private void SetupControls(BindableCollection<GeneralHelpers.PropertyCollection> dataModelProps)
private void SetupControls()
{
var dataModelProps = _layerEditorViewModel.DataModelProps;
Name = _property + ":";
// Populate target combobox
@ -144,11 +150,11 @@ namespace Artemis.ViewModels.Profiles
{
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
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
SelectedTarget = dataModelProps.FirstOrDefault(p => p.Path == Proposed.GameProperty);
@ -208,12 +214,13 @@ namespace Artemis.ViewModels.Profiles
public void Apply(LayerModel layerModel)
{
var original = layerModel.Properties.DynamicProperties.FirstOrDefault(lp => lp.LayerProperty == _property);
if (original != null)
layerModel.Properties.DynamicProperties.Remove(original);
var proposedProperties = _layerEditorViewModel.ProposedLayer.Properties;
proposedProperties.DynamicProperties = proposedProperties
.DynamicProperties
.Where(p => p.LayerProperty != _property).ToList();
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.KeyboardGif;
using Artemis.Services;
using Artemis.Utilities;
using Artemis.ViewModels.Profiles.Events;
using Caliburn.Micro;
using Newtonsoft.Json;
using Ninject;
using NuGet;
using static Artemis.Utilities.GeneralHelpers;
namespace Artemis.ViewModels.Profiles
{
public sealed class LayerEditorViewModel : Screen
{
private readonly IDataModel _dataModel;
private readonly List<ILayerAnimation> _layerAnimations;
private EventPropertiesViewModel _eventPropertiesViewModel;
private LayerModel _layer;
private LayerPropertiesViewModel _layerPropertiesViewModel;
private LayerModel _proposedLayer;
private ILayerType _selectedLayerType;
public LayerEditorViewModel(IDataModel dataModel, LayerModel layer, IEnumerable<ILayerType> layerTypes,
List<ILayerAnimation> layerAnimations)
public LayerEditorViewModel(LayerModel layer, IDataModel dataModel, IEnumerable<ILayerType> types,
List<ILayerAnimation> animations)
{
_dataModel = dataModel;
_layerAnimations = layerAnimations;
LayerTypes = new BindableCollection<ILayerType>(layerTypes);
DataModelProps = new BindableCollection<GeneralHelpers.PropertyCollection>(
GeneralHelpers.GenerateTypeMap(dataModel));
Layer = layer;
ProposedLayer = GeneralHelpers.Clone(layer);
ProposedLayer.Children.Clear();
ProposedLayer = Clone(layer);
DataModel = DataModel;
Types = new BindableCollection<ILayerType>(types);
Animations = animations;
DataModelProps = new BindableCollection<PropertyCollection>(GenerateTypeMap(dataModel));
if (Layer.Properties == null)
Layer.SetupProperties();
LayerConditionVms = new BindableCollection<LayerConditionViewModel>(
layer.Properties.Conditions.Select(c => new LayerConditionViewModel(this, c, DataModelProps)));
// Setup existing conditions
var conditions = layer.Properties.Conditions.Select(c => new LayerConditionViewModel(this, c));
LayerConditionVms = new BindableCollection<LayerConditionViewModel>(conditions);
PropertyChanged += PropertiesViewModelHandler;
// Setup existiing properties
PreSelect();
}
public bool ModelChanged { get; set; }
public object DataModel { get; set; }
[Inject]
public MetroDialogService DialogService { get; set; }
public BindableCollection<ILayerType> LayerTypes { get; set; }
public BindableCollection<GeneralHelpers.PropertyCollection> DataModelProps { get; set; }
public BindableCollection<ILayerType> Types { get; set; }
public BindableCollection<PropertyCollection> DataModelProps { get; set; }
public BindableCollection<LayerConditionViewModel> LayerConditionVms { get; set; }
public bool KeyboardGridIsVisible => ProposedLayer.LayerType is KeyboardType;
public bool GifGridIsVisible => ProposedLayer.LayerType is KeyboardGifType;
@ -76,6 +72,8 @@ namespace Artemis.ViewModels.Profiles
}
}
public List<ILayerAnimation> Animations { get; set; }
public LayerModel ProposedLayer
{
get { return _proposedLayer; }
@ -122,7 +120,7 @@ namespace Artemis.ViewModels.Profiles
public void PreSelect()
{
SelectedLayerType = LayerTypes.FirstOrDefault(t => t.Name == ProposedLayer.LayerType.Name);
SelectedLayerType = Types.FirstOrDefault(t => t.Name == ProposedLayer.LayerType.Name);
ToggleIsEvent();
}
@ -142,8 +140,7 @@ namespace Artemis.ViewModels.Profiles
}
// Let the layer type handle the viewmodel setup
LayerPropertiesViewModel = ProposedLayer.LayerType.SetupViewModel(LayerPropertiesViewModel, _layerAnimations,
_dataModel, ProposedLayer);
LayerPropertiesViewModel = ProposedLayer.LayerType.SetupViewModel(this, LayerPropertiesViewModel);
if (oldBrush != null)
ProposedLayer.Properties.Brush = oldBrush;
@ -161,22 +158,23 @@ namespace Artemis.ViewModels.Profiles
public void AddCondition()
{
var condition = new LayerConditionModel();
LayerConditionVms.Add(new LayerConditionViewModel(this, condition, DataModelProps));
LayerConditionVms.Add(new LayerConditionViewModel(this, condition));
}
public void Apply()
{
LayerPropertiesViewModel?.ApplyProperties();
Layer.Properties.DynamicProperties.Clear();
Layer.Properties.Conditions.Clear();
JsonConvert.PopulateObject(JsonConvert.SerializeObject(ProposedLayer), Layer);
foreach (var conditionViewModel in LayerConditionVms)
Layer.Properties.Conditions.Add(conditionViewModel.LayerConditionModel);
// TODO: EventPropVM must have layer too
if (EventPropertiesViewModel != null)
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
if (!(Layer.LayerType is KeyboardGifType))
return;
@ -214,7 +212,7 @@ namespace Artemis.ViewModels.Profiles
// 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?)
var currentObj = GeneralHelpers.Clone(Layer);
var currentObj = Clone(Layer);
currentObj.Children.Clear();
var current = JsonConvert.SerializeObject(currentObj, Formatting.Indented);
var proposed = JsonConvert.SerializeObject(ProposedLayer, Formatting.Indented);