mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-11-02 16:27:04 +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
|
namespace AideDeJeu.Tools
|
||||||
{
|
{
|
||||||
public sealed class NotifyTaskCompletion<TResult> : INotifyPropertyChanged
|
public class NotifyTaskCompletion<TResult> : INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
public NotifyTaskCompletion(Task<TResult> task)
|
public NotifyTaskCompletion(Task<TResult> task)
|
||||||
{
|
{
|
||||||
Task = task;
|
Task = task;
|
||||||
if (!task.IsCompleted)
|
if (task != null && !task.IsCompleted)
|
||||||
{
|
{
|
||||||
var _ = WatchTaskAsync(task);
|
var _ = WatchTaskAsync(task);
|
||||||
}
|
}
|
||||||
|
|
@ -51,22 +51,22 @@ namespace AideDeJeu.Tools
|
||||||
{
|
{
|
||||||
get
|
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 TaskStatus Status { get { return Task?.Status ?? TaskStatus.Running; } }
|
||||||
public bool IsCompleted { get { return Task.IsCompleted; } }
|
public bool IsCompleted { get { return Task?.IsCompleted ?? false; } }
|
||||||
public bool IsNotCompleted { get { return !Task.IsCompleted; } }
|
public bool IsNotCompleted { get { return Task?.IsCompleted == true ? false : true; } }
|
||||||
public bool IsSuccessfullyCompleted
|
public bool IsSuccessfullyCompleted
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return Task.Status == TaskStatus.RanToCompletion;
|
return Task?.Status == TaskStatus.RanToCompletion;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public bool IsCanceled { get { return Task.IsCanceled; } }
|
public bool IsCanceled { get { return Task?.IsCanceled ?? false; } }
|
||||||
public bool IsFaulted { get { return Task.IsFaulted; } }
|
public bool IsFaulted { get { return Task?.IsFaulted ?? false; } }
|
||||||
public AggregateException Exception { get { return Task.Exception; } }
|
public AggregateException Exception { get { return Task?.Exception; } }
|
||||||
public Exception InnerException
|
public Exception InnerException
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ namespace AideDeJeu.ViewModels
|
||||||
Races = new NotifyTaskCompletion<List<RaceItem>>(Task.Run(() => LoadRacesAsync()));
|
Races = new NotifyTaskCompletion<List<RaceItem>>(Task.Run(() => LoadRacesAsync()));
|
||||||
Classes = new NotifyTaskCompletion<List<ClassItem>>(Task.Run(() => LoadClassesAsync()));
|
Classes = new NotifyTaskCompletion<List<ClassItem>>(Task.Run(() => LoadClassesAsync()));
|
||||||
Backgrounds = new NotifyTaskCompletion<List<BackgroundItem>>(Task.Run(() => LoadBackgroundsAsync()));
|
Backgrounds = new NotifyTaskCompletion<List<BackgroundItem>>(Task.Run(() => LoadBackgroundsAsync()));
|
||||||
|
SubBackgrounds = new NotifyTaskCompletion<List<SubBackgroundItem>>(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NotifyTaskCompletion<List<RaceItem>> Races { get; private set; }
|
public NotifyTaskCompletion<List<RaceItem>> Races { get; private set; }
|
||||||
|
|
@ -64,8 +65,45 @@ namespace AideDeJeu.ViewModels
|
||||||
{
|
{
|
||||||
SetProperty(ref _BackgroundSelectedIndex, value);
|
SetProperty(ref _BackgroundSelectedIndex, value);
|
||||||
SelectedPlayerCharacter.Background = Backgrounds.Result[_BackgroundSelectedIndex];
|
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();
|
private PlayerCharacterViewModel _SelectedPlayerCharacter = new PlayerCharacterViewModel();
|
||||||
public PlayerCharacterViewModel SelectedPlayerCharacter
|
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);
|
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);
|
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">
|
<ContentPage Title="Historique">
|
||||||
<StackLayout>
|
<StackLayout>
|
||||||
<Picker Title="Historique" HorizontalOptions="FillAndExpand" IsEnabled="{Binding Backgrounds.IsSuccessfullyCompleted}" ItemsSource="{Binding Backgrounds.Result}" ItemDisplayBinding="{Binding Name}" SelectedIndex="{Binding BackgroundSelectedIndex, Mode=TwoWay}" />
|
<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">
|
<ScrollView Orientation="Vertical">
|
||||||
|
<StackLayout>
|
||||||
<mdview:MarkdownView Markdown="{Binding SelectedPlayerCharacter.Background.Markdown}" />
|
<mdview:MarkdownView Markdown="{Binding SelectedPlayerCharacter.Background.Markdown}" />
|
||||||
|
<mdview:MarkdownView Markdown="{Binding SelectedPlayerCharacter.SubBackground.Markdown}" />
|
||||||
|
</StackLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
</ContentPage>
|
</ContentPage>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue