[Android] Make joysticks less dumb from a configuration standpoint.

This commit is contained in:
Ryan Houdek 2013-11-18 14:48:08 -06:00
parent 07765aa6f0
commit ae11fba069
6 changed files with 68 additions and 64 deletions

View File

@ -6,16 +6,16 @@ Buttons/X = `Button 3`
Buttons/Y = `Button 4` Buttons/Y = `Button 4`
Buttons/Z = `Button 5` Buttons/Z = `Button 5`
Buttons/Start = `Button 2` Buttons/Start = `Button 2`
Main Stick/Up = `Axis 10` Main Stick/Up = `Axis 11`
Main Stick/Down = `Axis 11` Main Stick/Down = `Axis 12`
Main Stick/Left = `Axis 12` Main Stick/Left = `Axis 13`
Main Stick/Right = `Axis 13` Main Stick/Right = `Axis 14`
Main Stick/Modifier = Shift_L Main Stick/Modifier = Shift_L
Main Stick/Modifier/Range = 50.000000 Main Stick/Modifier/Range = 50.000000
C-Stick/Up = `Axis 14` C-Stick/Up = `Axis 15`
C-Stick/Down = `Axis 15` C-Stick/Down = `Axis 16`
C-Stick/Left = `Axis 16` C-Stick/Left = `Axis 17`
C-Stick/Right = `Axis 17` C-Stick/Right = `Axis 18`
C-Stick/Modifier = Control_L C-Stick/Modifier = Control_L
C-Stick/Modifier/Range = 50.000000 C-Stick/Modifier/Range = 50.000000
Triggers/L = `Axis 18` Triggers/L = `Axis 18`

View File

