diff --git a/Cores/DeltaCore b/Cores/DeltaCore index 026b22b..bbb3592 160000 --- a/Cores/DeltaCore +++ b/Cores/DeltaCore @@ -1 +1 @@ -Subproject commit 026b22be17246068f7e333437545db490882521f +Subproject commit bbb35924b544251b20061340fa9aa9e0275caee4 diff --git a/Delta.xcodeproj/project.pbxproj b/Delta.xcodeproj/project.pbxproj index 014b08c..7cc8de7 100644 --- a/Delta.xcodeproj/project.pbxproj +++ b/Delta.xcodeproj/project.pbxproj @@ -9,8 +9,14 @@ /* Begin PBXBuildFile section */ BF090CF41B490D8300DCAB45 /* UIDevice+Vibration.m in Sources */ = {isa = PBXBuildFile; fileRef = BF090CF31B490D8300DCAB45 /* UIDevice+Vibration.m */; }; BF46894F1AAC46EF00A2586D /* DirectoryContentsDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF46894E1AAC46EF00A2586D /* DirectoryContentsDataSource.swift */; }; + BF5E7F441B9A650B00AE44F8 /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF5E7F431B9A650B00AE44F8 /* SettingsViewController.swift */; settings = {ASSET_TAGS = (); }; }; + BF5E7F461B9A652600AE44F8 /* Settings.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BF5E7F451B9A652600AE44F8 /* Settings.storyboard */; settings = {ASSET_TAGS = (); }; }; + BF70798C1B6B464B0019077C /* ZipZap.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BF70798B1B6B464B0019077C /* ZipZap.framework */; }; + BF70798D1B6B464B0019077C /* ZipZap.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BF70798B1B6B464B0019077C /* ZipZap.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; BF9F4FCF1AAD7B87004C9500 /* DeltaCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BF9F4FCE1AAD7B87004C9500 /* DeltaCore.framework */; }; BF9F4FD01AAD7B87004C9500 /* DeltaCore.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BF9F4FCE1AAD7B87004C9500 /* DeltaCore.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + BFAA1FED1B8AA4FA00495943 /* Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFAA1FEC1B8AA4FA00495943 /* Settings.swift */; }; + BFAA1FF41B8AD7F900495943 /* ControllersSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFAA1FF31B8AD7F900495943 /* ControllersSettingsViewController.swift */; }; BFC134E11AAD82460087AD7B /* SNESDeltaCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BFC134E01AAD82460087AD7B /* SNESDeltaCore.framework */; }; BFC134E21AAD82470087AD7B /* SNESDeltaCore.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BFC134E01AAD82460087AD7B /* SNESDeltaCore.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; BFEC732D1AAECC4A00650035 /* Roxas.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BFEC732C1AAECC4A00650035 /* Roxas.framework */; }; @@ -33,6 +39,7 @@ files = ( BF9F4FD01AAD7B87004C9500 /* DeltaCore.framework in Embed Frameworks */, BFEC732E1AAECC4A00650035 /* Roxas.framework in Embed Frameworks */, + BF70798D1B6B464B0019077C /* ZipZap.framework in Embed Frameworks */, BFC134E21AAD82470087AD7B /* SNESDeltaCore.framework in Embed Frameworks */, ); name = "Embed Frameworks"; @@ -45,7 +52,12 @@ BF090CF21B490D8300DCAB45 /* UIDevice+Vibration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice+Vibration.h"; sourceTree = ""; }; BF090CF31B490D8300DCAB45 /* UIDevice+Vibration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice+Vibration.m"; sourceTree = ""; }; BF46894E1AAC46EF00A2586D /* DirectoryContentsDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DirectoryContentsDataSource.swift; sourceTree = ""; }; + BF5E7F431B9A650B00AE44F8 /* SettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = ""; }; + BF5E7F451B9A652600AE44F8 /* Settings.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Settings.storyboard; sourceTree = ""; }; + BF70798B1B6B464B0019077C /* ZipZap.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = ZipZap.framework; sourceTree = BUILT_PRODUCTS_DIR; }; BF9F4FCE1AAD7B87004C9500 /* DeltaCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = DeltaCore.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 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 = ""; }; BFC134E01AAD82460087AD7B /* SNESDeltaCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SNESDeltaCore.framework; sourceTree = BUILT_PRODUCTS_DIR; }; BFEC732C1AAECC4A00650035 /* Roxas.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Roxas.framework; sourceTree = BUILT_PRODUCTS_DIR; }; BFFA71D71AAC406100EE9DD1 /* Delta.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Delta.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -66,6 +78,7 @@ files = ( BF9F4FCF1AAD7B87004C9500 /* DeltaCore.framework in Frameworks */, BFEC732D1AAECC4A00650035 /* Roxas.framework in Frameworks */, + BF70798C1B6B464B0019077C /* ZipZap.framework in Frameworks */, BFC134E11AAD82460087AD7B /* SNESDeltaCore.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -94,6 +107,7 @@ BF9F4FCD1AAD7B25004C9500 /* Frameworks */ = { isa = PBXGroup; children = ( + BF70798B1B6B464B0019077C /* ZipZap.framework */, BFEC732C1AAECC4A00650035 /* Roxas.framework */, BF9F4FCE1AAD7B87004C9500 /* DeltaCore.framework */, BFC134E01AAD82460087AD7B /* SNESDeltaCore.framework */, @@ -101,6 +115,17 @@ name = Frameworks; sourceTree = ""; }; + BFAA1FEB1B8AA4E800495943 /* Settings */ = { + isa = PBXGroup; + children = ( + BFAA1FEC1B8AA4FA00495943 /* Settings.swift */, + BF5E7F451B9A652600AE44F8 /* Settings.storyboard */, + BF5E7F431B9A650B00AE44F8 /* SettingsViewController.swift */, + BFAA1FF31B8AD7F900495943 /* ControllersSettingsViewController.swift */, + ); + name = Settings; + sourceTree = ""; + }; BFEC732F1AAECCBD00650035 /* Resources */ = { isa = PBXGroup; children = ( @@ -133,6 +158,7 @@ BFFA71E01AAC406100EE9DD1 /* Main.storyboard */, BF46894D1AAC469800A2586D /* Game Selection */, BFFB709D1AF99ACA00DE56FE /* Emulation */, + BFAA1FEB1B8AA4E800495943 /* Settings */, BF090CEE1B490C1A00DCAB45 /* Extensions */, BFEC732F1AAECCBD00650035 /* Resources */, BFFA71DA1AAC406100EE9DD1 /* Supporting Files */, @@ -222,6 +248,7 @@ BFFB70A11AF99DFB00DE56FE /* EmulationViewController.xib in Resources */, BFFA71E71AAC406100EE9DD1 /* LaunchScreen.xib in Resources */, BFFA71E41AAC406100EE9DD1 /* Images.xcassets in Resources */, + BF5E7F461B9A652600AE44F8 /* Settings.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -232,11 +259,14 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + BFAA1FED1B8AA4FA00495943 /* Settings.swift in Sources */, BFFA71DF1AAC406100EE9DD1 /* GamesViewController.swift in Sources */, BFFB709F1AF99B1700DE56FE /* EmulationViewController.swift in Sources */, + BFAA1FF41B8AD7F900495943 /* ControllersSettingsViewController.swift in Sources */, BFFA71DD1AAC406100EE9DD1 /* AppDelegate.swift in Sources */, BF46894F1AAC46EF00A2586D /* DirectoryContentsDataSource.swift in Sources */, BF090CF41B490D8300DCAB45 /* UIDevice+Vibration.m in Sources */, + BF5E7F441B9A650B00AE44F8 /* SettingsViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Delta.xcworkspace/xcshareddata/Delta.xcscmblueprint b/Delta.xcworkspace/xcshareddata/Delta.xcscmblueprint new file mode 100644 index 0000000..bfaecf0 --- /dev/null +++ b/Delta.xcworkspace/xcshareddata/Delta.xcscmblueprint @@ -0,0 +1,43 @@ +{ + "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { + + }, + "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { + "377491A212AA92C1503AD101C88ADDBD6FD62CF0" : 0, + "C14902E1A817B9BD0549E16C5F6A56E2377FBF42" : 0, + "816D57F18EE93972A535858CB18F29A85BE91A39" : 0, + "82DF43EF5CA016D15C41E0AF1AF686E9973475B7" : 0 + }, + "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "8EE86D07-2AAF-47C3-91DF-0E46DBDAB128", + "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { + "377491A212AA92C1503AD101C88ADDBD6FD62CF0" : "Delta\/External\/Roxas\/", + "C14902E1A817B9BD0549E16C5F6A56E2377FBF42" : "Delta\/Cores\/SNESDeltaCore\/", + "816D57F18EE93972A535858CB18F29A85BE91A39" : "Delta\/Cores\/DeltaCore\/", + "82DF43EF5CA016D15C41E0AF1AF686E9973475B7" : "Delta\/Cores\/DeltaCore\/External\/ZipZap\/" + }, + "DVTSourceControlWorkspaceBlueprintNameKey" : "Delta", + "DVTSourceControlWorkspaceBlueprintVersion" : 204, + "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "Delta.xcworkspace", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "github.com:rileytestut\/Roxas.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "377491A212AA92C1503AD101C88ADDBD6FD62CF0" + }, + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "github.com:rileytestut\/DeltaCore.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "816D57F18EE93972A535858CB18F29A85BE91A39" + }, + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "github.com:pixelglow\/ZipZap.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "82DF43EF5CA016D15C41E0AF1AF686E9973475B7" + }, + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "github.com:rileytestut\/SNESDeltaCore.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "C14902E1A817B9BD0549E16C5F6A56E2377FBF42" + } + ] +} \ No newline at end of file diff --git a/Delta/AppDelegate.swift b/Delta/AppDelegate.swift index 8ac1088..34c88a3 100644 --- a/Delta/AppDelegate.swift +++ b/Delta/AppDelegate.swift @@ -7,16 +7,18 @@ // import UIKit +import DeltaCore @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { - // Override point for customization after application launch. + // Controllers + ExternalControllerManager.sharedManager.startMonitoringExternalControllers() + return true } diff --git a/Delta/Base.lproj/Main.storyboard b/Delta/Base.lproj/Main.storyboard index 9ba8d56..e08a55a 100644 --- a/Delta/Base.lproj/Main.storyboard +++ b/Delta/Base.lproj/Main.storyboard @@ -1,7 +1,8 @@ - + - + + @@ -32,8 +33,10 @@ + + @@ -43,11 +46,28 @@ - + + + + + + + + + + + + + + + + + + diff --git a/Delta/ControllersSettingsViewController.swift b/Delta/ControllersSettingsViewController.swift new file mode 100644 index 0000000..ef56fca --- /dev/null +++ b/Delta/ControllersSettingsViewController.swift @@ -0,0 +1,229 @@ +// +// ControllersSettingsViewController.swift +// Delta +// +// Created by Riley Testut on 8/23/15. +// Copyright © 2015 Riley Testut. All rights reserved. +// + +import UIKit +import DeltaCore + +private enum ControllersSettingsSection: Int +{ + case None + case LocalDevice + case ExternalControllers +} + +private class LocalDeviceController: ExternalController +{ + override var name: String { + return UIDevice.currentDevice().name + } +} + +class ControllersSettingsViewController: UITableViewController +{ + var playerIndex: Int? { + didSet + { + if let playerIndex = self.playerIndex + { + self.title = NSLocalizedString("Player \(playerIndex + 1)", comment: "") + } + else + { + self.title = NSLocalizedString("Controllers", comment: "") + } + } + } + + private var connectedControllers = ExternalControllerManager.sharedManager.connectedControllers.sort({ $0.playerIndex ?? NSIntegerMax < $1.playerIndex ?? NSIntegerMax }) + + private lazy var localDeviceController: LocalDeviceController = { + let device = LocalDeviceController() + device.playerIndex = Settings.localControllerPlayerIndex + + return device + }() + + required init?(coder aDecoder: NSCoder) + { + super.init(coder: aDecoder) + + NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("externalControllerDidConnect:"), name: ExternalControllerDidConnectNotification, object: nil) + NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("externalControllerDidDisconnect:"), name: ExternalControllerDidDisconnectNotification, object: nil) + } + + override func viewDidLoad() + { + super.viewDidLoad() + } + + //MARK: - Storyboards - + + override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) + { + guard let indexPath = self.tableView.indexPathForSelectedRow else { return } + + var controllers = self.connectedControllers + controllers.append(self.localDeviceController) + + // Reset previous controller + if let playerIndex = self.playerIndex, index = controllers.indexOf({ $0.playerIndex == playerIndex }) + { + let controller = controllers[index] + controller.playerIndex = nil + } + + switch ControllersSettingsSection(rawValue: indexPath.section)! + { + case .None: break + case .LocalDevice: self.localDeviceController.playerIndex = self.playerIndex + case .ExternalControllers: + let controller = self.connectedControllers[indexPath.row] + controller.playerIndex = self.playerIndex + } + + // Updates in case we reset it above, as well as if we updated in the switch statement + Settings.localControllerPlayerIndex = self.localDeviceController.playerIndex + } +} + +private extension ControllersSettingsViewController +{ + dynamic func externalControllerDidConnect(notification: NSNotification) + { + guard let controller = notification.object as? ExternalController else { return } + + if let playerIndex = controller.playerIndex + { + self.connectedControllers.insert(controller, atIndex: playerIndex) + } + else + { + self.connectedControllers.append(controller) + } + + if let index = self.connectedControllers.indexOf(controller) + { + if self.connectedControllers.count == 1 + { + self.tableView.insertSections(NSIndexSet(index: ControllersSettingsSection.ExternalControllers.rawValue), withRowAnimation: .Fade) + } + else + { + self.tableView.insertRowsAtIndexPaths([NSIndexPath(forRow: index, inSection: ControllersSettingsSection.ExternalControllers.rawValue)], withRowAnimation: .Automatic) + } + } + } + + dynamic func externalControllerDidDisconnect(notification: NSNotification) + { + guard let controller = notification.object as? ExternalController else { return } + + if let index = self.connectedControllers.indexOf(controller) + { + self.connectedControllers.removeAtIndex(index) + + if self.connectedControllers.count == 0 + { + self.tableView.deleteSections(NSIndexSet(index: ControllersSettingsSection.ExternalControllers.rawValue), withRowAnimation: .Fade) + } + else + { + self.tableView.deleteRowsAtIndexPaths([NSIndexPath(forRow: index, inSection: ControllersSettingsSection.ExternalControllers.rawValue)], withRowAnimation: .Automatic) + } + } + + if controller.playerIndex == self.playerIndex + { + self.tableView.reloadSections(NSIndexSet(index: ControllersSettingsSection.None.rawValue), withRowAnimation: .None) + } + } +} + +extension ControllersSettingsViewController +{ + override func numberOfSectionsInTableView(tableView: UITableView) -> Int + { + if self.connectedControllers.count == 0 + { + return 2 + } + + return 3 + } + + override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int + { + switch ControllersSettingsSection(rawValue: section)! + { + case .None: return 1 + case .LocalDevice: return 1 + case .ExternalControllers: return self.connectedControllers.count + } + } + + override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell + { + let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) + cell.detailTextLabel?.text = nil + cell.accessoryType = .None + + if indexPath.section == ControllersSettingsSection.None.rawValue + { + cell.textLabel?.text = NSLocalizedString("None", comment: "") + + if Settings.localControllerPlayerIndex != self.playerIndex && !self.connectedControllers.contains({ $0.playerIndex == self.playerIndex }) + { + cell.accessoryType = .Checkmark + } + } + else + { + let controller: ExternalController + + if indexPath.section == ControllersSettingsSection.LocalDevice.rawValue + { + controller = self.localDeviceController + } + else if indexPath.section == ControllersSettingsSection.ExternalControllers.rawValue + { + controller = self.connectedControllers[indexPath.row] + } + else + { + fatalError("Section index invalid") + } + + cell.textLabel?.text = controller.name + + if controller.playerIndex == self.playerIndex + { + cell.accessoryType = .Checkmark + } + else + { + if let playerIndex = controller.playerIndex + { + cell.detailTextLabel?.text = NSLocalizedString("Player \(playerIndex + 1)", comment: "") + } + + } + } + + return cell + } + + override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? + { + switch ControllersSettingsSection(rawValue: section)! + { + case .None: return nil + case .LocalDevice: return NSLocalizedString("Local Device", comment: "") + case .ExternalControllers: return self.connectedControllers.count > 0 ? NSLocalizedString("External Controllers", comment: "") : "" + } + } +} diff --git a/Delta/GamesViewController.swift b/Delta/GamesViewController.swift index cab52db..0e76319 100644 --- a/Delta/GamesViewController.swift +++ b/Delta/GamesViewController.swift @@ -77,6 +77,13 @@ class GamesViewController: UITableViewController // Dispose of any resources that can be recreated. } + //MARK: - Settings - + + @IBAction func dismissSettingsViewController(segue: UIStoryboardSegue) + { + + } + //MARK: UITableViewDelegate diff --git a/Delta/Images.xcassets/Contents.json b/Delta/Images.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/Delta/Images.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Delta/Images.xcassets/Settings_Button.imageset/Contents.json b/Delta/Images.xcassets/Settings_Button.imageset/Contents.json new file mode 100644 index 0000000..c810678 --- /dev/null +++ b/Delta/Images.xcassets/Settings_Button.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "gear_1.pdf" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Delta/Images.xcassets/Settings_Button.imageset/gear_1.pdf b/Delta/Images.xcassets/Settings_Button.imageset/gear_1.pdf new file mode 100644 index 0000000..3c2cee1 --- /dev/null +++ b/Delta/Images.xcassets/Settings_Button.imageset/gear_1.pdf @@ -0,0 +1,68 @@ +%PDF-1.5 +% +3 0 obj +<< /Length 4 0 R + /Filter /FlateDecode +>> +stream +xJ1 y ӏ'G #(ăo۴pYv&$$Ey7N!}}  b(r.$cC`#$r4 [` [Yx191-{v)dR T> + >> +>> +endobj +5 0 obj +<< /Type /Page + /Parent 1 0 R + /MediaBox [ 0 0 22.000074 22 ] + /Contents 3 0 R + /Group << + /Type /Group + /S /Transparency + /I true + /CS /DeviceRGB + >> + /Resources 2 0 R +>> +endobj +1 0 obj +<< /Type /Pages + /Kids [ 5 0 R ] + /Count 1 +>> +endobj +6 0 obj +<< /Creator (cairo 1.12.16 (http://cairographics.org)) + /Producer (cairo 1.12.16 (http://cairographics.org)) +>> +endobj +7 0 obj +<< /Type /Catalog + /Pages 1 0 R +>> +endobj +xref +0 8 +0000000000 65535 f +0000000803 00000 n +0000000512 00000 n +0000000015 00000 n +0000000490 00000 n +0000000584 00000 n +0000000868 00000 n +0000000997 00000 n +trailer +<< /Size 8 + /Root 7 0 R + /Info 6 0 R +>> +startxref +1049 +%%EOF diff --git a/Delta/Settings.storyboard b/Delta/Settings.storyboard new file mode 100644 index 0000000..05cad00 --- /dev/null +++ b/Delta/Settings.storyboard @@ -0,0 +1,208 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Delta/Settings.swift b/Delta/Settings.swift new file mode 100644 index 0000000..6becfa9 --- /dev/null +++ b/Delta/Settings.swift @@ -0,0 +1,16 @@ +// +// Settings.swift +// Delta +// +// Created by Riley Testut on 8/23/15. +// Copyright © 2015 Riley Testut. All rights reserved. +// + +import Foundation + +struct Settings +{ + /// Controllers + static var localControllerPlayerIndex: Int? = 0 + +} \ No newline at end of file diff --git a/Delta/SettingsViewController.swift b/Delta/SettingsViewController.swift new file mode 100644 index 0000000..c4a8667 --- /dev/null +++ b/Delta/SettingsViewController.swift @@ -0,0 +1,120 @@ +// +// SettingsViewController.swift +// Delta +// +// Created by Riley Testut on 9/4/15. +// Copyright © 2015 Riley Testut. All rights reserved. +// + +import UIKit +import DeltaCore + +private enum SettingsSection: Int +{ + case Controllers +} + +private enum SettingsSegues: String +{ + case Controllers = "controllersSegue" +} + +class SettingsViewController: UITableViewController +{ + required init?(coder aDecoder: NSCoder) + { + super.init(coder: aDecoder) + + NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("externalControllerDidConnect:"), name: ExternalControllerDidConnectNotification, object: nil) + NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("externalControllerDidDisconnect:"), name: ExternalControllerDidDisconnectNotification, object: nil) + } + + override func viewDidLoad() + { + super.viewDidLoad() + } + + override func viewWillAppear(animated: Bool) + { + super.viewWillAppear(animated) + + if let indexPath = self.tableView.indexPathForSelectedRow + { + self.tableView.deselectRowAtIndexPath(indexPath, animated: true) + } + } + + override func didReceiveMemoryWarning() + { + super.didReceiveMemoryWarning() + } + + override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) + { + if segue.identifier == SettingsSegues.Controllers.rawValue + { + let controllersSettingsViewController = segue.destinationViewController as! ControllersSettingsViewController + controllersSettingsViewController.playerIndex = self.tableView.indexPathForSelectedRow?.row + } + } +} + +private extension SettingsViewController +{ + @IBAction func unwindControllersSettingsViewController(segue: UIStoryboardSegue) + { + let indexPath = self.tableView.indexPathForSelectedRow + + self.tableView.reloadSections(NSIndexSet(index: SettingsSection.Controllers.rawValue), withRowAnimation: .None) + + self.tableView.selectRowAtIndexPath(indexPath, animated: true, scrollPosition: UITableViewScrollPosition.None) + } +} + +private extension SettingsViewController +{ + dynamic func externalControllerDidConnect(notification: NSNotification) + { + self.tableView.reloadSections(NSIndexSet(index: SettingsSection.Controllers.rawValue), withRowAnimation: .None) + } + + dynamic func externalControllerDidDisconnect(notification: NSNotification) + { + self.tableView.reloadSections(NSIndexSet(index: SettingsSection.Controllers.rawValue), withRowAnimation: .None) + } +} + +extension SettingsViewController +{ + override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell + { + let cell = super.tableView(tableView, cellForRowAtIndexPath: indexPath) + + if indexPath.section == SettingsSection.Controllers.rawValue + { + if indexPath.row == Settings.localControllerPlayerIndex + { + cell.detailTextLabel?.text = UIDevice.currentDevice().name + } + else if let index = ExternalControllerManager.sharedManager.connectedControllers.indexOf({ $0.playerIndex == indexPath.row }) + { + let controller = ExternalControllerManager.sharedManager.connectedControllers[index] + cell.detailTextLabel?.text = controller.name + } + else + { + cell.detailTextLabel?.text = nil + } + } + + return cell + } + + override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) + { + if indexPath.section == SettingsSection.Controllers.rawValue + { + self.performSegueWithIdentifier(SettingsSegues.Controllers.rawValue, sender: self) + } + } +}