[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"?>
|
<?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:glEsVersion="0x00020000" android:required="true" />
|
||||||
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
|
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
|
||||||
|
|
|
@ -28,7 +28,11 @@
|
||||||
</group>
|
</group>
|
||||||
</menu>
|
</menu>
|
||||||
</item>
|
</item>
|
||||||
<item
|
<item
|
||||||
|
android:id="@+id/menuItem_GameSpeed"
|
||||||
|
android:title="@string/menuItem_GameSpeed">
|
||||||
|
</item>
|
||||||
|
<item
|
||||||
android:id="@+id/menuItem_settings"
|
android:id="@+id/menuItem_settings"
|
||||||
android:title="@string/menuItem_settings"/>
|
android:title="@string/menuItem_settings"/>
|
||||||
<item
|
<item
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
<string name="menuItem_EndEmulation">End Emulation</string>
|
<string name="menuItem_EndEmulation">End Emulation</string>
|
||||||
<string name="menuItem_pause">Pause</string>
|
<string name="menuItem_pause">Pause</string>
|
||||||
<string name="menuItem_resume">Resume</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_CurrentSaveState">Current Save State…</string>
|
||||||
<string name="menuItem_CurrentSaveAuto">Auto</string>
|
<string name="menuItem_CurrentSaveAuto">Auto</string>
|
||||||
<string name="menuItem_CurrentSave1">Slot 1</string>
|
<string name="menuItem_CurrentSave1">Slot 1</string>
|
||||||
|
|
|
@ -21,12 +21,16 @@ import emu.project64.jni.SystemEvent;
|
||||||
import emu.project64.settings.SettingsActivity;
|
import emu.project64.settings.SettingsActivity;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.app.AlertDialog.Builder;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.PopupMenu;
|
import android.widget.PopupMenu;
|
||||||
|
import android.widget.SeekBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class GameMenuHandler implements PopupMenu.OnMenuItemClickListener, PopupMenu.OnDismissListener
|
public class GameMenuHandler implements PopupMenu.OnMenuItemClickListener, PopupMenu.OnDismissListener
|
||||||
{
|
{
|
||||||
|
@ -102,6 +106,10 @@ public class GameMenuHandler implements PopupMenu.OnMenuItemClickListener, Popup
|
||||||
case R.id.menuItem_DebuggingMenu:
|
case R.id.menuItem_DebuggingMenu:
|
||||||
mOpeningSubmenu = true;
|
mOpeningSubmenu = true;
|
||||||
break;
|
break;
|
||||||
|
case R.id.menuItem_GameSpeed:
|
||||||
|
mOpeningSubmenu = true;
|
||||||
|
SelectGameSpeed();
|
||||||
|
break;
|
||||||
case R.id.menuItem_SaveState:
|
case R.id.menuItem_SaveState:
|
||||||
NativeExports.ExternalEvent(SystemEvent.SysEvent_SaveMachineState.getValue());
|
NativeExports.ExternalEvent(SystemEvent.SysEvent_SaveMachineState.getValue());
|
||||||
break;
|
break;
|
||||||
|
@ -206,4 +214,76 @@ public class GameMenuHandler implements PopupMenu.OnMenuItemClickListener, Popup
|
||||||
String SlotName = SaveSlot == 0 ? "Auto" : "Slot " + SaveSlot;
|
String SlotName = SaveSlot == 0 ? "Auto" : "Slot " + SaveSlot;
|
||||||
item.setTitle(SlotName + Timestamp);
|
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 ExternalEvent(int Type);
|
||||||
public static native void ResetApplicationSettings();
|
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 onSurfaceCreated();
|
||||||
public static native void onSurfaceChanged(int width, int height);
|
public static native void onSurfaceChanged(int width, int height);
|
||||||
public static native void onDrawFrame();
|
public static native void onDrawFrame();
|
||||||
|
|
|
@ -43,7 +43,7 @@ public final class Notifier
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
new AlertDialog.Builder(finalActivity)
|
final AlertDialog dialog = new AlertDialog.Builder(finalActivity)
|
||||||
.setTitle("Error")
|
.setTitle("Error")
|
||||||
.setMessage(finalMessage)
|
.setMessage(finalMessage)
|
||||||
.setPositiveButton("OK", new DialogInterface.OnClickListener()
|
.setPositiveButton("OK", new DialogInterface.OnClickListener()
|
||||||
|
@ -51,14 +51,16 @@ public final class Notifier
|
||||||
public void onClick(DialogInterface dialog, int id)
|
public void onClick(DialogInterface dialog, int id)
|
||||||
{
|
{
|
||||||
// You don't have to do anything here if you just want it dismissed when clicked
|
// You don't have to do anything here if you just want it dismissed when clicked
|
||||||
synchronized(sDisplayMessager)
|
synchronized(sDisplayMessager)
|
||||||
{
|
{
|
||||||
sDisplayMessager.notify();
|
sDisplayMessager.notify();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.create()
|
.setCancelable(false)
|
||||||
.show();
|
.create();
|
||||||
|
dialog.setCanceledOnTouchOutside(false);
|
||||||
|
dialog.show();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
activity.runOnUiThread( sDisplayMessager );
|
activity.runOnUiThread( sDisplayMessager );
|
||||||
|
@ -66,8 +68,8 @@ public final class Notifier
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
sDisplayMessager.wait();
|
sDisplayMessager.wait();
|
||||||
}
|
}
|
||||||
catch (InterruptedException e)
|
catch (InterruptedException e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -85,7 +87,7 @@ public final class Notifier
|
||||||
|
|
||||||
GameOverlay overlay = (GameOverlay) activity.findViewById(R.id.gameOverlay);
|
GameOverlay overlay = (GameOverlay) activity.findViewById(R.id.gameOverlay);
|
||||||
if (overlay == null)
|
if (overlay == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
overlay.SetDisplayMessage(message, Duratation);
|
overlay.SetDisplayMessage(message, Duratation);
|
||||||
}
|
}
|
||||||
|
@ -109,11 +111,11 @@ public final class Notifier
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
finalActivity.finish();
|
finalActivity.finish();
|
||||||
synchronized(runEmulationStopped)
|
synchronized(runEmulationStopped)
|
||||||
{
|
{
|
||||||
runEmulationStopped.notify();
|
runEmulationStopped.notify();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
activity.runOnUiThread( runEmulationStopped );
|
activity.runOnUiThread( runEmulationStopped );
|
||||||
|
@ -121,8 +123,8 @@ public final class Notifier
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
runEmulationStopped.wait();
|
runEmulationStopped.wait();
|
||||||
}
|
}
|
||||||
catch (InterruptedException e)
|
catch (InterruptedException e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue