Merge pull request '⚡ Navigation entre les pages, interactions et persistance' (#100) from navigation into dev
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Reviewed-on: #100 Reviewed-by: Remi NEVEU <remi.neveu@etu.uca.fr>pull/108/head
commit
a34c5cc715
After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 228 B |
Before Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 18 KiB |
@ -1,16 +1,82 @@
|
||||
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Trek_12.Views;
|
||||
using Stub;
|
||||
using Models.Game;
|
||||
|
||||
public partial class PageSelectMap : ContentPage
|
||||
{
|
||||
public Game SelectMapManager => (App.Current as App).Manager;
|
||||
private Map? _selectedMap;
|
||||
|
||||
protected override async void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
if (SelectMapManager.Games.Any(g => g.IsRunning))
|
||||
{
|
||||
|
||||
await DisplayAlert("Warning", "You've previously quit in the middle of a game.\nIf you start a new game, this one will be permanently lost.", "I understand");
|
||||
|
||||
public Stub MyStub { get; set; } = new Stub();
|
||||
}
|
||||
}
|
||||
|
||||
public PageSelectMap()
|
||||
public PageSelectMap()
|
||||
{
|
||||
InitializeComponent();
|
||||
BindingContext = MyStub;
|
||||
BindingContext = SelectMapManager;
|
||||
|
||||
}
|
||||
|
||||
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
_selectedMap = e.CurrentSelection.FirstOrDefault() as Map;
|
||||
}
|
||||
|
||||
private async void BackButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
await Shell.Current.GoToAsync("..");
|
||||
}
|
||||
|
||||
private async void PlayButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
if (_selectedMap == null)
|
||||
{
|
||||
await DisplayAlert("Selection Required", "Please select a map you want to play to continue.", "OK");
|
||||
return;
|
||||
}
|
||||
if (SelectMapManager.Players.Count == 0)
|
||||
{
|
||||
await DisplayAlert("No player found", "Please add a player in the profile page.", "OK");
|
||||
return;
|
||||
}
|
||||
|
||||
string[] profiles = GetProfiles().ToArray();
|
||||
string choosenPlayerName = await DisplayActionSheet("Choose a player", "Cancel", null, profiles);
|
||||
if (choosenPlayerName == null || choosenPlayerName == "Cancel") return;
|
||||
|
||||
Player chosenPlayer = GetProfileByName(choosenPlayerName);
|
||||
|
||||
SelectMapManager.InitializeGame(_selectedMap, chosenPlayer);
|
||||
|
||||
if (SelectMapManager.UsedMap == _selectedMap && Equals(SelectMapManager.CurrentPlayer, chosenPlayer))
|
||||
{
|
||||
await Shell.Current.GoToAsync(nameof(PageBoard));
|
||||
}
|
||||
else
|
||||
{
|
||||
await DisplayAlert("Error", "An error occured while initializing the game. Please try again.", "OK");
|
||||
}
|
||||
}
|
||||
|
||||
private List<string> GetProfiles()
|
||||
{
|
||||
return SelectMapManager.Players.Select(p => p.Pseudo).ToList();
|
||||
}
|
||||
|
||||
private Player GetProfileByName(string pseudo)
|
||||
{
|
||||
return SelectMapManager.Players.FirstOrDefault(p => p.Pseudo == pseudo);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue