Implémentation du Manager Game de l'application dans la page, et refonte de l'ajout/suppression de Profils avec l'actualisation et vérification automatique. BindingContext -> Manager

pull/97/head
Rémi LAVERGNE 1 year ago
parent 39fb86e881
commit 1bffc98af6
No known key found for this signature in database
GPG Key ID: 7BCBAE9031E39160

@ -3,8 +3,15 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Trek_12.Views.PageProfils" x:Class="Trek_12.Views.PageProfils"
xmlns:views="clr-namespace:Trek_12.Views.Components" xmlns:views="clr-namespace:Trek_12.Views.Components"
xmlns:game="clr-namespace:Models.Game;assembly=Models"
Title="pageProfils"> Title="pageProfils">
<ContentPage.Resources>
<ResourceDictionary>
<game:Base64Converter x:Key="Base64Converter"/>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content> <ContentPage.Content>
@ -14,7 +21,7 @@
<Label Text="Profils" TextColor="black" HorizontalTextAlignment="Center" FontSize="Header" Margin="30"/> <Label Text="Profils" TextColor="black" HorizontalTextAlignment="Center" FontSize="Header" Margin="30"/>
<CollectionView Grid.Row="1" ItemsSource="{Binding ListPlayer}" <CollectionView Grid.Row="1" ItemsSource="{Binding Players}"
ItemsLayout="VerticalList" ItemsLayout="VerticalList"
VerticalOptions="Center"> VerticalOptions="Center">
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>

@ -1,46 +1,68 @@
namespace Trek_12.Views; using Models.Game;
using Stub; using Stub;
using System.Diagnostics; using System.Diagnostics;
using CommunityToolkit.Maui.Alerts; using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Maui.Core; using CommunityToolkit.Maui.Core;
using Models.Interfaces;
namespace Trek_12.Views;
public partial class PageProfils : ContentPage public partial class PageProfils : ContentPage
{ {
public Stub MyStub { get; set; } = new Stub(); public Game ProfileManager => (App.Current as App).Manager;
public PageProfils() public PageProfils()
{ {
InitializeComponent(); InitializeComponent();
BindingContext = MyStub; BindingContext = ProfileManager;
} }
async void Button_ClickedAdd(System.Object sender, System.EventArgs e) async void Button_ClickedAdd(System.Object sender, System.EventArgs e)
{ {
string result = await DisplayPromptAsync("Info", $"Choose a name : ", "Ok"); string pseudo = await DisplayPromptAsync("Info", $"Choose a name : ", "Ok");
Debug.WriteLine("Answer: " + result); if (pseudo == null) return;
if (result != null)
{ var profilePicture = await MediaPicker.PickPhotoAsync();
Debug.WriteLine("bam, added"); if (profilePicture == null) return;
MyStub.Add(result, "profile.jpg");
} IImageConverter converter = new Base64Converter();
}
string convertedProfilePicture = converter.ConvertImage(profilePicture.FullPath);
Player player = new Player(pseudo, convertedProfilePicture);
ProfileManager.AddPlayer(player);
Debug.WriteLine("Player " + pseudo + " added with profile picture " + convertedProfilePicture);
Debug.WriteLine("It's the number" + ProfileManager.Players.Count + " player");
ProfileManager.OnPropertyChanged(nameof(ProfileManager.Players));
ProfileManager.SaveData();
}
async void Button_ClickedPop(System.Object sender, System.EventArgs e) async void Button_ClickedPop(System.Object sender, System.EventArgs e)
{ {
string result = await DisplayPromptAsync("Info", $"Choose a name to delete : ", "Ok"); if (ProfileManager.Players.Count == 0)
{
await DisplayAlert("Info", "There is no player actually\nPlease add one", "Ok");
return;
}
string result = await DisplayPromptAsync("Info", $"Choose a pseudo to delete : ", "Ok");
if (result == null) return;
Debug.WriteLine("Answer: " + result); Debug.WriteLine("Answer: " + result);
if (result != null) if (ProfileManager.RemovePlayer(result))
{ {
Debug.WriteLine("bam, deleted"); Debug.WriteLine("bam, deleted");
MyStub.Pop(result, "profile.jpg"); OnPropertyChanged(nameof(ProfileManager));
} }
else Debug.WriteLine("Pseudo not found"); else Debug.WriteLine("Player not found");
} }
async void Button_ClickedModify(System.Object sender, System.EventArgs e) async void Button_ClickedModify(System.Object sender, System.EventArgs e)
{ {
throw new NotImplementedException();
/*
string result = await DisplayPromptAsync("Info", $"Choose a name to modify : ", "Ok"); string result = await DisplayPromptAsync("Info", $"Choose a name to modify : ", "Ok");
Debug.WriteLine("Answer: " + result); Debug.WriteLine("Answer: " + result);
if (result != null) if (result != null)
@ -60,7 +82,7 @@ public partial class PageProfils : ContentPage
} }
} }
else Debug.WriteLine("Did not found"); else Debug.WriteLine("Did not found");
*/
} }
} }

Loading…
Cancel
Save