From 3a635c8354c40efd7426fbc3ac2c73752dd50ff3 Mon Sep 17 00:00:00 2001 From: Ian C 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 @@ //------------------------------------------------------------------------------ // // 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 { } } + /// + /// Looks up a localized string similar to Sound. + /// + public static string SettingsSoundText { + get { + return ResourceManager.GetString("SettingsSoundText", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Base URL for loading tapes. + /// + public static string SettingsTapeUrlText { + get { + return ResourceManager.GetString("SettingsTapeUrlText", resourceCulture); + } + } + /// /// Looks up a localized string similar to See Source Code Online. /// 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 Settings + + Sound + + + Base URL for loading tapes + See Source Code Online 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 +{ + /// + /// Holds global settings + /// + public class Settings + { + /// + /// Get the singleton instance for the settings. + /// + public static Settings Get + { + get {return settings;} + } + + /// + /// Get/set whether sound is enabled. + /// + public bool Sound + { + get {return sound;} + set + { + if (sound != value) + { + sound = value; + Save("sound", sound); + } + } + } + + /// + /// Get/set URL to load tapes from. + /// + 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(string name, T defaultValue) + { + try + { + return (T)IsolatedStorageSettings.ApplicationSettings[name]; + } + catch (KeyNotFoundException) + { + } + + return defaultValue; + } + + private void Save(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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 @@ - - About.xaml + + AboutPage.xaml App.xaml @@ -84,13 +84,17 @@ True Strings.resx + + + SettingsPage.xaml + Designer MSBuild:Compile - + Designer MSBuild:Compile @@ -102,6 +106,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + -- cgit v1.2.3