mirror of
https://github.com/izzy2lost/WeeU.git
synced 2026-07-06 00:19:59 -07:00
better back button handling and exit game
This commit is contained in:
@@ -267,3 +267,9 @@ Java_com_izzy2lost_weeu_nativeinterface_NativeEmulation_startGame([[maybe_unused
|
||||
NativeEmulation::initializeAudioDevices();
|
||||
return NativeEmulation::startGame(JNIUtils::toString(env, launchPath));
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_com_izzy2lost_weeu_nativeinterface_NativeEmulation_stopGame([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
CafeSystem::ShutdownTitle();
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.os.Bundle
|
||||
import android.provider.DocumentsContract
|
||||
import android.widget.Toast
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.animation.EnterTransition
|
||||
import androidx.compose.animation.ExitTransition
|
||||
@@ -76,6 +77,23 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
showExitConfirmationDialog()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun showExitConfirmationDialog() {
|
||||
androidx.appcompat.app.AlertDialog.Builder(this)
|
||||
.setTitle(tr("Exit"))
|
||||
.setMessage(tr("Do you want to exit the app?"))
|
||||
.setPositiveButton(tr("Yes")) { _, _ ->
|
||||
finish()
|
||||
}
|
||||
.setNegativeButton(tr("No"), null)
|
||||
.show()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
||||
@@ -257,7 +257,10 @@ class EmulationActivity : AppCompatActivity() {
|
||||
onClick = inputOverlaySurfaceView::resetInputs
|
||||
)
|
||||
|
||||
exitMenuItem.configure(tr("Exit"), onClick = ::showExitConfirmationDialog)
|
||||
exitMenuItem.configure(tr("Exit"), onClick = {
|
||||
NativeEmulation.stopGame()
|
||||
finish()
|
||||
})
|
||||
}
|
||||
|
||||
private fun initializeView(launchPath: String) {
|
||||
|
||||
@@ -40,4 +40,7 @@ object NativeEmulation {
|
||||
|
||||
@JvmStatic
|
||||
external fun supportsLoadingCustomDriver(): Boolean
|
||||
|
||||
@JvmStatic
|
||||
external fun stopGame()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user