From bb418038e2654953d7225e4c7ec3eee18f8579d5 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Wed, 29 Nov 2017 01:41:05 -0800 Subject: [PATCH 1/3] Fixes misc. iPhone X layout issues --- Cores/DeltaCore | 2 +- .../GridCollectionViewLayout.swift | 58 ++++++++++++++----- Delta/Launch/LaunchViewController.swift | 4 ++ .../PausePresentationController.swift | 7 ++- .../SaveStatesViewController.swift | 2 +- 5 files changed, 56 insertions(+), 17 deletions(-) diff --git a/Cores/DeltaCore b/Cores/DeltaCore index d721326..dd292d6 160000 --- a/Cores/DeltaCore +++ b/Cores/DeltaCore @@ -1 +1 @@ -Subproject commit d7213260852683ea5a3f6c2274733bbd65d2ec92 +Subproject commit dd292d6ceaa1c0543e3dd0453251379287a923a7 diff --git a/Delta/Components/Collection View/GridCollectionViewLayout.swift b/Delta/Components/Collection View/GridCollectionViewLayout.swift index bc4fbba..e87a1c4 100644 --- a/Delta/Components/Collection View/GridCollectionViewLayout.swift +++ b/Delta/Components/Collection View/GridCollectionViewLayout.swift @@ -23,22 +23,52 @@ class GridCollectionViewLayout: UICollectionViewFlowLayout // If only one row, distribute the items equally horizontally var usesEqualHorizontalSpacingDistributionForSingleRow = false + private var contentInset: UIEdgeInsets { + guard let collectionView = self.collectionView else { return .zero } + + var contentInset = collectionView.contentInset + if #available(iOS 11, *) + { + contentInset.left += collectionView.safeAreaInsets.left + contentInset.right += collectionView.safeAreaInsets.right + } + + return contentInset + } + + private var contentWidth: CGFloat { + guard let collectionView = self.collectionView else { return 0.0 } + + let contentWidth = collectionView.bounds.width - (self.contentInset.left + self.contentInset.right) + return contentWidth + } + + private var maximumItemsPerRow: Int { + let maximumItemsPerRow = Int(floor((self.contentWidth - self.minimumInteritemSpacing) / (self.itemWidth + self.minimumInteritemSpacing))) + return maximumItemsPerRow + } + + private var interitemSpacing: CGFloat { + let interitemSpacing = (self.contentWidth - CGFloat(self.maximumItemsPerRow) * self.itemWidth) / CGFloat(self.maximumItemsPerRow + 1) + return interitemSpacing + } + override var estimatedItemSize: CGSize { didSet { fatalError("GridCollectionViewLayout does not support self-sizing cells.") } } + override func prepare() + { + super.prepare() + + self.sectionInset.left = self.interitemSpacing + self.contentInset.left + self.sectionInset.right = self.interitemSpacing + self.contentInset.right + } + override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { - guard let collectionView = self.collectionView else { return nil } - - let maximumItemsPerRow = floor((collectionView.bounds.width - self.minimumInteritemSpacing) / (self.itemWidth + self.minimumInteritemSpacing)) - let interitemSpacing = (collectionView.bounds.width - maximumItemsPerRow * self.itemWidth) / (maximumItemsPerRow + 1) - - self.sectionInset.left = interitemSpacing - self.sectionInset.right = interitemSpacing - let layoutAttributes = super.layoutAttributesForElements(in: rect)?.map({ $0.copy() }) as! [UICollectionViewLayoutAttributes] var minimumY: CGFloat? = nil @@ -58,7 +88,7 @@ class GridCollectionViewLayout: UICollectionViewFlowLayout if abs(attributes.frame.minX - self.sectionInset.left) > 1 { - attributes.frame.origin.x = previousLayoutAttributes.frame.maxX + interitemSpacing + attributes.frame.origin.x = previousLayoutAttributes.frame.maxX + self.interitemSpacing } } @@ -70,7 +100,7 @@ class GridCollectionViewLayout: UICollectionViewFlowLayout { isSingleRow = false - self.alignLayoutAttributes(tempLayoutAttributes, toMinimumY: minY) + self.align(tempLayoutAttributes, toMinimumY: minY) // Reset tempLayoutAttributes tempLayoutAttributes.removeAll() @@ -97,15 +127,15 @@ class GridCollectionViewLayout: UICollectionViewFlowLayout // Handle the remaining tempLayoutAttributes if let minimumY = minimumY { - self.alignLayoutAttributes(tempLayoutAttributes, toMinimumY: minimumY) + self.align(tempLayoutAttributes, toMinimumY: minimumY) if isSingleRow && self.usesEqualHorizontalSpacingDistributionForSingleRow { - let spacing = (collectionView.bounds.width - (self.itemWidth * CGFloat(tempLayoutAttributes.count))) / (CGFloat(tempLayoutAttributes.count) + 1.0) + let spacing = (self.contentWidth - (self.itemWidth * CGFloat(tempLayoutAttributes.count))) / (CGFloat(tempLayoutAttributes.count) + 1.0) for (index, layoutAttributes) in tempLayoutAttributes.enumerated() { - layoutAttributes.frame.origin.x = spacing + (spacing + self.itemWidth) * CGFloat(index) + layoutAttributes.frame.origin.x = spacing + (spacing + self.itemWidth) * CGFloat(index) + self.contentInset.left } } } @@ -117,7 +147,7 @@ class GridCollectionViewLayout: UICollectionViewFlowLayout private extension GridCollectionViewLayout { - func alignLayoutAttributes(_ layoutAttributes: [UICollectionViewLayoutAttributes], toMinimumY minimumY: CGFloat) + func align(_ layoutAttributes: [UICollectionViewLayoutAttributes], toMinimumY minimumY: CGFloat) { for attributes in layoutAttributes { diff --git a/Delta/Launch/LaunchViewController.swift b/Delta/Launch/LaunchViewController.swift index c2d0be5..3b38c96 100644 --- a/Delta/Launch/LaunchViewController.swift +++ b/Delta/Launch/LaunchViewController.swift @@ -23,6 +23,10 @@ class LaunchViewController: UIViewController return self.gameViewController?.prefersStatusBarHidden ?? false } + override func childViewControllerForHomeIndicatorAutoHidden() -> UIViewController? { + return self.gameViewController + } + override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) diff --git a/Delta/Pause Menu/Presentation Controller/PausePresentationController.swift b/Delta/Pause Menu/Presentation Controller/PausePresentationController.swift index c0fb79b..2bcea39 100644 --- a/Delta/Pause Menu/Presentation Controller/PausePresentationController.swift +++ b/Delta/Pause Menu/Presentation Controller/PausePresentationController.swift @@ -33,7 +33,7 @@ class PausePresentationController: UIPresentationController { guard let containerView = self.containerView else { return super.frameOfPresentedViewInContainerView } - let frame: CGRect + var frame: CGRect let contentHeight = self.presentedViewController.preferredContentSize.height if contentHeight == 0 @@ -44,6 +44,11 @@ class PausePresentationController: UIPresentationController else { frame = CGRect(x: 0, y: containerView.bounds.height - contentHeight, width: containerView.bounds.width, height: containerView.bounds.height) + + if #available(iOS 11.0, *) + { + frame.origin.y -= containerView.safeAreaInsets.bottom + } } return frame diff --git a/Delta/Pause Menu/Save States/SaveStatesViewController.swift b/Delta/Pause Menu/Save States/SaveStatesViewController.swift index 019be65..75ad69d 100644 --- a/Delta/Pause Menu/Save States/SaveStatesViewController.swift +++ b/Delta/Pause Menu/Save States/SaveStatesViewController.swift @@ -101,7 +101,7 @@ extension SaveStatesViewController // Use dimensions that allow two cells to fill the screen horizontally with padding in portrait mode // We'll keep the same size for landscape orientation, which will allow more to fit - collectionViewLayout.itemWidth = (portraitScreenWidth - (averageHorizontalInset * 3)) / 2 + collectionViewLayout.itemWidth = floor((portraitScreenWidth - (averageHorizontalInset * 3)) / 2) switch self.mode { From 6836fb5bae8d37ed5f46196a3a2ccc9ef63f7296 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Mon, 18 Dec 2017 18:14:28 -0600 Subject: [PATCH 2/3] Moves core ControllerSkin translucency logic to ControllerView --- Cores/DeltaCore | 2 +- Delta/Emulation/GameViewController.swift | 20 +++----------------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/Cores/DeltaCore b/Cores/DeltaCore index dd292d6..0102a81 160000 --- a/Cores/DeltaCore +++ b/Cores/DeltaCore @@ -1 +1 @@ -Subproject commit dd292d6ceaa1c0543e3dd0453251379287a923a7 +Subproject commit 0102a815adf25da3841d4273c044cbb59261709b diff --git a/Delta/Emulation/GameViewController.swift b/Delta/Emulation/GameViewController.swift index d8f1133..7733a61 100644 --- a/Delta/Emulation/GameViewController.swift +++ b/Delta/Emulation/GameViewController.swift @@ -192,6 +192,8 @@ extension GameViewController let gameViewContainerView = self.gameView.superview! + self.controllerView.translucentControllerSkinOpacity = Settings.translucentControllerSkinOpacity + self.sustainButtonsContentView = UIView(frame: CGRect(x: 0, y: 0, width: self.gameView.bounds.width, height: self.gameView.bounds.height)) self.sustainButtonsContentView.translatesAutoresizingMaskIntoConstraints = false self.sustainButtonsContentView.isHidden = true @@ -444,15 +446,6 @@ private extension GameViewController let controllerSkin = Settings.preferredControllerSkin(for: system, traits: traits) self.controllerView.controllerSkin = controllerSkin - - if controllerSkin?.isTranslucent(for: traits) ?? false - { - self.controllerView.alpha = Settings.translucentControllerSkinOpacity - } - else - { - self.controllerView.alpha = 1.0 - } } } @@ -860,14 +853,7 @@ private extension GameViewController self.updateControllerSkin() } - case .translucentControllerSkinOpacity: - if let traits = self.controllerView.controllerSkinTraits - { - if self.controllerView.controllerSkin?.isTranslucent(for: traits) ?? false - { - self.controllerView.alpha = Settings.translucentControllerSkinOpacity - } - } + case .translucentControllerSkinOpacity: self.controllerView.translucentControllerSkinOpacity = Settings.translucentControllerSkinOpacity } } } From 18d6bd262aec2637b02d74631f2d76bc78c9b69b Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Mon, 18 Dec 2017 19:36:56 -0600 Subject: [PATCH 3/3] Adds support for iPhone X-optimized controller skins --- Cores/DeltaCore | 2 +- Cores/GBADeltaCore | 2 +- Cores/GBCDeltaCore | 2 +- Cores/SNESDeltaCore | 2 +- Delta/Base.lproj/Settings.storyboard | 10 ++-- .../LoadControllerSkinImageOperation.swift | 4 +- .../Database/Model/Human/ControllerSkin.swift | 37 +++--------- .../Model/Misc/ControllerSkinConfigurations.h | 7 ++- Delta/Emulation/GameViewController.swift | 9 ++- .../ControllerSkin+Configuring.swift | 56 ++++--------------- .../ControllerSkinsViewController.swift | 25 +++++++-- .../SystemControllerSkinsViewController.swift | 39 +++++++++---- Delta/Settings/Settings.swift | 11 ++-- 13 files changed, 91 insertions(+), 115 deletions(-) diff --git a/Cores/DeltaCore b/Cores/DeltaCore index 0102a81..6658b7a 160000 --- a/Cores/DeltaCore +++ b/Cores/DeltaCore @@ -1 +1 @@ -Subproject commit 0102a815adf25da3841d4273c044cbb59261709b +Subproject commit 6658b7a7557278c9b846466a0599462c1aeb870b diff --git a/Cores/GBADeltaCore b/Cores/GBADeltaCore index 7babfcf..54d064d 160000 --- a/Cores/GBADeltaCore +++ b/Cores/GBADeltaCore @@ -1 +1 @@ -Subproject commit 7babfcf93a32916ad06989c9a63681acf7f07d50 +Subproject commit 54d064d34a4d856fd34a49308f42f1aefac8eaad diff --git a/Cores/GBCDeltaCore b/Cores/GBCDeltaCore index 9d71425..9c295a2 160000 --- a/Cores/GBCDeltaCore +++ b/Cores/GBCDeltaCore @@ -1 +1 @@ -Subproject commit 9d714254ace7bd5d63805d434f4ccd1f2a947951 +Subproject commit 9c295a2a287821544fec4b29d2b3f1205f965275 diff --git a/Cores/SNESDeltaCore b/Cores/SNESDeltaCore index a354c37..a3f0547 160000 --- a/Cores/SNESDeltaCore +++ b/Cores/SNESDeltaCore @@ -1 +1 @@ -Subproject commit a354c3700fc4576bbefb6a8324bcd7a121d9b934 +Subproject commit a3f0547bc57c14b548105020136a9ead56f73470 diff --git a/Delta/Base.lproj/Settings.storyboard b/Delta/Base.lproj/Settings.storyboard index ebcf37a..f62b0bb 100644 --- a/Delta/Base.lproj/Settings.storyboard +++ b/Delta/Base.lproj/Settings.storyboard @@ -1,11 +1,11 @@ - + - + @@ -193,7 +193,7 @@ -