Added stub implementations for provided PauseItems

This commit is contained in:
Riley Testut 2015-12-27 00:48:47 -06:00
parent 46eb747737
commit 0aba8b27d3
7 changed files with 115 additions and 9 deletions

View File

@ -256,7 +256,7 @@
</barButtonItem> </barButtonItem>
<barButtonItem key="rightBarButtonItem" title="Resume" style="done" id="ye0-Nk-K1X"> <barButtonItem key="rightBarButtonItem" title="Resume" style="done" id="ye0-Nk-K1X">
<connections> <connections>
<segue destination="mTB-5a-Mdf" kind="unwind" unwindAction="unwindFromPauseViewController:" id="OIW-2I-L70"/> <segue destination="mTB-5a-Mdf" kind="unwind" identifier="unwindPauseSegue" unwindAction="unwindFromPauseViewController:" id="OIW-2I-L70"/>
</connections> </connections>
</barButtonItem> </barButtonItem>
</navigationItem> </navigationItem>

View File

@ -143,6 +143,18 @@ class EmulationViewController: UIViewController
if let destinationViewController = segue.destinationViewController as? UINavigationController, pauseViewController = destinationViewController.topViewController as? PauseViewController if let destinationViewController = segue.destinationViewController as? UINavigationController, pauseViewController = destinationViewController.topViewController as? PauseViewController
{ {
pauseViewController.pauseText = self.game.name pauseViewController.pauseText = self.game.name
let dismissAction: (PauseItem -> Void) = { item in
pauseViewController.dismiss()
}
let saveStateItem = PauseItem(image: UIImage(named: "SmallPause")!, text: "Save State", action: dismissAction)
let loadStateItem = PauseItem(image: UIImage(named: "SmallPause")!, text: "Load State", action: dismissAction)
let cheatCodesItem = PauseItem(image: UIImage(named: "SmallPause")!, text: "Cheat Codes", action: dismissAction)
let fastForwardItem = PauseItem(image: UIImage(named: "SmallPause")!, text: "Fast Forward", action: dismissAction)
let sustainButtonItem = PauseItem(image: UIImage(named: "SmallPause")!, text: "Sustain Button", action: dismissAction)
pauseViewController.items = [saveStateItem, loadStateItem, cheatCodesItem, fastForwardItem, sustainButtonItem]
} }
self._isPauseViewControllerPresented = true self._isPauseViewControllerPresented = true

View File

@ -8,17 +8,33 @@
import UIKit import UIKit
struct PauseItem struct PauseItem: Equatable
{ {
let image: UIImage let image: UIImage
let text: String let text: String
let action: (PauseItem -> Void) let action: (PauseItem -> Void)
var selected = false
init(image: UIImage, text: String, action: (PauseItem -> Void))
{
self.image = image
self.text = text
self.action = action
}
}
func ==(lhs: PauseItem, rhs: PauseItem) -> Bool
{
return (lhs.image == rhs.image) && (lhs.text == rhs.text)
} }
class PauseViewController: UIViewController, PauseInfoProvidable class PauseViewController: UIViewController, PauseInfoProvidable
{ {
var items = [PauseItem]() { var items = [PauseItem]() {
didSet { didSet
{
guard oldValue != self.items else { return }
if self.items.count > 8 if self.items.count > 8
{ {
@ -61,9 +77,14 @@ class PauseViewController: UIViewController, PauseInfoProvidable
// Manually update prototype cell properties // Manually update prototype cell properties
self.prototypeCell.contentView.widthAnchor.constraintEqualToConstant(self.collectionViewLayout.itemWidth).active = true self.prototypeCell.contentView.widthAnchor.constraintEqualToConstant(self.collectionViewLayout.itemWidth).active = true
}
}
let pauseItem = PauseItem(image: UIImage(named: "Pause")!, text: "Resume", action: { _ in }) internal extension PauseViewController
self.items = [pauseItem, pauseItem, pauseItem, pauseItem, pauseItem, pauseItem] {
func dismiss()
{
self.performSegueWithIdentifier("unwindPauseSegue", sender: self)
} }
} }
@ -71,20 +92,43 @@ private extension PauseViewController
{ {
func configureCollectionViewCell(cell: GridCollectionViewCell, forIndexPath indexPath: NSIndexPath) func configureCollectionViewCell(cell: GridCollectionViewCell, forIndexPath indexPath: NSIndexPath)
{ {
let array = ["Save State", "Load State", "Cheat Codes", "Fast Forward", "Sustain Button", "Event Distribution"] let pauseItem = self.items[indexPath.item]
cell.maximumImageSize = CGSize(width: 60, height: 60) cell.maximumImageSize = CGSize(width: 60, height: 60)
cell.imageView.image = pauseItem.image
cell.imageView.contentMode = .Center
cell.imageView.layer.borderWidth = 2 cell.imageView.layer.borderWidth = 2
cell.imageView.layer.borderColor = UIColor.whiteColor().CGColor cell.imageView.layer.borderColor = UIColor.whiteColor().CGColor
cell.imageView.layer.cornerRadius = 10 cell.imageView.layer.cornerRadius = 10
cell.textLabel.text = array[indexPath.item] cell.textLabel.text = pauseItem.text
cell.textLabel.textColor = UIColor.whiteColor() cell.textLabel.textColor = UIColor.whiteColor()
if pauseItem.selected
{
cell.imageView.tintColor = UIColor.blackColor()
cell.imageView.backgroundColor = UIColor.whiteColor()
}
else
{
cell.imageView.tintColor = UIColor.whiteColor()
cell.imageView.backgroundColor = UIColor.clearColor()
}
}
func toggleSelectedStateForPauseItemAtIndexPath(indexPath: NSIndexPath)
{
var pauseItem = self.items[indexPath.item]
pauseItem.selected = !pauseItem.selected
self.items[indexPath.item] = pauseItem
let cell = self.collectionView.cellForItemAtIndexPath(indexPath) as! GridCollectionViewCell
self.configureCollectionViewCell(cell, forIndexPath: indexPath)
} }
} }
extension PauseViewController: UICollectionViewDataSource, UICollectionViewDelegateFlowLayout extension PauseViewController: UICollectionViewDataSource
{ {
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{ {
@ -97,7 +141,10 @@ extension PauseViewController: UICollectionViewDataSource, UICollectionViewDeleg
self.configureCollectionViewCell(cell, forIndexPath: indexPath) self.configureCollectionViewCell(cell, forIndexPath: indexPath)
return cell return cell
} }
}
extension PauseViewController: UICollectionViewDelegateFlowLayout
{
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize
{ {
self.configureCollectionViewCell(self.prototypeCell, forIndexPath: indexPath) self.configureCollectionViewCell(self.prototypeCell, forIndexPath: indexPath)
@ -107,3 +154,24 @@ extension PauseViewController: UICollectionViewDataSource, UICollectionViewDeleg
} }
} }
extension PauseViewController: UICollectionViewDelegate
{
func collectionView(collectionView: UICollectionView, didHighlightItemAtIndexPath indexPath: NSIndexPath)
{
self.toggleSelectedStateForPauseItemAtIndexPath(indexPath)
}
func collectionView(collectionView: UICollectionView, didUnhighlightItemAtIndexPath indexPath: NSIndexPath)
{
self.toggleSelectedStateForPauseItemAtIndexPath(indexPath)
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
{
self.toggleSelectedStateForPauseItemAtIndexPath(indexPath)
let pauseItem = self.items[indexPath.item]
pauseItem.action(pauseItem)
}
}

View File

@ -0,0 +1,26 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "SmallPause.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "SmallPause@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "SmallPause@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 687 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 778 B