From d30ec5ede9e357f2d3ec0f0b8e72abc88656ecdf Mon Sep 17 00:00:00 2001 From: Nicolas BLONDEAU Date: Tue, 23 May 2023 17:34:16 +0200 Subject: [PATCH] Debut Binding + modif Vues --- Sources/Console/Program.cs | 7 +- Sources/Modèle/Monstre.cs | 46 ++++++++- Sources/Vues/App.xaml.cs | 8 +- Sources/Vues/SearchMob.xaml | 170 ++++----------------------------- Sources/Vues/SearchMob.xaml.cs | 7 +- 5 files changed, 73 insertions(+), 165 deletions(-) diff --git a/Sources/Console/Program.cs b/Sources/Console/Program.cs index 633e206..f94eb67 100644 --- a/Sources/Console/Program.cs +++ b/Sources/Console/Program.cs @@ -424,5 +424,8 @@ Monstre monstre = new Monstre(1, "Dragon", "Dangereux", "Un redoutable dragon cr Conseil conseil = new Conseil(auteur, "Soyez prudent lors de votre rencontre avec le dragon.", monstre); // Affichage du conseil -conseil.affichConseil(); -menuAccueil(); \ No newline at end of file +/*conseil.affichConseil(); +menuAccueil();*/ + +Monstre uiui = new Monstre(1, "Poule", "passif", "Je suis un animal présent un peu partout, sauf dans le desert car il fait beaucoup trop chaud. Mais j'aime beaucoup la jungle !", new List { "Quand une poule est tué il y a 3.12% de chance que la poule laisse tomber un oeuf " }, new List { "Apparence1", "App2", "App3" }, new List { }); +Console.WriteLine(uiui.ImageLink); \ No newline at end of file diff --git a/Sources/Modèle/Monstre.cs b/Sources/Modèle/Monstre.cs index 8aefd91..1b272a1 100644 --- a/Sources/Modèle/Monstre.cs +++ b/Sources/Modèle/Monstre.cs @@ -8,13 +8,35 @@ namespace Model { [DataContract] - public class Monstre + public class Monstre : INotifyPropertyChanged { + public event PropertyChangedEventHandler? PropertyChanged; + + void OnPropertyChanged(string propertyName) + { + if (PropertyChanged != null) + { + PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); + } + } + + [DataMember(Order = 1)] public int Id { get; set; } // ID [DataMember(Order = 2)] - public string Name { get; set; } // Nom + public string Name + { + get => name; + set + { + if (name == value) + return; + name = value; + OnPropertyChanged("Name"); + } + } + private string name; // Nom [DataMember(Order = 3)] public string Dangerosite { get; private init; } // Dangerosité @@ -22,8 +44,19 @@ namespace Model //l'affichage de la liste des monstres une couleur selon ça, //genre rouge dangereux, violet hyper dangereux, et vert passif - [DataMember(Order = 4)] - public string Description { get; set; } // Description + [DataMember(Order = 4)] + public string Description + { + get => description; + set + { + if (description == value) + return; + description = value; + OnPropertyChanged("Description"); + } + } + private string description; // Description [DataMember(Order = 5)] public List CharacteristicsList // Liste des caractéristiques @@ -36,7 +69,10 @@ namespace Model { get; init; } + public List ListConseils { get; set; } + + public string ImageLink { get; init ; } public Monstre(int id, string name, string danger, string desc, List characList, List appearList, List conseilList) { Id = id; @@ -46,6 +82,8 @@ namespace Model CharacteristicsList = characList; AppearanceList = appearList; ListConseils = conseilList; + ImageLink = name.ToLower() + ".png"; + if (string.IsNullOrWhiteSpace(Name) || string.IsNullOrWhiteSpace(Description) || string.IsNullOrWhiteSpace(danger)) { throw new ArgumentException("Un monstre doit avoir un nom, une description et une dangerosité!"); diff --git a/Sources/Vues/App.xaml.cs b/Sources/Vues/App.xaml.cs index 61b8f98..0c04e75 100644 --- a/Sources/Vues/App.xaml.cs +++ b/Sources/Vues/App.xaml.cs @@ -1,11 +1,15 @@ -namespace Vues +using Model; +using Persistance; + +namespace Vues { public partial class App : Application { + MonsterManager mnstrMngr = new MonsterManager(new LoaderXml()); + public App() { InitializeComponent(); - MainPage = new AppShell(); } } diff --git a/Sources/Vues/SearchMob.xaml b/Sources/Vues/SearchMob.xaml index 424c8a0..03c8208 100644 --- a/Sources/Vues/SearchMob.xaml +++ b/Sources/Vues/SearchMob.xaml @@ -3,158 +3,22 @@ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit" xmlns:shape="Microsoft.Maui.Controls.Shapes" - x:Class="Vues.SearchMob" - BackgroundImageSource="backcollection.jpg" - > - + x:Class="Vues.SearchMob"> + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Sources/Vues/SearchMob.xaml.cs b/Sources/Vues/SearchMob.xaml.cs index 062b624..be2da8c 100644 --- a/Sources/Vues/SearchMob.xaml.cs +++ b/Sources/Vues/SearchMob.xaml.cs @@ -1,3 +1,5 @@ +using Model; + namespace Vues; public partial class SearchMob : ContentPage @@ -5,10 +7,7 @@ public partial class SearchMob : ContentPage public SearchMob() { InitializeComponent(); - } - - private void Label_SizeChanged(object sender, EventArgs e) - { + BindingContext = (App.Current as App).mnstrMngr; } } \ No newline at end of file