Back pauses Orbi-Raiders and BumbleHive on the TV (0.110.8-arcade1, versionCode 291)
Found on the downstairs TV: Back during Orbi-Raiders didn't pause. On Android TV, Compose spends a Back moving focus out of whatever has it, so a BackHandler alone never heard it. The games' own key handlers now catch Back (once per press): it pauses in play, and on the titles, the result cards and BumbleHive's menus does what it did before. The pause menu (its own window) is unchanged. Tests for the key and for Back on every BumbleHive screen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package tv.orbit.classic.arcade
|
||||
|
||||
import android.view.KeyEvent
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
||||
|
||||
/** The remote, as the Arcade sees it. */
|
||||
internal enum class ArcadeKey { Up, Down, Left, Right, Ok, Back, Menu, PlayPause, Other }
|
||||
@@ -17,6 +19,23 @@ internal fun arcadeKey(keyCode: Int): ArcadeKey = when (keyCode) {
|
||||
else -> ArcadeKey.Other
|
||||
}
|
||||
|
||||
/** Back, from the remote, a keyboard or a pad's B. */
|
||||
internal fun isBackKey(keyCode: Int) = arcadeKey(keyCode) == ArcadeKey.Back
|
||||
|
||||
/** A Back acts on its press (the first "down"); its repeats and its release are swallowed with it. */
|
||||
internal fun backPressActs(down: Boolean, repeatCount: Int) = down && repeatCount == 0
|
||||
|
||||
/**
|
||||
* Back caught in a screen's own key handler (8 November 2026, found on the TV). On Android TV, Compose uses a Back press
|
||||
* to move focus out of whatever has it, so a BackHandler alone never heard Back while a game held the focus: Orbi-Raiders
|
||||
* didn't pause. Screens that hold the focus catch Back here; their BackHandler stays for when nothing is focused.
|
||||
*/
|
||||
internal fun Modifier.onBackKey(enabled: Boolean = true, action: () -> Unit): Modifier = onPreviewKeyEvent { e ->
|
||||
val n = e.nativeKeyEvent
|
||||
if (!enabled || !isBackKey(n.keyCode)) false
|
||||
else { if (backPressActs(n.action == KeyEvent.ACTION_DOWN, n.repeatCount)) action(); true }
|
||||
}
|
||||
|
||||
/** What a key means in play: Back (and play/pause) always pause, never leave. */
|
||||
internal fun pausesGame(key: ArcadeKey) = key == ArcadeKey.Back || key == ArcadeKey.PlayPause
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ import tv.orbit.classic.arcade.KeyFooter
|
||||
import tv.orbit.classic.arcade.PauseWhenHidden
|
||||
import tv.orbit.classic.arcade.RunEnd
|
||||
import tv.orbit.classic.arcade.rememberRun
|
||||
import tv.orbit.classic.arcade.onBackKey
|
||||
import java.io.File
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
@@ -176,6 +177,11 @@ internal fun BumbleHiveScreen(play: ArcadePlay) {
|
||||
Box(Modifier.fillMaxSize().background(ArcadeColours.Night).focusRequester(focus).focusable().onPreviewKeyEvent { e ->
|
||||
if (overlay) return@onPreviewKeyEvent false
|
||||
val n = e.nativeKeyEvent
|
||||
// Back, caught here: on the TV, Compose spends a Back moving focus, so the BackHandler alone never heard it.
|
||||
if (tv.orbit.classic.arcade.isBackKey(n.keyCode)) {
|
||||
if (tv.orbit.classic.arcade.backPressActs(n.action == KeyEvent.ACTION_DOWN, n.repeatCount)) { sim.action(HiveKey.Back); sync() }
|
||||
return@onPreviewKeyEvent true
|
||||
}
|
||||
val k = hiveKey(n.keyCode) ?: return@onPreviewKeyEvent false
|
||||
sim.key(k, n.action == KeyEvent.ACTION_DOWN, n.repeatCount > 0)
|
||||
sync()
|
||||
@@ -216,7 +222,7 @@ private fun HiveResultCard(sim: HiveSim, onAct: (() -> Unit) -> Unit) {
|
||||
LaunchedEffect(Unit) { runCatching { first.requestFocus() } }
|
||||
BackHandler { onAct { sim.toLevels() } }
|
||||
val won = sim.screen == HiveScreen.Win
|
||||
Box(Modifier.fillMaxSize().background(ArcadeColours.Night.copy(alpha = .6f)), contentAlignment = Alignment.Center) {
|
||||
Box(Modifier.fillMaxSize().onBackKey { onAct { sim.toLevels() } }.background(ArcadeColours.Night.copy(alpha = .6f)), contentAlignment = Alignment.Center) {
|
||||
Column(Modifier.width(420.dp).background(ArcadeColours.PanelDeep, RoundedCornerShape(14.dp)).border(1.dp, ArcadeColours.Line, RoundedCornerShape(14.dp)).padding(20.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
Text("BUMBLEHIVE · LEVEL ${sim.level}${if (sim.mode == HiveMode.Hard) " · HARD" else ""}", color = ArcadeColours.Muted, fontSize = 13.sp, letterSpacing = 3.sp)
|
||||
|
||||
@@ -46,6 +46,7 @@ import tv.orbit.classic.arcade.KeyFooter
|
||||
import tv.orbit.classic.arcade.PauseWhenHidden
|
||||
import tv.orbit.classic.arcade.arcadeKey
|
||||
import tv.orbit.classic.arcade.pausesGame
|
||||
import tv.orbit.classic.arcade.onBackKey
|
||||
import tv.orbit.classic.drawOrbChaser
|
||||
import tv.orbit.classic.drawOrbMascot
|
||||
import kotlin.math.abs
|
||||
@@ -165,6 +166,11 @@ internal fun OrbiRaidersScreen(play: ArcadePlay) {
|
||||
Stage.Play, Stage.Result -> {
|
||||
Box(Modifier.fillMaxSize().focusRequester(playFocus).focusable().onPreviewKeyEvent { e ->
|
||||
if (stage != Stage.Play || paused) return@onPreviewKeyEvent false
|
||||
// Back pauses, caught here: on the TV, Compose spends a Back moving focus, so the BackHandler never heard it.
|
||||
if (tv.orbit.classic.arcade.isBackKey(e.nativeKeyEvent.keyCode)) {
|
||||
if (tv.orbit.classic.arcade.backPressActs(e.nativeKeyEvent.action == KeyEvent.ACTION_DOWN, e.nativeKeyEvent.repeatCount)) pause()
|
||||
return@onPreviewKeyEvent true
|
||||
}
|
||||
val n = e.nativeKeyEvent
|
||||
val key = arcadeKey(n.keyCode)
|
||||
val down = n.action == KeyEvent.ACTION_DOWN
|
||||
@@ -193,7 +199,7 @@ private fun TitleScreen(chosen: Pilot, best: Int, bestWave: Int, difficulty: Str
|
||||
// On opening, and again when How to Play closes.
|
||||
LaunchedEffect(refocus) { if (refocus) runCatching { cards.getValue(chosen).requestFocus() } }
|
||||
BackHandler(onBack = onBack)
|
||||
Box(Modifier.fillMaxSize().background(ArcadeColours.Night)) {
|
||||
Box(Modifier.fillMaxSize().onBackKey(action = onBack).background(ArcadeColours.Night)) {
|
||||
StarField()
|
||||
Column(Modifier.fillMaxSize().padding(start = 48.dp, end = 48.dp, top = 22.dp, bottom = 12.dp)) {
|
||||
Row(Modifier.fillMaxWidth().height(150.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
@@ -427,7 +433,7 @@ private fun ResultCard(sim: RaidersSim, bestBefore: Int, onNext: () -> Unit, onR
|
||||
val cleared = !sim.over
|
||||
val newRecord = sim.score > bestBefore && sim.score > 0
|
||||
val calm = Motion.reduce
|
||||
Box(Modifier.fillMaxSize().background(ArcadeColours.Night.copy(alpha = .82f)), contentAlignment = Alignment.Center) {
|
||||
Box(Modifier.fillMaxSize().onBackKey(action = onBack).background(ArcadeColours.Night.copy(alpha = .82f)), contentAlignment = Alignment.Center) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
if (newRecord) Cheer(OrbCharacter.Blaze, calm, 0f)
|
||||
Column(Modifier.width(520.dp).background(ArcadeColours.PanelDeep, RoundedCornerShape(14.dp)).border(1.dp, ArcadeColours.Line, RoundedCornerShape(14.dp)).padding(20.dp),
|
||||
|
||||
Reference in New Issue
Block a user