mirror of
https://github.com/kichikuou/system3-sdl2.git
synced 2026-10-11 16:58:11 +03:00
Android: Add system menu
The system menu opens with 3-finger touch. Currently, it can only exit the game.
This commit is contained in:
@@ -22,6 +22,10 @@ import android.media.MediaPlayer
|
||||
import android.os.Bundle
|
||||
import android.text.InputType
|
||||
import android.util.Log
|
||||
import android.view.ContextMenu
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.EditText
|
||||
import org.libsdl.app.SDLActivity
|
||||
import java.io.File
|
||||
@@ -44,6 +48,7 @@ class GameActivity : SDLActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
gameRoot = File(intent.getStringExtra(EXTRA_GAME_ROOT))
|
||||
cdda = CddaPlayer(File(gameRoot, Launcher.PLAYLIST_FILE))
|
||||
registerForContextMenu(mLayout)
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
@@ -97,6 +102,34 @@ class GameActivity : SDLActivity() {
|
||||
.show()
|
||||
}
|
||||
|
||||
private var menuShown = false
|
||||
private fun openMenu() {
|
||||
if (menuShown)
|
||||
return
|
||||
openContextMenu(mLayout)
|
||||
menuShown = true
|
||||
}
|
||||
|
||||
override fun onCreateContextMenu(menu: ContextMenu?, v: View?, menuInfo: ContextMenu.ContextMenuInfo?) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo)
|
||||
menuInflater.inflate(R.menu.game_menu, menu)
|
||||
}
|
||||
|
||||
override fun onContextItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.quit_game -> {
|
||||
finish()
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onContextMenuClosed(menu: Menu?) {
|
||||
super.onContextMenuClosed(menu)
|
||||
menuShown = false
|
||||
}
|
||||
|
||||
// The functions below are called in the SDL thread by JNI.
|
||||
@Suppress("unused") fun cddaStart(track: Int, loop: Boolean) = cdda.start(track, loop)
|
||||
@Suppress("unused") fun cddaStop() = cdda.stop()
|
||||
@@ -118,6 +151,10 @@ class GameActivity : SDLActivity() {
|
||||
}
|
||||
return result[0]
|
||||
}
|
||||
|
||||
@Suppress("unused") fun popupMenu() {
|
||||
runOnUiThread { openMenu() }
|
||||
}
|
||||
}
|
||||
|
||||
private class CddaPlayer(private val playlistPath: File) {
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/quit_game"
|
||||
android:title="@string/action_quit_game" />
|
||||
</menu>
|
||||
@@ -3,6 +3,7 @@
|
||||
<string name="app_name">System3</string>
|
||||
<string name="action_export_save_data">セーブデータをエクスポート</string>
|
||||
<string name="action_import_save_data">セーブデータをインポート</string>
|
||||
<string name="action_quit_game">ゲーム終了</string>
|
||||
<string name="cancel">キャンセル</string>
|
||||
<string name="cannot_find_adisk">System3 のファイル (*.dat) が見つかりません。</string>
|
||||
<string name="choose_a_file">ファイルを選択</string>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<string name="app_name">System3</string>
|
||||
<string name="action_export_save_data">Export Save Files</string>
|
||||
<string name="action_import_save_data">Import Save Files</string>
|
||||
<string name="action_quit_game">Quit Game</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="cannot_find_adisk">Cannot find System3 game files (*.dat).</string>
|
||||
<string name="choose_a_file">Choose a file</string>
|
||||
@@ -11,7 +12,7 @@
|
||||
<string name="install_from_zip">Install from ZIP</string>
|
||||
<string name="install_progress">Extracting %s</string>
|
||||
<string name="no_data_to_import">No save/ folder in the ZIP archive.</string>
|
||||
<string name="ok">OK</string>
|
||||
<string name="ok" translatable="false">OK</string>
|
||||
<string name="save_data_export_error">Failed to export save files.</string>
|
||||
<string name="save_data_import_success">Imported successfully.</string>
|
||||
<string name="save_data_export_success">Exported successfully.</string>
|
||||
|
||||
Reference in New Issue
Block a user