Copy paste sound bug fix

This commit is contained in:
azakhi 2018-08-30 19:33:46 +03:00
parent 15143f738f
commit 8f0f73f185
3 changed files with 65 additions and 27 deletions

View File

@ -222,7 +222,7 @@
<Button Grid.Column="0" Grid.Row="0" Command="{Binding Path=DataContext.PlayCustomSoundCommand, RelativeSource={RelativeSource AncestorType={x:Type views:ItemFilterBlockView}}}" Width="20" Height="20" Background="Transparent" BorderBrush="Transparent"> <Button Grid.Column="0" Grid.Row="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" /> <Image Source="/Filtration;component/Resources/Icons/speaker_icon.png" VerticalAlignment="Center" HorizontalAlignment="Center" />
</Button> </Button>
<ComboBox Grid.Column="1" Grid.Row="0" ItemsSource="{Binding Path=DataContext.CustomSoundsAvailable, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type views:ItemFilterBlockView}}}" <ComboBox Grid.Column="1" Grid.Row="0" ItemsSource="{Binding Path=DataContext.CustomSoundsAvailable, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type views:ItemFilterScriptView}}}"
SelectedValue="{Binding Value, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource MetroComboBox}"/> SelectedValue="{Binding Value, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource MetroComboBox}"/>
<Button Grid.Column="1" Grid.Row="0" Command="{Binding Path=DataContext.CustomSoundFileDialogCommand, RelativeSource={RelativeSource AncestorType={x:Type views:ItemFilterBlockView}}}" <Button Grid.Column="1" Grid.Row="0" 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"> Width="20" Height="20" Background="Transparent" BorderBrush="Transparent" Margin="0,0,30,0" VerticalAlignment="Center" HorizontalAlignment="Right">

View File

@ -31,7 +31,6 @@ 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;
@ -53,14 +52,6 @@ namespace Filtration.ViewModels
PlayPositionalSoundCommand = new RelayCommand(OnPlayPositionalSoundCommand, () => HasPositionalSound); PlayPositionalSoundCommand = new RelayCommand(OnPlayPositionalSoundCommand, () => HasPositionalSound);
PlayCustomSoundCommand = new RelayCommand(OnPlayCustomSoundCommand, () => HasCustomSound); PlayCustomSoundCommand = new RelayCommand(OnPlayCustomSoundCommand, () => HasCustomSound);
CustomSoundFileDialogCommand = new RelayCommand(OnCustomSoundFileDialog); 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)
@ -80,15 +71,6 @@ 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 (!string.IsNullOrWhiteSpace(customSoundBlockItem.Value) && _customSoundsAvailable.IndexOf(customSoundBlockItem.Value) < 0)
{
_customSoundsAvailable.Add(customSoundBlockItem.Value);
}
}
} }
base.Initialise(itemFilterBlock, parentScriptViewModel); base.Initialise(itemFilterBlock, parentScriptViewModel);
} }
@ -237,8 +219,6 @@ 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;
@ -461,11 +441,10 @@ namespace Filtration.ViewModels
var customSoundBlockItem = sender as CustomSoundBlockItem; var customSoundBlockItem = sender as CustomSoundBlockItem;
if (customSoundBlockItem != null) if (customSoundBlockItem != null)
{ {
if (!string.IsNullOrWhiteSpace(customSoundBlockItem.Value) && _customSoundsAvailable.IndexOf(customSoundBlockItem.Value) < 0) if (!string.IsNullOrWhiteSpace(customSoundBlockItem.Value) && _parentScriptViewModel.CustomSoundsAvailable.IndexOf(customSoundBlockItem.Value) < 0)
{ {
_customSoundsAvailable.Add(customSoundBlockItem.Value); _parentScriptViewModel.CustomSoundsAvailable.Add(customSoundBlockItem.Value);
} }
RaisePropertyChanged(nameof(CustomSoundsAvailable));
} }
Block.IsEdited = true; Block.IsEdited = true;
//if (sender is IAudioVisualBlockItem) //if (sender is IAudioVisualBlockItem)
@ -515,10 +494,9 @@ namespace Filtration.ViewModels
var customSoundBlockItem = BlockItems.First(b => b.GetType() == typeof(CustomSoundBlockItem)) as CustomSoundBlockItem; var customSoundBlockItem = BlockItems.First(b => b.GetType() == typeof(CustomSoundBlockItem)) as CustomSoundBlockItem;
if (CustomSoundsAvailable.IndexOf(fileName) < 0) if (_parentScriptViewModel.CustomSoundsAvailable.IndexOf(fileName) < 0)
{ {
CustomSoundsAvailable.Add(fileName); _parentScriptViewModel.CustomSoundsAvailable.Add(fileName);
RaisePropertyChanged(nameof(CustomSoundsAvailable));
} }
customSoundBlockItem.Value = fileName; customSoundBlockItem.Value = fileName;
} }

View File