@ -30,16 +30,18 @@ public final class NativeLibrary
public static final int BUTTON_DOWN = 7; public static final int BUTTON_DOWN = 7;
public static final int BUTTON_LEFT = 8; public static final int BUTTON_LEFT = 8;
public static final int BUTTON_RIGHT = 9; public static final int BUTTON_RIGHT = 9;
public static final int STICK_MAIN_UP = 10; public static final int STICK_MAIN = 10;
public static final int STICK_MAIN_DOWN = 11; public static final int STICK_MAIN_UP = 11;
public static final int STICK_MAIN_LEFT = 12; public static final int STICK_MAIN_DOWN = 12;
public static final int STICK_MAIN_RIGHT = 13; public static final int STICK_MAIN_LEFT = 13;
public static final int STICK_C_UP = 14; public static final int STICK_MAIN_RIGHT = 14;
public static final int STICK_C_DOWN = 15; public static final int STICK_C = 15;
public static final int STICK_C_LEFT = 16; public static final int STICK_C_UP = 16;
public static final int STICK_C_RIGHT = 17; public static final int STICK_C_DOWN = 17;
public static final int TRIGGER_L = 18; public static final int STICK_C_LEFT = 18;
public static final int TRIGGER_R = 19; public static final int STICK_C_RIGHT = 19;
public static final int TRIGGER_L = 20;
public static final int TRIGGER_R = 21;
} }
/** /**

View File

@ -50,8 +50,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
overlayButtons.add(initializeOverlayButton(context, R.drawable.button_start, ButtonType.BUTTON_START)); overlayButtons.add(initializeOverlayButton(context, R.drawable.button_start, ButtonType.BUTTON_START));
overlayJoysticks.add(initializeOverlayJoystick(context, overlayJoysticks.add(initializeOverlayJoystick(context,
R.drawable.joy_outer, R.drawable.joy_inner, R.drawable.joy_outer, R.drawable.joy_inner,
ButtonType.STICK_MAIN_UP, ButtonType.STICK_MAIN_DOWN, ButtonType.STICK_MAIN));
ButtonType.STICK_MAIN_LEFT, ButtonType.STICK_MAIN_RIGHT));
// Set the on touch listener. // Set the on touch listener.
setOnTouchListener(this); setOnTouchListener(this);
@ -200,14 +199,11 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
* @param context The current {@link Context} * @param context The current {@link Context}
* @param resOuter Resource ID for the outer image of the joystick (the static image that shows the circular bounds). * @param resOuter Resource ID for the outer image of the joystick (the static image that shows the circular bounds).
* @param resInner Resource ID for the inner image of the joystick (the one you actually move around). * @param resInner Resource ID for the inner image of the joystick (the one you actually move around).
* @param axisUp Identifier for this type of axis. * @param joystick Identifier for which joystick this is.
* @param axisDown Identifier for this type of axis.
* @param axisLeft Identifier for this type of axis.
* @param axisRight Identifier for this type of axis.
* *
* @return the initialized {@link InputOverlayDrawableJoystick}. * @return the initialized {@link InputOverlayDrawableJoystick}.
*/ */
private static InputOverlayDrawableJoystick initializeOverlayJoystick(Context context, int resOuter, int resInner, int axisUp, int axisDown, int axisLeft, int axisRight) private static InputOverlayDrawableJoystick initializeOverlayJoystick(Context context, int resOuter, int resInner, int joystick)
{ {
// Resources handle for fetching the initial Drawable resource. // Resources handle for fetching the initial Drawable resource.
final Resources res = context.getResources(); final Resources res = context.getResources();
@ -219,22 +215,26 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
final Bitmap bitmapOuter = BitmapFactory.decodeResource(res, resOuter); final Bitmap bitmapOuter = BitmapFactory.decodeResource(res, resOuter);
final Bitmap bitmapInner = BitmapFactory.decodeResource(res, resInner); final Bitmap bitmapInner = BitmapFactory.decodeResource(res, resInner);
// TODO: Load coordinates for the drawable from the SharedPreference keys // String ID of the Drawable. This is what is passed into SharedPreferences
// made from the overlay configuration window in the settings. // to check whether or not a value has been set.
final String drawableId = res.getResourceEntryName(resOuter);
// The X and Y coordinates of the InputOverlayDrawableButton on the InputOverlay.
// These were set in the input overlay configuration menu.
int drawableX = (int) sPrefs.getFloat(drawableId+"-X", 0f);
int drawableY = (int) sPrefs.getFloat(drawableId+"-Y", 0f);
// Now set the bounds for the InputOverlayDrawableJoystick. // Now set the bounds for the InputOverlayDrawableJoystick.
// This will dictate where on the screen (and the what the size) the InputOverlayDrawableJoystick will be. // This will dictate where on the screen (and the what the size) the InputOverlayDrawableJoystick will be.
int outerSize = bitmapOuter.getWidth() + 256; int outerSize = bitmapOuter.getWidth() + 256;
int X = 0; Rect outerRect = new Rect(drawableX, drawableY, drawableX + outerSize, drawableY + outerSize);
int Y = 0;
Rect outerRect = new Rect(X, Y, X + outerSize, Y + outerSize);
Rect innerRect = new Rect(0, 0, outerSize / 4, outerSize / 4); Rect innerRect = new Rect(0, 0, outerSize / 4, outerSize / 4);
final InputOverlayDrawableJoystick overlayDrawable final InputOverlayDrawableJoystick overlayDrawable
= new InputOverlayDrawableJoystick(res, = new InputOverlayDrawableJoystick(res,
bitmapOuter, bitmapInner, bitmapOuter, bitmapInner,
outerRect, innerRect, outerRect, innerRect,
axisUp, axisDown, axisLeft, axisRight); joystick);
return overlayDrawable; return overlayDrawable;

View File

@ -29,15 +29,12 @@ public final class InputOverlayDrawableJoystick extends BitmapDrawable
* *
* @param res {@link Resources} instance. * @param res {@link Resources} instance.
* @param bitmapOuter {@link Bitmap} to use with this Drawable. * @param bitmapOuter {@link Bitmap} to use with this Drawable.
* @param axisUp Identifier for this type of axis. * @param joystick Identifier for which joystick this is.
* @param axisDown Identifier for this type of axis.
* @param axisLeft Identifier for this type of axis.
* @param axisRight Identifier for this type of axis.
*/ */
public InputOverlayDrawableJoystick(Resources res, public InputOverlayDrawableJoystick(Resources res,
Bitmap bitmapOuter, Bitmap bitmapInner, Bitmap bitmapOuter, Bitmap bitmapInner,
Rect rectOuter, Rect rectInner, Rect rectOuter, Rect rectInner,
int axisUp, int axisDown, int axisLeft, int axisRight) int joystick)
{ {
super(res, bitmapOuter); super(res, bitmapOuter);
this.setBounds(rectOuter); this.setBounds(rectOuter);
@ -45,10 +42,10 @@ public final class InputOverlayDrawableJoystick extends BitmapDrawable
this.ringInner = new BitmapDrawable(res, bitmapInner); this.ringInner = new BitmapDrawable(res, bitmapInner);
this.ringInner.setBounds(rectInner); this.ringInner.setBounds(rectInner);
SetInnerBounds(); SetInnerBounds();
this.axisIDs[0] = axisUp; this.axisIDs[0] = joystick + 1;
this.axisIDs[1] = axisDown; this.axisIDs[1] = joystick + 2;
this.axisIDs[2] = axisLeft; this.axisIDs[2] = joystick + 3;
this.axisIDs[3] = axisRight; this.axisIDs[3] = joystick + 4;
} }
@Override @Override
@ -142,5 +139,6 @@ public final class InputOverlayDrawableJoystick extends BitmapDrawable
int height = this.ringInner.getBounds().height() / 2; int height = this.ringInner.getBounds().height() / 2;
this.ringInner.setBounds(X - width, Y - height, this.ringInner.setBounds(X - width, Y - height,
X + width, Y + height); X + width, Y + height);
} }
} }

