Refactored the Item Preview boxes in the block list and the replace colors dialog to use a common UserControl

This commit is contained in:
Ben 2015-06-07 18:56:55 +01:00
parent 0bab1e7c9a
commit dffe301c87
9 changed files with 149 additions and 41 deletions

View File

@ -148,6 +148,9 @@
<Compile Include="UserControls\EditableListBoxControl.xaml.cs">
<DependentUpon>EditableListBoxControl.xaml</DependentUpon>
</Compile>
<Compile Include="UserControls\ItemPreviewControl.xaml.cs">
<DependentUpon>ItemPreviewControl.xaml</DependentUpon>
</Compile>
<Compile Include="Utilities\LineReader.cs" />
<Compile Include="ViewModels\FiltrationViewModelBase.cs" />
<Compile Include="ViewModels\ILootFilterScriptViewModelFactory.cs" />
@ -183,6 +186,10 @@
<Compile Include="WindsorInstallers\TranslatorsInstaller.cs" />
<Compile Include="WindsorInstallers\ViewModelsInstaller.cs" />
<Compile Include="WindsorInstallers\ViewsInstaller.cs" />
<Page Include="UserControls\ItemPreviewControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\CrossButton.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@ -203,7 +210,7 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\LootFilterBlockViewDictionary.xaml">
<Page Include="Views\SharedResourcesDictionary.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>

View File

