1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-31 07:26:09 +00:00

Un peu de blindage, y'a un bug qui reste

This commit is contained in:
Yan Maniez 2018-05-28 11:58:24 +02:00
parent f324ea3f15
commit 8ff866f8b6
5 changed files with 75 additions and 170 deletions

View file

@ -19,6 +19,9 @@ namespace AideDeJeu.Tools
{ {
public override int Compare(string x, string y) public override int Compare(string x, string y)
{ {
if (string.IsNullOrEmpty(x) && string.IsNullOrEmpty(y)) return 0;
if (string.IsNullOrEmpty(x)) return 1;
if (string.IsNullOrEmpty(y)) return -1;
var regex = new Regex(@"\((?<xp>\d*?) (PX|XP)\)"); var regex = new Regex(@"\((?<xp>\d*?) (PX|XP)\)");
int xpx = int.Parse(regex.Match(x).Groups["xp"].Value); int xpx = int.Parse(regex.Match(x).Groups["xp"].Value);
int xpy = int.Parse(regex.Match(y).Groups["xp"].Value); int xpy = int.Parse(regex.Match(y).Groups["xp"].Value);

View file

@ -90,58 +90,6 @@ namespace AideDeJeu.Tools
} }
} }
public class ItemsTypeTemplateConverter : IValueConverter
{
public ControlTemplate SpellsTemplate { get; set; }
public ControlTemplate MonstersTemplate { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var itemType = value as ItemType?;
if (itemType == ItemType.Spell)
{
return SpellsTemplate;
}
if (itemType == ItemType.Monster)
{
return MonstersTemplate;
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
public class ItemTypeConverter<T> : IValueConverter
{
public T Spells { get; set; }
public T Monsters { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var itemType = value as ItemType?;
if (itemType == ItemType.Spell)
{
return Spells;
}
if (itemType == ItemType.Monster)
{
return Monsters;
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
public class ItemTypeToStringConverter : ItemTypeConverter<string> { }
public class ItemSourceTypeConverter<T> : IValueConverter public class ItemSourceTypeConverter<T> : IValueConverter
{ {
@ -154,31 +102,31 @@ namespace AideDeJeu.Tools
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{ {
//var itemType = value as ItemSourceType?; var itemType = value as ItemSourceType?;
//if (itemType == ItemSourceType.SpellVF) if (itemType == ItemSourceType.SpellVF)
//{ {
// return SpellVF; return SpellVF;
//} }
//if (itemType == ItemSourceType.SpellVO) if (itemType == ItemSourceType.SpellVO)
//{ {
// return SpellVO; return SpellVO;
//} }
//if (itemType == ItemSourceType.SpellHD) if (itemType == ItemSourceType.SpellHD)
//{ {
// return SpellHD; return SpellHD;
//} }
//if (itemType == ItemSourceType.MonsterVF) if (itemType == ItemSourceType.MonsterVF)
//{ {
// return MonsterVF; return MonsterVF;
//} }
//if (itemType == ItemSourceType.MonsterVO) if (itemType == ItemSourceType.MonsterVO)
//{ {
// return MonsterVO; return MonsterVO;
//} }
//if (itemType == ItemSourceType.MonsterHD) if (itemType == ItemSourceType.MonsterHD)
//{ {
// return MonsterHD; return MonsterHD;
//} }
return null; return null;
} }
@ -188,6 +136,8 @@ namespace AideDeJeu.Tools
} }
} }
public class ItemSourceTypeToStringConverter : ItemSourceTypeConverter<string> { }
public class ItemSourceTypeToItemsConverter : IValueConverter public class ItemSourceTypeToItemsConverter : IValueConverter
{ {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) public object Convert(object value, Type targetType, object parameter, CultureInfo culture)

View file

@ -4,6 +4,7 @@ using AideDeJeuLib.Monsters;
using AideDeJeuLib.Spells; using AideDeJeuLib.Spells;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Windows.Input; using System.Windows.Input;
@ -52,7 +53,7 @@ namespace AideDeJeu.ViewModels
public FilterKeys Key { get; set; } public FilterKeys Key { get; set; }
public string Name { get; set; } public string Name { get; set; }
public List<KeyValuePair<string, string>> KeyValues { get; set; } public List<KeyValuePair<string, string>> KeyValues { get; set; }
private int _Index; public int _Index;
public int Index public int Index
{ {
get get
@ -72,9 +73,13 @@ namespace AideDeJeu.ViewModels
public string SelectedKey public string SelectedKey
{ {
get get
{
if(Index >= 0 && Index < KeyValues.Count)
{ {
return KeyValues[Index].Key; return KeyValues[Index].Key;
} }
return null;
}
} }
} }
@ -90,12 +95,12 @@ namespace AideDeJeu.ViewModels
{ {
_Filters = new List<Filter>() _Filters = new List<Filter>()
{ {
new Filter() { Key = FilterKeys.Class, Name = "Classe", KeyValues = Classes, Index = 0 }, new Filter() { Key = FilterKeys.Class, Name = "Classe", KeyValues = Classes, _Index = 0 },
new Filter() { Key = FilterKeys.MinLevel, Name = "Niveau Min", KeyValues = Niveaux, Index = 0 }, new Filter() { Key = FilterKeys.MinLevel, Name = "Niveau Minimum", KeyValues = Niveaux, _Index = 0 },
new Filter() { Key = FilterKeys.MaxLevel, Name = "Niveau Max", KeyValues = Niveaux, Index = 9 }, new Filter() { Key = FilterKeys.MaxLevel, Name = "Niveau Maximum", KeyValues = Niveaux, _Index = 9 },
new Filter() { Key = FilterKeys.School, Name = "Ecole", KeyValues = Ecoles, Index = 0 }, new Filter() { Key = FilterKeys.School, Name = "École", KeyValues = Ecoles, _Index = 0 },
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 },
}; };
} }
return _Filters; return _Filters;
@ -105,12 +110,12 @@ namespace AideDeJeu.ViewModels
public override IEnumerable<Item> FilterItems(IEnumerable<Item> items) public override IEnumerable<Item> FilterItems(IEnumerable<Item> items)
{ {
var classe = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Class).SelectedKey; var classe = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Class).SelectedKey ?? "";
var niveauMin = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.MinLevel).SelectedKey; var niveauMin = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.MinLevel).SelectedKey ?? "0";
var niveauMax = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.MaxLevel).SelectedKey; var niveauMax = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.MaxLevel).SelectedKey ?? "9";
var ecole = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.School).SelectedKey; var ecole = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.School).SelectedKey ?? "";
var rituel = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Ritual).SelectedKey; var rituel = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Ritual).SelectedKey ?? "";
var source = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Source).SelectedKey; var source = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Source).SelectedKey ?? "";
return items return items
.Where(item => .Where(item =>
@ -322,13 +327,13 @@ namespace AideDeJeu.ViewModels
{ {
_Filters = new List<Filter>() _Filters = new List<Filter>()
{ {
new Filter() { Key = FilterKeys.Category, Name = "Catégories", KeyValues = Categories, Index = 0 }, //new Filter() { Key = FilterKeys.Category, Name = "Catégories", KeyValues = Categories, _Index = 0 },
new Filter() { Key = FilterKeys.Type, Name = "Type", KeyValues = Types, Index = 0 }, new Filter() { Key = FilterKeys.Type, Name = "Type", KeyValues = Types, _Index = 0 },
new Filter() { Key = FilterKeys.MinPower, Name = "Challenge Min", KeyValues = Powers, Index = 0 }, new Filter() { Key = FilterKeys.MinPower, Name = "FP Minimum", KeyValues = Powers, _Index = 0 },
new Filter() { Key = FilterKeys.MaxPower, Name = "Challenge Max", KeyValues = Powers, Index = 28 }, new Filter() { Key = FilterKeys.MaxPower, Name = "FP Maximum", KeyValues = Powers, _Index = 28 },
new Filter() { Key = FilterKeys.Size, Name = "Taille", KeyValues = Sizes, Index = 0 }, new Filter() { Key = FilterKeys.Size, Name = "Taille", KeyValues = Sizes, _Index = 0 },
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 },
}; };
} }
return _Filters; return _Filters;
@ -339,13 +344,13 @@ namespace AideDeJeu.ViewModels
{ {
var powerComparer = new PowerComparer(); var powerComparer = new PowerComparer();
var category = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Category).SelectedKey; //var category = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Category).SelectedKey ?? "";
var type = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Type).SelectedKey; var type = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Type).SelectedKey ?? "";
var minPower = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.MinPower).SelectedKey; var minPower = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.MinPower).SelectedKey ?? "0 (0 PX)";
var maxPower = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.MaxPower).SelectedKey; var maxPower = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.MaxPower).SelectedKey ?? "30 (155000 PX)";
var size = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Size).SelectedKey; var size = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Size).SelectedKey ?? "";
var legendary = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Legendary).SelectedKey; //var legendary = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Legendary).SelectedKey ?? "";
var source = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Source).SelectedKey; var source = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Source).SelectedKey ?? "";
return items.Where(item => return items.Where(item =>
{ {

View file

@ -46,9 +46,7 @@ namespace AideDeJeu.ViewModels
} }
set set
{ {
//CurrentViewModel.SearchText = "";
SetProperty(ref _ItemSourceType, value); SetProperty(ref _ItemSourceType, value);
//CurrentViewModel.SearchText = "";
LoadItemsCommand.Execute(null); LoadItemsCommand.Execute(null);
OnPropertyChanged(nameof(Items)); OnPropertyChanged(nameof(Items));
} }
@ -115,10 +113,9 @@ namespace AideDeJeu.ViewModels
public Command<string> SearchCommand { get; private set; } public Command<string> SearchCommand { get; private set; }
public Navigator Navigator { get; set; } public Navigator Navigator { get; set; }
public MainViewModel() public MainViewModel()
{ {
//Spells = new SpellsViewModel(navigator, Items);
//Monsters = new MonstersViewModel(navigator, Items);
LoadItemsCommand = new Command(() => LoadItemsCommand = new Command(() =>
{ {
GetItemsViewModel(ItemSourceType).ExecuteLoadItemsCommand(); GetItemsViewModel(ItemSourceType).ExecuteLoadItemsCommand();
@ -129,7 +126,7 @@ namespace AideDeJeu.ViewModels
SwitchToVF = new Command(() => ItemSourceType = (ItemSourceType & ~ItemSourceType.VO & ~ItemSourceType.HD) | ItemSourceType.VF); SwitchToVF = new Command(() => ItemSourceType = (ItemSourceType & ~ItemSourceType.VO & ~ItemSourceType.HD) | ItemSourceType.VF);
SwitchToVO = new Command(() => ItemSourceType = (ItemSourceType & ~ItemSourceType.VF & ~ItemSourceType.HD) | ItemSourceType.VO); SwitchToVO = new Command(() => ItemSourceType = (ItemSourceType & ~ItemSourceType.VF & ~ItemSourceType.HD) | ItemSourceType.VO);
SwitchToHD = new Command(() => ItemSourceType = (ItemSourceType & ~ItemSourceType.VF & ~ItemSourceType.VO) | ItemSourceType.HD); SwitchToHD = new Command(() => ItemSourceType = (ItemSourceType & ~ItemSourceType.VF & ~ItemSourceType.VO) | ItemSourceType.HD);
//AboutCommand = new Command(async() => await navigator.GotoAboutPageAsync()); AboutCommand = new Command(async() => await Main.Navigator.GotoAboutPageAsync());
SearchCommand = new Command<string>((text) => SearchCommand = new Command<string>((text) =>
{ {
GetFilterViewModel(ItemSourceType).SearchText = text; GetFilterViewModel(ItemSourceType).SearchText = text;

View file

@ -6,68 +6,18 @@
x:Class="AideDeJeu.Views.MainPage" x:Class="AideDeJeu.Views.MainPage"
x:Name="This" x:Name="This"
IsPresented="False" IsPresented="False"
Title="{Binding ItemsType,Converter={StaticResource ItemTypeToStringConverter}}"> Title="{Binding ItemSourceType,Converter={StaticResource ItemSourceTypeToTitleConverter}}">
<MasterDetailPage.Resources> <MasterDetailPage.Resources>
<ResourceDictionary> <ResourceDictionary>
<ControlTemplate x:Key="SpellsMasterDataTemplate"> <tools:ItemSourceTypeToStringConverter
<ScrollView Orientation="Vertical"> x:Key="ItemSourceTypeToTitleConverter"
<StackLayout Orientation="Vertical" Padding="15"> SpellVF="Sorts"
SpellVO="Spells"
<Label Text="Classe" Style="{StaticResource Key=subsubsection}" /> SpellHD="Sorts (H&amp;D)"
<Picker HorizontalOptions="FillAndExpand" ItemsSource="{TemplateBinding Parent.BindingContext.Spells.Classes, Mode=OneWay}" ItemDisplayBinding="{Binding Value, Mode=OneWay}" SelectedIndex="{TemplateBinding Parent.BindingContext.Spells.Classe}" /> MonsterVF="Monstres"
MonsterVO="Monsters"
<Label Text="Niveau minimum" Style="{StaticResource Key=subsubsection}" /> MonsterHD="Créatures (H&amp;D)"
<Picker HorizontalOptions="FillAndExpand" ItemsSource="{TemplateBinding Parent.BindingContext.Spells.Niveaux, Mode=OneWay}" ItemDisplayBinding="{Binding Value, Mode=OneWay}" SelectedIndex="{TemplateBinding Parent.BindingContext.Spells.NiveauMin}" /> />
<Label Text="Niveau maximum" Style="{StaticResource Key=subsubsection}" />
<Picker HorizontalOptions="FillAndExpand" ItemsSource="{TemplateBinding Parent.BindingContext.Spells.Niveaux, Mode=OneWay}" ItemDisplayBinding="{Binding Value, Mode=OneWay}" SelectedIndex="{TemplateBinding Parent.BindingContext.Spells.NiveauMax}" />
<Label Text="École" Style="{StaticResource Key=subsubsection}" />
<Picker HorizontalOptions="FillAndExpand" ItemsSource="{TemplateBinding Parent.BindingContext.Spells.Ecoles, Mode=OneWay}" ItemDisplayBinding="{Binding Value, Mode=OneWay}" SelectedIndex="{TemplateBinding Parent.BindingContext.Spells.Ecole}" />
<Label Text="Rituel" Style="{StaticResource Key=subsubsection}" />
<Picker HorizontalOptions="FillAndExpand" ItemsSource="{TemplateBinding Parent.BindingContext.Spells.Rituels, Mode=OneWay}" ItemDisplayBinding="{Binding Value, Mode=OneWay}" SelectedIndex="{TemplateBinding Parent.BindingContext.Spells.Rituel}" />
<Label Text="Source" Style="{StaticResource Key=subsubsection}" />
<Picker HorizontalOptions="FillAndExpand" ItemsSource="{TemplateBinding Parent.BindingContext.Spells.Sources, Mode=OneWay}" ItemDisplayBinding="{Binding Value, Mode=OneWay}" SelectedIndex="{TemplateBinding Parent.BindingContext.Spells.Source}" IsEnabled="False" />
</StackLayout>
</ScrollView>
</ControlTemplate>
<ControlTemplate x:Key="MonstersMasterDataTemplate">
<ScrollView Orientation="Vertical">
<StackLayout Orientation="Vertical" Padding="15">
<Label Text="Type" Style="{StaticResource Key=subsubsection}" />
<Picker HorizontalOptions="FillAndExpand" ItemsSource="{TemplateBinding Parent.BindingContext.Monsters.Types, Mode=OneWay}" ItemDisplayBinding="{Binding Value, Mode=OneWay}" SelectedIndex="{TemplateBinding Parent.BindingContext.Monsters.Type}" />
<StackLayout Orientation="Horizontal">
<StackLayout Orientation="Vertical">
<Label Text="FP minimum" Style="{StaticResource Key=subsubsection}" />
<Picker HorizontalOptions="FillAndExpand" ItemsSource="{TemplateBinding Parent.BindingContext.Monsters.Powers, Mode=OneWay}" ItemDisplayBinding="{Binding Value, Mode=OneWay}" SelectedIndex="{TemplateBinding Parent.BindingContext.Monsters.MinPower}" />
</StackLayout>
<StackLayout Orientation="Vertical">
<Label Text="FP maximum" Style="{StaticResource Key=subsubsection}" />
<Picker HorizontalOptions="FillAndExpand" ItemsSource="{TemplateBinding Parent.BindingContext.Monsters.Powers, Mode=OneWay}" ItemDisplayBinding="{Binding Value, Mode=OneWay}" SelectedIndex="{TemplateBinding Parent.BindingContext.Monsters.MaxPower}" />
</StackLayout>
</StackLayout>
<Label Text="Taille" Style="{StaticResource Key=subsubsection}" />
<Picker HorizontalOptions="FillAndExpand" ItemsSource="{TemplateBinding Parent.BindingContext.Monsters.Sizes, Mode=OneWay}" ItemDisplayBinding="{Binding Value, Mode=OneWay}" SelectedIndex="{TemplateBinding Parent.BindingContext.Monsters.Size}" />
<Label Text="Source" Style="{StaticResource Key=subsubsection}" />
<Picker HorizontalOptions="FillAndExpand" ItemsSource="{TemplateBinding Parent.BindingContext.Monsters.Sources, Mode=OneWay}" ItemDisplayBinding="{Binding Value, Mode=OneWay}" SelectedIndex="{TemplateBinding Parent.BindingContext.Monsters.Source}" IsEnabled="False"/>
</StackLayout>
</ScrollView>
</ControlTemplate>
<tools:ItemTypeToStringConverter
x:Key="ItemTypeToStringConverter"
Spells="Sorts"
Monsters="Monstres" />
<tools:ItemsTypeTemplateConverter
x:Key="ItemsTypeTemplateConverter"
SpellsTemplate="{StaticResource SpellsMasterDataTemplate}"
MonstersTemplate="{StaticResource MonstersMasterDataTemplate}" />
<tools:ItemSourceTypeToItemsConverter <tools:ItemSourceTypeToItemsConverter
x:Key="ItemSourceTypeToItemsConverter" /> x:Key="ItemSourceTypeToItemsConverter" />
<tools:ItemSourceTypeToFilterConverter <tools:ItemSourceTypeToFilterConverter