From 0bab1e7c9ab01634a2bc3756f1b52ab100f5f87b Mon Sep 17 00:00:00 2001 From: Ben Date: Sun, 7 Jun 2015 15:13:09 +0100 Subject: [PATCH] Cleaned up BlockItem classes, added BlockItemBase and pulled up ILootFilterBlockItem abstract members into it. Added click toggle for Show/Hide as per suggestion from Antnee --- Filtration/Filtration.csproj | 1 + .../BlockItemBaseTypes/ActionBlockItem.cs | 29 +++++++------------ .../BlockItemBaseTypes/ColorBlockItem.cs | 27 ++++------------- .../DualIntegerBlockItem.cs | 26 ++++------------- .../BlockItemBaseTypes/IntegerBlockItem.cs | 27 ++++------------- .../NumericFilterPredicateBlockItem.cs | 22 +------------- .../SocketGroupBlockItemBase.cs | 24 +-------------- .../BlockItemBaseTypes/StringListBlockItem.cs | 22 +------------- Filtration/Models/LootFilterScript.cs | 2 ++ .../ViewModels/LootFilterBlockViewModel.cs | 13 +++++++++ Filtration/Views/LootFilterBlockView.xaml | 18 ++++++++++-- .../Views/LootFilterBlockViewDictionary.xaml | 11 +++++++ 12 files changed, 71 insertions(+), 151 deletions(-) diff --git a/Filtration/Filtration.csproj b/Filtration/Filtration.csproj index c84a4e2..d338b2f 100644 --- a/Filtration/Filtration.csproj +++ b/Filtration/Filtration.csproj @@ -107,6 +107,7 @@ + diff --git a/Filtration/Models/BlockItemBaseTypes/ActionBlockItem.cs b/Filtration/Models/BlockItemBaseTypes/ActionBlockItem.cs index c033520..c570b93 100644 --- a/Filtration/Models/BlockItemBaseTypes/ActionBlockItem.cs +++ b/Filtration/Models/BlockItemBaseTypes/ActionBlockItem.cs @@ -1,12 +1,9 @@ -using System.ComponentModel; -using System.Runtime.CompilerServices; -using System.Windows.Media; -using Filtration.Annotations; +using System.Windows.Media; using Filtration.Enums; namespace Filtration.Models.BlockItemBaseTypes { - internal class ActionBlockItem : ILootFilterBlockItem + internal class ActionBlockItem : BlockItemBase { private BlockAction _action; @@ -28,17 +25,17 @@ namespace Filtration.Models.BlockItemBaseTypes } } - public string PrefixText + public override string PrefixText { get { return string.Empty; } } - public int MaximumAllowed + public override int MaximumAllowed { get { return 1; } } - public string DisplayHeading + public override string DisplayHeading { get { @@ -46,7 +43,7 @@ namespace Filtration.Models.BlockItemBaseTypes } } - public string SummaryText + public override string SummaryText { get { @@ -54,7 +51,7 @@ namespace Filtration.Models.BlockItemBaseTypes } } - public Color SummaryBackgroundColor + public override Color SummaryBackgroundColor { get { @@ -62,7 +59,7 @@ namespace Filtration.Models.BlockItemBaseTypes } } - public Color SummaryTextColor + public override Color SummaryTextColor { get { @@ -70,15 +67,11 @@ namespace Filtration.Models.BlockItemBaseTypes } } - public int SortOrder { get { return 0; } } + public override int SortOrder { get { return 0; } } - public event PropertyChangedEventHandler PropertyChanged; - - [NotifyPropertyChangedInvocator] - protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + public void ToggleAction() { - var handler = PropertyChanged; - if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); + Action = Action == BlockAction.Show ? BlockAction.Hide : BlockAction.Show; } } } diff --git a/Filtration/Models/BlockItemBaseTypes/ColorBlockItem.cs b/Filtration/Models/BlockItemBaseTypes/ColorBlockItem.cs index e99a20c..0b386a8 100644 --- a/Filtration/Models/BlockItemBaseTypes/ColorBlockItem.cs +++ b/Filtration/Models/BlockItemBaseTypes/ColorBlockItem.cs @@ -1,11 +1,8 @@ -using System.ComponentModel; -using System.Runtime.CompilerServices; -using System.Windows.Media; -using Filtration.Annotations; +using System.Windows.Media; namespace Filtration.Models.BlockItemBaseTypes { - internal abstract class ColorBlockItem : ILootFilterBlockItem, IAudioVisualBlockItem + internal abstract class ColorBlockItem : BlockItemBase, IAudioVisualBlockItem { private Color _color; @@ -18,19 +15,13 @@ namespace Filtration.Models.BlockItemBaseTypes Color = color; } - public abstract string PrefixText { get; } - public abstract int MaximumAllowed { get; } - - public abstract string DisplayHeading { get; } - - public string SummaryText + public override string SummaryText { get { return string.Empty; } } - public Color SummaryBackgroundColor { get { return Colors.Transparent; } } - public Color SummaryTextColor { get { return Colors.Transparent; } } - public abstract int SortOrder { get; } + public override Color SummaryBackgroundColor { get { return Colors.Transparent; } } + public override Color SummaryTextColor { get { return Colors.Transparent; } } public Color Color { @@ -41,13 +32,5 @@ namespace Filtration.Models.BlockItemBaseTypes OnPropertyChanged(); } } - - public event PropertyChangedEventHandler PropertyChanged; - [NotifyPropertyChangedInvocator] - protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) - { - var handler = PropertyChanged; - if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); - } } } diff --git a/Filtration/Models/BlockItemBaseTypes/DualIntegerBlockItem.cs b/Filtration/Models/BlockItemBaseTypes/DualIntegerBlockItem.cs index 1776a00..8d35d6c 100644 --- a/Filtration/Models/BlockItemBaseTypes/DualIntegerBlockItem.cs +++ b/Filtration/Models/BlockItemBaseTypes/DualIntegerBlockItem.cs @@ -1,11 +1,8 @@ -using System.ComponentModel; -using System.Runtime.CompilerServices; -using System.Windows.Media; -using Filtration.Annotations; +using System.Windows.Media; namespace Filtration.Models.BlockItemBaseTypes { - internal abstract class DualIntegerBlockItem : ILootFilterBlockItem, IAudioVisualBlockItem + internal abstract class DualIntegerBlockItem : BlockItemBase, IAudioVisualBlockItem { private int _value; private int _secondValue; @@ -20,14 +17,9 @@ namespace Filtration.Models.BlockItemBaseTypes SecondValue = secondValue; } - public abstract string PrefixText { get; } - public abstract int MaximumAllowed { get; } - public abstract string DisplayHeading { get; } - - public string SummaryText { get { return string.Empty; } } - public Color SummaryBackgroundColor { get { return Colors.Transparent; } } - public Color SummaryTextColor { get { return Colors.Transparent; } } - public abstract int SortOrder { get; } + public override string SummaryText { get { return string.Empty; } } + public override Color SummaryBackgroundColor { get { return Colors.Transparent; } } + public override Color SummaryTextColor { get { return Colors.Transparent; } } public int Value { @@ -48,13 +40,5 @@ namespace Filtration.Models.BlockItemBaseTypes OnPropertyChanged(); } } - - public event PropertyChangedEventHandler PropertyChanged; - [NotifyPropertyChangedInvocator] - protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) - { - var handler = PropertyChanged; - if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); - } } } diff --git a/Filtration/Models/BlockItemBaseTypes/IntegerBlockItem.cs b/Filtration/Models/BlockItemBaseTypes/IntegerBlockItem.cs index 6ee87de..42b83b3 100644 --- a/Filtration/Models/BlockItemBaseTypes/IntegerBlockItem.cs +++ b/Filtration/Models/BlockItemBaseTypes/IntegerBlockItem.cs @@ -1,11 +1,8 @@ -using System.ComponentModel; -using System.Runtime.CompilerServices; -using System.Windows.Media; -using Filtration.Annotations; +using System.Windows.Media; namespace Filtration.Models.BlockItemBaseTypes { - internal abstract class IntegerBlockItem : ILootFilterBlockItem, IAudioVisualBlockItem + internal abstract class IntegerBlockItem : BlockItemBase, IAudioVisualBlockItem { private int _value; @@ -18,15 +15,9 @@ namespace Filtration.Models.BlockItemBaseTypes Value = value; } - public abstract string PrefixText { get; } - public abstract int MaximumAllowed { get; } - - public abstract string DisplayHeading { get; } - - public string SummaryText { get { return string.Empty; } } - public Color SummaryBackgroundColor { get { return Colors.Transparent; } } - public Color SummaryTextColor { get { return Colors.Transparent; } } - public abstract int SortOrder { get; } + public override string SummaryText { get { return string.Empty; } } + public override Color SummaryBackgroundColor { get { return Colors.Transparent; } } + public override Color SummaryTextColor { get { return Colors.Transparent; } } public abstract int Minimum { get; } public abstract int Maximum { get; } @@ -40,13 +31,5 @@ namespace Filtration.Models.BlockItemBaseTypes OnPropertyChanged(); } } - - public event PropertyChangedEventHandler PropertyChanged; - [NotifyPropertyChangedInvocator] - protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) - { - var handler = PropertyChanged; - if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); - } } } diff --git a/Filtration/Models/BlockItemBaseTypes/NumericFilterPredicateBlockItem.cs b/Filtration/Models/BlockItemBaseTypes/NumericFilterPredicateBlockItem.cs index c0b6919..558fafc 100644 --- a/Filtration/Models/BlockItemBaseTypes/NumericFilterPredicateBlockItem.cs +++ b/Filtration/Models/BlockItemBaseTypes/NumericFilterPredicateBlockItem.cs @@ -1,13 +1,9 @@ using System; -using System.ComponentModel; -using System.Runtime.CompilerServices; -using System.Windows.Media; -using Filtration.Annotations; using Filtration.Enums; namespace Filtration.Models.BlockItemBaseTypes { - internal abstract class NumericFilterPredicateBlockItem : ILootFilterBlockItem + internal abstract class NumericFilterPredicateBlockItem : BlockItemBase { private NumericFilterPredicate _filterPredicate; @@ -23,14 +19,6 @@ namespace Filtration.Models.BlockItemBaseTypes FilterPredicate.PropertyChanged += OnFilterPredicateChanged; } - public abstract string PrefixText { get; } - public abstract int MaximumAllowed { get; } - public abstract string DisplayHeading { get; } - public abstract string SummaryText { get; } - public abstract Color SummaryBackgroundColor { get; } - public abstract Color SummaryTextColor { get; } - public abstract int SortOrder { get; } - public abstract int Minimum { get; } public abstract int Maximum { get; } @@ -49,13 +37,5 @@ namespace Filtration.Models.BlockItemBaseTypes OnPropertyChanged("FilterPredicate"); OnPropertyChanged("SummaryText"); } - - public event PropertyChangedEventHandler PropertyChanged; - [NotifyPropertyChangedInvocator] - protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) - { - var handler = PropertyChanged; - if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); - } } } diff --git a/Filtration/Models/BlockItemBaseTypes/SocketGroupBlockItemBase.cs b/Filtration/Models/BlockItemBaseTypes/SocketGroupBlockItemBase.cs index eb43d1c..d02a72a 100644 --- a/Filtration/Models/BlockItemBaseTypes/SocketGroupBlockItemBase.cs +++ b/Filtration/Models/BlockItemBaseTypes/SocketGroupBlockItemBase.cs @@ -1,44 +1,22 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; -using System.ComponentModel; -using System.Runtime.CompilerServices; -using System.Windows.Media; -using Filtration.Annotations; using Filtration.Enums; namespace Filtration.Models.BlockItemBaseTypes { - internal abstract class SocketGroupBlockItemBase : ILootFilterBlockItem + internal abstract class SocketGroupBlockItemBase : BlockItemBase { protected SocketGroupBlockItemBase() { SocketColorGroups = new ObservableCollection>(); SocketColorGroups.CollectionChanged += OnSocketColorGroupsCollectionChanged; } - - public abstract string PrefixText { get; } - public abstract int MaximumAllowed { get; } - public abstract string DisplayHeading { get; } - - public abstract string SummaryText { get; } - public abstract Color SummaryBackgroundColor { get; } - public abstract Color SummaryTextColor { get; } - public abstract int SortOrder { get; } public ObservableCollection> SocketColorGroups { get; private set; } private void OnSocketColorGroupsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { OnPropertyChanged("SocketColorGroups"); } - - public event PropertyChangedEventHandler PropertyChanged; - [NotifyPropertyChangedInvocator] - protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) - { - var handler = PropertyChanged; - if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); - } - } } diff --git a/Filtration/Models/BlockItemBaseTypes/StringListBlockItem.cs b/Filtration/Models/BlockItemBaseTypes/StringListBlockItem.cs index 08681a9..7b40b34 100644 --- a/Filtration/Models/BlockItemBaseTypes/StringListBlockItem.cs +++ b/Filtration/Models/BlockItemBaseTypes/StringListBlockItem.cs @@ -1,13 +1,9 @@ using System.Collections.ObjectModel; using System.Collections.Specialized; -using System.ComponentModel; -using System.Runtime.CompilerServices; -using System.Windows.Media; -using Filtration.Annotations; namespace Filtration.Models.BlockItemBaseTypes { - internal abstract class StringListBlockItem : ILootFilterBlockItem + internal abstract class StringListBlockItem : BlockItemBase { protected StringListBlockItem() { @@ -15,14 +11,6 @@ namespace Filtration.Models.BlockItemBaseTypes Items.CollectionChanged += OnItemsCollectionChanged; } - public abstract string PrefixText { get; } - public abstract int MaximumAllowed { get; } - public abstract string DisplayHeading { get; } - - public abstract string SummaryText { get; } - public abstract Color SummaryBackgroundColor { get; } - public abstract Color SummaryTextColor { get; } - public abstract int SortOrder { get; } public ObservableCollection Items { get; protected set; } private void OnItemsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) @@ -30,13 +18,5 @@ namespace Filtration.Models.BlockItemBaseTypes OnPropertyChanged("Items"); OnPropertyChanged("SummaryText"); } - - public event PropertyChangedEventHandler PropertyChanged; - [NotifyPropertyChangedInvocator] - protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) - { - var handler = PropertyChanged; - if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); - } } } diff --git a/Filtration/Models/LootFilterScript.cs b/Filtration/Models/LootFilterScript.cs index d746bda..3f0908a 100644 --- a/Filtration/Models/LootFilterScript.cs +++ b/Filtration/Models/LootFilterScript.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using Filtration.Models.BlockItemTypes; +using Filtration.ViewModels; +using Filtration.Views; namespace Filtration.Models { diff --git a/Filtration/ViewModels/LootFilterBlockViewModel.cs b/Filtration/ViewModels/LootFilterBlockViewModel.cs index 32d12d2..1f2e8b9 100644 --- a/Filtration/ViewModels/LootFilterBlockViewModel.cs +++ b/Filtration/ViewModels/LootFilterBlockViewModel.cs @@ -3,8 +3,10 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Linq; +using System.Windows; using System.Windows.Media; using Filtration.Models; +using Filtration.Models.BlockItemBaseTypes; using Filtration.Models.BlockItemTypes; using Filtration.Services; using Filtration.Views; @@ -44,6 +46,7 @@ namespace Filtration.ViewModels MoveBlockToBottomCommand = new RelayCommand(OnMoveBlockToBottomCommand); ReplaceColorsCommand = new RelayCommand(OnReplaceColorsCommand); AddFilterBlockItemCommand = new RelayCommand(OnAddFilterBlockItemCommand); + ToggleBlockActionCommand = new RelayCommand(OnToggleBlockActionCommand); AddAudioVisualBlockItemCommand = new RelayCommand(OnAddAudioVisualBlockItemCommand); RemoveFilterBlockItemCommand = new RelayCommand(OnRemoveFilterBlockItemCommand); RemoveAudioVisualBlockItemCommand = new RelayCommand(OnRemoveAudioVisualBlockItemCommand); @@ -77,6 +80,7 @@ namespace Filtration.ViewModels public RelayCommand MoveBlockDownCommand { get; private set; } public RelayCommand MoveBlockToTopCommand { get; private set; } public RelayCommand MoveBlockToBottomCommand { get; private set; } + public RelayCommand ToggleBlockActionCommand { get; private set; } public RelayCommand ReplaceColorsCommand { get; private set; } public RelayCommand AddFilterBlockItemCommand { get; private set; } public RelayCommand AddAudioVisualBlockItemCommand { get; private set; } @@ -245,6 +249,15 @@ namespace Filtration.ViewModels get { return Block.HasBlockItemOfType(); } } + private void OnToggleBlockActionCommand() + { + var actionBlock = Block.BlockItems.OfType().First(); + if (actionBlock != null) + { + actionBlock.ToggleAction(); + } + } + private void OnAddFilterBlockItemCommand(Type blockItemType) { if (!AddBlockItemAllowed(blockItemType)) return; diff --git a/Filtration/Views/LootFilterBlockView.xaml b/Filtration/Views/LootFilterBlockView.xaml index bd8db6d..52f7083 100644 --- a/Filtration/Views/LootFilterBlockView.xaml +++ b/Filtration/Views/LootFilterBlockView.xaml @@ -10,6 +10,7 @@ xmlns:blockItemTypes="clr-namespace:Filtration.Models.BlockItemTypes" xmlns:enums="clr-namespace:Filtration.Enums" xmlns:extensions="clr-namespace:Filtration.Extensions" + xmlns:models="clr-namespace:Filtration.Models" mc:Ignorable="d" d:DataContext="{d:DesignInstance Type=viewModels:LootFilterBlockViewModel}" d:DesignHeight="200" d:DesignWidth="800"> @@ -72,13 +73,24 @@ - - + + + + + - + + + + + diff --git a/Filtration/Views/LootFilterBlockViewDictionary.xaml b/Filtration/Views/LootFilterBlockViewDictionary.xaml index 1198f40..6ebc0ee 100644 --- a/Filtration/Views/LootFilterBlockViewDictionary.xaml +++ b/Filtration/Views/LootFilterBlockViewDictionary.xaml @@ -21,6 +21,17 @@ +