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.
This commit is contained in:
Sean Maas 2016-10-09 18:51:16 -04:00
parent 283c681f30
commit 05f78a7707
6 changed files with 117 additions and 38 deletions

View File

@ -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();

View File

@ -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

View File

@ -9,12 +9,12 @@
android:id="@+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/spacing_xlarge"
android:layout_marginRight="@dimen/spacing_xlarge"
android:layout_marginLeft="@dimen/spacing_large"
android:layout_marginRight="@dimen/spacing_large"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/text_value"
android:layout_marginBottom="@dimen/spacing_xlarge"/>
android:layout_marginBottom="@dimen/spacing_medlarge"/>
<TextView
android:layout_width="wrap_content"
@ -23,8 +23,8 @@
android:id="@+id/text_value"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/spacing_xlarge"
android:layout_marginBottom="@dimen/spacing_large"/>
android:layout_marginTop="@dimen/spacing_medlarge"
android:layout_marginBottom="@dimen/spacing_medlarge"/>
<TextView
android:layout_width="wrap_content"

View File

@ -25,18 +25,6 @@
android:title="@string/emulation_quickload"
/>
<!-- Enable/Disable Input Overlay -->
<item
android:id="@+id/menu_emulation_input_overlay"
android:showAsAction="never"
android:title="@string/emulation_toggle_input"/>
<item
android:id="@+id/menu_emulation_configure_controls"
android:showAsAction="never"
android:title="@string/emulation_configure_controls">
</item>
<!-- Save State Slots -->
<item
android:id="@+id/menu_emulation_save_root"
@ -92,4 +80,23 @@
android:title="@string/overlay_slot5"/>
</menu>
</item>
<item
android:id="@+id/menu_emulation_configure_controls"
android:showAsAction="never"
android:title="@string/emulation_configure_controls">
<menu>
<item
android:id="@+id/menu_emulation_edit_layout"
android:title="@string/emulation_edit_layout"/>
<item
android:id="@+id/menu_emulation_toggle_controls"
android:title="@string/emulation_toggle_controls"/>
<item
android:id="@+id/menu_emulation_adjust_scale"
android:title="@string/emulation_control_scale"/>
</menu>
</item>
</menu>

View File

@ -211,7 +211,7 @@
<item>2</item>
<item>+</item>
<item>-</item>
<item>Home</item>
<item>Home</item>
<item>C</item>
<item>Z</item>
<item>D-Pad</item>

View File

@ -355,13 +355,15 @@
<string name="dialog_seekbar_neg">Cancel</string>
<!-- Emulation Menu -->
<string name="emulation_toggle_input">Toggle Touch Controls</string>
<string name="emulation_toggle_all">Toggle All</string>
<string name="emulation_quicksave">Quick Save</string>
<string name="emulation_quickload">Quick Load</string>
<string name="emulation_refresh_wiimotes">Refresh Wiimotes</string>
<string name="emulation_configure_controls">Configure Controls</string>
<string name="emulation_edit_layout">Edit Layout</string>
<string name="emulation_done">Done</string>
<string name="emulation_toggle_controls">Toggle Controls</string>
<string name="emulation_toggle_all">Toggle All</string>
<string name="emulation_control_scale">Adjust Scale</string>
<!-- GC Adapter Menu-->
<string name="gc_adapter_rumble">Enable Vibration</string>