Presents confirmation dialog asking user what to do if resuming paused game from GamesViewController

This commit is contained in:
Riley Testut 2016-08-12 16:25:31 -05:00
parent 21c5d13ba2
commit bc9203fb44
6 changed files with 52 additions and 9 deletions

@ -1 +1 @@
Subproject commit d4895367427ffed6ef1fd04e60868cf799fb3371 Subproject commit e7c44d64678d2256af4429e8d2d39d5ffd54dc7f

View File

@ -183,13 +183,6 @@ extension GameViewController
self.updateControllers() self.updateControllers()
} }
override func viewDidDisappear(_ animated: Bool)
{
super.viewDidDisappear(animated)
self.emulatorCore?.pause()
}
// MARK: - Segues // MARK: - Segues
/// KVO /// KVO
@ -202,6 +195,7 @@ extension GameViewController
case "showGamesViewController": case "showGamesViewController":
let gamesViewController = (segue.destination as! UINavigationController).topViewController as! GamesViewController let gamesViewController = (segue.destination as! UINavigationController).topViewController as! GamesViewController
gamesViewController.theme = .dark gamesViewController.theme = .dark
gamesViewController.activeEmulatorCore = self.emulatorCore
self.updateAutoSaveState() self.updateAutoSaveState()

View File

@ -8,6 +8,8 @@
import UIKit import UIKit
import DeltaCore
import Roxas import Roxas
class GameCollectionViewController: UICollectionViewController class GameCollectionViewController: UICollectionViewController
@ -25,6 +27,8 @@ class GameCollectionViewController: UICollectionViewController
} }
} }
var activeEmulatorCore: EmulatorCore?
private var dataSource: RSTFetchedResultsCollectionViewDataSource<Game>! private var dataSource: RSTFetchedResultsCollectionViewDataSource<Game>!
private let prototypeCell = GridCollectionViewCell() private let prototypeCell = GridCollectionViewCell()
} }
@ -128,8 +132,36 @@ extension GameCollectionViewController
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
{ {
let cell = collectionView.cellForItem(at: indexPath) let cell = collectionView.cellForItem(at: indexPath)
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) 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)
}
}
} }
//MARK: - UICollectionViewDelegateFlowLayout - //MARK: - UICollectionViewDelegateFlowLayout -

View File

@ -30,6 +30,8 @@ class GamesViewController: UIViewController
} }
} }
var activeEmulatorCore: EmulatorCore?
private var pageViewController: UIPageViewController! private var pageViewController: UIPageViewController!
private var backgroundView: RSTBackgroundView! private var backgroundView: RSTBackgroundView!
private var pageControl: UIPageControl! private var pageControl: UIPageControl!
@ -181,6 +183,7 @@ private extension GamesViewController
let viewController = self.storyboard?.instantiateViewController(withIdentifier: "gameCollectionViewController") as! GameCollectionViewController let viewController = self.storyboard?.instantiateViewController(withIdentifier: "gameCollectionViewController") as! GameCollectionViewController
viewController.gameCollection = self.fetchedResultsController.object(at: indexPath) as! GameCollection viewController.gameCollection = self.fetchedResultsController.object(at: indexPath) as! GameCollection
viewController.theme = self.theme viewController.theme = self.theme
viewController.activeEmulatorCore = self.activeEmulatorCore
return viewController return viewController
} }

View File

@ -74,6 +74,8 @@ extension GamesStoryboardSegue: UIViewControllerAnimatedTransitioning
func animatePresentationTransition(using transitionContext: UIViewControllerContextTransitioning) func animatePresentationTransition(using transitionContext: UIViewControllerContextTransitioning)
{ {
transitionContext.sourceViewController.beginAppearanceTransition(false, animated: true)
transitionContext.destinationView.frame = transitionContext.destinationViewFinalFrame! transitionContext.destinationView.frame = transitionContext.destinationViewFinalFrame!
transitionContext.destinationView.transform = CGAffineTransform(scaleX: 2.0, y: 2.0) transitionContext.destinationView.transform = CGAffineTransform(scaleX: 2.0, y: 2.0)
transitionContext.containerView.addSubview(transitionContext.destinationView) transitionContext.containerView.addSubview(transitionContext.destinationView)
@ -137,6 +139,8 @@ extension GamesStoryboardSegue: UIViewControllerAnimatedTransitioning
topPaddingToolbar?.removeFromSuperview() topPaddingToolbar?.removeFromSuperview()
bottomPaddingToolbar?.removeFromSuperview() bottomPaddingToolbar?.removeFromSuperview()
transitionContext.sourceViewController.endAppearanceTransition()
} }
self.animator.startAnimation() self.animator.startAnimation()
@ -144,6 +148,8 @@ extension GamesStoryboardSegue: UIViewControllerAnimatedTransitioning
func animateDismissalTransition(using transitionContext: UIViewControllerContextTransitioning) func animateDismissalTransition(using transitionContext: UIViewControllerContextTransitioning)
{ {
transitionContext.destinationViewController.beginAppearanceTransition(true, animated: true)
self.animator.addAnimations { self.animator.addAnimations {
transitionContext.sourceView.alpha = 0.0 transitionContext.sourceView.alpha = 0.0
transitionContext.sourceView.transform = CGAffineTransform(scaleX: 2.0, y: 2.0) transitionContext.sourceView.transform = CGAffineTransform(scaleX: 2.0, y: 2.0)
@ -151,6 +157,7 @@ extension GamesStoryboardSegue: UIViewControllerAnimatedTransitioning
self.animator.addCompletion { (position) in self.animator.addCompletion { (position) in
transitionContext.completeTransition(position == .end) transitionContext.completeTransition(position == .end)
transitionContext.destinationViewController.endAppearanceTransition()
} }
self.animator.startAnimation() self.animator.startAnimation()

View File

@ -68,14 +68,20 @@ extension InitialGamesStoryboardSegue: UIViewControllerAnimatedTransitioning
func animatePresentationTransition(using transitionContext: UIViewControllerContextTransitioning) func animatePresentationTransition(using transitionContext: UIViewControllerContextTransitioning)
{ {
transitionContext.sourceViewController.beginAppearanceTransition(false, animated: false)
// No animation // No animation
transitionContext.destinationView.frame = transitionContext.destinationViewFinalFrame! transitionContext.destinationView.frame = transitionContext.destinationViewFinalFrame!
transitionContext.containerView.addSubview(transitionContext.destinationView) transitionContext.containerView.addSubview(transitionContext.destinationView)
transitionContext.completeTransition(true) transitionContext.completeTransition(true)
transitionContext.sourceViewController.endAppearanceTransition()
} }
func animateDismissalTransition(using transitionContext: UIViewControllerContextTransitioning) func animateDismissalTransition(using transitionContext: UIViewControllerContextTransitioning)
{ {
transitionContext.destinationViewController.beginAppearanceTransition(true, animated: true)
transitionContext.destinationView.transform = CGAffineTransform(scaleX: 0.5, y: 0.5) transitionContext.destinationView.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)
transitionContext.destinationView.alpha = 0.0 transitionContext.destinationView.alpha = 0.0
@ -89,6 +95,7 @@ extension InitialGamesStoryboardSegue: UIViewControllerAnimatedTransitioning
self.animator.addCompletion { (position) in self.animator.addCompletion { (position) in
transitionContext.completeTransition(position == .end) transitionContext.completeTransition(position == .end)
transitionContext.destinationViewController.endAppearanceTransition()
} }
self.animator.startAnimation() self.animator.startAnimation()