@ -17,6 +17,7 @@ using Filtration.Common.ViewModels;
using Filtration.Interface; using Filtration.Interface;
using Filtration.ObjectModel; using Filtration.ObjectModel;
using Filtration.ObjectModel.BlockItemBaseTypes; using Filtration.ObjectModel.BlockItemBaseTypes;
using Filtration.ObjectModel.BlockItemTypes;
using Filtration.ObjectModel.Commands; using Filtration.ObjectModel.Commands;
using Filtration.ObjectModel.Commands.ItemFilterScript; using Filtration.ObjectModel.Commands.ItemFilterScript;
using Filtration.Parser.Interface.Services; using Filtration.Parser.Interface.Services;
@ -34,6 +35,7 @@ namespace Filtration.ViewModels
IItemFilterBlockViewModelBase SelectedBlockViewModel { get; set; } IItemFilterBlockViewModelBase SelectedBlockViewModel { get; set; }
IItemFilterCommentBlockViewModel CommentBlockBrowserBrowserSelectedBlockViewModel { get; set; } IItemFilterCommentBlockViewModel CommentBlockBrowserBrowserSelectedBlockViewModel { get; set; }
IEnumerable<IItemFilterCommentBlockViewModel> ItemFilterCommentBlockViewModels { get; } IEnumerable<IItemFilterCommentBlockViewModel> ItemFilterCommentBlockViewModels { get; }
ObservableCollection<string> CustomSoundsAvailable { get; }
Predicate<IItemFilterBlockViewModel> BlockFilterPredicate { get; set; } Predicate<IItemFilterBlockViewModel> BlockFilterPredicate { get; set; }
bool ShowAdvanced { get; } bool ShowAdvanced { get; }
@ -106,6 +108,8 @@ namespace Filtration.ViewModels
private Predicate<IItemFilterBlockViewModel> _blockFilterPredicate; private Predicate<IItemFilterBlockViewModel> _blockFilterPredicate;
private ICommandManager _scriptCommandManager; private ICommandManager _scriptCommandManager;
private ObservableCollection<string> _customSoundsAvailable;
public ItemFilterScriptViewModel(IItemFilterBlockBaseViewModelFactory itemFilterBlockBaseViewModelFactory, public ItemFilterScriptViewModel(IItemFilterBlockBaseViewModelFactory itemFilterBlockBaseViewModelFactory,
IItemFilterBlockTranslator blockTranslator, IItemFilterBlockTranslator blockTranslator,
IAvalonDockWorkspaceViewModel avalonDockWorkspaceViewModel, IAvalonDockWorkspaceViewModel avalonDockWorkspaceViewModel,
@ -161,6 +165,11 @@ namespace Filtration.ViewModels
IconSource = icon; IconSource = icon;
_viewItemFilterBlockViewModels = new ObservableCollection<IItemFilterBlockViewModelBase>(); _viewItemFilterBlockViewModels = new ObservableCollection<IItemFilterBlockViewModelBase>();
_customSoundsAvailable = new ObservableCollection<string> {
"1maybevaluable.mp3", "2currency.mp3", "3uniques.mp3", "4maps.mp3", "5highmaps.mp3",
"6veryvaluable.mp3", "7chancing.mp3", "12leveling.mp3", "placeholder.mp3"
};
} }
public void Initialise(IItemFilterScript itemFilterScript, bool newScript) public void Initialise(IItemFilterScript itemFilterScript, bool newScript)
@ -170,8 +179,28 @@ namespace Filtration.ViewModels
Script = itemFilterScript; Script = itemFilterScript;
_scriptCommandManager = Script.CommandManager; _scriptCommandManager = Script.CommandManager;
AddItemFilterBlockViewModels(Script.ItemFilterBlocks, -1); AddItemFilterBlockViewModels(Script.ItemFilterBlocks, -1);
foreach(var block in Script.ItemFilterBlocks)
{
var itemBlock = block as IItemFilterBlock;
if(itemBlock != null)
{
foreach(var blockItem in itemBlock.BlockItems)
{
var customSoundBlockItem = blockItem as CustomSoundBlockItem;
if (customSoundBlockItem != null)
{
if (!string.IsNullOrWhiteSpace(customSoundBlockItem.Value) && _customSoundsAvailable.IndexOf(customSoundBlockItem.Value) < 0)
{
CustomSoundsAvailable.Add(customSoundBlockItem.Value);
}
}
}
}
}
Script.ItemFilterBlocks.CollectionChanged += ItemFilterBlocksOnCollectionChanged; Script.ItemFilterBlocks.CollectionChanged += ItemFilterBlocksOnCollectionChanged;
_customSoundsAvailable.CollectionChanged += CustomSoundsAvailableOnCollectionChanged;
_filenameIsFake = newScript; _filenameIsFake = newScript;
@ -211,6 +240,11 @@ namespace Filtration.ViewModels
UpdateBlockModelsForView(); UpdateBlockModelsForView();
} }
private void CustomSoundsAvailableOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs)
{
RaisePropertyChanged(nameof(CustomSoundsAvailable));
}
private void AddItemFilterBlockViewModels(IEnumerable<IItemFilterBlockBase> itemFilterBlocks, int addAtIndex) private void AddItemFilterBlockViewModels(IEnumerable<IItemFilterBlockBase> itemFilterBlocks, int addAtIndex)
{ {
var firstNewViewModel = true; var firstNewViewModel = true;
@ -235,6 +269,22 @@ namespace Filtration.ViewModels
SelectedBlockViewModel = vm; SelectedBlockViewModel = vm;
firstNewViewModel = false; firstNewViewModel = false;
} }
var itemBlock = itemFilterBlock as IItemFilterBlock;
if (itemBlock != null)
{
foreach (var blockItem in itemBlock.BlockItems)
{
var customSoundBlockItem = blockItem as CustomSoundBlockItem;
if (customSoundBlockItem != null)
{
if (!string.IsNullOrWhiteSpace(customSoundBlockItem.Value) && _customSoundsAvailable.IndexOf(customSoundBlockItem.Value) < 0)
{
CustomSoundsAvailable.Add(customSoundBlockItem.Value);
}
}
}
}
} }
} }
@ -293,6 +343,16 @@ namespace Filtration.ViewModels
} }
} }
public ObservableCollection<string> CustomSoundsAvailable
{
get => _customSoundsAvailable;
set
{
_customSoundsAvailable = value;
RaisePropertyChanged();
}
}
public ObservableCollection<IItemFilterBlockViewModelBase> ViewItemFilterBlockViewModels public ObservableCollection<IItemFilterBlockViewModelBase> ViewItemFilterBlockViewModels
{ {
get get