View File

@ -16,13 +16,12 @@ import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle; import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout;
import android.view.*; import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ListView; import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;
import org.dolphinemu.dolphinemu.AboutFragment; import org.dolphinemu.dolphinemu.AboutFragment;
import org.dolphinemu.dolphinemu.NativeLibrary; import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.R;
@ -31,6 +30,9 @@ import org.dolphinemu.dolphinemu.settings.PrefsActivity;
import org.dolphinemu.dolphinemu.sidemenu.SideMenuAdapter; import org.dolphinemu.dolphinemu.sidemenu.SideMenuAdapter;
import org.dolphinemu.dolphinemu.sidemenu.SideMenuItem; import org.dolphinemu.dolphinemu.sidemenu.SideMenuItem;
import java.util.ArrayList;
import java.util.List;
/** /**
* The activity that implements all of the functions * The activity that implements all of the functions
* for the game list. * for the game list.

View File

@ -28,25 +28,27 @@ namespace ButtonManager
enum ButtonType enum ButtonType
{ {
BUTTON_A = 0, BUTTON_A = 0,
BUTTON_B, BUTTON_B = 1,
BUTTON_START, BUTTON_START = 2,
BUTTON_X, BUTTON_X = 3,
BUTTON_Y, BUTTON_Y = 4,
BUTTON_Z, BUTTON_Z = 5,
BUTTON_UP, BUTTON_UP = 6,
BUTTON_DOWN, BUTTON_DOWN = 7,
BUTTON_LEFT, BUTTON_LEFT = 8,
BUTTON_RIGHT, BUTTON_RIGHT = 9,
STICK_MAIN_UP, STICK_MAIN = 10, /* Used on Java Side */
STICK_MAIN_DOWN, STICK_MAIN_UP = 11,
STICK_MAIN_LEFT, STICK_MAIN_DOWN = 12,
STICK_MAIN_RIGHT, STICK_MAIN_LEFT = 13,
STICK_C_UP, STICK_MAIN_RIGHT = 14,
STICK_C_DOWN, STICK_C = 15, /* Used on Java Side */
STICK_C_LEFT, STICK_C_UP = 16,
STICK_C_RIGHT, STICK_C_DOWN = 17,
TRIGGER_L, STICK_C_LEFT = 18,
TRIGGER_R STICK_C_RIGHT = 19,
TRIGGER_L = 20,
TRIGGER_R = 21,
}; };
enum ButtonState enum ButtonState
{ {