Added 'show key bindings' feature.

This commit is contained in:
2014-05-05 11:23:28 +03:00
parent 25b97fe51f
commit fb6791fee2
14 changed files with 3741 additions and 3616 deletions

View File

@ -1,164 +1,164 @@
<UserControl
x:Class="DrumKit.DrumsSettingsControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:DrumKit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="400"
d:DesignWidth="400">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Common/TextButtonStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
<DataTemplate x:Key="DrumsListDataTemplate">
<Grid Name="theGrid"
MinWidth="380">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- Left thing -->
<Border Name="yellowBorder"
Grid.Column="0" Grid.RowSpan="3"
Background="Yellow" Width="10" />
<!-- Thumbnail -->
<Image Grid.Row="0" Grid.RowSpan="2"
Grid.Column="2"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Width="60" Height="60"
Source="{Binding LoadedImageSource}"
Stretch="Uniform" />
<!-- Name -->
<TextBox Grid.Column="1" Grid.Row="0" Margin="15,2,15,0"
FontSize="15.3"
Style="{StaticResource MyTextBoxStyle}"
Text="{Binding Name}"
IsReadOnly="True" />
<!-- Configuration -->
<Grid
Grid.Column="1" Grid.Row="1" Margin="15,0,15,2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<ToggleButton
Name="toggleEnabled" Grid.Column="0"
Margin="0,-4,20,0" Padding="5,1"
Content="Enabled"
Click="ToggleEnabled_Click" />
<TextBlock
Grid.Column="1"
Style="{StaticResource TitleTextStyle}"
Text="Key:" />
<TextBox
Grid.Column="2"
Name="textKey"
Style="{StaticResource MyTextBoxStyle}"
KeyUp="TextKey_KeyUp" />
</Grid>
<Grid Grid.Column="1" Grid.Row="2" Margin="15,2,15,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock
Grid.Column="0"
Style="{StaticResource TitleTextStyle}"
Text="Volume left:" />
<Slider Name="sliderVolumeL"
Grid.Column="1"
Margin="5,-8,5,0"
Height="34"
Minimum="0" Maximum="1"
StepFrequency=".01"
ValueChanged="sliderVolumeL_ValueChanged"/>
<TextBlock
Margin="10,0,0,0"
Grid.Column="2"
Style="{StaticResource TitleTextStyle}"
Text="Right:" />
<Slider Name="sliderVolumeR"
Grid.Column="3"
Margin="5,-8,5,0"
Height="34"
Minimum="0" Maximum="1"
StepFrequency=".01"
ValueChanged="sliderVolumeR_ValueChanged" />
</Grid>
</Grid>
</DataTemplate>
<Style x:Key="GridViewStretchItemStyle" TargetType="GridViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<!-- Drums list -->
<GridView Name="listDrums"
Grid.Row="0" Grid.Column="0"
ItemTemplate="{StaticResource DrumsListDataTemplate}"
ItemContainerStyle="{StaticResource GridViewStretchItemStyle}"
SelectionMode="Single" >
<local:Drum ImageSource="/Assets/bg.png" Id="adda" Name="Hello world!" />
</GridView>
<!-- Buttons -->
<!--<StackPanel Grid.Row="1" Grid.ColumnSpan="2" Orientation="Horizontal">
<Button Style="{StaticResource MyButtonStyle}" Click="ButtonCreate_Click">Create</Button>
<Button Style="{StaticResource MyButtonStyle}" Click="ButtonDelete_Click">Delete</Button>
</StackPanel>-->
</Grid>
</UserControl>
<UserControl
x:Class="DrumKit.DrumsSettingsControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:DrumKit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="400"
d:DesignWidth="400">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Common/TextButtonStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
<DataTemplate x:Key="DrumsListDataTemplate">
<Grid Name="theGrid"
MinWidth="380">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- Left thing -->
<Border Name="yellowBorder"
Grid.Column="0" Grid.RowSpan="3"
Background="Yellow" Width="10" />
<!-- Thumbnail -->
<Image Grid.Row="0" Grid.RowSpan="2"
Grid.Column="2"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Width="60" Height="60"
Source="{Binding LoadedImageSource}"
Stretch="Uniform" />
<!-- Name -->
<TextBox Grid.Column="1" Grid.Row="0" Margin="15,2,15,0"
FontSize="15.3"
Style="{StaticResource MyTextBoxStyle}"
Text="{Binding Name}"
IsReadOnly="True" />
<!-- Configuration -->
<Grid
Grid.Column="1" Grid.Row="1" Margin="15,0,15,2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<ToggleButton
Name="toggleEnabled" Grid.Column="0"
Margin="0,-4,20,0" Padding="5,1"
Content="Visible"
Click="ToggleEnabled_Click" />
<TextBlock
Grid.Column="1"
Style="{StaticResource TitleTextStyle}"
Text="Key:" />
<TextBox
Grid.Column="2"
Name="textKey"
Style="{StaticResource MyTextBoxStyle}"
KeyUp="TextKey_KeyUp" />
</Grid>
<Grid Grid.Column="1" Grid.Row="2" Margin="15,2,15,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock
Grid.Column="0"
Style="{StaticResource TitleTextStyle}"
Text="Volume left:" />
<Slider Name="sliderVolumeL"
Grid.Column="1"
Margin="5,-8,5,0"
Height="34"
Minimum="0" Maximum="1"
StepFrequency=".01"
ValueChanged="sliderVolumeL_ValueChanged"/>
<TextBlock
Margin="10,0,0,0"
Grid.Column="2"
Style="{StaticResource TitleTextStyle}"
Text="Right:" />
<Slider Name="sliderVolumeR"
Grid.Column="3"
Margin="5,-8,5,0"
Height="34"
Minimum="0" Maximum="1"
StepFrequency=".01"
ValueChanged="sliderVolumeR_ValueChanged" />
</Grid>
</Grid>
</DataTemplate>
<Style x:Key="GridViewStretchItemStyle" TargetType="GridViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<!-- Drums list -->
<GridView Name="listDrums"
Grid.Row="0" Grid.Column="0"
ItemTemplate="{StaticResource DrumsListDataTemplate}"
ItemContainerStyle="{StaticResource GridViewStretchItemStyle}"
SelectionMode="Single" >
<local:Drum ImageSource="/Assets/bg.png" Id="adda" Name="Hello world!" />
</GridView>
<!-- Buttons -->
<!--<StackPanel Grid.Row="1" Grid.ColumnSpan="2" Orientation="Horizontal">
<Button Style="{StaticResource MyButtonStyle}" Click="ButtonCreate_Click">Create</Button>
<Button Style="{StaticResource MyButtonStyle}" Click="ButtonDelete_Click">Delete</Button>
</StackPanel>-->
</Grid>
</UserControl>

