mirror of
https://github.com/chibicitiberiu/drumkit.git
synced 2024-02-24 10:53:32 +00:00
Added 'show key bindings' feature.
This commit is contained in:
@ -1,65 +1,88 @@
|
||||
<UserControl
|
||||
x:Class="DrumKit.DrumPlayUI"
|
||||
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="300"
|
||||
d:DesignWidth="400">
|
||||
|
||||
<Grid Name="grid" Background="Transparent"
|
||||
PointerPressed="Grid_PointerPressed">
|
||||
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
|
||||
<VisualStateGroup x:Name="DrumGroups">
|
||||
|
||||
<VisualState x:Name="DrumNormal">
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="imagePressed"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
BeginTime="0:0:0.1" Duration="0:0:0.7" To="0" >
|
||||
<DoubleAnimation.EasingFunction>
|
||||
<SineEase EasingMode="EaseInOut" />
|
||||
</DoubleAnimation.EasingFunction>
|
||||
</DoubleAnimation>
|
||||
|
||||
<DoubleAnimation Storyboard.TargetName="image"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
Duration="0:0:0.3" To="1" >
|
||||
<DoubleAnimation.EasingFunction>
|
||||
<SineEase EasingMode="EaseIn" />
|
||||
</DoubleAnimation.EasingFunction>
|
||||
</DoubleAnimation>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
|
||||
<VisualState x:Name="DrumHit">
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="imagePressed"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
Duration="0" To="1" />
|
||||
<DoubleAnimation Storyboard.TargetName="image"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
Duration="0" To=".3" />
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
|
||||
|
||||
</VisualStateGroup>
|
||||
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
|
||||
<Image Name="image" IsHitTestVisible="False"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch" />
|
||||
|
||||
<Image Name="imagePressed" IsHitTestVisible="False"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Opacity="0" />
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
<UserControl
|
||||
x:Class="DrumKit.DrumPlayUI"
|
||||
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="300"
|
||||
d:DesignWidth="400">
|
||||
|
||||
<Grid Background="Transparent">
|
||||
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
|
||||
<VisualStateGroup x:Name="DrumGroups">
|
||||
|
||||
<VisualState x:Name="DrumNormal">
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="imagePressed"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
BeginTime="0:0:0.1" Duration="0:0:0.7" To="0" >
|
||||
<DoubleAnimation.EasingFunction>
|
||||
<SineEase EasingMode="EaseInOut" />
|
||||
</DoubleAnimation.EasingFunction>
|
||||
</DoubleAnimation>
|
||||
|
||||
<DoubleAnimation Storyboard.TargetName="image"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
Duration="0:0:0.3" To="1" >
|
||||
<DoubleAnimation.EasingFunction>
|
||||
<SineEase EasingMode="EaseIn" />
|
||||
</DoubleAnimation.EasingFunction>
|
||||
</DoubleAnimation>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
|
||||
<VisualState x:Name="DrumHit">
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="imagePressed"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
Duration="0" To="1" />
|
||||
<DoubleAnimation Storyboard.TargetName="image"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
Duration="0" To=".3" />
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
|
||||
|
||||
</VisualStateGroup>
|
||||
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
|
||||
|
||||
<Grid Name="grid" Background="Transparent"
|
||||
PointerPressed="Grid_PointerPressed">
|
||||
|
||||
<Image Name="image" IsHitTestVisible="False"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch" />
|
||||
|
||||
<Image Name="imagePressed" IsHitTestVisible="False"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Opacity="0" />
|
||||
</Grid>
|
||||
|
||||
|
||||
<TextBlock Name="textKeyShadow"
|
||||
Text="{Binding ElementName=textKey, Path=Text}"
|
||||
Style="{StaticResource TitleTextStyle}"
|
||||
Foreground="Black"
|
||||
IsHitTestVisible="False"
|
||||
VerticalAlignment="Bottom"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="2,0,0,13"
|
||||
Opacity="0.6" />
|
||||
|
||||
<TextBlock Name="textKey"
|
||||
IsHitTestVisible="False"
|
||||
Style="{StaticResource TitleTextStyle}"
|
||||
VerticalAlignment="Bottom"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,0,0,14"
|
||||
Opacity="0.8" />
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
@ -1,122 +1,162 @@
|
||||
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;
|
||||
|
||||
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
|
||||
|
||||
namespace DrumKit
|
||||
{
|
||||
public sealed partial class DrumPlayUI : UserControl
|
||||
{
|
||||
#region Public events
|
||||
public event PointerEventHandler Hit;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// Gets or sets the rotation of the drum
|
||||
/// </summary>
|
||||
public double Angle
|
||||
{
|
||||
get
|
||||
{
|
||||
// Get rotated grid
|
||||
var transform = grid.RenderTransform as RotateTransform;
|
||||
|
||||
// Get angle
|
||||
if (transform != null)
|
||||
return transform.Angle;
|
||||
|
||||
// No rotation
|
||||
return 0;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
// Set rotation transformation
|
||||
RotateTransform rot = new RotateTransform();
|
||||
rot.CenterX = this.Width / 2;
|
||||
rot.CenterY = this.Height / 2;
|
||||
rot.Angle = value;
|
||||
|
||||
grid.RenderTransform = rot;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the drum id.
|
||||
/// </summary>
|
||||
public string DrumID { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Enables or disables the hit animation.
|
||||
/// </summary>
|
||||
private bool IsAnimationEnabled {
|
||||
get {
|
||||
return DataController.Settings.Animations;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of DrumPlayUI
|
||||
/// </summary>
|
||||
/// <param name="drum"></param>
|
||||
public DrumPlayUI(Drum drum)
|
||||
{
|
||||
// Initialize
|
||||
this.InitializeComponent();
|
||||
|
||||
// Set drum properties
|
||||
this.DrumID = drum.Id;
|
||||
// TODO: key
|
||||
this.image.Source = drum.LoadedImageSource;
|
||||
this.imagePressed.Source = drum.LoadedImagePressedSource;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI handlers
|
||||
/// <summary>
|
||||
/// Handles the drum pressed event.
|
||||
/// </summary>
|
||||
private void Grid_PointerPressed(object sender, PointerRoutedEventArgs e)
|
||||
{
|
||||
// Call hit event immediately
|
||||
if (this.Hit != null)
|
||||
this.Hit(this, e);
|
||||
|
||||
// Play animation
|
||||
this.PerformHit();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Misc
|
||||
|
||||
public void PerformHit()
|
||||
{
|
||||
// Play animation
|
||||
if (this.IsAnimationEnabled)
|
||||
{
|
||||
VisualStateManager.GoToState(this, "DrumHit", true);
|
||||
VisualStateManager.GoToState(this, "DrumNormal", true);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
||||
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
|
||||
|
||||
namespace DrumKit
|
||||
{
|
||||
public sealed partial class DrumPlayUI : UserControl
|
||||
{
|
||||
#region Public events
|
||||
public event PointerEventHandler Hit;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// Gets or sets the rotation of the drum
|
||||
/// </summary>
|
||||
public double Angle
|
||||
{
|
||||
get
|
||||
{
|
||||
// Get rotated grid
|
||||
var transform = grid.RenderTransform as RotateTransform;
|
||||
|
||||
// Get angle
|
||||
if (transform != null)
|
||||
return transform.Angle;
|
||||
|
||||
// No rotation
|
||||
return 0;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
// Set rotation transformation
|
||||
RotateTransform rot = new RotateTransform();
|
||||
rot.CenterX = this.Width / 2;
|
||||
rot.CenterY = this.Height / 2;
|
||||
rot.Angle = value;
|
||||
|
||||
grid.RenderTransform = rot;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the drum id.
|
||||
/// </summary>
|
||||
public string DrumID { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Enables or disables the hit animation.
|
||||
/// </summary>
|
||||
private bool IsAnimationEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return DataController.Settings.Animations;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the key string for display
|
||||
/// </summary>
|
||||
public string KeyString
|
||||
{
|
||||
set
|
||||
{
|
||||
if (!String.IsNullOrEmpty(value))
|
||||
this.textKey.Text = String.Format("{0} [{1}]", DrumName, value);
|
||||
|
||||
else this.textKey.Text = DrumName;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating if the key is visible
|
||||
/// </summary>
|
||||
public bool IsKeyVisible
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.textKey.Visibility == Windows.UI.Xaml.Visibility.Visible;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.textKey.Visibility = (value) ? Visibility.Visible : Visibility.Collapsed;
|
||||
this.textKeyShadow.Visibility = (value) ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the drum name
|
||||
/// </summary>
|
||||
private string DrumName { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of DrumPlayUI
|
||||
/// </summary>
|
||||
/// <param name="drum"></param>
|
||||
public DrumPlayUI(Drum drum)
|
||||
{
|
||||
// Initialize
|
||||
this.InitializeComponent();
|
||||
|
||||
// Set drum properties
|
||||
this.DrumID = drum.Id;
|
||||
this.DrumName = drum.Name;
|
||||
this.KeyString = null;
|
||||
this.image.Source = drum.LoadedImageSource;
|
||||
this.imagePressed.Source = drum.LoadedImagePressedSource;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI handlers
|
||||
/// <summary>
|
||||
/// Handles the drum pressed event.
|
||||
/// </summary>
|
||||
private void Grid_PointerPressed(object sender, PointerRoutedEventArgs e)
|
||||
{
|
||||
// Call hit event immediately
|
||||
if (this.Hit != null)
|
||||
this.Hit(this, e);
|
||||
|
||||
// Play animation
|
||||
this.PerformHit();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Misc
|
||||
|
||||
public void PerformHit()
|
||||
{
|
||||
// Play animation
|
||||
if (this.IsAnimationEnabled)
|
||||
{
|
||||
VisualStateManager.GoToState(this, "DrumHit", true);
|
||||
VisualStateManager.GoToState(this, "DrumNormal", true);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -1,97 +1,104 @@
|
||||
<Page
|
||||
x:Class="DrumKit.MainPage"
|
||||
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">
|
||||
|
||||
<Page.Resources>
|
||||
|
||||
<ImageBrush x:Key="MainpageBackgroundBrush" ImageSource="ms-appx:///Assets/bg.png" Stretch="UniformToFill" />
|
||||
|
||||
</Page.Resources>
|
||||
|
||||
<Grid
|
||||
Background="{StaticResource MainpageBackgroundBrush}">
|
||||
|
||||
<Canvas Name="canvas" />
|
||||
|
||||
<!--<Grid Visibility="Collapsed">
|
||||
<Border Margin="7"
|
||||
CornerRadius="10"
|
||||
BorderBrush="Red"
|
||||
BorderThickness="5" />
|
||||
|
||||
<Canvas Name="recCanvas">
|
||||
<Ellipse Width="18" Height="18" Fill="Red"
|
||||
Canvas.Left="20"
|
||||
Canvas.Top="20"/>
|
||||
<TextBlock
|
||||
FontFamily="Consolas"
|
||||
FontSize="16"
|
||||
Foreground="Red"
|
||||
Canvas.Left="42"
|
||||
Canvas.Top="19">REC
|
||||
</TextBlock>
|
||||
|
||||
<Canvas.Triggers>
|
||||
<EventTrigger RoutedEvent="Canvas.Loaded">
|
||||
<BeginStoryboard>
|
||||
<Storyboard RepeatBehavior="Forever" >
|
||||
<DoubleAnimation
|
||||
Storyboard.TargetName="recCanvas"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
Duration="0:0:1" BeginTime="0:0:1" From="1" To="0.1" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</EventTrigger>
|
||||
</Canvas.Triggers>
|
||||
</Canvas>
|
||||
<StackPanel Orientation="Horizontal"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top">
|
||||
<Button>Record</Button>
|
||||
<Button>Stop</Button>
|
||||
</StackPanel>
|
||||
</Grid>-->
|
||||
|
||||
</Grid>
|
||||
|
||||
|
||||
<Page.BottomAppBar>
|
||||
<AppBar>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackPanel Grid.Column="0" Orientation="Horizontal">
|
||||
|
||||
<ToggleButton
|
||||
Name="buttonAnimations"
|
||||
Click="buttonAnimations_Click"
|
||||
AutomationProperties.Name="Animations"
|
||||
IsChecked="True"
|
||||
Style="{StaticResource VideoAppBarButtonStyle}" />
|
||||
|
||||
<Button
|
||||
Name="buttonEditMode"
|
||||
Click="ButtonEditMode_Click"
|
||||
Style="{StaticResource EditAppBarButtonStyle}" />
|
||||
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal" >
|
||||
<Button
|
||||
Name="buttonSettings"
|
||||
Click="ButtonSettings_Click"
|
||||
AutomationProperties.Name="Settings"
|
||||
Style="{StaticResource SettingsAppBarButtonStyle}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</AppBar>
|
||||
</Page.BottomAppBar>
|
||||
</Page>
|
||||
<Page
|
||||
x:Class="DrumKit.MainPage"
|
||||
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">
|
||||
|
||||
<Page.Resources>
|
||||
|
||||
<ImageBrush x:Key="MainpageBackgroundBrush" ImageSource="ms-appx:///Assets/bg.png" Stretch="UniformToFill" />
|
||||
|
||||
</Page.Resources>
|
||||
|
||||
<Grid
|
||||
Background="{StaticResource MainpageBackgroundBrush}">
|
||||
|
||||
<Canvas Name="canvas" />
|
||||
|
||||
<!--<Grid Visibility="Collapsed">
|
||||
<Border Margin="7"
|
||||
CornerRadius="10"
|
||||
BorderBrush="Red"
|
||||
BorderThickness="5" />
|
||||
|
||||
<Canvas Name="recCanvas">
|
||||
<Ellipse Width="18" Height="18" Fill="Red"
|
||||
Canvas.Left="20"
|
||||
Canvas.Top="20"/>
|
||||
<TextBlock
|
||||
FontFamily="Consolas"
|
||||
FontSize="16"
|
||||
Foreground="Red"
|
||||
Canvas.Left="42"
|
||||
Canvas.Top="19">REC
|
||||
</TextBlock>
|
||||
|
||||
<Canvas.Triggers>
|
||||
<EventTrigger RoutedEvent="Canvas.Loaded">
|
||||
<BeginStoryboard>
|
||||
<Storyboard RepeatBehavior="Forever" >
|
||||
<DoubleAnimation
|
||||
Storyboard.TargetName="recCanvas"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
Duration="0:0:1" BeginTime="0:0:1" From="1" To="0.1" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</EventTrigger>
|
||||
</Canvas.Triggers>
|
||||
</Canvas>
|
||||
<StackPanel Orientation="Horizontal"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top">
|
||||
<Button>Record</Button>
|
||||
<Button>Stop</Button>
|
||||
</StackPanel>
|
||||
</Grid>-->
|
||||
|
||||
</Grid>
|
||||
|
||||
|
||||
<Page.BottomAppBar>
|
||||
<AppBar>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackPanel Grid.Column="0" Orientation="Horizontal">
|
||||
|
||||
<ToggleButton
|
||||
Name="buttonAnimations"
|
||||
Click="buttonAnimations_Click"
|
||||
AutomationProperties.Name="Animations"
|
||||
IsChecked="True"
|
||||
Style="{StaticResource VideoAppBarButtonStyle}" />
|
||||
|
||||
<Button
|
||||
Name="buttonEditMode"
|
||||
Click="ButtonEditMode_Click"
|
||||
Style="{StaticResource EditAppBarButtonStyle}" />
|
||||
|
||||
<ToggleButton
|
||||
Name="buttonKeys"
|
||||
Click="buttonKeys_Click"
|
||||
AutomationProperties.Name="Show keys"
|
||||
IsChecked="True"
|
||||
Style="{StaticResource KeyboardAppBarButtonStyle}" />
|
||||
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal" >
|
||||
<Button
|
||||
Name="buttonSettings"
|
||||
Click="ButtonSettings_Click"
|
||||
AutomationProperties.Name="Settings"
|
||||
Style="{StaticResource SettingsAppBarButtonStyle}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</AppBar>
|
||||
</Page.BottomAppBar>
|
||||
</Page>
|
||||
|
@ -1,350 +1,389 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.Storage;
|
||||
using Windows.System;
|
||||
using Windows.UI.ApplicationSettings;
|
||||
using Windows.UI.ViewManagement;
|
||||
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 Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
||||
|
||||
namespace DrumKit
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty page that can be used on its own or navigated to within a Frame.
|
||||
/// </summary>
|
||||
public sealed partial class MainPage : Page
|
||||
{
|
||||
#region Fields: Private members
|
||||
private Dictionary<string, DrumPlayUI> DrumUIs { get; set; }
|
||||
private Dictionary<VirtualKey, string> Keymap { get; set; }
|
||||
private int CurrentLayout { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Initialization
|
||||
/// <summary>
|
||||
/// Creates a new instance of MainPage.
|
||||
/// </summary>
|
||||
public MainPage()
|
||||
{
|
||||
// Create private members
|
||||
this.DrumUIs = new Dictionary<string, DrumPlayUI>();
|
||||
this.Keymap = new Dictionary<VirtualKey, string>();
|
||||
CurrentLayout = 0;
|
||||
|
||||
// Initialize page
|
||||
this.InitializeComponent();
|
||||
this.SizeChanged += MainPage_SizeChanged;
|
||||
this.Loaded += MainPage_Loaded;
|
||||
|
||||
SettingsPane.GetForCurrentView().CommandsRequested += MainPage_CommandsRequested;
|
||||
|
||||
// Initialize drums
|
||||
this.InitializeDrums();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets up a single drum
|
||||
/// </summary>
|
||||
/// <param name="drum">The drum.</param>
|
||||
private void InitializeDrum(Drum drum)
|
||||
{
|
||||
// Create object
|
||||
DrumPlayUI d = new DrumPlayUI(drum);
|
||||
|
||||
// Set up callbacks
|
||||
d.Hit += HandlerDrumPointerPressed;
|
||||
|
||||
// Add to lists
|
||||
canvas.Children.Add(d);
|
||||
this.DrumUIs.Add(drum.Id, d);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets up the drums.
|
||||
/// </summary>
|
||||
private void InitializeDrums()
|
||||
{
|
||||
// Clear previous stuff if any
|
||||
this.DrumUIs.Clear();
|
||||
this.Keymap.Clear();
|
||||
|
||||
// Load drums
|
||||
foreach (var i in DataController.CurrentDrumkit.DrumsList)
|
||||
InitializeDrum(i);
|
||||
|
||||
// Load drum configurations
|
||||
foreach (var i in DataController.CurrentConfig.DrumsList)
|
||||
{
|
||||
// Unload if disabled
|
||||
if (!i.IsEnabled)
|
||||
{
|
||||
canvas.Children.Remove(this.DrumUIs[i.TargetId]);
|
||||
this.DrumUIs.Remove(i.TargetId);
|
||||
}
|
||||
|
||||
// Keyboard mapping
|
||||
if (!Keymap.ContainsKey(i.Key))
|
||||
Keymap.Add(i.Key, i.TargetId);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI: Settings charm
|
||||
/// <summary>
|
||||
/// Triggered when the settings pane requests commands/
|
||||
/// </summary>
|
||||
void MainPage_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
|
||||
{
|
||||
args.Request.ApplicationCommands.Clear();
|
||||
SettingsCommand general = new SettingsCommand("general", "General", new Windows.UI.Popups.UICommandInvokedHandler(MainPage_SettingsCommand));
|
||||
SettingsCommand drumkits = new SettingsCommand("drumkits", "Manage drumkits", new Windows.UI.Popups.UICommandInvokedHandler(MainPage_SettingsCommand));
|
||||
SettingsCommand drums = new SettingsCommand("drums", "Manage drums", new Windows.UI.Popups.UICommandInvokedHandler(MainPage_SettingsCommand));
|
||||
SettingsCommand layouts = new SettingsCommand("layouts", "Layouts", new Windows.UI.Popups.UICommandInvokedHandler(MainPage_SettingsCommand));
|
||||
|
||||
args.Request.ApplicationCommands.Add(general);
|
||||
args.Request.ApplicationCommands.Add(drumkits);
|
||||
args.Request.ApplicationCommands.Add(drums);
|
||||
args.Request.ApplicationCommands.Add(layouts);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the settings charms
|
||||
/// </summary>
|
||||
void MainPage_SettingsCommand(Windows.UI.Popups.IUICommand command)
|
||||
{
|
||||
Frame.Navigate(typeof(SettingsPage), command.Id);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Layouts
|
||||
|
||||
/// <summary>
|
||||
/// Figures out which is the best layout available, and uses it.
|
||||
/// </summary>
|
||||
private int PickBestLayout()
|
||||
{
|
||||
// Smaller index is better
|
||||
int[] picks = {-1, -1, -1, -1, -1, -1};
|
||||
|
||||
// Get current layout
|
||||
var view = UIHelper.ToDrumkitLayoutView(Windows.UI.ViewManagement.ApplicationView.Value);
|
||||
|
||||
// Find best option
|
||||
for (int index = 0; index < DataController.CurrentLayouts.Items.Count; index++ )
|
||||
{
|
||||
var i = DataController.CurrentLayouts.Items[index];
|
||||
|
||||
bool isSame = (i.TargetView == view);
|
||||
bool contains = (i.TargetView & view) > 0;
|
||||
bool all = i.TargetView == DrumkitLayoutTargetView.All;
|
||||
|
||||
if (i.IsDefault)
|
||||
{
|
||||
if (isSame) picks[0] = index;
|
||||
if (contains) picks[1] = index;
|
||||
if (all) picks[2] = index;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (isSame) picks[3] = index;
|
||||
if (contains) picks[4] = index;
|
||||
if (all) picks[5] = index;
|
||||
}
|
||||
}
|
||||
|
||||
// Return first value different than -1, or 0
|
||||
foreach (var i in picks)
|
||||
if (i != -1) return i;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets up the layout
|
||||
/// </summary>
|
||||
private void ReloadLayout()
|
||||
{
|
||||
// Get current size
|
||||
double w = canvas.ActualWidth;
|
||||
double h = canvas.ActualHeight;
|
||||
|
||||
if (double.IsNaN(w) || double.IsNaN(h) || double.IsInfinity(w) || double.IsInfinity(h))
|
||||
return;
|
||||
|
||||
// Pick a layout
|
||||
this.CurrentLayout = PickBestLayout();
|
||||
|
||||
Log.Write("Layout change: picked_layout={0}, w={1}, h={2}", this.CurrentLayout, w, h);
|
||||
|
||||
// Apply layout
|
||||
foreach (var i in DataController.CurrentLayouts.Items[CurrentLayout].Drums)
|
||||
{
|
||||
if (!DrumUIs.ContainsKey(i.Key))
|
||||
continue;
|
||||
|
||||
// Set angle
|
||||
DrumUIs[i.Key].Angle = i.Value.Angle;
|
||||
|
||||
// Set scale
|
||||
DrumUIs[i.Key].Width = i.Value.Size * w;
|
||||
DrumUIs[i.Key].Height = i.Value.Size * w;
|
||||
|
||||
// Set position
|
||||
Canvas.SetLeft(DrumUIs[i.Key], w * i.Value.X);
|
||||
Canvas.SetTop(DrumUIs[i.Key], h * i.Value.Y);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI: Drums
|
||||
/// <summary>
|
||||
/// Handles drum hit using mouse/finger
|
||||
/// </summary>
|
||||
void HandlerDrumPointerPressed(object sender, PointerRoutedEventArgs e)
|
||||
{
|
||||
var button = sender as DrumPlayUI;
|
||||
|
||||
if (button != null)
|
||||
this.HandlerDrumClickedCommon(button.DrumID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles drum hit using keyboard
|
||||
/// </summary>
|
||||
public void HandlerKeyDown(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.KeyEventArgs args)
|
||||
{
|
||||
string drum;
|
||||
|
||||
// Key repeat or something
|
||||
if (args.KeyStatus.WasKeyDown)
|
||||
return;
|
||||
|
||||
// If key in key map, perform "click"
|
||||
if (this.Keymap.TryGetValue(args.VirtualKey, out drum))
|
||||
HandlerDrumClickedCommon(drum);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles drum hit.
|
||||
/// </summary>
|
||||
private void HandlerDrumClickedCommon(string drum_id)
|
||||
{
|
||||
try
|
||||
{
|
||||
DataController.PlaySound(drum_id, 0);
|
||||
|
||||
if (DataController.Settings.Animations)
|
||||
this.DrumUIs[drum_id].PerformHit();
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("Error at playback!!! Drum id: {0}", drum_id);
|
||||
Log.Except(ex);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI: Page events
|
||||
/// <summary>
|
||||
/// Handles page size change event.
|
||||
/// </summary>
|
||||
void MainPage_SizeChanged(object sender, SizeChangedEventArgs e)
|
||||
{
|
||||
this.ReloadLayout();
|
||||
this.ReloadLayout();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles page load event.
|
||||
/// </summary>
|
||||
void MainPage_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Set layout
|
||||
this.ReloadLayout();
|
||||
|
||||
// Set toggles
|
||||
buttonAnimations.IsChecked = DataController.Settings.Animations;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when this page is about to be displayed in a Frame.
|
||||
/// </summary>
|
||||
/// <param name="e">Event data that describes how this page was reached. The Parameter
|
||||
/// property is typically used to configure the page.</param>
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
Log.Write("Navigated to main page.");
|
||||
|
||||
Window.Current.CoreWindow.KeyDown += this.HandlerKeyDown;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the page is about to be destroyed.
|
||||
/// </summary>
|
||||
protected override void OnNavigatedFrom(NavigationEventArgs e)
|
||||
{
|
||||
Window.Current.CoreWindow.KeyDown -= this.HandlerKeyDown;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI: Buttons
|
||||
/// <summary>
|
||||
/// Handles the edit button, going into the editor.
|
||||
/// </summary>
|
||||
private void ButtonEditMode_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Frame.Navigate(typeof(EditorPage), DataController.CurrentLayouts.Items[CurrentLayout]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the animations enabled toggle button.
|
||||
/// </summary>
|
||||
private void buttonAnimations_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var button = sender as ToggleButton;
|
||||
if (button == null) return;
|
||||
|
||||
bool isChecked = (button.IsChecked.HasValue && button.IsChecked.Value);
|
||||
|
||||
// Fix togglebuton style bug
|
||||
VisualStateManager.GoToState(button, isChecked ? "Checked" : "Unchecked", false);
|
||||
|
||||
// Change animation setting
|
||||
DataController.Settings.Animations = isChecked;
|
||||
|
||||
// Save modified setting
|
||||
DataController.SaveSettings();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Goes to application settings.
|
||||
/// </summary>
|
||||
private void ButtonSettings_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Frame.Navigate(typeof(SettingsPage), this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.Storage;
|
||||
using Windows.System;
|
||||
using Windows.UI.ApplicationSettings;
|
||||
using Windows.UI.ViewManagement;
|
||||
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 Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
||||
|
||||
namespace DrumKit
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty page that can be used on its own or navigated to within a Frame.
|
||||
/// </summary>
|
||||
public sealed partial class MainPage : Page
|
||||
{
|
||||
#region Fields: Private members
|
||||
private Dictionary<string, DrumPlayUI> DrumUIs { get; set; }
|
||||
private Dictionary<VirtualKey, string> Keymap { get; set; }
|
||||
private int CurrentLayout { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Initialization
|
||||
/// <summary>
|
||||
/// Creates a new instance of MainPage.
|
||||
/// </summary>
|
||||
public MainPage()
|
||||
{
|
||||
// Create private members
|
||||
this.DrumUIs = new Dictionary<string, DrumPlayUI>();
|
||||
this.Keymap = new Dictionary<VirtualKey, string>();
|
||||
CurrentLayout = 0;
|
||||
|
||||
// Initialize page
|
||||
this.InitializeComponent();
|
||||
this.SizeChanged += MainPage_SizeChanged;
|
||||
this.Loaded += MainPage_Loaded;
|
||||
|
||||
SettingsPane.GetForCurrentView().CommandsRequested += MainPage_CommandsRequested;
|
||||
|
||||
// Initialize drums
|
||||
this.InitializeDrums();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets up a single drum
|
||||
/// </summary>
|
||||
/// <param name="drum">The drum.</param>
|
||||
private void InitializeDrum(Drum drum)
|
||||
{
|
||||
// Create object
|
||||
DrumPlayUI d = new DrumPlayUI(drum);
|
||||
|
||||
// Set up callbacks
|
||||
d.Hit += HandlerDrumPointerPressed;
|
||||
|
||||
// Add to lists
|
||||
canvas.Children.Add(d);
|
||||
this.DrumUIs.Add(drum.Id, d);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets up the drums.
|
||||
/// </summary>
|
||||
private void InitializeDrums()
|
||||
{
|
||||
// Clear previous stuff if any
|
||||
this.DrumUIs.Clear();
|
||||
|
||||
// Load drums
|
||||
foreach (var i in DataController.CurrentDrumkit.DrumsList)
|
||||
InitializeDrum(i);
|
||||
|
||||
UpdateDrumConfig();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets up the drum configurations
|
||||
/// </summary>
|
||||
private void UpdateDrumConfig()
|
||||
{
|
||||
this.Keymap.Clear();
|
||||
|
||||
// Load drum configurations
|
||||
foreach (var i in DataController.CurrentConfig.DrumsList)
|
||||
{
|
||||
// Unload if disabled
|
||||
if (!i.IsEnabled)
|
||||
{
|
||||
canvas.Children.Remove(this.DrumUIs[i.TargetId]);
|
||||
this.DrumUIs.Remove(i.TargetId);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
// Set drum key
|
||||
this.DrumUIs[i.TargetId].KeyString = UIHelper.GetPrettifiedVKeyName(i.Key);
|
||||
this.DrumUIs[i.TargetId].IsKeyVisible = DataController.Settings.ShowKeyBindings;
|
||||
|
||||
// Keyboard mapping
|
||||
if (!Keymap.ContainsKey(i.Key))
|
||||
Keymap.Add(i.Key, i.TargetId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI: Settings charm
|
||||
/// <summary>
|
||||
/// Triggered when the settings pane requests commands/
|
||||
/// </summary>
|
||||
void MainPage_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
|
||||
{
|
||||
args.Request.ApplicationCommands.Clear();
|
||||
SettingsCommand general = new SettingsCommand("general", "General", new Windows.UI.Popups.UICommandInvokedHandler(MainPage_SettingsCommand));
|
||||
SettingsCommand drumkits = new SettingsCommand("drumkits", "Manage drumkits", new Windows.UI.Popups.UICommandInvokedHandler(MainPage_SettingsCommand));
|
||||
SettingsCommand drums = new SettingsCommand("drums", "Manage drums", new Windows.UI.Popups.UICommandInvokedHandler(MainPage_SettingsCommand));
|
||||
SettingsCommand layouts = new SettingsCommand("layouts", "Layouts", new Windows.UI.Popups.UICommandInvokedHandler(MainPage_SettingsCommand));
|
||||
|
||||
args.Request.ApplicationCommands.Add(general);
|
||||
args.Request.ApplicationCommands.Add(drumkits);
|
||||
args.Request.ApplicationCommands.Add(drums);
|
||||
args.Request.ApplicationCommands.Add(layouts);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the settings charms
|
||||
/// </summary>
|
||||
void MainPage_SettingsCommand(Windows.UI.Popups.IUICommand command)
|
||||
{
|
||||
Frame.Navigate(typeof(SettingsPage), command.Id);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Layouts
|
||||
|
||||
/// <summary>
|
||||
/// Figures out which is the best layout available, and uses it.
|
||||
/// </summary>
|
||||
private int PickBestLayout()
|
||||
{
|
||||
// Smaller index is better
|
||||
int[] picks = {-1, -1, -1, -1, -1, -1};
|
||||
|
||||
// Get current layout
|
||||
var view = UIHelper.ToDrumkitLayoutView(Windows.UI.ViewManagement.ApplicationView.Value);
|
||||
|
||||
// Find best option
|
||||
for (int index = 0; index < DataController.CurrentLayouts.Items.Count; index++ )
|
||||
{
|
||||
var i = DataController.CurrentLayouts.Items[index];
|
||||
|
||||
bool isSame = (i.TargetView == view);
|
||||
bool contains = (i.TargetView & view) > 0;
|
||||
bool all = i.TargetView == DrumkitLayoutTargetView.All;
|
||||
|
||||
if (i.IsDefault)
|
||||
{
|
||||
if (isSame) picks[0] = index;
|
||||
if (contains) picks[1] = index;
|
||||
if (all) picks[2] = index;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (isSame) picks[3] = index;
|
||||
if (contains) picks[4] = index;
|
||||
if (all) picks[5] = index;
|
||||
}
|
||||
}
|
||||
|
||||
// Return first value different than -1, or 0
|
||||
foreach (var i in picks)
|
||||
if (i != -1) return i;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets up the layout
|
||||
/// </summary>
|
||||
private void ReloadLayout()
|
||||
{
|
||||
// Get current size
|
||||
double w = canvas.ActualWidth;
|
||||
double h = canvas.ActualHeight;
|
||||
|
||||
if (double.IsNaN(w) || double.IsNaN(h) || double.IsInfinity(w) || double.IsInfinity(h))
|
||||
return;
|
||||
|
||||
// Pick a layout
|
||||
this.CurrentLayout = PickBestLayout();
|
||||
|
||||
Log.Write("Layout change: picked_layout={0}, w={1}, h={2}", this.CurrentLayout, w, h);
|
||||
|
||||
// Apply layout
|
||||
foreach (var i in DataController.CurrentLayouts.Items[CurrentLayout].Drums)
|
||||
{
|
||||
if (!DrumUIs.ContainsKey(i.Key))
|
||||
continue;
|
||||
|
||||
// Set angle
|
||||
DrumUIs[i.Key].Angle = i.Value.Angle;
|
||||
|
||||
// Set scale
|
||||
DrumUIs[i.Key].Width = i.Value.Size * w;
|
||||
DrumUIs[i.Key].Height = i.Value.Size * w;
|
||||
|
||||
// Set position
|
||||
Canvas.SetLeft(DrumUIs[i.Key], w * i.Value.X);
|
||||
Canvas.SetTop(DrumUIs[i.Key], h * i.Value.Y);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI: Drums
|
||||
/// <summary>
|
||||
/// Handles drum hit using mouse/finger
|
||||
/// </summary>
|
||||
void HandlerDrumPointerPressed(object sender, PointerRoutedEventArgs e)
|
||||
{
|
||||
var button = sender as DrumPlayUI;
|
||||
|
||||
if (button != null)
|
||||
this.HandlerDrumClickedCommon(button.DrumID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles drum hit using keyboard
|
||||
/// </summary>
|
||||
public void HandlerKeyDown(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.KeyEventArgs args)
|
||||
{
|
||||
string drum;
|
||||
|
||||
// Key repeat or something
|
||||
if (args.KeyStatus.WasKeyDown)
|
||||
return;
|
||||
|
||||
// If key in key map, perform "click"
|
||||
if (this.Keymap.TryGetValue(args.VirtualKey, out drum))
|
||||
HandlerDrumClickedCommon(drum);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles drum hit.
|
||||
/// </summary>
|
||||
private void HandlerDrumClickedCommon(string drum_id)
|
||||
{
|
||||
try
|
||||
{
|
||||
DataController.PlaySound(drum_id, 0);
|
||||
|
||||
if (DataController.Settings.Animations)
|
||||
this.DrumUIs[drum_id].PerformHit();
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("Error at playback!!! Drum id: {0}", drum_id);
|
||||
Log.Except(ex);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI: Page events
|
||||
/// <summary>
|
||||
/// Handles page size change event.
|
||||
/// </summary>
|
||||
void MainPage_SizeChanged(object sender, SizeChangedEventArgs e)
|
||||
{
|
||||
this.ReloadLayout();
|
||||
this.ReloadLayout();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles page load event.
|
||||
/// </summary>
|
||||
void MainPage_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Set layout
|
||||
this.ReloadLayout();
|
||||
|
||||
// Set toggles
|
||||
buttonAnimations.IsChecked = DataController.Settings.Animations;
|
||||
buttonKeys.IsChecked = DataController.Settings.ShowKeyBindings;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when this page is about to be displayed in a Frame.
|
||||
/// </summary>
|
||||
/// <param name="e">Event data that describes how this page was reached. The Parameter
|
||||
/// property is typically used to configure the page.</param>
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
Log.Write("Navigated to main page.");
|
||||
|
||||
Window.Current.CoreWindow.KeyDown += this.HandlerKeyDown;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the page is about to be destroyed.
|
||||
/// </summary>
|
||||
protected override void OnNavigatedFrom(NavigationEventArgs e)
|
||||
{
|
||||
Window.Current.CoreWindow.KeyDown -= this.HandlerKeyDown;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI: Buttons
|
||||
/// <summary>
|
||||
/// Handles the edit button, going into the editor.
|
||||
/// </summary>
|
||||
private void ButtonEditMode_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Frame.Navigate(typeof(EditorPage), DataController.CurrentLayouts.Items[CurrentLayout]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the animations enabled toggle button.
|
||||
/// </summary>
|
||||
private void buttonAnimations_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var button = sender as ToggleButton;
|
||||
if (button == null) return;
|
||||
|
||||
bool isChecked = (button.IsChecked.HasValue && button.IsChecked.Value);
|
||||
|
||||
// Fix togglebuton style bug
|
||||
VisualStateManager.GoToState(button, isChecked ? "Checked" : "Unchecked", false);
|
||||
|
||||
// Change animation setting
|
||||
DataController.Settings.Animations = isChecked;
|
||||
|
||||
// Save modified setting
|
||||
DataController.SaveSettings();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the 'show keys' toggle button
|
||||
/// </summary>
|
||||
private void buttonKeys_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var button = sender as ToggleButton;
|
||||
if (button == null) return;
|
||||
|
||||
bool isChecked = (button.IsChecked.HasValue && button.IsChecked.Value);
|
||||
|
||||
// Fix togglebuton style bug
|
||||
VisualStateManager.GoToState(button, isChecked ? "Checked" : "Unchecked", false);
|
||||
|
||||
// Change setting
|
||||
DataController.Settings.ShowKeyBindings = isChecked;
|
||||
|
||||
// Update UI
|
||||
UpdateDrumConfig();
|
||||
|
||||
// Save modified setting
|
||||
DataController.SaveSettings();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Goes to application settings.
|
||||
/// </summary>
|
||||
private void ButtonSettings_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Frame.Navigate(typeof(SettingsPage), this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
||||
|
@ -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
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user