Add a temporary block type for new beam feature

This commit is contained in:
azakhi 2018-08-22 13:15:50 +03:00
parent add7514ce7
commit 2a7df9a1ca
7 changed files with 82 additions and 7 deletions

View File

@ -0,0 +1,21 @@
using System.Windows.Media;
using Filtration.ObjectModel.BlockItemBaseTypes;
namespace Filtration.ObjectModel.BlockItemTypes
{
public class BeamBlockItem : ColorBlockItem
{
public BeamBlockItem()
{
}
public BeamBlockItem(Color color) : base(color)
{
}
public override string PrefixText => "BeamColor";
public override int MaximumAllowed => 1;
public override string DisplayHeading => "Beam Color";
public override int SortOrder => 29;
}
}

View File

@ -60,6 +60,7 @@
<Compile Include="BlockItemBaseTypes\StringListBlockItem.cs" /> <Compile Include="BlockItemBaseTypes\StringListBlockItem.cs" />
<Compile Include="BlockItemTypes\BackgroundColorBlockItem.cs" /> <Compile Include="BlockItemTypes\BackgroundColorBlockItem.cs" />
<Compile Include="BlockItemTypes\BaseTypeBlockItem.cs" /> <Compile Include="BlockItemTypes\BaseTypeBlockItem.cs" />
<Compile Include="BlockItemTypes\BeamBlockItem.cs" />
<Compile Include="BlockItemTypes\BorderColorBlockItem.cs" /> <Compile Include="BlockItemTypes\BorderColorBlockItem.cs" />
<Compile Include="BlockItemTypes\ClassBlockItem.cs" /> <Compile Include="BlockItemTypes\ClassBlockItem.cs" />
<Compile Include="BlockItemTypes\DisableDropSoundBlockItem.cs" /> <Compile Include="BlockItemTypes\DisableDropSoundBlockItem.cs" />

View File

@ -24,6 +24,7 @@ namespace Filtration.ObjectModel
Color DisplayBorderColor { get; } Color DisplayBorderColor { get; }
double DisplayFontSize { get; } double DisplayFontSize { get; }
string DisplayIcon { get; } string DisplayIcon { get; }
Color DisplayBeamColor { get; }
bool HasBlockItemOfType<T>(); bool HasBlockItemOfType<T>();
bool HasBlockGroupInParentHierarchy(ItemFilterBlockGroup targetBlockGroup, ItemFilterBlockGroup startingBlockGroup); bool HasBlockGroupInParentHierarchy(ItemFilterBlockGroup targetBlockGroup, ItemFilterBlockGroup startingBlockGroup);
} }
@ -270,5 +271,14 @@ namespace Filtration.ObjectModel
return (displayIcon != null) ? displayIcon.Value : ""; return (displayIcon != null) ? displayIcon.Value : "";
} }
} }
public Color DisplayBeamColor
{
get
{
var beamBlockItem = BlockItems.OfType<BeamBlockItem>().FirstOrDefault();
return beamBlockItem?.Color ?? new Color { A = 0, R = 0, G = 0, B = 0 };
}
}
} }
} }

View File