View File

@ -1,236 +1,221 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
namespace DrumKit
{
public sealed partial class DrumsSettingsControl : UserControl
{
#region Initialization
/// <summary>
/// Creates a new instance of DrumsSettingsControl
/// </summary>
public DrumsSettingsControl()
{
this.InitializeComponent();
this.Loaded += DrumsSettingsControl_Loaded;
}
/// <summary>
/// Loads drum list at startup
/// </summary>
void DrumsSettingsControl_Loaded(object sender, RoutedEventArgs e)
{
ReloadDrums();
}
#endregion
#region Reloads the list of drums
/// <summary>
/// Reloads the list of drums
/// </summary>
async void ReloadDrums()
{
// Clear previous stuff
listDrums.Items.Clear();
// Add new stuff
foreach (var i in DataController.CurrentDrumkit.Drums)
this.listDrums.Items.Add(i.Value);
// Wait for containers to be generated
await System.Threading.Tasks.Task.Delay(50);
// Update visual stuff
DrumConfig config = null;
foreach (var i in this.listDrums.Items)
{
// Get drum and configuration
var drum = i as Drum;
if (drum != null)
DataController.CurrentConfig.Drums.TryGetValue(drum.Id, out config);
// No drum, no configuration?
if (drum == null || config == null)
continue;
// Set up other properties
var container = listDrums.ItemContainerGenerator.ContainerFromItem(i) as FrameworkElement;
ToggleButton enabled = UIHelper.FindChildByName(container, "toggleEnabled") as ToggleButton;
if (enabled != null) enabled.IsChecked = config.IsEnabled;
Slider volumeL = UIHelper.FindChildByName(container, "sliderVolumeL") as Slider;
if (volumeL != null) volumeL.Value = config.VolumeL;
Slider volumeR = UIHelper.FindChildByName(container, "sliderVolumeR") as Slider;
if (volumeR != null) volumeR.Value = config.VolumeR;
}
ReloadKeys();
}
void ReloadKeys()
{
DrumConfig config = null;
foreach (var i in this.listDrums.Items)
{
// Get drum and configuration
var drum = i as Drum;
if (drum != null)
DataController.CurrentConfig.Drums.TryGetValue(drum.Id, out config);
// No drum, no configuration?
if (drum == null || config == null)
continue;
// Set up key
var container = listDrums.ItemContainerGenerator.ContainerFromItem(i) as FrameworkElement;
TextBox key = UIHelper.FindChildByName(container, "textKey") as TextBox;
if (key != null)
{
if (Enum.IsDefined(typeof(VirtualKey), config.Key))
{
// Get name
string text = Enum.GetName(typeof(VirtualKey), config.Key);
// Prettify the name
if (text.StartsWith("Number"))
text = text.Substring("Number".Length);
text = System.Text.RegularExpressions.Regex.Replace(text, "([a-z])([A-Z])", "${1} ${2}");
// Set the text
key.Text = text;
}
else key.Text = string.Format("Unnamed ({0})", (int)config.Key);
}
}
}
#endregion
#region UI Handlers: Items
/// <summary>
/// Handles "Landscape" toggle button.
/// </summary>
private void ToggleEnabled_Click(object sender, RoutedEventArgs e)
{
// Get drum object
var button = sender as ToggleButton;
var drum = (sender as FrameworkElement).DataContext as Drum;
// Change enabled property
if (drum != null && DataController.CurrentConfig.Drums.ContainsKey(drum.Id))
{
DataController.CurrentConfig.Drums[drum.Id].IsEnabled = button.IsChecked.HasValue && button.IsChecked.Value;
DataController.SaveConfig();
}
}
/// <summary>
/// Handles the "key press" event in the textbox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TextKey_KeyUp(object sender, KeyRoutedEventArgs e)
{
// Get drum object
var text = sender as TextBox;
var drum = (sender as FrameworkElement).DataContext as Drum;
// Set key
if (text != null && drum != null && DataController.CurrentConfig.Drums.ContainsKey(drum.Id))
{
// Remove duplicates
RemoveKeys(e.Key, drum.Id);
// Set key
DataController.CurrentConfig.Drums[drum.Id].Key = e.Key;
// Display
ReloadKeys();
// Save
DataController.SaveConfig();
}
}
private void sliderVolumeL_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
// Get drum object
var slider = sender as Slider;
var drum = (sender as FrameworkElement).DataContext as Drum;
// Set value
if (slider != null && drum != null && DataController.CurrentConfig.Drums.ContainsKey(drum.Id))
{
DataController.CurrentConfig.Drums[drum.Id].VolumeL = e.NewValue;
DataController.SaveConfig();
}
}
private void sliderVolumeR_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
// Get drum object
var slider = sender as Slider;
var drum = (sender as FrameworkElement).DataContext as Drum;
// Set value
if (slider != null && drum != null && DataController.CurrentConfig.Drums.ContainsKey(drum.Id))
{
DataController.CurrentConfig.Drums[drum.Id].VolumeR = e.NewValue;
DataController.SaveConfig();
}
}
#endregion
#region Misc
/// <summary>
/// Sets the keyboart shortcut to None for all the drums that have this key.
/// </summary>
/// <param name="key">The keyboard shortcut</param>
private void RemoveKeys(VirtualKey key, string exception_id=null)
{
// See if any other drum has the same key
foreach (var i in DataController.CurrentConfig.Drums)
if (i.Value.Key == key && i.Key != exception_id)
{
// Set to none
i.Value.Key = VirtualKey.None;
// Get drum
var drum = DataController.CurrentDrumkit.Drums[i.Key];
// Get key text box
var container = listDrums.ItemContainerGenerator.ContainerFromItem(drum) as FrameworkElement;
TextBox keytxt = UIHelper.FindChildByName(container, "textKey") as TextBox;
keytxt.Text = Enum.GetName(typeof(VirtualKey), i.Value.Key);
}
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
namespace DrumKit
{
public sealed partial class DrumsSettingsControl : UserControl
{
#region Initialization
/// <summary>
/// Creates a new instance of DrumsSettingsControl
/// </summary>
public DrumsSettingsControl()
{
this.InitializeComponent();
this.Loaded += DrumsSettingsControl_Loaded;
}
/// <summary>
/// Loads drum list at startup
/// </summary>
void DrumsSettingsControl_Loaded(object sender, RoutedEventArgs e)
{
ReloadDrums();
}
#endregion
#region Reloads the list of drums
/// <summary>
/// Reloads the list of drums
/// </summary>
async void ReloadDrums()
{
// Clear previous stuff
listDrums.Items.Clear();
// Add new stuff
foreach (var i in DataController.CurrentDrumkit.Drums)
this.listDrums.Items.Add(i.Value);
// Wait for containers to be generated
await System.Threading.Tasks.Task.Delay(50);
// Update visual stuff
DrumConfig config = null;
foreach (var i in this.listDrums.Items)
{
// Get drum and configuration
var drum = i as Drum;
if (drum != null)
DataController.CurrentConfig.Drums.TryGetValue(drum.Id, out config);
// No drum, no configuration?
if (drum == null || config == null)
continue;
// Set up other properties
var container = listDrums.ItemContainerGenerator.ContainerFromItem(i) as FrameworkElement;
ToggleButton enabled = UIHelper.FindChildByName(container, "toggleEnabled") as ToggleButton;
if (enabled != null) enabled.IsChecked = config.IsEnabled;
Slider volumeL = UIHelper.FindChildByName(container, "sliderVolumeL") as Slider;
if (volumeL != null) volumeL.Value = config.VolumeL;
Slider volumeR = UIHelper.FindChildByName(container, "sliderVolumeR") as Slider;
if (volumeR != null) volumeR.Value = config.VolumeR;
}
ReloadKeys();
}
void ReloadKeys()
{
DrumConfig config = null;
foreach (var i in this.listDrums.Items)
{
// Get drum and configuration
var drum = i as Drum;
if (drum != null)
DataController.CurrentConfig.Drums.TryGetValue(drum.Id, out config);
// No drum, no configuration?
if (drum == null || config == null)
continue;
// Set up key
var container = listDrums.ItemContainerGenerator.ContainerFromItem(i) as FrameworkElement;
TextBox key = UIHelper.FindChildByName(container, "textKey") as TextBox;
if (key != null)
{
key.Text = UIHelper.GetPrettifiedVKeyName(config.Key);
}
}
}
#endregion
#region UI Handlers: Items
/// <summary>
/// Handles "Landscape" toggle button.
/// </summary>
private void ToggleEnabled_Click(object sender, RoutedEventArgs e)
{
// Get drum object
var button = sender as ToggleButton;
var drum = (sender as FrameworkElement).DataContext as Drum;
// Change enabled property
if (drum != null && DataController.CurrentConfig.Drums.ContainsKey(drum.Id))
{
DataController.CurrentConfig.Drums[drum.Id].IsEnabled = button.IsChecked.HasValue && button.IsChecked.Value;
DataController.SaveConfig();
}
}
/// <summary>
/// Handles the "key press" event in the textbox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TextKey_KeyUp(object sender, KeyRoutedEventArgs e)
{
// Get drum object
var text = sender as TextBox;
var drum = (sender as FrameworkElement).DataContext as Drum;
// Set key
if (text != null && drum != null && DataController.CurrentConfig.Drums.ContainsKey(drum.Id))
{
// Remove duplicates
RemoveKeys(e.Key, drum.Id);
// Set key
DataController.CurrentConfig.Drums[drum.Id].Key = e.Key;
// Display
ReloadKeys();
// Save
DataController.SaveConfig();
}
}
private void sliderVolumeL_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
// Get drum object
var slider = sender as Slider;
var drum = (sender as FrameworkElement).DataContext as Drum;
// Set value
if (slider != null && drum != null && DataController.CurrentConfig.Drums.ContainsKey(drum.Id))
{
DataController.CurrentConfig.Drums[drum.Id].VolumeL = e.NewValue;
DataController.SaveConfig();
}
}
private void sliderVolumeR_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
// Get drum object
var slider = sender as Slider;
var drum = (sender as FrameworkElement).DataContext as Drum;
// Set value
if (slider != null && drum != null && DataController.CurrentConfig.Drums.ContainsKey(drum.Id))
{
DataController.CurrentConfig.Drums[drum.Id].VolumeR = e.NewValue;
DataController.SaveConfig();
}
}
#endregion
#region Misc
/// <summary>
/// Sets the keyboart shortcut to None for all the drums that have this key.
/// </summary>
/// <param name="key">The keyboard shortcut</param>
private void RemoveKeys(VirtualKey key, string exception_id=null)
{
// See if any other drum has the same key
foreach (var i in DataController.CurrentConfig.Drums)
if (i.Value.Key == key && i.Key != exception_id)
{
// Set to none
i.Value.Key = VirtualKey.None;
// Get drum
var drum = DataController.CurrentDrumkit.Drums[i.Key];
// Get key text box
var container = listDrums.ItemContainerGenerator.ContainerFromItem(drum) as FrameworkElement;
TextBox keytxt = UIHelper.FindChildByName(container, "textKey") as TextBox;
keytxt.Text = Enum.GetName(typeof(VirtualKey), i.Value.Key);
}
}
#endregion
}
}

