Add support for PlayAlertSoundPositional.

This commit is contained in:
GlenCFL 2017-12-07 08:20:18 -05:00
parent 010e0dda31
commit 8bf3527b69
6 changed files with 73 additions and 17 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
## files generated by popular Visual Studio add-ons. ## files generated by popular Visual Studio add-ons.
# User-specific files # User-specific files
/.vs/
*.suo *.suo
*.user *.user
*.sln.docstates *.sln.docstates

View File

@ -2,21 +2,21 @@
namespace Filtration.ObjectModel.BlockItemTypes namespace Filtration.ObjectModel.BlockItemTypes
{ {
public class PositionalSoundBlockItem : DualIntegerBlockItem public class PositionalSoundBlockItem : StrIntBlockItem
{ {
public PositionalSoundBlockItem() public PositionalSoundBlockItem()
{ {
Value = 1; Value = "1";
SecondValue = 79; SecondValue = 79;
} }
public PositionalSoundBlockItem(int value, int secondValue) : base(value, secondValue) public PositionalSoundBlockItem(string value, int secondValue) : base(value, secondValue)
{ {
} }
public override string PrefixText => "PlayAlertSoundPositional"; public override string PrefixText => "PlayAlertSoundPositional";
public override int MaximumAllowed => 1; public override int MaximumAllowed => 1;
public override string DisplayHeading => "Play Positional Alert Sound"; public override string DisplayHeading => "Play Positional Alert Sound";
public override int SortOrder => 18; public override int SortOrder => 22;
} }
} }

View File

@ -224,24 +224,42 @@ namespace Filtration.Parser.Services
RemoveExistingBlockItemsOfType<PositionalSoundBlockItem>(block); RemoveExistingBlockItemsOfType<PositionalSoundBlockItem>(block);
var match = Regex.Match(trimmedLine, @"\S+\s+(\S+)\s+(\d+)?"); var match = Regex.Match(trimmedLine, @"\S+\s+(\S+)\s+(\d+)?");
if (match.Success) if (match.Success)
{ {
string firstValue;
int secondValue;
if (match.Groups.Count == 2) if (match.Groups.Count == 2)
{
firstValue = match.Groups[1].Value;
secondValue = 79;
}
else if (match.Groups.Count == 3)
{
firstValue = match.Groups[1].Value;
secondValue = Convert.ToInt16(match.Groups[2].Value);
}
else
{
break;
}
if (lineOption == "PlayAlertSound")
{ {
var blockItemValue = new SoundBlockItem var blockItemValue = new SoundBlockItem
{ {
Value = match.Groups[1].Value, Value = firstValue,
SecondValue = 79 SecondValue = secondValue
}; };
block.BlockItems.Add(blockItemValue); block.BlockItems.Add(blockItemValue);
} }
else if(match.Groups.Count == 3) else
{ {
var blockItemValue = new SoundBlockItem var blockItemValue = new PositionalSoundBlockItem
{ {
Value = match.Groups[1].Value, Value = firstValue,
SecondValue = Int16.Parse(match.Groups[2].Value) SecondValue = secondValue
}; };
block.BlockItems.Add(blockItemValue); block.BlockItems.Add(blockItemValue);
} }

View File

@ -115,6 +115,17 @@
<xctk:ShortUpDown Value="{Binding Path=SecondValue}" Minimum="1" Maximum="300" HorizontalAlignment="Right" ToolTip="Volume"/> <xctk:ShortUpDown Value="{Binding Path=SecondValue}" Minimum="1" Maximum="300" HorizontalAlignment="Right" ToolTip="Volume"/>
</WrapPanel> </WrapPanel>
</DataTemplate> </DataTemplate>
<!-- Positional Sound Template -->
<DataTemplate DataType="{x:Type blockItemTypes:PositionalSoundBlockItem}">
<WrapPanel HorizontalAlignment="Left">
<Button Command="{Binding Path=DataContext.PlayPositionalSoundCommand, RelativeSource={RelativeSource AncestorType={x:Type views:ItemFilterBlockView}}}" Width="20" Height="20" Background="Transparent" BorderBrush="Transparent">
<Image Source="/Filtration;component/Resources/Icons/speaker_icon.png" VerticalAlignment="Center" HorizontalAlignment="Center" />
</Button>
<ComboBox ItemsSource="{Binding ElementName=BlockItemContentControl, Path=DataContext.SoundsAvailable}" SelectedValue="{Binding Value}" Style="{StaticResource MetroComboBox}" />
<xctk:ShortUpDown Value="{Binding Path=SecondValue}" Minimum="1" Maximum="300" HorizontalAlignment="Right" ToolTip="Volume"/>
</WrapPanel>
</DataTemplate>
</ContentControl.Resources> </ContentControl.Resources>
</ContentControl> </ContentControl>
</Grid> </Grid>

View File

@ -62,6 +62,7 @@ namespace Filtration.ViewModels
RemoveFilterBlockItemCommand = new RelayCommand<IItemFilterBlockItem>(OnRemoveFilterBlockItemCommand); RemoveFilterBlockItemCommand = new RelayCommand<IItemFilterBlockItem>(OnRemoveFilterBlockItemCommand);
SwitchBlockItemsViewCommand = new RelayCommand(OnSwitchBlockItemsViewCommand); SwitchBlockItemsViewCommand = new RelayCommand(OnSwitchBlockItemsViewCommand);
PlaySoundCommand = new RelayCommand(OnPlaySoundCommand, () => HasSound); PlaySoundCommand = new RelayCommand(OnPlaySoundCommand, () => HasSound);
PlayPositionalSoundCommand = new RelayCommand(OnPlayPositionalSoundCommand, () => HasPositionalSound);
} }
public event EventHandler BlockBecameDirty; public event EventHandler BlockBecameDirty;
@ -100,6 +101,7 @@ namespace Filtration.ViewModels
public RelayCommand<Type> AddFilterBlockItemCommand { get; private set; } public RelayCommand<Type> AddFilterBlockItemCommand { get; private set; }
public RelayCommand<IItemFilterBlockItem> RemoveFilterBlockItemCommand { get; private set; } public RelayCommand<IItemFilterBlockItem> RemoveFilterBlockItemCommand { get; private set; }
public RelayCommand PlaySoundCommand { get; private set; } public RelayCommand PlaySoundCommand { get; private set; }
public RelayCommand PlayPositionalSoundCommand { get; private set; }
public RelayCommand SwitchBlockItemsViewCommand { get; private set; } public RelayCommand SwitchBlockItemsViewCommand { get; private set; }
public IItemFilterBlock Block { get; private set; } public IItemFilterBlock Block { get; private set; }
@ -243,9 +245,9 @@ 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 bool HasSound => Block.HasBlockItemOfType<SoundBlockItem>() || public bool HasSound => Block.HasBlockItemOfType<SoundBlockItem>();
Block.HasBlockItemOfType<PositionalSoundBlockItem>(); public bool HasPositionalSound => Block.HasBlockItemOfType<PositionalSoundBlockItem>();
public bool HasAudioVisualBlockItems => AudioVisualBlockItems.Any(); public bool HasAudioVisualBlockItems => AudioVisualBlockItems.Any();
private void OnSwitchBlockItemsViewCommand() private void OnSwitchBlockItemsViewCommand()
@ -430,7 +432,19 @@ namespace Filtration.ViewModels
private void OnPlayPositionalSoundCommand() private void OnPlayPositionalSoundCommand()
{ {
var identifier = BlockItems.OfType<PositionalSoundBlockItem>().First().Value;
var prefix = "Resources/AlertSounds/";
var filePart = ComputeFilePartFromID(identifier);
if (filePart == "")
{
return;
}
else
{
_mediaPlayer.Open(new Uri(prefix + filePart, UriKind.Relative));
_mediaPlayer.Play();
}
} }
private void OnBlockItemChanged(object sender, EventArgs e) private void OnBlockItemChanged(object sender, EventArgs e)

