-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added volume bar, configuration and small fixes
- Loading branch information
Showing
12 changed files
with
239 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
|
||
/// <summary> | ||
/// The source of configuration data (Filesystem, Default Object, ...). | ||
/// </summary> | ||
public string Source { get; set; } | ||
|
||
public static Configuration GetInstance() | ||
{ | ||
if (_instance == null) | ||
{ | ||
_instance = new Configuration(); | ||
_instance.Initialize(); | ||
} | ||
|
||
return _instance; | ||
} | ||
|
||
/// <summary> | ||
/// Loads the configuration and stores it to the filesystem if necessary. | ||
/// </summary> | ||
private void Initialize() | ||
{ | ||
|
||
if (File.Exists(Filename)) | ||
{ | ||
Data = JsonConvert.DeserializeObject<ConfigurationData>(File.ReadAllText(Filename)); | ||
Source = "Filesystem"; | ||
} | ||
else | ||
{ | ||
Source = "DefaultDataObject"; | ||
|
||
SetupData(); | ||
|
||
// Erstellt eine Konfigurationsdatei für das nächste Mal. | ||
Save(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Creates a <seealso cref="ConfigurationData"/> object with default values. | ||
/// </summary> | ||
private void SetupData() | ||
{ | ||
var data = new ConfigurationData() | ||
{ | ||
Volume = 0.4 | ||
}; | ||
|
||
Data = data; | ||
} | ||
|
||
/// <summary> | ||
/// Saves the current configuration to the file specified at <see cref="Filename"/>. | ||
/// </summary> | ||
public void Save() | ||
{ | ||
Console.WriteLine("Saving configuration to filesystem."); | ||
File.WriteAllText(Filename, JsonConvert.SerializeObject(Data)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<UserControl x:Class="LunaticPlayer.Controls.VolumeBar" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:LunaticPlayer.Controls" | ||
mc:Ignorable="d" | ||
d:DesignHeight="50" d:DesignWidth="100"> | ||
<Grid Background="Transparent"> | ||
<Border Padding="5,15"> | ||
<Slider Name="VolumeSlider" Orientation="Horizontal" Maximum="1" Value="{Binding Volume}" ValueChanged="VolumeSlider_ValueChanged"/> | ||
</Border> | ||
</Grid> | ||
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} | ||
|
||
/// <summary> | ||
/// Interaktionslogik für VolumeBar.xaml | ||
/// </summary> | ||
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<double> e) | ||
{ | ||
Data.Volume = VolumeSlider.Value; | ||
|
||
OnValueChange?.Invoke(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Oops, something went wrong.