View File

@ -1,174 +1,174 @@
<UserControl
x:Class="DrumKit.GeneralSettingsControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:DrumKit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="635.463"
d:DesignWidth="1075.987">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.Resources>
<Style x:Key="MyTitleTextStyle" TargetType="TextBlock" BasedOn="{StaticResource TitleTextStyle}">
<Setter Property="Margin" Value="20,24,2,2" />
<Setter Property="Foreground" Value="#59FFFF" />
</Style>
<Style x:Key="MyItemTextStyle" TargetType="TextBlock" BasedOn="{StaticResource ItemTextStyle}">
<Setter Property="Margin" Value="2,12,2,2" />
</Style>
</Grid.Resources>
<!-- About section -->
<TextBlock Style="{StaticResource MyTitleTextStyle}"
Grid.Row="0" Margin="20,4,2,2">
About</TextBlock>
<!-- About section: Website -->
<TextBlock Style="{StaticResource ItemTextStyle}"
Grid.Row="1" Margin="2,12,2,2">
Drumkit website</TextBlock>
<Button Name="buttonWebsite"
Style="{StaticResource TextButtonStyle}"
Grid.Row="1" Grid.Column="1" VerticalAlignment="Bottom">
drumkit8.blogspot.com</Button>
<!-- About section: Support -->
<TextBlock Style="{StaticResource ItemTextStyle}"
Grid.Row="2" Margin="2,12,2,2">
Support</TextBlock>
<Button Name="buttonSupport"
Style="{StaticResource TextButtonStyle}"
Grid.Row="2" Grid.Column="1" VerticalAlignment="Bottom">
chibicitiberiu@outlook.com</Button>
<!-- About section: Version -->
<TextBlock Style="{StaticResource ItemTextStyle}"
Grid.Row="3" Margin="2,12,2,2">
Version</TextBlock>
<TextBlock Name="textVersion"
Grid.Row="3" Grid.Column="1" VerticalAlignment="Bottom"
Margin="0,2,2,2"
Style="{StaticResource BodyTextStyle}" >
1.0
</TextBlock>
<!-- Sound section -->
<TextBlock Style="{StaticResource MyTitleTextStyle}"
Grid.Row="6">
Sound</TextBlock>
<!-- Sound section: Master volume -->
<TextBlock Style="{StaticResource ItemTextStyle}"
Grid.Row="7" Margin="2,7,2,2">
Master volume</TextBlock>
<Slider Name="masterVolumeSlider"
Grid.Row="7" Grid.Column="1"
Minimum="0" Maximum="100"
StepFrequency="1"
SmallChange=".05" LargeChange=".2"
Width="100" Height="48"
HorizontalAlignment="Left"/>
<!-- Sound section: Polyphony -->
<TextBlock Style="{StaticResource ItemTextStyle}"
Grid.Row="8" Margin="2,7,2,2">
Polyphony*</TextBlock>
<Slider Name="polyphonySlider"
Grid.Row="8" Grid.Column="1"
Minimum="1" Maximum="256"
StepFrequency="1"
SmallChange="1" LargeChange="5"
Width="100" Height="48"
HorizontalAlignment="Left"/>
<!-- Interface section -->
<TextBlock Style="{StaticResource MyTitleTextStyle}"
Grid.Row="9">
Interface</TextBlock>
<!-- Interface section: Animations -->
<TextBlock Style="{StaticResource ItemTextStyle}"
Grid.Row="10" Margin="2,12,2,2">
Animations</TextBlock>
<ToggleSwitch Name="animationsToggle"
Grid.Row="10" Grid.Column="1"/>
<!-- Interface section: Key bindings -->
<!--<TextBlock Style="{StaticResource ItemTextStyle}"
Grid.Row="11" Margin="2,12,2,2">
Display key bindings</TextBlock>
<ToggleSwitch Name="keyBindingsToggle"
Grid.Row="11" Grid.Column="1"/>-->
<!-- Miscellaneous section -->
<TextBlock Style="{StaticResource MyTitleTextStyle}"
Grid.Row="12">
Miscellaneous</TextBlock>
<!-- Miscellaneous section: Debugging mode -->
<TextBlock Style="{StaticResource ItemTextStyle}"
Grid.Row="13" Margin="2,12,2,2">
Debugging mode</TextBlock>
<ToggleSwitch Name="debuggingModeToggle"
Grid.Row="13" Grid.Column="1"/>
<TextBlock Style="{StaticResource ItemTextStyle}"
Grid.Row="14" Margin="2,12,2,2">
Factory reset*</TextBlock>
<Button Name="buttonReset"
Style="{StaticResource TextButtonStyle}"
Grid.Row="14" Grid.Column="1" VerticalAlignment="Bottom">
Reset</Button>
<!-- Notes section -->
<TextBlock Grid.Row="100" Style="{StaticResource MyItemTextStyle}"
FontSize="11"
Foreground="Silver">
* Will be applied after the application is restarted.
</TextBlock>
</Grid>
</UserControl>
<UserControl
x:Class="DrumKit.GeneralSettingsControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:DrumKit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="635.463"
d:DesignWidth="1075.987">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.Resources>
<Style x:Key="MyTitleTextStyle" TargetType="TextBlock" BasedOn="{StaticResource TitleTextStyle}">
<Setter Property="Margin" Value="20,24,2,2" />
<Setter Property="Foreground" Value="#59FFFF" />
</Style>
<Style x:Key="MyItemTextStyle" TargetType="TextBlock" BasedOn="{StaticResource ItemTextStyle}">
<Setter Property="Margin" Value="2,12,2,2" />
</Style>
</Grid.Resources>
<!-- About section -->
<TextBlock Style="{StaticResource MyTitleTextStyle}"
Grid.Row="0" Margin="20,4,2,2">
About</TextBlock>
<!-- About section: Website -->
<TextBlock Style="{StaticResource ItemTextStyle}"
Grid.Row="1" Margin="2,12,2,2">
Drumkit website</TextBlock>
<Button Name="buttonWebsite"
Style="{StaticResource TextButtonStyle}"
Grid.Row="1" Grid.Column="1" VerticalAlignment="Bottom">
drumkit8.blogspot.com</Button>
<!-- About section: Support -->
<TextBlock Style="{StaticResource ItemTextStyle}"
Grid.Row="2" Margin="2,12,2,2">
Support</TextBlock>
<Button Name="buttonSupport"
Style="{StaticResource TextButtonStyle}"
Grid.Row="2" Grid.Column="1" VerticalAlignment="Bottom">
chibicitiberiu@outlook.com</Button>
<!-- About section: Version -->
<TextBlock Style="{StaticResource ItemTextStyle}"
Grid.Row="3" Margin="2,12,2,2">
Version</TextBlock>
<TextBlock Name="textVersion"
Grid.Row="3" Grid.Column="1" VerticalAlignment="Bottom"
Margin="0,2,2,2"
Style="{StaticResource BodyTextStyle}" >
1.0
</TextBlock>
<!-- Sound section -->
<TextBlock Style="{StaticResource MyTitleTextStyle}"
Grid.Row="6">
Sound</TextBlock>
<!-- Sound section: Master volume -->
<TextBlock Style="{StaticResource ItemTextStyle}"
Grid.Row="7" Margin="2,7,2,2">
Master volume</TextBlock>
<Slider Name="masterVolumeSlider"
Grid.Row="7" Grid.Column="1"
Minimum="0" Maximum="100"
StepFrequency="1"
SmallChange=".05" LargeChange=".2"
Width="100" Height="48"
HorizontalAlignment="Left"/>
<!-- Sound section: Polyphony -->
<TextBlock Style="{StaticResource ItemTextStyle}"
Grid.Row="8" Margin="2,7,2,2">
Polyphony*</TextBlock>
<Slider Name="polyphonySlider"
Grid.Row="8" Grid.Column="1"
Minimum="1" Maximum="256"
StepFrequency="1"
SmallChange="1" LargeChange="5"
Width="100" Height="48"
HorizontalAlignment="Left"/>
<!-- Interface section -->
<TextBlock Style="{StaticResource MyTitleTextStyle}"
Grid.Row="9">
Interface</TextBlock>
<!-- Interface section: Animations -->
<TextBlock Style="{StaticResource ItemTextStyle}"
Grid.Row="10" Margin="2,12,2,2">
Animations</TextBlock>
<ToggleSwitch Name="animationsToggle"
Grid.Row="10" Grid.Column="1"/>
<!-- Interface section: Key bindings -->
<TextBlock Style="{StaticResource ItemTextStyle}"
Grid.Row="11" Margin="2,12,2,2">
Display key bindings</TextBlock>
<ToggleSwitch Name="keyBindingsToggle"
Grid.Row="11" Grid.Column="1"/>
<!-- Miscellaneous section -->
<TextBlock Style="{StaticResource MyTitleTextStyle}"
Grid.Row="12">
Miscellaneous</TextBlock>
<!-- Miscellaneous section: Debugging mode -->
<TextBlock Style="{StaticResource ItemTextStyle}"
Grid.Row="13" Margin="2,12,2,2">
Debugging mode</TextBlock>
<ToggleSwitch Name="debuggingModeToggle"
Grid.Row="13" Grid.Column="1"/>
<TextBlock Style="{StaticResource ItemTextStyle}"
Grid.Row="14" Margin="2,12,2,2">
Factory reset*</TextBlock>
<Button Name="buttonReset"
Style="{StaticResource TextButtonStyle}"
Grid.Row="14" Grid.Column="1" VerticalAlignment="Bottom">
Reset</Button>
<!-- Notes section -->
<TextBlock Grid.Row="100" Style="{StaticResource MyItemTextStyle}"
FontSize="11"
Foreground="Silver">
* Will be applied after the application is restarted.
</TextBlock>
</Grid>
</UserControl>

