diff --git a/LunaticPlayer/Client/Configuration.cs b/LunaticPlayer/Client/Configuration.cs new file mode 100644 index 0000000..56044c7 --- /dev/null +++ b/LunaticPlayer/Client/Configuration.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace LunaticPlayer.Client +{ + class ConfigurationData + { + public double Volume { get; set; } + } + + class Configuration + { + private const string Filename = "config.json"; + + private static Configuration _instance; + + public ConfigurationData Data { get; set; } + + /// + /// The source of configuration data (Filesystem, Default Object, ...). + /// + public string Source { get; set; } + + public static Configuration GetInstance() + { + if (_instance == null) + { + _instance = new Configuration(); + _instance.Initialize(); + } + + return _instance; + } + + /// + /// Loads the configuration and stores it to the filesystem if necessary. + /// + private void Initialize() + { + + if (File.Exists(Filename)) + { + Data = JsonConvert.DeserializeObject(File.ReadAllText(Filename)); + Source = "Filesystem"; + } + else + { + Source = "DefaultDataObject"; + + SetupData(); + + // Erstellt eine Konfigurationsdatei für das nächste Mal. + Save(); + } + } + + /// + /// Creates a object with default values. + /// + private void SetupData() + { + var data = new ConfigurationData() + { + Volume = 0.4 + }; + + Data = data; + } + + /// + /// Saves the current configuration to the file specified at . + /// + public void Save() + { + Console.WriteLine("Saving configuration to filesystem."); + File.WriteAllText(Filename, JsonConvert.SerializeObject(Data)); + } + } +} diff --git a/LunaticPlayer/Controls/VolumeBar.xaml b/LunaticPlayer/Controls/VolumeBar.xaml new file mode 100644 index 0000000..1deceb8 --- /dev/null +++ b/LunaticPlayer/Controls/VolumeBar.xaml @@ -0,0 +1,14 @@ + + + + + + + diff --git a/LunaticPlayer/Controls/VolumeBar.xaml.cs b/LunaticPlayer/Controls/VolumeBar.xaml.cs new file mode 100644 index 0000000..4d1ccbe --- /dev/null +++ b/LunaticPlayer/Controls/VolumeBar.xaml.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace LunaticPlayer.Controls +{ + public class VolumeBarData + { + public double Volume { get; set; } + } + + /// + /// Interaktionslogik für VolumeBar.xaml + /// + public partial class VolumeBar : UserControl + { + public VolumeBarData Data { get; set; } + public Action OnValueChange { get; set; } + + public VolumeBar(VolumeBarData data) + { + InitializeComponent(); + + DataContext = Data = data; + } + + private void VolumeSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) + { + Data.Volume = VolumeSlider.Value; + + OnValueChange?.Invoke(); + } + } +} diff --git a/LunaticPlayer/LunaticPlayer.csproj b/LunaticPlayer/LunaticPlayer.csproj index 5fe0baf..2041010 100644 --- a/LunaticPlayer/LunaticPlayer.csproj +++ b/LunaticPlayer/LunaticPlayer.csproj @@ -66,6 +66,10 @@ MSBuild:Compile Designer + + + VolumeBar.xaml + PopupBanner.xaml @@ -81,6 +85,10 @@ DialogWindow.xaml + + Designer + MSBuild:Compile + MSBuild:Compile Designer @@ -163,8 +171,8 @@ - - + + @@ -200,6 +208,9 @@ + + + diff --git a/LunaticPlayer/Player/RadioPlayer.cs b/LunaticPlayer/Player/RadioPlayer.cs index 8d6e94f..675d4e3 100644 --- a/LunaticPlayer/Player/RadioPlayer.cs +++ b/LunaticPlayer/Player/RadioPlayer.cs @@ -7,7 +7,7 @@ class RadioPlayer { private readonly MediaPlayer _player; - public bool Muted => _player.Volume == 0.0; + public bool Muted { get; set; } public double Volume => _player.Volume; @@ -39,5 +39,19 @@ public void ToggleMute() { _player.Volume = _player.Volume == 0.0 ? 0.5 : 0.0; } + + public void ToggleMute(double volume) + { + if (Muted) + { + _player.Volume = volume; + Muted = false; + } + else + { + _player.Volume = 0.0; + Muted = true; + } + } } } diff --git a/LunaticPlayer/PlayerInterface.xaml b/LunaticPlayer/PlayerInterface.xaml index b1c64fe..f569519 100644 --- a/LunaticPlayer/PlayerInterface.xaml +++ b/LunaticPlayer/PlayerInterface.xaml @@ -4,6 +4,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:LunaticPlayer" + xmlns:controls="clr-namespace:LunaticPlayer.Controls" mc:Ignorable="d" Title="Lunatic Player" Height="245" Width="375" Closed="Window_Closed" Loaded="Window_Loaded"> @@ -79,20 +80,27 @@ - + - - + + + + + - + - - + +