mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-11-02 16:27:04 +00:00
Recablage filtres
This commit is contained in:
parent
e04be9e458
commit
c4c7c87ee8
5 changed files with 59 additions and 41 deletions
|
|
@ -109,19 +109,19 @@ namespace AideDeJeu.Tools
|
||||||
|
|
||||||
public class ItemSourceTypeToStringConverter : ItemSourceTypeConverter<string> { }
|
public class ItemSourceTypeToStringConverter : ItemSourceTypeConverter<string> { }
|
||||||
|
|
||||||
public class ItemSourceTypeToFilterConverter : IValueConverter
|
//public class ItemSourceTypeToFilterConverter : IValueConverter
|
||||||
{
|
//{
|
||||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
// public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
{
|
// {
|
||||||
var vm = DependencyService.Get<ItemsViewModel>();
|
// var vm = DependencyService.Get<ItemsViewModel>();
|
||||||
var itemSourceType = vm.ItemSourceType;
|
// var itemSourceType = vm.ItemSourceType;
|
||||||
return vm.Main.GetFilterViewModel(itemSourceType).Filters;
|
// return vm.Main.GetFilterViewModel(itemSourceType).Filters;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
// public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
{
|
// {
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ namespace AideDeJeu.ViewModels
|
||||||
{
|
{
|
||||||
public abstract class FilterViewModel : BaseViewModel
|
public abstract class FilterViewModel : BaseViewModel
|
||||||
{
|
{
|
||||||
public ICommand LoadItemsCommand { get; protected set; }
|
public ICommand LoadItemsCommand { get; set; }
|
||||||
public abstract Task<IEnumerable<Item>> FilterItems(IEnumerable<Item> items, CancellationToken cancellationToken = default);
|
public abstract Task<IEnumerable<Item>> FilterItems(IEnumerable<Item> items, CancellationToken cancellationToken = default);
|
||||||
public abstract IEnumerable<Filter> Filters { get; }
|
public abstract IEnumerable<Filter> Filters { get; }
|
||||||
private string _SearchText = "";
|
private string _SearchText = "";
|
||||||
|
|
@ -23,10 +23,27 @@ namespace AideDeJeu.ViewModels
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
SetProperty(ref _SearchText, value);
|
SetProperty(ref _SearchText, value);
|
||||||
//Main.LoadItemsCommand.Execute(null);
|
LoadItemsCommand.Execute(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void RegisterFilters()
|
||||||
|
{
|
||||||
|
foreach (var filter in Filters)
|
||||||
|
{
|
||||||
|
filter.PropertyChanged += Filter_PropertyChanged;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void Filter_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.PropertyName == "Index")
|
||||||
|
{
|
||||||
|
LoadItemsCommand.Execute(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum FilterKeys
|
public enum FilterKeys
|
||||||
|
|
@ -64,7 +81,6 @@ namespace AideDeJeu.ViewModels
|
||||||
if (_Index != value)
|
if (_Index != value)
|
||||||
{
|
{
|
||||||
SetProperty(ref _Index, value);
|
SetProperty(ref _Index, value);
|
||||||
Main.LoadItemsCommand.Execute(null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -95,6 +111,7 @@ namespace AideDeJeu.ViewModels
|
||||||
_Filters = new List<Filter>()
|
_Filters = new List<Filter>()
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
RegisterFilters();
|
||||||
}
|
}
|
||||||
return _Filters;
|
return _Filters;
|
||||||
}
|
}
|
||||||
|
|
@ -140,12 +157,12 @@ namespace AideDeJeu.ViewModels
|
||||||
new Filter() { Key = FilterKeys.Ritual, Name = "Rituel", KeyValues = Rituels, _Index = 0 },
|
new Filter() { Key = FilterKeys.Ritual, Name = "Rituel", KeyValues = Rituels, _Index = 0 },
|
||||||
new Filter() { Key = FilterKeys.Source, Name = "Source", KeyValues = Sources, _Index = 0 },
|
new Filter() { Key = FilterKeys.Source, Name = "Source", KeyValues = Sources, _Index = 0 },
|
||||||
};
|
};
|
||||||
|
RegisterFilters();
|
||||||
}
|
}
|
||||||
return _Filters;
|
return _Filters;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override async Task<IEnumerable<Item>> FilterItems(IEnumerable<Item> items, CancellationToken token = default)
|
public override async Task<IEnumerable<Item>> FilterItems(IEnumerable<Item> items, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
return await Task.Run(() =>
|
return await Task.Run(() =>
|
||||||
|
|
@ -378,6 +395,7 @@ namespace AideDeJeu.ViewModels
|
||||||
//new Filter() { Key = FilterKeys.Legendary, Name = "Légendaire", KeyValues = Legendaries, _Index = 0 },
|
//new Filter() { Key = FilterKeys.Legendary, Name = "Légendaire", KeyValues = Legendaries, _Index = 0 },
|
||||||
new Filter() { Key = FilterKeys.Source, Name = "Source", KeyValues = Sources, _Index = 0 },
|
new Filter() { Key = FilterKeys.Source, Name = "Source", KeyValues = Sources, _Index = 0 },
|
||||||
};
|
};
|
||||||
|
RegisterFilters();
|
||||||
}
|
}
|
||||||
return _Filters;
|
return _Filters;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,15 @@ namespace AideDeJeu.ViewModels
|
||||||
public ItemsViewModel(ItemSourceType itemSourceType)
|
public ItemsViewModel(ItemSourceType itemSourceType)
|
||||||
{
|
{
|
||||||
this.ItemSourceType = itemSourceType;
|
this.ItemSourceType = itemSourceType;
|
||||||
Filter = Main.GetFilterViewModel(ItemSourceType);
|
|
||||||
LoadItemsCommand = new Command(async () => await ExecuteLoadItemsCommandAsync().ConfigureAwait(false));
|
LoadItemsCommand = new Command(async () => await ExecuteLoadItemsCommandAsync().ConfigureAwait(false));
|
||||||
|
Filter = Main.GetFilterViewModel(ItemSourceType);
|
||||||
|
Filter.LoadItemsCommand = LoadItemsCommand;
|
||||||
|
SearchCommand = new Command<string>((text) =>
|
||||||
|
{
|
||||||
|
Filter.SearchText = text;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
public Command<string> SearchCommand { get; private set; }
|
||||||
public ICommand LoadItemsCommand { get; protected set; }
|
public ICommand LoadItemsCommand { get; protected set; }
|
||||||
public async Task ExecuteGotoItemCommandAsync(Item item)
|
public async Task ExecuteGotoItemCommandAsync(Item item)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -101,34 +101,34 @@ namespace AideDeJeu.ViewModels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dictionary<ItemSourceType, Lazy<ItemsViewModel>> AllItemsViewModel = new Dictionary<ItemSourceType, Lazy<ItemsViewModel>>()
|
public Dictionary<ItemSourceType, Func<ItemsViewModel>> AllItemsViewModel = new Dictionary<ItemSourceType, Func<ItemsViewModel>>()
|
||||||
{
|
{
|
||||||
{ ItemSourceType.SpellVO, new Lazy<ItemsViewModel>(() => new ItemsViewModel(ItemSourceType.SpellVO)) },
|
{ ItemSourceType.SpellVO, () => new ItemsViewModel(ItemSourceType.SpellVO) },
|
||||||
{ ItemSourceType.SpellHD, new Lazy<ItemsViewModel>(() => new ItemsViewModel(ItemSourceType.SpellHD)) },
|
{ ItemSourceType.SpellHD, () => new ItemsViewModel(ItemSourceType.SpellHD) },
|
||||||
{ ItemSourceType.MonsterVO, new Lazy<ItemsViewModel>(() => new ItemsViewModel(ItemSourceType.MonsterVO)) },
|
{ ItemSourceType.MonsterVO, () => new ItemsViewModel(ItemSourceType.MonsterVO) },
|
||||||
{ ItemSourceType.MonsterHD, new Lazy<ItemsViewModel>(() => new ItemsViewModel(ItemSourceType.MonsterHD)) },
|
{ ItemSourceType.MonsterHD, () => new ItemsViewModel(ItemSourceType.MonsterHD) },
|
||||||
{ ItemSourceType.ConditionHD, new Lazy<ItemsViewModel>(() => new ItemsViewModel(ItemSourceType.ConditionHD)) },
|
{ ItemSourceType.ConditionHD, () => new ItemsViewModel(ItemSourceType.ConditionHD) },
|
||||||
{ ItemSourceType.ConditionVO, new Lazy<ItemsViewModel>(() => new ItemsViewModel(ItemSourceType.ConditionVO)) },
|
{ ItemSourceType.ConditionVO, () => new ItemsViewModel(ItemSourceType.ConditionVO) },
|
||||||
};
|
};
|
||||||
|
|
||||||
public ItemsViewModel GetItemsViewModel(ItemSourceType itemSourceType)
|
public ItemsViewModel GetItemsViewModel(ItemSourceType itemSourceType)
|
||||||
{
|
{
|
||||||
return AllItemsViewModel[itemSourceType].Value;
|
return AllItemsViewModel[itemSourceType].Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dictionary<ItemSourceType, Lazy<FilterViewModel>> AllFiltersViewModel = new Dictionary<ItemSourceType, Lazy<FilterViewModel>>()
|
public Dictionary<ItemSourceType, Func<FilterViewModel>> AllFiltersViewModel = new Dictionary<ItemSourceType, Func<FilterViewModel>>()
|
||||||
{
|
{
|
||||||
{ ItemSourceType.SpellVO, new Lazy<FilterViewModel>(() => new VOSpellFilterViewModel()) },
|
{ ItemSourceType.SpellVO, () => new VOSpellFilterViewModel() },
|
||||||
{ ItemSourceType.SpellHD, new Lazy<FilterViewModel>(() => new HDSpellFilterViewModel()) },
|
{ ItemSourceType.SpellHD, () => new HDSpellFilterViewModel() },
|
||||||
{ ItemSourceType.MonsterVO, new Lazy<FilterViewModel>(() => new VOMonsterFilterViewModel()) },
|
{ ItemSourceType.MonsterVO, () => new VOMonsterFilterViewModel() },
|
||||||
{ ItemSourceType.MonsterHD, new Lazy<FilterViewModel>(() => new HDMonsterFilterViewModel()) },
|
{ ItemSourceType.MonsterHD, () => new HDMonsterFilterViewModel() },
|
||||||
{ ItemSourceType.ConditionHD, new Lazy<FilterViewModel>(() => new SearchFilterViewModel()) },
|
{ ItemSourceType.ConditionHD, () => new SearchFilterViewModel() },
|
||||||
{ ItemSourceType.ConditionVO, new Lazy<FilterViewModel>(() => new SearchFilterViewModel()) },
|
{ ItemSourceType.ConditionVO, () => new SearchFilterViewModel() },
|
||||||
};
|
};
|
||||||
|
|
||||||
public FilterViewModel GetFilterViewModel(ItemSourceType itemSourceType)
|
public FilterViewModel GetFilterViewModel(ItemSourceType itemSourceType)
|
||||||
{
|
{
|
||||||
return AllFiltersViewModel[itemSourceType].Value;
|
return AllFiltersViewModel[itemSourceType].Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Yan : pas besoin d'ObservableCollection, on ne modifie jamais la liste item par item
|
// Yan : pas besoin d'ObservableCollection, on ne modifie jamais la liste item par item
|
||||||
|
|
@ -153,7 +153,6 @@ namespace AideDeJeu.ViewModels
|
||||||
public Command SwitchToSpellsVO { get; private set; }
|
public Command SwitchToSpellsVO { get; private set; }
|
||||||
public Command SwitchToMonstersVO { get; private set; }
|
public Command SwitchToMonstersVO { get; private set; }
|
||||||
public Command AboutCommand { get; private set; }
|
public Command AboutCommand { get; private set; }
|
||||||
public Command<string> SearchCommand { get; private set; }
|
|
||||||
|
|
||||||
public Navigator Navigator { get; set; }
|
public Navigator Navigator { get; set; }
|
||||||
|
|
||||||
|
|
@ -173,11 +172,6 @@ namespace AideDeJeu.ViewModels
|
||||||
//SwitchToSpellsVO = new Command(() => ItemSourceType = ItemSourceType.SpellVO);
|
//SwitchToSpellsVO = new Command(() => ItemSourceType = ItemSourceType.SpellVO);
|
||||||
//SwitchToMonstersVO = new Command(() => ItemSourceType = ItemSourceType.MonsterVO);
|
//SwitchToMonstersVO = new Command(() => ItemSourceType = ItemSourceType.MonsterVO);
|
||||||
AboutCommand = new Command(async () => await Main.Navigator.GotoAboutPageAsync());
|
AboutCommand = new Command(async () => await Main.Navigator.GotoAboutPageAsync());
|
||||||
SearchCommand = new Command<string>(async (text) =>
|
|
||||||
{
|
|
||||||
//GetFilterViewModel(ItemSourceType).SearchText = text;
|
|
||||||
//await GetItemsViewModel(ItemSourceType).ExecuteLoadItemsCommandAsync();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemSourceType MDFileToItemSourceType(string file)
|
ItemSourceType MDFileToItemSourceType(string file)
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
<MasterDetailPage.Resources>
|
<MasterDetailPage.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
<tools:ItemSourceTypeToStringConverter x:Key="ItemSourceTypeToTitleConverter" SpellVO="Spells" SpellHD="Sorts (H&D)" MonsterVO="Monsters" MonsterHD="Créatures (H&D)" />
|
<tools:ItemSourceTypeToStringConverter x:Key="ItemSourceTypeToTitleConverter" SpellVO="Spells" SpellHD="Sorts (H&D)" MonsterVO="Monsters" MonsterHD="Créatures (H&D)" />
|
||||||
<tools:ItemSourceTypeToFilterConverter x:Key="ItemSourceTypeToFilterConverter" />
|
<!--<tools:ItemSourceTypeToFilterConverter x:Key="ItemSourceTypeToFilterConverter" />-->
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
</MasterDetailPage.Resources>
|
</MasterDetailPage.Resources>
|
||||||
<MasterDetailPage.Master>
|
<MasterDetailPage.Master>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue