Skip to content

Commit

Permalink
custom sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
tensei committed Feb 21, 2017
1 parent 8cb06da commit d9ac040
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 11 deletions.
1 change: 1 addition & 0 deletions GbfRaidfinder/GbfRaidfinder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
<Compile Include="Interfaces\ITweetObserver.cs" />
<Compile Include="Interfaces\ITweetProcessor.cs" />
<Compile Include="Interfaces\ITweetInfo.cs" />
<Compile Include="Models\SoundFileModel.cs" />
<Compile Include="Twitter\TweetInfo.cs" />
<Compile Include="Twitter\TweetObserver.cs" />
<Compile Include="Twitter\TweetProcessor.cs" />
Expand Down
29 changes: 24 additions & 5 deletions GbfRaidfinder/Models/FollowModel.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using GbfRaidfinder.Data;
using GbfRaidfinder.Interfaces;
using GbfRaidfinder.Twitter;
using GbfRaidfinder.ViewModels;
using Newtonsoft.Json;
using PropertyChanged;

namespace GbfRaidfinder.Models {
[ImplementPropertyChanged]
public class FollowModel {
[JsonIgnore] public ObservableCollection<TweetInfo> _TweetInfos = new ObservableCollection<TweetInfo>();
[JsonIgnore]
public readonly ObservableCollection<TweetInfo> TweetInfos = new ObservableCollection<TweetInfo>();

public FollowModel(string jp, string en, string image) {
English = en;
Japanese = jp;
Image = image;
CopyCommand = new ActionCommand(c => Copy((TweetInfo) c));
Tweets = new ReadOnlyObservableCollection<TweetInfo>(_TweetInfos);
Tweets = new ReadOnlyObservableCollection<TweetInfo>(TweetInfos);
}

public string English { get; set; }
Expand All @@ -24,17 +31,29 @@ public FollowModel(string jp, string en, string image) {
public bool ImageVisibility { get; set; }
public bool AutoCopy { get; set; }
public bool Sound { get; set; }
[JsonIgnore]
public List<SoundFileModel> SoundFiles => GetSoundFiles();
public SoundFileModel SelectedSoundFile { get; set; }
public int SelectedSoundFileIndex { get; set; }

[JsonIgnore]
public ReadOnlyObservableCollection<TweetInfo> Tweets { get; }

[JsonIgnore]
public ICommand CopyCommand { get; }



private void Copy(ITweetInfo tweetInfo) {
Clipboard.SetText(tweetInfo.Id);
tweetInfo.Clicked = !tweetInfo.Clicked;
}

private List<SoundFileModel> GetSoundFiles() {
var assets = Path.Combine(Directory.GetCurrentDirectory(), "assets");
var soundfiles = Directory.GetFiles(assets, "*.wav");
return soundfiles.Select(soundfile => new SoundFileModel {
Name = soundfile.Split('\\').Last(),
Path = soundfile
}).ToList();
}
}
}
9 changes: 9 additions & 0 deletions GbfRaidfinder/Models/SoundFileModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using PropertyChanged;

namespace GbfRaidfinder.Models {
[ImplementPropertyChanged]
public class SoundFileModel {
public string Name { get; set; }
public string Path { get; set; }
}
}
9 changes: 6 additions & 3 deletions GbfRaidfinder/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Media;
using System.Windows;
Expand Down Expand Up @@ -104,20 +106,21 @@ private void AddTweet(TweetInfo tweet) {
var follow =
_raidsController.Follows.FirstOrDefault(
f => f.English.Contains(tweet.Boss.Trim()) || f.Japanese.Contains(tweet.Boss.Trim()));
follow?._TweetInfos.Insert(0, tweet);
follow?.TweetInfos.Insert(0, tweet);
if (follow != null && follow.AutoCopy) {
Clipboard.SetText(tweet.Id);
}
if (follow != null && follow.Sound) {
try {
_soudplayer.SoundLocation = follow.SelectedSoundFile?.Path;
_soudplayer.Play();
}
catch (Exception) {
//no file
}
}
if (follow?._TweetInfos.Count > 30) {
follow._TweetInfos.RemoveAt(follow._TweetInfos.Count - 1);
if (follow?.TweetInfos.Count > 30) {
follow.TweetInfos.RemoveAt(follow.TweetInfos.Count - 1);
}
}));
}
Expand Down
18 changes: 15 additions & 3 deletions GbfRaidfinder/Views/BossView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:models="clr-namespace:GbfRaidfinder.Models"
xmlns:gbfRaidfinder="clr-namespace:GbfRaidfinder"
xmlns:system="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
d:DesignHeight="300" Width="300"
d:DataContext="{d:DesignInstance {x:Type models:FollowModel}, IsDesignTimeCreatable=False}">
Expand Down Expand Up @@ -105,6 +106,7 @@
<RowDefinition Height="35" />
<RowDefinition Height="35" />
<RowDefinition Height="35" />
<RowDefinition Height="35" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<materialDesign:ColorZone>
Expand Down Expand Up @@ -132,10 +134,20 @@
<ToggleButton Grid.Row="2" ToolTip="Sound Notifications" Margin="5,0" IsChecked="{Binding Sound}"
HorizontalAlignment="Right" />

<TextBlock Grid.Row="3" VerticalAlignment="Center" FontSize="16">Image</TextBlock>
<ToggleButton Grid.Row="3" ToolTip="Toggle Image" Margin="5,0" IsChecked="{Binding ImageVisibility}"
HorizontalAlignment="Right" />
<TextBlock Grid.Row="3" VerticalAlignment="Center" FontSize="16">Sound</TextBlock>
<ComboBox Grid.Row="3" Margin="5,0" ItemsSource="{Binding SoundFiles}" SelectedItem="{Binding SelectedSoundFile}"
HorizontalAlignment="Right" Width="200"
SelectedIndex="{Binding SelectedSoundFileIndex}">
<ComboBox.ItemTemplate>
<DataTemplate DataType="{x:Type models:SoundFileModel}">
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>

<TextBlock Grid.Row="4" VerticalAlignment="Center" FontSize="16">Image</TextBlock>
<ToggleButton Grid.Row="4" ToolTip="Toggle Image" Margin="5,0" IsChecked="{Binding ImageVisibility}"
HorizontalAlignment="Right" />
</Grid>
</materialDesign:Transitioner>
</UserControl>

0 comments on commit d9ac040

Please sign in to comment.