mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-10-30 23:16:09 +00:00 
			
		
		
		
	Sub backgrounds
This commit is contained in:
		
							parent
							
								
									82aaec1b90
								
							
						
					
					
						commit
						6cfa3ed4c1
					
				
					 4 changed files with 83 additions and 12 deletions
				
			
		|  | @ -4,12 +4,12 @@ using System.Threading.Tasks; | |||
| 
 | ||||
| namespace AideDeJeu.Tools | ||||
| { | ||||
|     public sealed class NotifyTaskCompletion<TResult> : INotifyPropertyChanged | ||||
|     public class NotifyTaskCompletion<TResult> : INotifyPropertyChanged | ||||
|     { | ||||
|         public NotifyTaskCompletion(Task<TResult> task) | ||||
|         { | ||||
|             Task = task; | ||||
|             if (!task.IsCompleted) | ||||
|             if (task != null && !task.IsCompleted) | ||||
|             { | ||||
|                 var _ = WatchTaskAsync(task); | ||||
|             } | ||||
|  | @ -51,22 +51,22 @@ namespace AideDeJeu.Tools | |||
|         { | ||||
|             get | ||||
|             { | ||||
|                 return (Task.Status == TaskStatus.RanToCompletion) ? Task.Result : default(TResult); | ||||
|                 return (Task?.Status == TaskStatus.RanToCompletion) ? Task.Result : default(TResult); | ||||
|             } | ||||
|         } | ||||
|         public TaskStatus Status { get { return Task.Status; } } | ||||
|         public bool IsCompleted { get { return Task.IsCompleted; } } | ||||
|         public bool IsNotCompleted { get { return !Task.IsCompleted; } } | ||||
|         public TaskStatus Status { get { return Task?.Status ?? TaskStatus.Running; } } | ||||
|         public bool IsCompleted { get { return Task?.IsCompleted ?? false; } } | ||||
|         public bool IsNotCompleted { get { return Task?.IsCompleted == true ? false : true; } } | ||||
|         public bool IsSuccessfullyCompleted | ||||
|         { | ||||
|             get | ||||
|             { | ||||
|                 return Task.Status == TaskStatus.RanToCompletion; | ||||
|                 return Task?.Status == TaskStatus.RanToCompletion; | ||||
|             } | ||||
|         } | ||||
|         public bool IsCanceled { get { return Task.IsCanceled; } } | ||||
|         public bool IsFaulted { get { return Task.IsFaulted; } } | ||||
|         public AggregateException Exception { get { return Task.Exception; } } | ||||
|         public bool IsCanceled { get { return Task?.IsCanceled ?? false; } } | ||||
|         public bool IsFaulted { get { return Task?.IsFaulted ?? false; } } | ||||
|         public AggregateException Exception { get { return Task?.Exception; } } | ||||
|         public Exception InnerException | ||||
|         { | ||||
|             get | ||||
|  |  | |||
|  | @ -16,6 +16,7 @@ namespace AideDeJeu.ViewModels | |||
|             Races = new NotifyTaskCompletion<List<RaceItem>>(Task.Run(() => LoadRacesAsync())); | ||||
|             Classes = new NotifyTaskCompletion<List<ClassItem>>(Task.Run(() => LoadClassesAsync())); | ||||
|             Backgrounds = new NotifyTaskCompletion<List<BackgroundItem>>(Task.Run(() => LoadBackgroundsAsync())); | ||||
|             SubBackgrounds = new NotifyTaskCompletion<List<SubBackgroundItem>>(null); | ||||
|         } | ||||
| 
 | ||||
|         public NotifyTaskCompletion<List<RaceItem>> Races { get; private set; } | ||||
|  | @ -64,8 +65,45 @@ namespace AideDeJeu.ViewModels | |||
|             { | ||||
|                 SetProperty(ref _BackgroundSelectedIndex, value); | ||||
|                 SelectedPlayerCharacter.Background = Backgrounds.Result[_BackgroundSelectedIndex]; | ||||
|                 SubBackgrounds = new NotifyTaskCompletion<List<SubBackgroundItem>>(Task.Run(() => LoadSubBackgroundsAsync(SelectedPlayerCharacter.Background))); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private NotifyTaskCompletion<List<SubBackgroundItem>> _SubBackgrounds = null; | ||||
|         public NotifyTaskCompletion<List<SubBackgroundItem>> SubBackgrounds | ||||
|         { | ||||
|             get | ||||
|             { | ||||
|                 return _SubBackgrounds; | ||||
|             } | ||||
|             private set | ||||
|             { | ||||
|                 SetProperty(ref _SubBackgrounds, value); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private int _SubBackgroundSelectedIndex = 0; | ||||
|         public int SubBackgroundSelectedIndex | ||||
|         { | ||||
|             get | ||||
|             { | ||||
|                 return _SubBackgroundSelectedIndex; | ||||
|             } | ||||
|             set | ||||
|             { | ||||
|                 SetProperty(ref _SubBackgroundSelectedIndex, value); | ||||
|                 if(_SubBackgroundSelectedIndex == 0) | ||||
|                 { | ||||
|                     SelectedPlayerCharacter.SubBackground = null; | ||||
|                     SubBackgroundSelectedIndex = -1; | ||||
|                 } | ||||
|                 else if(_SubBackgroundSelectedIndex > 0) | ||||
|                 { | ||||
|                     SelectedPlayerCharacter.SubBackground = SubBackgrounds.Result[_SubBackgroundSelectedIndex]; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private PlayerCharacterViewModel _SelectedPlayerCharacter = new PlayerCharacterViewModel(); | ||||
|         public PlayerCharacterViewModel SelectedPlayerCharacter | ||||
|         { | ||||
|  | @ -109,5 +147,22 @@ namespace AideDeJeu.ViewModels | |||
|                 return await context.Backgrounds.Where(b => b.GetType() == typeof(BackgroundItem)).OrderBy(b => Tools.Helpers.RemoveDiacritics(b.Name)).ToListAsync().ConfigureAwait(false); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public async Task<List<SubBackgroundItem>> LoadSubBackgroundsAsync(BackgroundItem background) | ||||
|         { | ||||
|             if (background != null) | ||||
|             { | ||||
|                 using (var context = await StoreViewModel.GetLibraryContextAsync()) | ||||
|                 { | ||||
|                     var list = await context.SubBackgrounds.Where(item => item.ParentLink == background.Id).OrderBy(b => Tools.Helpers.RemoveDiacritics(b.Name)).ToListAsync().ConfigureAwait(false); | ||||
|                     list.Insert(0, null); | ||||
|                     return list; | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new List<SubBackgroundItem>(); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -43,5 +43,17 @@ namespace AideDeJeu.ViewModels | |||
|                 SetProperty(ref _Background, value); | ||||
|             } | ||||
|         } | ||||
|         private SubBackgroundItem _SubBackground = null; | ||||
|         public SubBackgroundItem SubBackground | ||||
|         { | ||||
|             get | ||||
|             { | ||||
|                 return _SubBackground; | ||||
|             } | ||||
|             set | ||||
|             { | ||||
|                 SetProperty(ref _SubBackground, value); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -53,8 +53,12 @@ | |||
|     <ContentPage Title="Historique"> | ||||
|         <StackLayout> | ||||
|             <Picker Title="Historique" HorizontalOptions="FillAndExpand" IsEnabled="{Binding Backgrounds.IsSuccessfullyCompleted}" ItemsSource="{Binding Backgrounds.Result}" ItemDisplayBinding="{Binding Name}" SelectedIndex="{Binding BackgroundSelectedIndex, Mode=TwoWay}" /> | ||||
|             <Picker Title="Variante" HorizontalOptions="FillAndExpand" IsEnabled="{Binding SubBackgrounds.IsSuccessfullyCompleted}" ItemsSource="{Binding SubBackgrounds.Result}" ItemDisplayBinding="{Binding Name}" SelectedIndex="{Binding SubBackgroundSelectedIndex, Mode=TwoWay}" /> | ||||
|             <ScrollView Orientation="Vertical"> | ||||
|                 <mdview:MarkdownView Markdown="{Binding SelectedPlayerCharacter.Background.Markdown}" /> | ||||
|                 <StackLayout> | ||||
|                     <mdview:MarkdownView Markdown="{Binding SelectedPlayerCharacter.Background.Markdown}" /> | ||||
|                     <mdview:MarkdownView Markdown="{Binding SelectedPlayerCharacter.SubBackground.Markdown}" /> | ||||
|                 </StackLayout> | ||||
|             </ScrollView> | ||||
|         </StackLayout> | ||||
|     </ContentPage> | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yan Maniez
						Yan Maniez