@ -907,6 +907,24 @@ namespace Filtration.Parser.Tests.Services
Assert.AreEqual(1, result.BlockItems.Count(b => b is IconBlockItem)); Assert.AreEqual(1, result.BlockItems.Count(b => b is IconBlockItem));
var blockItem = result.BlockItems.OfType<IconBlockItem>().First(); var blockItem = result.BlockItems.OfType<IconBlockItem>().First();
Assert.AreEqual("Icon1", blockItem.Value); Assert.AreEqual("Icon1", blockItem.Value);
}
[Test]
public void TranslateStringToItemFilterBlock_BeamColor_ReturnsCorrectObject()
{
// Arrange
var inputString = "Show" + Environment.NewLine +
" BeamColor 255 20 100";
// Act
var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript);
// Assert
Assert.AreEqual(1, result.BlockItems.Count(b => b is BeamBlockItem));
var blockItem = result.BlockItems.OfType<BeamBlockItem>().First();
Assert.AreEqual(255, blockItem.Color.R);
Assert.AreEqual(20, blockItem.Color.G);
Assert.AreEqual(100, blockItem.Color.B);
} }
[Test] [Test]
@ -943,7 +961,8 @@ namespace Filtration.Parser.Tests.Services
" SetFontSize 50" + Environment.NewLine + " SetFontSize 50" + Environment.NewLine +
" PlayAlertSound 3" + Environment.NewLine + " PlayAlertSound 3" + Environment.NewLine +
" DisableDropSound False" + Environment.NewLine + " DisableDropSound False" + Environment.NewLine +
" Icon Icon2" + Environment.NewLine; " Icon Icon2" + Environment.NewLine +
" BeamColor 255 100 5" + Environment.NewLine;
// Act // Act
var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript);
@ -1051,6 +1070,11 @@ namespace Filtration.Parser.Tests.Services
var iconBlockItem = result.BlockItems.OfType<IconBlockItem>().First(); var iconBlockItem = result.BlockItems.OfType<IconBlockItem>().First();
Assert.AreEqual("Icon2", iconBlockItem.Value); Assert.AreEqual("Icon2", iconBlockItem.Value);
var beamBlockItem = result.BlockItems.OfType<BeamBlockItem>().First();
Assert.AreEqual(255, beamBlockItem.Color.R);
Assert.AreEqual(100, beamBlockItem.Color.G);
Assert.AreEqual(5, beamBlockItem.Color.B);
} }
[Test] [Test]
@ -1877,6 +1901,7 @@ namespace Filtration.Parser.Tests.Services
Assert.AreEqual(expectedResult, result); Assert.AreEqual(expectedResult, result);
} }
[Ignore("Ignore until the new block type is fully implemented")]
[Test] [Test]
public void TranslateItemFilterBlockToString_DropIcon_ReturnsCorrectString() public void TranslateItemFilterBlockToString_DropIcon_ReturnsCorrectString()
{ {
@ -1924,8 +1949,9 @@ namespace Filtration.Parser.Tests.Services
" SetBorderColor 255 1 254" + Environment.NewLine + " SetBorderColor 255 1 254" + Environment.NewLine +
" SetFontSize 50" + Environment.NewLine + " SetFontSize 50" + Environment.NewLine +
" PlayAlertSound 6 90" + Environment.NewLine + " PlayAlertSound 6 90" + Environment.NewLine +
" DisableDropSound True" + Environment.NewLine + " DisableDropSound True";/* + Environment.NewLine +
" Icon Icon4"; " Icon Icon4";
" BeamColor 120 130 140";*/
_testUtility.TestBlock.BlockItems.Add(new ActionBlockItem(BlockAction.Show)); _testUtility.TestBlock.BlockItems.Add(new ActionBlockItem(BlockAction.Show));
_testUtility.TestBlock.BlockItems.Add(new IdentifiedBlockItem(true)); _testUtility.TestBlock.BlockItems.Add(new IdentifiedBlockItem(true));
@ -1970,6 +1996,7 @@ namespace Filtration.Parser.Tests.Services
_testUtility.TestBlock.BlockItems.Add(new ElderMapBlockItem(true)); _testUtility.TestBlock.BlockItems.Add(new ElderMapBlockItem(true));
_testUtility.TestBlock.BlockItems.Add(new DisableDropSoundBlockItem(true)); _testUtility.TestBlock.BlockItems.Add(new DisableDropSoundBlockItem(true));
_testUtility.TestBlock.BlockItems.Add(new IconBlockItem("Icon4")); _testUtility.TestBlock.BlockItems.Add(new IconBlockItem("Icon4"));
_testUtility.TestBlock.BlockItems.Add(new BeamBlockItem(new Color { A = 255, R = 120, G = 130, B = 140 }));
// Act // Act
var result = _testUtility.Translator.TranslateItemFilterBlockToString(_testUtility.TestBlock); var result = _testUtility.Translator.TranslateItemFilterBlockToString(_testUtility.TestBlock);

View File

@ -314,6 +314,14 @@ namespace Filtration.Parser.Services
} }
break; break;
} }
case "BeamColor":
{
// Only ever use the last BeamColor item encountered as multiples aren't valid.
RemoveExistingBlockItemsOfType<BeamBlockItem>(block);
AddColorItemToBlockItems<BeamBlockItem>(block, trimmedLine);
break;
}
} }
} }
@ -587,8 +595,8 @@ namespace Filtration.Parser.Services
// ReSharper disable once LoopCanBeConvertedToQuery // ReSharper disable once LoopCanBeConvertedToQuery
foreach (var blockItem in block.BlockItems.Where(b => b.GetType() != typeof(ActionBlockItem)).OrderBy(b => b.SortOrder)) foreach (var blockItem in block.BlockItems.Where(b => b.GetType() != typeof(ActionBlockItem)).OrderBy(b => b.SortOrder))
{ {
// Do not save temporary block until the new feature is fully implemented // Do not save temporary blocks until the new features are fully implemented
if (blockItem is IconBlockItem) if (blockItem is IconBlockItem || blockItem is BeamBlockItem)
{ {
continue; continue;
} }

View File

@ -175,7 +175,8 @@ namespace Filtration.ViewModels
typeof (SoundBlockItem), typeof (SoundBlockItem),
typeof (PositionalSoundBlockItem), typeof (PositionalSoundBlockItem),
typeof (DisableDropSoundBlockItem), typeof (DisableDropSoundBlockItem),
typeof (IconBlockItem) typeof (IconBlockItem),
typeof (BeamBlockItem)
}; };
public bool BlockEnabled public bool BlockEnabled
@ -216,6 +217,7 @@ namespace Filtration.ViewModels
public Color DisplayBorderColor => Block.DisplayBorderColor; public Color DisplayBorderColor => Block.DisplayBorderColor;
public double DisplayFontSize => Block.DisplayFontSize/1.8; public double DisplayFontSize => Block.DisplayFontSize/1.8;
public string DisplayIcon => Block.DisplayIcon; public string DisplayIcon => Block.DisplayIcon;
public Color DisplayBeamColor => Block.DisplayBeamColor;
public bool HasSound => Block.HasBlockItemOfType<SoundBlockItem>(); public bool HasSound => Block.HasBlockItemOfType<SoundBlockItem>();
public bool HasPositionalSound => Block.HasBlockItemOfType<PositionalSoundBlockItem>(); public bool HasPositionalSound => Block.HasBlockItemOfType<PositionalSoundBlockItem>();
@ -440,6 +442,7 @@ namespace Filtration.ViewModels
RaisePropertyChanged(nameof(DisplayBorderColor)); RaisePropertyChanged(nameof(DisplayBorderColor));
RaisePropertyChanged(nameof(DisplayFontSize)); RaisePropertyChanged(nameof(DisplayFontSize));
RaisePropertyChanged(nameof(DisplayIcon)); RaisePropertyChanged(nameof(DisplayIcon));
RaisePropertyChanged(nameof(DisplayBeamColor));
RaisePropertyChanged(nameof(HasSound)); RaisePropertyChanged(nameof(HasSound));
} }

View File

@ -131,7 +131,12 @@
<!-- Item Preview Box --> <!-- Item Preview Box -->
<WrapPanel Grid.Row="0" Grid.Column="2" VerticalAlignment="Center"> <WrapPanel Grid.Row="0" Grid.Column="2" VerticalAlignment="Center">
<Image Source="{Binding DisplayIcon, Converter={StaticResource DropIconConverter}, Mode=OneWay}" Width="30" Height="30" /> <Image Source="{Binding DisplayIcon, Converter={StaticResource DropIconConverter}, Mode=OneWay}" Width="30" Height="30" Margin="0,0,10,0" />
<Line Y2="41" StrokeThickness="2" Stroke="{Binding DisplayBeamColor, Converter={StaticResource ColorToSolidColorBrushConverter}, Mode=OneWay}" Margin="0,2,10,0" >
<Line.Effect>
<DropShadowEffect BlurRadius="5" ShadowDepth="0" Color="{Binding DisplayBeamColor, Mode=OneWay}" Direction="0"/>
</Line.Effect>
</Line>
<Button Command="{Binding PlaySoundCommand}" <Button Command="{Binding PlaySoundCommand}"
Width="25" Width="25"
Height="25" Height="25"