games: share mode chooser, hearts, result overlay and info boxes
- Commit
30bcb7f2f53adac025e5fa12b2a9cc8fb7959cd9- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-24 19:55 UTC (3 months ago)
- Parents
204e1dc
Diff
games/arrows/src/main/java/com/vayunmathur/games/arrows/ui/ArrowsGameScreen.kt
diff --git a/games/arrows/src/main/java/com/vayunmathur/games/arrows/ui/ArrowsGameScreen.kt b/games/arrows/src/main/java/com/vayunmathur/games/arrows/ui/ArrowsGameScreen.ktindex 5ffce9f9c2..ea386ad3e6 100644--- a/games/arrows/src/main/java/com/vayunmathur/games/arrows/ui/ArrowsGameScreen.kt+++ b/games/arrows/src/main/java/com/vayunmathur/games/arrows/ui/ArrowsGameScreen.kt@@ -3,23 +3,14 @@ package com.vayunmathur.games.arrows.ui import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column-import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.widthIn import androidx.compose.runtime.Composable-import androidx.compose.runtime.getValue-import androidx.compose.runtime.mutableStateOf-import androidx.compose.runtime.remember-import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier-import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource-import androidx.compose.ui.semantics.clearAndSetSemantics-import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import com.vayunmathur.games.arrows.R@@ -32,19 +23,15 @@ import com.vayunmathur.library.ui.AppBarAlignment import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.CircularProgressIndicator-import com.vayunmathur.library.ui.DropdownMenu-import com.vayunmathur.library.ui.DropdownMenuItem-import com.vayunmathur.library.ui.IconArrowDropDown-import com.vayunmathur.library.ui.IconButton-import com.vayunmathur.library.ui.IconEmojiEvents-import com.vayunmathur.library.ui.IconFavorite-import com.vayunmathur.library.ui.IconSettings import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.OutlinedButton import com.vayunmathur.library.ui.Spacing import com.vayunmathur.library.ui.Text-import com.vayunmathur.library.ui.TextButton import com.vayunmathur.library.ui.appBarScrollBehavior+import com.vayunmathur.library.ui.game.DailyStreakText+import com.vayunmathur.library.ui.game.GameModeChooser+import com.vayunmathur.library.ui.game.GameTopBarActions+import com.vayunmathur.library.ui.game.HeartsRow /** Caps the board on tablets, where a full-width grid would give absurdly large cells. */ private val BoardMaxWidth = 420.dp@@ -63,16 +50,33 @@ fun ArrowsGameScreen( val daily = state.mode == GameMode.DAILY AppScaffold( title = {- ModeDropdown(- mode = state.mode,- level = state.level,+ GameModeChooser(+ selected = state.mode,+ options = GameMode.entries,+ // The ladder mode folds the level into its label, so the bar needs no second title.+ label = { mode ->+ when (mode) {+ GameMode.CASUAL -> stringResource(R.string.level_title, state.level)+ GameMode.DAILY -> stringResource(R.string.mode_daily)+ }+ },+ menuLabel = { mode ->+ stringResource(+ when (mode) {+ GameMode.CASUAL -> R.string.mode_casual+ GameMode.DAILY -> R.string.mode_daily+ }+ )+ }, onSelect = actions::setGameMode, ) }, alignment = AppBarAlignment.Center, actions = {- IconButton(onClick = onOpenGameCenter) { IconEmojiEvents() }- IconButton(onClick = onOpenSettings) { IconSettings() }+ GameTopBarActions(+ onOpenGameCenter = onOpenGameCenter,+ onOpenSettings = onOpenSettings,+ ) }, scrollBehavior = appBarScrollBehavior(), ) { padding ->@@ -85,11 +89,7 @@ fun ArrowsGameScreen( verticalArrangement = Arrangement.spacedBy(Spacing.md), ) { if (daily) {- Text(- stringResource(R.string.daily_streak, state.dailyStreak),- style = MaterialTheme.typography.labelLarge,- color = MaterialTheme.colorScheme.onSurfaceVariant,- )+ DailyStreakText(state.dailyStreak) } val game = state.game@@ -117,7 +117,7 @@ fun ArrowsGameScreen( ) { CircularProgressIndicator() } else -> {- Hearts(game.hearts)+ HeartsRow(remaining = game.hearts, total = STARTING_HEARTS) ArrowsBoard( game = game,@@ -180,74 +180,3 @@ fun ArrowsGameScreen( } } }--/**- * The hearts left.- *- * Spent hearts stay in place as hollow outlines rather than disappearing, so the row does not reflow- * and the player can see at a glance how much margin is gone.- */-@Composable-private fun Hearts(hearts: Int) {- val description = pluralStringResource(R.plurals.cd_hearts, hearts.coerceAtLeast(0), hearts.coerceAtLeast(0))- Row(- Modifier.clearAndSetSemantics { contentDescription = description },- horizontalArrangement = Arrangement.spacedBy(Spacing.xs),- ) {- repeat(STARTING_HEARTS) { index ->- val spent = index >= hearts- IconFavorite(- Modifier.size(20.dp),- tint = if (spent) MaterialTheme.colorScheme.surfaceContainerHighest- else MaterialTheme.colorScheme.error,- )- }- }-}--/**- * The title doubles as the mode switch.- *- * There is only one board, so putting the mode where the title would go keeps the app bar to a single- * control rather than adding a tab row for two options.- */-@Composable-private fun ModeDropdown(- mode: GameMode,- level: Int,- onSelect: (GameMode) -> Unit,-) {- var expanded by remember { mutableStateOf(false) }- Box {- TextButton(onClick = { expanded = true }) {- Text(- when (mode) {- GameMode.CASUAL -> stringResource(R.string.level_title, level)- GameMode.DAILY -> stringResource(R.string.mode_daily)- },- style = MaterialTheme.typography.titleLarge,- )- IconArrowDropDown()- }- DropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {- for (option in GameMode.entries) {- DropdownMenuItem(- text = {- Text(- stringResource(- when (option) {- GameMode.CASUAL -> R.string.mode_casual- GameMode.DAILY -> R.string.mode_daily- }- )- )- },- onClick = {- expanded = false- onSelect(option)- },- )- }- }- }-}
games/arrows/src/main/res/values/strings.xml
diff --git a/games/arrows/src/main/res/values/strings.xml b/games/arrows/src/main/res/values/strings.xmlindex 0a74f3c9d1..7950ea9bbc 100644--- a/games/arrows/src/main/res/values/strings.xml+++ b/games/arrows/src/main/res/values/strings.xml@@ -22,8 +22,6 @@ <string name="out_of_hearts">Out of hearts!</string> <!-- ArrowsGameScreen: Retries the level after running out of hearts. Verb phrase --> <string name="try_again">Try Again</string>- <!-- DailyStatusBar: Current daily streak length. %1$d = consecutive days, e.g. 5 -->- <string name="daily_streak">Streak: <xliff:g id="days" example="5">%1$d</xliff:g></string> <!-- ArrowsGameScreen: Hint under a fresh board explaining the one gesture. Imperative sentence --> <string name="how_to_play">Tap an arrow to send it off the board</string> @@ -35,11 +33,6 @@ <!-- SettingsScreen: Explains what the show-routes toggle does. Sentence --> <string name="show_routes_description">Trace the path a blocked arrow tried to take.</string> - <!-- ArrowsBoard: Content description of the hearts remaining. %1$d = hearts left, 0 to 3, e.g. 2 -->- <plurals name="cd_hearts">- <item quantity="one"><xliff:g id="count" example="1">%1$d</xliff:g> heart left</item>- <item quantity="other"><xliff:g id="count" example="2">%1$d</xliff:g> hearts left</item>- </plurals> <!-- ArrowsBoard: Content description of one arrow. %1$s = the direction it points, e.g. right. %2$d = row number starting at 1, e.g. 3. %3$d = column number starting at 1, e.g. 5 --> <string name="cd_arrow">Arrow pointing <xliff:g id="direction" example="right">%1$s</xliff:g> at row <xliff:g id="row" example="3">%2$d</xliff:g>, column <xliff:g id="column" example="5">%3$d</xliff:g></string> <!-- ArrowsBoard: Direction name, spoken in cd_arrow. Adverb -->
games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/DisplayNames.kt
diff --git a/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/DisplayNames.kt b/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/DisplayNames.ktindex 30f1be503c..f8c6f9b880 100644--- a/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/DisplayNames.kt+++ b/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/DisplayNames.kt@@ -28,12 +28,3 @@ fun Difficulty.displayName(): String = stringResource( Difficulty.EXPERT -> R.string.difficulty_expert } )--/** `mm:ss`, and `h:mm:ss` once a field has run past the hour. */-fun formatTime(seconds: Int): String {- val hours = seconds / 3600- val minutes = (seconds % 3600) / 60- val secs = seconds % 60- return if (hours > 0) "%d:%02d:%02d".format(hours, minutes, secs)- else "%02d:%02d".format(minutes, secs)-}
games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/GameBoardScreen.kt
diff --git a/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/GameBoardScreen.kt b/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/GameBoardScreen.ktindex 591152c94f..a9f895d50c 100644--- a/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/GameBoardScreen.kt+++ b/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/GameBoardScreen.kt@@ -1,6 +1,5 @@ package com.vayunmathur.games.minesweeper.ui -import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column@@ -30,14 +29,16 @@ import com.vayunmathur.library.ui.CircularProgressIndicator import com.vayunmathur.library.ui.ExperimentalMaterial3Api import com.vayunmathur.library.ui.IconFlag import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.library.ui.SegmentedButton import com.vayunmathur.library.ui.SegmentedButtonDefaults import com.vayunmathur.library.ui.SingleChoiceSegmentedButtonRow import com.vayunmathur.library.ui.Spacing-import com.vayunmathur.library.ui.Surface import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.TextButton import com.vayunmathur.library.ui.appBarScrollBehavior+import com.vayunmathur.library.ui.game.GameResultOverlay+import com.vayunmathur.library.ui.game.formatDuration /** Caps the field on tablets, where a full-width board would give absurdly large cells. */ private val FieldMaxWidth = 480.dp@@ -64,7 +65,7 @@ fun GameBoardScreen( actions = { if (game != null) { Text(- formatTime(game.elapsedSeconds),+ formatDuration(game.elapsedSeconds), style = MaterialTheme.typography.titleMedium, modifier = Modifier.padding(end = Spacing.lg), )@@ -142,12 +143,21 @@ fun GameBoardScreen( } if (game.isOver) {- ResultOverlay(- won = game.outcome == GameOutcome.WON,- elapsedSeconds = game.elapsedSeconds,+ val won = game.outcome == GameOutcome.WON+ GameResultOverlay(+ title = stringResource(if (won) R.string.cleared else R.string.boom),+ won = won, onPlayAgain = { actions.restart() }, onBack = onExit,- )+ ) {+ // A losing time is not an achievement, so it is only shown on a win.+ if (won) {+ Text(+ "${stringResource(UiR.string.game_time)}: " ++ formatDuration(game.elapsedSeconds)+ )+ }+ } } } }@@ -174,46 +184,3 @@ private fun TapModeToggle(mode: TapMode, onSelect: (TapMode) -> Unit) { } } }--@Composable-private fun ResultOverlay(- won: Boolean,- elapsedSeconds: Int,- onPlayAgain: () -> Unit,- onBack: () -> Unit,-) {- Box(- Modifier- .fillMaxSize()- // Scrim, so the card reads as modal instead of letting the field show around it.- .background(MaterialTheme.colorScheme.scrim.copy(alpha = 0.7f))- .padding(Spacing.lg),- contentAlignment = Alignment.Center,- ) {- Surface(- shape = MaterialTheme.shapes.extraLarge,- color = MaterialTheme.colorScheme.surfaceContainerHigh,- ) {- Column(- Modifier.padding(Spacing.xl),- horizontalAlignment = Alignment.CenterHorizontally,- verticalArrangement = Arrangement.spacedBy(Spacing.md),- ) {- Text(- stringResource(if (won) R.string.cleared else R.string.boom),- style = MaterialTheme.typography.headlineSmall,- color = if (won) MaterialTheme.colorScheme.primary- else MaterialTheme.colorScheme.error,- )- // A losing time is not an achievement, so it is only shown on a win.- if (won) Text("${stringResource(R.string.time)}: ${formatTime(elapsedSeconds)}")- Button(onClick = onPlayAgain, Modifier.fillMaxWidth()) {- Text(stringResource(R.string.play_again))- }- TextButton(onClick = onBack, Modifier.fillMaxWidth()) {- Text(stringResource(R.string.back))- }- }- }- }-}
games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/HomeScreen.kt
diff --git a/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/HomeScreen.kt b/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/HomeScreen.ktindex 85325cac00..19fead6db0 100644--- a/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/HomeScreen.kt+++ b/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/HomeScreen.kt@@ -25,12 +25,12 @@ import com.vayunmathur.games.minesweeper.ui.dialogs.GameConfigDialog import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.Card-import com.vayunmathur.library.ui.IconButton-import com.vayunmathur.library.ui.IconEmojiEvents import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Spacing import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.appBarScrollBehavior+import com.vayunmathur.library.ui.game.GameTopBarActions+import com.vayunmathur.library.ui.game.formatDuration import com.vayunmathur.library.util.NavBackStack @Composable@@ -44,7 +44,7 @@ fun HomeScreen( AppScaffold( title = stringResource(R.string.app_name), actions = {- IconButton(onClick = { backStack.add(Route.GameCenter) }) { IconEmojiEvents() }+ GameTopBarActions(onOpenGameCenter = { backStack.add(Route.GameCenter) }) }, scrollBehavior = appBarScrollBehavior(), ) { padding ->@@ -125,7 +125,7 @@ private fun SizeStatsCard( ) if (stats.bestTimeSeconds < Int.MAX_VALUE) { Text(- formatTime(stats.bestTimeSeconds),+ formatDuration(stats.bestTimeSeconds), style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant, textAlign = TextAlign.Center,
games/minesweeper/src/main/res/values/strings.xml
diff --git a/games/minesweeper/src/main/res/values/strings.xml b/games/minesweeper/src/main/res/values/strings.xmlindex 4ad8c19926..332f1269a8 100644--- a/games/minesweeper/src/main/res/values/strings.xml+++ b/games/minesweeper/src/main/res/values/strings.xml@@ -53,10 +53,6 @@ <string name="cleared">Field Cleared!</string> <!-- LossOverlay: Title shown when a mine is opened. Declarative, sympathetic --> <string name="boom">Boom!</string>- <!-- WinOverlay: Label for the finishing time, e.g. Time: 01:24. Noun -->- <string name="time">Time</string>- <!-- WinOverlay / LossOverlay: Plays another field with the same settings. Verb phrase -->- <string name="play_again">Play Again</string> <!-- HomeScreen stat card: Label under the cleared-of-played ratio. Verb past participle --> <string name="cleared_count">cleared</string>
games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/NonogramGameScreen.kt
diff --git a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/NonogramGameScreen.kt b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/NonogramGameScreen.ktindex 9955f908e5..03fce5518b 100644--- a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/NonogramGameScreen.kt+++ b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/NonogramGameScreen.kt@@ -3,23 +3,14 @@ package com.vayunmathur.games.nonogram.ui import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column-import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.widthIn import androidx.compose.runtime.Composable-import androidx.compose.runtime.getValue-import androidx.compose.runtime.mutableStateOf-import androidx.compose.runtime.remember-import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier-import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource-import androidx.compose.ui.semantics.clearAndSetSemantics-import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import com.vayunmathur.games.nonogram.R@@ -33,14 +24,7 @@ import com.vayunmathur.library.ui.AppBarAlignment import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.CircularProgressIndicator-import com.vayunmathur.library.ui.DropdownMenu-import com.vayunmathur.library.ui.DropdownMenuItem import com.vayunmathur.library.ui.ExperimentalMaterial3Api-import com.vayunmathur.library.ui.IconArrowDropDown-import com.vayunmathur.library.ui.IconButton-import com.vayunmathur.library.ui.IconEmojiEvents-import com.vayunmathur.library.ui.IconFavorite-import com.vayunmathur.library.ui.IconSettings import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.OutlinedButton import com.vayunmathur.library.ui.SegmentedButton@@ -48,8 +32,11 @@ import com.vayunmathur.library.ui.SegmentedButtonDefaults import com.vayunmathur.library.ui.SingleChoiceSegmentedButtonRow import com.vayunmathur.library.ui.Spacing import com.vayunmathur.library.ui.Text-import com.vayunmathur.library.ui.TextButton import com.vayunmathur.library.ui.appBarScrollBehavior+import com.vayunmathur.library.ui.game.DailyStreakText+import com.vayunmathur.library.ui.game.GameModeChooser+import com.vayunmathur.library.ui.game.GameTopBarActions+import com.vayunmathur.library.ui.game.HeartsRow /** Caps the board on tablets, where a full-width grid would give absurdly large cells. */ private val BoardMaxWidth = 460.dp@@ -79,30 +66,6 @@ private fun MarkModeToggle(mode: MarkMode, onSelect: (MarkMode) -> Unit) { } } -/**- * The hearts left.- *- * Spent hearts stay in place as dimmed shapes rather than disappearing, so the row does not reflow and- * the player can see at a glance how much margin is gone.- */-@Composable-private fun Hearts(hearts: Int) {- val safe = hearts.coerceAtLeast(0)- val description = pluralStringResource(R.plurals.cd_hearts, safe, safe)- Row(- Modifier.clearAndSetSemantics { contentDescription = description },- horizontalArrangement = Arrangement.spacedBy(Spacing.xs),- ) {- repeat(STARTING_HEARTS) { index ->- IconFavorite(- Modifier.size(20.dp),- tint = if (index >= hearts) MaterialTheme.colorScheme.surfaceContainerHighest- else MaterialTheme.colorScheme.error,- )- }- }-}- /** * The board, with no dependency on the ViewModel so it can be rendered from a `@Preview` — see * `src/screenshotTest`.@@ -117,16 +80,33 @@ fun NonogramGameScreen( val daily = state.mode == GameMode.DAILY AppScaffold( title = {- ModeDropdown(- mode = state.mode,- level = state.level,+ GameModeChooser(+ selected = state.mode,+ options = GameMode.entries,+ // The ladder mode folds the level into its label, so the bar needs no second title.+ label = { mode ->+ when (mode) {+ GameMode.CASUAL -> stringResource(R.string.level_title, state.level)+ GameMode.DAILY -> stringResource(R.string.mode_daily)+ }+ },+ menuLabel = { mode ->+ stringResource(+ when (mode) {+ GameMode.CASUAL -> R.string.mode_casual+ GameMode.DAILY -> R.string.mode_daily+ }+ )+ }, onSelect = actions::setGameMode, ) }, alignment = AppBarAlignment.Center, actions = {- IconButton(onClick = onOpenGameCenter) { IconEmojiEvents() }- IconButton(onClick = onOpenSettings) { IconSettings() }+ GameTopBarActions(+ onOpenGameCenter = onOpenGameCenter,+ onOpenSettings = onOpenSettings,+ ) }, scrollBehavior = appBarScrollBehavior(), ) { padding ->@@ -139,11 +119,7 @@ fun NonogramGameScreen( verticalArrangement = Arrangement.spacedBy(Spacing.md), ) { if (daily) {- Text(- stringResource(R.string.daily_streak, state.dailyStreak),- style = MaterialTheme.typography.labelLarge,- color = MaterialTheme.colorScheme.onSurfaceVariant,- )+ DailyStreakText(state.dailyStreak) } val game = state.game@@ -169,7 +145,7 @@ fun NonogramGameScreen( ) { CircularProgressIndicator() } else -> {- Hearts(game.hearts)+ HeartsRow(remaining = game.hearts, total = STARTING_HEARTS) NonogramBoard( game = game,@@ -235,50 +211,3 @@ fun NonogramGameScreen( } } }--/**- * The title doubles as the mode switch.- *- * There is only one board, so putting the mode where the title would go keeps the app bar to a single- * control rather than adding a tab row for two options.- */-@Composable-private fun ModeDropdown(- mode: GameMode,- level: Int,- onSelect: (GameMode) -> Unit,-) {- var expanded by remember { mutableStateOf(false) }- Box {- TextButton(onClick = { expanded = true }) {- Text(- when (mode) {- GameMode.CASUAL -> stringResource(R.string.level_title, level)- GameMode.DAILY -> stringResource(R.string.mode_daily)- },- style = MaterialTheme.typography.titleLarge,- )- IconArrowDropDown()- }- DropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {- for (option in GameMode.entries) {- DropdownMenuItem(- text = {- Text(- stringResource(- when (option) {- GameMode.CASUAL -> R.string.mode_casual- GameMode.DAILY -> R.string.mode_daily- }- )- )- },- onClick = {- expanded = false- onSelect(option)- },- )- }- }- }-}
games/nonogram/src/main/res/values/strings.xml
diff --git a/games/nonogram/src/main/res/values/strings.xml b/games/nonogram/src/main/res/values/strings.xmlindex 71b6552418..20cbea9473 100644--- a/games/nonogram/src/main/res/values/strings.xml+++ b/games/nonogram/src/main/res/values/strings.xml@@ -18,8 +18,7 @@ <string name="daily_come_back_tomorrow">Solved! Come back tomorrow for a new puzzle.</string> <!-- NonogramGameScreen: Celebratory line shown when a level is completed. Declarative --> <string name="solved">Solved!</string>- <!-- DailyStatusBar: Current daily streak length. %1$d = consecutive days, e.g. 5 -->- <string name="daily_streak">Streak: <xliff:g id="days" example="5">%1$d</xliff:g></string>+ <!-- NonogramGameScreen: Shown after clearing the daily, since there is only one per day. Sentence --> <!-- NonogramGameScreen: Hint under a fresh board explaining the two gestures. Imperative sentence --> <string name="how_to_play">Tap to fill, long press to cross out</string> <!-- MarkModeToggle: Tap places part of the picture. Verb, imperative -->@@ -29,12 +28,6 @@ <!-- NonogramGameScreen: Shown when the last heart is spent. Declarative, sympathetic --> <string name="out_of_hearts">Out of hearts!</string> - <!-- NonogramGameScreen: Content description of the hearts remaining. %1$d = hearts left, 0 to 3, e.g. 2 -->- <plurals name="cd_hearts">- <item quantity="one"><xliff:g id="count" example="1">%1$d</xliff:g> heart left</item>- <item quantity="other"><xliff:g id="count" example="2">%1$d</xliff:g> hearts left</item>- </plurals>- <!-- NonogramGameScreen: Shown when no fair puzzle could be generated for this level. Sentence --> <string name="generation_failed">Could not build a puzzle for this level.</string> <!-- NonogramGameScreen: Retries generation after a failure, and the level after running out of hearts. Verb -->
games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameBoardScreen.kt
diff --git a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameBoardScreen.kt b/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameBoardScreen.ktindex da2b61098b..f14bbf90e4 100644--- a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameBoardScreen.kt+++ b/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameBoardScreen.kt@@ -17,8 +17,8 @@ import androidx.compose.ui.unit.dp import com.vayunmathur.games.pipes.R import com.vayunmathur.games.pipes.platform.GameBoardUiState import com.vayunmathur.games.pipes.platform.PipesActions-import com.vayunmathur.games.pipes.ui.components.MovesInfoBox-import com.vayunmathur.games.pipes.ui.components.PuzzleInfoBox+import com.vayunmathur.library.ui.game.LevelPickerBox+import com.vayunmathur.library.ui.game.MovesBox import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.ExperimentalMaterial3Api@@ -33,7 +33,7 @@ import com.vayunmathur.library.ui.R as UiR fun GameBoardScreen(state: GameBoardUiState, actions: PipesActions, onBack: () -> Unit, onLevelChange: (Int) -> Unit) { AppScaffold(title = "", onNavigateBack = onBack, scrollBehavior = appBarScrollBehavior()) { innerPadding -> Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {- val infoBoxes = @Composable { PuzzleInfoBox(levelIndex = state.levelIndex, onLevelChange = onLevelChange, isCompleted = state.isCompleted, maxLevelIndex = state.maxLevelIndex); MovesInfoBox(moves = state.moves, bestScore = state.bestScore, optimalMoves = state.levelData.optimalMoves) }+ val infoBoxes = @Composable { LevelPickerBox(levelIndex = state.levelIndex, onLevelChange = onLevelChange, isCompleted = state.isCompleted, maxLevelIndex = state.maxLevelIndex); MovesBox(moves = state.moves, bestScore = state.bestScore, optimalMoves = state.levelData.optimalMoves) } val actionButtons = @Composable { if (!state.isLevelWon) { Button(onClick = { actions.onUndo() }, enabled = state.canUndo) { Text(stringResource(UiR.string.undo)) }; Button(onClick = { actions.onRestart() }, enabled = state.canUndo) { Text(stringResource(R.string.restart)) } } else if (state.levelIndex < state.maxLevelIndex) { Button(onClick = { onLevelChange(state.levelIndex + 1) }) { Text(stringResource(R.string.next_level)) } } } val board = @Composable { boardModifier: Modifier -> GameBoard(levelData = state.levelData, gameState = state.gameState, activeColor = state.activeColor, activePath = state.activePath, onStartDraw = actions::startDraw, onExtendPath = actions::extendPath, onCommitDraw = actions::commitDraw, isLevelWon = state.isLevelWon, colorblind = state.colorblind, modifier = boardModifier) } BoxWithConstraints(modifier = Modifier.fillMaxSize().padding(innerPadding).padding(16.dp)) {
games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/PackListScreen.kt
diff --git a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/PackListScreen.kt b/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/PackListScreen.ktindex e86c2e3822..c69a4d9b2d 100644--- a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/PackListScreen.kt+++ b/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/PackListScreen.kt@@ -16,7 +16,8 @@ import androidx.compose.ui.unit.dp import com.vayunmathur.games.pipes.R import com.vayunmathur.games.pipes.platform.DailyProgress import com.vayunmathur.games.pipes.platform.PackProgress-import com.vayunmathur.games.pipes.ui.components.DailyCard+import com.vayunmathur.library.ui.game.DailyChallengeCard+import com.vayunmathur.library.ui.game.GameTopBarActions import com.vayunmathur.library.ui.Card import com.vayunmathur.library.ui.CardDefaults import com.vayunmathur.library.ui.DetailLazyColumn@@ -31,8 +32,8 @@ import com.vayunmathur.library.ui.appBarScrollBehavior @OptIn(ExperimentalMaterial3Api::class) @Composable fun PackListScreen(packs: List<PackProgress>, onOpenPack: (Int) -> Unit, onOpenSettings: () -> Unit, onOpenGameCenter: () -> Unit, daily: DailyProgress? = null, onOpenDaily: () -> Unit = {}) {- DetailLazyColumn(title = stringResource(R.string.pack_selector), actions = { IconButton(onClick = onOpenSettings) { IconSettings() }; IconButton(onClick = onOpenGameCenter) { Icon(painterResource(id = android.R.drawable.btn_star_big_on), "Achievements") } }, scrollBehavior = appBarScrollBehavior()) {- daily?.let { item { DailyCard(it, onOpenDaily) } }+ DetailLazyColumn(title = stringResource(R.string.pack_selector), actions = { GameTopBarActions(onOpenGameCenter = onOpenGameCenter, onOpenSettings = onOpenSettings) }, scrollBehavior = appBarScrollBehavior()) {+ daily?.let { item { DailyChallengeCard(day = it.day, completed = it.completed, total = it.total, streak = it.streak, onOpen = onOpenDaily) } } itemsIndexed(packs) { index, pack -> Card(Modifier.clickable { onOpenPack(index) }, colors = CardDefaults.cardColors(MaterialTheme.colorScheme.surface)) { Row(Modifier.fillMaxWidth().padding(16.dp), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) { Column { Text(pack.name, style = MaterialTheme.typography.headlineMedium); Text(pack.shape.replaceFirstChar { it.uppercase() }, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f)) }; Text("${pack.completed}/${pack.total}", style = MaterialTheme.typography.titleMedium) } } } } }
games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/components/DailyCard.kt
diff --git a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/components/DailyCard.kt b/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/components/DailyCard.ktdeleted file mode 100644index d5b321885f..0000000000--- a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/components/DailyCard.kt+++ /dev/null@@ -1,33 +0,0 @@-package com.vayunmathur.games.pipes.ui.components--import androidx.compose.foundation.clickable-import androidx.compose.foundation.layout.Arrangement-import androidx.compose.foundation.layout.Column-import androidx.compose.foundation.layout.Row-import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.foundation.layout.padding-import androidx.compose.runtime.Composable-import androidx.compose.ui.Alignment-import androidx.compose.ui.Modifier-import androidx.compose.ui.res.stringResource-import androidx.compose.ui.unit.dp-import com.vayunmathur.games.pipes.R-import com.vayunmathur.games.pipes.platform.DailyProgress-import com.vayunmathur.library.ui.Card-import com.vayunmathur.library.ui.CardDefaults-import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.Text-import java.time.LocalDate-import java.time.format.DateTimeFormatter-import java.time.format.FormatStyle--@Composable-fun DailyCard(daily: DailyProgress, onOpen: () -> Unit) {- Card(Modifier.clickable { onOpen() }, colors = CardDefaults.cardColors(MaterialTheme.colorScheme.primaryContainer)) {- Row(Modifier.fillMaxWidth().padding(16.dp), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) {- Column { Text(stringResource(R.string.daily_challenge), style = MaterialTheme.typography.headlineMedium); Text(formatEpochDay(daily.day), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.7f)) }- Column(horizontalAlignment = Alignment.End) { Text("${daily.completed}/${daily.total}", style = MaterialTheme.typography.titleMedium); Text(stringResource(R.string.daily_streak, daily.streak.toInt()), style = MaterialTheme.typography.bodyMedium) }- }- }-}-private fun formatEpochDay(day: Long): String = LocalDate.ofEpochDay(day).format(DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM))
games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/components/InfoBox.kt
diff --git a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/components/InfoBox.kt b/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/components/InfoBox.ktdeleted file mode 100644index b29c6b320a..0000000000--- a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/components/InfoBox.kt+++ /dev/null@@ -1,19 +0,0 @@-package com.vayunmathur.games.pipes.ui.components--import androidx.compose.foundation.layout.Arrangement-import androidx.compose.foundation.layout.Column-import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.size-import androidx.compose.foundation.shape.RoundedCornerShape-import androidx.compose.runtime.Composable-import androidx.compose.ui.Alignment-import androidx.compose.ui.Modifier-import androidx.compose.ui.unit.dp-import androidx.compose.ui.unit.sp-import com.vayunmathur.library.ui.Surface-import com.vayunmathur.library.ui.Text--@Composable-fun InfoBox(title: String, content: @Composable () -> Unit) {- Surface(modifier = Modifier.size(width = 150.dp, height = 120.dp), shape = RoundedCornerShape(12.dp)) { Column(modifier = Modifier.padding(8.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.SpaceAround) { Text(text = title, fontSize = 16.sp); content() } }-}
games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/components/MovesInfoBox.kt
diff --git a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/components/MovesInfoBox.kt b/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/components/MovesInfoBox.ktdeleted file mode 100644index 49b0dc4a25..0000000000--- a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/components/MovesInfoBox.kt+++ /dev/null@@ -1,17 +0,0 @@-package com.vayunmathur.games.pipes.ui.components--import androidx.compose.foundation.layout.Column-import androidx.compose.runtime.Composable-import androidx.compose.ui.Alignment-import androidx.compose.ui.res.stringResource-import androidx.compose.ui.text.font.FontWeight-import androidx.compose.ui.unit.sp-import com.vayunmathur.games.pipes.R-import com.vayunmathur.library.ui.Text--@Composable-fun MovesInfoBox(moves: Int, bestScore: Int?, optimalMoves: Int) {- InfoBox(title = stringResource(R.string.moves)) {- Column(horizontalAlignment = Alignment.CenterHorizontally) { Text(text = "$moves", fontSize = 24.sp, fontWeight = FontWeight.Bold); Text(text = "${bestScore ?: "-"} / $optimalMoves", fontSize = 18.sp, fontWeight = FontWeight.Bold) }- }-}
games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/components/PuzzleInfoBox.kt
diff --git a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/components/PuzzleInfoBox.kt b/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/components/PuzzleInfoBox.ktdeleted file mode 100644index b1751cdb65..0000000000--- a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/components/PuzzleInfoBox.kt+++ /dev/null@@ -1,29 +0,0 @@-package com.vayunmathur.games.pipes.ui.components--import androidx.compose.foundation.layout.Arrangement-import androidx.compose.foundation.layout.Row-import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.runtime.Composable-import androidx.compose.ui.Alignment-import androidx.compose.ui.Modifier-import androidx.compose.ui.res.painterResource-import androidx.compose.ui.res.stringResource-import androidx.compose.ui.text.font.FontWeight-import androidx.compose.ui.unit.sp-import com.vayunmathur.games.pipes.R-import com.vayunmathur.library.ui.Icon-import com.vayunmathur.library.ui.IconButton-import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.Text--@Composable-fun PuzzleInfoBox(levelIndex: Int, onLevelChange: (Int) -> Unit, isCompleted: Boolean, maxLevelIndex: Int) {- InfoBox(title = stringResource(R.string.level)) {- Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween, modifier = Modifier.fillMaxWidth()) {- IconButton(onClick = { onLevelChange(levelIndex - 1) }, enabled = levelIndex > 0) { Icon(painterResource(R.drawable.arrow_back_24px), contentDescription = stringResource(R.string.previous_level)) }- Text(text = "${levelIndex + 1}", fontSize = 24.sp, fontWeight = FontWeight.Bold)- IconButton(onClick = { onLevelChange(levelIndex + 1) }, enabled = levelIndex < maxLevelIndex) { Icon(painterResource(R.drawable.arrow_forward_24px), contentDescription = stringResource(R.string.next_level)) }- }- if (isCompleted) { Text(text = stringResource(R.string.completed), color = MaterialTheme.colorScheme.error, fontSize = 12.sp, fontWeight = FontWeight.Bold) }- }-}
games/pipes/src/main/res/drawable/arrow_back_24px.xml
diff --git a/games/pipes/src/main/res/drawable/arrow_back_24px.xml b/games/pipes/src/main/res/drawable/arrow_back_24px.xmldeleted file mode 100644index 7b45e90f7b..0000000000--- a/games/pipes/src/main/res/drawable/arrow_back_24px.xml+++ /dev/null@@ -1,5 +0,0 @@-<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="24dp" android:tint="#000000" android:viewportHeight="960" android:viewportWidth="960" android:width="24dp">- - <path android:fillColor="@android:color/white" android:pathData="M313,520L537,744L480,800L160,480L480,160L537,216L313,440L800,440L800,520L313,520Z"/>- -</vector>
games/pipes/src/main/res/drawable/arrow_forward_24px.xml
diff --git a/games/pipes/src/main/res/drawable/arrow_forward_24px.xml b/games/pipes/src/main/res/drawable/arrow_forward_24px.xmldeleted file mode 100644index 143dcf9ac9..0000000000--- a/games/pipes/src/main/res/drawable/arrow_forward_24px.xml+++ /dev/null@@ -1,5 +0,0 @@-<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="24dp" android:tint="#000000" android:viewportHeight="960" android:viewportWidth="960" android:width="24dp">- - <path android:fillColor="@android:color/white" android:pathData="M647,520L160,520L160,440L647,440L423,216L480,160L800,480L480,800L423,744L647,520Z"/>- -</vector>
games/pipes/src/main/res/values/strings.xml
diff --git a/games/pipes/src/main/res/values/strings.xml b/games/pipes/src/main/res/values/strings.xmlindex 77eb8de0a6..1273ce7f2c 100644--- a/games/pipes/src/main/res/values/strings.xml+++ b/games/pipes/src/main/res/values/strings.xml@@ -5,24 +5,14 @@ <string name="pack_selector">Pack Select</string> <!-- LevelScreen: TopAppBar title for level grid inside a pack. Noun phrase --> <string name="level_selector">Level Select</string>- <!-- GameScreen PuzzleInfoBox: Title of info box showing current level number with prev/next navigation. Noun -->- <string name="level">Level</string>- <!-- GameScreen MovesInfoBox: Title of info box showing move counter and best/optimal. Noun -->- <string name="moves">Moves</string> <!-- GameScreen: Button to reset current level to initial state. Verb --> <string name="restart">Restart</string>- <!-- GameScreen PuzzleInfoBox: Accessibility content description for back arrow to previous level. Noun phrase -->- <string name="previous_level">Previous Level</string>- <!-- GameScreen PuzzleInfoBox: Accessibility content description for forward arrow to next level. Noun phrase -->+ <!-- GameScreen: Button advancing to the next level once the current one is solved. Noun phrase --> <string name="next_level">Next Level</string>- <!-- GameScreen PuzzleInfoBox: Red badge below level number when level already completed (stats present). Adjective/status -->- <string name="completed">Completed</string> <!-- SettingsScreen: Toggle label for colorblind accessibility mode. Noun phrase --> <string name="colorblind_mode">Colorblind mode</string> <!-- SettingsScreen: Subtitle explaining colorblind mode labels each flow with letter A-Z. Sentence --> <string name="colorblind_mode_desc">Label each flow with a letter (A–Z)</string> <!-- PackScreen / DailyLevelScreen: Pinned card and screen title for the date-generated daily pack. Noun phrase --> <string name="daily_challenge">Daily Challenge</string>- <!-- PackScreen daily card: Consecutive days the player has cleared the daily pack. %1$d = streak length e.g. 5. Noun phrase with number -->- <string name="daily_streak"><xliff:g id="days" example="5">%1$d</xliff:g> day streak</string> </resources>
games/pipes/src/screenshotTest/kotlin/com/vayunmathur/games/pipes/MetadataPreviews.kt
diff --git a/games/pipes/src/screenshotTest/kotlin/com/vayunmathur/games/pipes/MetadataPreviews.kt b/games/pipes/src/screenshotTest/kotlin/com/vayunmathur/games/pipes/MetadataPreviews.ktindex 1179d4928f..8b14e36dc4 100644--- a/games/pipes/src/screenshotTest/kotlin/com/vayunmathur/games/pipes/MetadataPreviews.kt+++ b/games/pipes/src/screenshotTest/kotlin/com/vayunmathur/games/pipes/MetadataPreviews.kt@@ -6,6 +6,8 @@ import com.android.tools.screenshot.PreviewTest import com.vayunmathur.games.pipes.data.CellPos import com.vayunmathur.games.pipes.data.EndpointPair import com.vayunmathur.games.pipes.data.LevelData+import com.vayunmathur.games.pipes.ui.GameBoardScreen+import com.vayunmathur.games.pipes.ui.PackListScreen import com.vayunmathur.games.pipes.ui.PipesTheme import com.vayunmathur.games.pipes.platform.GameBoardUiState import com.vayunmathur.games.pipes.platform.PackProgress
games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/GameBoardScreen.kt
diff --git a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/GameBoardScreen.kt b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/GameBoardScreen.ktindex f2adbdc821..252b366aaa 100644--- a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/GameBoardScreen.kt+++ b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/GameBoardScreen.kt@@ -9,9 +9,9 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll-import androidx.compose.material3.ExperimentalMaterial3Api-import androidx.compose.material3.MaterialTheme-import androidx.compose.material3.Text+import com.vayunmathur.library.ui.ExperimentalMaterial3Api+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.AppScaffold import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment@@ -24,6 +24,7 @@ import com.vayunmathur.games.solitaire.data.SolitaireUiState import com.vayunmathur.games.solitaire.platform.SolitaireActions import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.appBarScrollBehavior+import com.vayunmathur.library.ui.game.formatDuration private val SolitaireBoardMaxWidth = 640.dp @@ -40,7 +41,7 @@ fun GameBoardScreen(state: SolitaireUiState, mode: GameMode, actions: SolitaireA val moveCount = activeGame?.second ?: 0 val elapsed = activeGame?.third ?: 0 val modeName = mode.displayName()- val timeText = "%02d:%02d".format(elapsed / 60, elapsed % 60)+ val timeText = formatDuration(elapsed) AppScaffold( title = modeName, actions = {
games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/HomeScreen.kt
diff --git a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/HomeScreen.kt b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/HomeScreen.ktindex 1f3d241b18..f16b4ec56d 100644--- a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/HomeScreen.kt+++ b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/HomeScreen.kt@@ -6,15 +6,7 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding-import androidx.compose.material3.Card-import androidx.compose.material3.CardDefaults-import androidx.compose.material3.ExperimentalMaterial3Api-import androidx.compose.material3.Icon-import androidx.compose.material3.IconButton-import androidx.compose.material3.MaterialTheme-import androidx.compose.material3.Text import androidx.compose.runtime.Composable-import com.vayunmathur.library.ui.AppScaffold import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf@@ -22,7 +14,6 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier-import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp@@ -33,9 +24,17 @@ import com.vayunmathur.games.solitaire.data.GameMode import com.vayunmathur.games.solitaire.platform.SolitaireViewModel import com.vayunmathur.games.solitaire.ui.dialogs.GameConfigDialog import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.Button+import com.vayunmathur.library.ui.Card+import com.vayunmathur.library.ui.CardDefaults+import com.vayunmathur.library.ui.ExperimentalMaterial3Api+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.TextButton import com.vayunmathur.library.ui.appBarScrollBehavior+import com.vayunmathur.library.ui.game.GameTopBarActions+import com.vayunmathur.library.ui.game.formatDuration import com.vayunmathur.library.util.NavBackStack @OptIn(ExperimentalMaterial3Api::class)@@ -53,9 +52,7 @@ fun HomeScreen(backStack: NavBackStack<Route>, viewModel: SolitaireViewModel) { AppScaffold( title = stringResource(R.string.app_name), actions = {- IconButton(onClick = { backStack.add(Route.GameCenter) }) {- Icon(painterResource(id = android.R.drawable.btn_star_big_on), "Achievements")- }+ GameTopBarActions(onOpenGameCenter = { backStack.add(Route.GameCenter) }) }, scrollBehavior = appBarScrollBehavior(), ) { paddingValues ->@@ -80,7 +77,7 @@ fun HomeScreen(backStack: NavBackStack<Route>, viewModel: SolitaireViewModel) { Text("${stats.gamesWon}/${stats.gamesPlayed}", style = MaterialTheme.typography.bodyLarge, textAlign = TextAlign.Center) Text(stringResource(R.string.won), style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f), textAlign = TextAlign.Center) if (stats.bestTimeSeconds < Int.MAX_VALUE) {- Text("%02d:%02d".format(stats.bestTimeSeconds / 60, stats.bestTimeSeconds % 60), style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f), textAlign = TextAlign.Center)+ Text(formatDuration(stats.bestTimeSeconds), style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f), textAlign = TextAlign.Center) } } }
games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/WinOverlay.kt
diff --git a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/WinOverlay.kt b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/WinOverlay.ktindex ab4a3074b1..2d497d4eb0 100644--- a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/WinOverlay.kt+++ b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/WinOverlay.kt@@ -1,27 +1,19 @@ package com.vayunmathur.games.solitaire.ui -import androidx.compose.foundation.background-import androidx.compose.foundation.layout.Arrangement-import androidx.compose.foundation.layout.Box-import androidx.compose.foundation.layout.Column-import androidx.compose.foundation.layout.Row-import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.shape.RoundedCornerShape-import com.vayunmathur.library.ui.Button-import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.Surface-import com.vayunmathur.library.ui.Text import androidx.compose.runtime.Composable-import androidx.compose.ui.Alignment-import androidx.compose.ui.Modifier-import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.stringResource-import androidx.compose.ui.text.font.FontWeight-import androidx.compose.ui.unit.dp-import androidx.compose.ui.unit.sp import com.vayunmathur.games.solitaire.R+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.game.GameResultOverlay+import com.vayunmathur.library.ui.game.formatDuration +/**+ * Solitaire's win card.+ *+ * A thin wrapper over the shared [GameResultOverlay] — solitaire used to carry its own scrim alpha,+ * corner radius and type sizes, which drifted from the other games for no reason anyone could point at.+ */ @Composable fun WinOverlay( elapsedSeconds: Int,@@ -29,47 +21,21 @@ fun WinOverlay( onNewGame: () -> Unit, onBack: () -> Unit ) {- val minutes = elapsedSeconds / 60- val seconds = elapsedSeconds % 60-- Box(- Modifier- .fillMaxSize()- .background(Color.Black.copy(alpha = 0.6f)),- contentAlignment = Alignment.Center+ GameResultOverlay(+ title = stringResource(R.string.congratulations),+ won = true,+ onPlayAgain = onNewGame,+ onBack = onBack,+ playAgainLabel = stringResource(R.string.new_game),+ backLabel = stringResource(R.string.back), ) {- Surface(- shape = RoundedCornerShape(16.dp),- color = MaterialTheme.colorScheme.surface- ) {- Column(- Modifier.padding(32.dp),- horizontalAlignment = Alignment.CenterHorizontally,- verticalArrangement = Arrangement.spacedBy(16.dp)- ) {- Text(- stringResource(R.string.congratulations),- fontSize = 28.sp,- fontWeight = FontWeight.Bold,- color = MaterialTheme.colorScheme.primary- )- Text(- "${stringResource(R.string.time)}: %02d:%02d".format(minutes, seconds),- style = MaterialTheme.typography.titleMedium- )- Text(- "${stringResource(R.string.moves)}: $moveCount",- style = MaterialTheme.typography.titleMedium- )- Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) {- Button(onClick = onNewGame) {- Text(stringResource(R.string.new_game))- }- Button(onClick = onBack) {- Text(stringResource(R.string.back))- }- }- }- }+ Text(+ "${stringResource(R.string.time)}: ${formatDuration(elapsedSeconds)}",+ style = MaterialTheme.typography.titleMedium,+ )+ Text(+ "${stringResource(R.string.moves)}: $moveCount",+ style = MaterialTheme.typography.titleMedium,+ ) } }
games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/dialogs/GameConfigDialog.kt
diff --git a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/dialogs/GameConfigDialog.kt b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/dialogs/GameConfigDialog.ktindex a025d89a27..099dc29b70 100644--- a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/dialogs/GameConfigDialog.kt+++ b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/dialogs/GameConfigDialog.kt@@ -3,11 +3,11 @@ package com.vayunmathur.games.solitaire.ui.dialogs import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.material3.ExperimentalMaterial3Api-import androidx.compose.material3.SegmentedButton-import androidx.compose.material3.SegmentedButtonDefaults-import androidx.compose.material3.SingleChoiceSegmentedButtonRow-import androidx.compose.material3.Text+import com.vayunmathur.library.ui.ExperimentalMaterial3Api+import com.vayunmathur.library.ui.SegmentedButton+import com.vayunmathur.library.ui.SegmentedButtonDefaults+import com.vayunmathur.library.ui.SingleChoiceSegmentedButtonRow+import com.vayunmathur.library.ui.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf
games/solitaire/src/screenshotTest/kotlin/com/vayunmathur/games/solitaire/MetadataPreviews.kt
diff --git a/games/solitaire/src/screenshotTest/kotlin/com/vayunmathur/games/solitaire/MetadataPreviews.kt b/games/solitaire/src/screenshotTest/kotlin/com/vayunmathur/games/solitaire/MetadataPreviews.ktindex 67f28b3c93..c294119558 100644--- a/games/solitaire/src/screenshotTest/kotlin/com/vayunmathur/games/solitaire/MetadataPreviews.kt+++ b/games/solitaire/src/screenshotTest/kotlin/com/vayunmathur/games/solitaire/MetadataPreviews.kt@@ -15,6 +15,7 @@ import com.vayunmathur.games.solitaire.data.SpiderState import com.vayunmathur.games.solitaire.data.Suit import com.vayunmathur.games.solitaire.data.TableauPile import com.vayunmathur.games.solitaire.platform.SolitaireActions+import com.vayunmathur.games.solitaire.ui.GameBoardScreen import com.vayunmathur.library.ui.DynamicTheme /** Phone-shaped, roughly 1080x2340 at xxhdpi — comfortably above the F-Droid minimum. */
games/sudoku/src/main/java/com/vayunmathur/games/sudoku/ui/GameBoardScreen.kt
diff --git a/games/sudoku/src/main/java/com/vayunmathur/games/sudoku/ui/GameBoardScreen.kt b/games/sudoku/src/main/java/com/vayunmathur/games/sudoku/ui/GameBoardScreen.ktindex 0d7aa70d20..7d207dab3b 100644--- a/games/sudoku/src/main/java/com/vayunmathur/games/sudoku/ui/GameBoardScreen.kt+++ b/games/sudoku/src/main/java/com/vayunmathur/games/sudoku/ui/GameBoardScreen.kt@@ -1,6 +1,5 @@ package com.vayunmathur.games.sudoku.ui -import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column@@ -21,16 +20,17 @@ import com.vayunmathur.games.sudoku.ui.components.NumberPad import com.vayunmathur.games.sudoku.ui.components.SudokuGrid import com.vayunmathur.library.ui.AppBarAlignment import com.vayunmathur.library.ui.AppScaffold-import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.CircularProgressIndicator import com.vayunmathur.library.ui.FilledTonalButton import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.OutlinedButton+import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.library.ui.Spacing-import com.vayunmathur.library.ui.Surface import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.TextButton import com.vayunmathur.library.ui.appBarScrollBehavior+import com.vayunmathur.library.ui.game.GameResultOverlay+import com.vayunmathur.library.ui.game.formatDuration /** Caps the grid on tablets, where a full-width board would put the digits absurdly far apart. */ private val BoardMaxWidth = 520.dp@@ -54,7 +54,7 @@ fun GameBoardScreen( actions = { if (game != null) { Text(- formatTime(game.elapsedSeconds),+ formatDuration(game.elapsedSeconds), style = MaterialTheme.typography.titleMedium, modifier = Modifier.padding(end = Spacing.lg), )@@ -106,12 +106,21 @@ fun GameBoardScreen( } if (game.isWon) {- WinOverlay(- elapsedSeconds = game.elapsedSeconds,- hintsUsed = game.hintsUsed,+ GameResultOverlay(+ title = stringResource(R.string.congratulations),+ won = true, onPlayAgain = { actions.restart() }, onBack = onExit,- )+ ) {+ Text("${stringResource(UiR.string.game_time)}: ${formatDuration(game.elapsedSeconds)}")+ if (game.hintsUsed > 0) {+ Text(+ "${stringResource(R.string.hints_used)}: ${game.hintsUsed}",+ style = MaterialTheme.typography.bodySmall,+ color = MaterialTheme.colorScheme.onSurfaceVariant,+ )+ }+ } } } }@@ -166,51 +175,3 @@ private fun ActionBar( ) { Text(stringResource(R.string.give_up)) } } }--@Composable-private fun WinOverlay(- elapsedSeconds: Int,- hintsUsed: Int,- onPlayAgain: () -> Unit,- onBack: () -> Unit,-) {- Box(- Modifier- .fillMaxSize()- // Scrim, so the card reads as modal instead of letting the number pad show around it.- .background(MaterialTheme.colorScheme.scrim.copy(alpha = 0.7f))- .padding(Spacing.lg),- contentAlignment = Alignment.Center,- ) {- Surface(- shape = MaterialTheme.shapes.extraLarge,- color = MaterialTheme.colorScheme.surfaceContainerHigh,- ) {- Column(- Modifier.padding(Spacing.xl),- horizontalAlignment = Alignment.CenterHorizontally,- verticalArrangement = Arrangement.spacedBy(Spacing.md),- ) {- Text(- stringResource(R.string.congratulations),- style = MaterialTheme.typography.headlineSmall,- color = MaterialTheme.colorScheme.primary,- )- Text("${stringResource(R.string.time)}: ${formatTime(elapsedSeconds)}")- if (hintsUsed > 0) {- Text(- "${stringResource(R.string.hints_used)}: $hintsUsed",- style = MaterialTheme.typography.bodySmall,- color = MaterialTheme.colorScheme.onSurfaceVariant,- )- }- Button(onClick = onPlayAgain, Modifier.fillMaxWidth()) {- Text(stringResource(R.string.play_again))- }- TextButton(onClick = onBack, Modifier.fillMaxWidth()) {- Text(stringResource(R.string.back))- }- }- }- }-}
games/sudoku/src/main/java/com/vayunmathur/games/sudoku/ui/HomeScreen.kt
diff --git a/games/sudoku/src/main/java/com/vayunmathur/games/sudoku/ui/HomeScreen.kt b/games/sudoku/src/main/java/com/vayunmathur/games/sudoku/ui/HomeScreen.ktindex d97c894d06..c8a3a0d13f 100644--- a/games/sudoku/src/main/java/com/vayunmathur/games/sudoku/ui/HomeScreen.kt+++ b/games/sudoku/src/main/java/com/vayunmathur/games/sudoku/ui/HomeScreen.kt@@ -25,12 +25,12 @@ import com.vayunmathur.games.sudoku.ui.dialogs.GameConfigDialog import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.Card-import com.vayunmathur.library.ui.IconButton-import com.vayunmathur.library.ui.IconEmojiEvents import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Spacing import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.appBarScrollBehavior+import com.vayunmathur.library.ui.game.GameTopBarActions+import com.vayunmathur.library.ui.game.formatDuration import com.vayunmathur.library.util.NavBackStack @Composable@@ -46,9 +46,7 @@ fun HomeScreen( AppScaffold( title = stringResource(R.string.app_name), actions = {- IconButton(onClick = { backStack.add(Route.GameCenter) }) {- IconEmojiEvents()- }+ GameTopBarActions(onOpenGameCenter = { backStack.add(Route.GameCenter) }) }, scrollBehavior = appBarScrollBehavior(), ) { padding ->@@ -134,7 +132,7 @@ private fun SizeStatsCard( ) if (stats.bestTimeSeconds < Int.MAX_VALUE) { Text(- formatTime(stats.bestTimeSeconds),+ formatDuration(stats.bestTimeSeconds), style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant, textAlign = TextAlign.Center,@@ -143,12 +141,3 @@ private fun SizeStatsCard( } } }--/** `mm:ss`, and `h:mm:ss` once a puzzle has run past the hour. */-fun formatTime(seconds: Int): String {- val hours = seconds / 3600- val minutes = (seconds % 3600) / 60- val secs = seconds % 60- return if (hours > 0) "%d:%02d:%02d".format(hours, minutes, secs)- else "%02d:%02d".format(minutes, secs)-}
games/sudoku/src/main/res/values/strings.xml
diff --git a/games/sudoku/src/main/res/values/strings.xml b/games/sudoku/src/main/res/values/strings.xmlindex 92f805b762..643f239d96 100644--- a/games/sudoku/src/main/res/values/strings.xml+++ b/games/sudoku/src/main/res/values/strings.xml@@ -45,10 +45,7 @@ <!-- WinOverlay: Celebratory title shown when the grid is completed. Declarative --> <string name="congratulations">Congratulations!</string>- <!-- WinOverlay: Label for the finishing time, e.g. Time: 04:12. Noun -->- <string name="time">Time</string>- <!-- WinOverlay: Restarts the same puzzle from empty. Verb phrase -->- <string name="play_again">Play Again</string>+ <!-- WinOverlay: Celebratory title shown when the grid is completed. Declarative --> <!-- HomeScreen stat card: Label under the won-of-played ratio. Verb past participle --> <string name="won">won</string>
games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/Navigation.kt
diff --git a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/Navigation.kt b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/Navigation.ktindex 7f25d3f8bc..6c6a2a1e40 100644--- a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/Navigation.kt+++ b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/Navigation.kt@@ -36,12 +36,9 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color-import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource-import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp-import androidx.compose.ui.unit.sp import androidx.compose.ui.zIndex import com.vayunmathur.games.unblockjam.data.DailyLevelGenerator import com.vayunmathur.games.unblockjam.data.LevelData@@ -64,10 +61,7 @@ import com.vayunmathur.library.ui.DailyReminderSettingsSection import com.vayunmathur.library.ui.DetailScaffold import com.vayunmathur.library.ui.ExperimentalMaterial3Api import com.vayunmathur.library.ui.GameCenterScreen-import com.vayunmathur.library.ui.Icon-import com.vayunmathur.library.ui.IconButton import com.vayunmathur.library.ui.IconCheck-import com.vayunmathur.library.ui.IconSettings import com.vayunmathur.library.ui.IconStar import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.AppScaffold@@ -75,6 +69,10 @@ import com.vayunmathur.library.ui.Surface import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.appBarScrollBehavior import com.vayunmathur.library.ui.rememberPermissionRequest+import com.vayunmathur.library.ui.game.DailyChallengeCard+import com.vayunmathur.library.ui.game.GameTopBarActions+import com.vayunmathur.library.ui.game.LevelPickerBox+import com.vayunmathur.library.ui.game.MovesBox import com.vayunmathur.library.util.GameHubComposeHook import com.vayunmathur.library.util.LevelStats import com.vayunmathur.library.util.MainNavigation@@ -82,9 +80,6 @@ import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.library.util.openSettingsIfRequested import com.vayunmathur.library.util.rememberNavBackStack import com.vayunmathur.library.ui.R as UiR-import java.time.LocalDate-import java.time.format.DateTimeFormatter-import java.time.format.FormatStyle @Composable fun Navigation(viewModel: UnblockJamViewModel) {@@ -230,12 +225,10 @@ fun PackScreen( AppScaffold( title = stringResource(R.string.pack_selector), actions = {- IconButton(onClick = onOpenSettings) {- IconSettings()- }- IconButton(onClick = onOpenGameCenter) {- Icon(painterResource(id = android.R.drawable.btn_star_big_on), "Achievements")- }+ GameTopBarActions(+ onOpenGameCenter = onOpenGameCenter,+ onOpenSettings = onOpenSettings,+ ) }, scrollBehavior = appBarScrollBehavior(), ) { paddingValues ->@@ -244,7 +237,17 @@ fun PackScreen( contentPadding = paddingValues + PaddingValues(start = 16.dp, top = 16.dp, end = 16.dp, bottom = 0.dp), verticalArrangement = Arrangement.spacedBy(12.dp), ) {- daily?.let { item { DailyCard(it, onOpenDaily) } }+ daily?.let {+ item {+ DailyChallengeCard(+ day = it.day,+ completed = it.completed,+ total = it.total,+ streak = it.streak,+ onOpen = onOpenDaily,+ )+ }+ } itemsIndexed(packNames) { index, name -> Card(Modifier.clickable{ onOpenPack(index)@@ -258,39 +261,6 @@ fun PackScreen( } } -@Composable-private fun DailyCard(daily: DailyProgress, onOpen: () -> Unit) {- Card(- Modifier.clickable { onOpen() },- colors = CardDefaults.cardColors(MaterialTheme.colorScheme.primaryContainer)- ) {- Row(- Modifier.fillMaxWidth().padding(16.dp),- horizontalArrangement = Arrangement.SpaceBetween,- verticalAlignment = Alignment.CenterVertically- ) {- Column {- Text(- stringResource(R.string.daily_challenge),- style = MaterialTheme.typography.headlineMedium- )- Text(- LocalDate.ofEpochDay(daily.day)- .format(DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM)),- style = MaterialTheme.typography.bodyMedium- )- }- Column(horizontalAlignment = Alignment.End) {- Text("${daily.completed}/${daily.total}", style = MaterialTheme.typography.titleMedium)- Text(- stringResource(R.string.daily_streak, daily.streak.toInt()),- style = MaterialTheme.typography.bodyMedium- )- }- }- }-}- /** Binds [UnblockJamViewModel] to today's daily pack, reusing the pack level grid. */ @Composable fun DailyLevelPage(backStack: NavBackStack<Route>, viewModel: UnblockJamViewModel) {@@ -449,13 +419,15 @@ fun GameScreen(state: GameUiState, actions: GameActions, onBack: () -> Unit) { color = MaterialTheme.colorScheme.background ) { val infoBoxes = @Composable {- PuzzleInfoBox(+ LevelPickerBox( levelIndex = state.levelIndex,- onLevelChange = actions::onLevelChange,+ maxLevelIndex = state.maxLevelIndex, isCompleted = state.isCompleted,- maxLevelIndex = state.maxLevelIndex+ onLevelChange = actions::onLevelChange,+ // unblockjam calls its levels puzzles.+ title = stringResource(R.string.level), )- MovesInfoBox(+ MovesBox( moves = state.moves, bestScore = state.bestScore, optimalMoves = currentLevelData.optimalMoves@@ -553,84 +525,6 @@ fun GameScreen(state: GameUiState, actions: GameActions, onBack: () -> Unit) { } } -@Composable-fun PuzzleInfoBox(levelIndex: Int, onLevelChange: (Int) -> Unit, isCompleted: Boolean, maxLevelIndex: Int) {- InfoBox(title = stringResource(R.string.level)) {- Row(- verticalAlignment = Alignment.CenterVertically,- horizontalArrangement = Arrangement.SpaceBetween,- modifier = Modifier.fillMaxWidth()- ) {- IconButton(- onClick = { onLevelChange(levelIndex - 1) },- enabled = levelIndex > 0- ) {- Icon(- painterResource(R.drawable.arrow_back_24px),- contentDescription = stringResource(R.string.previous_level),- )- }- Text(- text = "${levelIndex + 1}",- fontSize = 24.sp,- fontWeight = FontWeight.Bold- )- IconButton(- onClick = { onLevelChange(levelIndex + 1) },- enabled = levelIndex < maxLevelIndex- ) {- Icon(- painterResource(R.drawable.arrow_forward_24px),- contentDescription = stringResource(R.string.next_level),- )- }- }- if (isCompleted) {- Text(- text = stringResource(R.string.completed),- color = MaterialTheme.colorScheme.error,- fontSize = 12.sp,- fontWeight = FontWeight.Bold- )- }- }-}--@Composable-fun MovesInfoBox(moves: Int, bestScore: Int?, optimalMoves: Int) {- InfoBox(title = stringResource(R.string.moves)) {- Column(horizontalAlignment = Alignment.CenterHorizontally) {- Text(- text = "$moves",- fontSize = 24.sp,- fontWeight = FontWeight.Bold- )- Text(- text = "${bestScore ?: "-"} / $optimalMoves",- fontSize = 18.sp,- fontWeight = FontWeight.Bold- )- }- }-}--@Composable-fun InfoBox(title: String, content: @Composable () -> Unit) {- Surface(- modifier = Modifier.size(width = 150.dp, height = 120.dp),- shape = RoundedCornerShape(12.dp),- ) {- Column(- modifier = Modifier.padding(8.dp),- horizontalAlignment = Alignment.CenterHorizontally,- verticalArrangement = Arrangement.SpaceAround- ) {- Text(text = title, fontSize = 16.sp)- content()- }- }-}- @Composable fun GameBoard( levelData: LevelData,
games/unblockjam/src/main/res/drawable/arrow_back_24px.xml
diff --git a/games/unblockjam/src/main/res/drawable/arrow_back_24px.xml b/games/unblockjam/src/main/res/drawable/arrow_back_24px.xmldeleted file mode 100644index 7b45e90f7b..0000000000--- a/games/unblockjam/src/main/res/drawable/arrow_back_24px.xml+++ /dev/null@@ -1,5 +0,0 @@-<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="24dp" android:tint="#000000" android:viewportHeight="960" android:viewportWidth="960" android:width="24dp">- - <path android:fillColor="@android:color/white" android:pathData="M313,520L537,744L480,800L160,480L480,160L537,216L313,440L800,440L800,520L313,520Z"/>- -</vector>
games/unblockjam/src/main/res/drawable/arrow_forward_24px.xml
diff --git a/games/unblockjam/src/main/res/drawable/arrow_forward_24px.xml b/games/unblockjam/src/main/res/drawable/arrow_forward_24px.xmldeleted file mode 100644index 143dcf9ac9..0000000000--- a/games/unblockjam/src/main/res/drawable/arrow_forward_24px.xml+++ /dev/null@@ -1,5 +0,0 @@-<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="24dp" android:tint="#000000" android:viewportHeight="960" android:viewportWidth="960" android:width="24dp">- - <path android:fillColor="@android:color/white" android:pathData="M647,520L160,520L160,440L647,440L423,216L480,160L800,480L480,800L423,744L647,520Z"/>- -</vector>
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/CompetitiveLobbyScreen.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/CompetitiveLobbyScreen.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/CompetitiveLobbyScreen.ktindex c5afbe82d4..bbe6dd1a3b 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/CompetitiveLobbyScreen.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/CompetitiveLobbyScreen.kt@@ -6,15 +6,11 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding-import androidx.compose.material3.Button-import androidx.compose.material3.MaterialTheme-import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier-import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp@@ -24,14 +20,15 @@ import com.vayunmathur.games.wordmaker.platform.CompetitiveLobbyActions import com.vayunmathur.games.wordmaker.platform.CompetitiveLobbyUiState import com.vayunmathur.games.wordmaker.platform.WordMakerViewModel import com.vayunmathur.games.wordmaker.ui.components.DifficultyDropdown-import com.vayunmathur.games.wordmaker.ui.components.GameModeDropdown+import com.vayunmathur.games.wordmaker.ui.components.WordMakerModeChooser import com.vayunmathur.library.ui.AppBarAlignment import com.vayunmathur.library.ui.AppScaffold+import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.ExperimentalMaterial3Api-import com.vayunmathur.library.ui.Icon-import com.vayunmathur.library.ui.IconButton-import com.vayunmathur.library.ui.IconSettings+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.appBarScrollBehavior+import com.vayunmathur.library.ui.game.GameTopBarActions @Composable fun CompetitiveLobbyPage(@@ -69,15 +66,17 @@ fun CompetitiveLobbyScreen( val result = state.result AppScaffold(- title = {},- navigationIcon = { GameModeDropdown(selected = state.gameMode, onSelected = { actions.setGameMode(it) }) },+ title = {+ WordMakerModeChooser(+ selected = state.gameMode,+ onSelected = { actions.setGameMode(it) },+ )+ }, actions = {- IconButton(onClick = onOpenGameCenter) {- Icon(painterResource(id = android.R.drawable.btn_star_big_on), "Achievements")- }- IconButton(onClick = onOpenSettings) {- IconSettings()- }+ GameTopBarActions(+ onOpenGameCenter = onOpenGameCenter,+ onOpenSettings = onOpenSettings,+ ) }, alignment = AppBarAlignment.Center, scrollBehavior = appBarScrollBehavior(),
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameScreen.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameScreen.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameScreen.ktindex a3a59d6a10..6e2651f535 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameScreen.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameScreen.kt@@ -65,12 +65,13 @@ import com.vayunmathur.library.ui.IconSettings import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.appBarScrollBehavior+import com.vayunmathur.library.ui.game.GameTopBarActions import com.vayunmathur.library.util.AchievementsManager import com.vayunmathur.games.wordmaker.ui.components.CompetitiveStatusBar import com.vayunmathur.games.wordmaker.ui.components.CrosswordBoard import com.vayunmathur.games.wordmaker.ui.components.DailyStatusBar-import com.vayunmathur.games.wordmaker.ui.components.GameModeDropdown import com.vayunmathur.games.wordmaker.ui.components.LetterChooser+import com.vayunmathur.games.wordmaker.ui.components.WordMakerModeChooser import com.vayunmathur.games.wordmaker.ui.dialogs.BonusWordsDialog import com.vayunmathur.games.wordmaker.ui.dialogs.DefinitionDialog import kotlinx.coroutines.delay@@ -205,18 +206,17 @@ fun WordGameScreen( AppScaffold( modifier = Modifier.fillMaxSize(), title = {- if (gameMode == GameMode.CASUAL) {- Text(text = stringResource(R.string.level_number, currentLevel), fontWeight = FontWeight.Bold)- }+ WordMakerModeChooser(+ selected = gameMode,+ onSelected = { actions.setGameMode(it) },+ levelNumber = currentLevel,+ ) },- navigationIcon = { GameModeDropdown(selected = gameMode, onSelected = { actions.setGameMode(it) }) }, actions = {- IconButton(onClick = onOpenGameCenter) {- Icon(painterResource(id = android.R.drawable.btn_star_big_on), "Achievements")- }- IconButton(onClick = onOpenSettings) {- IconSettings()- }+ GameTopBarActions(+ onOpenGameCenter = onOpenGameCenter,+ onOpenSettings = onOpenSettings,+ ) }, alignment = AppBarAlignment.Center, scrollBehavior = appBarScrollBehavior(),
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WordComponents.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WordComponents.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WordComponents.ktindex 0411c42d95..3b825a2642 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WordComponents.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WordComponents.kt@@ -6,9 +6,9 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.RoundedCornerShape-import androidx.compose.material3.MaterialTheme-import androidx.compose.material3.Surface-import androidx.compose.material3.Text+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Surface+import com.vayunmathur.library.ui.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WordMakerTopBar.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WordMakerTopBar.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WordMakerTopBar.ktindex 7c11654683..4f1207ffe1 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WordMakerTopBar.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WordMakerTopBar.kt@@ -1,21 +1,12 @@ package com.vayunmathur.games.wordmaker.ui.components -import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.size-import androidx.compose.material3.MaterialTheme-import androidx.compose.material3.Text import androidx.compose.runtime.Composable-import androidx.compose.runtime.getValue-import androidx.compose.runtime.mutableStateOf-import androidx.compose.runtime.remember-import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier-import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp@@ -24,42 +15,13 @@ import com.vayunmathur.games.wordmaker.R import com.vayunmathur.games.wordmaker.data.Difficulty import com.vayunmathur.games.wordmaker.data.GameMode import com.vayunmathur.library.ui.CenterAlignedTopAppBar-import com.vayunmathur.library.ui.DropdownMenu-import com.vayunmathur.library.ui.DropdownMenuItem import com.vayunmathur.library.ui.ExperimentalMaterial3Api-import com.vayunmathur.library.ui.Icon-import com.vayunmathur.library.ui.IconArrowDropDown-import com.vayunmathur.library.ui.IconButton-import com.vayunmathur.library.ui.IconSettings-import com.vayunmathur.library.ui.TextButton--@Composable-fun GameModeDropdown(selected: GameMode, onSelected: (GameMode) -> Unit) {- var expanded by remember { mutableStateOf(false) }- Box {- TextButton(onClick = { expanded = true }) {- Text(stringResource(gameModeLabel(selected)), fontWeight = FontWeight.Bold)- IconArrowDropDown(modifier = Modifier.size(18.dp))- }- DropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {- GameMode.entries.forEach { mode ->- DropdownMenuItem(- text = { Text(stringResource(gameModeLabel(mode))) },- onClick = {- expanded = false- onSelected(mode)- }- )- }- }- }-}--private fun gameModeLabel(mode: GameMode) = when (mode) {- GameMode.CASUAL -> R.string.mode_casual- GameMode.COMPETITIVE -> R.string.mode_competitive- GameMode.DAILY -> R.string.mode_daily-}+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.game.DailyStreakText+import com.vayunmathur.library.ui.game.GameModeChooser+import com.vayunmathur.library.ui.game.GameTopBarActions+import com.vayunmathur.library.ui.game.formatDuration @Composable fun DailyStatusBar(streak: Long) {@@ -71,41 +33,64 @@ fun DailyStatusBar(streak: Long) { ) { Text(stringResource(R.string.daily_challenge), fontWeight = FontWeight.Bold) Spacer(Modifier.weight(1f))- Text(stringResource(R.string.daily_streak, streak.toInt()))+ DailyStreakText(streak) } } - @Composable fun DifficultyDropdown(selected: Difficulty, onSelected: (Difficulty) -> Unit) {- var expanded by remember { mutableStateOf(false) }- fun label(d: Difficulty) = when (d) {- Difficulty.EASY -> R.string.difficulty_easy- Difficulty.MEDIUM -> R.string.difficulty_medium- Difficulty.HARD -> R.string.difficulty_hard- }- Box {- TextButton(onClick = { expanded = true }) {- Text(stringResource(label(selected)))- IconArrowDropDown(modifier = Modifier.size(18.dp))- }- DropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {- Difficulty.values().forEach { d ->- DropdownMenuItem(- text = { Text(stringResource(label(d))) },- onClick = {- expanded = false- onSelected(d)- }- )+ GameModeChooser(+ selected = selected,+ options = Difficulty.entries,+ label = { stringResource(difficultyLabel(it)) },+ onSelect = onSelected,+ // Sits inline in the lobby rather than in an app bar, so it takes body type.+ textStyle = MaterialTheme.typography.bodyLarge,+ )+}++private fun difficultyLabel(difficulty: Difficulty) = when (difficulty) {+ Difficulty.EASY -> R.string.difficulty_easy+ Difficulty.MEDIUM -> R.string.difficulty_medium+ Difficulty.HARD -> R.string.difficulty_hard+}++private fun gameModeLabel(mode: GameMode) = when (mode) {+ GameMode.CASUAL -> R.string.mode_casual+ GameMode.COMPETITIVE -> R.string.mode_competitive+ GameMode.DAILY -> R.string.mode_daily+}++/**+ * The mode chooser wordmaker's screens put in their title slot.+ *+ * Wraps the shared [GameModeChooser] with wordmaker's own labels so its three screens cannot drift+ * apart again. [levelNumber] folds the level into the label for the ladder mode, which is why the bar+ * needs no separate title.+ */+@Composable+fun WordMakerModeChooser(+ selected: GameMode,+ onSelected: (GameMode) -> Unit,+ levelNumber: Int? = null,+) {+ GameModeChooser(+ selected = selected,+ options = GameMode.entries,+ label = { mode ->+ if (mode == GameMode.CASUAL && levelNumber != null) {+ stringResource(R.string.level_number, levelNumber)+ } else {+ stringResource(gameModeLabel(mode)) }- }- }+ },+ menuLabel = { stringResource(gameModeLabel(it)) },+ onSelect = onSelected,+ ) } @OptIn(ExperimentalMaterial3Api::class) @Composable- fun WordMakerTopBar( gameMode: GameMode, onModeSelected: (GameMode) -> Unit,@@ -115,23 +100,13 @@ fun WordMakerTopBar( ) { CenterAlignedTopAppBar( title = {- if (gameMode == GameMode.CASUAL && levelNumber != null) {- Text(- text = stringResource(R.string.level_number, levelNumber),- fontWeight = FontWeight.Bold- )- }- },- navigationIcon = {- GameModeDropdown(selected = gameMode, onSelected = onModeSelected)+ WordMakerModeChooser(gameMode, onModeSelected, levelNumber) }, actions = {- IconButton(onClick = onOpenGameCenter) {- Icon(painterResource(id = android.R.drawable.btn_star_big_on), "Achievements")- }- IconButton(onClick = onOpenSettings) {- IconSettings()- }+ GameTopBarActions(+ onOpenGameCenter = onOpenGameCenter,+ onOpenSettings = onOpenSettings,+ ) } ) }@@ -143,9 +118,8 @@ fun CompetitiveStatusBar( remainingTimeMs: Long ) { val totalSeconds = (remainingTimeMs / 1000L).toInt()- val minutes = totalSeconds / 60- val seconds = totalSeconds % 60- val timeColor = if (totalSeconds <= 10) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.onSurface+ val timeColor = if (totalSeconds <= URGENT_SECONDS) MaterialTheme.colorScheme.error+ else MaterialTheme.colorScheme.onSurface Row( modifier = Modifier .fillMaxWidth()@@ -155,10 +129,13 @@ fun CompetitiveStatusBar( Text(stringResource(R.string.competitive_score, score)) Spacer(Modifier.weight(1f)) Text(- text = "%d:%02d".format(minutes, seconds),+ text = formatDuration(totalSeconds), fontWeight = FontWeight.Bold, fontSize = 20.sp, color = timeColor ) } }++/** Where the countdown turns red, which is about as long as one more word takes. */+private const val URGENT_SECONDS = 10
games/wordmaker/src/screenshotTest/kotlin/com/vayunmathur/games/wordmaker/MetadataPreviews.kt
diff --git a/games/wordmaker/src/screenshotTest/kotlin/com/vayunmathur/games/wordmaker/MetadataPreviews.kt b/games/wordmaker/src/screenshotTest/kotlin/com/vayunmathur/games/wordmaker/MetadataPreviews.ktindex c74e08f93a..c2205c88bf 100644--- a/games/wordmaker/src/screenshotTest/kotlin/com/vayunmathur/games/wordmaker/MetadataPreviews.kt+++ b/games/wordmaker/src/screenshotTest/kotlin/com/vayunmathur/games/wordmaker/MetadataPreviews.kt@@ -11,6 +11,8 @@ import com.vayunmathur.games.wordmaker.platform.CompetitiveLobbyUiState import com.vayunmathur.games.wordmaker.platform.CompetitiveResult import com.vayunmathur.games.wordmaker.platform.WordGameActions import com.vayunmathur.games.wordmaker.platform.WordGameUiState+import com.vayunmathur.games.wordmaker.ui.CompetitiveLobbyScreen+import com.vayunmathur.games.wordmaker.ui.WordGameScreen import com.vayunmathur.library.ui.DynamicTheme /** Phone-shaped, roughly 1080x2340 at xxhdpi — comfortably above the F-Droid minimum. */
library/ui/src/main/java/com/vayunmathur/library/ui/game/DailyChallengeCard.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/game/DailyChallengeCard.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/game/DailyChallengeCard.ktnew file mode 100644index 0000000000..c2abdf706c--- /dev/null+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/game/DailyChallengeCard.kt@@ -0,0 +1,74 @@+package com.vayunmathur.library.ui.game++import androidx.compose.foundation.clickable+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import com.vayunmathur.library.ui.Card+import com.vayunmathur.library.ui.CardDefaults+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.R+import com.vayunmathur.library.ui.Spacing+import com.vayunmathur.library.ui.Text+import java.time.LocalDate+import java.time.format.DateTimeFormatter+import java.time.format.FormatStyle++/**+ * The entry point to a game's daily challenge, for games that keep it on a list screen rather than+ * behind a mode switch.+ *+ * Carries the date, how far through today's set the player is, and the streak — the three things that+ * decide whether they tap it. Filled in the primary container colour so it reads as the one live thing+ * on a list of otherwise static packs.+ *+ * @param day the daily's epoch day, formatted in the user's locale.+ * @param completed how many of [total] parts of today's challenge are done.+ */+@Composable+fun DailyChallengeCard(+ day: Long,+ completed: Int,+ total: Int,+ streak: Long,+ onOpen: () -> Unit,+ modifier: Modifier = Modifier,+) {+ Card(+ modifier.clickable { onOpen() },+ colors = CardDefaults.cardColors(MaterialTheme.colorScheme.primaryContainer),+ ) {+ Row(+ Modifier+ .fillMaxWidth()+ .padding(Spacing.lg),+ horizontalArrangement = Arrangement.SpaceBetween,+ verticalAlignment = Alignment.CenterVertically,+ ) {+ Column {+ Text(+ stringResource(R.string.game_daily_challenge),+ style = MaterialTheme.typography.headlineMedium,+ )+ Text(+ formatEpochDay(day),+ style = MaterialTheme.typography.bodyMedium,+ color = MaterialTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.7f),+ )+ }+ Column(horizontalAlignment = Alignment.End) {+ Text("$completed/$total", style = MaterialTheme.typography.titleMedium)+ DailyStreakText(streak)+ }+ }+ }+}++private fun formatEpochDay(day: Long): String =+ LocalDate.ofEpochDay(day).format(DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM))
library/ui/src/main/java/com/vayunmathur/library/ui/game/DailyStreakText.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/game/DailyStreakText.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/game/DailyStreakText.ktnew file mode 100644index 0000000000..b63fcb02ef--- /dev/null+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/game/DailyStreakText.kt@@ -0,0 +1,28 @@+package com.vayunmathur.library.ui.game++import androidx.compose.runtime.Composable+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.pluralStringResource+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.R+import com.vayunmathur.library.ui.Text++/**+ * How many days running the player has cleared the daily board.+ *+ * Reads as "5 day streak" rather than "Streak: 5" so it needs no separate label, and pluralises so a+ * first day is not "1 days".+ */+@Composable+fun DailyStreakText(+ streak: Long,+ modifier: Modifier = Modifier,+) {+ val days = streak.coerceAtLeast(0).toInt()+ Text(+ text = pluralStringResource(R.plurals.game_daily_streak, days, days),+ modifier = modifier,+ style = MaterialTheme.typography.labelLarge,+ color = MaterialTheme.colorScheme.onSurfaceVariant,+ )+}
library/ui/src/main/java/com/vayunmathur/library/ui/game/FormatDuration.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/game/FormatDuration.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/game/FormatDuration.ktnew file mode 100644index 0000000000..54bcc9cb81--- /dev/null+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/game/FormatDuration.kt@@ -0,0 +1,18 @@+package com.vayunmathur.library.ui.game++/**+ * `mm:ss`, and `h:mm:ss` once the clock has run past the hour.+ *+ * Shared because five games format an elapsed time and every one of them wants the same shape. A+ * duration is not a time of day, so `DateString` is the wrong home for it.+ *+ * Negative input is clamped: a countdown that has run out should read `00:00`, not `-1:-1`.+ */+fun formatDuration(seconds: Int): String {+ val safe = seconds.coerceAtLeast(0)+ val hours = safe / 3600+ val minutes = (safe % 3600) / 60+ val secs = safe % 60+ return if (hours > 0) "%d:%02d:%02d".format(hours, minutes, secs)+ else "%02d:%02d".format(minutes, secs)+}
library/ui/src/main/java/com/vayunmathur/library/ui/game/GameInfoBox.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/game/GameInfoBox.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/game/GameInfoBox.ktnew file mode 100644index 0000000000..8d76e17c29--- /dev/null+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/game/GameInfoBox.kt@@ -0,0 +1,44 @@+package com.vayunmathur.library.ui.game++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Surface+import com.vayunmathur.library.ui.Text++/**+ * A fixed-size titled panel for the readouts flanking a game board — level number, move count.+ *+ * Fixed rather than intrinsic so a row of them stays aligned as their contents change width: a move+ * counter ticking from 9 to 10 should not shift the box beside it.+ */+@Composable+fun GameInfoBox(+ title: String,+ modifier: Modifier = Modifier,+ content: @Composable () -> Unit,+) {+ Surface(+ modifier = modifier.size(width = BoxWidth, height = BoxHeight),+ shape = MaterialTheme.shapes.medium,+ ) {+ Column(+ modifier = Modifier.padding(8.dp),+ horizontalAlignment = Alignment.CenterHorizontally,+ verticalArrangement = Arrangement.SpaceAround,+ ) {+ Text(text = title, fontSize = 16.sp)+ content()+ }+ }+}++private val BoxWidth = 150.dp+private val BoxHeight = 120.dp
library/ui/src/main/java/com/vayunmathur/library/ui/game/GameInfoBoxes.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/game/GameInfoBoxes.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/game/GameInfoBoxes.ktnew file mode 100644index 0000000000..cf75b88c22--- /dev/null+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/game/GameInfoBoxes.kt@@ -0,0 +1,89 @@+package com.vayunmathur.library.ui.game++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.unit.sp+import com.vayunmathur.library.ui.IconArrowForward+import com.vayunmathur.library.ui.IconBack+import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.R+import com.vayunmathur.library.ui.Text++/**+ * The level readout, with arrows for stepping to the neighbouring level.+ *+ * [levelIndex] is 0-based because that is what a caller indexes its level list with; the number shown is+ * one higher. Arrows disable at the ends rather than wrapping, so the player can tell where the pack+ * stops.+ *+ * [title] is a parameter because the games do not agree on the noun — unblockjam calls them puzzles — and+ * sharing the mechanism should not flatten their wording.+ */+@Composable+fun LevelPickerBox(+ levelIndex: Int,+ maxLevelIndex: Int,+ isCompleted: Boolean,+ onLevelChange: (Int) -> Unit,+ modifier: Modifier = Modifier,+ title: String = stringResource(R.string.game_level),+) {+ GameInfoBox(title = title, modifier = modifier) {+ Row(+ verticalAlignment = Alignment.CenterVertically,+ horizontalArrangement = Arrangement.SpaceBetween,+ modifier = Modifier.fillMaxWidth(),+ ) {+ IconButton(+ onClick = { onLevelChange(levelIndex - 1) },+ enabled = levelIndex > 0,+ ) { IconBack() }+ Text(text = "${levelIndex + 1}", fontSize = 24.sp, fontWeight = FontWeight.Bold)+ IconButton(+ onClick = { onLevelChange(levelIndex + 1) },+ enabled = levelIndex < maxLevelIndex,+ ) { IconArrowForward() }+ }+ if (isCompleted) {+ Text(+ text = stringResource(R.string.game_completed),+ color = MaterialTheme.colorScheme.error,+ fontSize = 12.sp,+ fontWeight = FontWeight.Bold,+ )+ }+ }+}++/**+ * The move counter, with the player's best against the known optimum.+ *+ * [bestScore] is null until the level has been finished once, and shows as a dash rather than a zero —+ * "no best yet" and "a best of nothing" are different facts.+ */+@Composable+fun MovesBox(+ moves: Int,+ bestScore: Int?,+ optimalMoves: Int,+ modifier: Modifier = Modifier,+) {+ GameInfoBox(title = stringResource(R.string.game_moves), modifier = modifier) {+ Column(horizontalAlignment = Alignment.CenterHorizontally) {+ Text(text = "$moves", fontSize = 24.sp, fontWeight = FontWeight.Bold)+ Text(+ text = "${bestScore ?: "-"} / $optimalMoves",+ fontSize = 18.sp,+ fontWeight = FontWeight.Bold,+ )+ }+ }+}
library/ui/src/main/java/com/vayunmathur/library/ui/game/GameModeChooser.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/game/GameModeChooser.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/game/GameModeChooser.ktnew file mode 100644index 0000000000..68551a3527--- /dev/null+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/game/GameModeChooser.kt@@ -0,0 +1,69 @@+package com.vayunmathur.library.ui.game++import androidx.compose.foundation.layout.Box+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Modifier+import androidx.compose.ui.text.TextStyle+import androidx.compose.ui.text.style.TextOverflow+import com.vayunmathur.library.ui.DropdownMenu+import com.vayunmathur.library.ui.DropdownMenuItem+import com.vayunmathur.library.ui.IconArrowDropDown+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton++/**+ * A dropdown for choosing one of a small fixed set of game options, styled to sit in an app bar.+ *+ * Games with a handful of modes — a level ladder, a daily board, sometimes a timed mode — put this where+ * a title would go, so the mode and the current level read as one thing and the bar keeps to a single+ * control. It is a dropdown rather than a tab row because the label doubles as the title, and because+ * two or three tabs across the top of a game board is a lot of chrome for a rare action.+ *+ * Also used for in-board pickers such as a difficulty selector, which is the same widget in a smaller+ * [textStyle].+ *+ * [label] renders the *selected* option, so a caller can fold extra context in — "Level 12" for a ladder+ * mode, a bare name for the rest. [menuLabel] is the plain name used inside the menu, where that+ * context would be noise. Both are `@Composable` so they can read string resources.+ *+ * @param options every choice on offer, in the order they should be listed.+ */+@Composable+fun <T> GameModeChooser(+ selected: T,+ options: List<T>,+ label: @Composable (T) -> String,+ onSelect: (T) -> Unit,+ modifier: Modifier = Modifier,+ menuLabel: @Composable (T) -> String = label,+ textStyle: TextStyle = MaterialTheme.typography.titleLarge,+) {+ var expanded by remember { mutableStateOf(false) }+ Box(modifier) {+ TextButton(onClick = { expanded = true }) {+ Text(+ text = label(selected),+ style = textStyle,+ maxLines = 1,+ overflow = TextOverflow.Ellipsis,+ )+ IconArrowDropDown()+ }+ DropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {+ for (option in options) {+ DropdownMenuItem(+ text = { Text(menuLabel(option)) },+ onClick = {+ expanded = false+ onSelect(option)+ },+ )+ }+ }+ }+}
library/ui/src/main/java/com/vayunmathur/library/ui/game/GameResultOverlay.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/game/GameResultOverlay.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/game/GameResultOverlay.ktnew file mode 100644index 0000000000..618aa181ad--- /dev/null+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/game/GameResultOverlay.kt@@ -0,0 +1,80 @@+package com.vayunmathur.library.ui.game++import androidx.compose.foundation.background+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.ColumnScope+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import com.vayunmathur.library.ui.Button+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.R+import com.vayunmathur.library.ui.Spacing+import com.vayunmathur.library.ui.Surface+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton++/**+ * The card shown over a finished board.+ *+ * Drawn over a scrim so it reads as modal: without one, whatever the game puts under the board — a+ * number pad, an action row — shows around the card's edges and the board looks half-live.+ *+ * [won] only picks the title colour; the caller supplies the words, because "Solved", "Field Cleared"+ * and "Congratulations" all mean the same thing in different games and none of them belongs here.+ * [stats] is a free slot for the lines a game wants to boast about, which is the one part that has+ * never been the same twice.+ *+ * @param onPlayAgain primary action. Null hides it, for a daily board where there is nothing to replay.+ */+@Composable+fun GameResultOverlay(+ title: String,+ won: Boolean,+ onBack: () -> Unit,+ modifier: Modifier = Modifier,+ onPlayAgain: (() -> Unit)? = null,+ playAgainLabel: String = stringResource(R.string.game_play_again),+ backLabel: String = stringResource(R.string.game_back),+ stats: @Composable ColumnScope.() -> Unit = {},+) {+ Box(+ modifier+ .fillMaxSize()+ .background(MaterialTheme.colorScheme.scrim.copy(alpha = ScrimAlpha))+ .padding(Spacing.lg),+ contentAlignment = Alignment.Center,+ ) {+ Surface(+ shape = MaterialTheme.shapes.extraLarge,+ color = MaterialTheme.colorScheme.surfaceContainerHigh,+ ) {+ Column(+ Modifier.padding(Spacing.xl),+ horizontalAlignment = Alignment.CenterHorizontally,+ verticalArrangement = Arrangement.spacedBy(Spacing.md),+ ) {+ Text(+ text = title,+ style = MaterialTheme.typography.headlineSmall,+ color = if (won) MaterialTheme.colorScheme.primary+ else MaterialTheme.colorScheme.error,+ )+ stats()+ if (onPlayAgain != null) {+ Button(onClick = onPlayAgain, Modifier.fillMaxWidth()) { Text(playAgainLabel) }+ }+ TextButton(onClick = onBack, Modifier.fillMaxWidth()) { Text(backLabel) }+ }+ }+ }+}++/** Dark enough to mute the board behind, light enough to keep it recognisable. */+private const val ScrimAlpha = 0.7f
library/ui/src/main/java/com/vayunmathur/library/ui/game/GameTopBarActions.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/game/GameTopBarActions.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/game/GameTopBarActions.ktnew file mode 100644index 0000000000..27a40eef40--- /dev/null+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/game/GameTopBarActions.kt@@ -0,0 +1,27 @@+package com.vayunmathur.library.ui.game++import androidx.compose.foundation.layout.RowScope+import androidx.compose.runtime.Composable+import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.IconEmojiEvents+import com.vayunmathur.library.ui.IconSettings++/**+ * The app-bar actions a game screen carries.+ *+ * One order everywhere — achievements then settings — because the games had drifted into two orderings+ * and two different trophy glyphs, one of which was a raw `android.R.drawable` that CONTRIBUTING.md+ * forbids. Passing null for [onOpenSettings] covers the games whose settings live elsewhere.+ *+ * Meant for the `actions` slot of `AppScaffold`, which is why it extends [RowScope].+ */+@Composable+fun RowScope.GameTopBarActions(+ onOpenGameCenter: () -> Unit,+ onOpenSettings: (() -> Unit)? = null,+) {+ IconButton(onClick = onOpenGameCenter) { IconEmojiEvents() }+ if (onOpenSettings != null) {+ IconButton(onClick = onOpenSettings) { IconSettings() }+ }+}
library/ui/src/main/java/com/vayunmathur/library/ui/game/HeartsRow.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/game/HeartsRow.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/game/HeartsRow.ktnew file mode 100644index 0000000000..826184dbb9--- /dev/null+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/game/HeartsRow.kt@@ -0,0 +1,49 @@+package com.vayunmathur.library.ui.game++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.size+import androidx.compose.runtime.Composable+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.pluralStringResource+import androidx.compose.ui.semantics.clearAndSetSemantics+import androidx.compose.ui.semantics.contentDescription+import androidx.compose.ui.unit.dp+import com.vayunmathur.library.ui.IconFavorite+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.R+import com.vayunmathur.library.ui.Spacing++/**+ * The attempts a player has left on the current board.+ *+ * Spent hearts stay in place as dimmed shapes rather than disappearing, so the row never reflows and+ * the player can see at a glance how much margin is gone.+ *+ * The whole row carries one description instead of [total] separate ones, because "2 hearts left" is+ * the fact a screen-reader user wants — not a walk through three individual icons.+ */+@Composable+fun HeartsRow(+ remaining: Int,+ total: Int,+ modifier: Modifier = Modifier,+) {+ val safe = remaining.coerceIn(0, total)+ val description = pluralStringResource(R.plurals.game_hearts_left, safe, safe)+ Row(+ modifier.clearAndSetSemantics { contentDescription = description },+ horizontalArrangement = Arrangement.spacedBy(Spacing.xs),+ ) {+ repeat(total) { index ->+ IconFavorite(+ Modifier.size(HeartSize),+ tint = if (index >= safe) MaterialTheme.colorScheme.surfaceContainerHighest+ else MaterialTheme.colorScheme.error,+ )+ }+ }+}++/** Large enough to read at a glance, small enough not to compete with the board. */+private val HeartSize = 20.dp
library/ui/src/main/res/values/strings.xml
diff --git a/library/ui/src/main/res/values/strings.xml b/library/ui/src/main/res/values/strings.xmlindex 0976af61e3..e771e4ca59 100644--- a/library/ui/src/main/res/values/strings.xml+++ b/library/ui/src/main/res/values/strings.xml@@ -101,4 +101,29 @@ <string name="ringtone_silent">Silent</string> <!-- Shared library: UI - RingtonePicker: fallback label when the picked sound file has no readable title --> <string name="ringtone_custom">Custom</string>++ <!-- Shared library: UI - HeartsRow: content description of the attempts left on the current board. %1$d = hearts remaining, e.g. 2 -->+ <plurals name="game_hearts_left">+ <item quantity="one"><xliff:g id="count" example="1">%1$d</xliff:g> heart left</item>+ <item quantity="other"><xliff:g id="count" example="2">%1$d</xliff:g> hearts left</item>+ </plurals>+ <!-- Shared library: UI - DailyStreakText: consecutive days the player has cleared the daily board. %1$d = days, e.g. 5 -->+ <plurals name="game_daily_streak">+ <item quantity="one"><xliff:g id="days" example="1">%1$d</xliff:g> day streak</item>+ <item quantity="other"><xliff:g id="days" example="5">%1$d</xliff:g> day streak</item>+ </plurals>+ <!-- Shared library: UI - GameResultOverlay: primary button starting another round of the same thing. Verb phrase -->+ <string name="game_play_again">Play Again</string>+ <!-- Shared library: UI - GameResultOverlay: secondary button dismissing the result and leaving the board. Verb -->+ <string name="game_back">Back</string>+ <!-- Shared library: UI - games: label preceding an elapsed time, e.g. Time: 04:12. Noun -->+ <string name="game_time">Time</string>+ <!-- Shared library: UI - LevelPickerBox: title over the current level number. Noun -->+ <string name="game_level">Level</string>+ <!-- Shared library: UI - MovesBox: title over the move counter. Noun, plural -->+ <string name="game_moves">Moves</string>+ <!-- Shared library: UI - LevelPickerBox: shown under the level number once that level has been finished. Verb past participle -->+ <string name="game_completed">Completed</string>+ <!-- Shared library: UI - DailyChallengeCard: title of the card opening today's challenge. Noun phrase -->+ <string name="game_daily_challenge">Daily Challenge</string> </resources>
library/ui/src/test/java/com/vayunmathur/library/ui/game/FormatDurationTest.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/game/FormatDurationTest.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/game/FormatDurationTest.ktnew file mode 100644index 0000000000..8d045a3a26--- /dev/null+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/game/FormatDurationTest.kt@@ -0,0 +1,36 @@+package com.vayunmathur.library.ui.game++import kotlin.test.Test+import kotlin.test.assertEquals++class FormatDurationTest {++ @Test+ fun secondsAndMinutesArePadded() {+ assertEquals("00:00", formatDuration(0))+ assertEquals("00:07", formatDuration(7))+ assertEquals("01:00", formatDuration(60))+ assertEquals("04:12", formatDuration(252))+ assertEquals("59:59", formatDuration(3599))+ }++ @Test+ fun hoursAppearOnlyOncePastTheHour() {+ // The hour field is unpadded, so a long game reads 1:02:03 rather than 01:02:03.+ assertEquals("1:00:00", formatDuration(3600))+ assertEquals("1:02:03", formatDuration(3723))+ assertEquals("10:00:00", formatDuration(36_000))+ }++ @Test+ fun negativeInputClampsToZero() {+ // A countdown that has run out should read 00:00, not -1:-1.+ assertEquals("00:00", formatDuration(-1))+ assertEquals("00:00", formatDuration(Int.MIN_VALUE))+ }++ @Test+ fun theLargestPlausibleGameStillFormats() {+ assertEquals("596523:14:07", formatDuration(Int.MAX_VALUE))+ }+}
metadata_data/photos/games-arrows/3.png
diff --git a/metadata_data/photos/games-arrows/3.png b/metadata_data/photos/games-arrows/3.pngindex 5b95fdfef1..62180d181a 100644Binary files a/metadata_data/photos/games-arrows/3.png and b/metadata_data/photos/games-arrows/3.png differ
metadata_data/photos/games-nonogram/3.png
diff --git a/metadata_data/photos/games-nonogram/3.png b/metadata_data/photos/games-nonogram/3.pngindex 6a2c9bd813..fd8968c76c 100644Binary files a/metadata_data/photos/games-nonogram/3.png and b/metadata_data/photos/games-nonogram/3.png differ
metadata_data/photos/games-pipes/1.png
diff --git a/metadata_data/photos/games-pipes/1.png b/metadata_data/photos/games-pipes/1.pngindex 9cb50f11f7..611ef2791e 100644Binary files a/metadata_data/photos/games-pipes/1.png and b/metadata_data/photos/games-pipes/1.png differ
metadata_data/photos/games-pipes/2.png
diff --git a/metadata_data/photos/games-pipes/2.png b/metadata_data/photos/games-pipes/2.pngindex c00bda7e0f..225dd28ca7 100644Binary files a/metadata_data/photos/games-pipes/2.png and b/metadata_data/photos/games-pipes/2.png differ
metadata_data/photos/games-pipes/3.png
diff --git a/metadata_data/photos/games-pipes/3.png b/metadata_data/photos/games-pipes/3.pngindex 640b58c5dd..bae115ac90 100644Binary files a/metadata_data/photos/games-pipes/3.png and b/metadata_data/photos/games-pipes/3.png differ
metadata_data/photos/games-solitaire/1.png
diff --git a/metadata_data/photos/games-solitaire/1.png b/metadata_data/photos/games-solitaire/1.pngindex 8139458333..676ef54d45 100644Binary files a/metadata_data/photos/games-solitaire/1.png and b/metadata_data/photos/games-solitaire/1.png differ
metadata_data/photos/games-solitaire/3.png
diff --git a/metadata_data/photos/games-solitaire/3.png b/metadata_data/photos/games-solitaire/3.pngindex 7803146cec..ed7b21e1c3 100644Binary files a/metadata_data/photos/games-solitaire/3.png and b/metadata_data/photos/games-solitaire/3.png differ
metadata_data/photos/games-solitaire/4.png
diff --git a/metadata_data/photos/games-solitaire/4.png b/metadata_data/photos/games-solitaire/4.pngindex 22639be506..3d936d0f4a 100644Binary files a/metadata_data/photos/games-solitaire/4.png and b/metadata_data/photos/games-solitaire/4.png differ
metadata_data/photos/games-wordmaker/1.png
diff --git a/metadata_data/photos/games-wordmaker/1.png b/metadata_data/photos/games-wordmaker/1.pngindex 541a3b95a0..0bfd557056 100644Binary files a/metadata_data/photos/games-wordmaker/1.png and b/metadata_data/photos/games-wordmaker/1.png differ
metadata_data/photos/games-wordmaker/2.png
diff --git a/metadata_data/photos/games-wordmaker/2.png b/metadata_data/photos/games-wordmaker/2.pngindex 1e1546b321..e12e3cff7b 100644Binary files a/metadata_data/photos/games-wordmaker/2.png and b/metadata_data/photos/games-wordmaker/2.png differ
metadata_data/photos/games-wordmaker/3.png
diff --git a/metadata_data/photos/games-wordmaker/3.png b/metadata_data/photos/games-wordmaker/3.pngindex c0d40f8142..c6d1a38f28 100644Binary files a/metadata_data/photos/games-wordmaker/3.png and b/metadata_data/photos/games-wordmaker/3.png differ