Adds button to change save states sort order
This commit is contained in:
parent
bcfbb7d7a0
commit
63a8dfd5b9
@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14868" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Dt0-nV-isV">
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15400" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Dt0-nV-isV">
|
||||
<device id="retina4_7" orientation="portrait" appearance="light"/>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14824"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15404"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
@ -160,13 +160,28 @@
|
||||
</connections>
|
||||
</collectionView>
|
||||
<navigationItem key="navigationItem" title="Save State" id="BoG-k2-aR2">
|
||||
<barButtonItem key="rightBarButtonItem" systemItem="add" id="lKg-Ks-hWN">
|
||||
<connections>
|
||||
<action selector="addSaveState" destination="OOk-k7-INg" id="xY2-94-EOr"/>
|
||||
</connections>
|
||||
</barButtonItem>
|
||||
<rightBarButtonItems>
|
||||
<barButtonItem systemItem="add" id="lKg-Ks-hWN">
|
||||
<connections>
|
||||
<action selector="addSaveState" destination="OOk-k7-INg" id="xY2-94-EOr"/>
|
||||
</connections>
|
||||
</barButtonItem>
|
||||
<barButtonItem style="plain" id="has-I3-HDZ">
|
||||
<button key="customView" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="y2a-9f-EFz">
|
||||
<rect key="frame" x="288.5" y="13" width="30" height="30"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<state key="normal" title="▼"/>
|
||||
<connections>
|
||||
<action selector="changeSortOrder:" destination="OOk-k7-INg" eventType="primaryActionTriggered" id="qQn-uw-SN1"/>
|
||||
</connections>
|
||||
</button>
|
||||
</barButtonItem>
|
||||
</rightBarButtonItems>
|
||||
</navigationItem>
|
||||
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" barStyle="black" prompted="NO"/>
|
||||
<connections>
|
||||
<outlet property="sortButton" destination="y2a-9f-EFz" id="Zbo-Q0-bVL"/>
|
||||
</connections>
|
||||
</collectionViewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="cL5-DH-K3b" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
|
||||
@ -24,7 +24,7 @@ class SaveStatesStoryboardSegue: UIStoryboardSegue
|
||||
saveStatesViewController.loadViewIfNeeded()
|
||||
|
||||
let doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(SaveStatesStoryboardSegue.handleDoneButton))
|
||||
saveStatesViewController.navigationItem.rightBarButtonItem = doneButton
|
||||
saveStatesViewController.navigationItem.leftBarButtonItem = doneButton
|
||||
|
||||
guard saveStatesViewController.theme == .translucent else { return }
|
||||
|
||||
|
||||
@ -54,7 +54,7 @@ class SaveStatesViewController: UICollectionViewController
|
||||
didSet {
|
||||
if self.isViewLoaded
|
||||
{
|
||||
self.updateTheme()
|
||||
self.update()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -70,6 +70,8 @@ class SaveStatesViewController: UICollectionViewController
|
||||
|
||||
private var emulatorCoreSaveState: SaveStateProtocol?
|
||||
|
||||
@IBOutlet private var sortButton: UIButton!
|
||||
|
||||
required init?(coder aDecoder: NSCoder)
|
||||
{
|
||||
self.dataSource = RSTFetchedResultsCollectionViewPrefetchingDataSource<SaveState, UIImage>(fetchedResultsController: NSFetchedResultsController())
|
||||
@ -106,7 +108,7 @@ extension SaveStatesViewController
|
||||
case .loading:
|
||||
self.title = NSLocalizedString("Load State", comment: "")
|
||||
self.placeholderView.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
|
||||
self.navigationItem.rightBarButtonItems?.removeFirst()
|
||||
}
|
||||
|
||||
// Manually update prototype cell properties
|
||||
@ -123,7 +125,7 @@ extension SaveStatesViewController
|
||||
self.navigationController?.navigationBar.barStyle = .blackTranslucent
|
||||
self.navigationController?.toolbar.barStyle = .blackTranslucent
|
||||
|
||||
self.updateTheme()
|
||||
self.update()
|
||||
}
|
||||
|
||||
override func viewWillDisappear(_ animated: Bool)
|
||||
@ -195,12 +197,12 @@ private extension SaveStatesViewController
|
||||
let fetchRequest: NSFetchRequest<SaveState> = SaveState.fetchRequest()
|
||||
fetchRequest.returnsObjectsAsFaults = false
|
||||
fetchRequest.predicate = NSPredicate(format: "%K == %@", #keyPath(SaveState.game), self.game)
|
||||
fetchRequest.sortDescriptors = [NSSortDescriptor(key: #keyPath(SaveState.type), ascending: true), NSSortDescriptor(key: #keyPath(SaveState.creationDate), ascending: true)]
|
||||
fetchRequest.sortDescriptors = [NSSortDescriptor(key: #keyPath(SaveState.type), ascending: true), NSSortDescriptor(key: #keyPath(SaveState.creationDate), ascending: Settings.sortSaveStatesByOldestFirst)]
|
||||
|
||||
self.dataSource.fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: DatabaseManager.shared.viewContext, sectionNameKeyPath: #keyPath(SaveState.type), cacheName: nil)
|
||||
}
|
||||
|
||||
func updateTheme()
|
||||
func update()
|
||||
{
|
||||
switch self.theme
|
||||
{
|
||||
@ -220,6 +222,8 @@ private extension SaveStatesViewController
|
||||
self.placeholderView.textLabel.textColor = UIColor.white
|
||||
self.placeholderView.detailTextLabel.textColor = UIColor.white
|
||||
}
|
||||
|
||||
self.sortButton.transform = CGAffineTransform.identity.rotated(by: Settings.sortSaveStatesByOldestFirst ? 0 : .pi)
|
||||
}
|
||||
|
||||
//MARK: - Configure Views -
|
||||
@ -433,6 +437,25 @@ private extension SaveStatesViewController
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func changeSortOrder(_ sender: UIButton)
|
||||
{
|
||||
Settings.sortSaveStatesByOldestFirst.toggle()
|
||||
|
||||
UIView.transition(with: self.collectionView, duration: 0.4, options: .transitionCrossDissolve, animations: {
|
||||
self.updateDataSource()
|
||||
}, completion: nil)
|
||||
|
||||
UIView.animate(withDuration: 0.4) {
|
||||
self.update()
|
||||
}
|
||||
|
||||
let toastView = RSTToastView()
|
||||
toastView.textLabel.text = Settings.sortSaveStatesByOldestFirst ? NSLocalizedString("Oldest First", comment: "") : NSLocalizedString("Newest First", comment: "")
|
||||
toastView.presentationEdge = .top
|
||||
toastView.tintColor = UIColor.deltaPurple
|
||||
toastView.show(in: self.view, duration: 2.0)
|
||||
}
|
||||
|
||||
//MARK: - Convenience Methods -
|
||||
|
||||
func correctedSectionForSectionIndex(_ section: Int) -> Section
|
||||
|
||||
@ -54,7 +54,8 @@ struct Settings
|
||||
let defaults = [#keyPath(UserDefaults.translucentControllerSkinOpacity): 0.7,
|
||||
#keyPath(UserDefaults.gameShortcutsMode): GameShortcutsMode.recent.rawValue,
|
||||
#keyPath(UserDefaults.isButtonHapticFeedbackEnabled): true,
|
||||
#keyPath(UserDefaults.isThumbstickHapticFeedbackEnabled): true] as [String : Any]
|
||||
#keyPath(UserDefaults.isThumbstickHapticFeedbackEnabled): true,
|
||||
#keyPath(UserDefaults.sortSaveStatesByOldestFirst): true] as [String : Any]
|
||||
UserDefaults.standard.register(defaults: defaults)
|
||||
}
|
||||
}
|
||||
@ -168,6 +169,14 @@ extension Settings
|
||||
}
|
||||
}
|
||||
|
||||
static var sortSaveStatesByOldestFirst: Bool {
|
||||
set { UserDefaults.standard.sortSaveStatesByOldestFirst = newValue }
|
||||
get {
|
||||
let sortByOldestFirst = UserDefaults.standard.sortSaveStatesByOldestFirst
|
||||
return sortByOldestFirst
|
||||
}
|
||||
}
|
||||
|
||||
static func preferredControllerSkin(for system: System, traits: DeltaCore.ControllerSkin.Traits) -> ControllerSkin?
|
||||
{
|
||||
guard let userDefaultsKey = self.preferredControllerSkinKey(for: system, traits: traits) else { return nil }
|
||||
@ -270,4 +279,6 @@ private extension UserDefaults
|
||||
|
||||
@NSManaged var isButtonHapticFeedbackEnabled: Bool
|
||||
@NSManaged var isThumbstickHapticFeedbackEnabled: Bool
|
||||
|
||||
@NSManaged var sortSaveStatesByOldestFirst: Bool
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user