#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 ColorThemeComponent()
{
}
public ColorThemeComponent(ThemeComponentType componentType, string componentName, Color componentColor)
{
if (componentName == null || componentColor == null)
@ -23,7 +27,7 @@ namespace Filtration.ObjectModel.ThemeEditor
public Color Color
{
get { return _color; }
get => _color;
set
{
_color = value;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,13 +7,17 @@ using Filtration.ObjectModel.Enums;
namespace Filtration.ObjectModel.ThemeEditor
{
[Serializable]
[XmlInclude(typeof(ColorThemeComponent))]
[XmlInclude(typeof(EffectColorThemeComponent))]
[XmlInclude(typeof(IconThemeComponent))]
[XmlInclude(typeof(IntegerThemeComponent))]
[XmlInclude(typeof(StringThemeComponent))]
[XmlInclude(typeof(StrIntThemeComponent))]
public class Theme
{
private readonly ThemeComponentCollection _components;
public Theme()
{
_components = new ThemeComponentCollection { IsMasterCollection = false};
Components = new ThemeComponentCollection { IsMasterCollection = false};
}
public string Name { get; set; }
@ -21,28 +25,28 @@ namespace Filtration.ObjectModel.ThemeEditor
[XmlIgnore]
public string FilePath { get; set; }
public ThemeComponentCollection Components => _components;
public ThemeComponentCollection Components { get; set; }
public bool ComponentExists(ThemeComponentType componentType, string componentName)
{
var componentCount =
_components.Count(c => c.ComponentName == componentName && c.ComponentType == componentType);
Components.Count(c => c.ComponentName == componentName && c.ComponentType == componentType);
return componentCount > 0;
}
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)
{
_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)
{
_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<IconThemeComponent, IconThemeComponentViewModel>().ReverseMap();
cfg.CreateMap<EffectColorThemeComponent, EffectColorThemeComponentViewModel>().ReverseMap();
cfg.CreateMap<IThemeEditorViewModel, Theme>();
cfg.CreateMap<ThemeEditorViewModel, Theme>();
});
Mapper.AssertConfigurationIsValid();