From 3a635c8354c40efd7426fbc3ac2c73752dd50ff3 Mon Sep 17 00:00:00 2001 From: Ian C <ianc@noddybox.co.uk> Date: Sat, 18 Feb 2012 17:38:37 +0000 Subject: Added simple config settings --- wpspec/wpspec/AboutPage.xaml | 52 ++++++++++++++++ wpspec/wpspec/AboutPage.xaml.cs | 23 +++++++ wpspec/wpspec/MainPage.xaml.cs | 4 +- wpspec/wpspec/Resources/Strings.Designer.cs | 20 +++++- wpspec/wpspec/Resources/Strings.resx | 6 ++ wpspec/wpspec/Settings.cs | 96 +++++++++++++++++++++++++++++ wpspec/wpspec/SettingsPage.xaml | 55 +++++++++++++++++ wpspec/wpspec/SettingsPage.xaml.cs | 36 +++++++++++ wpspec/wpspec/wpspec.csproj | 14 ++++- 9 files changed, 300 insertions(+), 6 deletions(-) create mode 100644 wpspec/wpspec/AboutPage.xaml create mode 100644 wpspec/wpspec/AboutPage.xaml.cs create mode 100644 wpspec/wpspec/Settings.cs create mode 100644 wpspec/wpspec/SettingsPage.xaml create mode 100644 wpspec/wpspec/SettingsPage.xaml.cs diff --git a/wpspec/wpspec/AboutPage.xaml b/wpspec/wpspec/AboutPage.xaml new file mode 100644 index 0000000..38ac6a8 --- /dev/null +++ b/wpspec/wpspec/AboutPage.xaml @@ -0,0 +1,52 @@ +<phone:PhoneApplicationPage + x:Class="wpspec.AboutPage" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" + xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:res="clr-namespace:wpspec.Resources" + FontFamily="{StaticResource PhoneFontFamilyNormal}" + FontSize="{StaticResource PhoneFontSizeNormal}" + Foreground="{StaticResource PhoneForegroundBrush}" + SupportedOrientations="Portrait" Orientation="Portrait" + mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480" + shell:SystemTray.IsVisible="True"> + + <phone:PhoneApplicationPage.Resources> + <res:Strings x:Key="Strings" /> + </phone:PhoneApplicationPage.Resources> + + <!--LayoutRoot is the root grid where all page content is placed--> + <Grid x:Name="LayoutRoot" Background="Transparent"> + <Grid.RowDefinitions> + <RowDefinition Height="Auto"/> + <RowDefinition Height="*"/> + </Grid.RowDefinitions> + + <!--ContentPanel - place additional content here--> + <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> + <Grid.RowDefinitions> + <RowDefinition Height="auto" /> + <RowDefinition Height="auto" /> + <RowDefinition Height="auto" /> + <RowDefinition Height="auto" /> + </Grid.RowDefinitions> + <TextBlock TextWrapping="Wrap" TextAlignment="Left" Grid.Row="0" + Style="{StaticResource PhoneTextNormalStyle}" Foreground="White" Margin="2,2,2,2" + Text="{Binding CopyrightText, Source={StaticResource Strings}}" /> + <HyperlinkButton Content="{Binding LicenseHyperlinkText, Source={StaticResource Strings}}" + TargetName="_blank" Grid.Row="1" + Margin="2,5,2,2" + NavigateUri="{Binding LicenseHyperlinkUri, Source={StaticResource Strings}}" /> + <HyperlinkButton Content="{Binding SourceHyperlinkText, Source={StaticResource Strings}}" + Margin="2,5,2,2" + TargetName="_blank" Grid.Row="2" + NavigateUri="{Binding SourceHyperlinkUri, Source={StaticResource Strings}}" /> + <TextBlock TextWrapping="Wrap" TextAlignment="Left" Grid.Row="3" + FontSize="24" Foreground="Red" Margin="2,2,2,2" + Text="{Binding ROMCopyrightText, Source={StaticResource Strings}}" /> + </Grid> + </Grid> +</phone:PhoneApplicationPage> diff --git a/wpspec/wpspec/AboutPage.xaml.cs b/wpspec/wpspec/AboutPage.xaml.cs new file mode 100644 index 0000000..ec8799d --- /dev/null +++ b/wpspec/wpspec/AboutPage.xaml.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; +using Microsoft.Phone.Controls; + +namespace wpspec +{ + public partial class AboutPage : PhoneApplicationPage + { + public AboutPage() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/wpspec/wpspec/MainPage.xaml.cs b/wpspec/wpspec/MainPage.xaml.cs index 4744469..26230f2 100644 --- a/wpspec/wpspec/MainPage.xaml.cs +++ b/wpspec/wpspec/MainPage.xaml.cs @@ -23,7 +23,7 @@ namespace wpspec private void SettingsClick(object sender, RoutedEventArgs e) { - NavigationService.Navigate(new Uri("/Settings.xaml", UriKind.Relative)); + NavigationService.Navigate(new Uri("/SettingsPage.xaml", UriKind.Relative)); } private void RunEmulationClick(object sender, RoutedEventArgs e) @@ -33,7 +33,7 @@ namespace wpspec private void AboutClick(object sender, RoutedEventArgs e) { - NavigationService.Navigate(new Uri("/About.xaml", UriKind.Relative)); + NavigationService.Navigate(new Uri("/AboutPage.xaml", UriKind.Relative)); } } } \ No newline at end of file diff --git a/wpspec/wpspec/Resources/Strings.Designer.cs b/wpspec/wpspec/Resources/Strings.Designer.cs index 80d881b..36310a1 100644 --- a/wpspec/wpspec/Resources/Strings.Designer.cs +++ b/wpspec/wpspec/Resources/Strings.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. -// Runtime Version:4.0.30319.239 +// Runtime Version:4.0.30319.261 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -163,6 +163,24 @@ namespace wpspec.Resources { } } + /// <summary> + /// Looks up a localized string similar to Sound. + /// </summary> + public static string SettingsSoundText { + get { + return ResourceManager.GetString("SettingsSoundText", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to Base URL for loading tapes. + /// </summary> + public static string SettingsTapeUrlText { + get { + return ResourceManager.GetString("SettingsTapeUrlText", resourceCulture); + } + } + /// <summary> /// Looks up a localized string similar to See Source Code Online. /// </summary> diff --git a/wpspec/wpspec/Resources/Strings.resx b/wpspec/wpspec/Resources/Strings.resx index 47a8b08..edb24a0 100644 --- a/wpspec/wpspec/Resources/Strings.resx +++ b/wpspec/wpspec/Resources/Strings.resx @@ -154,6 +154,12 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY <data name="SettingsPageTitle" xml:space="preserve"> <value>Settings</value> </data> + <data name="SettingsSoundText" xml:space="preserve"> + <value>Sound</value> + </data> + <data name="SettingsTapeUrlText" xml:space="preserve"> + <value>Base URL for loading tapes</value> + </data> <data name="SourceHyperlinkText" xml:space="preserve"> <value>See Source Code Online</value> </data> diff --git a/wpspec/wpspec/Settings.cs b/wpspec/wpspec/Settings.cs new file mode 100644 index 0000000..333df0b --- /dev/null +++ b/wpspec/wpspec/Settings.cs @@ -0,0 +1,96 @@ +using System; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Ink; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; +using System.IO.IsolatedStorage; +using System.Collections.Generic; + +namespace wpspec +{ + /// <summary> + /// Holds global settings + /// </summary> + public class Settings + { + /// <summary> + /// Get the singleton instance for the settings. + /// </summary> + public static Settings Get + { + get {return settings;} + } + + /// <summary> + /// Get/set whether sound is enabled. + /// </summary> + public bool Sound + { + get {return sound;} + set + { + if (sound != value) + { + sound = value; + Save("sound", sound); + } + } + } + + /// <summary> + /// Get/set URL to load tapes from. + /// </summary> + public string TapeUrl + { + get {return tapeUrl;} + set + { + if (tapeUrl != value) + { + tapeUrl = value; + Save("tapeurl", tapeUrl); + } + } + } + + + #region Private code + + private static readonly Settings settings = new Settings(); + + private bool sound; + private string tapeUrl; + + private Settings() + { + sound = Load("sound", true); + tapeUrl = Load("tapeurl", "http://enter-a-url.here/"); + } + + private T Load<T>(string name, T defaultValue) + { + try + { + return (T)IsolatedStorageSettings.ApplicationSettings[name]; + } + catch (KeyNotFoundException) + { + } + + return defaultValue; + } + + private void Save<T>(string name, T value) + { + IsolatedStorageSettings.ApplicationSettings.Add(name, value); + IsolatedStorageSettings.ApplicationSettings.Save(); + } + + #endregion + } +} diff --git a/wpspec/wpspec/SettingsPage.xaml b/wpspec/wpspec/SettingsPage.xaml new file mode 100644 index 0000000..296efa3 --- /dev/null +++ b/wpspec/wpspec/SettingsPage.xaml @@ -0,0 +1,55 @@ +<phone:PhoneApplicationPage + x:Class="wpspec.SettingsPage" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" + xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:res="clr-namespace:wpspec.Resources" + FontFamily="{StaticResource PhoneFontFamilyNormal}" + FontSize="{StaticResource PhoneFontSizeNormal}" + Foreground="{StaticResource PhoneForegroundBrush}" + SupportedOrientations="Portrait" Orientation="Portrait" + mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480" + shell:SystemTray.IsVisible="True"> + + <phone:PhoneApplicationPage.Resources> + <res:Strings x:Key="Strings" /> + </phone:PhoneApplicationPage.Resources> + + <!--LayoutRoot is the root grid where all page content is placed--> + <Grid x:Name="LayoutRoot" Background="Transparent"> + <Grid.RowDefinitions> + <RowDefinition Height="Auto"/> + <RowDefinition Height="*"/> + </Grid.RowDefinitions> + + <!--TitlePanel contains the name of the application and page title--> + <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> + <TextBlock x:Name="ApplicationTitle" + Text="{Binding AppTitle, Source={StaticResource Strings}}" + Style="{StaticResource PhoneTextNormalStyle}"/> + <TextBlock x:Name="PageTitle" + Text="{Binding SettingsPageTitle, Source={StaticResource Strings}}" + Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/> + </StackPanel> + + <!--ContentPanel - place additional content here--> + <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> + <Grid.RowDefinitions> + <RowDefinition Height="Auto"/> + <RowDefinition Height="Auto"/> + <RowDefinition Height="Auto"/> + <RowDefinition Height="*"/> + </Grid.RowDefinitions> + <CheckBox IsChecked="{Binding SoundSetting, Mode=TwoWay}" + Content="{Binding SettingsSoundText, Source={StaticResource Strings}}" + Grid.Row="0" /> + <TextBlock Text="{Binding SettingsTapeUrlText, Source={StaticResource Strings}}" + Grid.Row="1" /> + <TextBox Text="{Binding TapeUrlSetting, Mode=TwoWay}" + Grid.Row="2" /> + </Grid> + </Grid> +</phone:PhoneApplicationPage> diff --git a/wpspec/wpspec/SettingsPage.xaml.cs b/wpspec/wpspec/SettingsPage.xaml.cs new file mode 100644 index 0000000..02ac7d6 --- /dev/null +++ b/wpspec/wpspec/SettingsPage.xaml.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; +using Microsoft.Phone.Controls; + +namespace wpspec +{ + public partial class SettingsPage : PhoneApplicationPage + { + public SettingsPage() + { + InitializeComponent(); + ContentPanel.DataContext = this; + } + + public bool SoundSetting + { + get {return Settings.Get.Sound;} + set {Settings.Get.Sound = value;} + } + + public string TapeUrlSetting + { + get {return Settings.Get.TapeUrl;} + set {Settings.Get.TapeUrl = value;} + } + } +} \ No newline at end of file diff --git a/wpspec/wpspec/wpspec.csproj b/wpspec/wpspec/wpspec.csproj index cf676ca..48a0c19 100644 --- a/wpspec/wpspec/wpspec.csproj +++ b/wpspec/wpspec/wpspec.csproj @@ -63,8 +63,8 @@ <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> - <Compile Include="About.xaml.cs"> - <DependentUpon>About.xaml</DependentUpon> + <Compile Include="AboutPage.xaml.cs"> + <DependentUpon>AboutPage.xaml</DependentUpon> </Compile> <Compile Include="App.xaml.cs"> <DependentUpon>App.xaml</DependentUpon> @@ -84,13 +84,17 @@ <DesignTime>True</DesignTime> <DependentUpon>Strings.resx</DependentUpon> </Compile> + <Compile Include="Settings.cs" /> + <Compile Include="SettingsPage.xaml.cs"> + <DependentUpon>SettingsPage.xaml</DependentUpon> + </Compile> </ItemGroup> <ItemGroup> <ApplicationDefinition Include="App.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </ApplicationDefinition> - <Page Include="About.xaml"> + <Page Include="AboutPage.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> @@ -102,6 +106,10 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="SettingsPage.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> </ItemGroup> <ItemGroup> <None Include="Properties\AppManifest.xml" /> -- cgit v1.2.3