Add Custom Sound block

This commit is contained in:
azakhi 2018-08-27 22:43:01 +03:00
parent 1e9b1158bd
commit 2958d93b33
7 changed files with 154 additions and 5 deletions

View File

@ -15,7 +15,7 @@ namespace Filtration.ObjectModel.BlockItemBaseTypes
Value = value; Value = value;
} }
public override string OutputText => PrefixText + " " + Value; public override string OutputText => PrefixText + " \"" + Value + "\"";
public override string SummaryText => string.Empty; public override string SummaryText => string.Empty;
public override Color SummaryBackgroundColor => Colors.Transparent; public override Color SummaryBackgroundColor => Colors.Transparent;

View File

@ -0,0 +1,21 @@
using Filtration.ObjectModel.BlockItemBaseTypes;
namespace Filtration.ObjectModel.BlockItemTypes
{
public class CustomSoundBlockItem : StringBlockItem
{
public CustomSoundBlockItem()
{
Value = "";
}
public CustomSoundBlockItem(string value) : base(value)
{
}
public override string PrefixText => "CustomAlertSound";
public override int MaximumAllowed => 1;
public override string DisplayHeading => "Custom Alert Sound";
public override int SortOrder => 30;
}
}

View File

@ -64,6 +64,7 @@
<Compile Include="BlockItemTypes\BeamBlockItem.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\CustomSoundBlockItem.cs" />
<Compile Include="BlockItemTypes\DisableDropSoundBlockItem.cs" /> <Compile Include="BlockItemTypes\DisableDropSoundBlockItem.cs" />
<Compile Include="BlockItemTypes\ElderMapBlockItem.cs" /> <Compile Include="BlockItemTypes\ElderMapBlockItem.cs" />
<Compile Include="BlockItemTypes\GemLevelBlockItem.cs" /> <Compile Include="BlockItemTypes\GemLevelBlockItem.cs" />

View File

@ -235,6 +235,7 @@ namespace Filtration.Parser.Services
// Only ever use the last PlayAlertSound item encountered as multiples aren't valid. // Only ever use the last PlayAlertSound item encountered as multiples aren't valid.
RemoveExistingBlockItemsOfType<SoundBlockItem>(block); RemoveExistingBlockItemsOfType<SoundBlockItem>(block);
RemoveExistingBlockItemsOfType<PositionalSoundBlockItem>(block); RemoveExistingBlockItemsOfType<PositionalSoundBlockItem>(block);
RemoveExistingBlockItemsOfType<CustomSoundBlockItem>(block);
var match = Regex.Match(trimmedLine, @"\S+\s+(\S+)\s?(\d+)?\s*([#]?)(.*)"); var match = Regex.Match(trimmedLine, @"\S+\s+(\S+)\s?(\d+)?\s*([#]?)(.*)");
@ -314,7 +315,7 @@ namespace Filtration.Parser.Services
// Only ever use the last Icon item encountered as multiples aren't valid. // Only ever use the last Icon item encountered as multiples aren't valid.
RemoveExistingBlockItemsOfType<IconBlockItem>(block); RemoveExistingBlockItemsOfType<IconBlockItem>(block);
var match = Regex.Match(trimmedLine, @"\S+\s+(\S+)"); var match = Regex.Match(trimmedLine, @"\S+\s+""(\S+)""");
if (match.Success) if (match.Success)
{ {
@ -341,6 +342,25 @@ namespace Filtration.Parser.Services
block.BlockItems.Add(beamBlockItem); block.BlockItems.Add(beamBlockItem);
break; break;
} }
case "CustomAlertSound":
{
// Only ever use the last CustomSoundBlockItem item encountered as multiples aren't valid.
RemoveExistingBlockItemsOfType<CustomSoundBlockItem>(block);
RemoveExistingBlockItemsOfType<SoundBlockItem>(block);
RemoveExistingBlockItemsOfType<PositionalSoundBlockItem>(block);
var match = Regex.Match(trimmedLine, @"\S+\s+""(\S+)""");
if (match.Success)
{
var blockItemValue = new CustomSoundBlockItem
{
Value = match.Groups[1].Value
};
block.BlockItems.Add(blockItemValue);
}
break;
}
} }
} }

View File

