mirror of
https://github.com/chibicitiberiu/drumkit.git
synced 2024-02-24 10:53:32 +00:00
Latest build (version 2.2)
This commit is contained in:
36
DrumKit/UI/CommonControls/FileControl.xaml
Normal file
36
DrumKit/UI/CommonControls/FileControl.xaml
Normal file
@ -0,0 +1,36 @@
|
||||
<UserControl
|
||||
x:Class="DrumKit.FileControl"
|
||||
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="120"
|
||||
d:DesignWidth="400">
|
||||
|
||||
<Grid>
|
||||
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock Name="textName" Style="{StaticResource TitleTextStyle}"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,0,8">Test</TextBlock>
|
||||
|
||||
<Image Grid.Row="1" Name="image"
|
||||
VerticalAlignment="Stretch"
|
||||
HorizontalAlignment="Left" Width="120"/>
|
||||
|
||||
<Button Name="buttonBrowse" Style="{StaticResource TextButtonStyle}"
|
||||
Grid.Column="1" Margin="10,5,10,5">...</Button>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
26
DrumKit/UI/CommonControls/FileControl.xaml.cs
Normal file
26
DrumKit/UI/CommonControls/FileControl.xaml.cs
Normal file
@ -0,0 +1,26 @@
|
||||
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 FileControl : UserControl
|
||||
{
|
||||
public FileControl()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
211
DrumKit/UI/DrumEditUI.xaml
Normal file
211
DrumKit/UI/DrumEditUI.xaml
Normal file
@ -0,0 +1,211 @@
|
||||
<UserControl
|
||||
x:Class="DrumKit.DrumEditUI"
|
||||
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"
|
||||
SizeChanged="DrumEditUl_SizeChanged">
|
||||
|
||||
<UserControl.Resources>
|
||||
|
||||
<!-- Translation thumb -->
|
||||
<SolidColorBrush x:Key="TranslationThumbBackgroundBrush" Color="Transparent" />
|
||||
|
||||
<LinearGradientBrush x:Key="TranslationThumbBackgroundFocusedBrush" StartPoint="0,0" EndPoint="0,1">
|
||||
<GradientStop Color="#2fff" Offset="1" />
|
||||
<GradientStop Color="#5fff" Offset="0" />
|
||||
</LinearGradientBrush>
|
||||
|
||||
<LinearGradientBrush x:Key="TranslationThumbBackgroundPressedBrush" StartPoint="0,0" EndPoint="0,1">
|
||||
<GradientStop Color="#1fff" Offset="1" />
|
||||
<GradientStop Color="#3fff" Offset="0" />
|
||||
</LinearGradientBrush>
|
||||
|
||||
<LinearGradientBrush x:Key="TranslationThumbBorderBrush" StartPoint="0,0" EndPoint="0,1" >
|
||||
<GradientStop Color="#2fff" Offset="1" />
|
||||
<GradientStop Color="#5fff" Offset="0" />
|
||||
</LinearGradientBrush>
|
||||
|
||||
<!-- Drum name background -->
|
||||
<LinearGradientBrush x:Key="DrumNameBackgroundBrush" StartPoint="0,0" EndPoint="0,1">
|
||||
<GradientStop Color="#0000" Offset="1" />
|
||||
<GradientStop Color="#2000" Offset="0.7" />
|
||||
<GradientStop Color="#a000" Offset="0" />
|
||||
</LinearGradientBrush>
|
||||
|
||||
<!-- Round thumb -->
|
||||
<SolidColorBrush x:Key="RoundThumbBackgroundBrush" Color="WhiteSmoke" />
|
||||
<SolidColorBrush x:Key="RoundThumbBorderBrush" Color="LightGray" />
|
||||
<SolidColorBrush x:Key="RoundThumbForegroundBrush" Color="Gray" />
|
||||
|
||||
<!-- Rotation thumb -->
|
||||
<SolidColorBrush x:Key="RotationTranslationThumbBackgroundBrush" Color="Coral" />
|
||||
<SolidColorBrush x:Key="RotationTranslationThumbBorderBrush" Color="LightCoral" />
|
||||
<SolidColorBrush x:Key="RotationDrumForegroundBrush" Color="Brown" />
|
||||
|
||||
<!-- Translation thumb style -->
|
||||
<Style x:Name="TranslationThumbStyle" TargetType="Thumb">
|
||||
<Setter Property="Background" Value="{StaticResource TranslationThumbBackgroundBrush}" />
|
||||
<Setter Property="BorderBrush" Value="{StaticResource TranslationThumbBorderBrush}" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="VerticalAlignment" Value="Stretch" />
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Thumb">
|
||||
|
||||
<Grid>
|
||||
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="CommonStates">
|
||||
<VisualState x:Name="Normal" >
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="normalRectangle"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
Duration="0" To="1" />
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState x:Name="PointerOver">
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="focusedRectangle"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
Duration="0" To="1" />
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState x:Name="Pressed">
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="pressedRectangle"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
Duration="0" To="1" />
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
|
||||
<Rectangle Name="normalRectangle"
|
||||
Fill="{TemplateBinding Background}"
|
||||
Stroke="{TemplateBinding BorderBrush}"
|
||||
StrokeThickness="{TemplateBinding BorderThickness}"
|
||||
Opacity="0" />
|
||||
|
||||
<Rectangle Name="focusedRectangle"
|
||||
Fill="{StaticResource TranslationThumbBackgroundFocusedBrush}"
|
||||
Stroke="{TemplateBinding BorderBrush}"
|
||||
StrokeThickness="{TemplateBinding BorderThickness}"
|
||||
Opacity="0" />
|
||||
|
||||
<Rectangle Name="pressedRectangle"
|
||||
Fill="{StaticResource TranslationThumbBackgroundPressedBrush}"
|
||||
Stroke="{TemplateBinding BorderBrush}"
|
||||
StrokeThickness="{TemplateBinding BorderThickness}"
|
||||
Opacity="0" />
|
||||
</Grid>
|
||||
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!-- Round thumb style -->
|
||||
<Style x:Key="RoundThumbStyle" TargetType="Thumb">
|
||||
<Setter Property="Background" Value="{StaticResource RoundThumbBackgroundBrush}" />
|
||||
<Setter Property="BorderBrush" Value="{StaticResource RoundThumbBorderBrush}" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="Foreground" Value="{StaticResource RoundThumbForegroundBrush}" />
|
||||
<Setter Property="Height" Value="16" />
|
||||
<Setter Property="Width" Value="16" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Thumb">
|
||||
<Grid>
|
||||
<Ellipse
|
||||
Fill="{TemplateBinding Background}"
|
||||
Stroke="{TemplateBinding BorderBrush}"
|
||||
StrokeThickness="{TemplateBinding BorderThickness}" />
|
||||
|
||||
<TextBlock
|
||||
Foreground="{TemplateBinding Foreground}"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center"
|
||||
Text="{TemplateBinding Tag}"/>
|
||||
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!-- Rotation thumb style -->
|
||||
<Style x:Key="RotationThumbStyle" TargetType="Thumb" BasedOn="{StaticResource RoundThumbStyle}" >
|
||||
<Setter Property="Background" Value="{StaticResource RotationTranslationThumbBackgroundBrush}" />
|
||||
<Setter Property="BorderBrush" Value="{StaticResource RotationTranslationThumbBorderBrush}" />
|
||||
<Setter Property="Foreground" Value="{StaticResource RotationDrumForegroundBrush}" />
|
||||
<Setter Property="FontFamily" Value="{StaticResource SymbolThemeFontFamily}" />
|
||||
<Setter Property="FontSize" Value="10" />
|
||||
<Setter Property="FontStyle" Value="Normal" />
|
||||
<Setter Property="Tag" Value="" />
|
||||
</Style>
|
||||
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid>
|
||||
|
||||
<Grid Name="rotateGrid" IsHitTestVisible="False">
|
||||
|
||||
<Image Name="image" IsHitTestVisible="False"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch" />
|
||||
|
||||
</Grid>
|
||||
|
||||
<Border HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Top"
|
||||
IsHitTestVisible="False"
|
||||
Background="{StaticResource DrumNameBackgroundBrush}">
|
||||
|
||||
<TextBlock
|
||||
IsHitTestVisible="False"
|
||||
Name="nameText" HorizontalAlignment="Center"
|
||||
Style="{StaticResource TitleTextStyle}"
|
||||
Margin="0,2,0,16"/>
|
||||
|
||||
</Border>
|
||||
|
||||
<Border BorderBrush="Black" BorderThickness="1">
|
||||
|
||||
<Thumb
|
||||
Name="translationThumb"
|
||||
Style="{StaticResource TranslationThumbStyle}"
|
||||
DragDelta="translationThumb_DragDelta" />
|
||||
|
||||
</Border>
|
||||
|
||||
<Thumb
|
||||
Name="rotationThumb"
|
||||
Style="{StaticResource RotationThumbStyle}"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
DragStarted="rotationThumb_DragStarted"
|
||||
DragDelta="rotationThumb_DragDelta" >
|
||||
|
||||
</Thumb>
|
||||
|
||||
<Thumb
|
||||
Name="scaleThumb" Grid.Row="1"
|
||||
Style="{StaticResource RoundThumbStyle}"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Bottom"
|
||||
DragDelta="scaleThumb_DragDelta" >
|
||||
|
||||
<Thumb.RenderTransform>
|
||||
<TranslateTransform X="8" Y="8" />
|
||||
</Thumb.RenderTransform>
|
||||
|
||||
</Thumb>
|
||||
</Grid>
|
||||
|
||||
</UserControl>
|
180
DrumKit/UI/DrumEditUI.xaml.cs
Normal file
180
DrumKit/UI/DrumEditUI.xaml.cs
Normal file
@ -0,0 +1,180 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.UI;
|
||||
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 DrumEditUI : UserControl
|
||||
{
|
||||
#region Constants
|
||||
const double RotationHandleOffset = 8;
|
||||
#endregion
|
||||
|
||||
#region Public events
|
||||
/// <summary>
|
||||
/// Triggered when the item was dragged.
|
||||
/// </summary>
|
||||
public event DragDeltaEventHandler DragDelta;
|
||||
|
||||
/// <summary>
|
||||
/// Triggered when the angle changes
|
||||
/// </summary>
|
||||
public event EventHandler AngleChanged;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the drum rotation
|
||||
/// </summary>
|
||||
public double Angle
|
||||
{
|
||||
get
|
||||
{
|
||||
// Get rotated grid
|
||||
var transform = rotateGrid.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;
|
||||
|
||||
rotateGrid.RenderTransform = rot;
|
||||
|
||||
// Set thumb position
|
||||
TranslateTransform tr = new TranslateTransform();
|
||||
double radius = this.Height / 2 + RotationHandleOffset;
|
||||
double rads = Math.PI * (value - 90) / 180;
|
||||
|
||||
tr.X = radius * Math.Cos(rads);
|
||||
tr.Y = radius * Math.Sin(rads);
|
||||
|
||||
rotationThumb.RenderTransform = tr;
|
||||
|
||||
// Call event
|
||||
if (AngleChanged != null)
|
||||
AngleChanged(this, new EventArgs());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the drum id.
|
||||
/// </summary>
|
||||
public string DrumID { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private fields
|
||||
|
||||
private double rotationDragX = 0, rotationDragY = 0;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of DrumEditUI
|
||||
/// </summary>
|
||||
public DrumEditUI(Drum drum)
|
||||
{
|
||||
// Initialize
|
||||
this.InitializeComponent();
|
||||
|
||||
// Set drum properties
|
||||
this.DrumID = drum.Id;
|
||||
this.nameText.Text = drum.Name;
|
||||
|
||||
// Set image
|
||||
this.image.Source = drum.LoadedImageSource;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI handlers
|
||||
|
||||
/// <summary>
|
||||
/// Handles the "rotation handle drag started" event.
|
||||
/// </summary>
|
||||
private void rotationThumb_DragStarted(object sender, DragStartedEventArgs e)
|
||||
{
|
||||
var transl = this.rotationThumb.RenderTransform as TranslateTransform;
|
||||
|
||||
double x = (transl == null) ? 0 : transl.X;
|
||||
double y = (transl == null) ? 0 : transl.Y;
|
||||
|
||||
rotationDragX = x;
|
||||
rotationDragY = y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the "rotation handle dragged" event.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void rotationThumb_DragDelta(object sender, DragDeltaEventArgs e)
|
||||
{
|
||||
rotationDragX += e.HorizontalChange;
|
||||
rotationDragY += e.VerticalChange;
|
||||
|
||||
double angle = Math.Atan2(rotationDragY, rotationDragX) * 180.0 / Math.PI + 90;
|
||||
this.Angle = angle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the "scale handle dragged" event.
|
||||
/// </summary>
|
||||
private void scaleThumb_DragDelta(object sender, DragDeltaEventArgs e)
|
||||
{
|
||||
double new_w = this.Width + e.HorizontalChange;
|
||||
// double new_h = this.Height + e.VerticalChange;
|
||||
|
||||
this.Width = Math.Max(0, new_w);
|
||||
this.Height = Math.Max(0, new_w);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the translation drag delta event.
|
||||
/// </summary>
|
||||
private void translationThumb_DragDelta(object sender, DragDeltaEventArgs e)
|
||||
{
|
||||
if (this.DragDelta != null)
|
||||
this.DragDelta(this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the size changed event.
|
||||
/// </summary>
|
||||
private void DrumEditUl_SizeChanged(object sender, SizeChangedEventArgs e)
|
||||
{
|
||||
this.Angle = Angle;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
65
DrumKit/UI/DrumPlayUI.xaml
Normal file
65
DrumKit/UI/DrumPlayUI.xaml
Normal file
@ -0,0 +1,65 @@
|
||||
<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>
|
122
DrumKit/UI/DrumPlayUI.xaml.cs
Normal file
122
DrumKit/UI/DrumPlayUI.xaml.cs
Normal file
@ -0,0 +1,122 @@
|
||||
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
|
||||
}
|
||||
}
|
@ -1,178 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage;
|
||||
using Windows.UI;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Controls.Primitives;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Media.Animation;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
|
||||
namespace DrumKit
|
||||
{
|
||||
class DrumUI
|
||||
{
|
||||
#region Private attributes
|
||||
private Thumb thumb;
|
||||
private Image image, imagePressed;
|
||||
private Grid grid;
|
||||
private Storyboard hitAnimation;
|
||||
#endregion
|
||||
|
||||
#region Public properties
|
||||
/// <summary>
|
||||
/// Gets the ui element which will be put in a canvas.
|
||||
/// </summary>
|
||||
public FrameworkElement Element { get { return grid; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the drum id.
|
||||
/// </summary>
|
||||
public string DrumID { get; private set; }
|
||||
|
||||
public event Windows.UI.Xaml.Input.PointerEventHandler PointerPressed
|
||||
{
|
||||
add {
|
||||
grid.PointerPressed += value;
|
||||
}
|
||||
|
||||
remove {
|
||||
grid.PointerPressed -= value;
|
||||
}
|
||||
}
|
||||
|
||||
public event DragDeltaEventHandler DragDelta
|
||||
{
|
||||
add {
|
||||
thumb.DragDelta += value;
|
||||
}
|
||||
|
||||
remove {
|
||||
thumb.DragDelta -= value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Initialization
|
||||
private void GridAddChild(FrameworkElement element)
|
||||
{
|
||||
grid.Children.Add(element);
|
||||
element.HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||
element.VerticalAlignment = VerticalAlignment.Stretch;
|
||||
}
|
||||
|
||||
private void InitializeCreateObjects()
|
||||
{
|
||||
// Create thumb
|
||||
this.thumb = new Thumb()
|
||||
{
|
||||
Background = new SolidColorBrush(Colors.Green),
|
||||
Opacity = .3,
|
||||
Visibility = Visibility.Collapsed
|
||||
};
|
||||
|
||||
// Create image
|
||||
this.image = new Image();
|
||||
|
||||
// Create pressed image
|
||||
this.imagePressed = new Image()
|
||||
{
|
||||
Opacity = 0
|
||||
};
|
||||
|
||||
// Create grid
|
||||
this.grid = new Grid();
|
||||
|
||||
// Create animation
|
||||
DoubleAnimation fade = new DoubleAnimation();
|
||||
fade.Duration = TimeSpan.FromSeconds(.6);
|
||||
fade.From = 1;
|
||||
fade.To = 0;
|
||||
|
||||
Storyboard.SetTarget(fade, this.imagePressed);
|
||||
Storyboard.SetTargetProperty(fade, "Opacity");
|
||||
|
||||
this.hitAnimation = new Storyboard();
|
||||
this.hitAnimation.Children.Add(fade);
|
||||
|
||||
// grid.Resources.Add("hitanimation", this.hitAnimation);
|
||||
}
|
||||
|
||||
private void InitializeParenting()
|
||||
{
|
||||
this.GridAddChild(this.image);
|
||||
this.GridAddChild(this.imagePressed);
|
||||
this.GridAddChild(this.thumb);
|
||||
}
|
||||
|
||||
public async Task InitializeDrum(Drum drum, StorageFolder root)
|
||||
{
|
||||
// Set path
|
||||
Uri rootpath = new Uri(root.Path);
|
||||
|
||||
// Set drum id
|
||||
this.DrumID = drum.Id;
|
||||
|
||||
// Set images
|
||||
this.image.Source = await IOHelper.GetImageAsync(root, drum.ImageSource);
|
||||
this.imagePressed.Source = await IOHelper.GetImageAsync(root, drum.ImagePressedSource);
|
||||
|
||||
// Set tags
|
||||
this.thumb.Tag = drum.Id;
|
||||
this.grid.Tag = drum.Id;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public DrumUI()
|
||||
{
|
||||
// Create objects
|
||||
this.InitializeCreateObjects();
|
||||
this.InitializeParenting();
|
||||
}
|
||||
|
||||
public void UpdateLayout(DrumLayout layout, double canvasWidth, double canvasHeight)
|
||||
{
|
||||
// Set up size
|
||||
this.grid.Width = layout.Size * canvasWidth;
|
||||
this.grid.Height = layout.Size * canvasWidth;
|
||||
|
||||
// Set up position
|
||||
Canvas.SetLeft(this.grid, layout.X * canvasWidth);
|
||||
Canvas.SetTop(this.grid, layout.Y * canvasHeight);
|
||||
Canvas.SetZIndex(this.grid, layout.ZIndex);
|
||||
|
||||
// Rotation
|
||||
RotateTransform transform = new RotateTransform();
|
||||
transform.Angle = layout.Angle;
|
||||
transform.CenterX = this.grid.Width / 2;
|
||||
transform.CenterY = this.grid.Height / 2;
|
||||
this.image.RenderTransform = transform;
|
||||
this.imagePressed.RenderTransform = transform;
|
||||
}
|
||||
|
||||
public void Hit()
|
||||
{
|
||||
// Perform a drum hit
|
||||
this.hitAnimation.Begin();
|
||||
}
|
||||
|
||||
public void EnableEdit()
|
||||
{
|
||||
// Thumb becomes visible
|
||||
this.thumb.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
public void DisableEdit()
|
||||
{
|
||||
// Thumb becomes invisible
|
||||
this.thumb.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
}
|
34
DrumKit/UI/EditorPage.xaml
Normal file
34
DrumKit/UI/EditorPage.xaml
Normal file
@ -0,0 +1,34 @@
|
||||
<Page
|
||||
x:Class="DrumKit.EditorPage"
|
||||
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="EditorBackgroundBrush" ImageSource="ms-appx:///Assets/bg.png" Stretch="UniformToFill" />
|
||||
|
||||
</Page.Resources>
|
||||
|
||||
<Canvas
|
||||
Name="container"
|
||||
Background="{StaticResource EditorBackgroundBrush}">
|
||||
|
||||
<Button Name="buttonBack" Canvas.Left="10" Canvas.Top="10" Canvas.ZIndex="1"
|
||||
Style="{StaticResource BackButtonStyle}"
|
||||
Click="buttonBack_Click" />
|
||||
|
||||
</Canvas>
|
||||
|
||||
<!--<Page.BottomAppBar>
|
||||
<AppBar>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Button>Change order</Button>
|
||||
<Button>Bring all drums into view</Button>
|
||||
</StackPanel>
|
||||
</AppBar>
|
||||
</Page.BottomAppBar>-->
|
||||
|
||||
</Page>
|
244
DrumKit/UI/EditorPage.xaml.cs
Normal file
244
DrumKit/UI/EditorPage.xaml.cs
Normal file
@ -0,0 +1,244 @@
|
||||
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 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 EditorPage : Page
|
||||
{
|
||||
#region Private properties
|
||||
private int LayoutIndex { get; set; }
|
||||
|
||||
private DrumkitLayout Layout {
|
||||
get {
|
||||
if (this.LayoutIndex == -1)
|
||||
return null;
|
||||
|
||||
return DataController.CurrentLayouts.Items[LayoutIndex];
|
||||
}
|
||||
|
||||
set {
|
||||
this.LayoutIndex = DataController.CurrentLayouts.Items.IndexOf(value);
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<string, DrumEditUI> DrumUIs { get; set; }
|
||||
|
||||
private bool IgnoreEvent = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor, initialization
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of EditorPage.
|
||||
/// </summary>
|
||||
public EditorPage()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
|
||||
this.DrumUIs = new Dictionary<string, DrumEditUI>();
|
||||
this.LayoutIndex = -1;
|
||||
|
||||
this.SizeChanged += EditorPage_SizeChanged;
|
||||
this.Loaded += EditorPage_Loaded;
|
||||
|
||||
this.InitializeDrums();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Handles the page loaded event.
|
||||
/// </summary>
|
||||
void EditorPage_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ReloadLayout();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the drums.
|
||||
/// </summary>
|
||||
void InitializeDrums()
|
||||
{
|
||||
foreach (var i in DataController.CurrentDrumkit.Drums)
|
||||
{
|
||||
// Create drum edit UI
|
||||
var ui = new DrumEditUI(i.Value);
|
||||
|
||||
// Set up events
|
||||
ui.DragDelta += Drum_Dragged;
|
||||
ui.SizeChanged += Drum_SizeChanged;
|
||||
ui.AngleChanged += Drum_AngleChanged;
|
||||
|
||||
// Add to canvas and dictionary
|
||||
this.container.Children.Add(ui);
|
||||
this.DrumUIs.Add(i.Key, ui);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Reload layout
|
||||
/// <summary>
|
||||
/// Updates the layout of the drums
|
||||
/// </summary>
|
||||
void ReloadLayout()
|
||||
{
|
||||
// Get current size
|
||||
double w = container.ActualWidth;
|
||||
double h = container.ActualHeight;
|
||||
|
||||
if (double.IsNaN(w) || double.IsNaN(h) || double.IsInfinity(w) || double.IsInfinity(h))
|
||||
return;
|
||||
|
||||
// Flag that tells event handlers to ignore event
|
||||
this.IgnoreEvent = true;
|
||||
|
||||
// Set layouts
|
||||
foreach (var i in Layout.Drums)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
// Ignore no more
|
||||
this.IgnoreEvent = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI: Page events
|
||||
|
||||
/// <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 editor page.");
|
||||
|
||||
// When we arrive here, we should have a layout
|
||||
var layout = e.Parameter as DrumkitLayout;
|
||||
|
||||
if (layout == null)
|
||||
Frame.GoBack();
|
||||
|
||||
// Set layout
|
||||
this.Layout = layout;
|
||||
this.ReloadLayout();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the page resize event.
|
||||
/// </summary>
|
||||
private void EditorPage_SizeChanged(object sender, SizeChangedEventArgs e)
|
||||
{
|
||||
ReloadLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI: Buttons events
|
||||
|
||||
/// <summary>
|
||||
/// Handles the "Back" button click event.
|
||||
/// </summary>
|
||||
private void buttonBack_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Frame.GoBack();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI: Drum events
|
||||
|
||||
/// <summary>
|
||||
/// Triggered when the angle is changed.
|
||||
/// </summary>
|
||||
void Drum_AngleChanged(object sender, EventArgs e)
|
||||
{
|
||||
var drumui = sender as DrumEditUI;
|
||||
|
||||
if (sender != null && !IgnoreEvent)
|
||||
{
|
||||
this.Layout.Drums[drumui.DrumID].Angle = drumui.Angle;
|
||||
|
||||
DataController.SaveLayout();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggered when the size of a drum is changed.
|
||||
/// </summary>
|
||||
void Drum_SizeChanged(object sender, SizeChangedEventArgs e)
|
||||
{
|
||||
var drumui = sender as DrumEditUI;
|
||||
|
||||
if (drumui != null && !IgnoreEvent)
|
||||
{
|
||||
this.Layout.Drums[drumui.DrumID].Size = drumui.ActualWidth / container.ActualWidth;
|
||||
DataController.SaveLayout();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggered when the drum is dragged.
|
||||
/// We have to perform the move ourselves.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
void Drum_Dragged(object sender, DragDeltaEventArgs e)
|
||||
{
|
||||
var drumui = sender as DrumEditUI;
|
||||
|
||||
if (drumui != null && !IgnoreEvent)
|
||||
{
|
||||
// Get old position
|
||||
double old_x = Canvas.GetLeft(drumui);
|
||||
double old_y = Canvas.GetTop(drumui);
|
||||
|
||||
// Calculate new position
|
||||
double new_x = old_x + e.HorizontalChange;
|
||||
double new_y = old_y + e.VerticalChange;
|
||||
|
||||
// Save layout
|
||||
Layout.Drums[drumui.DrumID].X = new_x / container.ActualWidth;
|
||||
Layout.Drums[drumui.DrumID].Y = new_y / container.ActualHeight;
|
||||
|
||||
// Move object
|
||||
Canvas.SetLeft(drumui, new_x);
|
||||
Canvas.SetTop(drumui, new_y);
|
||||
|
||||
// Save modification
|
||||
DataController.SaveLayout();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
@ -7,13 +7,20 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid Background="#164646">
|
||||
<Grid Background="{StaticResource ApplicationBackgroundColor}">
|
||||
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center">
|
||||
<Image Source="ms-appx:///Assets/Logos/SplashScreen.png"
|
||||
Stretch="None"/>
|
||||
|
||||
</Grid>
|
||||
|
||||
|
||||
<StackPanel
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Bottom"
|
||||
@ -21,10 +28,15 @@
|
||||
Margin="20">
|
||||
<ProgressRing Width="40" Height="40" IsActive="True" Foreground="White" />
|
||||
<TextBlock
|
||||
Name="TextLoading"
|
||||
Name="textLoading"
|
||||
Style="{StaticResource SubheaderTextStyle}" Margin="10,0,0,0">
|
||||
Loading resources...</TextBlock>
|
||||
</StackPanel>
|
||||
|
||||
<ProgressBar
|
||||
Name="progressBar" Grid.Row="1"
|
||||
Foreground="#53AB6D" Background="#20FFFFFF"
|
||||
Minimum="0" Maximum="100"/>
|
||||
|
||||
</Grid>
|
||||
</Page>
|
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.UI.Xaml;
|
||||
@ -24,10 +25,8 @@ namespace DrumKit
|
||||
public LoadingPage()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.Loaded += LoadingPage_Loaded;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when this page is about to be displayed in a Frame.
|
||||
/// </summary>
|
||||
@ -35,38 +34,70 @@ namespace DrumKit
|
||||
/// property is typically used to configure the page.</param>
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
LoadStuff(e.Parameter);
|
||||
}
|
||||
|
||||
|
||||
private async void LoadingPage_Loaded(object sender, RoutedEventArgs e)
|
||||
private async Task DoFactoryReset()
|
||||
{
|
||||
DataController.Dispose();
|
||||
await DataController.FactoryReset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs the loading of the application stuff.
|
||||
/// </summary>
|
||||
/// <param name="arg"></param>
|
||||
private async void LoadStuff(object arg)
|
||||
{
|
||||
bool error = false;
|
||||
DataController.ProgressChanged += DataController_ProgressChanged;
|
||||
|
||||
// Application restart?
|
||||
if (arg is string && (string) arg == "restart")
|
||||
DataController.Dispose();
|
||||
|
||||
// Factory reset?
|
||||
if (arg is string && (string) arg == "reset")
|
||||
await DoFactoryReset();
|
||||
|
||||
// Perform initializations
|
||||
try
|
||||
{
|
||||
TextLoading.Text = "Loading data...";
|
||||
await DataManager.Initialize();
|
||||
await Log.Initialize();
|
||||
await DrumsManager.Initialize(DataManager.Settings);
|
||||
|
||||
TextLoading.Text = "Loading sounds...";
|
||||
SoundManager.Initialize();
|
||||
await SoundManager.LoadDrumkit(DrumsManager.CurrentDrumkit, DrumsManager.CurrentDrumkitLocation);
|
||||
|
||||
TextLoading.Text = "Loading interface...";
|
||||
UIManager.Initialize();
|
||||
await UIManager.ReloadDrumkit();
|
||||
await UIManager.ReloadConfig();
|
||||
|
||||
try {
|
||||
await DataController.Initialize();
|
||||
Frame.Navigate(typeof(MainPage));
|
||||
}
|
||||
|
||||
// Error handling
|
||||
catch (Exception ex)
|
||||
{
|
||||
TextLoading.Text = "Failure: " + ex.Message;
|
||||
catch (Exception ex) {
|
||||
error = true;
|
||||
Log.Error("Failure during loading!");
|
||||
Log.Except(ex);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
var dialog = new Windows.UI.Popups.MessageDialog("A problem occurred, and the application could not be loaded.", "An error occurred!");
|
||||
dialog.Commands.Add(new Windows.UI.Popups.UICommand("Close", new Windows.UI.Popups.UICommandInvokedHandler(UICommandCloseHandler)));
|
||||
dialog.CancelCommandIndex = dialog.DefaultCommandIndex = 0;
|
||||
await dialog.ShowAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Application failed to load
|
||||
/// </summary>
|
||||
private async void UICommandCloseHandler(Windows.UI.Popups.IUICommand cmd)
|
||||
{
|
||||
await System.Threading.Tasks.Task.Delay(1000);
|
||||
Windows.ApplicationModel.Core.CoreApplication.Exit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Progress event
|
||||
/// </summary>
|
||||
void DataController_ProgressChanged(object sender, KeyValuePair<int, string> e)
|
||||
{
|
||||
progressBar.Value = e.Key;
|
||||
textLoading.Text = e.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,21 +6,19 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
<Page.Transitions>
|
||||
<TransitionCollection>
|
||||
<EntranceThemeTransition />
|
||||
</TransitionCollection>
|
||||
</Page.Transitions>
|
||||
|
||||
<Grid
|
||||
Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
|
||||
|
||||
<Image Source="ms-appx:///Assets/bg.png"
|
||||
Stretch="UniformToFill"/>
|
||||
|
||||
<Grid Name="canvasContainer" />
|
||||
|
||||
<Grid Visibility="Collapsed">
|
||||
<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"
|
||||
@ -51,34 +49,49 @@
|
||||
</EventTrigger>
|
||||
</Canvas.Triggers>
|
||||
</Canvas>
|
||||
<!--<StackPanel Orientation="Horizontal"
|
||||
<StackPanel Orientation="Horizontal"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top">
|
||||
<Button>Record</Button>
|
||||
<Button>Stop</Button>
|
||||
</StackPanel>-->
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Grid>-->
|
||||
|
||||
</Grid>
|
||||
|
||||
|
||||
|
||||
<Page.BottomAppBar>
|
||||
<AppBar>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
|
||||
<ToggleButton
|
||||
Name="buttonAnimations"
|
||||
Click="buttonAnimations_Click"
|
||||
AutomationProperties.Name="Animations"
|
||||
IsChecked="True"
|
||||
Style="{StaticResource VideoAppBarButtonStyle}" />
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<ToggleButton
|
||||
Name="buttonEditMode"
|
||||
Click="buttonEditMode_Click"
|
||||
Style="{StaticResource EditAppBarButtonStyle}" />
|
||||
|
||||
</StackPanel>
|
||||
<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>
|
||||
|
@ -2,9 +2,13 @@
|
||||
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;
|
||||
@ -22,31 +26,263 @@ namespace DrumKit
|
||||
/// </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;
|
||||
|
||||
this.canvasContainer.Children.Add(UIManager.TheCanvas);
|
||||
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)
|
||||
{
|
||||
// TODO: Find best layout, and change it
|
||||
DrumsManager.SetLayout();
|
||||
UIManager.ReloadLayout();
|
||||
this.ReloadLayout();
|
||||
this.ReloadLayout();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles page load event.
|
||||
/// </summary>
|
||||
void MainPage_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Set layout
|
||||
DrumsManager.SetLayout();
|
||||
UIManager.ReloadLayout();
|
||||
this.ReloadLayout();
|
||||
|
||||
// Set toggles
|
||||
buttonAnimations.IsChecked = DataManager.Settings.Animations;
|
||||
buttonAnimations.IsChecked = DataController.Settings.Animations;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -56,29 +292,33 @@ namespace DrumKit
|
||||
/// property is typically used to configure the page.</param>
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
Window.Current.CoreWindow.KeyDown += UIManager.HandlerKeyDown;
|
||||
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 -= UIManager.HandlerKeyDown;
|
||||
Window.Current.CoreWindow.KeyDown -= this.HandlerKeyDown;
|
||||
}
|
||||
|
||||
private void buttonEditMode_Click(object sender, RoutedEventArgs e)
|
||||
#endregion
|
||||
|
||||
#region UI: Buttons
|
||||
/// <summary>
|
||||
/// Handles the edit button, going into the editor.
|
||||
/// </summary>
|
||||
private void ButtonEditMode_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 visibility of thumbs
|
||||
if (isChecked) UIManager.EnterEdit();
|
||||
else UIManager.ExitEdit();
|
||||
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;
|
||||
@ -90,8 +330,21 @@ namespace DrumKit
|
||||
VisualStateManager.GoToState(button, isChecked ? "Checked" : "Unchecked", false);
|
||||
|
||||
// Change animation setting
|
||||
DataManager.Settings.Animations = isChecked;
|
||||
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
|
||||
|
||||
}
|
||||
}
|
||||
|
108
DrumKit/UI/Settings/DrumkitsSettingsControl.xaml
Normal file
108
DrumKit/UI/Settings/DrumkitsSettingsControl.xaml
Normal file
@ -0,0 +1,108 @@
|
||||
<UserControl
|
||||
x:Class="DrumKit.DrumkitsSettingsControl"
|
||||
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="321.429"
|
||||
d:DesignWidth="696.617">
|
||||
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/Common/TextButtonStyles.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
|
||||
<DataTemplate x:Key="DrumkitListDataTemplate">
|
||||
<Grid Name="theGrid">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Left thing -->
|
||||
<Border Name="orangeBorder"
|
||||
Grid.Column="0" Grid.RowSpan="3"
|
||||
Background="OrangeRed" Width="10" />
|
||||
|
||||
<!--<Image MinWidth="10"
|
||||
Source="{Binding Thumbnail}" />-->
|
||||
|
||||
<!-- Name -->
|
||||
<TextBox Grid.Column="1" Grid.Row="0" Margin="15,2,15,0"
|
||||
FontSize="15.3"
|
||||
Style="{StaticResource MyTextBoxStyle}"
|
||||
IsReadOnly="True"
|
||||
Text="{Binding Name}"
|
||||
TextChanged="NameTextChanged"/>
|
||||
|
||||
<!-- Description -->
|
||||
<TextBox Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1" Margin="15,0,15,2"
|
||||
Style="{StaticResource MyTextBoxStyle}"
|
||||
Text="{Binding Description}"
|
||||
TextChanged="DescriptionTextChanged"
|
||||
FontSize="13"
|
||||
FontStyle="Italic"
|
||||
IsReadOnly="True"
|
||||
AcceptsReturn="True"
|
||||
TextWrapping="Wrap"
|
||||
Height="80" />
|
||||
|
||||
</Grid>
|
||||
|
||||
</DataTemplate>
|
||||
|
||||
<Style x:Key="ListViewStretchItemStyle" TargetType="ListViewItem">
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||
</Style>
|
||||
|
||||
</ResourceDictionary>
|
||||
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Drumkit list -->
|
||||
<ListView Name="listDrumkits"
|
||||
Grid.Row="0" Grid.Column="0"
|
||||
ItemTemplate="{StaticResource DrumkitListDataTemplate}"
|
||||
ItemContainerStyle="{StaticResource ListViewStretchItemStyle}"
|
||||
SelectionMode="Single" >
|
||||
|
||||
</ListView>
|
||||
|
||||
<ProgressRing
|
||||
Name="progressRing"
|
||||
Foreground="White"
|
||||
Width="50" Height="50" />
|
||||
|
||||
<!-- Buttons -->
|
||||
<StackPanel Grid.Row="1" Grid.ColumnSpan="2" Orientation="Horizontal">
|
||||
<!--<Button Style="{StaticResource MyButtonStyle}" Click="ButtonCreate_Click">Create</Button>-->
|
||||
<Button Style="{StaticResource MyButtonStyle}" Click="ButtonImport_Click">Import</Button>
|
||||
<Button Style="{StaticResource MyButtonStyle}" Click="ButtonExport_Click">Export</Button>
|
||||
<Border Width="20" />
|
||||
<Button Style="{StaticResource MyButtonStyle}" Click="ButtonDelete_Click">Delete</Button>
|
||||
<Button Style="{StaticResource MyButtonStyle}" Click="ButtonSetCurrent_Clicked">Set current</Button>
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
|
||||
</UserControl>
|
319
DrumKit/UI/Settings/DrumkitsSettingsControl.xaml.cs
Normal file
319
DrumKit/UI/Settings/DrumkitsSettingsControl.xaml.cs
Normal file
@ -0,0 +1,319 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Windows.Data.Xml.Dom;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.UI;
|
||||
using Windows.UI.Notifications;
|
||||
using Windows.UI.Popups;
|
||||
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;
|
||||
|
||||
|
||||
namespace DrumKit
|
||||
{
|
||||
public sealed partial class DrumkitsSettingsControl : UserControl
|
||||
{
|
||||
#region Initialization
|
||||
/// <summary>
|
||||
/// Creates a new instance of DrumkitsSettingsControl
|
||||
/// </summary>
|
||||
public DrumkitsSettingsControl()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.Loaded += DrumkitsSettingsControl_Loaded;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads drumkit list at startup
|
||||
/// </summary>
|
||||
void DrumkitsSettingsControl_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ReloadDrumkits();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Reload drumkit list
|
||||
|
||||
/// <summary>
|
||||
/// Reloads the list of drumkits from the data controller
|
||||
/// </summary>
|
||||
async void ReloadDrumkits()
|
||||
{
|
||||
// Remove previous stuff
|
||||
this.listDrumkits.Items.Clear();
|
||||
|
||||
// Add new stuff
|
||||
foreach (var i in DataController.AvailableDrumkits)
|
||||
this.listDrumkits.Items.Add(i.Value);
|
||||
|
||||
// Wait containers to be generated
|
||||
await System.Threading.Tasks.Task.Delay(50);
|
||||
|
||||
// Update visual stuff
|
||||
foreach (var i in this.listDrumkits.Items)
|
||||
{
|
||||
var it = i as Drumkit;
|
||||
|
||||
// Is current?
|
||||
if (DataController.Settings.CurrentKit == it.Name)
|
||||
{
|
||||
// Get border and grid
|
||||
var container = listDrumkits.ItemContainerGenerator.ContainerFromItem(it) as FrameworkElement;
|
||||
Border b = UIHelper.FindChildByName(container, "orangeBorder") as Border;
|
||||
Grid g = UIHelper.FindChildByName(container, "theGrid") as Grid;
|
||||
|
||||
// Change look
|
||||
if (b != null) b.Background = new SolidColorBrush(Color.FromArgb(0xff, 0xff, 0x78, 0x33));
|
||||
if (g != null) g.Background = new SolidColorBrush(Color.FromArgb(0x1f, 0xff, 0xef, 0xdf));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI Handlers: Text boxes
|
||||
/// <summary>
|
||||
/// Handles drumkit name change
|
||||
/// </summary>
|
||||
private void NameTextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
var drumkit = (sender as FrameworkElement).DataContext as Drumkit;
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles drumkit description change
|
||||
/// </summary>
|
||||
private void DescriptionTextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
var drumkit = (sender as FrameworkElement).DataContext as Drumkit;
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI Handlers: Buttons
|
||||
/// <summary>
|
||||
/// Handles the Create button
|
||||
/// </summary>
|
||||
private void ButtonCreate_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the Import button
|
||||
/// </summary>
|
||||
private async void ButtonImport_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Error handling
|
||||
string error = null;
|
||||
|
||||
// Create file picker
|
||||
Windows.Storage.Pickers.FileOpenPicker picker = new Windows.Storage.Pickers.FileOpenPicker();
|
||||
picker.CommitButtonText = "Select drum package";
|
||||
picker.FileTypeFilter.Add(".tar");
|
||||
picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Downloads;
|
||||
|
||||
// Pick a tarball
|
||||
var tarball = await picker.PickSingleFileAsync();
|
||||
|
||||
if (tarball == null)
|
||||
return;
|
||||
|
||||
// Enable progress ring
|
||||
progressRing.IsActive = true;
|
||||
|
||||
// See if it works
|
||||
try
|
||||
{
|
||||
await DataController.InstallDrumkit(tarball);
|
||||
ReloadDrumkits();
|
||||
}
|
||||
|
||||
catch (Repository.RepositoryException ex)
|
||||
{
|
||||
error = "A drumkit package with the same name already exists!";
|
||||
Log.Except(ex);
|
||||
}
|
||||
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
error = "The selected file is not a valid drumkit package!";
|
||||
Log.Except(ex);
|
||||
}
|
||||
|
||||
catch (IOException ex)
|
||||
{
|
||||
error = "The selected file is not a valid drumkit package!";
|
||||
Log.Except(ex);
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = "An unexpected error occured while importing the drumkit package!";
|
||||
Log.Except(ex);
|
||||
}
|
||||
|
||||
// Disable progress ring
|
||||
progressRing.IsActive = false;
|
||||
|
||||
// Show error if any occured
|
||||
if (!string.IsNullOrEmpty(error))
|
||||
{
|
||||
MessageDialog err = new MessageDialog(error, "An error occured!");
|
||||
await err.ShowAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the Delete button
|
||||
/// </summary>
|
||||
private async void ButtonDelete_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Get the selected drumkit
|
||||
Drumkit selected = listDrumkits.SelectedItem as Drumkit;
|
||||
string error = null;
|
||||
|
||||
// Try to delete
|
||||
if (selected != null)
|
||||
try
|
||||
{
|
||||
await DataController.RemoveDrumkit(selected.Name);
|
||||
ReloadDrumkits();
|
||||
}
|
||||
|
||||
catch (ControllerException ex)
|
||||
{
|
||||
error = "There has to be at least one drumkit remaining!";
|
||||
Log.Except(ex);
|
||||
}
|
||||
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
error = "Cannot delete the currently loaded drumkit!";
|
||||
Log.Except(ex);
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = "An unexpected error occured while deleting the drumkit!";
|
||||
Log.Except(ex);
|
||||
}
|
||||
|
||||
// Show error if any occured
|
||||
if (!string.IsNullOrEmpty(error))
|
||||
{
|
||||
MessageDialog err = new MessageDialog(error, "An error occured!");
|
||||
await err.ShowAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the Export button
|
||||
/// </summary>
|
||||
private async void ButtonExport_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Variables
|
||||
Drumkit selected = listDrumkits.SelectedItem as Drumkit;
|
||||
string error = null;
|
||||
|
||||
// Make sure there is something selected
|
||||
if (selected == null) return;
|
||||
|
||||
// Pick a file
|
||||
Windows.Storage.Pickers.FileSavePicker picker = new Windows.Storage.Pickers.FileSavePicker();
|
||||
picker.CommitButtonText = "Export drum package";
|
||||
picker.FileTypeChoices.Add("Tarball", new string[] { ".tar" } );
|
||||
picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
|
||||
var file = await picker.PickSaveFileAsync();
|
||||
|
||||
if (file == null) return;
|
||||
|
||||
// Enable progress ring
|
||||
progressRing.IsActive = true;
|
||||
|
||||
// See if it works
|
||||
try {
|
||||
await DataController.ExportDrumkit(selected.Name, file);
|
||||
}
|
||||
|
||||
catch (IOException ex)
|
||||
{
|
||||
error = "An unexpected error occured while exporting the drumkit package!";
|
||||
Log.Except(ex);
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = "An unexpected error occured while exporting the drumkit package!";
|
||||
Log.Except(ex);
|
||||
}
|
||||
|
||||
// Disable progress ring
|
||||
progressRing.IsActive = false;
|
||||
|
||||
// Show error if any occured
|
||||
if (!string.IsNullOrEmpty(error))
|
||||
{
|
||||
MessageDialog err = new MessageDialog(error, "An error occured!");
|
||||
await err.ShowAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the SetCurrent button
|
||||
/// </summary>
|
||||
private async void ButtonSetCurrent_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var drumkit = listDrumkits.SelectedItem as Drumkit;
|
||||
|
||||
if (drumkit != null && drumkit.Name != DataController.Settings.CurrentKit)
|
||||
{
|
||||
// Change drumkit
|
||||
DataController.Settings.CurrentKit = drumkit.Name;
|
||||
DataController.SaveSettings();
|
||||
|
||||
// Reload list
|
||||
ReloadDrumkits();
|
||||
|
||||
// Notify that the application needs to be restarted
|
||||
MessageDialog dialog = new MessageDialog("The application needs to be restarted in " +
|
||||
"order to change the current drumkit. If not restarted now, the selected drumkit " +
|
||||
"will be loaded the next time the application is started. ", "Application restart required");
|
||||
|
||||
dialog.Commands.Add(new UICommand("Restart application", new UICommandInvokedHandler(UICommandRestartHandler)));
|
||||
dialog.Commands.Add(new UICommand("Close"));
|
||||
dialog.DefaultCommandIndex = 1;
|
||||
|
||||
await dialog.ShowAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UI Command that restarts the application, when current drumkit changes
|
||||
/// </summary>
|
||||
private void UICommandRestartHandler(Windows.UI.Popups.IUICommand cmd)
|
||||
{
|
||||
if (Window.Current.Content is Frame)
|
||||
{
|
||||
Frame frame = (Frame)Window.Current.Content;
|
||||
frame.Navigate(typeof(LoadingPage), "drumkitchange");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
164
DrumKit/UI/Settings/DrumsSettingsControl.xaml
Normal file
164
DrumKit/UI/Settings/DrumsSettingsControl.xaml
Normal file
@ -0,0 +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>
|
236
DrumKit/UI/Settings/DrumsSettingsControl.xaml.cs
Normal file
236
DrumKit/UI/Settings/DrumsSettingsControl.xaml.cs
Normal file
@ -0,0 +1,236 @@
|
||||
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
|
||||
|
||||
}
|
||||
}
|
26
DrumKit/UI/Settings/ExperimentsSettingsControl.xaml
Normal file
26
DrumKit/UI/Settings/ExperimentsSettingsControl.xaml
Normal file
@ -0,0 +1,26 @@
|
||||
<UserControl
|
||||
x:Class="DrumKit.ExperimentsSettingsControl"
|
||||
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">
|
||||
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/Common/TextButtonStyles.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Canvas Name="canvas">
|
||||
<StackPanel>
|
||||
<TextBox Style="{StaticResource MyTextBoxStyle}" Width="200" Text="Hello world!"/>
|
||||
</StackPanel>
|
||||
|
||||
</Canvas>
|
||||
</UserControl>
|
31
DrumKit/UI/Settings/ExperimentsSettingsControl.xaml.cs
Normal file
31
DrumKit/UI/Settings/ExperimentsSettingsControl.xaml.cs
Normal file
@ -0,0 +1,31 @@
|
||||
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 ExperimentsSettingsControl : UserControl
|
||||
{
|
||||
public ExperimentsSettingsControl()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
|
||||
DrumPlayUI ui = new DrumPlayUI(DataController.CurrentDrumkit.Drums.First().Value);
|
||||
canvas.Children.Add(ui);
|
||||
Canvas.SetTop(ui, 100);
|
||||
Canvas.SetLeft(ui, 300);
|
||||
}
|
||||
}
|
||||
}
|
174
DrumKit/UI/Settings/GeneralSettingsControl.xaml
Normal file
174
DrumKit/UI/Settings/GeneralSettingsControl.xaml
Normal file
@ -0,0 +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>
|
120
DrumKit/UI/Settings/GeneralSettingsControl.xaml.cs
Normal file
120
DrumKit/UI/Settings/GeneralSettingsControl.xaml.cs
Normal file
@ -0,0 +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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
92
DrumKit/UI/Settings/LayoutsSettingsControl.xaml
Normal file
92
DrumKit/UI/Settings/LayoutsSettingsControl.xaml
Normal file
@ -0,0 +1,92 @@
|
||||
<UserControl
|
||||
x:Class="DrumKit.LayoutsSettingsControl"
|
||||
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">
|
||||
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
|
||||
<DataTemplate x:Key="DrumkitListDataTemplate">
|
||||
<Grid Name="theGrid">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Left thing -->
|
||||
<Border Name="greenBorder"
|
||||
Grid.Column="0" Grid.RowSpan="3"
|
||||
Background="GreenYellow" Width="10" />
|
||||
|
||||
<!-- Name -->
|
||||
<TextBox Grid.Column="1" Grid.Row="0" Margin="15,2,15,0"
|
||||
FontSize="15.3"
|
||||
Style="{StaticResource MyTextBoxStyle}"
|
||||
Text="{Binding Name}"
|
||||
TextChanged="NameTextChanged" />
|
||||
|
||||
<!-- Description -->
|
||||
<StackPanel Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1" Margin="15,0,15,2"
|
||||
Orientation="Horizontal">
|
||||
<ToggleButton Name="toggleLandscape" Click="ToggleLandscape_Click">Landscape</ToggleButton>
|
||||
<ToggleButton Name="togglePortrait" Click="TogglePortrait_Click">Portrait</ToggleButton>
|
||||
<ToggleButton Name="toggleFilled" Click="ToggleFilled_Click">Filled</ToggleButton>
|
||||
<ToggleButton Name="toggleSnapped" Click="ToggleSnapped_Click">Snapped</ToggleButton>
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
|
||||
</DataTemplate>
|
||||
|
||||
<Style x:Key="ListViewStretchItemStyle" TargetType="ListViewItem">
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||
</Style>
|
||||
|
||||
</ResourceDictionary>
|
||||
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Drumkit list -->
|
||||
<ListView Name="listLayouts"
|
||||
Grid.Row="0" Grid.Column="0"
|
||||
ItemTemplate="{StaticResource DrumkitListDataTemplate}"
|
||||
ItemContainerStyle="{StaticResource ListViewStretchItemStyle}"
|
||||
SelectionMode="Single" >
|
||||
|
||||
<local:DrumkitLayout IsDefault="True" Name="Hello world" TargetViewSerialize="All" />
|
||||
|
||||
<TextBlock>Hello world!</TextBlock>
|
||||
|
||||
</ListView>
|
||||
|
||||
<!-- Buttons -->
|
||||
<StackPanel Grid.Row="1" Grid.ColumnSpan="2" Orientation="Horizontal">
|
||||
<Button Style="{StaticResource MyButtonStyle}" Click="ButtonCreate_Click">Create</Button>
|
||||
<Button Style="{StaticResource MyButtonStyle}" Click="ButtonEdit_Click">Edit</Button>
|
||||
<Button Style="{StaticResource MyButtonStyle}" Click="ButtonDelete_Click">Delete</Button>
|
||||
<Button Style="{StaticResource MyButtonStyle}" Click="ButtonToggleActive_Click">Toggle active</Button>
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
248
DrumKit/UI/Settings/LayoutsSettingsControl.xaml.cs
Normal file
248
DrumKit/UI/Settings/LayoutsSettingsControl.xaml.cs
Normal file
@ -0,0 +1,248 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.UI;
|
||||
using Windows.UI.Popups;
|
||||
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 LayoutsSettingsControl : UserControl
|
||||
{
|
||||
#region Initialization
|
||||
/// <summary>
|
||||
/// Creates a new instance of LayoutsSettingsControl
|
||||
/// </summary>
|
||||
public LayoutsSettingsControl()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.Loaded += LayoutsSettingsControl_Loaded;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads layout list at startup
|
||||
/// </summary>
|
||||
void LayoutsSettingsControl_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ReloadLayouts();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Reloads the list of layouts
|
||||
|
||||
/// <summary>
|
||||
/// Reloads the list of layouts
|
||||
/// </summary>
|
||||
async void ReloadLayouts()
|
||||
{
|
||||
// Clear previous stuff
|
||||
listLayouts.Items.Clear();
|
||||
|
||||
// Add new stuff
|
||||
foreach (var i in DataController.CurrentLayouts.Items)
|
||||
this.listLayouts.Items.Add(i);
|
||||
|
||||
// Wait for containers to be generated
|
||||
await System.Threading.Tasks.Task.Delay(50);
|
||||
|
||||
// Update visual stuff
|
||||
foreach (var i in this.listLayouts.Items)
|
||||
{
|
||||
var it = i as DrumkitLayout;
|
||||
|
||||
// Set up target views
|
||||
var container = listLayouts.ItemContainerGenerator.ContainerFromItem(i) as FrameworkElement;
|
||||
ToggleButton fi = UIHelper.FindChildByName(container, "toggleFilled") as ToggleButton;
|
||||
ToggleButton la = UIHelper.FindChildByName(container, "toggleLandscape") as ToggleButton;
|
||||
ToggleButton po = UIHelper.FindChildByName(container, "togglePortrait") as ToggleButton;
|
||||
ToggleButton sn = UIHelper.FindChildByName(container, "toggleSnapped") as ToggleButton;
|
||||
|
||||
if (fi != null) fi.IsChecked = (it.TargetView & DrumkitLayoutTargetView.Filled) > 0;
|
||||
if (la != null) la.IsChecked = (it.TargetView & DrumkitLayoutTargetView.Landscape) > 0;
|
||||
if (po != null) po.IsChecked = (it.TargetView & DrumkitLayoutTargetView.Portrait) > 0;
|
||||
if (sn != null) sn.IsChecked = (it.TargetView & DrumkitLayoutTargetView.Snapped) > 0;
|
||||
|
||||
// Is active?
|
||||
if (it.IsDefault)
|
||||
{
|
||||
// Change grid look
|
||||
Grid g = UIHelper.FindChildByName(container, "theGrid") as Grid;
|
||||
if (g != null) g.Background = new SolidColorBrush(Color.FromArgb(0x1f, 0xad, 0xff, 0x2f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI Handlers: Items
|
||||
|
||||
/// <summary>
|
||||
/// Handles layout name change.
|
||||
/// </summary>
|
||||
private void NameTextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
// Get layout object
|
||||
var textbox = sender as TextBox;
|
||||
var layout = (sender as FrameworkElement).DataContext as DrumkitLayout;
|
||||
int index = DataController.CurrentLayouts.Items.IndexOf(layout);
|
||||
|
||||
// Change name
|
||||
if (index != -1)
|
||||
DataController.CurrentLayouts.Items[index].Name = textbox.Text;
|
||||
|
||||
// Save changes
|
||||
DataController.SaveLayout();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles target view change.
|
||||
/// </summary>
|
||||
private void TogglesCommon(object sender, DrumkitLayoutTargetView view)
|
||||
{
|
||||
// Get layout object
|
||||
var button = sender as ToggleButton;
|
||||
var layout = (sender as FrameworkElement).DataContext as DrumkitLayout;
|
||||
int i = DataController.CurrentLayouts.Items.IndexOf(layout);
|
||||
|
||||
// Shouldn't happen
|
||||
if (i == -1)
|
||||
return;
|
||||
|
||||
// Change target view value
|
||||
if (button.IsChecked.HasValue && button.IsChecked.Value)
|
||||
DataController.CurrentLayouts.Items[i].TargetView |= view;
|
||||
|
||||
else DataController.CurrentLayouts.Items[i].TargetView &= ~view;
|
||||
|
||||
// Save modified setting
|
||||
DataController.SaveLayout();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles "Landscape" toggle button.
|
||||
/// </summary>
|
||||
private void ToggleLandscape_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
TogglesCommon(sender, DrumkitLayoutTargetView.Landscape);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles "Portrait" toggle button.
|
||||
/// </summary>
|
||||
private void TogglePortrait_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
TogglesCommon(sender, DrumkitLayoutTargetView.Portrait);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles "Filled" toggle button.
|
||||
/// </summary>
|
||||
private void ToggleFilled_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
TogglesCommon(sender, DrumkitLayoutTargetView.Filled);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles "Snapped" toggle button.
|
||||
/// </summary>
|
||||
private void ToggleSnapped_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
TogglesCommon(sender, DrumkitLayoutTargetView.Snapped);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI Handlers: Buttons
|
||||
|
||||
/// <summary>
|
||||
/// Handles the "Create" button
|
||||
/// </summary>
|
||||
private void ButtonCreate_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Create layout
|
||||
DataController.CreateLayout();
|
||||
|
||||
// Reload list
|
||||
this.ReloadLayouts();
|
||||
}
|
||||
|
||||
private void ButtonEdit_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Ignore if nothing selected
|
||||
if (this.listLayouts.SelectedItem == null)
|
||||
return;
|
||||
|
||||
// Go to editor
|
||||
if (Window.Current.Content is Frame)
|
||||
{
|
||||
Frame frame = (Frame)Window.Current.Content;
|
||||
frame.Navigate(typeof(EditorPage), this.listLayouts.SelectedItem);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the "Delete" button
|
||||
/// </summary>
|
||||
private async void ButtonDelete_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Make sure there is at least one layout remaining
|
||||
if (DataController.CurrentLayouts.Items.Count <= 1)
|
||||
{
|
||||
MessageDialog dialog = new MessageDialog("There has to be at least one layout remaining!", "Error");
|
||||
await dialog.ShowAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
// Get layout object
|
||||
var layout = listLayouts.SelectedItem as DrumkitLayout;
|
||||
int i = DataController.CurrentLayouts.Items.IndexOf(layout);
|
||||
|
||||
// Delete from list
|
||||
DataController.CurrentLayouts.Items.Remove(layout);
|
||||
|
||||
// Save changes
|
||||
DataController.SaveLayout();
|
||||
|
||||
// Refresh list
|
||||
this.ReloadLayouts();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the "Toggle active" button
|
||||
/// </summary>
|
||||
private void ButtonToggleActive_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Get layout object
|
||||
var layout = listLayouts.SelectedItem as DrumkitLayout;
|
||||
int i = DataController.CurrentLayouts.Items.IndexOf(layout);
|
||||
|
||||
// Find layout?
|
||||
if (i != -1)
|
||||
{
|
||||
// Toggle active
|
||||
DataController.CurrentLayouts.Items[i].IsDefault = !DataController.CurrentLayouts.Items[i].IsDefault;
|
||||
|
||||
// Save modified setting
|
||||
DataController.SaveLayout();
|
||||
|
||||
// Reload list
|
||||
ReloadLayouts();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
37
DrumKit/UI/Settings/LogControl.xaml
Normal file
37
DrumKit/UI/Settings/LogControl.xaml
Normal file
@ -0,0 +1,37 @@
|
||||
<UserControl
|
||||
x:Class="DrumKit.LogControl"
|
||||
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>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="2.5*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ListView Name="logEntriesList" Grid.Column="0" Margin="5"
|
||||
Background="#3FFF"
|
||||
SelectionChanged="LogEntriesList_SelectionChanged"/>
|
||||
|
||||
<Rectangle Name="logTextPlaceholder" Grid.Column="1" Margin="0,5,5,5" />
|
||||
<WebView Name="logText" Grid.Column="1" Margin="0,5,5,5"/>
|
||||
|
||||
<StackPanel Grid.Row="1" Grid.ColumnSpan="5" Orientation="Horizontal">
|
||||
<Button Style="{StaticResource MyButtonStyle}" Click="ButtonSave_Click">Save as</Button>
|
||||
<Button Style="{StaticResource MyButtonStyle}" Click="ButtonClear_Click">Delete all</Button>
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
|
||||
</UserControl>
|
156
DrumKit/UI/Settings/LogControl.xaml.cs
Normal file
156
DrumKit/UI/Settings/LogControl.xaml.cs
Normal file
@ -0,0 +1,156 @@
|
||||
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.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 LogControl : UserControl
|
||||
{
|
||||
#region Constructor
|
||||
/// <summary>
|
||||
/// Creates a new instance of log page
|
||||
/// </summary>
|
||||
public LogControl()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.Loaded += LogControl_Loaded;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Initialization
|
||||
/// <summary>
|
||||
/// Initialization performed when the page is loaded.
|
||||
/// </summary>
|
||||
private async void LogControl_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Reload entries
|
||||
await ReloadEntries();
|
||||
}
|
||||
|
||||
private async Task ReloadEntries()
|
||||
{
|
||||
// Get list of log files
|
||||
await Repository.LogRepository.ReadLogFiles();
|
||||
|
||||
// Create list
|
||||
this.logEntriesList.Items.Clear();
|
||||
foreach (DateTime i in Repository.LogRepository.Dates)
|
||||
this.logEntriesList.Items.Add(i);
|
||||
|
||||
// Set selected item
|
||||
int index = Repository.LogRepository.Dates.IndexOf(Repository.LogRepository.CurrentLogDate);
|
||||
this.logEntriesList.SelectedIndex = index;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI Events
|
||||
|
||||
/// <summary>
|
||||
/// Handles selection changed action.
|
||||
/// </summary>
|
||||
private void LogEntriesList_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
// Load selected log file
|
||||
if (logEntriesList.SelectedItem is DateTime)
|
||||
LoadLogFile((DateTime)logEntriesList.SelectedItem);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles clear button
|
||||
/// </summary>
|
||||
private async void ButtonClear_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
await Repository.LogRepository.Clear();
|
||||
await this.ReloadEntries();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles saving currently selected log file.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private async void ButtonSave_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Sanity check
|
||||
if (!(logEntriesList.SelectedItem is DateTime)) return;
|
||||
|
||||
// Pick a destination folder
|
||||
var picker = new Windows.Storage.Pickers.FolderPicker();
|
||||
picker.FileTypeFilter.Add("*");
|
||||
picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
|
||||
var destination = await picker.PickSingleFolderAsync();
|
||||
|
||||
// Save
|
||||
if (destination != null)
|
||||
await Repository.LogRepository.SaveAs((DateTime)logEntriesList.SelectedItem, destination);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Misc
|
||||
/// <summary>
|
||||
/// Loads a log file, and converts it to html for display.
|
||||
/// </summary>
|
||||
private async void LoadLogFile(DateTime dt)
|
||||
{
|
||||
// Get file contents
|
||||
var lines = await Repository.LogRepository.ReadLog(dt);
|
||||
|
||||
// Generate HTML
|
||||
System.Text.StringBuilder html = new System.Text.StringBuilder();
|
||||
|
||||
html.Append("<html><body style=\"font-family: Helvetica;\">");
|
||||
|
||||
foreach (var i in lines)
|
||||
{
|
||||
if (i.Contains("ERROR"))
|
||||
{
|
||||
html.Append("<p style=\"color: red;\">");
|
||||
html.Append(i);
|
||||
html.Append("</p>");
|
||||
}
|
||||
|
||||
else if (i.Contains("EXCEPTION"))
|
||||
{
|
||||
html.Append("<p style=\"background-color: darkred; color: white;\">");
|
||||
html.Append(i);
|
||||
html.Append("</p>");
|
||||
}
|
||||
|
||||
else if (i.TrimStart(' ').StartsWith("at"))
|
||||
{
|
||||
html.Insert(html.Length - 4, "<br />" + i);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
html.Append("<p>");
|
||||
html.Append(i);
|
||||
html.Append("</p>");
|
||||
}
|
||||
}
|
||||
|
||||
html.Append("</body></html>");
|
||||
|
||||
// Set text
|
||||
this.logText.NavigateToString(html.ToString());
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
136
DrumKit/UI/SettingsPage.xaml
Normal file
136
DrumKit/UI/SettingsPage.xaml
Normal file
@ -0,0 +1,136 @@
|
||||
<Page
|
||||
x:Class="DrumKit.SettingsPage"
|
||||
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>
|
||||
<Style x:Key="TabRadioButtonStyle" TargetType="RadioButton">
|
||||
<Setter Property="FontSize" Value="26.667"/>
|
||||
<Setter Property="FontWeight" Value="Light"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="RadioButton">
|
||||
<Border Padding="10,5,10,5">
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="CheckStates">
|
||||
<VisualStateGroup.Transitions>
|
||||
<VisualTransition GeneratedDuration="0:0:0.2"/>
|
||||
</VisualStateGroup.Transitions>
|
||||
<VisualState x:Name="Checked">
|
||||
<Storyboard>
|
||||
<ColorAnimation Duration="0" To="#59FFFF" Storyboard.TargetProperty="(ContentPresenter.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="contentPresenter" d:IsOptimized="True"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState x:Name="Unchecked">
|
||||
<Storyboard>
|
||||
<ColorAnimation Duration="0" To="White" Storyboard.TargetProperty="(ContentPresenter.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="contentPresenter" d:IsOptimized="True"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState x:Name="Indeterminate">
|
||||
<Storyboard>
|
||||
<ColorAnimation Duration="0" To="White" Storyboard.TargetProperty="(ContentPresenter.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="contentPresenter" d:IsOptimized="True"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
<VisualStateGroup x:Name="FocusStates"/>
|
||||
<VisualStateGroup x:Name="CommonStates"/>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
<ContentPresenter x:Name="contentPresenter"/>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</Page.Resources>
|
||||
|
||||
<Page.Transitions>
|
||||
<TransitionCollection>
|
||||
<EntranceThemeTransition />
|
||||
</TransitionCollection>
|
||||
</Page.Transitions>
|
||||
|
||||
<Border Background="{StaticResource ApplicationPageBackgroundThemeBrush}"
|
||||
Padding="40">
|
||||
<Grid >
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120"/>
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Button Name="buttonBack" Grid.Row="0" Grid.Column="0"
|
||||
Style="{StaticResource BackButtonStyle}"
|
||||
Click="buttonBack_Click_1"/>
|
||||
|
||||
<ScrollViewer Grid.Row="0" Grid.Column="1"
|
||||
ZoomMode="Disabled"
|
||||
HorizontalScrollMode="Enabled"
|
||||
HorizontalScrollBarVisibility="Hidden"
|
||||
VerticalScrollBarVisibility="Disabled"
|
||||
VerticalScrollMode="Disabled"
|
||||
VerticalAlignment="Top">
|
||||
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<StackPanel.ChildrenTransitions>
|
||||
<TransitionCollection>
|
||||
<EntranceThemeTransition />
|
||||
</TransitionCollection>
|
||||
</StackPanel.ChildrenTransitions>
|
||||
<RadioButton Name="radioGeneral"
|
||||
Style="{StaticResource TabRadioButtonStyle}"
|
||||
IsChecked="True"
|
||||
Click="radioGeneral_Click_1">
|
||||
General
|
||||
</RadioButton>
|
||||
<RadioButton Name="radioDrumkit"
|
||||
Style="{StaticResource TabRadioButtonStyle}"
|
||||
Click="radioGeneral_Click_1">
|
||||
Drumkits
|
||||
</RadioButton>
|
||||
<RadioButton Name="radioDrums"
|
||||
Style="{StaticResource TabRadioButtonStyle}"
|
||||
Click="radioGeneral_Click_1">
|
||||
Drums
|
||||
</RadioButton>
|
||||
<RadioButton Name="radioLayouts"
|
||||
Style="{StaticResource TabRadioButtonStyle}"
|
||||
Click="radioGeneral_Click_1">
|
||||
Layouts
|
||||
</RadioButton>
|
||||
<RadioButton Name="radioLogs"
|
||||
Style="{StaticResource TabRadioButtonStyle}"
|
||||
Click="radioGeneral_Click_1">
|
||||
Logs
|
||||
</RadioButton>
|
||||
<!--<RadioButton Name="radioExperiments"
|
||||
Style="{StaticResource TabRadioButtonStyle}"
|
||||
Click="radioGeneral_Click_1">
|
||||
Experiments
|
||||
</RadioButton>-->
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
|
||||
<ContentControl Name="contentControl"
|
||||
Grid.Row="1" Grid.ColumnSpan="4"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
VerticalContentAlignment="Stretch"
|
||||
VerticalAlignment="Stretch">
|
||||
<ContentControl.ContentTransitions>
|
||||
<TransitionCollection>
|
||||
<ContentThemeTransition HorizontalOffset="200" />
|
||||
</TransitionCollection>
|
||||
</ContentControl.ContentTransitions>
|
||||
</ContentControl>
|
||||
|
||||
</Grid>
|
||||
</Border>
|
||||
</Page>
|
123
DrumKit/UI/SettingsPage.xaml.cs
Normal file
123
DrumKit/UI/SettingsPage.xaml.cs
Normal file
@ -0,0 +1,123 @@
|
||||
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 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 SettingsPage : Page
|
||||
{
|
||||
string currentTabName;
|
||||
|
||||
public SettingsPage()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
|
||||
currentTabName = null;
|
||||
radioLogs.Visibility = (DataController.Settings.DebugMode) ? Visibility.Visible : Visibility.Collapsed;
|
||||
//radioExperiments.Visibility = (DataController.Settings.DebugMode) ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
// Get parameter
|
||||
string parameter = e.Parameter as string;
|
||||
|
||||
// Coming back? Probably from the editor. We should go to layouts.
|
||||
if (e.NavigationMode == NavigationMode.Back)
|
||||
parameter = "layouts";
|
||||
|
||||
// Log
|
||||
Log.Write("Navigated to settings page.");
|
||||
|
||||
// Check parameter
|
||||
switch (parameter)
|
||||
{
|
||||
case "general": radioGeneral.IsChecked = true; break;
|
||||
case "drumkits": radioDrumkit.IsChecked = true; break;
|
||||
case "drums": radioDrums.IsChecked = true; break;
|
||||
case "layouts": radioLayouts.IsChecked = true; break;
|
||||
case "logs": radioLogs.IsChecked = true; break;
|
||||
}
|
||||
|
||||
// Load content
|
||||
LoadContent();
|
||||
}
|
||||
|
||||
|
||||
private void buttonBack_Click_1(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (Frame.CanGoBack)
|
||||
Frame.GoBack();
|
||||
}
|
||||
|
||||
bool IsTrue(bool? value)
|
||||
{
|
||||
return value.HasValue && value.Value;
|
||||
}
|
||||
|
||||
void LoadContent()
|
||||
{
|
||||
if (IsTrue(radioGeneral.IsChecked) && currentTabName != radioGeneral.Name)
|
||||
{
|
||||
currentTabName = radioGeneral.Name;
|
||||
this.contentControl.Content = new GeneralSettingsControl();
|
||||
}
|
||||
|
||||
else if (IsTrue(radioDrumkit.IsChecked) && currentTabName != radioDrumkit.Name)
|
||||
{
|
||||
currentTabName = radioDrumkit.Name;
|
||||
this.contentControl.Content = new DrumkitsSettingsControl();
|
||||
}
|
||||
|
||||
else if (IsTrue(radioDrums.IsChecked) && currentTabName != radioDrums.Name)
|
||||
{
|
||||
currentTabName = radioDrums.Name;
|
||||
this.contentControl.Content = new DrumsSettingsControl();
|
||||
}
|
||||
|
||||
else if (IsTrue(radioLayouts.IsChecked) && currentTabName != radioLayouts.Name)
|
||||
{
|
||||
currentTabName = radioLayouts.Name;
|
||||
this.contentControl.Content = new LayoutsSettingsControl();
|
||||
}
|
||||
|
||||
else if (IsTrue(radioLogs.IsChecked) && currentTabName != radioLogs.Name)
|
||||
{
|
||||
currentTabName = radioLogs.Name;
|
||||
this.contentControl.Content = new DrumKit.LogControl();
|
||||
}
|
||||
|
||||
//else if (IsTrue(radioExperiments.IsChecked) && currentTabName != radioExperiments.Name)
|
||||
//{
|
||||
// currentTabName = radioExperiments.Name;
|
||||
// this.contentControl.Content = new DrumKit.ExperimentsSettingsControl();
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
private void radioGeneral_Click_1(object sender, RoutedEventArgs e)
|
||||
{
|
||||
LoadContent();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user