mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-11-02 16:27:04 +00:00
Picker amélioré
This commit is contained in:
parent
e5f244df36
commit
62b17e8659
8 changed files with 136 additions and 7 deletions
|
|
@ -100,6 +100,9 @@
|
||||||
<EmbeddedResource Update="Views\PlayerCharacterEditorPage.xaml">
|
<EmbeddedResource Update="Views\PlayerCharacterEditorPage.xaml">
|
||||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Update="Views\StringPicker.xaml">
|
||||||
|
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||||
|
</EmbeddedResource>
|
||||||
<EmbeddedResource Update="Views\TextInputCancellableView.xaml">
|
<EmbeddedResource Update="Views\TextInputCancellableView.xaml">
|
||||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ namespace AideDeJeu.ViewModels
|
||||||
}
|
}
|
||||||
public class Navigator : BaseViewModel, INavigator
|
public class Navigator : BaseViewModel, INavigator
|
||||||
{
|
{
|
||||||
INavigation Navigation;
|
public INavigation Navigation;
|
||||||
|
|
||||||
public Navigator(INavigation navigation)
|
public Navigator(INavigation navigation)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
47
AideDeJeu/AideDeJeu/ViewModels/PickerViewModel.cs
Normal file
47
AideDeJeu/AideDeJeu/ViewModels/PickerViewModel.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AideDeJeu.ViewModels
|
||||||
|
{
|
||||||
|
public class PickerViewModel<T> : BaseViewModel where T:class
|
||||||
|
{
|
||||||
|
private List<T> _Items = null;
|
||||||
|
public List<T> Items
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _Items;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
SetProperty(ref _Items, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private T _SelectedItem = null;
|
||||||
|
public T SelectedItem
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _SelectedItem;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
SetProperty(ref _SelectedItem, value);
|
||||||
|
if (_taskCompletionSource != null)
|
||||||
|
{
|
||||||
|
_taskCompletionSource.SetResult(value);
|
||||||
|
_taskCompletionSource = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private TaskCompletionSource<T> _taskCompletionSource;
|
||||||
|
public Task<T> PickValueAsync()
|
||||||
|
{
|
||||||
|
_taskCompletionSource = new TaskCompletionSource<T>();
|
||||||
|
return _taskCompletionSource.Task;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,9 +3,12 @@ using AideDeJeuLib;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
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.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
namespace AideDeJeu.ViewModels
|
namespace AideDeJeu.ViewModels
|
||||||
{
|
{
|
||||||
|
|
@ -183,7 +186,8 @@ namespace AideDeJeu.ViewModels
|
||||||
if (line.StartsWith("|"))
|
if (line.StartsWith("|"))
|
||||||
{
|
{
|
||||||
var cols = line.Split('|');
|
var cols = line.Split('|');
|
||||||
result.Add(cols[2]);
|
var text = cols[2].Replace("<!--br-->", " ").Replace(" ", " ");
|
||||||
|
result.Add(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -211,6 +215,25 @@ namespace AideDeJeu.ViewModels
|
||||||
return new List<SubBackgroundItem>();
|
return new List<SubBackgroundItem>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ICommand StringPickerCommand
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return new Command<List<string>>(async (strings) => await ExecuteStringPickerCommandAsync(strings));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ExecuteStringPickerCommandAsync(List<string> strings)
|
||||||
|
{
|
||||||
|
var picker = new Views.StringPicker();
|
||||||
|
var vm = picker.ViewModel;
|
||||||
|
vm.Items = strings;
|
||||||
|
await Main.Navigator.Navigation.PushModalAsync(picker, true);
|
||||||
|
var result = await vm.PickValueAsync();
|
||||||
|
await Main.Navigator.Navigation.PopModalAsync(true);
|
||||||
|
SelectedPlayerCharacter.PersonalityTrait = result;
|
||||||
|
}
|
||||||
#endregion Background
|
#endregion Background
|
||||||
|
|
||||||
#region Abilities
|
#region Abilities
|
||||||
|
|
|
||||||
|
|
@ -55,5 +55,17 @@ namespace AideDeJeu.ViewModels
|
||||||
SetProperty(ref _SubBackground, value);
|
SetProperty(ref _SubBackground, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private string _PersonalityTrait = null;
|
||||||
|
public string PersonalityTrait
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _PersonalityTrait;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
SetProperty(ref _PersonalityTrait, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,9 @@
|
||||||
<StackLayout HorizontalOptions="FillAndExpand" >
|
<StackLayout HorizontalOptions="FillAndExpand" >
|
||||||
<mdview:MarkdownView Markdown="{Binding SelectedPlayerCharacter.Background.Description}" />
|
<mdview:MarkdownView Markdown="{Binding SelectedPlayerCharacter.Background.Description}" />
|
||||||
<mdview:MarkdownView Markdown="{Binding SelectedPlayerCharacter.SubBackground.Description}" />
|
<mdview:MarkdownView Markdown="{Binding SelectedPlayerCharacter.SubBackground.Description}" />
|
||||||
<ListView HorizontalOptions="FillAndExpand" ItemsSource="{Binding PersonalityTraits.Result}">
|
<Button Text="Trait de personnalité" Command="{Binding StringPickerCommand}" CommandParameter="{Binding PersonalityTraits.Result}" />
|
||||||
|
<mdview:MarkdownView HorizontalOptions="FillAndExpand" Markdown="{Binding SelectedPlayerCharacter.PersonalityTrait}" />
|
||||||
|
<!--<ListView HorizontalOptions="FillAndExpand" ItemsSource="{Binding PersonalityTraits.Result}">
|
||||||
<ListView.ItemTemplate>
|
<ListView.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<ViewCell>
|
<ViewCell>
|
||||||
|
|
@ -66,7 +68,7 @@
|
||||||
</ViewCell>
|
</ViewCell>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ListView.ItemTemplate>
|
</ListView.ItemTemplate>
|
||||||
</ListView>
|
</ListView>-->
|
||||||
<mdview:MarkdownView Markdown="{Binding SelectedPlayerCharacter.Background.Markdown}" />
|
<mdview:MarkdownView Markdown="{Binding SelectedPlayerCharacter.Background.Markdown}" />
|
||||||
<mdview:MarkdownView Markdown="{Binding SelectedPlayerCharacter.SubBackground.Markdown}" />
|
<mdview:MarkdownView Markdown="{Binding SelectedPlayerCharacter.SubBackground.Markdown}" />
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
|
|
|
||||||
19
AideDeJeu/AideDeJeu/Views/StringPicker.xaml
Normal file
19
AideDeJeu/AideDeJeu/Views/StringPicker.xaml
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
|
xmlns:mdview="clr-namespace:Xam.Forms.Markdown"
|
||||||
|
x:Class="AideDeJeu.Views.StringPicker">
|
||||||
|
<ContentPage.Content>
|
||||||
|
<StackLayout>
|
||||||
|
<ListView ItemsSource="{Binding Items}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
|
||||||
|
<ListView.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<ViewCell>
|
||||||
|
<mdview:MarkdownView HorizontalOptions="FillAndExpand" Markdown="{Binding}" />
|
||||||
|
</ViewCell>
|
||||||
|
</DataTemplate>
|
||||||
|
</ListView.ItemTemplate>
|
||||||
|
</ListView>
|
||||||
|
</StackLayout>
|
||||||
|
</ContentPage.Content>
|
||||||
|
</ContentPage>
|
||||||
23
AideDeJeu/AideDeJeu/Views/StringPicker.xaml.cs
Normal file
23
AideDeJeu/AideDeJeu/Views/StringPicker.xaml.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
using AideDeJeu.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using Xamarin.Forms;
|
||||||
|
using Xamarin.Forms.Xaml;
|
||||||
|
|
||||||
|
namespace AideDeJeu.Views
|
||||||
|
{
|
||||||
|
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||||
|
public partial class StringPicker : ContentPage
|
||||||
|
{
|
||||||
|
public PickerViewModel<string> ViewModel { get; set; } = new PickerViewModel<string>();
|
||||||
|
public StringPicker()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
BindingContext = ViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue