From e59aad59edd1af49305e3741e48d06af544bc6cf Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Tue, 19 Jan 2016 21:32:16 +0100 Subject: [PATCH] Bugfixes and improvements --- YJMPD-UWP/App.xaml.cs | 4 +++- YJMPD-UWP/Model/ApiHandler.cs | 16 ++-------------- YJMPD-UWP/Model/GameHandler.cs | 12 +++++++++++- YJMPD-UWP/Model/NetworkHandler.cs | 5 ++++- YJMPD-UWP/Model/PhotoHandler.cs | 5 +++++ 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/YJMPD-UWP/App.xaml.cs b/YJMPD-UWP/App.xaml.cs index b3fffca..2ed0978 100644 --- a/YJMPD-UWP/App.xaml.cs +++ b/YJMPD-UWP/App.xaml.cs @@ -225,7 +225,9 @@ namespace YJMPD_UWP private void OnSuspending(object sender, SuspendingEventArgs e) { var deferral = e.SuspendingOperation.GetDeferral(); - //TODO: Save application state and stop any background activity + + App.Network.Disconnect(); + deferral.Complete(); } } diff --git a/YJMPD-UWP/Model/ApiHandler.cs b/YJMPD-UWP/Model/ApiHandler.cs index d3d0492..c88943c 100644 --- a/YJMPD-UWP/Model/ApiHandler.cs +++ b/YJMPD-UWP/Model/ApiHandler.cs @@ -13,8 +13,6 @@ namespace YJMPD_UWP.Model { public class ApiHandler { - public delegate void OnGameFoundHandler(object sender, EventArgs e); - public event OnGameFoundHandler OnGameFound; public enum Command { @@ -22,7 +20,6 @@ namespace YJMPD_UWP.Model Name, Picture, Msg, - GameFound, PlayerJoined, PlayerRemoved } @@ -39,9 +36,6 @@ namespace YJMPD_UWP.Model switch (c) { - case Command.GameFound: - GameFound(); - break; case Command.PlayerJoined: Debug.WriteLine("Played joined"); PlayerJoined(o[Command.PlayerJoined.ToString()].ToString()); @@ -59,6 +53,8 @@ namespace YJMPD_UWP.Model } else App.Navigate(typeof(WaitingView)); + + App.Game.MoveToWaiting(); break; default: //Do nothing @@ -79,14 +75,6 @@ namespace YJMPD_UWP.Model App.Game.RemovePlayer(username); } - private void GameFound() - { - throw new NotImplementedException(); - if (OnGameFound == null) return; - - OnGameFound(this, new EventArgs()); - } - public JObject Message(Command c, string msg) { return JObject.FromObject(new diff --git a/YJMPD-UWP/Model/GameHandler.cs b/YJMPD-UWP/Model/GameHandler.cs index b252ad3..82f729c 100644 --- a/YJMPD-UWP/Model/GameHandler.cs +++ b/YJMPD-UWP/Model/GameHandler.cs @@ -54,6 +54,11 @@ namespace YJMPD_UWP.Model UpdateGamePlayers(p); } + public void MoveToWaiting() + { + UpdateGameStatus(GameStatus.WAITING); + } + public void RemovePlayer(string username) { for(int i=Players.Count-1; i>=0; i--) @@ -69,6 +74,8 @@ namespace YJMPD_UWP.Model public void Reset() { + App.Photo.Reset(); + Selected = false; Players.Clear(); UpdateGamePlayers(null); } @@ -126,7 +133,10 @@ namespace YJMPD_UWP.Model App.Navigate(typeof(MatchView)); break; case GameStatus.WAITING: - App.Navigate(typeof(WaitingView)); + if (Selected) + App.Navigate(typeof(PhotoView)); + else + App.Navigate(typeof(WaitingView)); break; case GameStatus.STARTED: if (Selected && App.Photo.Photo == null) diff --git a/YJMPD-UWP/Model/NetworkHandler.cs b/YJMPD-UWP/Model/NetworkHandler.cs index 2b8509b..aceee33 100644 --- a/YJMPD-UWP/Model/NetworkHandler.cs +++ b/YJMPD-UWP/Model/NetworkHandler.cs @@ -95,8 +95,11 @@ namespace YJMPD_UWP.Model return true; } - private async Task Disconnect() + public async Task Disconnect() { + if(App.Game.Status != GameHandler.GameStatus.STOPPED) + App.Api.LeaveGame(); + UpdateNetworkStatus(NetworkStatus.DISCONNECTED); if (BackgroundReader != null) diff --git a/YJMPD-UWP/Model/PhotoHandler.cs b/YJMPD-UWP/Model/PhotoHandler.cs index cc8526a..5383a00 100644 --- a/YJMPD-UWP/Model/PhotoHandler.cs +++ b/YJMPD-UWP/Model/PhotoHandler.cs @@ -21,6 +21,11 @@ namespace YJMPD_UWP.Model } + public void Reset() + { + Photo = null; + } + private void UpdatePhotoTaken(SoftwareBitmapSource photo) { Photo = photo;