[Android] Add UI for game speed
This commit is contained in:
parent
ce56d2e35f
commit
e5a99a9e12
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="emu.project64" android:versionCode="4" android:versionName="2.3.1" >
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="emu.project64" android:versionCode="6" android:versionName="2.3.1" >
|
||||
|
||||
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
|
||||
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
|
||||
|
|
|
@ -28,6 +28,10 @@
|
|||
</group>
|
||||
</menu>
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/menuItem_GameSpeed"
|
||||
android:title="@string/menuItem_GameSpeed">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/menuItem_settings"
|
||||
android:title="@string/menuItem_settings"/>
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
<string name="menuItem_EndEmulation">End Emulation</string>
|
||||
<string name="menuItem_pause">Pause</string>
|
||||
<string name="menuItem_resume">Resume</string>
|
||||
<string name="menuItem_GameSpeed">Game Speed</string>
|
||||
<string name="menuItem_CurrentSaveState">Current Save State…</string>
|
||||
<string name="menuItem_CurrentSaveAuto">Auto</string>
|
||||
<string name="menuItem_CurrentSave1">Slot 1</string>
|
||||
|
|
|
@ -21,12 +21,16 @@ import emu.project64.jni.SystemEvent;
|
|||
import emu.project64.settings.SettingsActivity;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.content.Intent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class GameMenuHandler implements PopupMenu.OnMenuItemClickListener, PopupMenu.OnDismissListener
|
||||
{
|
||||
|
@ -102,6 +106,10 @@ public class GameMenuHandler implements PopupMenu.OnMenuItemClickListener, Popup
|
|||
case R.id.menuItem_DebuggingMenu:
|
||||
mOpeningSubmenu = true;
|
||||
break;
|
||||
case R.id.menuItem_GameSpeed:
|
||||
mOpeningSubmenu = true;
|
||||
SelectGameSpeed();
|
||||
break;
|
||||
case R.id.menuItem_SaveState:
|
||||
NativeExports.ExternalEvent(SystemEvent.SysEvent_SaveMachineState.getValue());
|
||||
break;
|
||||
|
@ -206,4 +214,76 @@ public class GameMenuHandler implements PopupMenu.OnMenuItemClickListener, Popup
|
|||
String SlotName = SaveSlot == 0 ? "Auto" : "Slot " + SaveSlot;
|
||||
item.setTitle(SlotName + Timestamp);
|
||||
}
|
||||
|
||||
private void SelectGameSpeed()
|
||||
{
|
||||
NativeExports.ExternalEvent( SystemEvent.SysEvent_PauseCPU_AppLostActive.getValue());
|
||||
final int MAX_SPEED = 300;
|
||||
final int MIN_SPEED = 10;
|
||||
final int initial = (NativeExports.GetSpeed() * 100) / NativeExports.GetBaseSpeed();
|
||||
final View layout = View.inflate( mActivity, R.layout.seek_bar_preference, null );
|
||||
final SeekBar seek = (SeekBar) layout.findViewById( R.id.seekbar );
|
||||
final TextView text = (TextView) layout.findViewById( R.id.textFeedback );
|
||||
final String finalFormat = "%1$d %%";
|
||||
|
||||
text.setText( String.format( finalFormat, initial ) );
|
||||
seek.setMax( MAX_SPEED - MIN_SPEED );
|
||||
seek.setProgress( initial - MIN_SPEED );
|
||||
seek.setOnSeekBarChangeListener( new SeekBar.OnSeekBarChangeListener()
|
||||
{
|
||||
public void onProgressChanged( SeekBar seekBar, int progress, boolean fromUser )
|
||||
{
|
||||
text.setText( String.format( finalFormat, progress + MIN_SPEED ) );
|
||||
}
|
||||
|
||||
public void onStartTrackingTouch( SeekBar seekBar )
|
||||
{
|
||||
}
|
||||
|
||||
public void onStopTrackingTouch( SeekBar seekBar )
|
||||
{
|
||||
}
|
||||
});
|
||||
|
||||
Builder builder = new Builder(mActivity);
|
||||
builder.setTitle(mActivity.getText( R.string.menuItem_GameSpeed ));
|
||||
builder.setPositiveButton("Cancel", null);
|
||||
builder.setNeutralButton("OK", null);
|
||||
builder.setNegativeButton("Reset", null);
|
||||
builder.setCancelable(false);
|
||||
builder.setView(layout);
|
||||
|
||||
final AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener( new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
dialog.dismiss();
|
||||
NativeExports.ExternalEvent( SystemEvent.SysEvent_ResumeCPU_AppGainedActive.getValue());
|
||||
}
|
||||
});
|
||||
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener( new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
int speed = ((seek.getProgress() + MIN_SPEED) * NativeExports.GetBaseSpeed()) / 100;
|
||||
NativeExports.SetSpeed(speed);
|
||||
dialog.dismiss();
|
||||
NativeExports.ExternalEvent( SystemEvent.SysEvent_ResumeCPU_AppGainedActive.getValue());
|
||||
}
|
||||
});
|
||||
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener( new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
NativeExports.SetSpeed(NativeExports.GetBaseSpeed());
|
||||
dialog.dismiss();
|
||||
NativeExports.ExternalEvent( SystemEvent.SysEvent_ResumeCPU_AppGainedActive.getValue());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,10 @@ public class NativeExports
|
|||
public static native void ExternalEvent(int Type);
|
||||
public static native void ResetApplicationSettings();
|
||||
|
||||
public static native void SetSpeed(int Speed);
|
||||
public static native int GetSpeed();
|
||||
public static native int GetBaseSpeed();
|
||||
|
||||
public static native void onSurfaceCreated();
|
||||
public static native void onSurfaceChanged(int width, int height);
|
||||
public static native void onDrawFrame();
|
||||
|
|
|
@ -43,7 +43,7 @@ public final class Notifier
|
|||
@Override
|
||||
public void run()
|
||||
{
|
||||
new AlertDialog.Builder(finalActivity)
|
||||
final AlertDialog dialog = new AlertDialog.Builder(finalActivity)
|
||||
.setTitle("Error")
|
||||
.setMessage(finalMessage)
|
||||
.setPositiveButton("OK", new DialogInterface.OnClickListener()
|
||||
|
@ -57,8 +57,10 @@ public final class Notifier
|
|||
};
|
||||
}
|
||||
})
|
||||
.create()
|
||||
.show();
|
||||
.setCancelable(false)
|
||||
.create();
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
dialog.show();
|
||||
}
|
||||
};
|
||||
activity.runOnUiThread( sDisplayMessager );
|
||||
|
|
Loading…
Reference in New Issue