From 130b6039646ef0f5f029268dcfe0c12a464111db Mon Sep 17 00:00:00 2001 From: Baptiste ARNAUD Date: Tue, 10 Dec 2019 09:22:29 +0100 Subject: [PATCH] Serialisation du premier pseudo --- .../Properties/AndroidManifest.xml | 2 +- TheGameExtreme/IO/IOGamePreparation.cs | 26 +++++++++++++++++++ TheGameExtreme/view/GamePreparationPage.xaml | 1 + .../view/GamePreparationPage.xaml.cs | 9 +++++++ TheGameExtreme/view/HomePage.xaml.cs | 1 + 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/TheGameExtreme.Android/Properties/AndroidManifest.xml b/TheGameExtreme.Android/Properties/AndroidManifest.xml index e90eb53..c42c213 100644 --- a/TheGameExtreme.Android/Properties/AndroidManifest.xml +++ b/TheGameExtreme.Android/Properties/AndroidManifest.xml @@ -1,5 +1,5 @@  - + diff --git a/TheGameExtreme/IO/IOGamePreparation.cs b/TheGameExtreme/IO/IOGamePreparation.cs index 2a1dd28..e7bc6f8 100644 --- a/TheGameExtreme/IO/IOGamePreparation.cs +++ b/TheGameExtreme/IO/IOGamePreparation.cs @@ -12,6 +12,7 @@ namespace TheGameExtreme.IO static string pathGameModeValue = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "GameModeValue.xml"); static string pathNbStacks = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NbStacks.xml"); static string pathNbCards = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NbCards.xml"); + static string pathNameFirstPlayer = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NamePlayer.xml"); public static void SaveParamaterGamePreparationNbPlayers(int nbPlayers) { @@ -113,5 +114,30 @@ namespace TheGameExtreme.IO return 0; } } + + public static void SaveParameterGamePreparationName(string namePseudo) + { + XmlSerializer xs = new XmlSerializer(typeof(string)); + TextWriter tw = new StreamWriter(pathNameFirstPlayer); + xs.Serialize(tw, namePseudo); + tw.Close(); + } + + public static string LoadNameFromGamePrepararion() + { + XmlSerializer xs = new XmlSerializer(typeof(string)); + try + { + using (FileStream fs = new FileStream (pathNameFirstPlayer, FileMode.Open)) + { + string namePseudo = (string)xs.Deserialize(fs); + return namePseudo; + } + } + catch + { + return ""; + } + } } } diff --git a/TheGameExtreme/view/GamePreparationPage.xaml b/TheGameExtreme/view/GamePreparationPage.xaml index d40e0e4..2a38240 100644 --- a/TheGameExtreme/view/GamePreparationPage.xaml +++ b/TheGameExtreme/view/GamePreparationPage.xaml @@ -168,6 +168,7 @@ MinimumWidthRequest="50" WidthRequest="200" MaxLength="18" + x:Name="FirstEntry" IsTextPredictionEnabled="False"/> diff --git a/TheGameExtreme/view/GamePreparationPage.xaml.cs b/TheGameExtreme/view/GamePreparationPage.xaml.cs index 0b4f868..2db9fef 100644 --- a/TheGameExtreme/view/GamePreparationPage.xaml.cs +++ b/TheGameExtreme/view/GamePreparationPage.xaml.cs @@ -18,6 +18,7 @@ namespace TheGameExtreme.view { InitializeComponent(); NavigationPage.SetHasNavigationBar(this, false); + LoadParameterName(); PlayerSelecter.ItemsSource = listNbPlayer; LoadParameterNbPlayerGamePreparation(); @@ -41,6 +42,7 @@ namespace TheGameExtreme.view IOGamePreparation.SaveParameterGamePreparationGameModeValue(SelectMode.SelectedIndex); IOGamePreparation.SaveParameterGamePreparationNbStacks(SelectNbStack.SelectedIndex); IOGamePreparation.SaveParameterGamePreparationNbCards(SelectNbCard.SelectedIndex); + IOGamePreparation.SaveParameterGamePreparationName(FirstEntry.Text); await Navigation.PopAsync(); } @@ -50,6 +52,7 @@ namespace TheGameExtreme.view IOGamePreparation.SaveParameterGamePreparationGameModeValue(SelectMode.SelectedIndex); IOGamePreparation.SaveParameterGamePreparationNbStacks(SelectNbStack.SelectedIndex); IOGamePreparation.SaveParameterGamePreparationNbCards(SelectNbCard.SelectedIndex); + IOGamePreparation.SaveParameterGamePreparationName(FirstEntry.Text); return base.OnBackButtonPressed(); } @@ -71,6 +74,7 @@ namespace TheGameExtreme.view IOGamePreparation.SaveParameterGamePreparationGameModeValue(SelectMode.SelectedIndex); IOGamePreparation.SaveParameterGamePreparationNbStacks(SelectNbStack.SelectedIndex); IOGamePreparation.SaveParameterGamePreparationNbCards(SelectNbCard.SelectedIndex); + IOGamePreparation.SaveParameterGamePreparationName(FirstEntry.Text); await Navigation.PushAsync(new MainPage(playersNames, (int)SelectNbStack.SelectedItem, (int)SelectMode.SelectedIndex, (int)SelectNbCard.SelectedItem)); } @@ -123,6 +127,11 @@ namespace TheGameExtreme.view int nbCards = IOGamePreparation.LoadParameterGamePreparationNbCards(); SelectNbCard.SelectedIndex = nbCards; } + public void LoadParameterName() + { + string pseudo = IOGamePreparation.LoadNameFromGamePrepararion(); + FirstEntry.Text = pseudo; + } diff --git a/TheGameExtreme/view/HomePage.xaml.cs b/TheGameExtreme/view/HomePage.xaml.cs index 85195a9..e46f0ab 100644 --- a/TheGameExtreme/view/HomePage.xaml.cs +++ b/TheGameExtreme/view/HomePage.xaml.cs @@ -1,6 +1,7 @@ using System; using Xamarin.Forms; using TheGameExtreme.IO; +using TheGameExtreme.Resx; namespace TheGameExtreme.view {