From 10569b5a8d073e3be505765686881dc47f7ff244 Mon Sep 17 00:00:00 2001 From: xXJsonDeruloXx Date: Sat, 26 Sep 2026 21:31:26 -0400 Subject: [PATCH] feat(ui): turn the steam tab into a capsule wall --- .../droiddeck/launcher/ui/FrontEndScreen.kt | 131 +--------- .../java/com/droiddeck/launcher/ui/Layout.kt | 3 - .../com/droiddeck/launcher/ui/SteamHome.kt | 223 ++++++++++++++++++ 3 files changed, 234 insertions(+), 123 deletions(-) create mode 100644 app/src/main/java/com/droiddeck/launcher/ui/SteamHome.kt diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt index 27ecfea673..95f017c1e2 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt @@ -260,9 +260,9 @@ internal object Motion { private val Shape10 = RoundedCornerShape(10.dp) private val Shape12 = RoundedCornerShape(12.dp) -private fun hueOf(name: String) = (name.hashCode().toUInt() % 360u).toFloat() +internal fun hueOf(name: String) = (name.hashCode().toUInt() % 360u).toFloat() private fun tint(h: Float, s: Float = 0.7f, v: Float = 0.58f) = Color.hsv(h, s, v) -private fun artBrush(h: Float) = Brush.linearGradient(listOf(tint(h), tint((h + 32f) % 360f, 0.65f, 0.30f), tint((h + 64f) % 360f, 0.6f, 0.14f))) +internal fun artBrush(h: Float) = Brush.linearGradient(listOf(tint(h), tint((h + 32f) % 360f, 0.65f, 0.30f), tint((h + 64f) % 360f, 0.6f, 0.14f))) @Composable internal fun Rise(i: Int, modifier: Modifier = Modifier, content: @Composable () -> Unit) { @@ -815,6 +815,11 @@ private fun Content( } return } + // Steam is a full-bleed wall of the library with Play over it. + if (selected == "steam") { + SteamHome(s, a, modifier) + return + } // The Games tab lays out its own list and detail. if (selected == "games" || selected.startsWith("app:")) { GamesPage(s, a, selected, onSelect, modifier) @@ -840,57 +845,6 @@ private fun Content( }) } } - selected == "steam" -> { - // Most recently played first; Steam's own LastPlayed, games never played keep their order. - val games = remember(s.steamGames) { s.steamGames.sortedByDescending { it.lastPlayed } } - val recent = games.firstOrNull { it.lastPlayed > 0L } - val heroHeight = if (LocalConfiguration.current.screenHeightDp < 480) 150.dp else 180.dp - val short = isShortScreen() - // A small screen keeps Launch by the game; Open Steam moves to the header and Desktop - // UI and Steam's settings behind its ⋯. - val condensed = narrow || short - val host = rememberMenuHost() - Rise(0) { - PageHeader("Steam") { - RuntimeChip(s) - if (condensed && recent != null) { - Spacer(Modifier.weight(1f)) - SecondaryButton("Open Steam", enabled = !s.busy, compact = true, onClick = a.onPlay) - SteamMoreMenu(s, a, host) - } - } - } - if (recent != null) Rise(2) { - if (short) ContinueStrip(recent, s) { a.onSteamGame(recent) } - else GameHero(recent, Modifier.fillMaxWidth().heightIn(min = heroHeight)) { - Text("CONTINUE", fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.5.sp, color = LocalPalette.current.signal) - Text(recent.name, fontSize = if (narrow) 24.sp else 28.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis) - Text( - listOfNotNull(lastPlayedText(recent.lastPlayed), libraryLabel(recent.library)).joinToString(" · "), - fontSize = 13.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis, - ) - Spacer(Modifier.height(8.dp)) - Actions { - PrimaryButton("Launch", enabled = s.ready && !s.busy, main = true) { a.onSteamGame(recent) } - if (!condensed) { - SecondaryButton("Open Steam", enabled = !s.busy, onClick = a.onPlay) - SecondaryButton("Desktop UI", enabled = !s.busy, onClick = a.onPlayDesktopUi) - Cog(a.onSteamSettings) - } - } - } - } else Rise(2) { - Actions { - // Enabled without a runtime: the session's loading screen installs it first. - PrimaryButton("Play", enabled = !s.busy, main = true, onClick = a.onPlay) - SecondaryButton("Steam Desktop UI", enabled = !s.busy, onClick = a.onPlayDesktopUi) - Cog(a.onSteamSettings) - } - } - Rise(4) { SectionTitle("Installed", "${games.size} game${if (games.size == 1) "" else "s"}") } - if (games.isEmpty()) Rise(5) { Note("No games installed.") } - else Rise(5, Modifier.fillMaxWidth()) { ArtGrid(games.map { g -> Tile(g.name, null, g.art, "steam:${g.appId}", null) { onSelect("app:${g.appId}") } }) } - } selected == "desktop" -> { val installed = s.emulators.filter { it.installed } val available = s.emulators.filter { !it.installed } @@ -1676,76 +1630,13 @@ private fun PageHeader(title: String, trailing: @Composable RowScope.() -> Unit /** Whether Steam can start, said where Play is rather than only in Setup. */ @Composable -private fun RuntimeChip(s: FrontEndState) = when { +internal fun RuntimeChip(s: FrontEndState) = when { s.busy -> Chip(if (s.percent >= 0) "${s.stage} · ${s.percent}%" else s.stage, ok = false) !s.ready -> Chip("Runtime installs on first Play", ok = false) s.available != null && s.available != s.installed -> Chip("Runtime update available", ok = false) else -> Chip("● Runtime ready", ok = true) } -/** The hero cut to one line for a short screen: the art, the game and Launch. */ -@Composable -private fun ContinueStrip(g: Library.SteamGame, s: FrontEndState, onLaunch: () -> Unit) { - val colors = MaterialTheme.colorScheme - val pal = LocalPalette.current - Box(modifier = Modifier.fillMaxWidth().heightIn(min = 72.dp).clip(Shape14).background(artBrush(hueOf(g.name)))) { - val image = g.hero ?: g.art - if (image != null) AsyncImage( - model = image, contentDescription = null, contentScale = ContentScale.Crop, - modifier = Modifier.matchParentSize().then(if (g.hero == null) Modifier.blur(24.dp) else Modifier), - ) - Spacer( - Modifier.matchParentSize().background( - Brush.horizontalGradient(listOf(colors.background.copy(alpha = 0.9f), colors.background.copy(alpha = 0.55f))), - ), - ) - Row( - verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp), - modifier = Modifier.fillMaxWidth().padding(start = 10.dp, end = 12.dp, top = 9.dp, bottom = 9.dp), - ) { - Box(Modifier.width(36.dp).aspectRatio(2f / 3f).clip(RoundedCornerShape(6.dp)).background(artBrush(hueOf(g.name)))) { - if (g.art != null) AsyncImage(model = g.art, contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier.matchParentSize()) - } - Column(modifier = Modifier.weight(1f)) { - val span = lastPlayedText(g.lastPlayed)?.removePrefix("Last played ") - Text( - listOfNotNull("CONTINUE", span?.uppercase()).joinToString(" · "), - fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.2.sp, color = pal.signal, - maxLines = 1, overflow = TextOverflow.Ellipsis, - ) - Text(g.name, fontSize = 17.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis) - } - PrimaryButton("Launch", enabled = s.ready && !s.busy, main = true, compact = true, onClick = onLaunch) - } - } -} - -/** Desktop UI and Steam's settings, behind one button where the header has no room for both. */ -@Composable -private fun SteamMoreMenu(s: FrontEndState, a: FrontEndActions, host: MenuHost) { - val colors = MaterialTheme.colorScheme - val pal = LocalPalette.current - val src = remember { MutableInteractionSource() } - val hot = rememberHot(src) - val open = host.open == "steam-more" - val toggle: () -> Unit = { host.open = if (host.open == "steam-more") null else "steam-more" } - Box { - Box( - contentAlignment = Alignment.Center, - modifier = Modifier.paneItem("steam-more").size(40.dp).clip(Shape12) - .background(if (hot || open) pal.signal.copy(alpha = 0.14f) else Color.White.copy(alpha = 0.03f)) - .border(if (hot) 2.dp else 1.dp, if (hot || open) pal.signal else pal.line2, Shape12) - .hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, role = Role.Button, onClick = toggle) - .controllerConfirm(onClick = toggle) - .semantics { contentDescription = "More Steam options" }, - ) { Icon(Icons.Filled.MoreHoriz, contentDescription = null, tint = colors.onBackground, modifier = Modifier.size(20.dp)) } - AnchoredMenu(open, onDismiss = { if (host.open == "steam-more") host.open = null }, title = "Steam") { first -> - MenuItem("Steam desktop UI", checked = false, enabled = !s.busy, focusRequester = first) { host.open = null; a.onPlayDesktopUi() } - MenuItem("Steam session settings", checked = false) { host.open = null; a.onSteamSettings() } - } - } -} - /** "Last played 3 days ago" from Steam's unix seconds; null for a game never played. */ private fun lastPlayedText(lastPlayed: Long): String? { if (lastPlayed <= 0L) return null @@ -1880,7 +1771,7 @@ internal fun SecondaryButton(text: String, enabled: Boolean = true, compact: Boo } @Composable -private fun Cog(onClick: () -> Unit) { +internal fun Cog(size: androidx.compose.ui.unit.Dp = 42.dp, onClick: () -> Unit) { val colors = MaterialTheme.colorScheme val src = remember { MutableInteractionSource() } val hot = rememberHot(src) @@ -1889,9 +1780,9 @@ private fun Cog(onClick: () -> Unit) { val edge by animateColorAsState(if (hot) pal.signal else pal.line2, Motion.tw(250), label = "cogEdge") Box( contentAlignment = Alignment.Center, - modifier = Modifier.paneItem("cog").downToFirstTile().size(42.dp).clip(Shape12).background(Color.White.copy(alpha = 0.03f)).border(1.dp, edge, Shape12) + modifier = Modifier.paneItem("cog").downToFirstTile().size(size).clip(if (size > 48.dp) Shape14 else Shape12).background(Color.White.copy(alpha = 0.03f)).border(1.dp, edge, if (size > 48.dp) Shape14 else Shape12) .hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, onClick = onClick), - ) { Icon(Icons.Filled.Settings, "Settings", tint = if (hot) pal.signal else colors.onBackground, modifier = Modifier.size(18.dp).rotate(rot)) } + ) { Icon(Icons.Filled.Settings, "Settings", tint = if (hot) pal.signal else colors.onBackground, modifier = Modifier.size(if (size > 48.dp) 20.dp else 18.dp).rotate(rot)) } } @Composable diff --git a/app/src/main/java/com/droiddeck/launcher/ui/Layout.kt b/app/src/main/java/com/droiddeck/launcher/ui/Layout.kt index 1889b72a90..3ddef26c31 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/Layout.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/Layout.kt @@ -18,6 +18,3 @@ val LocalNarrowPane = compositionLocalOf { false } @Composable internal fun isNarrowScreen(): Boolean = LocalConfiguration.current.screenWidthDp < 600 -/** Too short a screen for a hero banner: a landscape phone, a 4:3 or a near-square handheld. */ -@Composable -internal fun isShortScreen(): Boolean = LocalConfiguration.current.screenHeightDp < 440 diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SteamHome.kt b/app/src/main/java/com/droiddeck/launcher/ui/SteamHome.kt new file mode 100644 index 0000000000..a1d15f49cf --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/ui/SteamHome.kt @@ -0,0 +1,223 @@ +package com.droiddeck.launcher.ui + +import androidx.compose.animation.core.FastOutSlowInEasing +import androidx.compose.animation.core.LinearEasing +import androidx.compose.animation.core.RepeatMode +import androidx.compose.runtime.State +import androidx.compose.animation.core.animateFloat +import androidx.compose.animation.core.infiniteRepeatable +import androidx.compose.animation.core.rememberInfiniteTransition +import androidx.compose.animation.core.tween +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.BoxWithConstraints +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.offset +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.requiredSize +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.wrapContentHeight +import androidx.compose.foundation.layout.wrapContentSize +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.PlayArrow +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.draw.clipToBounds +import androidx.compose.ui.draw.drawBehind +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.graphics.Brush +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import coil.compose.AsyncImage +import com.droiddeck.launcher.frontend.Library + +/** From this many games the Steam tab is a wall; fewer would only repeat the same covers. */ +private const val WALL_MIN_GAMES = 4 + +/** + * The Steam tab: the library as a slowly drifting, tilted wall of capsules (a few games instead + * lean on their own; none, a wall of empty ones), and over it Steam and the one thing to do here - + * Play. Everything about a single game lives on the Games tab. + */ +@Composable +internal fun SteamHome(s: FrontEndState, a: FrontEndActions, modifier: Modifier) { + val games = remember(s.steamGames) { s.steamGames.sortedByDescending { it.lastPlayed } } + val narrow = LocalNarrowPane.current + val colors = MaterialTheme.colorScheme + val pal = LocalPalette.current + Box(modifier = modifier.fillMaxSize().clipToBounds()) { + if (games.size in 1 until WALL_MIN_GAMES) CapsuleFan(games) + else { + if (games.isEmpty()) Box( + Modifier.fillMaxSize().drawBehind { + drawRect( + Brush.radialGradient( + listOf(pal.signal.copy(alpha = 0.12f), Color.Transparent), + center = Offset(size.width * 0.72f, size.height * 0.42f), radius = 380.dp.toPx(), + ), + ) + }, + ) + CapsuleWall(games) + // The wall fades out behind the words, and toward the bottom where the buttons sit. + Box( + Modifier.fillMaxSize().background( + Brush.horizontalGradient( + 0f to colors.background.copy(alpha = 0.97f), + 0.34f to colors.background.copy(alpha = 0.86f), + 0.68f to colors.background.copy(alpha = 0.25f), + 1f to colors.background.copy(alpha = 0.1f), + ), + ), + ) + Box(Modifier.fillMaxSize().background(Brush.verticalGradient(0.55f to Color.Transparent, 1f to colors.background.copy(alpha = 0.9f)))) + } + Column( + modifier = Modifier.align(Alignment.BottomStart) + .padding(start = if (narrow) 20.dp else 44.dp, bottom = if (narrow) 20.dp else 44.dp, end = 20.dp), + ) { + Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp)) { + Text( + "Steam", fontSize = if (narrow) 34.sp else 44.sp, lineHeight = if (narrow) 40.sp else 50.sp, + fontWeight = FontWeight.Bold, color = colors.onBackground, maxLines = 1, + ) + // Said only when something stands between Play and Steam; a ready runtime needs no words. + if (s.busy || !s.ready || (s.available != null && s.available != s.installed)) RuntimeChip(s) + } + Spacer(Modifier.height(18.dp)) + Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) { + // Enabled without a runtime: the session's loading screen installs it first. + PrimaryButton("Play Steam", enabled = !s.busy, main = true, large = true, icon = Icons.Filled.PlayArrow, onClick = a.onPlay) + Cog(size = 54.dp, onClick = a.onSteamSettings) + } + } + } +} + +/** + * Columns of capsules tilted a few degrees, alternate columns drifting up and down. Each column + * holds its run of covers twice and moves by exactly one run, so the loop has no seam. An empty + * library draws the same wall in blank capsules, slower. + */ +@Composable +private fun CapsuleWall(games: List) { + val capW = 112.dp + val capH = 168.dp + val gap = 14.dp + val transition = rememberInfiniteTransition(label = "wall") + val drift = transition.animateFloat( + 0f, 1f, + infiniteRepeatable(tween(if (games.isEmpty()) 75_000 else 40_000, easing = LinearEasing)), + label = "drift", + ) + // Animations off in the system settings: a still wall. + val still = Motion.scale == 0f + BoxWithConstraints(Modifier.fillMaxSize()) { + val wallW = maxWidth * 1.3f + val wallH = maxHeight * 2.4f + val columns = ((wallW + gap) / (capW + gap)).toInt() + 1 + val perRun = ((wallH + gap) / (capH + gap)).toInt() + 1 + val run = (capH + gap) * perRun + Row( + horizontalArrangement = Arrangement.spacedBy(gap), + modifier = Modifier + .wrapContentSize(Alignment.TopStart, unbounded = true) + .offset(x = maxWidth * 0.16f, y = -(wallH - maxHeight) / 2) + .requiredSize(wallW, wallH) + .graphicsLayer { rotationZ = -13f }, + ) { + repeat(columns) { c -> + Column( + verticalArrangement = Arrangement.spacedBy(gap), + modifier = Modifier.wrapContentHeight(Alignment.Top, unbounded = true).graphicsLayer { + val shift = if (still) 0f else run.toPx() * drift.value + translationY = if (c % 2 == 0) -shift else shift - run.toPx() + }, + ) { + repeat(perRun * 2) { i -> + val g = if (games.isEmpty()) null else games[(c * 5 + (i % perRun) * 3) % games.size] + Capsule(g, RoundedCornerShape(10.dp), Modifier.size(capW, capH)) + } + } + } + } + } +} + +/** One to three games, each a large capsule leaning on the others and floating a little. */ +@Composable +private fun CapsuleFan(games: List) { + val pal = LocalPalette.current + val transition = rememberInfiniteTransition(label = "fan") + val floats = listOf(9_000, 11_000, 13_000).map { ms -> + transition.animateFloat(0f, 1f, infiniteRepeatable(tween(ms, easing = FastOutSlowInEasing), RepeatMode.Reverse), label = "float") + } + val still = Motion.scale == 0f + // Where each sits (share of the page), its height (share of the page's) and its lean; front first. + val slots = listOf( + FanSlot(0.54f, 0.14f, 0.62f, -9f), + FanSlot(0.70f, 0.24f, 0.56f, 5f), + FanSlot(0.40f, 0.30f, 0.50f, -17f), + ) + BoxWithConstraints( + Modifier.fillMaxSize().drawBehind { + drawRect( + Brush.radialGradient( + listOf(pal.signal.copy(alpha = 0.14f), Color.Transparent), + center = Offset(size.width * 0.68f, size.height * 0.45f), radius = size.height * 0.6f, + ), + ) + }, + ) { + for (i in games.indices.reversed()) { + val slot = slots[i] + val h = maxHeight * slot.height + val v: State = floats[i] + Capsule( + games[i], RoundedCornerShape(14.dp), + Modifier + .offset(x = maxWidth * slot.x, y = maxHeight * slot.y) + .size(h * 2f / 3f, h) + .graphicsLayer { + val t = if (still) 0f else v.value + rotationZ = slot.lean + 2f * t + translationY = -12.dp.toPx() * t + shadowElevation = 24.dp.toPx() + shape = RoundedCornerShape(14.dp) + clip = false + }, + ) + } + } +} + +private class FanSlot(val x: Float, val y: Float, val height: Float, val lean: Float) + +/** A game's portrait capsule, or a blank one standing in for a game yet to be installed. */ +@Composable +private fun Capsule(g: Library.SteamGame?, shape: RoundedCornerShape, modifier: Modifier) { + val pal = LocalPalette.current + if (g == null) { + Box(modifier.clip(shape).background(Brush.linearGradient(listOf(pal.surface, pal.background))).border(1.dp, pal.line, shape)) + return + } + Box(modifier.clip(shape).background(artBrush(hueOf(g.name)))) { + if (g.art != null) AsyncImage(model = g.art, contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier.matchParentSize()) + } +}