Skip to content
Permalink
Browse files

Android: add IR width/height/center option in emu menu

This sets the IR/Width, IR/Height, and IR/Center per game, so a controller profile is used
to save the value, then enable the profile in the game ini, then reload the
control configs.
  • Loading branch information...
zackhow committed Oct 13, 2018
1 parent 47d6406 commit 1db02c14c7d289eb2e6466928fe7ccf7e074ba7a
@@ -397,6 +397,8 @@ public static native String GetConfig(String configFile, String Section, String
*/
public static native void RefreshWiimotes();

public static native void ReloadWiimoteConfig();

private static boolean alertResult = false;

public static boolean displayAlertMsg(final String caption, final String text,
@@ -74,12 +74,14 @@

private boolean activityRecreated;
private String mSelectedTitle;
private String mSelectedGameId;
private int mPlatform;
private String[] mPaths;
private boolean backPressedOnce = false;

public static final String EXTRA_SELECTED_GAMES = "SelectedGames";
public static final String EXTRA_SELECTED_TITLE = "SelectedTitle";
public static final String EXTRA_SELECTED_GAMEID = "SelectedGameId";
public static final String EXTRA_PLATFORM = "Platform";

@Retention(SOURCE)
@@ -91,7 +93,7 @@
MENU_ACTION_SAVE_SLOT6, MENU_ACTION_LOAD_SLOT1, MENU_ACTION_LOAD_SLOT2,
MENU_ACTION_LOAD_SLOT3, MENU_ACTION_LOAD_SLOT4, MENU_ACTION_LOAD_SLOT5,
MENU_ACTION_LOAD_SLOT6, MENU_ACTION_EXIT, MENU_ACTION_CHANGE_DISC,
MENU_ACTION_RESET_OVERLAY})
MENU_ACTION_RESET_OVERLAY, MENU_SET_IR_SENSITIVITY})
public @interface MenuAction
{
}
@@ -123,6 +125,7 @@
public static final int MENU_ACTION_JOYSTICK_REL_CENTER = 24;
public static final int MENU_ACTION_RUMBLE = 25;
public static final int MENU_ACTION_RESET_OVERLAY = 26;
public static final int MENU_SET_IR_SENSITIVITY = 27;


private static SparseIntArray buttonsActionsMap = new SparseIntArray();
@@ -165,6 +168,8 @@
buttonsActionsMap.append(R.id.menu_emulation_rumble, EmulationActivity.MENU_ACTION_RUMBLE);
buttonsActionsMap
.append(R.id.menu_emulation_reset_overlay, EmulationActivity.MENU_ACTION_RESET_OVERLAY);
buttonsActionsMap.append(R.id.menu_emulation_set_ir_sensitivity,
EmulationActivity.MENU_SET_IR_SENSITIVITY);
}

private static String[] scanForSecondDisc(GameFile gameFile)
@@ -182,6 +187,7 @@ public static void launch(FragmentActivity activity, GameFile gameFile)

launcher.putExtra(EXTRA_SELECTED_GAMES, scanForSecondDisc(gameFile));
launcher.putExtra(EXTRA_SELECTED_TITLE, gameFile.getTitle());
launcher.putExtra(EXTRA_SELECTED_GAMEID, gameFile.getGameId());
launcher.putExtra(EXTRA_PLATFORM, gameFile.getPlatform());
activity.startActivityForResult(launcher, MainPresenter.REQUEST_EMULATE_GAME);
}
@@ -201,6 +207,7 @@ protected void onCreate(Bundle savedInstanceState)
Intent gameToEmulate = getIntent();
mPaths = gameToEmulate.getStringArrayExtra(EXTRA_SELECTED_GAMES);
mSelectedTitle = gameToEmulate.getStringExtra(EXTRA_SELECTED_TITLE);
mSelectedGameId = gameToEmulate.getStringExtra(EXTRA_SELECTED_GAMEID);
mPlatform = gameToEmulate.getIntExtra(EXTRA_PLATFORM, 0);
activityRecreated = false;
}
@@ -294,6 +301,7 @@ protected void onSaveInstanceState(Bundle outState)
}
outState.putStringArray(EXTRA_SELECTED_GAMES, mPaths);
outState.putString(EXTRA_SELECTED_TITLE, mSelectedTitle);
outState.putString(EXTRA_SELECTED_GAMEID, mSelectedGameId);
outState.putInt(EXTRA_PLATFORM, mPlatform);
super.onSaveInstanceState(outState);
}
@@ -302,6 +310,7 @@ protected void restoreState(Bundle savedInstanceState)
{
mPaths = savedInstanceState.getStringArray(EXTRA_SELECTED_GAMES);
mSelectedTitle = savedInstanceState.getString(EXTRA_SELECTED_TITLE);
mSelectedGameId = savedInstanceState.getString(EXTRA_SELECTED_GAMEID);
mPlatform = savedInstanceState.getInt(EXTRA_PLATFORM);
}

