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:
2026-11-08 22:29:25 +00:00
co-authored by Claude Opus 5.5
parent 4bfb568989
commit 582c08ed93
6 changed files with 62 additions and 5 deletions
+2 -2
View File
@@ -9,8 +9,8 @@ android {
applicationId = "tv.orbit.classic" applicationId = "tv.orbit.classic"
minSdk = 26 minSdk = 26
targetSdk = 36 targetSdk = 36
versionCode = 290 versionCode = 291
versionName = "0.110.7-arcade1" versionName = "0.110.8-arcade1"
} }
buildFeatures { compose = true } buildFeatures { compose = true }
// The finished build for the TVs (Paul, 6 November 2026: the test build stuttered on the box). Not debuggable, so // The finished build for the TVs (Paul, 6 November 2026: the test build stuttered on the box). Not debuggable, so
@@ -1,6 +1,8 @@
package tv.orbit.classic.arcade package tv.orbit.classic.arcade
import android.view.KeyEvent import android.view.KeyEvent
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.key.onPreviewKeyEvent
/** The remote, as the Arcade sees it. */ /** The remote, as the Arcade sees it. */
internal enum class ArcadeKey { Up, Down, Left, Right, Ok, Back, Menu, PlayPause, Other } 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 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. */ /** 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 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.PauseWhenHidden
import tv.orbit.classic.arcade.RunEnd import tv.orbit.classic.arcade.RunEnd
import tv.orbit.classic.arcade.rememberRun import tv.orbit.classic.arcade.rememberRun
import tv.orbit.classic.arcade.onBackKey
import java.io.File import java.io.File
import java.util.concurrent.atomic.AtomicBoolean 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 -> Box(Modifier.fillMaxSize().background(ArcadeColours.Night).focusRequester(focus).focusable().onPreviewKeyEvent { e ->
if (overlay) return@onPreviewKeyEvent false if (overlay) return@onPreviewKeyEvent false
val n = e.nativeKeyEvent 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 val k = hiveKey(n.keyCode) ?: return@onPreviewKeyEvent false
sim.key(k, n.action == KeyEvent.ACTION_DOWN, n.repeatCount > 0) sim.key(k, n.action == KeyEvent.ACTION_DOWN, n.repeatCount > 0)
sync() sync()
@@ -216,7 +222,7 @@ private fun HiveResultCard(sim: HiveSim, onAct: (() -> Unit) -> Unit) {
LaunchedEffect(Unit) { runCatching { first.requestFocus() } } LaunchedEffect(Unit) { runCatching { first.requestFocus() } }
BackHandler { onAct { sim.toLevels() } } BackHandler { onAct { sim.toLevels() } }
val won = sim.screen == HiveScreen.Win 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), 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)) { 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) 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.PauseWhenHidden
import tv.orbit.classic.arcade.arcadeKey import tv.orbit.classic.arcade.arcadeKey
import tv.orbit.classic.arcade.pausesGame import tv.orbit.classic.arcade.pausesGame
import tv.orbit.classic.arcade.onBackKey
import tv.orbit.classic.drawOrbChaser import tv.orbit.classic.drawOrbChaser
import tv.orbit.classic.drawOrbMascot import tv.orbit.classic.drawOrbMascot
import kotlin.math.abs import kotlin.math.abs
@@ -165,6 +166,11 @@ internal fun OrbiRaidersScreen(play: ArcadePlay) {
Stage.Play, Stage.Result -> { Stage.Play, Stage.Result -> {
Box(Modifier.fillMaxSize().focusRequester(playFocus).focusable().onPreviewKeyEvent { e -> Box(Modifier.fillMaxSize().focusRequester(playFocus).focusable().onPreviewKeyEvent { e ->
if (stage != Stage.Play || paused) return@onPreviewKeyEvent false 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 n = e.nativeKeyEvent
val key = arcadeKey(n.keyCode) val key = arcadeKey(n.keyCode)
val down = n.action == KeyEvent.ACTION_DOWN 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. // On opening, and again when How to Play closes.
LaunchedEffect(refocus) { if (refocus) runCatching { cards.getValue(chosen).requestFocus() } } LaunchedEffect(refocus) { if (refocus) runCatching { cards.getValue(chosen).requestFocus() } }
BackHandler(onBack = onBack) BackHandler(onBack = onBack)
Box(Modifier.fillMaxSize().background(ArcadeColours.Night)) { Box(Modifier.fillMaxSize().onBackKey(action = onBack).background(ArcadeColours.Night)) {
StarField() StarField()
Column(Modifier.fillMaxSize().padding(start = 48.dp, end = 48.dp, top = 22.dp, bottom = 12.dp)) { 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) { 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 cleared = !sim.over
val newRecord = sim.score > bestBefore && sim.score > 0 val newRecord = sim.score > bestBefore && sim.score > 0
val calm = Motion.reduce 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) { Row(verticalAlignment = Alignment.CenterVertically) {
if (newRecord) Cheer(OrbCharacter.Blaze, calm, 0f) 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), Column(Modifier.width(520.dp).background(ArcadeColours.PanelDeep, RoundedCornerShape(14.dp)).border(1.dp, ArcadeColours.Line, RoundedCornerShape(14.dp)).padding(20.dp),
@@ -52,4 +52,14 @@ class ArcadeInputTest {
assertFalse(shouldPauseOnHide(wasShown = true, shown = false, alive = false)) assertFalse(shouldPauseOnHide(wasShown = true, shown = false, alive = false))
assertFalse(shouldPauseOnHide(wasShown = true, shown = true, alive = true)) assertFalse(shouldPauseOnHide(wasShown = true, shown = true, alive = true))
} }
// Found on the TV (8 November 2026): Back during Orbi-Raiders didn't pause. The games now catch Back themselves.
@Test fun backIsCaughtOncePerPressFromTheRemoteKeyboardAndPad() {
for (code in listOf(KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_ESCAPE, KeyEvent.KEYCODE_BUTTON_B)) assertTrue(isBackKey(code))
for (code in listOf(KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, KeyEvent.KEYCODE_MENU, KeyEvent.KEYCODE_DPAD_UP)) assertFalse(isBackKey(code))
// The press acts; a held Back's repeats and the release don't (so a pause isn't undone, nor a menu left twice).
assertTrue(backPressActs(down = true, repeatCount = 0))
assertFalse(backPressActs(down = true, repeatCount = 1))
assertFalse(backPressActs(down = false, repeatCount = 0))
}
} }
@@ -195,6 +195,22 @@ class HiveSimTest {
s.resume(); s.action(HiveKey.Back); s.toLevels(); s.action(HiveKey.Back); assertEquals(HiveScreen.Title, s.screen) s.resume(); s.action(HiveKey.Back); s.toLevels(); s.action(HiveKey.Back); assertEquals(HiveScreen.Title, s.screen)
} }
@Test fun backDoesWhatGameJsDidOnEveryScreen() {
val legacy = LegacyHiveSave.parse("""{"unlocked":5}""")!!
val host = Host(); val s = sim(HiveSaveData(), host, legacy)
// The Household question: Back leaves, unanswered.
assertEquals(HiveScreen.Household, s.screen); s.action(HiveKey.Back); assertEquals(1, host.left); assertEquals(HiveScreen.Household, s.screen)
s.act(s.buttons.first { it.act == HiveAct.Fresh })
for (from in listOf(HiveAct.Levels, HiveAct.Help, HiveAct.Daily)) {
s.act(s.buttons.first { it.act == from }); s.action(HiveKey.Back); assertEquals("$from", HiveScreen.Title, s.screen)
}
// In play: Back pauses; in the pause it resumes; a result goes to Level Select; the title leaves.
s.startLevel(1); s.action(HiveKey.Back); assertEquals(HiveScreen.Pause, s.screen)
s.action(HiveKey.Back); assertEquals(HiveScreen.Play, s.screen)
winNow(s); s.action(HiveKey.Back); assertEquals(HiveScreen.Levels, s.screen)
s.action(HiveKey.Back); s.action(HiveKey.Back); assertEquals(2, host.left)
}
@Test fun levelSelectOpensOnTheFurthestLevelAndLockedOnesDontStart() { @Test fun levelSelectOpensOnTheFurthestLevelAndLockedOnesDontStart() {
val save = HiveSaveData().also { it.normal.unlocked = 48 } val save = HiveSaveData().also { it.normal.unlocked = 48 }
val host = Host(); val s = sim(save, host) val host = Host(); val s = sim(save, host)