Adds mode property to SaveStatesViewController to switch between saving and loading save states

This commit is contained in:
Riley Testut 2016-03-14 16:02:02 -05:00
parent ee1e57f54b
commit e08cc1c331
3 changed files with 29 additions and 4 deletions

View File

@ -154,11 +154,11 @@ class EmulationViewController: UIViewController
// As a dirty workaround, we just use a weak reference, and force unwrap it if needed
let saveStateItem = PauseItem(image: UIImage(named: "SmallPause")!, text: NSLocalizedString("Save State", comment: ""), action: { [weak self] _ in
pauseViewController.presentSaveStateViewController(delegate: self!)
pauseViewController.presentSaveStateViewControllerWithMode(.Saving, delegate: self!)
})
let loadStateItem = PauseItem(image: UIImage(named: "SmallPause")!, text: NSLocalizedString("Load State", comment: ""), action: { [weak self] _ in
pauseViewController.presentSaveStateViewController(delegate: self!)
pauseViewController.presentSaveStateViewControllerWithMode(.Loading, delegate: self!)
})
let cheatCodesItem = PauseItem(image: UIImage(named: "SmallPause")!, text: NSLocalizedString("Cheat Codes", comment: ""), action: dismissAction)

View File

@ -17,6 +17,7 @@ class PauseViewController: UIViewController, PauseInfoProvidable
var pauseText: String? = nil
private weak var saveStatesViewControllerDelegate: SaveStatesViewControllerDelegate?
private var saveStatesViewControllerMode = SaveStatesViewController.Mode.Saving
/// UIViewController
override var preferredContentSize: CGSize {
@ -88,6 +89,7 @@ extension PauseViewController
case "saveState":
let saveStatesViewController = segue.destinationViewController as! SaveStatesViewController
saveStatesViewController.delegate = self.saveStatesViewControllerDelegate
saveStatesViewController.mode = self.saveStatesViewControllerMode
default: break
}
@ -101,8 +103,9 @@ extension PauseViewController
self.performSegueWithIdentifier("unwindFromPauseMenu", sender: self)
}
func presentSaveStateViewController(delegate delegate: SaveStatesViewControllerDelegate)
func presentSaveStateViewControllerWithMode(mode: SaveStatesViewController.Mode, delegate: SaveStatesViewControllerDelegate)
{
self.saveStatesViewControllerMode = mode
self.saveStatesViewControllerDelegate = delegate
self.performSegueWithIdentifier("saveState", sender: self)

View File

@ -19,6 +19,15 @@ protocol SaveStatesViewControllerDelegate: class
func saveStatesViewController(saveStatesViewController: SaveStatesViewController, loadSaveState saveState: SaveState)
}
extension SaveStatesViewController
{
enum Mode
{
case Saving
case Loading
}
}
class SaveStatesViewController: UICollectionViewController
{
weak var delegate: SaveStatesViewControllerDelegate! {
@ -27,6 +36,8 @@ class SaveStatesViewController: UICollectionViewController
}
}
var mode = Mode.Saving
private var backgroundView: RSTBackgroundView!
private var prototypeCell = GridCollectionViewCell()
@ -60,7 +71,6 @@ extension SaveStatesViewController
self.backgroundView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
self.backgroundView.textLabel.text = NSLocalizedString("No Save States", comment: "")
self.backgroundView.textLabel.textColor = UIColor.whiteColor()
self.backgroundView.detailTextLabel.text = NSLocalizedString("You can create a new save state by pressing the + button in the top right.", comment: "")
self.backgroundView.detailTextLabel.textColor = UIColor.whiteColor()
self.view.insertSubview(self.backgroundView, atIndex: 0)
@ -72,6 +82,18 @@ extension SaveStatesViewController
// We'll keep the same size for landscape orientation, which will allow more to fit
collectionViewLayout.itemWidth = (portraitScreenWidth - (averageHorizontalInset * 3)) / 2
switch self.mode
{
case .Saving:
self.title = NSLocalizedString("Save State", comment: "")
self.backgroundView.detailTextLabel.text = NSLocalizedString("You can create a new save state by pressing the + button in the top right.", comment: "")
case .Loading:
self.title = NSLocalizedString("Load State", comment: "")
self.backgroundView.detailTextLabel.text = NSLocalizedString("You can create a new save state by pressing the Save State option in the pause menu.", comment: "")
self.navigationItem.rightBarButtonItem = nil
}
// Manually update prototype cell properties
self.prototypeCellWidthConstraint = self.prototypeCell.contentView.widthAnchor.constraintEqualToConstant(collectionViewLayout.itemWidth)
self.prototypeCellWidthConstraint.active = true