@@ -578,6 +587,10 @@ public void handleMenuAction(@MenuAction int menuAction)
FileBrowserHelper.openFilePicker(this, REQUEST_CHANGE_DISC);
return;

case MENU_SET_IR_SENSITIVITY:
setIRSensitivity();
return;

case MENU_ACTION_EXIT:
// ATV menu is built using a fragment, this will pop that fragment before emulation ends.
if (TvUtil.isLeanback(getApplicationContext()))
@@ -785,6 +798,132 @@ private void chooseController()

}

private void setIRSensitivity()
{
int irHeight = Integer.valueOf(
mPreferences.getString(SettingsFile.KEY_WIIBIND_IR_HEIGHT + mSelectedGameId, "50"));

LayoutInflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.dialog_ir_sensitivity, null);

TextView mTextSliderValueHeight = (TextView) view.findViewById(R.id.text_ir_height);
TextView units = (TextView) view.findViewById(R.id.text_ir_height_units);
SeekBar seekbarHeight = view.findViewById(R.id.seekbar_height);

mTextSliderValueHeight.setText(String.valueOf(irHeight));
units.setText(getString(R.string.height));
seekbarHeight.setMax(100);
seekbarHeight.setProgress(irHeight);
seekbarHeight.setKeyProgressIncrement(5);
seekbarHeight.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
{
@Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
mTextSliderValueHeight.setText(String.valueOf(progress));
}

@Override public void onStartTrackingTouch(SeekBar seekBar)
{
// Do nothing
}

@Override public void onStopTrackingTouch(SeekBar seekBar)
{
// Do nothing
}
});

int irWidth = Integer.valueOf(
mPreferences.getString(SettingsFile.KEY_WIIBIND_IR_WIDTH + mSelectedGameId, "50"));

TextView mTextSliderValueWidth = (TextView) view.findViewById(R.id.text_ir_width);
TextView unitsWidth = (TextView) view.findViewById(R.id.text_ir_width_units);
SeekBar seekbarWidth = view.findViewById(R.id.seekbar_width);

mTextSliderValueWidth.setText(String.valueOf(irWidth));
unitsWidth.setText(getString(R.string.width));
seekbarWidth.setMax(100);
seekbarWidth.setProgress(irWidth);
seekbarWidth.setKeyProgressIncrement(5);
seekbarWidth.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
{
@Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
mTextSliderValueWidth.setText(String.valueOf(progress));
}

@Override public void onStartTrackingTouch(SeekBar seekBar)
{
// Do nothing
}

@Override public void onStopTrackingTouch(SeekBar seekBar)
{
// Do nothing
}
});


int irCenter = Integer.valueOf(
mPreferences.getString(SettingsFile.KEY_WIIBIND_IR_CENTER + mSelectedGameId, "50"));

TextView mTextSliderValueCenter = (TextView) view.findViewById(R.id.text_ir_center);
TextView unitsCenter = (TextView) view.findViewById(R.id.text_ir_center_units);
SeekBar seekbarCenter = view.findViewById(R.id.seekbar_center);

mTextSliderValueCenter.setText(String.valueOf(irCenter));
unitsCenter.setText(getString(R.string.center));
seekbarCenter.setMax(100);
seekbarCenter.setProgress(irCenter);
seekbarCenter.setKeyProgressIncrement(5);
seekbarCenter.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
{
@Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
mTextSliderValueCenter.setText(String.valueOf(progress));
}

@Override public void onStartTrackingTouch(SeekBar seekBar)
{
// Do nothing
}

@Override public void onStopTrackingTouch(SeekBar seekBar)
{
// Do nothing
}
});

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.emulation_ir_sensitivity));
builder.setView(view);
builder.setPositiveButton(R.string.ok, (dialogInterface, i) ->
{
SettingsFile.saveSingleCustomSetting(mSelectedGameId, Settings.SECTION_CONTROLS,
SettingsFile.KEY_WIIBIND_IR_HEIGHT, mTextSliderValueHeight.getText().toString());
SettingsFile.saveSingleCustomSetting(mSelectedGameId, Settings.SECTION_CONTROLS,
SettingsFile.KEY_WIIBIND_IR_WIDTH, mTextSliderValueWidth.getText().toString());
SettingsFile.saveSingleCustomSetting(mSelectedGameId, Settings.SECTION_CONTROLS,
SettingsFile.KEY_WIIBIND_IR_CENTER, mTextSliderValueCenter.getText().toString());

NativeLibrary.ReloadWiimoteConfig();

SharedPreferences.Editor editor = mPreferences.edit();
editor.putString(SettingsFile.KEY_WIIBIND_IR_HEIGHT + mSelectedGameId,
mTextSliderValueHeight.getText().toString());
editor.putString(SettingsFile.KEY_WIIBIND_IR_WIDTH + mSelectedGameId,
mTextSliderValueWidth.getText().toString());
editor.putString(SettingsFile.KEY_WIIBIND_IR_CENTER + mSelectedGameId,
mTextSliderValueCenter.getText().toString());
editor.apply();
});
builder.setNegativeButton(R.string.cancel, (dialogInterface, i) ->
{
// Do nothing
});
builder.show();
}

