From bc9203fb44bc4fd2a8bc14d867143158e79464eb Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Fri, 12 Aug 2016 16:25:31 -0500 Subject: [PATCH] Presents confirmation dialog asking user what to do if resuming paused game from GamesViewController --- Cores/DeltaCore | 2 +- Delta/Emulation/GameViewController.swift | 8 +---- .../GameCollectionViewController.swift | 34 ++++++++++++++++++- .../Game Selection/GamesViewController.swift | 3 ++ .../Segues/GamesStoryboardSegue.swift | 7 ++++ .../Segues/InitialGamesStoryboardSegue.swift | 7 ++++ 6 files changed, 52 insertions(+), 9 deletions(-) diff --git a/Cores/DeltaCore b/Cores/DeltaCore index d489536..e7c44d6 160000 --- a/Cores/DeltaCore +++ b/Cores/DeltaCore @@ -1 +1 @@ -Subproject commit d4895367427ffed6ef1fd04e60868cf799fb3371 +Subproject commit e7c44d64678d2256af4429e8d2d39d5ffd54dc7f diff --git a/Delta/Emulation/GameViewController.swift b/Delta/Emulation/GameViewController.swift index 2e76960..dd84b43 100644 --- a/Delta/Emulation/GameViewController.swift +++ b/Delta/Emulation/GameViewController.swift @@ -183,13 +183,6 @@ extension GameViewController self.updateControllers() } - override func viewDidDisappear(_ animated: Bool) - { - super.viewDidDisappear(animated) - - self.emulatorCore?.pause() - } - // MARK: - Segues /// KVO @@ -202,6 +195,7 @@ extension GameViewController case "showGamesViewController": let gamesViewController = (segue.destination as! UINavigationController).topViewController as! GamesViewController gamesViewController.theme = .dark + gamesViewController.activeEmulatorCore = self.emulatorCore self.updateAutoSaveState() diff --git a/Delta/Game Selection/GameCollectionViewController.swift b/Delta/Game Selection/GameCollectionViewController.swift index 836ba9c..dcb729a 100644 --- a/Delta/Game Selection/GameCollectionViewController.swift +++ b/Delta/Game Selection/GameCollectionViewController.swift @@ -8,6 +8,8 @@ import UIKit +import DeltaCore + import Roxas class GameCollectionViewController: UICollectionViewController @@ -25,6 +27,8 @@ class GameCollectionViewController: UICollectionViewController } } + var activeEmulatorCore: EmulatorCore? + private var dataSource: RSTFetchedResultsCollectionViewDataSource! private let prototypeCell = GridCollectionViewCell() } @@ -128,7 +132,35 @@ extension GameCollectionViewController override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { let cell = collectionView.cellForItem(at: indexPath) - self.performSegue(withIdentifier: "unwindFromGames", sender: cell) + let game = self.dataSource.fetchedResultsController.object(at: indexPath) + + func launchGame(clearScreen: Bool) + { + if clearScreen + { + self.activeEmulatorCore?.gameViews.forEach({ $0.inputImage = nil }) + } + + self.performSegue(withIdentifier: "unwindFromGames", sender: cell) + } + + if game.fileURL == self.activeEmulatorCore?.game.fileURL + { + let alertController = UIAlertController(title: NSLocalizedString("Game Paused", comment: ""), message: NSLocalizedString("Would you like to resume where you left off, or restart the game?", comment: ""), preferredStyle: .alert) + alertController.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .cancel, handler: nil)) + alertController.addAction(UIAlertAction(title: NSLocalizedString("Resume", comment: ""), style: .default, handler: { (action) in + launchGame(clearScreen: false) + })) + alertController.addAction(UIAlertAction(title: NSLocalizedString("Restart", comment: ""), style: .destructive, handler: { (action) in + self.activeEmulatorCore?.stop() + launchGame(clearScreen: true) + })) + self.present(alertController, animated: true) + } + else + { + launchGame(clearScreen: true) + } } } diff --git a/Delta/Game Selection/GamesViewController.swift b/Delta/Game Selection/GamesViewController.swift index eb9d7c3..ae8caa3 100644 --- a/Delta/Game Selection/GamesViewController.swift +++ b/Delta/Game Selection/GamesViewController.swift @@ -30,6 +30,8 @@ class GamesViewController: UIViewController } } + var activeEmulatorCore: EmulatorCore? + private var pageViewController: UIPageViewController! private var backgroundView: RSTBackgroundView! private var pageControl: UIPageControl! @@ -181,6 +183,7 @@ private extension GamesViewController let viewController = self.storyboard?.instantiateViewController(withIdentifier: "gameCollectionViewController") as! GameCollectionViewController viewController.gameCollection = self.fetchedResultsController.object(at: indexPath) as! GameCollection viewController.theme = self.theme + viewController.activeEmulatorCore = self.activeEmulatorCore return viewController } diff --git a/Delta/Game Selection/Segues/GamesStoryboardSegue.swift b/Delta/Game Selection/Segues/GamesStoryboardSegue.swift index 9888780..3f84bdd 100644 --- a/Delta/Game Selection/Segues/GamesStoryboardSegue.swift +++ b/Delta/Game Selection/Segues/GamesStoryboardSegue.swift @@ -74,6 +74,8 @@ extension GamesStoryboardSegue: UIViewControllerAnimatedTransitioning func animatePresentationTransition(using transitionContext: UIViewControllerContextTransitioning) { + transitionContext.sourceViewController.beginAppearanceTransition(false, animated: true) + transitionContext.destinationView.frame = transitionContext.destinationViewFinalFrame! transitionContext.destinationView.transform = CGAffineTransform(scaleX: 2.0, y: 2.0) transitionContext.containerView.addSubview(transitionContext.destinationView) @@ -137,6 +139,8 @@ extension GamesStoryboardSegue: UIViewControllerAnimatedTransitioning topPaddingToolbar?.removeFromSuperview() bottomPaddingToolbar?.removeFromSuperview() + + transitionContext.sourceViewController.endAppearanceTransition() } self.animator.startAnimation() @@ -144,6 +148,8 @@ extension GamesStoryboardSegue: UIViewControllerAnimatedTransitioning func animateDismissalTransition(using transitionContext: UIViewControllerContextTransitioning) { + transitionContext.destinationViewController.beginAppearanceTransition(true, animated: true) + self.animator.addAnimations { transitionContext.sourceView.alpha = 0.0 transitionContext.sourceView.transform = CGAffineTransform(scaleX: 2.0, y: 2.0) @@ -151,6 +157,7 @@ extension GamesStoryboardSegue: UIViewControllerAnimatedTransitioning self.animator.addCompletion { (position) in transitionContext.completeTransition(position == .end) + transitionContext.destinationViewController.endAppearanceTransition() } self.animator.startAnimation() diff --git a/Delta/Game Selection/Segues/InitialGamesStoryboardSegue.swift b/Delta/Game Selection/Segues/InitialGamesStoryboardSegue.swift index f2ec7a9..cdf1a34 100644 --- a/Delta/Game Selection/Segues/InitialGamesStoryboardSegue.swift +++ b/Delta/Game Selection/Segues/InitialGamesStoryboardSegue.swift @@ -68,14 +68,20 @@ extension InitialGamesStoryboardSegue: UIViewControllerAnimatedTransitioning func animatePresentationTransition(using transitionContext: UIViewControllerContextTransitioning) { + transitionContext.sourceViewController.beginAppearanceTransition(false, animated: false) + // No animation transitionContext.destinationView.frame = transitionContext.destinationViewFinalFrame! transitionContext.containerView.addSubview(transitionContext.destinationView) transitionContext.completeTransition(true) + + transitionContext.sourceViewController.endAppearanceTransition() } func animateDismissalTransition(using transitionContext: UIViewControllerContextTransitioning) { + transitionContext.destinationViewController.beginAppearanceTransition(true, animated: true) + transitionContext.destinationView.transform = CGAffineTransform(scaleX: 0.5, y: 0.5) transitionContext.destinationView.alpha = 0.0 @@ -89,6 +95,7 @@ extension InitialGamesStoryboardSegue: UIViewControllerAnimatedTransitioning self.animator.addCompletion { (position) in transitionContext.completeTransition(position == .end) + transitionContext.destinationViewController.endAppearanceTransition() } self.animator.startAnimation()