Merge pull request #76 from GlenCFL/transparency_rework

Make the minimap icons transparent. Take 2.
This commit is contained in:
Ben Wallis 2018-09-07 08:13:27 +01:00 committed by GitHub
commit e15efe4e15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 151 additions and 173 deletions

View File

@ -2,16 +2,22 @@
namespace Filtration.ObjectModel.Enums namespace Filtration.ObjectModel.Enums
{ {
public enum IconColor /// <summary>
/// Each of the colors supported by the MinimapIcon block rule.
/// </summary>
/// <remarks>
/// The ordering here should match the ordering of the colors within the source image.
/// </remarks>
public enum IconColor
{ {
[Description("Red")] [Description("Blue")]
Blue,
[Description("Green")]
Green,
[Description("Brown")]
Brown,
[Description("Red")]
Red, Red,
[Description("Green")]
Green,
[Description("Blue")]
Blue,
[Description("Brown")]
Brown,
[Description("White")] [Description("White")]
White, White,
[Description("Yellow")] [Description("Yellow")]

View File

@ -2,7 +2,13 @@
namespace Filtration.ObjectModel.Enums namespace Filtration.ObjectModel.Enums
{ {
public enum IconShape /// <summary>
/// Each of the shapes supported by the MinimapIcon block rule.
/// </summary>
/// <remarks>
/// The ordering here should match the ordering of the shapes within the source image.
/// </remarks>
public enum IconShape
{ {
[Description("Circle")] [Description("Circle")]
Circle, Circle,

View File

@ -2,7 +2,13 @@
namespace Filtration.ObjectModel.Enums namespace Filtration.ObjectModel.Enums
{ {
public enum IconSize /// <summary>
/// Each of the sizes supported by the MinimapIcon block rule.
/// </summary>
/// <remarks>
/// The ordering here should match the ordering of the sizes within the source image.
/// </remarks>
public enum IconSize
{ {
[Description("Largest")] [Description("Largest")]
Largest, Largest,

View File

@ -1,37 +0,0 @@
using Filtration.ObjectModel.Enums;
using System;
using System.Globalization;
using System.Windows.Data;
namespace Filtration.Converters
{
internal class IconShapeToSourceConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var iconShape = (IconShape)(int)value;
switch (iconShape)
{
case IconShape.Circle:
return "/Filtration;component/Resources/DropIcons/Circle.png";
case IconShape.Diamond:
return "/Filtration;component/Resources/DropIcons/Diamond.png";
case IconShape.Hexagon:
return "/Filtration;component/Resources/DropIcons/Hexagon.png";
case IconShape.Square:
return "/Filtration;component/Resources/DropIcons/Square.png";
case IconShape.Star:
return "/Filtration;component/Resources/DropIcons/Star.png";
case IconShape.Triangle:
return "/Filtration;component/Resources/DropIcons/Triangle.png";
}
return "/Filtration;component/Resources/DropIcons/NoIcon.png";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media.Imaging;
using Filtration.ObjectModel.Enums;
namespace Filtration.Converters
{
internal class MinimapIconToCroppedBitmapConverter : IMultiValueConverter
{
private static readonly int cellHeight = 64;
private static readonly int cellWidth = 64;
private static readonly int gridWidth = 14;
private static readonly int startColumn = 4;
private static readonly int startRow = 3;
private static readonly int emptyColumn = 2;
private static readonly int emptyRow = 11;
private static readonly int colorCount = 6;
private static readonly int shapeCount = 6;
private static readonly int sizeCount = 3;
private static readonly Uri uri;
private static readonly CroppedBitmap empty;
private static readonly List<CroppedBitmap> bitmaps;
static MinimapIconToCroppedBitmapConverter()
{
uri = new Uri("pack://application:,,,/Filtration;component/Resources/minimap_icons.png", UriKind.Absolute);
var sourceImage = new BitmapImage(uri);
var emptyRect = new Int32Rect
{
Width = cellWidth,
Height = cellHeight,
X = emptyColumn * cellWidth,
Y = emptyRow * cellHeight
};
empty = new CroppedBitmap(new BitmapImage(uri), emptyRect);
bitmaps = new List<CroppedBitmap>(shapeCount * colorCount * sizeCount);
var row = startRow;
var column = startColumn;
for (var i = 0; i < shapeCount; i++) {
for (var j = 0; j < colorCount; j++) {
for (var k = 0; k < sizeCount; k++) {
if (column == gridWidth) {
column = 0;
row++;
}
var bitmapRect = new Int32Rect
{
Width = cellWidth,
Height = cellHeight,
X = column * cellWidth,
Y = row * cellHeight
};
bitmaps.Add(new CroppedBitmap(sourceImage, bitmapRect));
column++;
}
}
}
}
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values[0] == DependencyProperty.UnsetValue ||
values[1] == DependencyProperty.UnsetValue ||
values[2] == DependencyProperty.UnsetValue)
{
return empty;
}
var iconSize = (int)(values[0]);
var iconColor = (int)(values[1]);
var iconShape = (int)(values[2]);
if (!Enum.IsDefined(typeof(IconSize), iconSize) ||
!Enum.IsDefined(typeof(IconColor), iconColor) ||
!Enum.IsDefined(typeof(IconShape), iconShape))
{
return empty;
}
var shapeOffset = iconShape * (sizeCount * colorCount);
var colorOffset = iconColor * sizeCount;
var iconIndex = shapeOffset + colorOffset + iconSize;
if (iconIndex >= bitmaps.Count)
{
return empty;
}
else
{
return bitmaps[iconIndex];
}
}
public object[] ConvertBack(object value, Type[] targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@ -1,38 +0,0 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace Filtration.Converters
{
internal class SizeColorToRectConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values[0] == DependencyProperty.UnsetValue ||
values[1] == DependencyProperty.UnsetValue)
return new Rect(0, 0, 0, 0);
var size = (int)(values[0]);
var color = (int)(values[1]);
if (size < 0 || color < 0)
return new Rect(0, 0, 0, 0);
var cropArea = new Rect
{
Width = 64,
Height = 64,
X = 0 + size * 64,
Y = 0 + color * 64
};
return cropArea;
}
public object[] ConvertBack(object value, Type[] targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@ -167,9 +167,8 @@
<Compile Include="Converters\BooleanToBlockActionInverseConverter.cs" /> <Compile Include="Converters\BooleanToBlockActionInverseConverter.cs" />
<Compile Include="Converters\BooleanToBlockActionConverter.cs" /> <Compile Include="Converters\BooleanToBlockActionConverter.cs" />
<Compile Include="Converters\BlockItemToRemoveEnabledVisibilityConverter.cs" /> <Compile Include="Converters\BlockItemToRemoveEnabledVisibilityConverter.cs" />
<Compile Include="Converters\SizeColorToRectConverter.cs" /> <Compile Include="Converters\MinimapIconToCroppedBitmapConverter.cs" />
<Compile Include="Converters\HashSignRemovalConverter.cs" /> <Compile Include="Converters\HashSignRemovalConverter.cs" />
<Compile Include="Converters\IconShapeToSourceConverter.cs" />
<Compile Include="Converters\ItemRarityConverter.cs" /> <Compile Include="Converters\ItemRarityConverter.cs" />
<Compile Include="Converters\TreeViewMarginConverter.cs" /> <Compile Include="Converters\TreeViewMarginConverter.cs" />
<Compile Include="Models\UpdateData.cs" /> <Compile Include="Models\UpdateData.cs" />
@ -190,9 +189,6 @@
<Compile Include="UserControls\EditableListBoxControl.xaml.cs"> <Compile Include="UserControls\EditableListBoxControl.xaml.cs">
<DependentUpon>EditableListBoxControl.xaml</DependentUpon> <DependentUpon>EditableListBoxControl.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="UserControls\ImageComboBoxControl.xaml.cs">
<DependentUpon>ImageComboBoxControl.xaml</DependentUpon>
</Compile>
<Compile Include="UserControls\ItemPreviewControl.xaml.cs"> <Compile Include="UserControls\ItemPreviewControl.xaml.cs">
<DependentUpon>ItemPreviewControl.xaml</DependentUpon> <DependentUpon>ItemPreviewControl.xaml</DependentUpon>
</Compile> </Compile>
@ -233,10 +229,6 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="UserControls\ImageComboBoxControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserControls\ThemeComponentSelectionControl.xaml"> <Page Include="UserControls\ThemeComponentSelectionControl.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
@ -545,13 +537,7 @@
</None> </None>
<Resource Include="Resources\Icons\redo_icon.png" /> <Resource Include="Resources\Icons\redo_icon.png" />
<Resource Include="Resources\Icons\undo_icon.png" /> <Resource Include="Resources\Icons\undo_icon.png" />
<Resource Include="Resources\DropIcons\NoIcon.png" /> <Resource Include="Resources\minimap_icons.png" />
<Resource Include="Resources\DropIcons\Circle.png" />
<Resource Include="Resources\DropIcons\Diamond.png" />
<Resource Include="Resources\DropIcons\Hexagon.png" />
<Resource Include="Resources\DropIcons\Square.png" />
<Resource Include="Resources\DropIcons\Star.png" />
<Resource Include="Resources\DropIcons\Triangle.png" />
<Content Include="Resources\ItemBaseTypes.txt" /> <Content Include="Resources\ItemBaseTypes.txt" />
<Content Include="Resources\ItemClasses.txt" /> <Content Include="Resources\ItemClasses.txt" />
</ItemGroup> </ItemGroup>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 642 KiB

View File

@ -1,26 +0,0 @@
<UserControl
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:local="clr-namespace:Filtration.UserControls"
xmlns:Converters="clr-namespace:Filtration.Converters" x:Class="Filtration.UserControls.ImageComboBoxControl"
mc:Ignorable="d">
<UserControl.Resources>
<Converters:SizeColorToRectConverter x:Key="DropIconConverter"/>
</UserControl.Resources>
<Grid>
<ComboBox ItemsSource="{Binding DataContext.IconsAvailable, ElementName=BlockItemContentControl}" SelectedValue="{Binding Value}" Style="{StaticResource MetroComboBox}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image MaxWidth="20" MaxHeight="20" Source="{Binding Converter={StaticResource DropIconConverter}, Mode=OneWay}" />
<Label Content="{Binding}" VerticalAlignment="Stretch"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
</UserControl>

View File

@ -1,28 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Filtration.UserControls
{
/// <summary>
/// Interaction logic for ImageComboBoxControl.xaml
/// </summary>
public partial class ImageComboBoxControl : UserControl
{
public ImageComboBoxControl()
{
InitializeComponent();
}
}
}

View File

@ -18,8 +18,7 @@
<ResourceDictionary> <ResourceDictionary>
<views:BindingProxy x:Key="Proxy" Data="{Binding}" /> <views:BindingProxy x:Key="Proxy" Data="{Binding}" />
<converters:BlockGroupAdvancedFillColorConverter x:Key="BlockGroupAdvancedFillColorConverter" /> <converters:BlockGroupAdvancedFillColorConverter x:Key="BlockGroupAdvancedFillColorConverter" />
<converters:IconShapeToSourceConverter x:Key="IconShapeToSourceConverter"/> <converters:MinimapIconToCroppedBitmapConverter x:Key="MinimapIconToCroppedBitmapConverter"/>
<converters:SizeColorToRectConverter x:Key="SizeColorToRectConverter"/>
<Style TargetType="{x:Type ContentPresenter}" x:Key="BlockItemFadeInStyle"> <Style TargetType="{x:Type ContentPresenter}" x:Key="BlockItemFadeInStyle">
<Setter Property="LayoutTransform"> <Setter Property="LayoutTransform">
<Setter.Value> <Setter.Value>
@ -132,19 +131,15 @@
<!-- Item Preview Box --> <!-- Item Preview Box -->
<WrapPanel Grid.Row="0" Grid.Column="2" VerticalAlignment="Center"> <WrapPanel Grid.Row="0" Grid.Column="2" VerticalAlignment="Center">
<Rectangle Height="40" Width="40" Margin="0,0,10,0"> <Image Height="40" Width="40" Margin="0,0,10,0" Stretch="Fill">
<Rectangle.Fill> <Image.Source>
<ImageBrush ImageSource="{Binding DisplayIconShape, Converter={StaticResource IconShapeToSourceConverter}, Mode=OneWay}" <MultiBinding Converter="{StaticResource MinimapIconToCroppedBitmapConverter}">
ViewboxUnits="Absolute" Stretch="Fill"> <Binding Path="DisplayIconSize"/>
<ImageBrush.Viewbox> <Binding Path="DisplayIconColor"/>
<MultiBinding Converter="{StaticResource SizeColorToRectConverter}"> <Binding Path="DisplayIconShape"/>
<Binding Path="DisplayIconSize"/> </MultiBinding>
<Binding Path="DisplayIconColor"/> </Image.Source>
</MultiBinding> </Image>
</ImageBrush.Viewbox>
</ImageBrush>
</Rectangle.Fill>
</Rectangle>
<Button Command="{Binding PlaySoundCommand}" <Button Command="{Binding PlaySoundCommand}"
Width="25" Width="25"
Height="25" Height="25"