View File

@ -1,120 +1,120 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Reflection;
using Windows.UI.Popups;
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
namespace DrumKit
{
public sealed partial class GeneralSettingsControl : UserControl
{
public GeneralSettingsControl()
{
this.InitializeComponent();
this.LoadSettings();
}
private void LoadSettings()
{
// Version
var version = typeof(GeneralSettingsControl).GetTypeInfo().Assembly.GetName().Version;
this.textVersion.Text = String.Format("{0}.{1}", version.Major, version.Minor);
// Other
this.masterVolumeSlider.Value = DataController.MasterVolume * 100;
this.polyphonySlider.Value = DataController.Settings.Polyphony;
this.animationsToggle.IsOn = DataController.Settings.Animations;
//this.keyBindingsToggle.IsOn = DataController.Settings.ShowKeyBindings;
this.debuggingModeToggle.IsOn = DataController.Settings.DebugMode;
// Set up events
masterVolumeSlider.ValueChanged += masterVolumeSlider_ValueChanged;
polyphonySlider.ValueChanged += polyphonySlider_ValueChanged;
animationsToggle.Toggled += animationsToggle_Toggled;
//keyBindingsToggle.Toggled += keyBindingsToggle_Toggled;
buttonWebsite.Click += buttonWebsite_Click;
buttonSupport.Click += buttonSupport_Click;
buttonReset.Click += buttonReset_Click;
debuggingModeToggle.Toggled += debuggingModeToggle_Toggled;
}
private void masterVolumeSlider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
DataController.MasterVolume = Convert.ToSingle(masterVolumeSlider.Value) / 100.0f;
DataController.SaveSettings();
}
void polyphonySlider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
DataController.Settings.Polyphony = Convert.ToInt32(polyphonySlider.Value);
DataController.SaveSettings();
}
private void animationsToggle_Toggled(object sender, RoutedEventArgs e)
{
DataController.Settings.Animations = this.animationsToggle.IsOn;
DataController.SaveSettings();
}
//private void keyBindingsToggle_Toggled(object sender, RoutedEventArgs e)
//{
// DataController.Settings.ShowKeyBindings = this.keyBindingsToggle.IsOn;
// DataController.SaveSettings();
//}
private async void buttonWebsite_Click(object sender, RoutedEventArgs e)
{
await Windows.System.Launcher.LaunchUriAsync(new Uri("http://drumkit8.blogspot.com/"));
}
private async void buttonSupport_Click(object sender, RoutedEventArgs e)
{
await Windows.System.Launcher.LaunchUriAsync(new Uri("mailto:chibicitiberiu@outlook.com"));
}
private async void buttonReset_Click(object sender, RoutedEventArgs e)
{
// Notify that the application needs to be restarted
MessageDialog dialog = new MessageDialog("The application needs to be restarted in " +
"order to reset to factory settings. Note that every customisation will be deleted.",
"Application restart required");
dialog.Commands.Add(new UICommand("Continue", new UICommandInvokedHandler(UICommandFactoryResetHandler)));
dialog.Commands.Add(new UICommand("Cancel"));
dialog.DefaultCommandIndex = 1;
await dialog.ShowAsync();
}
/// <summary>
/// UI Command that restarts the application, when current drumkit changes
/// </summary>
private void UICommandFactoryResetHandler(Windows.UI.Popups.IUICommand cmd)
{
if (Window.Current.Content is Frame)
{
Frame frame = (Frame) Window.Current.Content;
frame.Navigate(typeof(LoadingPage), "reset");
}
}
private void debuggingModeToggle_Toggled(object sender, RoutedEventArgs e)
{
DataController.Settings.DebugMode = this.debuggingModeToggle.IsOn;
DataController.SaveSettings();
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Reflection;
using Windows.UI.Popups;
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
namespace DrumKit
{
public sealed partial class GeneralSettingsControl : UserControl
{
public GeneralSettingsControl()
{
this.InitializeComponent();
this.LoadSettings();
}
private void LoadSettings()
{
// Version
var version = typeof(GeneralSettingsControl).GetTypeInfo().Assembly.GetName().Version;
this.textVersion.Text = String.Format("{0}.{1}", version.Major, version.Minor);
// Other
this.masterVolumeSlider.Value = DataController.MasterVolume * 100;
this.polyphonySlider.Value = DataController.Settings.Polyphony;
this.animationsToggle.IsOn = DataController.Settings.Animations;
this.keyBindingsToggle.IsOn = DataController.Settings.ShowKeyBindings;
this.debuggingModeToggle.IsOn = DataController.Settings.DebugMode;
// Set up events
masterVolumeSlider.ValueChanged += masterVolumeSlider_ValueChanged;
polyphonySlider.ValueChanged += polyphonySlider_ValueChanged;
animationsToggle.Toggled += animationsToggle_Toggled;
keyBindingsToggle.Toggled += keyBindingsToggle_Toggled;
buttonWebsite.Click += buttonWebsite_Click;
buttonSupport.Click += buttonSupport_Click;
buttonReset.Click += buttonReset_Click;
debuggingModeToggle.Toggled += debuggingModeToggle_Toggled;
}
private void masterVolumeSlider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
DataController.MasterVolume = Convert.ToSingle(masterVolumeSlider.Value) / 100.0f;
DataController.SaveSettings();
}
void polyphonySlider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
DataController.Settings.Polyphony = Convert.ToInt32(polyphonySlider.Value);
DataController.SaveSettings();
}
private void animationsToggle_Toggled(object sender, RoutedEventArgs e)
{
DataController.Settings.Animations = this.animationsToggle.IsOn;
DataController.SaveSettings();
}
private void keyBindingsToggle_Toggled(object sender, RoutedEventArgs e)
{
DataController.Settings.ShowKeyBindings = this.keyBindingsToggle.IsOn;
DataController.SaveSettings();
}
private async void buttonWebsite_Click(object sender, RoutedEventArgs e)
{
await Windows.System.Launcher.LaunchUriAsync(new Uri("http://drumkit8.blogspot.com/"));
}
private async void buttonSupport_Click(object sender, RoutedEventArgs e)
{
await Windows.System.Launcher.LaunchUriAsync(new Uri("mailto:chibicitiberiu@outlook.com"));
}
private async void buttonReset_Click(object sender, RoutedEventArgs e)
{
// Notify that the application needs to be restarted
MessageDialog dialog = new MessageDialog("The application needs to be restarted in " +
"order to reset to factory settings. Note that every customisation will be deleted.",
"Application restart required");
dialog.Commands.Add(new UICommand("Continue", new UICommandInvokedHandler(UICommandFactoryResetHandler)));
dialog.Commands.Add(new UICommand("Cancel"));
dialog.DefaultCommandIndex = 1;
await dialog.ShowAsync();
}
/// <summary>
/// UI Command that restarts the application, when current drumkit changes
/// </summary>
private void UICommandFactoryResetHandler(Windows.UI.Popups.IUICommand cmd)
{
if (Window.Current.Content is Frame)
{
Frame frame = (Frame) Window.Current.Content;
frame.Navigate(typeof(LoadingPage), "reset");
}
}
private void debuggingModeToggle_Toggled(object sender, RoutedEventArgs e)
{
DataController.Settings.DebugMode = this.debuggingModeToggle.IsOn;
DataController.SaveSettings();
}
}
}