mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-12-15 14:49:42 +00:00
Titre
This commit is contained in:
parent
cd365b69b5
commit
a6a1c53e9b
4 changed files with 83 additions and 162 deletions
|
|
@ -1,5 +1,10 @@
|
|||
using AideDeJeuLib;
|
||||
using AideDeJeuLib.Monsters;
|
||||
using AideDeJeuLib.Spells;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Xamarin.Forms;
|
||||
|
|
@ -8,39 +13,87 @@ namespace AideDeJeu.ViewModels
|
|||
{
|
||||
public abstract class ItemsViewModel : BaseViewModel
|
||||
{
|
||||
public ItemsViewModel()
|
||||
public ItemsViewModel(ItemSourceType itemSourceType)
|
||||
{
|
||||
this.ItemSourceType = itemSourceType;
|
||||
LoadItemsCommand = new Command(() => ExecuteLoadItemsCommand());
|
||||
}
|
||||
public ICommand LoadItemsCommand { get; protected set; }
|
||||
public abstract void ExecuteLoadItemsCommand();
|
||||
//public abstract void ExecuteLoadItemsCommand();
|
||||
public abstract Task ExecuteGotoItemCommandAsync(Item item);
|
||||
protected ItemSourceType ItemSourceType;
|
||||
|
||||
//private string _SearchText = "";
|
||||
//public string SearchText
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return _SearchText;
|
||||
// }
|
||||
// set
|
||||
// {
|
||||
// SetProperty(ref _SearchText, value);
|
||||
// FilterItems();
|
||||
// }
|
||||
//}
|
||||
|
||||
//public void FilterItems()
|
||||
//{
|
||||
// Items.Clear();
|
||||
// foreach (var item in AllItems)
|
||||
// {
|
||||
// if (item.NamePHB.ToLower().Contains(SearchText.ToLower()))
|
||||
// {
|
||||
// Items.Add(item);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
private IEnumerable<Item> _AllItems = null;
|
||||
public IEnumerable<Item> AllItems
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_AllItems == null)
|
||||
{
|
||||
string resourceName = null;
|
||||
switch (ItemSourceType)
|
||||
{
|
||||
case ItemSourceType.MonsterVF:
|
||||
resourceName = "AideDeJeu.Data.monsters_vf.json";
|
||||
break;
|
||||
case ItemSourceType.MonsterVO:
|
||||
resourceName = "AideDeJeu.Data.monsters_vo.json";
|
||||
break;
|
||||
case ItemSourceType.MonsterHD:
|
||||
resourceName = "AideDeJeu.Data.monsters_hd.json";
|
||||
break;
|
||||
case ItemSourceType.SpellVF:
|
||||
resourceName = "AideDeJeu.Data.spells_vf.json";
|
||||
break;
|
||||
case ItemSourceType.SpellVO:
|
||||
resourceName = "AideDeJeu.Data.spells_vo.json";
|
||||
break;
|
||||
case ItemSourceType.SpellHD:
|
||||
resourceName = "AideDeJeu.Data.spells_hd.json";
|
||||
break;
|
||||
}
|
||||
if (ItemSourceType.HasFlag(ItemSourceType.Spell))
|
||||
{
|
||||
_AllItems = Tools.Helpers.GetResourceObject<IEnumerable<Spell>>(resourceName);
|
||||
}
|
||||
else if (ItemSourceType.HasFlag(ItemSourceType.Monster))
|
||||
{
|
||||
_AllItems = Tools.Helpers.GetResourceObject<IEnumerable<Monster>>(resourceName);
|
||||
}
|
||||
}
|
||||
return _AllItems;
|
||||
}
|
||||
}
|
||||
|
||||
public void ExecuteLoadItemsCommand()
|
||||
{
|
||||
if (IsBusy)
|
||||
return;
|
||||
|
||||
IsBusy = true;
|
||||
|
||||
try
|
||||
{
|
||||
Main.Items.Clear();
|
||||
|
||||
var filterViewModel = Main.GetFilterViewModel(ItemSourceType);
|
||||
var items = filterViewModel.FilterItems(AllItems);
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
Main.Items.Add(item);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsBusy = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,73 +15,13 @@ namespace AideDeJeu.ViewModels
|
|||
{
|
||||
public class MonstersViewModel : ItemsViewModel
|
||||
{
|
||||
ItemSourceType ItemSourceType;
|
||||
public MonstersViewModel(ItemSourceType itemSourceType)
|
||||
public MonstersViewModel(ItemSourceType itemSourceType) : base(itemSourceType)
|
||||
{
|
||||
this.ItemSourceType = itemSourceType;
|
||||
}
|
||||
|
||||
|
||||
private IEnumerable<Monster> _AllMonsters = null;
|
||||
private IEnumerable<Monster> AllMonsters
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_AllMonsters == null)
|
||||
{
|
||||
string resourceName = null;
|
||||
switch (ItemSourceType)
|
||||
{
|
||||
case ItemSourceType.MonsterVF:
|
||||
resourceName = "AideDeJeu.Data.monsters_vf.json";
|
||||
break;
|
||||
case ItemSourceType.MonsterVO:
|
||||
resourceName = "AideDeJeu.Data.monsters_vo.json";
|
||||
break;
|
||||
case ItemSourceType.MonsterHD:
|
||||
resourceName = "AideDeJeu.Data.monsters_hd.json";
|
||||
break;
|
||||
}
|
||||
_AllMonsters = Tools.Helpers.GetResourceObject<IEnumerable<Monster>>(resourceName);
|
||||
}
|
||||
return _AllMonsters;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ExecuteLoadItemsCommand()
|
||||
{
|
||||
if (IsBusy)
|
||||
return;
|
||||
|
||||
IsBusy = true;
|
||||
|
||||
try
|
||||
{
|
||||
Main.Items.Clear();
|
||||
|
||||
var filterViewModel = Main.GetFilterViewModel(ItemSourceType);
|
||||
var items = filterViewModel.FilterItems(AllMonsters);
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
Main.Items.Add(item);
|
||||
}
|
||||
//FilterItems();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsBusy = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override async Task ExecuteGotoItemCommandAsync(Item item)
|
||||
{
|
||||
await Main.Navigator.GotoMonsterDetailPageAsync(item as Monster);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -14,80 +14,8 @@ namespace AideDeJeu.ViewModels
|
|||
{
|
||||
public class SpellsViewModel : ItemsViewModel
|
||||
{
|
||||
ItemSourceType ItemSourceType;
|
||||
public SpellsViewModel(ItemSourceType itemSourceType)
|
||||
public SpellsViewModel(ItemSourceType itemSourceType) : base(itemSourceType)
|
||||
{
|
||||
this.ItemSourceType = itemSourceType;
|
||||
}
|
||||
private IEnumerable<Spell> _AllSpells = null;
|
||||
private IEnumerable<Spell> AllSpells
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_AllSpells == null)
|
||||
{
|
||||
string resourceName = null;
|
||||
switch(ItemSourceType)
|
||||
{
|
||||
case ItemSourceType.SpellVF:
|
||||
resourceName = "AideDeJeu.Data.spells_vf.json";
|
||||
break;
|
||||
case ItemSourceType.SpellVO:
|
||||
resourceName = "AideDeJeu.Data.spells_vo.json";
|
||||
break;
|
||||
case ItemSourceType.SpellHD:
|
||||
resourceName = "AideDeJeu.Data.spells_hd.json";
|
||||
break;
|
||||
}
|
||||
_AllSpells = Tools.Helpers.GetResourceObject<IEnumerable<Spell>>(resourceName);
|
||||
}
|
||||
return _AllSpells;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Spell> GetSpells(string classe, string niveauMin, string niveauMax, string ecole, string rituel, string source)
|
||||
{
|
||||
return AllSpells
|
||||
.Where(spell =>
|
||||
(int.Parse(spell.Level) >= int.Parse(niveauMin)) &&
|
||||
(int.Parse(spell.Level) <= int.Parse(niveauMax)) &&
|
||||
spell.Type.ToLower().Contains(ecole.ToLower()) &&
|
||||
spell.Source.Contains(source) &&
|
||||
spell.Source.Contains(classe) &&
|
||||
spell.Type.Contains(rituel)
|
||||
)
|
||||
.OrderBy(spell => spell.NamePHB)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
|
||||
public override void ExecuteLoadItemsCommand()
|
||||
{
|
||||
if (IsBusy)
|
||||
return;
|
||||
|
||||
IsBusy = true;
|
||||
|
||||
try
|
||||
{
|
||||
Main.Items.Clear();
|
||||
|
||||
var filterViewModel = Main.GetFilterViewModel(ItemSourceType);
|
||||
var items = filterViewModel.FilterItems(AllSpells);
|
||||
foreach (var item in items)
|
||||
{
|
||||
Main.Items.Add(item);
|
||||
}
|
||||
//FilterItems();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsBusy = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override async Task ExecuteGotoItemCommandAsync(Item item)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
x:Class="AideDeJeu.Views.MainPage"
|
||||
x:Name="This"
|
||||
IsPresented="False"
|
||||
Title="{Binding ItemSourceType,Converter={StaticResource ItemSourceTypeToTitleConverter}}">
|
||||
Title="">
|
||||
<MasterDetailPage.Resources>
|
||||
<ResourceDictionary>
|
||||
<tools:ItemSourceTypeToStringConverter
|
||||
|
|
@ -45,7 +45,7 @@
|
|||
<MasterDetailPage.Detail>
|
||||
<NavigationPage>
|
||||
<x:Arguments>
|
||||
<ContentPage Title="">
|
||||
<ContentPage Title="{Binding ItemSourceType,Converter={StaticResource ItemSourceTypeToTitleConverter}}">
|
||||
<ContentPage.ToolbarItems>
|
||||
<ToolbarItem Name="Spells" Text="Sorts" Order="Primary" Icon="spell_book.png" Command="{Binding SwitchToSpells}" />
|
||||
<ToolbarItem Name="Monsters" Text="Monstres" Order="Primary" Icon="dragon_head.png" Command="{Binding SwitchToMonsters}" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue