Skip to content

Commit

Permalink
Android: Add In-Game Speed Limit setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Ebola16 committed Aug 7, 2020
1 parent 5ec65a2 commit bda2973
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ public static native String GetConfig(String configFile, String Section, String
*/
public static native void SetConfig(String configFile, String Section, String Key, String Value);

public static native void UpdateSpeedLimit(float Value);

/**
* Gets the Dolphin version string.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public final class EmulationActivity extends AppCompatActivity
MENU_ACTION_LOAD_SLOT6, MENU_ACTION_EXIT, MENU_ACTION_CHANGE_DISC,
MENU_ACTION_RESET_OVERLAY, MENU_SET_IR_SENSITIVITY, MENU_ACTION_CHOOSE_DOUBLETAP,
MENU_ACTION_SCREEN_ORIENTATION, MENU_ACTION_MOTION_CONTROLS, MENU_ACTION_PAUSE_EMULATION,
MENU_ACTION_UNPAUSE_EMULATION})
MENU_ACTION_UNPAUSE_EMULATION, MENU_ACTION_SPEED_LIMIT})
public @interface MenuAction
{
}
Expand Down Expand Up @@ -143,6 +143,7 @@ public final class EmulationActivity extends AppCompatActivity
public static final int MENU_ACTION_MOTION_CONTROLS = 30;
public static final int MENU_ACTION_PAUSE_EMULATION = 31;
public static final int MENU_ACTION_UNPAUSE_EMULATION = 32;
public static final int MENU_ACTION_SPEED_LIMIT = 33;


private static SparseIntArray buttonsActionsMap = new SparseIntArray();
Expand Down Expand Up @@ -197,6 +198,8 @@ public final class EmulationActivity extends AppCompatActivity
EmulationActivity.MENU_ACTION_SCREEN_ORIENTATION);
buttonsActionsMap.append(R.id.menu_emulation_motion_controls,
EmulationActivity.MENU_ACTION_MOTION_CONTROLS);
buttonsActionsMap.append(R.id.menu_speed_limit,
EmulationActivity.MENU_ACTION_SPEED_LIMIT);
}

private static String[] scanForSecondDisc(GameFile gameFile)
Expand Down Expand Up @@ -730,6 +733,10 @@ public void handleMenuAction(@MenuAction int menuAction)
mEmulationFragment.stopEmulation();
finish();
return;

case MENU_ACTION_SPEED_LIMIT:
chooseSpeedLimit();
return;
}
}

Expand Down Expand Up @@ -1171,6 +1178,57 @@ private void setIRSensitivity()
builder.show();
}

private void chooseSpeedLimit()
{
LayoutInflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.dialog_seekbar, null);

final SeekBar seekbar = view.findViewById(R.id.seekbar);
final TextView value = view.findViewById(R.id.text_value);
final TextView units = view.findViewById(R.id.text_units);

seekbar.setMax(200);
seekbar.setProgress(Math.round(Float.parseFloat(NativeLibrary
.GetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE,
SettingsFile.KEY_SPEED_LIMIT, Float.toString(1.0f))) * 100.0f));
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
{
public void onStartTrackingTouch(SeekBar seekBar)
{
// Do nothing
}

public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
value.setText(String.valueOf(progress));
}

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

value.setText(String.valueOf(seekbar.getProgress()));
units.setText("%");

AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.DolphinDialogBase);
builder.setTitle(R.string.speed_limit);
builder.setView(view);
builder.setPositiveButton(getString(R.string.ok), (dialogInterface, i) ->
{
float slValue = seekbar.getProgress() / 100.0f;

NativeLibrary.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE,
SettingsFile.KEY_SPEED_LIMIT, String.valueOf(slValue));

NativeLibrary.UpdateSpeedLimit(slValue);
});

AlertDialog alertDialog = builder.create();
alertDialog.show();
}

private void resetOverlay()
{
new AlertDialog.Builder(this, R.style.DolphinDialogBase)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
.append(R.id.menu_emulation_load_root, EmulationActivity.MENU_ACTION_LOAD_ROOT);
buttonsActionsMap
.append(R.id.menu_refresh_wiimotes, EmulationActivity.MENU_ACTION_REFRESH_WIIMOTES);
buttonsActionsMap.append(R.id.menu_speed_limit, EmulationActivity.MENU_ACTION_SPEED_LIMIT);
buttonsActionsMap.append(R.id.menu_change_disc, EmulationActivity.MENU_ACTION_CHANGE_DISC);
buttonsActionsMap.append(R.id.menu_exit, EmulationActivity.MENU_ACTION_EXIT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
android:text="@string/emulation_refresh_wiimotes"
style="@style/InGameMenuOption"/>

<Button
android:id="@+id/menu_speed_limit"
android:text="@string/speed_limit"
style="@style/InGameMenuOption"/>

<Button
android:id="@+id/menu_change_disc"
android:text="@string/emulation_change_disc"
Expand Down
5 changes: 5 additions & 0 deletions Source/Android/app/src/main/res/menu/menu_emulation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@
</menu>
</item>

<item
android:id="@+id/menu_speed_limit"
app:showAsAction="never"
android:title="@string/speed_limit"/>

<item
android:id="@+id/menu_screen_orientation"
app:showAsAction="never"
Expand Down
5 changes: 5 additions & 0 deletions Source/Android/app/src/main/res/menu/menu_emulation_wii.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@
</menu>
</item>

<item
android:id="@+id/menu_speed_limit"
app:showAsAction="never"
android:title="@string/speed_limit"/>

<item
android:id="@+id/menu_screen_orientation"
app:showAsAction="never"
Expand Down
7 changes: 7 additions & 0 deletions Source/Android/jni/MainAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,13 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetConfig(
ini.Save(File::GetUserPath(D_CONFIG_IDX) + std::string(file));
}

JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_UpdateSpeedLimit(JNIEnv* env,
jobject obj,
jfloat Value)
{
SConfig::GetInstance().m_EmulationSpeed = Value;
}

JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveState(JNIEnv* env,
jobject obj,
jint slot,
Expand Down

0 comments on commit bda2973

Please sign in to comment.