pageProfils #94

Merged
remi.neveu merged 5 commits from pageProfils into dev 11 months ago

@ -1,15 +1,37 @@
namespace Models.Game using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Models.Game
{ {
/// <summary> /// <summary>
/// Represents a player in the game. /// Represents a player in the game.
/// </summary> /// </summary>
public class Player public class Player : INotifyPropertyChanged
{ {
public event PropertyChangedEventHandler? PropertyChanged;
void OnPropertyChanged([CallerMemberName] string propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
/// <summary> /// <summary>
/// It is he pseudo of the player. /// It is he pseudo of the player.
/// </summary> /// </summary>
public string Pseudo { get; private set; } private string _pseudo;
public string Pseudo
{
get => _pseudo;
set
{
if (_pseudo == value)
return;
_pseudo = value;
OnPropertyChanged();
}
}
private int hairCount;
/// <summary> /// <summary>
/// It is the profile picture of the player. /// It is the profile picture of the player.
@ -46,6 +68,7 @@
ProfilePicture = profilePicture; ProfilePicture = profilePicture;
} }
/// <summary> /// <summary>
/// Chooses the operation for the player. /// Chooses the operation for the player.
/// </summary> /// </summary>

@ -0,0 +1,51 @@
using System.Collections.ObjectModel;
using System.Data;
using System.Numerics;
using Models.Game;
namespace Stub
{
public class Stub
{
public ReadOnlyObservableCollection<Player> ListPlayer { get; private set; }
private readonly ObservableCollection<Player> listplayer = new ObservableCollection<Player>();
public Stub()
{
LoadPlayer();
ListPlayer = new ReadOnlyObservableCollection<Player>(listplayer);
}
public void LoadPlayer()
{
listplayer.Add(new Player());
listplayer.Add(new Player("Lucas", "profile.jpg"));
listplayer.Add(new Player("relavergne", "profile.jpg"));
listplayer.Add(new Player("reneveu", "profile.jpg"));
}
public void Add(string pseudo, string profilePicture)
{
listplayer.Add(new Player(pseudo, profilePicture));
}
public void Pop(string pseudo, string profilePicture)
{
listplayer.Remove(new Player(pseudo, profilePicture));
}
public bool Modify(string pseudo, string newpseudo)
{
foreach(var index in listplayer)
{
if (index.Pseudo == pseudo)
{
index.Pseudo = newpseudo;
return true;
}
}
return false;
}
}
}

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Models\Models.csproj" />
</ItemGroup>
</Project>

@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataContractPersistence", "DataContractPersistence\DataContractPersistence.csproj", "{FC6A23C3-A1E3-4BF4-85B0-404D8574E190}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataContractPersistence", "DataContractPersistence\DataContractPersistence.csproj", "{FC6A23C3-A1E3-4BF4-85B0-404D8574E190}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Stub", "Stub\Stub.csproj", "{49360F7D-C59D-4B4F-AF5A-73FF61D9EF9B}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -41,6 +43,10 @@ Global
{FC6A23C3-A1E3-4BF4-85B0-404D8574E190}.Debug|Any CPU.Build.0 = Debug|Any CPU {FC6A23C3-A1E3-4BF4-85B0-404D8574E190}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC6A23C3-A1E3-4BF4-85B0-404D8574E190}.Release|Any CPU.ActiveCfg = Release|Any CPU {FC6A23C3-A1E3-4BF4-85B0-404D8574E190}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC6A23C3-A1E3-4BF4-85B0-404D8574E190}.Release|Any CPU.Build.0 = Release|Any CPU {FC6A23C3-A1E3-4BF4-85B0-404D8574E190}.Release|Any CPU.Build.0 = Release|Any CPU
{49360F7D-C59D-4B4F-AF5A-73FF61D9EF9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{49360F7D-C59D-4B4F-AF5A-73FF61D9EF9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{49360F7D-C59D-4B4F-AF5A-73FF61D9EF9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{49360F7D-C59D-4B4F-AF5A-73FF61D9EF9B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

@ -63,6 +63,11 @@
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Models\Models.csproj" />
<ProjectReference Include="..\Stub\Stub.csproj" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Update="Views\PageLeaderBoard.xaml.cs"> <Compile Update="Views\PageLeaderBoard.xaml.cs">
<DependentUpon>PageLeaderBoard.xaml</DependentUpon> <DependentUpon>PageLeaderBoard.xaml</DependentUpon>
@ -82,9 +87,6 @@
<MauiXaml Update="Views\PageLeaderBoard.xaml"> <MauiXaml Update="Views\PageLeaderBoard.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
<MauiXaml Update="Views\PageConnexion.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Trek_12.Views.Components.viewsProfils"> x:Class="Trek_12.Views.Components.viewsProfils"
x:Name="this">
<VerticalStackLayout> <VerticalStackLayout>
<Grid ColumnDefinitions="*,*,*,*" > <Grid ColumnDefinitions="*,*,*,*" >
<Frame Margin="10" <Frame Margin="10"
@ -13,11 +14,11 @@
IsClippedToBounds="True" IsClippedToBounds="True"
HasShadow="True" HasShadow="True"
HorizontalOptions="CenterAndExpand"> HorizontalOptions="CenterAndExpand">
<Image Source="profile.jpg" <Image Source="{Binding ProfilePicture, Source={x:Reference this}}"
Aspect="AspectFill" Aspect="AspectFill"
Margin="-20"/> Margin="-20"/>
</Frame> </Frame>
<Label Text="Profile n°*" Grid.Column="2" TextColor="Black" FontSize="Large" HorizontalTextAlignment="Center" Margin="100"/> <Label Text="{Binding Pseudo, Source={x:Reference this}}" Grid.Column="2" TextColor="Black" FontSize="Large" HorizontalTextAlignment="Center" Margin="100"/>
</Grid> </Grid>
</VerticalStackLayout> </VerticalStackLayout>
</ContentView> </ContentView>

@ -6,4 +6,23 @@ public partial class viewsProfils : ContentView
{ {
InitializeComponent(); InitializeComponent();
} }
public static readonly BindableProperty PseudoProperty =
BindableProperty.Create("Pseudo", typeof(string), typeof(ContentLeaderBoard), "Profile n°*");
public string Pseudo
{
get => (string)GetValue(PseudoProperty);
set => SetValue(PseudoProperty, value);
}
public static readonly BindableProperty ProfilePictureProperty =
BindableProperty.Create("ProfilePicture", typeof(string), typeof(ContentLeaderBoard), "profile.jpg");
public string ProfilePicture
{
get => (string)GetValue(ProfilePictureProperty);
set => SetValue(ProfilePictureProperty, value);
}
} }

@ -14,22 +14,22 @@
<Label Text="Profils" TextColor="black" HorizontalTextAlignment="Center" FontSize="Header" Margin="30"/> <Label Text="Profils" TextColor="black" HorizontalTextAlignment="Center" FontSize="Header" Margin="30"/>
<ScrollView Grid.Row="1"> <CollectionView Grid.Row="1" ItemsSource="{Binding ListPlayer}"
<Grid RowDefinitions="*,*,*,*,*,*"> ItemsLayout="VerticalList"
<views:viewsProfils /> VerticalOptions="Center">
<views:viewsProfils Grid.Row="1" /> <CollectionView.ItemTemplate>
<views:viewsProfils Grid.Row="2"/> <DataTemplate>
<views:viewsProfils Grid.Row="3"/> <views:viewsProfils
<views:viewsProfils Grid.Row="4"/> Pseudo="{Binding Pseudo}"
<views:viewsProfils Grid.Row="5"/> ProfilePicture="{Binding ProfilePicture}"/>
</DataTemplate>
</Grid> </CollectionView.ItemTemplate>
</ScrollView> </CollectionView>
<HorizontalStackLayout Grid.Row="2" HorizontalOptions="Center" Spacing="50"> <HorizontalStackLayout Grid.Row="2" HorizontalOptions="Center" Spacing="50">
<Button Text="Modifier" WidthRequest="300" HeightRequest="60" CornerRadius="4"/> <Button Text="Modifier" WidthRequest="300" HeightRequest="60" CornerRadius="4" Clicked="Button_ClickedModify"/>
<Button Text="Créer" WidthRequest="300" HeightRequest="60" CornerRadius="4"/> <Button Text="Créer" WidthRequest="300" HeightRequest="60" CornerRadius="4" Clicked="Button_ClickedAdd"/>
<Button Text="Supprimer" WidthRequest="300" HeightRequest="60" CornerRadius="4"/> <Button Text="Supprimer" WidthRequest="300" HeightRequest="60" CornerRadius="4" Clicked="Button_ClickedPop"/>
</HorizontalStackLayout> </HorizontalStackLayout>
</Grid> </Grid>

@ -1,9 +1,66 @@
namespace Trek_12.Views; namespace Trek_12.Views;
using Stub;
using System.Diagnostics;
using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Maui.Core;
public partial class PageProfils : ContentPage public partial class PageProfils : ContentPage
{ {
public PageProfils() public Stub MyStub { get; set; } = new Stub();
public PageProfils()
{ {
InitializeComponent(); InitializeComponent();
BindingContext = MyStub;
} }
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");
}
}
async void Button_ClickedPop(System.Object sender, System.EventArgs e)
{
string result = await DisplayPromptAsync("Info", $"Choose a name to delete : ", "Ok");
Debug.WriteLine("Answer: " + result);
if (result != null)
{
Debug.WriteLine("bam, deleted");
MyStub.Pop(result, "profile.jpg");
}
else Debug.WriteLine("Pseudo not found");
}
async void Button_ClickedModify(System.Object sender, System.EventArgs e)
{
string result = await DisplayPromptAsync("Info", $"Choose a name to modify : ", "Ok");
Debug.WriteLine("Answer: " + result);
if (result != null)
{
string tomodify = await DisplayPromptAsync("Info", $"How will you rename it ?: ", "Ok");
Debug.WriteLine("Answer: " + tomodify);
if (tomodify != null)
{
Debug.WriteLine("bam, modified");
bool ismodified = MyStub.Modify(result, tomodify);
if (ismodified)
{
Debug.WriteLine("Modified");
}
else Debug.WriteLine("Player not found");
}
}
else Debug.WriteLine("Did not found");
}
} }

Loading…
Cancel
Save