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 11 months 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"
x:Class="Trek_12.Views.PageProfils"
xmlns:views="clr-namespace:Trek_12.Views.Components"
xmlns:game="clr-namespace:Models.Game;assembly=Models"
Title="pageProfils">
<ContentPage.Resources>
<ResourceDictionary>
<game:Base64Converter x:Key="Base64Converter"/>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
@ -14,7 +21,7 @@
<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"
VerticalOptions="Center">
<CollectionView.ItemTemplate>

@ -1,46 +1,68 @@
namespace Trek_12.Views;
using Models.Game;
using Stub;
using System.Diagnostics;
using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Maui.Core;
using Models.Interfaces;
namespace Trek_12.Views;
public partial class PageProfils : ContentPage
{
public Stub MyStub { get; set; } = new Stub();
public Game ProfileManager => (App.Current as App).Manager;
public PageProfils()
{
InitializeComponent();
BindingContext = MyStub;
BindingContext = ProfileManager;
}
async void Button_ClickedAdd(System.Object sender, System.EventArgs e)
{
string result = await DisplayPromptAsync("Info", $"Choose a name : ", "Ok");
Debug.WriteLine("Answer: " + result);
if (result != null)
{
Debug.WriteLine("bam, added");
MyStub.Add(result, "profile.jpg");
}
}
string pseudo = await DisplayPromptAsync("Info", $"Choose a name : ", "Ok");
if (pseudo == null) return;
var profilePicture = await MediaPicker.PickPhotoAsync();
if (profilePicture == null) return;
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)
{
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);
if (result != null)
if (ProfileManager.RemovePlayer(result))
{
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)
{
throw new NotImplementedException();
/*
string result = await DisplayPromptAsync("Info", $"Choose a name to modify : ", "Ok");
Debug.WriteLine("Answer: " + result);
if (result != null)
@ -60,7 +82,7 @@ public partial class PageProfils : ContentPage
}
}
else Debug.WriteLine("Did not found");
*/
}
}

Loading…
Cancel
Save