diff options
| author | Sean Maas <seanmaas27@gmail.com> | 2016-10-09 18:51:16 -0400 |
|---|---|---|
| committer | Sean Maas <seanmaas27@gmail.com> | 2016-10-09 19:00:32 -0400 |
| commit | 05f78a77073ab3d8b1c31004e5d2851f5520659c (patch) | |
| tree | ba7bff99562e23f97abbbe07150754fbf44fce79 /Source/Android/app/src/main/java | |
| parent | 283c681f304a5c55228f04b42491d3e0c6a0980f (diff) | |
Android: Add custom control scaling
Also put all touch control settings under a "Configure Controls" submenu
so the in-game menu isn't so cluttered.
Diffstat (limited to 'Source/Android/app/src/main/java')
2 files changed, 88 insertions, 18 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java index 7aa2800ea4..a534f16304 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java @@ -16,6 +16,7 @@ import android.preference.PreferenceManager; import android.support.v7.app.AppCompatActivity; import android.view.InputDevice; import android.view.KeyEvent; +import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; @@ -24,6 +25,8 @@ import android.view.ViewTreeObserver; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.SeekBar; +import android.widget.TextView; import com.squareup.picasso.Callback; import com.squareup.picasso.Picasso; @@ -395,12 +398,25 @@ public final class EmulationActivity extends AppCompatActivity { switch (id) { + // Edit the placement of the controls + case R.id.menu_emulation_edit_layout: + EmulationFragment emulationFragment = (EmulationFragment) getFragmentManager().findFragmentById(R.id.frame_emulation_fragment); + if (emulationFragment.isConfiguringControls()) + { + emulationFragment.stopConfiguringControls(); + } + else + { + emulationFragment.startConfiguringControls(); + } + break; + // Enable/Disable specific buttons or the entire input overlay. - case R.id.menu_emulation_input_overlay: + case R.id.menu_emulation_toggle_controls: { boolean[] enabledButtons = new boolean[11]; AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(R.string.emulation_toggle_input); + builder.setTitle(R.string.emulation_toggle_controls); if (mIsGameCubeGame) { for (int i = 0; i < enabledButtons.length; i++) @@ -485,17 +501,60 @@ public final class EmulationActivity extends AppCompatActivity return; } - case R.id.menu_emulation_configure_controls: - EmulationFragment emulationFragment = (EmulationFragment) getFragmentManager().findFragmentById(R.id.frame_emulation_fragment); - if (emulationFragment.isConfiguringControls()) + // Adjust the scale of the overlay controls. + case R.id.menu_emulation_adjust_scale: + { + LayoutInflater inflater = LayoutInflater.from(this); + View view = inflater.inflate(R.layout.dialog_seekbar, null); + + final SeekBar seekbar = (SeekBar) view.findViewById(R.id.seekbar); + final TextView value = (TextView) view.findViewById(R.id.text_value); + final TextView units = (TextView) view.findViewById(R.id.text_units); + + seekbar.setMax(150); + seekbar.setProgress(mPreferences.getInt("controlScale", 50)); + seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { - emulationFragment.stopConfiguringControls(); - } - else + public void onStartTrackingTouch(SeekBar seekBar) + { + // Do nothing + } + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) + { + value.setText(String.valueOf(progress + 50)); + } + public void onStopTrackingTouch(SeekBar seekBar) + { + // Do nothing + } + }); + + value.setText(String.valueOf(seekbar.getProgress() + 50)); + units.setText("%"); + + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.emulation_control_scale); + builder.setView(view); + builder.setPositiveButton(getString(R.string.emulation_done), new DialogInterface.OnClickListener() { - emulationFragment.startConfiguringControls(); - } - break; + @Override + public void onClick(DialogInterface dialogInterface, int i) + { + SharedPreferences.Editor editor = mPreferences.edit(); + editor.putInt("controlScale", seekbar.getProgress()); + editor.apply(); + + EmulationFragment emulationFragment = (EmulationFragment) getFragmentManager() + .findFragmentByTag(EmulationFragment.FRAGMENT_TAG); + emulationFragment.refreshInputOverlay(); + } + }); + + AlertDialog alertDialog = builder.create(); + alertDialog.show(); + + return; + } case R.id.menu_refresh_wiimotes: NativeLibrary.RefreshWiimotes(); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java index 5b90b43b6a..b13892f3e3 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java @@ -489,7 +489,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener // SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableButton. final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context); - // Decide scale based on button ID + // Decide scale based on button ID and user preference float scale; switch (buttonId) @@ -525,6 +525,9 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener break; } + scale *= (sPrefs.getInt("controlScale", 50) + 50); + scale /= 100; + // Initialize the InputOverlayDrawableButton. final Bitmap bitmap = resizeBitmap(context, BitmapFactory.decodeResource(res, resId), scale); final InputOverlayDrawableButton overlayDrawable = new InputOverlayDrawableButton(res, bitmap, buttonId); @@ -572,7 +575,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener // SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableDpad. final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context); - // Decide scale based on button ID + // Decide scale based on button ID and user preference float scale; switch (buttonUp) @@ -588,6 +591,9 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener break; } + scale *= (sPrefs.getInt("controlScale", 50) + 50); + scale /= 100; + // Initialize the InputOverlayDrawableDpad. final Bitmap bitmap = resizeBitmap(context, BitmapFactory.decodeResource(res, resId), scale); final InputOverlayDrawableDpad overlayDrawable = new InputOverlayDrawableDpad(res, bitmap, @@ -632,8 +638,13 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener // SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableJoystick. final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context); + // Decide scale based on user preference + float scale = 0.275f; + scale *= (sPrefs.getInt("controlScale", 50) + 50); + scale /= 100; + // Initialize the InputOverlayDrawableJoystick. - final Bitmap bitmapOuter = resizeBitmap(context, BitmapFactory.decodeResource(res, resOuter), 0.275f); + final Bitmap bitmapOuter = resizeBitmap(context, BitmapFactory.decodeResource(res, resOuter), scale); final Bitmap bitmapInner = BitmapFactory.decodeResource(res, resInner); // The X and Y coordinates of the InputOverlayDrawableButton on the InputOverlay. @@ -642,15 +653,15 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener int drawableY = (int) sPrefs.getFloat(joystick+"-Y", 0f); // Decide inner scale based on joystick ID - float scale; + float innerScale; switch (joystick) { case ButtonType.STICK_C: - scale = 1.833f; + innerScale = 1.833f; break; default: - scale = 1.375f; + innerScale = 1.375f; break; } @@ -658,7 +669,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener // This will dictate where on the screen (and the what the size) the InputOverlayDrawableJoystick will be. int outerSize = bitmapOuter.getWidth(); Rect outerRect = new Rect(drawableX, drawableY, drawableX + outerSize, drawableY + outerSize); - Rect innerRect = new Rect(0, 0, (int) (outerSize / scale), (int) (outerSize / scale)); + Rect innerRect = new Rect(0, 0, (int) (outerSize / innerScale), (int) (outerSize / innerScale)); // Send the drawableId to the joystick so it can be referenced when saving control position. final InputOverlayDrawableJoystick overlayDrawable |
