Handles input from all connected controllers correctly

This commit is contained in:
Riley Testut 2015-09-07 17:57:12 -07:00
parent cc6a044b29
commit c59f4642cd
3 changed files with 40 additions and 5 deletions

@ -1 +1 @@
Subproject commit bbb35924b544251b20061340fa9aa9e0275caee4
Subproject commit 0d618e031f284cad733b1122c60e148601b24ad6

@ -1 +1 @@
Subproject commit 746632eee940d597777d2c32d5e031807fd788fb
Subproject commit d99e5066db54aae4f987a8c2726be27b0eac6ee8

View File

@ -29,13 +29,16 @@ class EmulationViewController: UIViewController
self.emulatorCore = EmulatorCore(game: game)
super.init(nibName: "EmulationViewController", bundle: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("updateControllers"), name: ExternalControllerDidConnectNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("updateControllers"), name: ExternalControllerDidDisconnectNotification, object: nil)
}
required init(coder aDecoder: NSCoder) {
fatalError("initWithCoder: not implemented.")
}
//MARK: - Overrides -
//MARK: - Overrides
/** Overrides **/
//MARK: - UIViewController
@ -49,6 +52,8 @@ class EmulationViewController: UIViewController
self.controllerView.controllerSkin = controllerSkin
self.controllerView.addReceiver(self)
self.emulatorCore.setGameController(self.controllerView, atIndex: 0)
self.updateControllers()
}
override func viewDidAppear(animated: Bool)
@ -62,8 +67,16 @@ class EmulationViewController: UIViewController
{
super.viewDidLayoutSubviews()
let scale = self.view.bounds.width / self.controllerView.intrinsicContentSize().width
self.controllerViewHeightConstraint.constant = self.controllerView.intrinsicContentSize().height * scale
if Settings.localControllerPlayerIndex != nil
{
let scale = self.view.bounds.width / self.controllerView.intrinsicContentSize().width
self.controllerViewHeightConstraint.constant = self.controllerView.intrinsicContentSize().height * scale
}
else
{
self.controllerViewHeightConstraint.constant = 0
}
}
override func prefersStatusBarHidden() -> Bool
@ -82,6 +95,28 @@ class EmulationViewController: UIViewController
self.controllerView.finishAnimatingUpdateControllerSkin()
}
}
//MARK: - Controllers -
/// Controllers
func updateControllers()
{
self.emulatorCore.removeAllGameControllers()
if let index = Settings.localControllerPlayerIndex
{
self.emulatorCore.setGameController(self.controllerView, atIndex: index)
}
for controller in ExternalControllerManager.sharedManager.connectedControllers
{
if let index = controller.playerIndex
{
self.emulatorCore.setGameController(controller, atIndex: index)
}
}
self.view.setNeedsLayout()
}
}
//MARK: - <GameControllerReceiver> -