View File

@ -129,7 +129,7 @@
<!-- Item Preview Box --> <!-- Item Preview Box -->
<WrapPanel Grid.Row="0" Grid.Column="2" VerticalAlignment="Center"> <WrapPanel Grid.Row="0" Grid.Column="2" VerticalAlignment="Center">
<Button Command="{Binding PlaySoundCommand}" <Button Command="{Binding PlaySoundCommand}"
Width="25" Width="25"
Height="25" Height="25"
VerticalAlignment="Center" VerticalAlignment="Center"
@ -141,6 +141,18 @@
ToolTip="Click to preview drop sound"> ToolTip="Click to preview drop sound">
<Image Source="/Filtration;component/Resources/Icons/speaker_icon.png" VerticalAlignment="Center" HorizontalAlignment="Center" /> <Image Source="/Filtration;component/Resources/Icons/speaker_icon.png" VerticalAlignment="Center" HorizontalAlignment="Center" />
</Button> </Button>
<Button Command="{Binding PlayPositionalSoundCommand}"
Width="25"
Height="25"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Margin="0,0,3,0"
Visibility="{Binding HasPositionalSound, Converter={StaticResource BooleanVisibilityConverter}}"
Background="Transparent"
BorderBrush="Transparent"
ToolTip="Click to preview drop sound">
<Image Source="/Filtration;component/Resources/Icons/speaker_icon.png" VerticalAlignment="Center" HorizontalAlignment="Center" />
</Button>
<ToggleButton Margin="0,2,2,2" <ToggleButton Margin="0,2,2,2"
Style="{StaticResource ChromelessToggleButton}" Style="{StaticResource ChromelessToggleButton}"
x:Name="ItemPreviewButton" x:Name="ItemPreviewButton"