@ -177,6 +177,25 @@
<userControls:ImageComboBoxControl/> <userControls:ImageComboBoxControl/>
</WrapPanel> </WrapPanel>
</DataTemplate> </DataTemplate>
<!-- Custom Sound Template -->
<DataTemplate DataType="{x:Type blockItemTypes:CustomSoundBlockItem}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Command="{Binding Path=DataContext.PlayCustomSoundCommand, 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 Grid.Column="1" ItemsSource="{Binding Path=DataContext.CustomSoundsAvailable, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type views:ItemFilterBlockView}}}"
SelectedValue="{Binding Value}" Style="{StaticResource MetroComboBox}"/>
<Button Grid.Column="1" Command="{Binding Path=DataContext.CustomSoundFileDialogCommand, RelativeSource={RelativeSource AncestorType={x:Type views:ItemFilterBlockView}}}"
Width="20" Height="20" Background="Transparent" BorderBrush="Transparent" Margin="0,0,30,0" VerticalAlignment="Center" HorizontalAlignment="Right">
<Image Grid.Column="1" Source="/Filtration;component/Resources/Icons/open_icon.png"/>
</Button>
</Grid>
</DataTemplate>
</ContentControl.Resources> </ContentControl.Resources>
</ContentControl> </ContentControl>
</Grid> </Grid>

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.IO;
using System.Linq; using System.Linq;
using System.Windows.Media; using System.Windows.Media;
using Filtration.ObjectModel; using Filtration.ObjectModel;
@ -10,6 +11,7 @@ using Filtration.ObjectModel.BlockItemTypes;
using Filtration.Services; using Filtration.Services;
using Filtration.Views; using Filtration.Views;
using GalaSoft.MvvmLight.CommandWpf; using GalaSoft.MvvmLight.CommandWpf;
using Microsoft.Win32;
using Xceed.Wpf.Toolkit; using Xceed.Wpf.Toolkit;
namespace Filtration.ViewModels namespace Filtration.ViewModels
@ -28,6 +30,7 @@ namespace Filtration.ViewModels
private readonly IStaticDataService _staticDataService; private readonly IStaticDataService _staticDataService;
private readonly IReplaceColorsViewModel _replaceColorsViewModel; private readonly IReplaceColorsViewModel _replaceColorsViewModel;
private readonly MediaPlayer _mediaPlayer = new MediaPlayer(); private readonly MediaPlayer _mediaPlayer = new MediaPlayer();
public static ObservableCollection<string> _customSoundsAvailable;
private bool _displaySettingsPopupOpen; private bool _displaySettingsPopupOpen;
private bool _isExpanded; private bool _isExpanded;
@ -47,6 +50,16 @@ namespace Filtration.ViewModels
SwitchBlockItemsViewCommand = new RelayCommand(OnSwitchBlockItemsViewCommand); SwitchBlockItemsViewCommand = new RelayCommand(OnSwitchBlockItemsViewCommand);
PlaySoundCommand = new RelayCommand(OnPlaySoundCommand, () => HasSound); PlaySoundCommand = new RelayCommand(OnPlaySoundCommand, () => HasSound);
PlayPositionalSoundCommand = new RelayCommand(OnPlayPositionalSoundCommand, () => HasPositionalSound); PlayPositionalSoundCommand = new RelayCommand(OnPlayPositionalSoundCommand, () => HasPositionalSound);
PlayCustomSoundCommand = new RelayCommand(OnPlayCustomSoundCommand, () => HasCustomSound);
CustomSoundFileDialogCommand = new RelayCommand(OnCustomSoundFileDialog);
if(_customSoundsAvailable == null || _customSoundsAvailable.Count < 1)
{
_customSoundsAvailable = new ObservableCollection<string> {
"1maybevaluable.mp3", "2currency.mp3", "3uniques.mp3", "4maps.mp3", "5highmaps.mp3",
"6veryvaluable.mp3", "7chancing.mp3", "12leveling.mp3", "placeholder.mp3"
};
}
} }
public override void Initialise(IItemFilterBlockBase itemFilterBlockBase, IItemFilterScriptViewModel parentScriptViewModel) public override void Initialise(IItemFilterBlockBase itemFilterBlockBase, IItemFilterScriptViewModel parentScriptViewModel)
@ -66,9 +79,16 @@ namespace Filtration.ViewModels
foreach (var blockItem in itemFilterBlock.BlockItems) foreach (var blockItem in itemFilterBlock.BlockItems)
{ {
blockItem.PropertyChanged += OnBlockItemChanged; blockItem.PropertyChanged += OnBlockItemChanged;
var customSoundBlockItem = blockItem as CustomSoundBlockItem;
if (customSoundBlockItem != null)
{
if (_customSoundsAvailable.IndexOf(customSoundBlockItem.Value) < 0)
{
_customSoundsAvailable.Add(customSoundBlockItem.Value);
}
}
} }
base.Initialise(itemFilterBlock, parentScriptViewModel); base.Initialise(itemFilterBlock, parentScriptViewModel);
} }
@ -81,6 +101,8 @@ namespace Filtration.ViewModels
public RelayCommand PlaySoundCommand { get; } public RelayCommand PlaySoundCommand { get; }
public RelayCommand PlayPositionalSoundCommand { get; } public RelayCommand PlayPositionalSoundCommand { get; }
public RelayCommand SwitchBlockItemsViewCommand { get; } public RelayCommand SwitchBlockItemsViewCommand { get; }
public RelayCommand CustomSoundFileDialogCommand { get; }
public RelayCommand PlayCustomSoundCommand { get; }
public IItemFilterBlock Block { get; private set; } public IItemFilterBlock Block { get; private set; }
@ -176,7 +198,8 @@ namespace Filtration.ViewModels
typeof (PositionalSoundBlockItem), typeof (PositionalSoundBlockItem),
typeof (DisableDropSoundBlockItem), typeof (DisableDropSoundBlockItem),
typeof (IconBlockItem), typeof (IconBlockItem),
typeof (BeamBlockItem) typeof (BeamBlockItem),
typeof (CustomSoundBlockItem)
}; };
public bool BlockEnabled public bool BlockEnabled
@ -212,6 +235,8 @@ namespace Filtration.ViewModels
public ObservableCollection<ColorItem> AvailableColors => PathOfExileColors.DefaultColors; public ObservableCollection<ColorItem> AvailableColors => PathOfExileColors.DefaultColors;
public ObservableCollection<string> CustomSoundsAvailable => _customSoundsAvailable;
public Color DisplayTextColor => Block.DisplayTextColor; public Color DisplayTextColor => Block.DisplayTextColor;
public Color DisplayBackgroundColor => Block.DisplayBackgroundColor; public Color DisplayBackgroundColor => Block.DisplayBackgroundColor;
public Color DisplayBorderColor => Block.DisplayBorderColor; public Color DisplayBorderColor => Block.DisplayBorderColor;
@ -221,6 +246,7 @@ namespace Filtration.ViewModels
public bool HasSound => Block.HasBlockItemOfType<SoundBlockItem>(); public bool HasSound => Block.HasBlockItemOfType<SoundBlockItem>();
public bool HasPositionalSound => Block.HasBlockItemOfType<PositionalSoundBlockItem>(); public bool HasPositionalSound => Block.HasBlockItemOfType<PositionalSoundBlockItem>();
public bool HasCustomSound => Block.HasBlockItemOfType<CustomSoundBlockItem>();
public bool HasAudioVisualBlockItems => AudioVisualBlockItems.Any(); public bool HasAudioVisualBlockItems => AudioVisualBlockItems.Any();
@ -444,6 +470,8 @@ namespace Filtration.ViewModels
RaisePropertyChanged(nameof(DisplayIcon)); RaisePropertyChanged(nameof(DisplayIcon));
RaisePropertyChanged(nameof(DisplayBeamColor)); RaisePropertyChanged(nameof(DisplayBeamColor));
RaisePropertyChanged(nameof(HasSound)); RaisePropertyChanged(nameof(HasSound));
RaisePropertyChanged(nameof(HasPositionalSound));
RaisePropertyChanged(nameof(HasCustomSound));
} }
private void OnBlockItemsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) private void OnBlockItemsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
@ -453,5 +481,53 @@ namespace Filtration.ViewModels
RaisePropertyChanged(nameof(AudioVisualBlockItems)); RaisePropertyChanged(nameof(AudioVisualBlockItems));
RaisePropertyChanged(nameof(HasAudioVisualBlockItems)); RaisePropertyChanged(nameof(HasAudioVisualBlockItems));
} }
private void OnCustomSoundFileDialog()
{
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.DefaultExt = ".mp3";
var poePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments).ToString() + @"\My Games\Path of Exile\";
fileDialog.InitialDirectory = poePath;
Nullable<bool> result = fileDialog.ShowDialog();
if (result == true)
{
var fileName = fileDialog.FileName;
if(fileName.StartsWith(poePath))
{
fileName = fileName.Replace(poePath, "");
}
var customSoundBlockItem = BlockItems.First(b => b.GetType() == typeof(CustomSoundBlockItem)) as CustomSoundBlockItem;
if (CustomSoundsAvailable.IndexOf(fileName) < 0)
{
CustomSoundsAvailable.Add(fileName);
RaisePropertyChanged(nameof(CustomSoundsAvailable));
}
customSoundBlockItem.Value = fileName;
}
}
private void OnPlayCustomSoundCommand()
{
var poePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments).ToString() + @"\My Games\Path of Exile\";
var identifier = BlockItems.OfType<CustomSoundBlockItem>().First().Value;
if(!Path.IsPathRooted(identifier))
{
identifier = poePath + identifier;
}
try
{
_mediaPlayer.Open(new Uri(identifier, UriKind.Absolute));
_mediaPlayer.Play();
}
catch
{
MessageBox.Show("Couldn't play the file. Please be sure it is a valid audio file.");
}
}
} }
} }

View File

@ -161,6 +161,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 PlayCustomSoundCommand}"
Width="25"
Height="25"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Margin="0,0,3,0"
Visibility="{Binding HasCustomSound, 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"