private void resetOverlay()
{
new AlertDialog.Builder(this)
@@ -151,6 +151,9 @@
public static final String KEY_WIIBIND_IR_FORWARD = "IRForward_";
public static final String KEY_WIIBIND_IR_BACKWARD = "IRBackward_";
public static final String KEY_WIIBIND_IR_HIDE = "IRHide_";
public static final String KEY_WIIBIND_IR_HEIGHT = "IRHeight";
public static final String KEY_WIIBIND_IR_WIDTH = "IRWidth";
public static final String KEY_WIIBIND_IR_CENTER = "IRCenter";
public static final String KEY_WIIBIND_SWING_UP = "SwingUp_";
public static final String KEY_WIIBIND_SWING_DOWN = "SwingDown_";
public static final String KEY_WIIBIND_SWING_LEFT = "SwingLeft_";
@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">

<SeekBar
android:id="@+id/seekbar_width"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/text_ir_width"
android:layout_marginBottom="@dimen/spacing_medlarge"
android:layout_marginLeft="@dimen/spacing_large"
android:layout_marginRight="@dimen/spacing_large"/>

<TextView
android:id="@+id/text_ir_width"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/spacing_medlarge"
android:layout_marginTop="@dimen/spacing_medlarge"
tools:text="75"/>

<TextView
android:id="@+id/text_ir_width_units"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/text_ir_width"
android:layout_toEndOf="@+id/text_ir_width"
tools:text="%"/>
</RelativeLayout>

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">

<SeekBar
android:id="@+id/seekbar_height"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/text_ir_height"
android:layout_marginBottom="@dimen/spacing_medlarge"
android:layout_marginLeft="@dimen/spacing_large"
android:layout_marginRight="@dimen/spacing_large"/>

<TextView
android:id="@+id/text_ir_height"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/spacing_medlarge"
android:layout_marginTop="@dimen/spacing_medlarge"
tools:text="75"/>

<TextView
android:id="@+id/text_ir_height_units"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/text_ir_height"
android:layout_toEndOf="@+id/text_ir_height"
tools:text="%"/>

</RelativeLayout>

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">

<SeekBar
android:id="@+id/seekbar_center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/text_ir_center"
android:layout_marginBottom="@dimen/spacing_medlarge"
android:layout_marginLeft="@dimen/spacing_large"
android:layout_marginRight="@dimen/spacing_large"/>

<TextView
android:id="@+id/text_ir_center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/spacing_medlarge"
android:layout_marginTop="@dimen/spacing_medlarge"
tools:text="75"/>

<TextView
android:id="@+id/text_ir_center_units"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/text_ir_center"
android:layout_toEndOf="@+id/text_ir_center"
tools:text="%"/>

</RelativeLayout>

</LinearLayout>
@@ -113,6 +113,11 @@
android:id="@+id/menu_emulation_choose_controller"
android:title="@string/emulation_choose_controller"/>

<item
android:id="@+id/menu_emulation_set_ir_sensitivity"
app:showAsAction="ifRoom"
android:title="@string/emulation_ir_sensitivity"/>

<item
android:id="@+id/menu_emulation_reset_overlay"
android:title="@string/emulation_touch_overlay_reset"/>
@@ -298,6 +298,7 @@
<string name="emulation_controller_changed">You may have to reload the game after changing extensions.</string>
<string name="emulation_touch_button_help">Swipe down from the top of the screen to access the menu.</string>
<string name="emulation_touch_overlay_reset">Reset Overlay</string>
<string name="emulation_ir_sensitivity">IR Sensitivity</string>

<!-- GC Adapter Menu-->
<string name="gc_adapter_rumble">Enable Vibration</string>
@@ -322,4 +323,10 @@
<string name="homescreen_favorites">Favorites</string>

<string name="select_dir">Select This Directory</string>

<!-- Misc -->
<string name="height">Height</string>
<string name="width">Width</string>
<string name="center">Center</string>

</resources>
@@ -571,6 +571,12 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_RefreshWiimo
WiimoteReal::Refresh();
}

JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReloadWiimoteConfig(JNIEnv* env,
jobject obj)
{
Wiimote::LoadConfig();
}

static void Run(const std::vector<std::string>& paths, bool first_open,
std::optional<std::string> savestate_path = {}, bool delete_savestate = false)
{

0 comments on commit 1db02c1

Please sign in to comment.
You can’t perform that action at this time.