diff --git a/SPD-classes/src/main/java/com/watabou/input/ControllerHandler.java b/SPD-classes/src/main/java/com/watabou/input/ControllerHandler.java index 4452bf512..389880f7b 100644 --- a/SPD-classes/src/main/java/com/watabou/input/ControllerHandler.java +++ b/SPD-classes/src/main/java/com/watabou/input/ControllerHandler.java @@ -84,6 +84,12 @@ public class ControllerHandler implements ControllerListener { } } + public static void vibrate( int millis ){ + if (Controllers.getCurrent().canVibrate()) { + Controllers.getCurrent().startVibration(millis, 1f); + } + } + public static boolean isControllerConnected(){ return controllersSupported() && Controllers.getCurrent() != null; } diff --git a/SPD-classes/src/main/java/com/watabou/utils/PlatformSupport.java b/SPD-classes/src/main/java/com/watabou/utils/PlatformSupport.java index 1a7e96a56..9f1a2bf31 100644 --- a/SPD-classes/src/main/java/com/watabou/utils/PlatformSupport.java +++ b/SPD-classes/src/main/java/com/watabou/utils/PlatformSupport.java @@ -26,6 +26,7 @@ import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.PixmapPacker; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; +import com.watabou.input.ControllerHandler; import com.watabou.noosa.Game; import java.util.HashMap; @@ -39,9 +40,11 @@ public abstract class PlatformSupport { public abstract boolean connectedToUnmeteredNetwork(); public void vibrate( int millis ){ - //regular GDX vibration by default - //TODO should this trigger controller vibration if available? - Gdx.input.vibrate( millis ); + if (ControllerHandler.isControllerConnected()) { + ControllerHandler.vibrate(millis); + } else { + Gdx.input.vibrate( millis ); + } } public void setHonorSilentSwitch( boolean value ){ diff --git a/ios/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ios/IOSPlatformSupport.java b/ios/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ios/IOSPlatformSupport.java index 6d25f3766..dff4e71fe 100644 --- a/ios/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ios/IOSPlatformSupport.java +++ b/ios/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ios/IOSPlatformSupport.java @@ -29,6 +29,7 @@ import com.badlogic.gdx.graphics.g2d.PixmapPacker; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; +import com.watabou.input.ControllerHandler; import com.watabou.noosa.Game; import com.watabou.utils.PlatformSupport; @@ -82,8 +83,12 @@ public class IOSPlatformSupport extends PlatformSupport { } public void vibrate( int millis ){ - if (Gdx.input.isPeripheralAvailable(Input.Peripheral.HapticFeedback)){ - super.vibrate( millis ); + if (ControllerHandler.isControllerConnected()){ + if (ControllerHandler.isControllerConnected()) { + ControllerHandler.vibrate(millis); + } + } else if (Gdx.input.isPeripheralAvailable(Input.Peripheral.HapticFeedback)){ + Gdx.input.vibrate( millis ); } else { //devices without haptics support use a short vibrate on iPhone 6+, no vibration otherwise AudioServices.playSystemSound(1520);