@ -0,0 +1,26 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Media;
using Filtration.Annotations;
namespace Filtration.Models.BlockItemBaseTypes
{
abstract class BlockItemBase : ILootFilterBlockItem
{
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 event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
var handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View File

@ -0,0 +1,26 @@
<UserControl x:Class="Filtration.UserControls.ItemPreviewControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:userControls="clr-namespace:Filtration.UserControls"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=userControls:ItemPreviewControl}"
d:DesignHeight="35" d:DesignWidth="170">
<UserControl.Resources>
<ResourceDictionary Source="../Views/SharedResourcesDictionary.xaml" />
</UserControl.Resources>
<Grid Width="143" Height="28">
<Image Source="pack://application:,,,/resources/groundtile.png" Stretch="Fill" />
<Border Margin="3" Padding="4,0,4,2" BorderThickness="2" BorderBrush="{Binding BorderColor, Converter={StaticResource ColorToSolidColorBrushConverter}}">
<Border.Background>
<SolidColorBrush Color="{Binding BackgroundColor}" />
</Border.Background>
<TextBlock TextAlignment="Center" Text="Test Item Preview" Style="{StaticResource PathOfExileFont}">
<TextBlock.Foreground>
<SolidColorBrush Color="{Binding TextColor}" />
</TextBlock.Foreground>
</TextBlock>
</Border>
</Grid>
</UserControl>

View File

@ -0,0 +1,74 @@
using System.Windows;
using System.Windows.Media;
namespace Filtration.UserControls
{
public partial class ItemPreviewControl
{
public ItemPreviewControl()
{
InitializeComponent();
// ReSharper disable once PossibleNullReferenceException
(Content as FrameworkElement).DataContext = this;
}
public static readonly DependencyProperty TextColorProperty = DependencyProperty.Register(
"TextColor",
typeof (Color),
typeof(ItemPreviewControl),
new FrameworkPropertyMetadata()
);
public static readonly DependencyProperty BackgroundColorProperty = DependencyProperty.Register(
"BackgroundColor",
typeof(Color),
typeof(ItemPreviewControl),
new FrameworkPropertyMetadata()
);
public static readonly DependencyProperty BorderColorProperty = DependencyProperty.Register(
"BorderColor",
typeof(Color),
typeof(ItemPreviewControl),
new FrameworkPropertyMetadata()
);
public Color TextColor
{
get { return (Color) GetValue(TextColorProperty); }
set { SetValue(TextColorProperty, value); }
}
public Color BackgroundColor
{
get { return (Color)GetValue(BackgroundColorProperty); }
set { SetValue(BackgroundColorProperty, value); }
}
public Color BorderColor
{
get { return (Color)GetValue(BorderColorProperty); }
set { SetValue(BorderColorProperty, value); }
}
//private static void OnItemPreviewControlPropertyChanged(DependencyObject source,
// DependencyPropertyChangedEventArgs e)
//{
// var control = source as ItemPreviewControl;
// if (control == null) return;
// control.OnPropertyChanged("TextColor");
// control.OnPropertyChanged("BackgroundColor");
// control.OnPropertyChanged("BorderColor");
//}
//public event PropertyChangedEventHandler PropertyChanged;
//[NotifyPropertyChangedInvocator]
//protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
//{
// var handler = PropertyChanged;
// if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
//}
}
}

View File

@ -31,25 +31,28 @@ namespace Filtration.ViewModels
if (initialiseFromBlock.BlockItems.Count(b => b.GetType() == typeof (TextColorBlockItem)) > 0)
{
_replaceColorsParameterSet.ReplaceTextColor = true;
_replaceColorsParameterSet.OldTextColor =
((TextColorBlockItem)
var existingBlockColor = ((TextColorBlockItem)
initialiseFromBlock.BlockItems.First(b => b.GetType() == typeof (TextColorBlockItem))).Color;
_replaceColorsParameterSet.OldTextColor = existingBlockColor;
_replaceColorsParameterSet.NewTextColor = existingBlockColor;
}
if (initialiseFromBlock.BlockItems.Count(b => b.GetType() == typeof(BackgroundColorBlockItem)) > 0)
{
_replaceColorsParameterSet.ReplaceBackgroundColor = true;
_replaceColorsParameterSet.OldBackgroundColor =
((BackgroundColorBlockItem)
var existingBlockColor = ((BackgroundColorBlockItem)
initialiseFromBlock.BlockItems.First(b => b.GetType() == typeof(BackgroundColorBlockItem))).Color;
_replaceColorsParameterSet.OldBackgroundColor = existingBlockColor;
_replaceColorsParameterSet.NewBackgroundColor = existingBlockColor;
}
if (initialiseFromBlock.BlockItems.Count(b => b.GetType() == typeof(BorderColorBlockItem)) > 0)
{
_replaceColorsParameterSet.ReplaceBorderColor = true;
_replaceColorsParameterSet.OldBorderColor =
((BorderColorBlockItem)
var existingBlockColor = ((BorderColorBlockItem)
initialiseFromBlock.BlockItems.First(b => b.GetType() == typeof(BorderColorBlockItem))).Color;
_replaceColorsParameterSet.OldBorderColor = existingBlockColor;
_replaceColorsParameterSet.NewBorderColor = existingBlockColor;
}
_lootFilterScript = lootFilterScript;

View File

@ -15,7 +15,7 @@
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="LootFilterBlockViewDictionary.xaml" />
<ResourceDictionary Source="SharedResourcesDictionary.xaml" />
<ResourceDictionary>
<CollectionViewSource x:Key="AudioVisualBlockItemsViewSource" Source="{Binding AudioVisualBlockItems}">
<CollectionViewSource.SortDescriptions>

View File

@ -10,14 +10,13 @@
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">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="LootFilterBlockViewDictionary.xaml" />
<ResourceDictionary Source="SharedResourcesDictionary.xaml" />
<ResourceDictionary>
<views:BindingProxy x:Key="proxy" Data="{Binding}" />
</ResourceDictionary>
@ -74,9 +73,6 @@
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type blockItemBaseTypes:BlockItemBase}">
<Border BorderBrush="Black" CornerRadius="4" Margin="0,2,2,2" BorderThickness="1" Background="{Binding SummaryBackgroundColor, Converter={StaticResource ColorToSolidColorBrushConverter}}">
<TextBlock Text="{Binding SummaryText}" Margin="5,1,5,1" Foreground="{Binding SummaryTextColor, Converter={StaticResource ColorToSolidColorBrushConverter}}" />
@ -89,7 +85,6 @@
</Border>
</Button>
</DataTemplate>
<!--</ItemsControl.ItemTemplate>-->
</ItemsControl.Resources>
</ItemsControl>
</StackPanel>
@ -104,19 +99,7 @@
x:Name="ItemPreviewButton"
IsChecked="{Binding DisplaySettingsPopupOpen, Mode=OneWayToSource}"
ToolTip="Click here to change color and font settings" Cursor="Hand" >
<Grid>
<Image Source="pack://application:,,,/resources/groundtile.png" Stretch="Fill" />
<Border Margin="3" Padding="4,0,4,2" BorderThickness="2" BorderBrush="{Binding DisplayBorderColor, Converter={StaticResource ColorToSolidColorBrushConverter}}">
<Border.Background>
<SolidColorBrush Color="{Binding DisplayBackgroundColor}" />
</Border.Background>
<TextBlock TextAlignment="Center" Text="Test Item Preview" Style="{StaticResource PathOfExileFont}">
<TextBlock.Foreground>
<SolidColorBrush Color="{Binding DisplayTextColor}" />
</TextBlock.Foreground>
</TextBlock>
</Border>
</Grid>
<userControls:ItemPreviewControl TextColor="{Binding DisplayTextColor}" BackgroundColor="{Binding DisplayBackgroundColor}" BorderColor="{Binding DisplayBorderColor}" />
</ToggleButton>
</WrapPanel>

View File

@ -6,6 +6,7 @@
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:viewModels="clr-namespace:Filtration.ViewModels"
xmlns:userControls="clr-namespace:Filtration.UserControls"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=viewModels:ReplaceColorsViewModel}"
ShowMaxRestoreButton="False"
@ -15,7 +16,7 @@
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="LootFilterBlockViewDictionary.xaml" />
<ResourceDictionary Source="SharedResourcesDictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
@ -56,19 +57,7 @@
<TextBlock Grid.Row="5" Grid.Column="2" VerticalAlignment="Center">New Border Color</TextBlock>
<xctk:ColorPicker Grid.Row="5" Grid.Column="4" SelectedColor="{Binding NewBorderColor}" />
<Grid Grid.Row="6" Grid.Column="4">
<Image Source="pack://application:,,,/resources/groundtile.png" Stretch="Fill" />
<Border Padding="4,2,4,2" BorderThickness="2" BorderBrush="{Binding DisplayBorderColor, Converter={StaticResource ColorToSolidColorBrushConverter}}">
<Border.Background>
<SolidColorBrush Color="{Binding DisplayBackgroundColor}" />
</Border.Background>
<TextBlock TextAlignment="Center" Text="Test Item Preview" Style="{StaticResource PathOfExileFont}">
<TextBlock.Foreground>
<SolidColorBrush Color="{Binding DisplayTextColor}" />
</TextBlock.Foreground>
</TextBlock>
</Border>
</Grid>
<userControls:ItemPreviewControl Grid.Row="6" Grid.Column="4" TextColor="{Binding DisplayTextColor}" BackgroundColor="{Binding DisplayBackgroundColor}" BorderColor="{Binding DisplayBorderColor}" />
<TextBlock Grid.Row="6" Grid.Column="2" VerticalAlignment="Center">Preview</TextBlock>
<Button Grid.Row="7" Grid.Column="4" Command="{Binding ReplaceColorsCommand}">Replace Colors</Button>
</Grid>