diff --git a/Common/Collection View/GridCollectionViewCell.swift b/Common/Collection View/GridCollectionViewCell.swift index 8906bd3..eb8a6eb 100644 --- a/Common/Collection View/GridCollectionViewCell.swift +++ b/Common/Collection View/GridCollectionViewCell.swift @@ -50,6 +50,7 @@ class GridCollectionViewCell: UICollectionViewCell self.contentView.clipsToBounds = false self.imageView.translatesAutoresizingMaskIntoConstraints = false + self.imageView.contentMode = .ScaleAspectFit #if os(tvOS) self.imageView.adjustsImageWhenAncestorFocused = true #endif @@ -135,7 +136,7 @@ private extension GridCollectionViewCell self.imageViewWidthConstraint.constant = self.maximumImageSize.width self.imageViewHeightConstraint.constant = self.maximumImageSize.height - self.textLabelVerticalSpacingConstraint.constant = self.maximumImageSize.height / 10.0 + self.textLabelVerticalSpacingConstraint.constant = 8 self.textLabelFocusedVerticalSpacingConstraint?.constant = self.maximumImageSize.height / 10.0 } } \ No newline at end of file diff --git a/Common/Collection View/GridCollectionViewLayout.swift b/Common/Collection View/GridCollectionViewLayout.swift index 0467743..048ee1e 100644 --- a/Common/Collection View/GridCollectionViewLayout.swift +++ b/Common/Collection View/GridCollectionViewLayout.swift @@ -12,7 +12,11 @@ class GridCollectionViewLayout: UICollectionViewFlowLayout { var itemWidth: CGFloat = 150 { didSet { - self.invalidateLayout() + // Only invalidate if needed, otherwise could potentially cause endless loop + if oldValue != self.itemWidth + { + self.invalidateLayout() + } } } diff --git a/Delta/Pause Menu/Presentation Controller/PausePresentationController.swift b/Delta/Pause Menu/Presentation Controller/PausePresentationController.swift index 19764da..20bf6f7 100644 --- a/Delta/Pause Menu/Presentation Controller/PausePresentationController.swift +++ b/Delta/Pause Menu/Presentation Controller/PausePresentationController.swift @@ -39,13 +39,19 @@ class PausePresentationController: UIPresentationController { guard let containerView = self.containerView else { return super.frameOfPresentedViewInContainerView() } - var contentHeight = self.presentedViewController.preferredContentSize.height + let frame: CGRect + let contentHeight = self.presentedViewController.preferredContentSize.height + if contentHeight == 0 { - contentHeight = containerView.bounds.height - UIApplication.sharedApplication().statusBarFrame.height + let statusBarHeight = UIApplication.sharedApplication().statusBarFrame.height + frame = CGRect(x: 0, y: statusBarHeight, width: containerView.bounds.width, height: containerView.bounds.height - statusBarHeight) + } + else + { + frame = CGRect(x: 0, y: containerView.bounds.height - contentHeight, width: containerView.bounds.width, height: containerView.bounds.height) } - let frame = CGRect(x: 0, y: containerView.bounds.height - contentHeight, width: containerView.bounds.width, height: containerView.bounds.height) return frame } diff --git a/Delta/Pause Menu/Save States/SaveStatesViewController.swift b/Delta/Pause Menu/Save States/SaveStatesViewController.swift index da7ab84..8065915 100644 --- a/Delta/Pause Menu/Save States/SaveStatesViewController.swift +++ b/Delta/Pause Menu/Save States/SaveStatesViewController.swift @@ -10,25 +10,90 @@ import UIKit import Roxas +private let SaveStatesViewControllerContentInset: CGFloat = 20 + class SaveStatesViewController: UICollectionViewController { private var backgroundView: RSTBackgroundView! + private var prototypeCell = GridCollectionViewCell() + private var prototypeCellWidthConstraint: NSLayoutConstraint! +} + +extension SaveStatesViewController +{ override func viewDidLoad() { super.viewDidLoad() self.backgroundView = RSTBackgroundView(frame: self.view.bounds) + self.backgroundView.hidden = true 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) + + // We update the layout in code because we need to use our SaveStatesViewControllerContentInset constant + // The reason for this is we cannot query the layout for its sectionInset in viewDidLayoutSubviews, so might as well be explicit in code with a constant + // Otherwise, we could configure this all in Interface Builder, but we'd still need to hardcode 20 in for viewDidLayoutSubviews + let collectionViewLayout = self.collectionViewLayout as! GridCollectionViewLayout + collectionViewLayout.sectionInset = UIEdgeInsets(top: SaveStatesViewControllerContentInset, left: SaveStatesViewControllerContentInset, bottom: SaveStatesViewControllerContentInset, right: SaveStatesViewControllerContentInset) + collectionViewLayout.minimumInteritemSpacing = SaveStatesViewControllerContentInset + collectionViewLayout.minimumLineSpacing = SaveStatesViewControllerContentInset + + let portraitScreenWidth = UIScreen.mainScreen().coordinateSpace.convertRect(UIScreen.mainScreen().bounds, toCoordinateSpace: UIScreen.mainScreen().fixedCoordinateSpace).width + collectionViewLayout.itemWidth = (portraitScreenWidth - ((SaveStatesViewControllerContentInset) * 3)) / 2 + + // Manually update prototype cell properties + self.prototypeCellWidthConstraint = self.prototypeCell.contentView.widthAnchor.constraintEqualToConstant(collectionViewLayout.itemWidth) + self.prototypeCellWidthConstraint.active = true } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } +} + +private extension SaveStatesViewController +{ + func configureCollectionViewCell(cell: GridCollectionViewCell, forIndexPath indexPath: NSIndexPath) + { + cell.imageView.backgroundColor = UIColor.whiteColor() + cell.imageView.image = UIImage(named: "DeltaPlaceholder") + + cell.maximumImageSize = CGSizeMake(self.prototypeCellWidthConstraint.constant, (self.prototypeCellWidthConstraint.constant / 4.0) * 3.0) + + cell.textLabel.textColor = UIColor.whiteColor() + cell.textLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleSubheadline) + cell.textLabel.text = "Save State" + } +} + +extension SaveStatesViewController +{ + override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int + { + return 12 + } + + override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell + { + let cell = collectionView.dequeueReusableCellWithReuseIdentifier(RSTGenericCellIdentifier, forIndexPath: indexPath) as! GridCollectionViewCell + self.configureCollectionViewCell(cell, forIndexPath: indexPath) + return cell + } +} + +extension SaveStatesViewController: UICollectionViewDelegateFlowLayout +{ + func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize + { + self.configureCollectionViewCell(self.prototypeCell, forIndexPath: indexPath) + + let size = self.prototypeCell.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize) + return size + } } \ No newline at end of file diff --git a/Resources/Assets.xcassets/DeltaPlaceholder.imageset/Contents.json b/Resources/Assets.xcassets/DeltaPlaceholder.imageset/Contents.json new file mode 100644 index 0000000..8755372 --- /dev/null +++ b/Resources/Assets.xcassets/DeltaPlaceholder.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "DeltaPlaceholder.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "DeltaPlaceholder@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "DeltaPlaceholder@3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Resources/Assets.xcassets/DeltaPlaceholder.imageset/DeltaPlaceholder.png b/Resources/Assets.xcassets/DeltaPlaceholder.imageset/DeltaPlaceholder.png new file mode 100644 index 0000000..ff6a2a0 Binary files /dev/null and b/Resources/Assets.xcassets/DeltaPlaceholder.imageset/DeltaPlaceholder.png differ diff --git a/Resources/Assets.xcassets/DeltaPlaceholder.imageset/DeltaPlaceholder@2x.png b/Resources/Assets.xcassets/DeltaPlaceholder.imageset/DeltaPlaceholder@2x.png new file mode 100644 index 0000000..4cce81d Binary files /dev/null and b/Resources/Assets.xcassets/DeltaPlaceholder.imageset/DeltaPlaceholder@2x.png differ diff --git a/Resources/Assets.xcassets/DeltaPlaceholder.imageset/DeltaPlaceholder@3x.png b/Resources/Assets.xcassets/DeltaPlaceholder.imageset/DeltaPlaceholder@3x.png new file mode 100644 index 0000000..3ccc7a8 Binary files /dev/null and b/Resources/Assets.xcassets/DeltaPlaceholder.imageset/DeltaPlaceholder@3x.png differ