diff --git a/Common/Database/Model/GameCollection.swift b/Common/Database/Model/GameCollection.swift index 2be6a1b..2d5bae4 100644 --- a/Common/Database/Model/GameCollection.swift +++ b/Common/Database/Model/GameCollection.swift @@ -32,26 +32,16 @@ class GameCollection: NSManagedObject @NSManaged var games: Set - var name: String { - - switch self.identifier - { - case GameType.snes.rawValue: return NSLocalizedString("Super Nintendo Entertainment System", comment: "") - case GameType.gba.rawValue: return NSLocalizedString("Game Boy Advance", comment: "") - case GameType.delta.rawValue: return NSLocalizedString("Unsupported Games", comment: "") - default: return NSLocalizedString("Unknown", comment: "") - } + var name: String + { + let gameType = GameType(rawValue: self.identifier) + return gameType.localizedName } - var shortName: String { - - switch self.identifier - { - case GameType.snes.rawValue as String as String: return NSLocalizedString("SNES", comment: "") - case GameType.gba.rawValue as String as String: return NSLocalizedString("GBA", comment: "") - case GameType.delta.rawValue as String as String: return NSLocalizedString("Unsupported", comment: "") - default: return NSLocalizedString("Unknown", comment: "") - } + var shortName: String + { + let gameType = GameType(rawValue: self.identifier) + return gameType.localizedShortName } class func gameSystemCollectionForPathExtension(_ pathExtension: String?, inManagedObjectContext managedObjectContext: NSManagedObjectContext) -> GameCollection diff --git a/Cores/DeltaCore b/Cores/DeltaCore index f2d7845..040f323 160000 --- a/Cores/DeltaCore +++ b/Cores/DeltaCore @@ -1 +1 @@ -Subproject commit f2d78459b5cc37039f72427dbdcfedde00947690 +Subproject commit 040f323f314ab60e85d7d5e40633ec30668ff874 diff --git a/Delta.xcodeproj/project.pbxproj b/Delta.xcodeproj/project.pbxproj index a71bfd7..bf56f71 100644 --- a/Delta.xcodeproj/project.pbxproj +++ b/Delta.xcodeproj/project.pbxproj @@ -12,9 +12,12 @@ BF090CF41B490D8300DCAB45 /* UIDevice+Vibration.m in Sources */ = {isa = PBXBuildFile; fileRef = BF090CF31B490D8300DCAB45 /* UIDevice+Vibration.m */; }; BF0CDDAD1C8155D200640168 /* LoadImageOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0CDDAC1C8155D200640168 /* LoadImageOperation.swift */; }; BF107EC41BF413F000E0C32C /* GamesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF107EC31BF413F000E0C32C /* GamesViewController.swift */; }; + BF11734D1DA32A5200047DF8 /* GameType+Localization.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF11734C1DA32A5200047DF8 /* GameType+Localization.swift */; }; + BF1173501DA32CF600047DF8 /* ControllersSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF11734F1DA32CF600047DF8 /* ControllersSettingsViewController.swift */; }; BF13A7561D5D29B0000BB055 /* PreviewGameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF13A7551D5D29B0000BB055 /* PreviewGameViewController.swift */; }; BF13A7581D5D2FD9000BB055 /* EmulatorCore+Cheats.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF13A7571D5D2FD9000BB055 /* EmulatorCore+Cheats.swift */; }; BF172AEB1C68986300C26774 /* NSManagedObjectContext+Conveniences.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF172AEA1C68986300C26774 /* NSManagedObjectContext+Conveniences.swift */; }; + BF1DAD5D1D9F576000E752A7 /* GameTypeControllerSkinsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF1DAD5C1D9F576000E752A7 /* GameTypeControllerSkinsViewController.swift */; }; BF1FB1861C5EE643007E2494 /* SaveState.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF1FB1831C5EE643007E2494 /* SaveState.swift */; }; BF27CC8E1BC9FEA200A20D89 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BF6BB2451BB73FE800CCF94A /* Assets.xcassets */; }; BF2B98E61C97E32F00F6D57D /* SaveStatesCollectionHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF2B98E51C97E32F00F6D57D /* SaveStatesCollectionHeaderView.swift */; }; @@ -48,7 +51,6 @@ BFA0D1271D3AE1F600565894 /* GameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF63BDE91D389EEB00FCB040 /* GameViewController.swift */; }; BFA2315C1CED10BE0011E35A /* Action.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFA2315B1CED10BE0011E35A /* Action.swift */; }; BFAA1FED1B8AA4FA00495943 /* Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFAA1FEC1B8AA4FA00495943 /* Settings.swift */; }; - BFAA1FF41B8AD7F900495943 /* ControllersSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFAA1FF31B8AD7F900495943 /* ControllersSettingsViewController.swift */; }; BFBAA86A1D5A483900A29C1B /* DatabaseManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBAA8691D5A483900A29C1B /* DatabaseManager.swift */; }; BFC2731A1BE6152200D22B05 /* GameCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFC273171BE6152200D22B05 /* GameCollection.swift */; }; BFC9B7391CEFCD34008629BB /* CheatsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFC9B7381CEFCD34008629BB /* CheatsViewController.swift */; }; @@ -102,9 +104,12 @@ BF090CF31B490D8300DCAB45 /* UIDevice+Vibration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice+Vibration.m"; sourceTree = ""; }; BF0CDDAC1C8155D200640168 /* LoadImageOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LoadImageOperation.swift; path = Components/LoadImageOperation.swift; sourceTree = ""; }; BF107EC31BF413F000E0C32C /* GamesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GamesViewController.swift; sourceTree = ""; }; + BF11734C1DA32A5200047DF8 /* GameType+Localization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "GameType+Localization.swift"; sourceTree = ""; }; + BF11734F1DA32CF600047DF8 /* ControllersSettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ControllersSettingsViewController.swift; path = Controllers/ControllersSettingsViewController.swift; sourceTree = ""; }; BF13A7551D5D29B0000BB055 /* PreviewGameViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreviewGameViewController.swift; sourceTree = ""; }; BF13A7571D5D2FD9000BB055 /* EmulatorCore+Cheats.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "EmulatorCore+Cheats.swift"; sourceTree = ""; }; BF172AEA1C68986300C26774 /* NSManagedObjectContext+Conveniences.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSManagedObjectContext+Conveniences.swift"; sourceTree = ""; }; + BF1DAD5C1D9F576000E752A7 /* GameTypeControllerSkinsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = GameTypeControllerSkinsViewController.swift; path = "Controller Skins/GameTypeControllerSkinsViewController.swift"; sourceTree = ""; }; BF1FB1831C5EE643007E2494 /* SaveState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SaveState.swift; sourceTree = ""; }; BF27CC861BC9E3C600A20D89 /* Delta.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Delta.entitlements; sourceTree = ""; }; BF27CC8A1BC9FE4D00A20D89 /* Pods.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Pods.framework; path = "Pods/../build/Debug-appletvos/Pods.framework"; sourceTree = ""; }; @@ -138,7 +143,6 @@ BF9F4FCE1AAD7B87004C9500 /* DeltaCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = DeltaCore.framework; sourceTree = BUILT_PRODUCTS_DIR; }; BFA2315B1CED10BE0011E35A /* Action.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Action.swift; path = Components/Action.swift; sourceTree = ""; }; BFAA1FEC1B8AA4FA00495943 /* Settings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Settings.swift; sourceTree = ""; }; - BFAA1FF31B8AD7F900495943 /* ControllersSettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ControllersSettingsViewController.swift; sourceTree = ""; }; BFBAA8691D5A483900A29C1B /* DatabaseManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseManager.swift; sourceTree = ""; }; BFC134E01AAD82460087AD7B /* SNESDeltaCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SNESDeltaCore.framework; sourceTree = BUILT_PRODUCTS_DIR; }; BFC273171BE6152200D22B05 /* GameCollection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GameCollection.swift; sourceTree = ""; }; @@ -196,10 +200,27 @@ BF7AE8091C2E8C7600B1B5BC /* UIColor+Delta.swift */, BFCEA67D1D56FF640061A534 /* UIViewControllerContextTransitioning+Conveniences.swift */, BF13A7571D5D2FD9000BB055 /* EmulatorCore+Cheats.swift */, + BF11734C1DA32A5200047DF8 /* GameType+Localization.swift */, ); path = Extensions; sourceTree = ""; }; + BF11734E1DA32CEC00047DF8 /* Controllers */ = { + isa = PBXGroup; + children = ( + BF11734F1DA32CF600047DF8 /* ControllersSettingsViewController.swift */, + ); + name = Controllers; + sourceTree = ""; + }; + BF1DAD5B1D9F574900E752A7 /* Controller Skins */ = { + isa = PBXGroup; + children = ( + BF1DAD5C1D9F576000E752A7 /* GameTypeControllerSkinsViewController.swift */, + ); + name = "Controller Skins"; + sourceTree = ""; + }; BF353FFB1C5DA2F600C1184C /* Presentation Controller */ = { isa = PBXGroup; children = ( @@ -334,7 +355,8 @@ BFAA1FEC1B8AA4FA00495943 /* Settings.swift */, BF5E7F451B9A652600AE44F8 /* Settings.storyboard */, BF5E7F431B9A650B00AE44F8 /* SettingsViewController.swift */, - BFAA1FF31B8AD7F900495943 /* ControllersSettingsViewController.swift */, + BF11734E1DA32CEC00047DF8 /* Controllers */, + BF1DAD5B1D9F574900E752A7 /* Controller Skins */, ); path = Settings; sourceTree = ""; @@ -594,7 +616,6 @@ BF31878B1D489AAA00BD020D /* CheatValidator.swift in Sources */, BFFC46201D59823500AF2CC6 /* InitialGamesStoryboardSegue.swift in Sources */, BFA2315C1CED10BE0011E35A /* Action.swift in Sources */, - BFAA1FF41B8AD7F900495943 /* ControllersSettingsViewController.swift in Sources */, BF353FF91C5D870B00C1184C /* PauseItem.swift in Sources */, BFBAA86A1D5A483900A29C1B /* DatabaseManager.swift in Sources */, BFDD04F11D5E2C27002D450E /* GameCollectionViewController.swift in Sources */, @@ -602,10 +623,12 @@ BFFA71DD1AAC406100EE9DD1 /* AppDelegate.swift in Sources */, BF7AE81E1C2E984300B1B5BC /* GridCollectionViewCell.swift in Sources */, BF34FA111CF1899D006624C7 /* CheatTextView.swift in Sources */, + BF1DAD5D1D9F576000E752A7 /* GameTypeControllerSkinsViewController.swift in Sources */, BFFC46231D5984A000AF2CC6 /* LaunchViewController.swift in Sources */, BF4566E81BC090B6007BFA1A /* Model.xcdatamodeld in Sources */, BFDE393C1BC0CEDF003F72E8 /* Game.swift in Sources */, BF34FA071CF0F510006624C7 /* EditCheatViewController.swift in Sources */, + BF11734D1DA32A5200047DF8 /* GameType+Localization.swift in Sources */, BFC2731A1BE6152200D22B05 /* GameCollection.swift in Sources */, BFFC461F1D59823500AF2CC6 /* GamesStoryboardSegue.swift in Sources */, BF2B98E61C97E32F00F6D57D /* SaveStatesCollectionHeaderView.swift in Sources */, @@ -625,6 +648,7 @@ BF13A7561D5D29B0000BB055 /* PreviewGameViewController.swift in Sources */, BFDD04EF1D5E27DB002D450E /* NSFetchedResultsController+Conveniences.m in Sources */, BFCEA67E1D56FF640061A534 /* UIViewControllerContextTransitioning+Conveniences.swift in Sources */, + BF1173501DA32CF600047DF8 /* ControllersSettingsViewController.swift in Sources */, BFFC461E1D59823500AF2CC6 /* GamesPresentationController.swift in Sources */, BF5E7F441B9A650B00AE44F8 /* SettingsViewController.swift in Sources */, BF353FF21C5D7FB000C1184C /* PauseViewController.swift in Sources */, diff --git a/Delta/Extensions/GameType+Localization.swift b/Delta/Extensions/GameType+Localization.swift new file mode 100644 index 0000000..f2d64ec --- /dev/null +++ b/Delta/Extensions/GameType+Localization.swift @@ -0,0 +1,34 @@ +// +// GameType+Localization.swift +// Delta +// +// Created by Riley Testut on 10/3/16. +// Copyright © 2016 Riley Testut. All rights reserved. +// + +import DeltaCore + +extension GameType +{ + var localizedName: String + { + switch self + { + case GameType.snes: return NSLocalizedString("Super Nintendo Entertainment System", comment: "") + case GameType.gba: return NSLocalizedString("Game Boy Advance", comment: "") + case GameType.delta: return NSLocalizedString("Unsupported System", comment: "") + default: return NSLocalizedString("Unknown", comment: "") + } + } + + var localizedShortName: String + { + switch self + { + case GameType.snes: return NSLocalizedString("SNES", comment: "") + case GameType.gba: return NSLocalizedString("GBA", comment: "") + case GameType.delta: return NSLocalizedString("Unsupported", comment: "") + default: return NSLocalizedString("Unknown", comment: "") + } + } +} diff --git a/Delta/Settings/Controller Skins/GameTypeControllerSkinsViewController.swift b/Delta/Settings/Controller Skins/GameTypeControllerSkinsViewController.swift new file mode 100644 index 0000000..acbba6d --- /dev/null +++ b/Delta/Settings/Controller Skins/GameTypeControllerSkinsViewController.swift @@ -0,0 +1,87 @@ +// +// GameTypeControllerSkinsViewController.swift +// Delta +// +// Created by Riley Testut on 9/30/16. +// Copyright © 2016 Riley Testut. All rights reserved. +// + +import UIKit + +import DeltaCore + +extension GameTypeControllerSkinsViewController +{ + fileprivate enum Section: Int + { + case portrait + case landscape + } +} + +class GameTypeControllerSkinsViewController: UITableViewController +{ + var gameType: GameType! + + @IBOutlet fileprivate var portraitImageView: UIImageView! + @IBOutlet fileprivate var landscapeImageView: UIImageView! +} + +extension GameTypeControllerSkinsViewController +{ + override func viewDidLoad() + { + super.viewDidLoad() + + self.title = self.gameType.localizedShortName + } + + override func viewWillAppear(_ animated: Bool) + { + self.updateControllerSkins() + + super.viewWillAppear(animated) + } + + override func didReceiveMemoryWarning() + { + super.didReceiveMemoryWarning() + } +} + +extension GameTypeControllerSkinsViewController +{ + override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat + { + let section = Section(rawValue: indexPath.section)! + + let imageSize: CGSize? + + switch section + { + case .portrait: imageSize = self.portraitImageView.image?.size + case .landscape: imageSize = self.landscapeImageView.image?.size + } + + guard let unwrappedImageSize = imageSize else { return super.tableView(tableView, heightForRowAt: indexPath) } + + let scale = (self.view.bounds.width / unwrappedImageSize.width) + + let height = unwrappedImageSize.height * scale + return height + } +} + +private extension GameTypeControllerSkinsViewController +{ + func updateControllerSkins() + { + let controllerSkin = ControllerSkin.standardControllerSkin(for: self.gameType) + + let portraitTraits = ControllerSkin.Traits(deviceType: .iphone, displayMode: ControllerSkin.DisplayMode.fullScreen, orientation: .portrait) + self.portraitImageView.image = controllerSkin?.image(for: portraitTraits, preferredSize: UIScreen.main.defaultControllerSkinSize) + + let landscapeTraits = ControllerSkin.Traits(deviceType: .iphone, displayMode: ControllerSkin.DisplayMode.fullScreen, orientation: .landscape) + self.landscapeImageView.image = controllerSkin?.image(for: landscapeTraits, preferredSize: UIScreen.main.defaultControllerSkinSize) + } +} diff --git a/Delta/Settings/ControllersSettingsViewController.swift b/Delta/Settings/Controllers/ControllersSettingsViewController.swift similarity index 100% rename from Delta/Settings/ControllersSettingsViewController.swift rename to Delta/Settings/Controllers/ControllersSettingsViewController.swift diff --git a/Delta/Settings/Settings.storyboard b/Delta/Settings/Settings.storyboard index cae7682..b64d9e4 100644 --- a/Delta/Settings/Settings.storyboard +++ b/Delta/Settings/Settings.storyboard @@ -1,7 +1,9 @@ - - + + - + + + @@ -9,103 +11,141 @@ - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -128,6 +168,7 @@ + @@ -140,29 +181,29 @@ - + - + - + - + @@ -185,6 +226,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Delta/Settings/SettingsViewController.swift b/Delta/Settings/SettingsViewController.swift index 89fb488..32a585c 100644 --- a/Delta/Settings/SettingsViewController.swift +++ b/Delta/Settings/SettingsViewController.swift @@ -9,14 +9,19 @@ import UIKit import DeltaCore -private enum SettingsSection: Int +extension SettingsViewController { - case controllers -} - -private enum SettingsSegues: String -{ - case Controllers = "controllersSegue" + fileprivate enum Section: Int + { + case controllers + case controllerSkins + } + + fileprivate enum Segue: String + { + case controllers = "controllersSegue" + case controllerSkins = "controllerSkinsSegue" + } } class SettingsViewController: UITableViewController @@ -51,10 +56,28 @@ class SettingsViewController: UITableViewController override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - if segue.identifier == SettingsSegues.Controllers.rawValue + guard + let identifier = segue.identifier, + let segueType = Segue(rawValue: identifier), + let cell = sender as? UITableViewCell, + let indexPath = self.tableView.indexPath(for: cell) + else { return } + + switch segueType { + case Segue.controllers: let controllersSettingsViewController = segue.destination as! ControllersSettingsViewController - controllersSettingsViewController.playerIndex = (self.tableView.indexPathForSelectedRow as NSIndexPath?)?.row + controllersSettingsViewController.playerIndex = indexPath.row + + case Segue.controllerSkins: + let gameTypeControllerSkinsViewController = segue.destination as! GameTypeControllerSkinsViewController + + switch indexPath.row + { + case 0: gameTypeControllerSkinsViewController.gameType = .snes + case 1: gameTypeControllerSkinsViewController.gameType = .gba + default: break + } } } } @@ -65,7 +88,7 @@ private extension SettingsViewController { let indexPath = self.tableView.indexPathForSelectedRow - self.tableView.reloadSections(IndexSet(integer: SettingsSection.controllers.rawValue), with: .none) + self.tableView.reloadSections(IndexSet(integer: Section.controllers.rawValue), with: .none) self.tableView.selectRow(at: indexPath, animated: true, scrollPosition: UITableViewScrollPosition.none) } @@ -75,12 +98,12 @@ private extension SettingsViewController { dynamic func externalControllerDidConnect(_ notification: Notification) { - self.tableView.reloadSections(IndexSet(integer: SettingsSection.controllers.rawValue), with: .none) + self.tableView.reloadSections(IndexSet(integer: Section.controllers.rawValue), with: .none) } dynamic func externalControllerDidDisconnect(_ notification: Notification) { - self.tableView.reloadSections(IndexSet(integer: SettingsSection.controllers.rawValue), with: .none) + self.tableView.reloadSections(IndexSet(integer: Section.controllers.rawValue), with: .none) } } @@ -90,13 +113,13 @@ extension SettingsViewController { let cell = super.tableView(tableView, cellForRowAt: indexPath) - if (indexPath as NSIndexPath).section == SettingsSection.controllers.rawValue + if indexPath.section == Section.controllers.rawValue { - if (indexPath as NSIndexPath).row == Settings.localControllerPlayerIndex + if indexPath.row == Settings.localControllerPlayerIndex { cell.detailTextLabel?.text = UIDevice.current.name } - else if let index = ExternalControllerManager.shared.connectedControllers.index(where: { $0.playerIndex == (indexPath as NSIndexPath).row }) + else if let index = ExternalControllerManager.shared.connectedControllers.index(where: { $0.playerIndex == indexPath.row }) { let controller = ExternalControllerManager.shared.connectedControllers[index] cell.detailTextLabel?.text = controller.name @@ -112,9 +135,13 @@ extension SettingsViewController override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - if (indexPath as NSIndexPath).section == SettingsSection.controllers.rawValue + let cell = tableView.cellForRow(at: indexPath) + let section = Section(rawValue: indexPath.section)! + + switch section { - self.performSegue(withIdentifier: SettingsSegues.Controllers.rawValue, sender: self) + case Section.controllers: self.performSegue(withIdentifier: Segue.controllers.rawValue, sender: cell) + case Section.controllerSkins: self.performSegue(withIdentifier: Segue.controllerSkins.rawValue, sender: cell) } } }