mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-10-29 14:35:45 +00:00
Encore refonte
This commit is contained in:
parent
1c35626e45
commit
a89e7a9cd1
3 changed files with 60 additions and 3 deletions
|
|
@ -52,14 +52,14 @@ namespace AideDeJeu.ViewModels
|
|||
public Command SwitchToMonsters { get; private set; }
|
||||
public Command AboutCommand { get; private set; }
|
||||
|
||||
public MainViewModel(INavigation navigation)
|
||||
public MainViewModel(INavigator navigator)
|
||||
{
|
||||
Spells = new SpellsViewModel(Items);
|
||||
Monsters = new MonstersViewModel(Items);
|
||||
LoadItemsCommand = new Command(async () => await CurrentViewModel.ExecuteLoadItemsCommandAsync());
|
||||
SwitchToSpells = new Command(() => ItemsType = ItemType.Spell);
|
||||
SwitchToMonsters = new Command(() => ItemsType = ItemType.Monster);
|
||||
AboutCommand = new Command(async() => await navigation.PushAsync(new Views.AboutPage()));
|
||||
AboutCommand = new Command(async() => await navigator.GotoAboutPageAsync());
|
||||
}
|
||||
}
|
||||
}
|
||||
55
AideDeJeu/AideDeJeu/ViewModels/Navigator.cs
Normal file
55
AideDeJeu/AideDeJeu/ViewModels/Navigator.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
using AideDeJeu.Views;
|
||||
using AideDeJeuLib;
|
||||
using AideDeJeuLib.Monsters;
|
||||
using AideDeJeuLib.Spells;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace AideDeJeu.ViewModels
|
||||
{
|
||||
public interface INavigator
|
||||
{
|
||||
Task GotoAboutPageAsync();
|
||||
Task GotoMonsterDetailPageAsync(Item item);
|
||||
Task GotoSpellDetailPageAsync(Item item);
|
||||
}
|
||||
public class Navigator : INavigator
|
||||
{
|
||||
INavigation Navigation;
|
||||
|
||||
public Navigator(INavigation navigation)
|
||||
{
|
||||
Navigation = navigation;
|
||||
}
|
||||
|
||||
public async Task GotoAboutPageAsync()
|
||||
{
|
||||
await Navigation.PushAsync(new Views.AboutPage());
|
||||
}
|
||||
|
||||
public async Task GotoMonsterDetailPageAsync(Item item)
|
||||
{
|
||||
var monster = item as Monster;
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
var vm = new MonsterDetailViewModel(monster);
|
||||
vm.LoadItemCommand.Execute(null);
|
||||
await Navigation.PushAsync(new MonsterDetailPage(vm));
|
||||
}
|
||||
|
||||
public async Task GotoSpellDetailPageAsync(Item item)
|
||||
{
|
||||
var spell = item as Spell;
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
var vm = new SpellDetailViewModel(spell);
|
||||
vm.LoadItemCommand.Execute(null);
|
||||
await Navigation.PushAsync(new SpellDetailPage(vm));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -12,11 +12,13 @@ namespace AideDeJeu.Views
|
|||
public partial class MainPage : MasterDetailPage
|
||||
{
|
||||
MainViewModel viewModel;
|
||||
INavigator Navigator;
|
||||
|
||||
public MainPage ()
|
||||
{
|
||||
InitializeComponent ();
|
||||
BindingContext = viewModel = new MainViewModel(Navigation);
|
||||
Navigator = new Navigator(Navigation);
|
||||
BindingContext = viewModel = new MainViewModel(Navigator);
|
||||
}
|
||||
|
||||
protected override bool OnBackButtonPressed()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue