diff --git a/flixel/input/gamepad/FlxGamepad.hx b/flixel/input/gamepad/FlxGamepad.hx index 93a1a3c69d..ab3931eb78 100644 --- a/flixel/input/gamepad/FlxGamepad.hx +++ b/flixel/input/gamepad/FlxGamepad.hx @@ -4,20 +4,20 @@ import flixel.input.FlxInput.FlxInputState; import flixel.input.gamepad.FlxGamepadInputID; import flixel.input.gamepad.id.FlxGamepadAnalogList; import flixel.input.gamepad.id.FlxGamepadButtonList; +import flixel.input.gamepad.id.FlxGamepadMotionValueList; +import flixel.input.gamepad.id.FlxGamepadPointerValueList; +import flixel.input.gamepad.id.WiiRemoteID; import flixel.math.FlxPoint; import flixel.math.FlxVector; import flixel.util.FlxDestroyUtil; import flixel.util.FlxStringUtil; +import flixel.util.FlxTimer; #if FLX_GAMEINPUT_API import flash.ui.GameInputControl; import flash.ui.GameInputDevice; #end -#if flash -import flash.system.Capabilities; -#end - @:allow(flixel.input.gamepad) class FlxGamepad implements IFlxDestroyable { @@ -32,6 +32,18 @@ class FlxGamepad implements IFlxDestroyable */ public var model(default, set):FlxGamepadModel; + /** + * For gamepads that can have things plugged into them (the Wii Remote, basically). + * Making the user set this helps Flixel properly interpret inputs properly. + * EX: if you plug a nunchuk into the Wii Remote, you will get different values for + * certain buttons than with the Wii Remote alone. + * (This is probably why Wii games ask the player what control scheme they are using.) + * + * In the future, this could also be used for any attachment that exposes new API features + * to the controller, e.g. a microphone or headset + */ + public var attachment(default, set):FlxGamepadModelAttachment; + /** * The gamepad model this gamepad has been identified as. */ @@ -63,6 +75,15 @@ class FlxGamepad implements IFlxDestroyable * Helper class to get the justMoved, justReleased, and float values of analog input. */ public var analog(default, null):FlxGamepadAnalogList; + /** + * Helper class to get the float values of motion-sensing input, if it is supported + */ + public var motion(default, null):FlxGamepadMotionValueList; + /** + * Helper class to get the float values of mouse-like pointer input, if it is supported. + * (contains continously updated X and Y coordinates, each between 0.0 and 1.0) + */ + public var pointer(default, null):FlxGamepadPointerValueList; #if FLX_JOYSTICK_API public var hat(default, null):FlxPoint = FlxPoint.get(); @@ -75,51 +96,59 @@ class FlxGamepad implements IFlxDestroyable private var manager:FlxGamepadManager; private var _deadZone:Float = 0.15; - #if FLX_JOYSTICK_API private var leftStick:FlxGamepadAnalogStick; private var rightStick:FlxGamepadAnalogStick; - #elseif FLX_GAMEINPUT_API + #if FLX_GAMEINPUT_API private var _device:GameInputDevice; #end - #if flash - private var _isChrome:Bool = false; - #end - - public function new(ID:Int, Manager:FlxGamepadManager, ?Model:FlxGamepadModel) + public function new(ID:Int, Manager:FlxGamepadManager, ?Model:FlxGamepadModel, ?Attachment:FlxGamepadModelAttachment) { id = ID; manager = Manager; + pressed = new FlxGamepadButtonList(FlxInputState.PRESSED, this); + justPressed = new FlxGamepadButtonList(FlxInputState.JUST_PRESSED, this); + justReleased = new FlxGamepadButtonList(FlxInputState.JUST_RELEASED, this); + analog = new FlxGamepadAnalogList(this); + motion = new FlxGamepadMotionValueList(this); + pointer = new FlxGamepadPointerValueList(this); + if (Model == null) Model = XBox360; + + if (Attachment == null) + Attachment = None; - buttonIndex = new FlxGamepadMapping(model); + buttonIndex = new FlxGamepadMapping(model, attachment); model = Model; detectedModel = Model; - - #if flash - _isChrome = (Capabilities.manufacturer == "Google Pepper"); - #end - - pressed = new FlxGamepadButtonList(FlxInputState.PRESSED, this); - justPressed = new FlxGamepadButtonList(FlxInputState.JUST_PRESSED, this); - justReleased = new FlxGamepadButtonList(FlxInputState.JUST_RELEASED, this); - analog = new FlxGamepadAnalogList(this); } public function set_model(Model:FlxGamepadModel):FlxGamepadModel { model = Model; buttonIndex.model = Model; - #if FLX_JOYSTICK_API + + motion.isSupported = buttonIndex.supportsMotion(); + pointer.isSupported = buttonIndex.supportsPointer(); + leftStick = getRawAnalogStick(FlxGamepadInputID.LEFT_ANALOG_STICK); rightStick = getRawAnalogStick(FlxGamepadInputID.RIGHT_ANALOG_STICK); - #end + return model; } + public function set_attachment(Attachment:FlxGamepadModelAttachment):FlxGamepadModelAttachment + { + attachment = Attachment; + buttonIndex.attachment = Attachment; + leftStick = getRawAnalogStick(FlxGamepadInputID.LEFT_ANALOG_STICK); + rightStick = getRawAnalogStick(FlxGamepadInputID.RIGHT_ANALOG_STICK); + return attachment; + } + /** * Returns the "universal" gamepad input ID Given a raw integer. */ @@ -143,6 +172,7 @@ class FlxGamepad implements IFlxDestroyable public function getButton(RawID:Int):FlxGamepadButton { + if (RawID == -1) return null; var gamepadButton:FlxGamepadButton = buttons[RawID]; if (gamepadButton == null) @@ -154,6 +184,11 @@ class FlxGamepad implements IFlxDestroyable return gamepadButton; } + public inline function getFlipAxis(AxisID:Int):Int + { + return buttonIndex.getFlipAxis(AxisID); + } + /** * Updates the key states (for tracking just pressed, just released, etc). */ @@ -171,6 +206,7 @@ class FlxGamepad implements IFlxDestroyable for (i in 0..._device.numControls) { control = _device.getControlAt(i); + var value = control.value; value = Math.abs(value); //quick absolute value for analog sticks button = getButton(i); @@ -184,6 +220,7 @@ class FlxGamepad implements IFlxDestroyable button.press(); } } + #elseif FLX_JOYSTICK_API for (i in 0...axis.length) { @@ -193,7 +230,7 @@ class FlxGamepad implements IFlxDestroyable if (button != null) { //TODO: account for circular deadzone if an analog stick input is detected? - var value = Math.abs(axis[i]); + var value = Math.abs(axis[i]) * getFlipAxis(i); if (value > deadZone) { button.press(); @@ -489,9 +526,28 @@ class FlxGamepad implements IFlxDestroyable * use this only for things like FlxGamepadButtonID.LEFT_TRIGGER, * use getXAxis() / getYAxis() for analog sticks! */ - public inline function getAxis(AxisButtonID:FlxGamepadInputID):Float + public function getAxis(AxisButtonID:FlxGamepadInputID):Float { - return getAxisRaw(getRawID(AxisButtonID)); + #if !FLX_JOYSTICK_API + return getAxisRaw(getRawID(AxisButtonID)); + #else + var fakeAxisRawID:Int = checkForFakeAxis(AxisButtonID); + + if (fakeAxisRawID == -1) + { + //return the regular axis value + var rawID = getRawID(AxisButtonID); + return getAxisRaw(rawID) * getFlipAxis(AxisButtonID); + } + else + { + //if analog isn't supported for this input, return the correct digital button input instead + var btn = getButton(fakeAxisRawID); + if (btn == null) return 0; + if (btn.pressed) return 1; + } + return 0; + #end } /** @@ -518,15 +574,37 @@ class FlxGamepad implements IFlxDestroyable return buttonIndex.axisIndexToRawID(AxisIndex); } - public inline function isAxisForAnalogStick(AxisIndex:Int):Bool + public inline function checkForFakeAxis(ID:FlxGamepadInputID):Int { - return AxisIndex == leftStick.x || - AxisIndex == leftStick.y || - AxisIndex == rightStick.x || - AxisIndex == rightStick.y; + return buttonIndex.checkForFakeAxis(ID); } #end + public function isAxisForMotion(AxisIndex:Int):Bool + { + return buttonIndex.isAxisForMotion(AxisIndex); + } + + public function isAxisForAnalogStick(AxisIndex:Int):Bool + { + if (leftStick != null) + { + if (AxisIndex == leftStick.x || AxisIndex == leftStick.y) return true; + } + if (rightStick != null) + { + if (AxisIndex == rightStick.x || AxisIndex == rightStick.y) return true; + } + return false; + } + + public inline function getAnalogStickByAxis(AxisIndex:Int):FlxGamepadAnalogStick + { + if (leftStick != null && AxisIndex == leftStick.x || AxisIndex == leftStick.y) return leftStick; + if (rightStick != null && AxisIndex == rightStick.x || AxisIndex == rightStick.y) return rightStick; + return null; + } + /** * Given a ButtonID for an analog stick, gets the value of its x axis * @param AxesButtonID an analog stick like FlxGamepadButtonID.LEFT_STICK @@ -559,17 +637,7 @@ class FlxGamepad implements IFlxDestroyable */ public function getYAxisRaw(Stick:FlxGamepadAnalogStick):Float { - var axisValue = getAnalogYAxisValue(Stick); - - // the y axis is inverted on the Xbox gamepad in flash for some reason - but not in Chrome! - #if flash - if (model == XBox360 && !_isChrome) - { - axisValue = -axisValue; - } - #end - - return axisValue; + return getAnalogYAxisValue(Stick); } /** @@ -625,6 +693,10 @@ class FlxGamepad implements IFlxDestroyable var axisValue:Float = 0; #if FLX_GAMEINPUT_API + if (AxisID == -1) + { + return 0; + } if ((_device != null) && _device.enabled) { axisValue = _device.getControlAt(AxisID).value; @@ -638,11 +710,17 @@ class FlxGamepad implements IFlxDestroyable axisValue = axis[AxisID]; #end + if (isAxisForAnalogStick(AxisID)) + { + axisValue *= getFlipAxis(AxisID); + } + return axisValue; } private function getAnalogXAxisValue(stick:FlxGamepadAnalogStick):Float { + if (stick == null) return 0; return if (deadZoneMode == CIRCULAR) getAnalogAxisValueCircular(stick, stick.x); else @@ -651,6 +729,7 @@ class FlxGamepad implements IFlxDestroyable private function getAnalogYAxisValue(stick:FlxGamepadAnalogStick):Float { + if (stick == null) return 0; return if (deadZoneMode == CIRCULAR) getAnalogAxisValueCircular(stick, stick.y); else @@ -659,6 +738,7 @@ class FlxGamepad implements IFlxDestroyable private function getAnalogAxisValueCircular(stick:FlxGamepadAnalogStick, axisID:Int):Float { + if (stick == null) return 0; var xAxis = getAxisValue(stick.x); var yAxis = getAxisValue(stick.y); @@ -719,13 +799,75 @@ class FlxGamepadAnalogStick public var x(default, null):Int; public var y(default, null):Int; - public function new(x:Int, y:Int) + /**a raw button input ID, for sending a digital event for "up" alongside the analog event**/ + public var rawUp(default, null):Int = -1; + /**a raw button input ID, for sending a digital event for "down" alongside the analog event**/ + public var rawDown(default, null):Int = -1; + /**a raw button input ID, for sending a digital event for "left" alongside the analog event**/ + public var rawLeft(default, null):Int = -1; + /**a raw button input ID, for sending a digital event for "right" alongside the analog event**/ + public var rawRight(default, null):Int = -1; + + /**the absolute value the dpad must be greater than before digital inputs are sent**/ + public var digitalThreshold(default, null):Float = 0.5; + + /**when analog inputs are received, how to process them digitally**/ + public var mode(default, null):FlxAnalogToDigitalMode = OnlyAnalog; + + public function new(x:Int, y:Int, ?settings:FlxGamepadAnalogStickSettings) { this.x = x; this.y = y; + if (settings != null) + { + mode = (settings.mode != null ? settings.mode : OnlyAnalog); + rawUp = (settings.up != null ? settings.up : -1); + rawDown = (settings.down != null ? settings.down : -1); + rawLeft = (settings.left != null ? settings.left : -1); + rawRight = (settings.right != null ? settings.right : -1); + digitalThreshold = (settings.threshold != null ? settings.threshold : -1); + } + } + + public function toString():String + { + return FlxStringUtil.getDebugString([ + LabelValuePair.weak("x", x), + LabelValuePair.weak("y", y), + LabelValuePair.weak("rawUp", rawUp), + LabelValuePair.weak("rawDown", rawDown), + LabelValuePair.weak("rawLeft", rawLeft), + LabelValuePair.weak("rawRight", rawRight), + LabelValuePair.weak("digitalThreshold", digitalThreshold), + LabelValuePair.weak("mode", mode)]); } } +typedef FlxGamepadAnalogStickSettings = { + ?up:Int, + ?down:Int, + ?left:Int, + ?right:Int, + ?threshold:Float, + ?mode:FlxAnalogToDigitalMode +} + +enum FlxAnalogToDigitalMode +{ + /** + * Send both digital and analog events when the analog stick is moved + */ + Both; + /** + * Send only digital events when the analog stick is moved + */ + OnlyDigital; + /** + * Send only analog events when the analog stick is moved + */ + OnlyAnalog; +} + enum FlxGamepadModel { Logitech; @@ -734,4 +876,13 @@ enum FlxGamepadModel PS4; XBox360; XInput; + MayflashWiiRemote; + WiiRemote; +} + +enum FlxGamepadModelAttachment +{ + WiiNunchuk; + WiiClassicController; + None; } \ No newline at end of file diff --git a/flixel/input/gamepad/FlxGamepadInputID.hx b/flixel/input/gamepad/FlxGamepadInputID.hx index 533cfc853a..e37ebf2d61 100644 --- a/flixel/input/gamepad/FlxGamepadInputID.hx +++ b/flixel/input/gamepad/FlxGamepadInputID.hx @@ -70,6 +70,25 @@ abstract FlxGamepadInputID(Int) from Int to Int var LEFT_STICK_FAKE = 24; var RIGHT_STICK_FAKE = 25; #end + + /**tilting towards or away from the ceiling (think "look up", "look down")**/ + var TILT_PITCH = 26; + /**tilting side-to-side (think "twisting", or "do a barrel roll!")**/ + var TILT_ROLL = 27; + + /**for a mouse-like input such as touch or IR camera. Horizontal axis.**/ + var POINTER_X = 28; + /**for a mouse-like input such as touch or IR camera. Vertical axis.**/ + var POINTER_Y = 29; + + /**an extra digital button that doesn't fit cleanly into the universal template**/ + var EXTRA_0 = 30; + /**an extra digital button that doesn't fit cleanly into the universal template**/ + var EXTRA_1 = 31; + /**an extra digital button that doesn't fit cleanly into the universal template**/ + var EXTRA_2 = 32; + /**an extra digital button that doesn't fit cleanly into the universal template**/ + var EXTRA_3 = 33; @:from public static inline function fromString(s:String) diff --git a/flixel/input/gamepad/FlxGamepadManager.hx b/flixel/input/gamepad/FlxGamepadManager.hx index f864967b03..d98e9bc9f0 100644 --- a/flixel/input/gamepad/FlxGamepadManager.hx +++ b/flixel/input/gamepad/FlxGamepadManager.hx @@ -437,13 +437,18 @@ class FlxGamepadManager implements IFlxInputManager } } + //"Sony PLAYSTATION(R)3 Controller" is the PS3 controller, but that is not supported as its PC drivers are terrible, + //and the most popular tools just turn it into a 360 controller + // needs to be checked even though it's default to not mistake it for XInput on flash return if (str.contains("xbox") && str.contains("360")) XBox360; - else if (str.contains("playstation")) PS3; //"Sony PLAYSTATION(R)3 Controller" - else if (str.contains("ouya")) OUYA; //"OUYA Game Controller" + else if (str.contains("ouya")) OUYA; //"OUYA Game Controller" else if (str.contains("wireless controller") || str.contains("ps4")) PS4; //"Wireless Controller" or "PS4 controller" else if (str.contains("logitech")) Logitech; else if (str.contains("xinput")) XInput; + else if (str.contains("nintendo rvlcnt01tr")) WiiRemote; //WiiRemote with motion plus + else if (str.contains("nintendo rvlcnt01")) WiiRemote; //WiiRemote w/o motion plus + else if (str.contains("mayflash wiimote pc adapter")) MayflashWiiRemote; //WiiRemote paired to MayFlash DolphinBar (with or w/o motion plus) else XBox360; //default } @@ -464,25 +469,27 @@ class FlxGamepadManager implements IFlxInputManager #end #if FLX_JOYSTICK_API - private function handleButtonDown(FlashEvent:JoystickEvent):Void + private function getModelFromJoystick(f:Float):FlxGamepadModel { - var gamepad:FlxGamepad = createByID(FlashEvent.device); - var button:FlxGamepadButton = gamepad.getButton(FlashEvent.id); + //id "1" is PS3, but that is not supported as its PC drivers are terrible, and the most popular tools just turn it into a 360 controller - if (button != null) + return switch (Math.round(f)) { - button.press(); + case 2: PS4; + case 3: OUYA; + case 4: MayflashWiiRemote; + case 5: WiiRemote; + default: XBox360; } } - private function getModelFromJoystick(f:Float):FlxGamepadModel + private function handleButtonDown(FlashEvent:JoystickEvent):Void { - return switch (Math.round(f)) + var gamepad:FlxGamepad = createByID(FlashEvent.device); + var button:FlxGamepadButton = gamepad.getButton(FlashEvent.id); + if (button != null) { - case 1: PS3; - case 2: PS4; - case 3: OUYA; - default: XBox360; + button.press(); } } @@ -490,7 +497,6 @@ class FlxGamepadManager implements IFlxInputManager { var gamepad:FlxGamepad = createByID(FlashEvent.device); var button:FlxGamepadButton = gamepad.getButton(FlashEvent.id); - if (button != null) { button.release(); @@ -500,16 +506,71 @@ class FlxGamepadManager implements IFlxInputManager private function handleAxisMove(FlashEvent:JoystickEvent):Void { var gamepad:FlxGamepad = createByID(FlashEvent.device); - gamepad.axis = FlashEvent.axis; - for (i in 0...gamepad.axis.length) + + var oldAxis = gamepad.axis; + var newAxis = FlashEvent.axis; + + for (i in 0...newAxis.length) { - if (!gamepad.isAxisForAnalogStick(i)) + var isForStick = gamepad.isAxisForAnalogStick(i); + var isForMotion = gamepad.isAxisForMotion(i); + if (!isForStick && !isForMotion) { // in legacy this returns a (-1,1) range, but in flash/next it // returns (0,1) so we normalize to (0,1) for legacy target only - gamepad.axis[i] = (gamepad.axis[i] + 1) / 2; + newAxis[i] = (newAxis[i] + 1) / 2; + } + else if(isForStick) + { + //check to see if we should send digital inputs as well as analog + var stick:FlxGamepadAnalogStick = gamepad.getAnalogStickByAxis(i); + if (stick.mode == OnlyDigital || stick.mode == Both) + { + var newVal = newAxis[i]; + var oldVal = oldAxis[i]; + + var neg = stick.digitalThreshold * -1; + var pos = stick.digitalThreshold; + var digitalButton = -1; + + //pressed/released for digital LEFT/UP + if (newVal < neg && oldVal >= neg) + { + if (i == stick.x) digitalButton = stick.rawLeft; + else if (i == stick.y) digitalButton = stick.rawUp; + handleButtonDown(new JoystickEvent(JoystickEvent.BUTTON_DOWN, FlashEvent.bubbles, FlashEvent.cancelable, FlashEvent.device, digitalButton)); + } + else if (newVal >= neg && oldVal < neg) + { + if (i == stick.x) digitalButton = stick.rawLeft; + else if (i == stick.y) digitalButton = stick.rawUp; + handleButtonUp(new JoystickEvent(JoystickEvent.BUTTON_UP, FlashEvent.bubbles, FlashEvent.cancelable, FlashEvent.device, digitalButton)); + } + + //pressed/released for digital RIGHT/DOWN + if (newVal > pos && oldVal <= pos) + { + if (i == stick.x) digitalButton = stick.rawRight; + else if (i == stick.y) digitalButton = stick.rawDown; + handleButtonDown(new JoystickEvent(JoystickEvent.BUTTON_DOWN, FlashEvent.bubbles, FlashEvent.cancelable, FlashEvent.device, digitalButton)); + } + else if (newVal <= pos && oldVal > pos) + { + if (i == stick.x) digitalButton = stick.rawRight; + else if (i == stick.y) digitalButton = stick.rawDown; + handleButtonUp(new JoystickEvent(JoystickEvent.BUTTON_UP, FlashEvent.bubbles, FlashEvent.cancelable, FlashEvent.device, digitalButton)); + } + + if (stick.mode == OnlyDigital) + { + //still haven't figured out how to suppress the analog inputs properly. Oh well. + } + } } } + + gamepad.axis = newAxis; + gamepad.axisActive = true; } diff --git a/flixel/input/gamepad/FlxGamepadMapping.hx b/flixel/input/gamepad/FlxGamepadMapping.hx index 5e4016139e..a83bec8986 100644 --- a/flixel/input/gamepad/FlxGamepadMapping.hx +++ b/flixel/input/gamepad/FlxGamepadMapping.hx @@ -2,14 +2,20 @@ package flixel.input.gamepad; import flixel.input.gamepad.FlxGamepad.FlxGamepadAnalogStick; import flixel.input.gamepad.FlxGamepad.FlxGamepadModel; +import flixel.input.gamepad.FlxGamepad.FlxGamepadModelAttachment; import flixel.input.gamepad.FlxGamepadInputID; import flixel.input.gamepad.id.LogitechID; import flixel.input.gamepad.id.OUYAID; -import flixel.input.gamepad.id.PS3ID; import flixel.input.gamepad.id.PS4ID; +import flixel.input.gamepad.id.MayflashWiiRemoteID; +import flixel.input.gamepad.id.WiiRemoteID; import flixel.input.gamepad.id.XBox360ID; import flixel.input.gamepad.id.XInputID; +#if flash +import openfl.system.Capabilities; +#end + /** * ... * @author larsiusprime @@ -19,11 +25,24 @@ class FlxGamepadMapping @:allow(flixel.input.gamepad.FlxGamepad) public var model(default, null):FlxGamepadModel; - public function new(Model:FlxGamepadModel) + @:allow(flixel.input.gamepad.FlxGamepad) + public var attachment(default, null):FlxGamepadModelAttachment = None; + + private var _manufacturer:Manufacturer = Unknown; + + public function new(Model:FlxGamepadModel, attachment:FlxGamepadModelAttachment=null) { model = Model; + #if flash + _manufacturer = switch(Capabilities.manufacturer) + { + case "Google Pepper": GooglePepper; + case "Adobe Windows": AdobeWindows; + default: Unknown; + } + #end } - + /** * Given a ID, return the raw hardware code * @param ID the "universal" ID @@ -35,10 +54,23 @@ class FlxGamepadMapping { case Logitech: getRawLogitech(ID); case OUYA: getRawOUYA(ID); - case PS3: getRawPS3(ID); case PS4: getRawPS4(ID); case XBox360: getRawXBox360(ID); case XInput: getRawXInput(ID); + case MayflashWiiRemote: + switch(attachment) + { + case WiiClassicController: getRawMayflashWiiClassicController(ID); + case WiiNunchuk: getRawMayflashWiiNunchuk(ID); + case None: getRawMayflashWiiRemote(ID); + } + case WiiRemote: + switch(attachment) + { + case WiiClassicController: getRawWiiClassicController(ID); + case WiiNunchuk: getRawWiiNunchuk(ID); + case None: getRawWiiRemote(ID); + } default: -1; } } @@ -54,10 +86,23 @@ class FlxGamepadMapping { case Logitech: getIDLogitech(RawID); case OUYA: getIDOUYA(RawID); - case PS3: getIDPS3(RawID); case PS4: getIDPS4(RawID); case XBox360: getIDXBox360(RawID); case XInput: getIDXInput(RawID); + case MayflashWiiRemote: + switch(attachment) + { + case WiiClassicController: getIDMayflashWiiClassicController(RawID); + case WiiNunchuk: getIDMayflashWiiNunchuk(RawID); + case None: getIDMayflashWiiRemote(RawID); + } + case WiiRemote: + switch(attachment) + { + case WiiClassicController: getIDWiiClassicController(RawID); + case WiiNunchuk: getIDWiiNunchuk(RawID); + case None: getIDWiiRemote(RawID); + } default: NONE; } } @@ -75,10 +120,21 @@ class FlxGamepadMapping { case Logitech: LogitechID.LEFT_ANALOG_STICK; case OUYA: OUYAID.LEFT_ANALOG_STICK; - case PS3: PS3ID.LEFT_ANALOG_STICK; case PS4: PS4ID.LEFT_ANALOG_STICK; case XBox360: XBox360ID.LEFT_ANALOG_STICK; case XInput: XInputID.LEFT_ANALOG_STICK; + case MayflashWiiRemote: + switch(attachment) + { + case WiiNunchuk, WiiClassicController: MayflashWiiRemoteID.LEFT_ANALOG_STICK; + case None: MayflashWiiRemoteID.REMOTE_DPAD; + } + case WiiRemote: + switch(attachment) + { + case WiiNunchuk, WiiClassicController: WiiRemoteID.LEFT_ANALOG_STICK; + case None: WiiRemoteID.REMOTE_DPAD; + } default: null; } } @@ -88,16 +144,46 @@ class FlxGamepadMapping { case Logitech: LogitechID.RIGHT_ANALOG_STICK; case OUYA: OUYAID.RIGHT_ANALOG_STICK; - case PS3: PS3ID.RIGHT_ANALOG_STICK; case PS4: PS4ID.RIGHT_ANALOG_STICK; case XBox360: XBox360ID.RIGHT_ANALOG_STICK; case XInput: XInputID.RIGHT_ANALOG_STICK; + case MayflashWiiRemote: + switch(attachment) + { + case WiiClassicController: MayflashWiiRemoteID.RIGHT_ANALOG_STICK; + default: null; + } + case WiiRemote: + switch(attachment) + { + case WiiClassicController: WiiRemoteID.RIGHT_ANALOG_STICK; + default: null; + } default: null; } } return null; } + /** + * Returns 1 or -1 depending on whether this axis needs to be flipped + */ + public function getFlipAxis(AxisID:Int):Int + { + return switch (model) + { + case Logitech: LogitechID.getFlipAxis(AxisID); + case OUYA: OUYAID.getFlipAxis(AxisID); + case PS4: PS4ID.getFlipAxis(AxisID); + case XBox360: XBox360ID.getFlipAxis(AxisID, _manufacturer); + case XInput: XInputID.getFlipAxis(AxisID); + case MayflashWiiRemote: MayflashWiiRemoteID.getFlipAxis(AxisID, attachment); + case WiiRemote: WiiRemoteID.getFlipAxis(AxisID, attachment); + default: -1; + } + } + + #if FLX_JOYSTICK_API /** * Given an axis index value like 0-6, figures out which input that corresponds to and returns a "fake" ButtonID for that input @@ -108,15 +194,72 @@ class FlxGamepadMapping { case Logitech: LogitechID.axisIndexToRawID(AxisID); case OUYA: OUYAID.axisIndexToRawID(AxisID); - case PS3: PS3ID.axisIndexToRawID(AxisID); case PS4: PS4ID.axisIndexToRawID(AxisID); case XBox360: XBox360ID.axisIndexToRawID(AxisID); case XInput: XInputID.axisIndexToRawID(AxisID); + case MayflashWiiRemote: MayflashWiiRemoteID.axisIndexToRawID(AxisID, attachment); + case WiiRemote: WiiRemoteID.axisIndexToRawID(AxisID, attachment); default: -1; } } + + public function checkForFakeAxis(ID:FlxGamepadInputID):Int + { + return switch (model) + { + case MayflashWiiRemote: MayflashWiiRemoteID.checkForFakeAxis(ID, attachment); + case WiiRemote: WiiRemoteID.checkForFakeAxis(ID, attachment); + default: -1; + } + } + #end + public function isAxisForMotion(ID:FlxGamepadInputID):Bool + { + return switch (model) + { + case Logitech: LogitechID.isAxisForMotion(ID); + case OUYA: OUYAID.isAxisForMotion(ID); + case PS4: PS4ID.isAxisForMotion(ID); + case XBox360: XBox360ID.isAxisForMotion(ID); + case XInput: XInputID.isAxisForMotion(ID); + case MayflashWiiRemote: MayflashWiiRemoteID.isAxisForMotion(ID, attachment); + case WiiRemote: WiiRemoteID.isAxisForMotion(ID, attachment); + default: false; + } + } + + public function supportsMotion():Bool + { + return switch (model) + { + case Logitech: LogitechID.SUPPORTS_MOTION; + case OUYA: OUYAID.SUPPORTS_MOTION; + case PS4: PS4ID.SUPPORTS_MOTION; + case XBox360: XBox360ID.SUPPORTS_MOTION; + case XInput: XInputID.SUPPORTS_MOTION; + case MayflashWiiRemote: MayflashWiiRemoteID.SUPPORTS_MOTION; + case WiiRemote: WiiRemoteID.SUPPORTS_MOTION; + default: false; + } + } + + public function supportsPointer():Bool + { + return switch (model) + { + case Logitech: LogitechID.SUPPORTS_POINTER; + case OUYA: OUYAID.SUPPORTS_POINTER; + case PS4: PS4ID.SUPPORTS_POINTER; + case XBox360: XBox360ID.SUPPORTS_POINTER; + case XInput: XInputID.SUPPORTS_POINTER; + case MayflashWiiRemote: MayflashWiiRemoteID.SUPPORTS_POINTER; + case WiiRemote: WiiRemoteID.SUPPORTS_POINTER; + default: false; + } + } + public function getRawOUYA(ID:FlxGamepadInputID):Int { return switch (ID) @@ -198,35 +341,6 @@ class FlxGamepadMapping } } - public function getRawPS3(ID:FlxGamepadInputID):Int - { - return switch (ID) - { - case A: PS3ID.X; - case B: PS3ID.CIRCLE; - case X: PS3ID.SQUARE; - case Y: PS3ID.TRIANGLE; - case BACK: PS3ID.SELECT; - case GUIDE: PS3ID.PS; - case START: PS3ID.START; - case LEFT_STICK_CLICK: PS3ID.LEFT_STICK_CLICK; - case RIGHT_STICK_CLICK: PS3ID.RIGHT_STICK_CLICK; - case LEFT_SHOULDER: PS3ID.L1; - case RIGHT_SHOULDER: PS3ID.R1; - case DPAD_UP: PS3ID.DPAD_UP; - case DPAD_DOWN: PS3ID.DPAD_DOWN; - case DPAD_LEFT: PS3ID.DPAD_LEFT; - case DPAD_RIGHT: PS3ID.DPAD_RIGHT; - case LEFT_TRIGGER: PS3ID.L2; - case RIGHT_TRIGGER: PS3ID.R2; - #if FLX_JOYSTICK_API - case LEFT_TRIGGER_FAKE: PS3ID.LEFT_TRIGGER_FAKE; - case RIGHT_TRIGGER_FAKE: PS3ID.RIGHT_TRIGGER_FAKE; - #end - default: -1; - } - } - public function getRawXBox360(ID:FlxGamepadInputID):Int { return switch (ID) @@ -285,6 +399,142 @@ class FlxGamepadMapping } } + public function getRawMayflashWiiClassicController(ID:FlxGamepadInputID):Int + { + return switch (ID) + { + case A: MayflashWiiRemoteID.CLASSIC_B; + case B: MayflashWiiRemoteID.CLASSIC_A; + case X: MayflashWiiRemoteID.CLASSIC_Y; + case Y: MayflashWiiRemoteID.CLASSIC_X; + case DPAD_UP: MayflashWiiRemoteID.CLASSIC_DPAD_UP; + case DPAD_DOWN: MayflashWiiRemoteID.CLASSIC_DPAD_DOWN; + case DPAD_LEFT: MayflashWiiRemoteID.CLASSIC_DPAD_LEFT; + case DPAD_RIGHT: MayflashWiiRemoteID.CLASSIC_DPAD_RIGHT; + case BACK: MayflashWiiRemoteID.CLASSIC_SELECT; + case GUIDE: MayflashWiiRemoteID.CLASSIC_HOME; + case START: MayflashWiiRemoteID.CLASSIC_START; + case LEFT_SHOULDER: MayflashWiiRemoteID.CLASSIC_ZL; + case RIGHT_SHOULDER: MayflashWiiRemoteID.CLASSIC_ZR; + case LEFT_TRIGGER: MayflashWiiRemoteID.CLASSIC_L; + case RIGHT_TRIGGER: MayflashWiiRemoteID.CLASSIC_R; + case EXTRA_0: MayflashWiiRemoteID.CLASSIC_ONE; + case EXTRA_1: MayflashWiiRemoteID.CLASSIC_TWO; + default: getRawMayflashWiiRemote(ID); + } + } + + public function getRawMayflashWiiNunchuk(ID:FlxGamepadInputID):Int + { + return switch (ID) + { + case A: MayflashWiiRemoteID.NUNCHUK_A; + case B: MayflashWiiRemoteID.NUNCHUK_B; + case X: MayflashWiiRemoteID.NUNCHUK_ONE; + case Y: MayflashWiiRemoteID.NUNCHUK_TWO; + case BACK: MayflashWiiRemoteID.NUNCHUK_MINUS; + case START: MayflashWiiRemoteID.NUNCHUK_PLUS; + case GUIDE: MayflashWiiRemoteID.NUNCHUK_HOME; + case LEFT_SHOULDER: MayflashWiiRemoteID.NUNCHUK_C; + case LEFT_TRIGGER: MayflashWiiRemoteID.NUNCHUK_Z; + case DPAD_UP: MayflashWiiRemoteID.NUNCHUK_DPAD_UP; + case DPAD_DOWN: MayflashWiiRemoteID.NUNCHUK_DPAD_DOWN; + case DPAD_LEFT: MayflashWiiRemoteID.NUNCHUK_DPAD_LEFT; + case DPAD_RIGHT: MayflashWiiRemoteID.NUNCHUK_DPAD_RIGHT; + case POINTER_X: MayflashWiiRemoteID.NUNCHUK_POINTER_X; + case POINTER_Y: MayflashWiiRemoteID.NUNCHUK_POINTER_Y; + default: -1; + } + } + + public function getRawMayflashWiiRemote(ID:FlxGamepadInputID):Int + { + return switch (ID) + { + case A: MayflashWiiRemoteID.REMOTE_A; + case B: MayflashWiiRemoteID.REMOTE_B; + case X: MayflashWiiRemoteID.REMOTE_ONE; + case Y: MayflashWiiRemoteID.REMOTE_TWO; + case DPAD_UP: MayflashWiiRemoteID.REMOTE_DPAD_UP; + case DPAD_DOWN: MayflashWiiRemoteID.REMOTE_DPAD_DOWN; + case DPAD_LEFT: MayflashWiiRemoteID.REMOTE_DPAD_LEFT; + case DPAD_RIGHT: MayflashWiiRemoteID.REMOTE_DPAD_RIGHT; + case BACK: MayflashWiiRemoteID.REMOTE_MINUS; + case GUIDE: MayflashWiiRemoteID.REMOTE_HOME; + case START: MayflashWiiRemoteID.REMOTE_PLUS; + default: -1; + } + } + + public function getRawWiiClassicController(ID:FlxGamepadInputID):Int + { + return switch (ID) + { + case A: WiiRemoteID.CLASSIC_B; + case B: WiiRemoteID.CLASSIC_A; + case X: WiiRemoteID.CLASSIC_Y; + case Y: WiiRemoteID.CLASSIC_X; + case DPAD_UP: WiiRemoteID.CLASSIC_DPAD_UP; + case DPAD_DOWN: WiiRemoteID.CLASSIC_DPAD_DOWN; + case DPAD_LEFT: WiiRemoteID.CLASSIC_DPAD_LEFT; + case DPAD_RIGHT: WiiRemoteID.CLASSIC_DPAD_RIGHT; + case BACK: WiiRemoteID.CLASSIC_SELECT; + case GUIDE: WiiRemoteID.CLASSIC_HOME; + case START: WiiRemoteID.CLASSIC_START; + case LEFT_SHOULDER: WiiRemoteID.CLASSIC_ZL; + case RIGHT_SHOULDER: WiiRemoteID.CLASSIC_ZR; + case LEFT_TRIGGER: WiiRemoteID.CLASSIC_L; + case RIGHT_TRIGGER: WiiRemoteID.CLASSIC_R; + case EXTRA_0: WiiRemoteID.CLASSIC_ONE; + case EXTRA_1: WiiRemoteID.CLASSIC_TWO; + default: -1; + } + } + + public function getRawWiiNunchuk(ID:FlxGamepadInputID):Int + { + return switch (ID) + { + case A: WiiRemoteID.NUNCHUK_A; + case B: WiiRemoteID.NUNCHUK_B; + case LEFT_SHOULDER: WiiRemoteID.NUNCHUK_C; + case LEFT_TRIGGER: WiiRemoteID.NUNCHUK_Z; + case X: WiiRemoteID.NUNCHUK_ONE; + case Y: WiiRemoteID.NUNCHUK_TWO; + case BACK: WiiRemoteID.NUNCHUK_MINUS; + case START: WiiRemoteID.NUNCHUK_PLUS; + case GUIDE: WiiRemoteID.NUNCHUK_HOME; + case DPAD_UP: WiiRemoteID.NUNCHUK_DPAD_UP; + case DPAD_DOWN: WiiRemoteID.NUNCHUK_DPAD_DOWN; + case DPAD_LEFT: WiiRemoteID.NUNCHUK_DPAD_LEFT; + case DPAD_RIGHT: WiiRemoteID.NUNCHUK_DPAD_RIGHT; + case TILT_PITCH: WiiRemoteID.NUNCHUK_TILT_PITCH; + case TILT_ROLL: WiiRemoteID.NUNCHUK_TILT_ROLL; + default: -1; + } + } + + public function getRawWiiRemote(ID:FlxGamepadInputID):Int + { + return switch (ID) + { + case A: WiiRemoteID.REMOTE_A; + case B: WiiRemoteID.REMOTE_B; + case X: WiiRemoteID.REMOTE_ONE; + case Y: WiiRemoteID.REMOTE_TWO; + case DPAD_UP: WiiRemoteID.REMOTE_DPAD_UP; + case DPAD_DOWN: WiiRemoteID.REMOTE_DPAD_DOWN; + case DPAD_LEFT: WiiRemoteID.REMOTE_DPAD_LEFT; + case DPAD_RIGHT: WiiRemoteID.REMOTE_DPAD_RIGHT; + case BACK: WiiRemoteID.REMOTE_MINUS; + case GUIDE: WiiRemoteID.REMOTE_HOME; + case START: WiiRemoteID.REMOTE_PLUS; + case TILT_PITCH: WiiRemoteID.REMOTE_TILT_PITCH; + case TILT_ROLL: WiiRemoteID.REMOTE_TILT_ROLL; + default: -1; + } + } + public function getIDOUYA(rawID:Int):FlxGamepadInputID { return switch (rawID) @@ -356,31 +606,6 @@ class FlxGamepadMapping } } - public function getIDPS3(rawID:Int):FlxGamepadInputID - { - return switch (rawID) - { - case PS3ID.X: A; - case PS3ID.CIRCLE: B; - case PS3ID.SQUARE: X; - case PS3ID.TRIANGLE: Y; - case PS3ID.SELECT: BACK; - case PS3ID.PS: GUIDE; - case PS3ID.START: START; - case PS3ID.LEFT_STICK_CLICK: LEFT_STICK_CLICK; - case PS3ID.RIGHT_STICK_CLICK: RIGHT_STICK_CLICK; - case PS3ID.L1: LEFT_SHOULDER; - case PS3ID.R1: RIGHT_SHOULDER; - case PS3ID.L2: LEFT_TRIGGER; - case PS3ID.R2: RIGHT_TRIGGER; - case PS3ID.DPAD_UP: DPAD_UP; - case PS3ID.DPAD_DOWN: DPAD_DOWN; - case PS3ID.DPAD_LEFT: DPAD_LEFT; - case PS3ID.DPAD_RIGHT: DPAD_RIGHT; - default: NONE; - } - } - public function getIDXBox360(rawID:Int):FlxGamepadInputID { return switch (rawID) @@ -408,10 +633,10 @@ class FlxGamepadMapping { return switch (rawID) { - case XInputID.A: A; - case XInputID.B: B; - case XInputID.X: X; - case XInputID.Y: Y; + case XInputID.A: B; + case XInputID.B: A; + case XInputID.X: Y; + case XInputID.Y: X; case XInputID.BACK: BACK; case XInputID.GUIDE: GUIDE; case XInputID.START: START; @@ -428,4 +653,139 @@ class FlxGamepadMapping default: NONE; } } + + public function getIDMayflashWiiClassicController(rawID:Int):FlxGamepadInputID + { + return switch (rawID) + { + case MayflashWiiRemoteID.CLASSIC_A: B; + case MayflashWiiRemoteID.CLASSIC_B: A; + case MayflashWiiRemoteID.CLASSIC_X: Y; + case MayflashWiiRemoteID.CLASSIC_Y: X; + case MayflashWiiRemoteID.CLASSIC_SELECT: BACK; + case MayflashWiiRemoteID.CLASSIC_HOME: GUIDE; + case MayflashWiiRemoteID.CLASSIC_START: START; + case MayflashWiiRemoteID.CLASSIC_L: LEFT_TRIGGER; + case MayflashWiiRemoteID.CLASSIC_R: RIGHT_TRIGGER; + case MayflashWiiRemoteID.CLASSIC_ZL: LEFT_SHOULDER; + case MayflashWiiRemoteID.CLASSIC_ZR: RIGHT_SHOULDER; + case MayflashWiiRemoteID.CLASSIC_DPAD_UP: DPAD_UP; + case MayflashWiiRemoteID.CLASSIC_DPAD_DOWN: DPAD_DOWN; + case MayflashWiiRemoteID.CLASSIC_DPAD_LEFT: DPAD_LEFT; + case MayflashWiiRemoteID.CLASSIC_DPAD_RIGHT: DPAD_RIGHT; + default: NONE; + } + } + + public function getIDMayflashWiiNunchuk(rawID:Int):FlxGamepadInputID + { + return switch (rawID) + { + case MayflashWiiRemoteID.NUNCHUK_A: A; + case MayflashWiiRemoteID.NUNCHUK_B: B; + case MayflashWiiRemoteID.NUNCHUK_ONE: X; + case MayflashWiiRemoteID.NUNCHUK_TWO: Y; + case MayflashWiiRemoteID.NUNCHUK_MINUS: BACK; + case MayflashWiiRemoteID.NUNCHUK_PLUS: START; + case MayflashWiiRemoteID.NUNCHUK_HOME: GUIDE; + case MayflashWiiRemoteID.NUNCHUK_C: LEFT_SHOULDER; + case MayflashWiiRemoteID.NUNCHUK_Z: LEFT_TRIGGER; + case MayflashWiiRemoteID.NUNCHUK_DPAD_UP: DPAD_UP; + case MayflashWiiRemoteID.NUNCHUK_DPAD_DOWN: DPAD_DOWN; + case MayflashWiiRemoteID.NUNCHUK_DPAD_LEFT: DPAD_LEFT; + case MayflashWiiRemoteID.NUNCHUK_DPAD_RIGHT: DPAD_RIGHT; + default: NONE; + } + } + + public function getIDMayflashWiiRemote(rawID:Int):FlxGamepadInputID + { + return switch (rawID) + { + case MayflashWiiRemoteID.REMOTE_A: A; + case MayflashWiiRemoteID.REMOTE_B: B; + case MayflashWiiRemoteID.REMOTE_ONE: X; + case MayflashWiiRemoteID.REMOTE_TWO: Y; + case MayflashWiiRemoteID.REMOTE_MINUS: BACK; + case MayflashWiiRemoteID.REMOTE_HOME: GUIDE; + case MayflashWiiRemoteID.REMOTE_PLUS: START; + case MayflashWiiRemoteID.REMOTE_DPAD_UP: DPAD_UP; + case MayflashWiiRemoteID.REMOTE_DPAD_DOWN: DPAD_DOWN; + case MayflashWiiRemoteID.REMOTE_DPAD_LEFT: DPAD_LEFT; + case MayflashWiiRemoteID.REMOTE_DPAD_RIGHT: DPAD_RIGHT; + default: NONE; + } + } + + public function getIDWiiClassicController(rawID:Int):FlxGamepadInputID + { + return switch (rawID) + { + case WiiRemoteID.CLASSIC_A: B; + case WiiRemoteID.CLASSIC_B: A; + case WiiRemoteID.CLASSIC_X: Y; + case WiiRemoteID.CLASSIC_Y: X; + case WiiRemoteID.CLASSIC_SELECT: BACK; + case WiiRemoteID.CLASSIC_HOME: GUIDE; + case WiiRemoteID.CLASSIC_START: START; + case WiiRemoteID.CLASSIC_ZL: LEFT_SHOULDER; + case WiiRemoteID.CLASSIC_ZR: RIGHT_SHOULDER; + case WiiRemoteID.CLASSIC_L: LEFT_TRIGGER; + case WiiRemoteID.CLASSIC_R: RIGHT_TRIGGER; + case WiiRemoteID.CLASSIC_DPAD_UP: DPAD_UP; + case WiiRemoteID.CLASSIC_DPAD_DOWN: DPAD_DOWN; + case WiiRemoteID.CLASSIC_DPAD_LEFT: DPAD_LEFT; + case WiiRemoteID.CLASSIC_DPAD_RIGHT: DPAD_RIGHT; + case WiiRemoteID.CLASSIC_ONE: EXTRA_0; + case WiiRemoteID.CLASSIC_TWO: EXTRA_1; + default: NONE; + } + } + + public function getIDWiiNunchuk(rawID:Int):FlxGamepadInputID + { + return switch (rawID) + { + case WiiRemoteID.NUNCHUK_A: A; + case WiiRemoteID.NUNCHUK_B: B; + case WiiRemoteID.NUNCHUK_C: LEFT_SHOULDER; + case WiiRemoteID.NUNCHUK_Z: LEFT_TRIGGER; + case WiiRemoteID.NUNCHUK_ONE: X; + case WiiRemoteID.NUNCHUK_TWO: Y; + case WiiRemoteID.NUNCHUK_MINUS: BACK; + case WiiRemoteID.NUNCHUK_PLUS: START; + case WiiRemoteID.NUNCHUK_HOME: GUIDE; + case WiiRemoteID.NUNCHUK_DPAD_UP: DPAD_UP; + case WiiRemoteID.NUNCHUK_DPAD_DOWN: DPAD_DOWN; + case WiiRemoteID.NUNCHUK_DPAD_LEFT: DPAD_LEFT; + case WiiRemoteID.NUNCHUK_DPAD_RIGHT: DPAD_RIGHT; + default: NONE; + } + } + + public function getIDWiiRemote(rawID:Int):FlxGamepadInputID + { + return switch (rawID) + { + case WiiRemoteID.REMOTE_A: A; + case WiiRemoteID.REMOTE_B: B; + case WiiRemoteID.REMOTE_ONE: X; + case WiiRemoteID.REMOTE_TWO: Y; + case WiiRemoteID.REMOTE_MINUS: BACK; + case WiiRemoteID.REMOTE_HOME: GUIDE; + case WiiRemoteID.REMOTE_PLUS: START; + case WiiRemoteID.REMOTE_DPAD_UP: DPAD_UP; + case WiiRemoteID.REMOTE_DPAD_DOWN: DPAD_DOWN; + case WiiRemoteID.REMOTE_DPAD_LEFT: DPAD_LEFT; + case WiiRemoteID.REMOTE_DPAD_RIGHT: DPAD_RIGHT; + default: NONE; + } + } +} + +enum Manufacturer +{ + GooglePepper; + AdobeWindows; + Unknown; } \ No newline at end of file diff --git a/flixel/input/gamepad/id/FlxGamepadAnalogStateList.hx b/flixel/input/gamepad/id/FlxGamepadAnalogStateList.hx index a08ae4648d..d1412c0ce1 100644 --- a/flixel/input/gamepad/id/FlxGamepadAnalogStateList.hx +++ b/flixel/input/gamepad/id/FlxGamepadAnalogStateList.hx @@ -34,6 +34,7 @@ class FlxGamepadAnalogStateList private function checkXY(id:FlxGamepadInputID):Bool { var stick = gamepad.getRawAnalogStick(id); + if (stick == null) return false; //no matter what status we're checking for, we do two tests: //easy : both values are exactly the same (both JUST_PRESSED, both JUST_RELEASED) @@ -77,12 +78,16 @@ class FlxGamepadAnalogStateList private inline function checkX(id:FlxGamepadInputID):Bool { - return checkRaw(gamepad.getRawAnalogStick(id).x, status); + var stick = gamepad.getRawAnalogStick(id); + if (stick == null) return false; + return checkRaw(stick.x, status); } private inline function checkY(id:FlxGamepadInputID):Bool { - return checkRaw(gamepad.getRawAnalogStick(id).y, status); + var stick = gamepad.getRawAnalogStick(id); + if (stick == null) return false; + return checkRaw(stick.y, status); } private inline function checkRaw(RawID:Int, Status:FlxInputState):Bool diff --git a/flixel/input/gamepad/id/FlxGamepadAnalogValueList.hx b/flixel/input/gamepad/id/FlxGamepadAnalogValueList.hx index 784562869f..649a7f0762 100644 --- a/flixel/input/gamepad/id/FlxGamepadAnalogValueList.hx +++ b/flixel/input/gamepad/id/FlxGamepadAnalogValueList.hx @@ -18,6 +18,9 @@ class FlxGamepadAnalogValueList public var LEFT_TRIGGER (get, never):Float; inline function get_LEFT_TRIGGER() { return getAxis (FlxGamepadInputID.LEFT_TRIGGER); } public var RIGHT_TRIGGER (get, never):Float; inline function get_RIGHT_TRIGGER() { return getAxis (FlxGamepadInputID.RIGHT_TRIGGER); } + public var POINTER_X (get, never):Float; inline function get_POINTER_X() { return getAxis (FlxGamepadInputID.POINTER_X); } + public var POINTER_Y (get, never):Float; inline function get_POINTER_Y() { return getAxis (FlxGamepadInputID.POINTER_Y); } + public function new(gamepad:FlxGamepad) { this.gamepad = gamepad; diff --git a/flixel/input/gamepad/id/FlxGamepadButtonList.hx b/flixel/input/gamepad/id/FlxGamepadButtonList.hx index aecb9e83f9..79f02cc163 100644 --- a/flixel/input/gamepad/id/FlxGamepadButtonList.hx +++ b/flixel/input/gamepad/id/FlxGamepadButtonList.hx @@ -32,6 +32,10 @@ class FlxGamepadButtonList extends FlxBaseGamepadList public var LEFT_TRIGGER (get, never):Bool; inline function get_LEFT_TRIGGER() { return check(FlxGamepadInputID.LEFT_TRIGGER_FAKE); } public var RIGHT_TRIGGER (get, never):Bool; inline function get_RIGHT_TRIGGER() { return check(FlxGamepadInputID.RIGHT_TRIGGER_FAKE); } #end + public var EXTRA_0 (get, never):Bool; inline function get_EXTRA_0() { return check(FlxGamepadInputID.EXTRA_0); } + public var EXTRA_1 (get, never):Bool; inline function get_EXTRA_1() { return check(FlxGamepadInputID.EXTRA_1); } + public var EXTRA_2 (get, never):Bool; inline function get_EXTRA_2() { return check(FlxGamepadInputID.EXTRA_2); } + public var EXTRA_3 (get, never):Bool; inline function get_EXTRA_3() { return check(FlxGamepadInputID.EXTRA_3); } public function new(status:FlxInputState, gamepad:FlxGamepad) { diff --git a/flixel/input/gamepad/id/FlxGamepadMotionValueList.hx b/flixel/input/gamepad/id/FlxGamepadMotionValueList.hx new file mode 100644 index 0000000000..c928c1e9a2 --- /dev/null +++ b/flixel/input/gamepad/id/FlxGamepadMotionValueList.hx @@ -0,0 +1,32 @@ +package flixel.input.gamepad.id; +import flixel.input.gamepad.FlxGamepad; + +/** + * A helper class for gamepad input. + * Provides optimized gamepad button checking using direct array access. + */ +@:keep +class FlxGamepadMotionValueList +{ + private var gamepad:FlxGamepad; + + @:allow(flixel.input.gamepad.FlxGamepad) + /**whether or not the current gamepad model supports any motion features**/ + public var isSupported(default, null):Bool = true; + + /**analog value (-1.0 to +1.0) tilting towards or away from the ceiling (think "look up", "look down")**/ + public var TILT_PITCH (get, never):Float; inline function get_TILT_PITCH() { return getAxis (FlxGamepadInputID.TILT_PITCH);} + /**analog value (-1.0 to +1.0) tilting side-to-side (think "twisting", or "do a barrel roll!")**/ + public var TILT_ROLL (get, never):Float; inline function get_TILT_ROLL() { return getAxis (FlxGamepadInputID.TILT_ROLL); } + + public function new(gamepad:FlxGamepad) + { + this.gamepad = gamepad; + } + + private inline function getAxis(id:FlxGamepadInputID):Float + { + if (!isSupported) return 0; + return gamepad.getAxis(id); + } +} \ No newline at end of file diff --git a/flixel/input/gamepad/id/FlxGamepadPointerValueList.hx b/flixel/input/gamepad/id/FlxGamepadPointerValueList.hx new file mode 100644 index 0000000000..986e6b5e15 --- /dev/null +++ b/flixel/input/gamepad/id/FlxGamepadPointerValueList.hx @@ -0,0 +1,32 @@ +package flixel.input.gamepad.id; +import flixel.input.gamepad.FlxGamepad; + +/** + * A helper class for gamepad input -- returns X/Y analog coordinate values between 0.0 and 1.0 + * Provides optimized gamepad button checking using direct array access. + */ +@:keep +class FlxGamepadPointerValueList +{ + private var gamepad:FlxGamepad; + + /**whether or not the current gamepad model supports any pointer features (IR Camera, touch surface, etc)**/ + @:allow(flixel.input.gamepad.FlxGamepad) + public var isSupported(default, null):Bool = true; + + /**horizontal position (0.0-1.0) on the touch-surface or pointer-space**/ + public var X (get, never):Float; inline function get_X() { return getAxis (FlxGamepadInputID.POINTER_X); } + /**vertical position (0.0-1.0) on the touch-surface or pointer-space**/ + public var Y (get, never):Float; inline function get_Y() { return getAxis (FlxGamepadInputID.POINTER_Y); } + + public function new(gamepad:FlxGamepad) + { + this.gamepad = gamepad; + } + + private inline function getAxis(id:FlxGamepadInputID):Float + { + if (!isSupported) return 0; + return gamepad.getAxis(id); + } +} \ No newline at end of file diff --git a/flixel/input/gamepad/id/LogitechID.hx b/flixel/input/gamepad/id/LogitechID.hx index 1bb8742009..8b7c74425f 100644 --- a/flixel/input/gamepad/id/LogitechID.hx +++ b/flixel/input/gamepad/id/LogitechID.hx @@ -7,6 +7,13 @@ import flixel.input.gamepad.FlxGamepad; */ class LogitechID { + public static inline var SUPPORTS_MOTION = false; + public static inline var SUPPORTS_POINTER = false; + + public static inline function getFlipAxis(AxisID:Int):Int { return 1; } + + public static function isAxisForMotion(ID:FlxGamepadInputID):Bool {return false;} + #if flash // Button IDs public static inline var ONE:Int = 8; diff --git a/flixel/input/gamepad/id/MayflashWiiRemoteID.hx b/flixel/input/gamepad/id/MayflashWiiRemoteID.hx new file mode 100644 index 0000000000..bf5b6f749a --- /dev/null +++ b/flixel/input/gamepad/id/MayflashWiiRemoteID.hx @@ -0,0 +1,295 @@ +package flixel.input.gamepad.id; +import flixel.input.gamepad.FlxGamepad.FlxGamepadAnalogStick; +import flixel.input.gamepad.FlxGamepad.FlxGamepadModelAttachment; + +/** + * WiiRemote hardware input ID's when using "Mode 3" of the MayFlash DolphinBar accessory + * + * @author larsiusprime + */ +class MayflashWiiRemoteID +{ + public static inline var SUPPORTS_MOTION = false; + public static inline var SUPPORTS_POINTER = true; //But you'll only get non-zero values for it when the Nunchuk is attached + + public static inline function getFlipAxis(AxisID:Int, attachment:FlxGamepadModelAttachment):Int { return 1; } + + /*Things to add: + + - Accelerometer (in both remote and nunchuk) + - Gyroscope (in Motion-Plus version only) + - IR camera (position tracking) + - Rumble + - Speaker + + */ + + #if FLX_JOYSTICK_API + + //Standard Wii Remote inputs: + public static inline var REMOTE_ONE:Int = 0; + public static inline var REMOTE_TWO:Int = 1; + public static inline var REMOTE_A:Int = 2; + public static inline var REMOTE_B:Int = 3; + + public static inline var REMOTE_MINUS:Int = 4; + public static inline var REMOTE_PLUS:Int = 5; + + public static inline var REMOTE_HOME:Int = 11; + + //Nunchuk attachment: + public static inline var NUNCHUK_Z:Int = 6; + public static inline var NUNCHUK_C:Int = 7; + + public static inline var NUNCHUK_DPAD_DOWN:Int = 12; + public static inline var NUNCHUK_DPAD_UP:Int = 13; + public static inline var NUNCHUK_DPAD_LEFT:Int = 14; + public static inline var NUNCHUK_DPAD_RIGHT:Int = 15; + + public static inline var NUNCHUK_MINUS:Int = 4; + public static inline var NUNCHUK_PLUS:Int = 5; + + public static inline var NUNCHUK_HOME:Int = 11; + + public static inline var NUNCHUK_ONE:Int = 0; + public static inline var NUNCHUK_TWO:Int = 1; + public static inline var NUNCHUK_A:Int = 2; + public static inline var NUNCHUK_B:Int = 3; + + //classic controller attachment: + public static inline var CLASSIC_Y:Int = 0; //Identical to WiiRemote 1 + public static inline var CLASSIC_X:Int = 1; //Identical to WiiRemote 2 + public static inline var CLASSIC_B:Int = 2; //Identical to WiiRemote A + public static inline var CLASSIC_A:Int = 3; //Identical to WiiRemote B + + public static inline var CLASSIC_L:Int = 4; //Identical to MINUS and PLUS + public static inline var CLASSIC_R:Int = 5; + public static inline var CLASSIC_ZL:Int = 6; //Identical to C and Z + public static inline var CLASSIC_ZR:Int = 7; + + public static inline var CLASSIC_SELECT:Int = 8; + public static inline var CLASSIC_START:Int = 9; + + public static inline var CLASSIC_HOME:Int = 11; + + public static inline var CLASSIC_DPAD_DOWN:Int = 12; + public static inline var CLASSIC_DPAD_UP:Int = 13; + public static inline var CLASSIC_DPAD_LEFT:Int = 14; + public static inline var CLASSIC_DPAD_RIGHT:Int = 15; + + public static inline var CLASSIC_ONE:Int = -1; + public static inline var CLASSIC_TWO:Int = -1; + + // Axis indices + + public static inline var NUNCHUK_POINTER_X:Int = 2; + public static inline var NUNCHUK_POINTER_Y:Int = 3; + + //Yes, the WiiRemote DPAD is treated as ANALOG for some reason...so we have to pass in some "fake" ID's to get simulated digital inputs + public static var REMOTE_DPAD(default, null) = new FlxGamepadAnalogStick(0, 1, { + up:REMOTE_DPAD_UP, + down:REMOTE_DPAD_DOWN, + left:REMOTE_DPAD_LEFT, + right:REMOTE_DPAD_RIGHT, + threshold:0.5, + mode:OnlyDigital + }); + + public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1); //the nunchuk only has the "left" analog stick + public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3); //the classic controller has both the "left" and "right" analog sticks + + //these aren't real axes, they're simulated when the right digital buttons are pushed + public static inline var LEFT_TRIGGER_FAKE:Int = 4; + public static inline var RIGHT_TRIGGER_FAKE:Int = 5; + + //Analog stick and trigger values overlap with regular buttons so we remap to "fake" button ID's + public static function axisIndexToRawID(index:Int, attachment:FlxGamepadModelAttachment):Int + { + if (attachment == WiiNunchuk || attachment == WiiClassicController) + { + if (index == LEFT_ANALOG_STICK.x) return LEFT_ANALOG_STICK_FAKE_X; + else if (index == LEFT_ANALOG_STICK.y) return LEFT_ANALOG_STICK_FAKE_Y; + } + else + { + if (index == LEFT_ANALOG_STICK.x) return REMOTE_DPAD_X; + else if (index == LEFT_ANALOG_STICK.y) return REMOTE_DPAD_Y; + } + + if (index == RIGHT_ANALOG_STICK.x) return RIGHT_ANALOG_STICK_FAKE_X; + else if (index == RIGHT_ANALOG_STICK.y) return RIGHT_ANALOG_STICK_FAKE_Y; + + return index; + } + + public static function checkForFakeAxis(ID:FlxGamepadInputID, attachment:FlxGamepadModelAttachment):Int + { + if (attachment == WiiNunchuk) + { + if (ID == LEFT_TRIGGER) return NUNCHUK_Z; + } + else if (attachment == WiiClassicController) + { + if (ID == LEFT_TRIGGER) return LEFT_TRIGGER_FAKE; + if (ID == RIGHT_TRIGGER) return RIGHT_TRIGGER_FAKE; + } + return -1; + } + + public static function isAxisForMotion(ID:FlxGamepadInputID, attachment:FlxGamepadModelAttachment):Bool + { + return false; + } + + //"fake" IDs + public static inline var REMOTE_DPAD_X:Int = 16; + public static inline var REMOTE_DPAD_Y:Int = 17; + + public static inline var LEFT_ANALOG_STICK_FAKE_X:Int = 18; + public static inline var LEFT_ANALOG_STICK_FAKE_Y:Int = 19; + public static inline var RIGHT_ANALOG_STICK_FAKE_X:Int = 20; + public static inline var RIGHT_ANALOG_STICK_FAKE_Y:Int = 21; + + public static inline var REMOTE_DPAD_UP:Int = 22; + public static inline var REMOTE_DPAD_DOWN:Int = 23; + public static inline var REMOTE_DPAD_LEFT:Int = 24; + public static inline var REMOTE_DPAD_RIGHT:Int = 25; + + /**************************/ + + #else //gamepad API + + //Standard Wii Remote inputs: + public static inline var REMOTE_ONE:Int = 8; + public static inline var REMOTE_TWO:Int = 9; + public static inline var REMOTE_A:Int = 10; + public static inline var REMOTE_B:Int = 11; + + public static inline var REMOTE_MINUS:Int = 12; + public static inline var REMOTE_PLUS:Int = 13; + + public static inline var REMOTE_HOME:Int = 19; + + //Nunchuk attachment: + public static inline var NUNCHUK_Z:Int = 14; + public static inline var NUNCHUK_C:Int = 15; + + public static inline var NUNCHUK_DPAD_UP:Int = 4; + public static inline var NUNCHUK_DPAD_DOWN:Int = 5; + public static inline var NUNCHUK_DPAD_LEFT:Int = 6; + public static inline var NUNCHUK_DPAD_RIGHT:Int = 7; + + public static inline var NUNCHUK_MINUS:Int = 12; + public static inline var NUNCHUK_PLUS:Int = 13; + + public static inline var NUNCHUK_HOME:Int = 19; + + public static inline var NUNCHUK_A:Int = 10; + public static inline var NUNCHUK_B:Int = 11; + + public static inline var NUNCHUK_ONE:Int = 8; + public static inline var NUNCHUK_TWO:Int = 9; + + //classic controller attachment: + public static inline var CLASSIC_Y:Int = 8; + public static inline var CLASSIC_X:Int = 9; + public static inline var CLASSIC_B:Int = 10; + public static inline var CLASSIC_A:Int = 11; + + public static inline var CLASSIC_L:Int = 12; + public static inline var CLASSIC_R:Int = 13; + public static inline var CLASSIC_ZL:Int = 14; + public static inline var CLASSIC_ZR:Int = 15; + + public static inline var CLASSIC_SELECT:Int = 16; + public static inline var CLASSIC_START:Int = 17; + + public static inline var CLASSIC_HOME:Int = 19; + + public static inline var CLASSIC_ONE:Int = -1; + public static inline var CLASSIC_TWO:Int = -1; + + //(input "10" does not seem to be defined) + + public static inline var CLASSIC_DPAD_UP:Int = 4; + public static inline var CLASSIC_DPAD_DOWN:Int = 5; + public static inline var CLASSIC_DPAD_LEFT:Int = 6; + public static inline var CLASSIC_DPAD_RIGHT:Int = 7; + + // Axis indices + + public static inline var NUNCHUK_POINTER_X:Int = 2; + public static inline var NUNCHUK_POINTER_Y:Int = 3; + + //Yes, the WiiRemote DPAD is treated as ANALOG for some reason...so we have to pass in some "fake" ID's to get simulated digital inputs + public static var REMOTE_DPAD(default, null) = new FlxGamepadAnalogStick(0, 1, { + up:REMOTE_DPAD_UP, + down:REMOTE_DPAD_DOWN, + left:REMOTE_DPAD_LEFT, + right:REMOTE_DPAD_RIGHT, + threshold:0.5, + mode:OnlyDigital + }); + + public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1); //the nunchuk only has the "left" analog stick + public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3); //the classic controller has both the "left" and "right" analog sticks + + //these aren't real axes, they're simulated when the right digital buttons are pushed + public static inline var LEFT_TRIGGER_FAKE:Int = 4; + public static inline var RIGHT_TRIGGER_FAKE:Int = 5; + + //Analog stick and trigger values overlap with regular buttons so we remap to "fake" button ID's + public static function axisIndexToRawID(index:Int, attachment:FlxGamepadModelAttachment):Int + { + if (attachment == WiiNunchuk || attachment == WiiClassicController) + { + if (index == LEFT_ANALOG_STICK.x) return LEFT_ANALOG_STICK_FAKE_X; + else if (index == LEFT_ANALOG_STICK.y) return LEFT_ANALOG_STICK_FAKE_Y; + } + else + { + if (index == LEFT_ANALOG_STICK.x) return REMOTE_DPAD_X; + else if (index == LEFT_ANALOG_STICK.y) return REMOTE_DPAD_Y; + } + + if (index == RIGHT_ANALOG_STICK.x) return RIGHT_ANALOG_STICK_FAKE_X; + else if (index == RIGHT_ANALOG_STICK.y) return RIGHT_ANALOG_STICK_FAKE_Y; + + return index; + } + + public static function checkForFakeAxis(ID:FlxGamepadInputID, attachment:FlxGamepadModelAttachment):Int + { + if (attachment == WiiNunchuk) + { + if (ID == LEFT_TRIGGER) return NUNCHUK_Z; + } + else if (attachment == WiiClassicController) + { + if (ID == LEFT_TRIGGER) return CLASSIC_ZL; + if (ID == RIGHT_TRIGGER) return CLASSIC_ZR; + } + return -1; + } + + public static function isAxisForMotion(ID:FlxGamepadInputID, attachment:FlxGamepadModelAttachment):Bool + { + return false; + } + + //"fake" IDs + public static inline var REMOTE_DPAD_X:Int = 16; + public static inline var REMOTE_DPAD_Y:Int = 17; + + public static inline var LEFT_ANALOG_STICK_FAKE_X:Int = 18; + public static inline var LEFT_ANALOG_STICK_FAKE_Y:Int = 19; + public static inline var RIGHT_ANALOG_STICK_FAKE_X:Int = 20; + public static inline var RIGHT_ANALOG_STICK_FAKE_Y:Int = 21; + + public static inline var REMOTE_DPAD_UP:Int = 22; + public static inline var REMOTE_DPAD_DOWN:Int = 23; + public static inline var REMOTE_DPAD_LEFT:Int = 24; + public static inline var REMOTE_DPAD_RIGHT:Int = 25; + + #end +} \ No newline at end of file diff --git a/flixel/input/gamepad/id/OUYAID.hx b/flixel/input/gamepad/id/OUYAID.hx index deb6abd472..421337fc90 100644 --- a/flixel/input/gamepad/id/OUYAID.hx +++ b/flixel/input/gamepad/id/OUYAID.hx @@ -7,6 +7,12 @@ import flixel.input.gamepad.FlxGamepad; */ class OUYAID { + public static inline var SUPPORTS_MOTION = false; + public static inline var SUPPORTS_POINTER = false; //Don't know whether OUYA's touch maps to the system mouse or not, so setting to false for now + + public static inline function getFlipAxis(AxisID:Int):Int { return 1; } + public static function isAxisForMotion(ID:FlxGamepadInputID):Bool { return false; } + // Button IDs public static inline var O:Int = 0; public static inline var U:Int = 3; diff --git a/flixel/input/gamepad/id/PS3ID.hx b/flixel/input/gamepad/id/PS3ID.hx deleted file mode 100644 index 3e7a2a7a7d..0000000000 --- a/flixel/input/gamepad/id/PS3ID.hx +++ /dev/null @@ -1,58 +0,0 @@ -package flixel.input.gamepad.id; - -import flixel.input.gamepad.FlxGamepad; - -/** - * IDs for PlayStation 3 controllers - */ -class PS3ID -{ - public static inline var TRIANGLE:Int = 12; - public static inline var CIRCLE:Int = 13; - public static inline var X:Int = 14; - public static inline var SQUARE:Int = 15; - public static inline var L1:Int = 10; - public static inline var R1:Int = 11; - public static inline var L2:Int = 8; - public static inline var R2:Int = 9; - public static inline var SELECT:Int = 0; - public static inline var START:Int = 3; - public static inline var PS:Int = 16; - public static inline var LEFT_STICK_CLICK:Int = 1; - public static inline var RIGHT_STICK_CLICK:Int = 2; - - public static inline var DPAD_UP:Int = 4; - public static inline var DPAD_DOWN:Int = 6; - public static inline var DPAD_LEFT:Int = 7; - public static inline var DPAD_RIGHT:Int = 5; - - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1); - public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3); - - public static inline var TRIANGLE_PRESSURE:Int = 16; - public static inline var CIRCLE_PRESSURE:Int = 17; - public static inline var X_PRESSURE:Int = 18; - public static inline var SQUARE_PRESSURE:Int = 19; - - #if FLX_JOYSTICK_API - //Analog stick values overlap with regular buttons so we remap to "fake" button ID's - public static function axisIndexToRawID(index:Int):Int - { - return if (index == LEFT_ANALOG_STICK.x) LEFT_ANALOG_STICK_FAKE_X; - else if (index == LEFT_ANALOG_STICK.y) LEFT_ANALOG_STICK_FAKE_Y; - else if (index == RIGHT_ANALOG_STICK.x) RIGHT_ANALOG_STICK_FAKE_X; - else if (index == RIGHT_ANALOG_STICK.y) RIGHT_ANALOG_STICK_FAKE_Y; - else return index; // return what was passed in, no overlaps for the other IDs - } - //"fake" IDs - public static inline var LEFT_ANALOG_STICK_FAKE_X:Int = 20; - public static inline var LEFT_ANALOG_STICK_FAKE_Y:Int = 21; - - public static inline var RIGHT_ANALOG_STICK_FAKE_X:Int = 22; - public static inline var RIGHT_ANALOG_STICK_FAKE_Y:Int = 23; - - //Just pass back L2/R2 - public static inline var LEFT_TRIGGER_FAKE:Int = L2; - public static inline var RIGHT_TRIGGER_FAKE:Int = R2; - #end -} diff --git a/flixel/input/gamepad/id/PS4ID.hx b/flixel/input/gamepad/id/PS4ID.hx index 1f56daa2be..a4674e2106 100644 --- a/flixel/input/gamepad/id/PS4ID.hx +++ b/flixel/input/gamepad/id/PS4ID.hx @@ -8,6 +8,12 @@ import flixel.input.gamepad.FlxGamepad; */ class PS4ID { + public static inline var SUPPORTS_MOTION = false; //TODO: on a native PS4 both should be set to true, but on PC they're false + public static inline var SUPPORTS_POINTER = false; + + public static inline function getFlipAxis(AxisID:Int):Int { return 1; } + public static function isAxisForMotion(ID:FlxGamepadInputID):Bool { return false; } + //These values have only been tested on WINDOWS! #if flash diff --git a/flixel/input/gamepad/id/WiiRemoteID.hx b/flixel/input/gamepad/id/WiiRemoteID.hx new file mode 100644 index 0000000000..57f640aa5c --- /dev/null +++ b/flixel/input/gamepad/id/WiiRemoteID.hx @@ -0,0 +1,264 @@ +package flixel.input.gamepad.id; +import flixel.input.gamepad.FlxGamepad.FlxGamepadAnalogStick; +import flixel.input.gamepad.FlxGamepad.FlxGamepadModelAttachment; +import flixel.input.gamepad.FlxGamepadInputID; + +/** + * WiiRemote hardware input ID's when using the device directly + * Hardware ID's: "Nintendo RVL-CNT-01-TR" and "Nintendo RVL-CNT-01" -- the latter does not have the Motion-Plus attachment + * + * NOTE: On Windows this requires the HID-Wiimote driver by Julian Löhr, available here: + * https://github.com/jloehr/HID-Wiimote + * + * @author larsiusprime + */ +class WiiRemoteID +{ + public static inline var SUPPORTS_MOTION = true; + public static inline var SUPPORTS_POINTER = false; //when Julian updates his driver, this can be set to "true" + + /*Things to add: + + - Accelerometer (in both remote and nunchuk) + - Gyroscope (in Motion-Plus version only) + - IR camera (position tracking) + - Rumble + - Speaker + + */ + + public static function checkForFakeAxis(ID:FlxGamepadInputID, attachment:FlxGamepadModelAttachment):Int + { + if (attachment == WiiNunchuk) + { + if (ID == LEFT_TRIGGER) return NUNCHUK_Z; + } + return -1; + } + + public static function isAxisForMotion(ID:FlxGamepadInputID, attachment:FlxGamepadModelAttachment):Bool + { + if (attachment == None) + { + if (ID == REMOTE_TILT_PITCH || ID == REMOTE_TILT_ROLL ) return true; + } + else if (attachment == WiiNunchuk) + { + if (ID == NUNCHUK_TILT_PITCH || ID == NUNCHUK_TILT_ROLL) return true; + } + return false; + } + + public static inline function getFlipAxis(AxisID:Int, attachment:FlxGamepadModelAttachment):Int + { + if (AxisID == LEFT_TRIGGER_FAKE) + { + return -1; + } + return 1; + } + + //Analog stick and trigger values overlap with regular buttons so we remap to "fake" button ID's + public static function axisIndexToRawID(index:Int, attachment:FlxGamepadModelAttachment):Int + { + if (attachment == None && index == REMOTE_NULL_AXIS ) return -1; //return null for this unused access so it doesn't overlap a button input + else if (attachment == WiiNunchuk && index == NUNCHUK_NULL_AXIS) return -1; //return null for this unused access so it doesn't overlap a button input + + if (attachment == WiiNunchuk || attachment == WiiClassicController) + { + if (index == LEFT_ANALOG_STICK.x) return LEFT_ANALOG_STICK_FAKE_X; + else if (index == LEFT_ANALOG_STICK.y) return LEFT_ANALOG_STICK_FAKE_Y; + } + else + { + if (index == LEFT_ANALOG_STICK.x) return REMOTE_DPAD_X; + else if (index == LEFT_ANALOG_STICK.y) return REMOTE_DPAD_Y; + } + + if (index == RIGHT_ANALOG_STICK.x) return RIGHT_ANALOG_STICK_FAKE_X; + else if (index == RIGHT_ANALOG_STICK.y) return RIGHT_ANALOG_STICK_FAKE_Y; + + return index; + } + + #if FLX_JOYSTICK_API + + //Standard Wii Remote inputs: + public static inline var REMOTE_ONE:Int = 0; + public static inline var REMOTE_TWO:Int = 1; + public static inline var REMOTE_A:Int = 2; + public static inline var REMOTE_B:Int = 3; + public static inline var REMOTE_PLUS:Int = 4; + public static inline var REMOTE_MINUS:Int = 5; + public static inline var REMOTE_HOME:Int = 6; + + //Nunchuk attachment: + public static inline var NUNCHUK_A:Int = 0; + public static inline var NUNCHUK_B:Int = 1; + public static inline var NUNCHUK_C:Int = 2; + public static inline var NUNCHUK_Z:Int = 3; + public static inline var NUNCHUK_ONE:Int = 4; + public static inline var NUNCHUK_TWO:Int = 5; + public static inline var NUNCHUK_PLUS:Int = 6; + public static inline var NUNCHUK_MINUS:Int = 7; + public static inline var NUNCHUK_HOME:Int = 8; + + //classic controller attachment: + public static inline var CLASSIC_A:Int = 0; + public static inline var CLASSIC_B:Int = 1; + public static inline var CLASSIC_Y:Int = 2; + public static inline var CLASSIC_X:Int = 3; + public static inline var CLASSIC_L:Int = 4; + public static inline var CLASSIC_R:Int = 5; + public static inline var CLASSIC_ZL:Int = 6; + public static inline var CLASSIC_ZR:Int = 7; + public static inline var CLASSIC_START:Int = 8; + public static inline var CLASSIC_SELECT:Int = 9; + public static inline var CLASSIC_HOME:Int = 10; + public static inline var CLASSIC_ONE:Int = 11; + public static inline var CLASSIC_TWO:Int = 12; + + // Axis indices + public static inline var REMOTE_TILT_PITCH:Int = 2; + public static inline var REMOTE_TILT_ROLL:Int = 3; + + public static inline var NUNCHUK_TILT_PITCH:Int = 3; + public static inline var NUNCHUK_TILT_ROLL:Int = 2; + + public static inline var REMOTE_NULL_AXIS:Int = 4; + public static inline var NUNCHUK_NULL_AXIS:Int = 4; + + //Yes, the WiiRemote DPAD is treated as ANALOG for some reason...so we have to pass in some "fake" ID's to get simulated digital inputs + public static var REMOTE_DPAD(default, null) = new FlxGamepadAnalogStick(0, 1, { + up:REMOTE_DPAD_UP, + down:REMOTE_DPAD_DOWN, + left:REMOTE_DPAD_LEFT, + right:REMOTE_DPAD_RIGHT, + threshold:0.5, + mode:OnlyDigital + }); + + public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1); //the nunchuk only has the "left" analog stick + public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3); //the classic controller has both the "left" and "right" analog sticks + + //these aren't real axes, they're simulated when the right digital buttons are pushed + public static inline var LEFT_TRIGGER_FAKE:Int = 4; + public static inline var RIGHT_TRIGGER_FAKE:Int = 5; + + //"fake" ID's + + public static inline var REMOTE_DPAD_UP:Int = 14; + public static inline var REMOTE_DPAD_DOWN:Int = 15; + public static inline var REMOTE_DPAD_LEFT:Int = 16; + public static inline var REMOTE_DPAD_RIGHT:Int = 17; + + public static inline var REMOTE_DPAD_X:Int = 18; + public static inline var REMOTE_DPAD_Y:Int = 19; + + public static inline var LEFT_ANALOG_STICK_FAKE_X:Int = 20; + public static inline var LEFT_ANALOG_STICK_FAKE_Y:Int = 21; + public static inline var RIGHT_ANALOG_STICK_FAKE_X:Int = 22; + public static inline var RIGHT_ANALOG_STICK_FAKE_Y:Int = 23; + + public static inline var CLASSIC_DPAD_DOWN:Int = 24; + public static inline var CLASSIC_DPAD_UP:Int = 25; + public static inline var CLASSIC_DPAD_LEFT:Int = 26; + public static inline var CLASSIC_DPAD_RIGHT:Int = 27; + + public static inline var NUNCHUK_DPAD_DOWN:Int = 28; + public static inline var NUNCHUK_DPAD_UP:Int = 29; + public static inline var NUNCHUK_DPAD_LEFT:Int = 30; + public static inline var NUNCHUK_DPAD_RIGHT:Int = 31; + + #else //gamepad API + + //Standard Wii Remote inputs: + public static inline var REMOTE_ONE:Int = 9; + public static inline var REMOTE_TWO:Int = 10; + public static inline var REMOTE_A:Int = 11; + public static inline var REMOTE_B:Int = 12; + public static inline var REMOTE_PLUS:Int = 13; + public static inline var REMOTE_MINUS:Int = 14; + public static inline var REMOTE_HOME:Int = 15; + + //Nunchuk attachment: + + public static inline var NUNCHUK_A:Int = 9; + public static inline var NUNCHUK_B:Int = 10; + public static inline var NUNCHUK_C:Int = 11; + public static inline var NUNCHUK_Z:Int = 12; + public static inline var NUNCHUK_ONE:Int = 13; + public static inline var NUNCHUK_TWO:Int = 14; + public static inline var NUNCHUK_PLUS:Int = 15; + public static inline var NUNCHUK_MINUS:Int = 16; + public static inline var NUNCHUK_HOME:Int = 17; + + public static inline var NUNCHUK_DPAD_UP:Int = 5; + public static inline var NUNCHUK_DPAD_DOWN:Int = 6; + public static inline var NUNCHUK_DPAD_LEFT:Int = 7; + public static inline var NUNCHUK_DPAD_RIGHT:Int = 8; + + //classic controller attachment: + public static inline var CLASSIC_A:Int = 9; + public static inline var CLASSIC_B:Int = 10; + public static inline var CLASSIC_Y:Int = 11; + public static inline var CLASSIC_X:Int = 12; + public static inline var CLASSIC_L:Int = 13; + public static inline var CLASSIC_R:Int = 14; + public static inline var CLASSIC_ZL:Int = 15; + public static inline var CLASSIC_ZR:Int = 16; + public static inline var CLASSIC_START:Int = 17; + public static inline var CLASSIC_SELECT:Int = 18; + public static inline var CLASSIC_HOME:Int = 19; + public static inline var CLASSIC_ONE:Int = 20; + public static inline var CLASSIC_TWO:Int = 21; + + public static inline var CLASSIC_DPAD_UP:Int = 5; + public static inline var CLASSIC_DPAD_DOWN:Int = 6; + public static inline var CLASSIC_DPAD_LEFT:Int = 7; + public static inline var CLASSIC_DPAD_RIGHT:Int = 8; + + // Axis indices + + public static inline var REMOTE_TILT_PITCH:Int = 2; + public static inline var REMOTE_TILT_ROLL:Int = 3; + + public static inline var NUNCHUK_TILT_PITCH:Int = 3; + public static inline var NUNCHUK_TILT_ROLL:Int = 2; + + public static inline var REMOTE_NULL_AXIS:Int = 4; + public static inline var NUNCHUK_NULL_AXIS:Int = 4; + + //Yes, the WiiRemote DPAD is treated as ANALOG for some reason...so we have to pass in some "fake" ID's to get simulated digital inputs + public static var REMOTE_DPAD(default, null) = new FlxGamepadAnalogStick(0, 1, { + up:REMOTE_DPAD_UP, + down:REMOTE_DPAD_DOWN, + left:REMOTE_DPAD_LEFT, + right:REMOTE_DPAD_RIGHT, + threshold:0.5, + mode:OnlyDigital + }); + + public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1); //the nunchuk only has the "left" analog stick + public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3); //the classic controller has both the "left" and "right" analog sticks + + //these aren't real axes, they're simulated when the right digital buttons are pushed + public static inline var LEFT_TRIGGER_FAKE:Int = 4; + public static inline var RIGHT_TRIGGER_FAKE:Int = 5; + + //"fake" ID's + public static inline var REMOTE_DPAD_UP:Int = 22; + public static inline var REMOTE_DPAD_DOWN:Int = 23; + public static inline var REMOTE_DPAD_LEFT:Int = 24; + public static inline var REMOTE_DPAD_RIGHT:Int = 25; + + public static inline var REMOTE_DPAD_X:Int = 26; + public static inline var REMOTE_DPAD_Y:Int = 27; + + public static inline var LEFT_ANALOG_STICK_FAKE_X:Int = 28; + public static inline var LEFT_ANALOG_STICK_FAKE_Y:Int = 29; + public static inline var RIGHT_ANALOG_STICK_FAKE_X:Int = 30; + public static inline var RIGHT_ANALOG_STICK_FAKE_Y:Int = 31; + + #end +} \ No newline at end of file diff --git a/flixel/input/gamepad/id/XBox360ID.hx b/flixel/input/gamepad/id/XBox360ID.hx index 7bcccc7c3b..8e1d08bcde 100644 --- a/flixel/input/gamepad/id/XBox360ID.hx +++ b/flixel/input/gamepad/id/XBox360ID.hx @@ -1,12 +1,35 @@ package flixel.input.gamepad.id; import flixel.input.gamepad.FlxGamepad; +import flixel.input.gamepad.FlxGamepadMapping.Manufacturer; /** * IDs for Xbox 360 controllers */ class XBox360ID { + public static inline var SUPPORTS_MOTION = false; + public static inline var SUPPORTS_POINTER = false; + + public static inline function getFlipAxis(AxisID:Int, manufacturer:Manufacturer):Int + { + #if flash + var a = 1; + if (manufacturer == AdobeWindows) + { + if (AxisID == LEFT_ANALOG_STICK.y || AxisID == RIGHT_ANALOG_STICK.y) + { + a = -1; + } + } + return a; + #else + return 1; + #end + } + + public static function isAxisForMotion(ID:FlxGamepadInputID):Bool { return false; } + #if flash // Button IDs public static inline var A:Int = 4; diff --git a/flixel/input/gamepad/id/XInputID.hx b/flixel/input/gamepad/id/XInputID.hx index c68ddad8ed..e74a33c2bc 100644 --- a/flixel/input/gamepad/id/XInputID.hx +++ b/flixel/input/gamepad/id/XInputID.hx @@ -7,6 +7,12 @@ import flixel.input.gamepad.FlxGamepad; */ class XInputID { + public static inline var SUPPORTS_MOTION = false; + public static inline var SUPPORTS_POINTER = false; + + public static inline function getFlipAxis(AxisID:Int):Int { return 1; } + public static function isAxisForMotion(ID:FlxGamepadInputID):Bool { return false; } + // Button IDs public static inline var A:Int = 6; public static inline var B:Int = 7;