#83 - Fixed theme serialization

This commit is contained in:
Ben Wallis 2018-11-28 21:50:42 +00:00
parent e3b1a5dba7
commit fd2023598b
8 changed files with 53 additions and 29 deletions

View File

@ -9,6 +9,10 @@ namespace Filtration.ObjectModel.ThemeEditor
{ {
private Color _color; private Color _color;
private ColorThemeComponent()
{
}
public ColorThemeComponent(ThemeComponentType componentType, string componentName, Color componentColor) public ColorThemeComponent(ThemeComponentType componentType, string componentName, Color componentColor)
{ {
if (componentName == null || componentColor == null) if (componentName == null || componentColor == null)
@ -23,7 +27,7 @@ namespace Filtration.ObjectModel.ThemeEditor
public Color Color public Color Color
{ {
get { return _color; } get => _color;
set set
{ {
_color = value; _color = value;

View File

@ -9,22 +9,21 @@ namespace Filtration.ObjectModel.ThemeEditor
private EffectColor _effectColor; private EffectColor _effectColor;
private bool _temporary; private bool _temporary;
public EffectColorThemeComponent(ThemeComponentType componentType, string componentName, EffectColor componentEffectColor, bool componentTemporary) private EffectColorThemeComponent()
{ {
if (componentName == null)
{
throw new ArgumentException("Null parameters not allowed in EffectColorThemeComponent constructor");
} }
public EffectColorThemeComponent(ThemeComponentType componentType, string componentName, EffectColor componentEffectColor, bool componentTemporary)
{
ComponentType = componentType; ComponentType = componentType;
ComponentName = componentName; ComponentName = componentName ?? throw new ArgumentException("Null parameters not allowed in EffectColorThemeComponent constructor");
EffectColor = componentEffectColor; EffectColor = componentEffectColor;
Temporary = componentTemporary; Temporary = componentTemporary;
} }
public EffectColor EffectColor public EffectColor EffectColor
{ {
get { return _effectColor; } get => _effectColor;
set set
{ {
_effectColor = value; _effectColor = value;
@ -35,7 +34,7 @@ namespace Filtration.ObjectModel.ThemeEditor
public bool Temporary public bool Temporary
{ {
get { return _temporary; } get => _temporary;
set set
{ {
_temporary = value; _temporary = value;

View File

@ -10,6 +10,10 @@ namespace Filtration.ObjectModel.ThemeEditor
private IconColor _iconColor; private IconColor _iconColor;
private IconShape _iconShape; private IconShape _iconShape;
private IconThemeComponent()
{
}
public IconThemeComponent(ThemeComponentType componentType, string componentName, IconSize componentIconSize, IconColor componentIconColor, IconShape componentIconShape) public IconThemeComponent(ThemeComponentType componentType, string componentName, IconSize componentIconSize, IconColor componentIconColor, IconShape componentIconShape)
{ {
if (componentName == null) if (componentName == null)
@ -26,7 +30,7 @@ namespace Filtration.ObjectModel.ThemeEditor
public IconSize IconSize public IconSize IconSize
{ {
get { return _iconSize; } get => _iconSize;
set set
{ {
_iconSize = value; _iconSize = value;
@ -37,7 +41,7 @@ namespace Filtration.ObjectModel.ThemeEditor
public IconColor IconColor public IconColor IconColor
{ {
get { return _iconColor; } get => _iconColor;
set set
{ {
_iconColor = value; _iconColor = value;
@ -48,7 +52,7 @@ namespace Filtration.ObjectModel.ThemeEditor
public IconShape IconShape public IconShape IconShape
{ {
get { return _iconShape; } get => _iconShape;
set set
{ {
_iconShape = value; _iconShape = value;

View File

@ -9,6 +9,10 @@ namespace Filtration.ObjectModel.ThemeEditor
{ {
private int _value; private int _value;
private IntegerThemeComponent()
{
}
public IntegerThemeComponent(ThemeComponentType componentType, string componentName, int componentValue) public IntegerThemeComponent(ThemeComponentType componentType, string componentName, int componentValue)
{ {
if (componentName == null) if (componentName == null)
@ -23,7 +27,7 @@ namespace Filtration.ObjectModel.ThemeEditor
public int Value public int Value
{ {
get { return _value; } get => _value;
set set
{ {
_value = value; _value = value;

View File

@ -9,6 +9,10 @@ namespace Filtration.ObjectModel.ThemeEditor
private string _value; private string _value;
private int _secondValue; private int _secondValue;
private StrIntThemeComponent()
{
}
public StrIntThemeComponent(ThemeComponentType componentType, string componentName, string componentValue, int componentSecondValue) public StrIntThemeComponent(ThemeComponentType componentType, string componentName, string componentValue, int componentSecondValue)
{ {
if (componentName == null || componentValue == null) if (componentName == null || componentValue == null)
@ -24,7 +28,7 @@ namespace Filtration.ObjectModel.ThemeEditor
public string Value public string Value
{ {
get { return _value; } get => _value;
set set
{ {
_value = value; _value = value;
@ -35,7 +39,7 @@ namespace Filtration.ObjectModel.ThemeEditor
public int SecondValue public int SecondValue
{ {
get { return _secondValue; } get => _secondValue;
set set
{ {
_secondValue = value; _secondValue = value;

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Xml.Serialization;
using Filtration.ObjectModel.Enums; using Filtration.ObjectModel.Enums;
using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Command;
using Microsoft.Win32; using Microsoft.Win32;
@ -13,6 +14,10 @@ namespace Filtration.ObjectModel.ThemeEditor
private string _value; private string _value;
public static ObservableCollection<string> _customSoundsAvailable; public static ObservableCollection<string> _customSoundsAvailable;
private StringThemeComponent()
{
}
public StringThemeComponent(ThemeComponentType componentType, string componentName, string componentValue) public StringThemeComponent(ThemeComponentType componentType, string componentName, string componentValue)
{ {
if (componentName == null || componentValue == null) if (componentName == null || componentValue == null)
@ -61,13 +66,14 @@ namespace Filtration.ObjectModel.ThemeEditor
CustomSoundFileDialogCommand = new RelayCommand(OnCustomSoundFileDialog); CustomSoundFileDialogCommand = new RelayCommand(OnCustomSoundFileDialog);
} }
[XmlIgnore]
public RelayCommand CustomSoundFileDialogCommand { get; set; } public RelayCommand CustomSoundFileDialogCommand { get; set; }
public ObservableCollection<string> CustomSoundsAvailable => _customSoundsAvailable; public ObservableCollection<string> CustomSoundsAvailable => _customSoundsAvailable;
public string Value public string Value
{ {
get { return _value; } get => _value;
set set
{ {
_value = value; _value = value;
@ -78,12 +84,11 @@ namespace Filtration.ObjectModel.ThemeEditor
private void OnCustomSoundFileDialog() private void OnCustomSoundFileDialog()
{ {
OpenFileDialog fileDialog = new OpenFileDialog(); OpenFileDialog fileDialog = new OpenFileDialog {DefaultExt = ".mp3"};
fileDialog.DefaultExt = ".mp3"; var poePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\My Games\Path of Exile\";
var poePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments).ToString() + @"\My Games\Path of Exile\";
fileDialog.InitialDirectory = poePath; fileDialog.InitialDirectory = poePath;
Nullable<bool> result = fileDialog.ShowDialog(); bool? result = fileDialog.ShowDialog();
if (result == true) if (result == true)
{ {
var fileName = fileDialog.FileName; var fileName = fileDialog.FileName;

View File

@ -7,13 +7,17 @@ using Filtration.ObjectModel.Enums;
namespace Filtration.ObjectModel.ThemeEditor namespace Filtration.ObjectModel.ThemeEditor
{ {
[Serializable] [Serializable]
[XmlInclude(typeof(ColorThemeComponent))]
[XmlInclude(typeof(EffectColorThemeComponent))]
[XmlInclude(typeof(IconThemeComponent))]
[XmlInclude(typeof(IntegerThemeComponent))]
[XmlInclude(typeof(StringThemeComponent))]
[XmlInclude(typeof(StrIntThemeComponent))]
public class Theme public class Theme
{ {
private readonly ThemeComponentCollection _components;
public Theme() public Theme()
{ {
_components = new ThemeComponentCollection { IsMasterCollection = false}; Components = new ThemeComponentCollection { IsMasterCollection = false};
} }
public string Name { get; set; } public string Name { get; set; }
@ -21,28 +25,28 @@ namespace Filtration.ObjectModel.ThemeEditor
[XmlIgnore] [XmlIgnore]
public string FilePath { get; set; } public string FilePath { get; set; }
public ThemeComponentCollection Components => _components; public ThemeComponentCollection Components { get; set; }
public bool ComponentExists(ThemeComponentType componentType, string componentName) public bool ComponentExists(ThemeComponentType componentType, string componentName)
{ {
var componentCount = var componentCount =
_components.Count(c => c.ComponentName == componentName && c.ComponentType == componentType); Components.Count(c => c.ComponentName == componentName && c.ComponentType == componentType);
return componentCount > 0; return componentCount > 0;
} }
public void AddComponent(ThemeComponentType componentType, string componentName, Color componentColor) public void AddComponent(ThemeComponentType componentType, string componentName, Color componentColor)
{ {
_components.Add(new ColorThemeComponent(componentType, componentName, componentColor)); Components.Add(new ColorThemeComponent(componentType, componentName, componentColor));
} }
public void AddComponent(ThemeComponentType componentType, string componentName, int componentValue) public void AddComponent(ThemeComponentType componentType, string componentName, int componentValue)
{ {
_components.Add(new IntegerThemeComponent(componentType, componentName, componentValue)); Components.Add(new IntegerThemeComponent(componentType, componentName, componentValue));
} }
public void AddComponent(ThemeComponentType componentType, string componentName, string componentValue, int componentSecondValue) public void AddComponent(ThemeComponentType componentType, string componentName, string componentValue, int componentSecondValue)
{ {
_components.Add(new StrIntThemeComponent(componentType, componentName, componentValue, componentSecondValue)); Components.Add(new StrIntThemeComponent(componentType, componentName, componentValue, componentSecondValue));
} }
} }
} }

View File

@ -43,7 +43,7 @@ namespace Filtration
cfg.CreateMap<StringThemeComponent, StringThemeComponentViewModel>().ReverseMap(); cfg.CreateMap<StringThemeComponent, StringThemeComponentViewModel>().ReverseMap();
cfg.CreateMap<IconThemeComponent, IconThemeComponentViewModel>().ReverseMap(); cfg.CreateMap<IconThemeComponent, IconThemeComponentViewModel>().ReverseMap();
cfg.CreateMap<EffectColorThemeComponent, EffectColorThemeComponentViewModel>().ReverseMap(); cfg.CreateMap<EffectColorThemeComponent, EffectColorThemeComponentViewModel>().ReverseMap();
cfg.CreateMap<IThemeEditorViewModel, Theme>(); cfg.CreateMap<ThemeEditorViewModel, Theme>();
}); });
Mapper.AssertConfigurationIsValid(); Mapper.AssertConfigurationIsValid();