Skip to content

Commit

Permalink
Finalized sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
Imaginary-Narwhal committed Aug 14, 2021
1 parent 4206d43 commit 3bd2c80
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 33 deletions.
Binary file modified .vs/EZCounter/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file added .vs/EZCounter/v17/.futdcache.v1
Binary file not shown.
11 changes: 8 additions & 3 deletions App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ public partial class App : Application

public App()
{
string placementFile = Path.Combine(
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "EZCounter"),
"placement.config");
string Storage = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "EZCounter");

string placementFile = Path.Combine(Storage, "placement.config");

if(!Directory.Exists(Path.Combine(Storage, "Sounds")))
{
Directory.CreateDirectory(Path.Combine(Storage, "Sounds"));
}

WindowPlace = new WindowPlace(placementFile);
}
Expand Down
100 changes: 100 additions & 0 deletions Custom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
using System.Media;
using System.Windows.Media;
using ImaginaryNarwhal;
using System.IO;
using System.Collections.ObjectModel;
using System.Collections.Generic;

namespace EZCounter
{
Expand Down Expand Up @@ -83,4 +89,98 @@ public object ConvertBack(object value, Type targetType, object parameter,

#endregion
}

public class TimerSounds : ICustomPropertyNotify
{
private MediaPlayer player = new MediaPlayer();
private List<Uri> _soundFiles;
private List<string> _allSounds;
private string _selectedSound;

public List<Uri> SoundFiles
{
get => _soundFiles;
set => SetProperty(ref _soundFiles, value);
}

public List<string> AllSounds
{
get => _allSounds;
set => SetProperty(ref _allSounds, value);
}

public string SelectedSound
{
get => _selectedSound;
set
{
SetProperty(ref _selectedSound, value);
if(!SelectedSound.Contains("System:"))
{
player.Close();
player.Open(GetSoundFileFromString(value));
}
}
}

public TimerSounds()
{
SoundFiles = new List<Uri>();
GetSoundFiles();

AllSounds = new List<string>();
AllSounds.Add("None");
AllSounds.Add("System: Asterisk");
AllSounds.Add("System: Beep");
AllSounds.Add("System: Exclamation");
AllSounds.Add("System: Hand");
AllSounds.Add("System: Question");
foreach(var file in SoundFiles)
{
AllSounds.Add(Path.GetFileName(file.LocalPath));
}

SelectedSound = Properties.Settings.Default.timerSound;
}

public void GetSoundFiles()
{
SoundFiles.Clear();

var ext = new List<string> { "wav", "mp3", "wma" };

var files = Directory.EnumerateFiles(Storage.Sounds, "*.*").Where(f => ext.Contains(Path.GetExtension(f).TrimStart('.').ToLowerInvariant())).ToList();
foreach(var file in files)
{
SoundFiles.Add(new Uri(Path.Combine(Storage.Sounds, file)));
}
}

public Uri GetSoundFileFromString(string sound)
{
return SoundFiles.Where(x => Path.GetFileName(x.LocalPath) == sound).FirstOrDefault();
}

public void PlaySound()
{
switch(SelectedSound)
{
case "None": break;
case "System: Asterisk": SystemSounds.Asterisk.Play(); break;
case "System: Beep": SystemSounds.Beep.Play(); break;
case "System: Exclamation": SystemSounds.Exclamation.Play(); break;
case "System: Hand": SystemSounds.Hand.Play(); break;
case "System: Question": SystemSounds.Question.Play(); break;
default:
player.Play();
break;
}
}
}

public static class Storage
{
public static string Dir => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "EZCounter");
public static string Sounds => Path.Combine(Dir, "Sounds");
}
}
1 change: 1 addition & 0 deletions EZCounter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<UseWPF>true</UseWPF>
<ApplicationIcon />
<StartupObject />
<Version>1.3.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
14 changes: 13 additions & 1 deletion Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@
<Setting Name="listOpen" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="timerSound" Type="System.String" Scope="User">
<Value Profile="(Default)">None</Value>
</Setting>
</Settings>
</SettingsFile>
6 changes: 6 additions & 0 deletions ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace EZCounter.ViewModels
{
public class MainViewModel : ICustomPropertyNotify
{
public TimerSounds Sounds { get; set; }

public readonly dbContext db;
private Timer cTimer;
private decimal currentTime = 0;
Expand Down Expand Up @@ -53,6 +55,7 @@ public MainViewModel()
cTimer.Elapsed += new ElapsedEventHandler(OnTimerEVent);
cTimer.Interval = 1000;
TimerCounter = 0;
Sounds = new TimerSounds();
}

private void OnTimerEVent(object sender, ElapsedEventArgs e)
Expand All @@ -64,7 +67,10 @@ private void OnTimerEVent(object sender, ElapsedEventArgs e)

if (currentTime == maxTime)
{
var sounds = new TimerSounds();
TimerCounter = 100;
cTimer.Stop();
sounds.PlaySound();
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion Views/MainView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Topmost="True" Background="#121212"
Height="65" Width="240" Name="TehWindow"
ResizeMode="NoResize" WindowStyle="None" MouseDown="Window_MouseDown"
Loaded="Window_Loaded" LocationChanged="Moving" Closing="OnClose">
Loaded="Window_Loaded" LocationChanged="Moving" Closing="OnClose" >
<Window.Resources>
<Style x:Key="{x:Type ContextMenu}" TargetType="{x:Type ContextMenu}">
<Setter Property="OverridesDefaultStyle" Value="True"/>
Expand Down
8 changes: 4 additions & 4 deletions Views/MainView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ namespace EZCounter.Views
/// </summary>
public partial class MainView : Window
{
private MainViewModel vm;
public MainViewModel vm { get; set; }
private ListView lWindow;

public TimerSounds tSounds { get; set; }

public MainView()
{
Expand All @@ -35,7 +35,7 @@ public MainView()
DataContext = vm;

lWindow = new ListView(vm);
lWindow.Show();
lWindow.Show();
}

private void Window_Loaded(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -99,7 +99,7 @@ private void MenuClick(object sender, RoutedEventArgs e)

private void Moving(object sender, EventArgs e)
{
if (Properties.Settings.Default.listOpen && lWindow != null)
if (lWindow != null)
{
lWindow.Top = GetTop();
lWindow.Left = TehWindow.Left;
Expand Down
77 changes: 53 additions & 24 deletions Views/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
xmlns:local="clr-namespace:EZCounter.Views"
xmlns:custom="clr-namespace:EZCounter"
mc:Ignorable="d" Background="#121212"
Title="Settings" Height="140" Width="300" WindowStyle="ToolWindow" WindowStartupLocation="CenterScreen">
Title="Settings" Height="250" Width="450" WindowStyle="ToolWindow" WindowStartupLocation="CenterScreen" Topmost="True" ResizeMode="NoResize">
<Window.Resources>
<BooleanToVisibilityConverter x:Key="bool2Vis"/>
<custom:BoolInverterConverter x:Key="boolInvert"/>
Expand All @@ -18,17 +18,44 @@
<RowDefinition Height="35"/>
<RowDefinition Height="35"/>
<RowDefinition Height="35"/>
<RowDefinition Height="35"/>
<RowDefinition Height="35"/>
<RowDefinition Height="35"/>
<RowDefinition Height="35"/>
<RowDefinition Height="35"/>
<RowDefinition Height="35"/>
<RowDefinition Height="35"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.ColumnSpan="2" Foreground="#B6B5B5" FontSize="12pt">Timer settings:</Label>
<Label Grid.Row="0" Foreground="#B6B5B5" FontSize="12pt">List Anchor:</Label>
<StackPanel Grid.Column="1" Grid.Row="0" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<RadioButton
IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=anchorListTop}"
Background="#b6b5b5"
Content="Top"
Foreground="#b6b5b5"
FontSize="12pt"
VerticalContentAlignment="Center" Click="MoveWindow"
Padding="0,0,15,0"/>
<RadioButton
IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=anchorListTop, Converter={StaticResource boolInvert}}"
Background="#b6b5b5"
Content="Bottom"
Foreground="#b6b5b5"
FontSize="12pt" Click="MoveWindow"
VerticalContentAlignment="Center"/>
</StackPanel>


<Label Grid.Row="1" Grid.ColumnSpan="2" Foreground="#B6B5B5" FontSize="12pt">Timer settings:</Label>
<CheckBox FlowDirection="RightToLeft" Background="#B6B5B5"
FontSize="12pt" VerticalContentAlignment="Center"
VerticalAlignment="Center"
Content="?On"
Grid.Row="1" Grid.Column="0"
Grid.Row="2" Grid.Column="0"
Margin="0,0,10,0"
Foreground="#B6B5B5"
x:Name="TimerCheck"
Expand All @@ -40,7 +67,7 @@
</CheckBox.Resources>
</CheckBox>
<StackPanel Grid.Column="1"
Grid.Row="1"
Grid.Row="2"
Orientation="Horizontal"
Margin="10,5,0,5"
Visibility="{Binding IsChecked, ElementName=TimerCheck, Converter={StaticResource bool2Vis}}">
Expand All @@ -58,23 +85,25 @@
Foreground="White"/>
</StackPanel>

<Label Grid.Row="2" Foreground="#B6B5B5" FontSize="12pt">List Anchor:</Label>
<StackPanel Grid.Column="1" Grid.Row="2" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<RadioButton
IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=anchorListTop}"
Background="#b6b5b5"
Content="Top"
Foreground="#b6b5b5"
FontSize="12pt"
VerticalContentAlignment="Center" Click="MoveWindow"
Padding="0,0,15,0"/>
<RadioButton
IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=anchorListTop, Converter={StaticResource boolInvert}}"
Background="#b6b5b5"
Content="Bottom"
Foreground="#b6b5b5"
FontSize="12pt" Click="MoveWindow"
VerticalContentAlignment="Center"/>
</StackPanel>
<Label
Foreground="#B6B5B5" FontSize="12pt"
Grid.Row="3"
Content="Timer Sound:" HorizontalContentAlignment="Right"
Visibility="{Binding IsChecked, ElementName=TimerCheck, Converter={StaticResource bool2Vis}}"
/>
<ComboBox
SelectionChanged="ChangedSound"
SelectedItem="{Binding SelectedSound}"
Grid.Row="3"
Grid.Column="1"
FontSize="12pt"
Margin="10,3,10,3"
ItemsSource="{Binding AllSounds}"
Visibility="{Binding IsChecked, ElementName=TimerCheck, Converter={StaticResource bool2Vis}}"/>
<Button
Grid.Row="4"
Grid.Column="1"
Margin="10,3,10,3" Width="200" FontSize="12pt"
Background="SlateGray" Foreground="#B6B5B5" Click="OpenSounds">Open Sound Folder</Button>
</Grid>
</Window>
17 changes: 17 additions & 0 deletions Views/SettingsView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -21,16 +22,32 @@ namespace EZCounter.Views
public partial class SettingsView : Window
{
private MainView TehWindow;
private App app = Application.Current as App;
public TimerSounds Sounds { get; set; }

public SettingsView(MainView tehWindow)
{
TehWindow = tehWindow;
InitializeComponent();

Sounds = TehWindow.vm.Sounds;
DataContext = Sounds;
}

private void MoveWindow(object sender, RoutedEventArgs e)
{
TehWindow.MoveListView();
}

private void ChangedSound(object sender, SelectionChangedEventArgs e)
{
Properties.Settings.Default.timerSound = Sounds.SelectedSound;
Properties.Settings.Default.Save();
}

private void OpenSounds(object sender, RoutedEventArgs e)
{
Process.Start("explorer.exe", Storage.Sounds);
}
}
}

0 comments on commit 3bd2c80

Please sign in to comment.