Modern Apps git

← Modern-Apps.git

nonogram, minesweeper: add cross and flag tap modes

Commit
d2ac272b3061a5af411bc05dc751e0a120c1683f
Author
vayun-mathur <[email protected]>
When
2026-08-24 19:14 UTC (3 months ago)
Parents
4c81ef8

Diff

games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/data/MinesweeperModels.kt
diff --git a/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/data/MinesweeperModels.kt b/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/data/MinesweeperModels.ktindex 1d00f213e3..52a87e973e 100644--- a/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/data/MinesweeperModels.kt+++ b/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/data/MinesweeperModels.kt@@ -60,6 +60,14 @@ data class GameConfig( /** How a game ended, or that it is still going. */ enum class GameOutcome { PLAYING, WON, LOST } +/**+ * Which action a plain tap performs.+ *+ * Long press always does the opposite, whatever the mode is, so the mode is a convenience for placing a+ * run of flags rather than the only way to reach either action.+ */+enum class TapMode { DIG, FLAG }+ /**  * Everything about a field in progress.  *
games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/platform/MinesweeperUiContract.kt
diff --git a/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/platform/MinesweeperUiContract.kt b/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/platform/MinesweeperUiContract.ktindex ad5b080a50..ab076dcca1 100644--- a/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/platform/MinesweeperUiContract.kt+++ b/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/platform/MinesweeperUiContract.kt@@ -2,6 +2,7 @@ package com.vayunmathur.games.minesweeper.platform  import com.vayunmathur.games.minesweeper.data.GameConfig import com.vayunmathur.games.minesweeper.data.MinesweeperGameState+import com.vayunmathur.games.minesweeper.data.TapMode  /**  * The UI contract between [MinesweeperViewModel] and the board.@@ -14,12 +15,13 @@ import com.vayunmathur.games.minesweeper.data.MinesweeperGameState  * Every member has a no-op default, so [Noop] is the whole implementation a preview needs.  */ interface MinesweeperActions {-    /** Tap: opens a covered cell, or chords an already-open number. */+    /** Tap: digs or flags depending on the current [TapMode]; chords an already-open number. */     fun tapCell(index: Int) {} -    /** Long press: cycles the flag. */+    /** Long press: the other action from whatever the mode is. */     fun flagCell(index: Int) {} +    fun setTapMode(mode: TapMode) {}     fun restart() {}     fun giveUp() {} @@ -29,10 +31,11 @@ interface MinesweeperActions { /**  * What the board needs to draw itself.  *- * [config] lives here rather than on the game state because the chosen size and density belong to- * the session, not the field — the rules work on any rectangle.+ * [config] lives here rather than on the game state because the chosen size and density belong to the+ * session, not the field — the rules work on any rectangle.  */ data class MinesweeperUiState(     val config: GameConfig = GameConfig(),     val game: MinesweeperGameState? = null,+    val tapMode: TapMode = TapMode.DIG, )
games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/platform/MinesweeperViewModel.kt
diff --git a/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/platform/MinesweeperViewModel.kt b/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/platform/MinesweeperViewModel.ktindex 4908ee8a07..74903cbdde 100644--- a/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/platform/MinesweeperViewModel.kt+++ b/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/platform/MinesweeperViewModel.kt@@ -8,6 +8,7 @@ import com.vayunmathur.games.minesweeper.data.GameConfig import com.vayunmathur.games.minesweeper.data.GameOutcome import com.vayunmathur.games.minesweeper.data.MinesweeperGameState import com.vayunmathur.games.minesweeper.data.MinesweeperStatsRepository+import com.vayunmathur.games.minesweeper.data.TapMode import com.vayunmathur.games.minesweeper.domain.FieldGenerator import com.vayunmathur.games.minesweeper.domain.MinesweeperRules import com.vayunmathur.library.util.AchievementsManager@@ -57,49 +58,80 @@ class MinesweeperViewModel(application: Application) :      fun getSizeStats(size: BoardSize) = statsRepository.getSizeStats(size) -    /** Deals a blank field for [config]. Mines are not laid until the first tap. */+    /** Deals a blank field for [config]. Mines are not laid until the first dig. */     fun newGame(config: GameConfig) {         placedAnyFlag = false         _uiState.value = MinesweeperUiState(             config = config,             game = MinesweeperGameState.empty(config),+            // Carried over: a player who prefers flag mode should not have to re-pick it every field.+            tapMode = _uiState.value.tapMode,         )     }      /**-     * Opens a covered cell, or chords an open number.+     * Tap: digs, flags, or chords, depending on the mode and what is under the finger.      *-     * The first tap also lays the mines, keeping itself and its neighbours clear, so the opening move-     * can never lose. That is also where the game counts as played — backing out of a field you never-     * touched should not show up in the stats.+     * In flag mode a tap can never uncover anything, which is the whole point — clearing a run of+     * suspected mines should not risk ending the game on a mis-tap. Chording still works in flag mode,+     * because tapping an already-open number is unambiguous whichever mode is active.      */     override fun tapCell(index: Int) {         val state = _uiState.value         val game = state.game ?: return         if (game.isOver) return +        if (game.started && game.revealed[index]) {+            chord(game, index)+            return+        }+        if (state.tapMode == TapMode.FLAG) {+            toggleFlag(game, index)+            return+        }+        dig(state, game, index)+    }++    /** Long press: the other action from whatever the mode is. */+    override fun flagCell(index: Int) {+        val state = _uiState.value+        val game = state.game ?: return+        if (game.isOver) return+        if (state.tapMode == TapMode.FLAG) dig(state, game, index) else toggleFlag(game, index)+    }++    override fun setTapMode(mode: TapMode) {+        _uiState.update { it.copy(tapMode = mode) }+    }++    /**+     * Uncovers [index], laying the mines first if this is the opening move.+     *+     * The first dig is also where the game counts as played — backing out of a field you never touched+     * should not show up in the stats.+     */+    private fun dig(+        state: MinesweeperUiState,+        game: MinesweeperGameState,+        index: Int,+    ) {         val laid = if (game.started) game else {             statsRepository.recordGamePlayed(state.config.size, state.config.difficulty)             FieldGenerator.lay(game, index, Random.Default)         }+        publish(MinesweeperRules.reveal(laid, index))+    } -        val next =-            if (laid.revealed[index]) {-                MinesweeperRules.chord(laid, index).also { chorded ->-                    // Only counts when the chord was legal and actually opened something.-                    if (chorded !== laid) achievementsManager.onAchievementUnlocked("first_chord")-                }-            } else {-                MinesweeperRules.reveal(laid, index)-            }--        publish(next)+    private fun chord(game: MinesweeperGameState, index: Int) {+        val chorded = MinesweeperRules.chord(game, index)+        // Only counts when the chord was legal and actually opened something.+        if (chorded !== game) achievementsManager.onAchievementUnlocked("first_chord")+        publish(chorded)     } -    override fun flagCell(index: Int) {-        val game = _uiState.value.game ?: return-        // Flagging before the first reveal would have nothing to flag: the mines are not laid yet.-        if (!game.started || game.isOver) return+    private fun toggleFlag(game: MinesweeperGameState, index: Int) {+        // Flagging before the first dig would have nothing to flag: the mines are not laid yet.+        if (!game.started) return         val next = MinesweeperRules.toggleFlag(game, index)         if (next.flagsPlaced > game.flagsPlaced) placedAnyFlag = true         publish(next)@@ -117,7 +149,7 @@ class MinesweeperViewModel(application: Application) :         if (game.started && !game.isOver) {             statsRepository.recordGameLost(state.config.size, state.config.difficulty)         }-        _uiState.value = MinesweeperUiState(config = state.config)+        _uiState.value = MinesweeperUiState(config = state.config, tapMode = state.tapMode)     }      fun incrementTimer() {
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 55b75980d7..591152c94f 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@@ -19,6 +19,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.vayunmathur.games.minesweeper.R import com.vayunmathur.games.minesweeper.data.GameOutcome+import com.vayunmathur.games.minesweeper.data.TapMode import com.vayunmathur.games.minesweeper.platform.MinesweeperActions import com.vayunmathur.games.minesweeper.platform.MinesweeperUiState import com.vayunmathur.games.minesweeper.ui.components.MineFieldGrid@@ -26,8 +27,12 @@ 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.ExperimentalMaterial3Api import com.vayunmathur.library.ui.IconFlag import com.vayunmathur.library.ui.MaterialTheme+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@@ -86,6 +91,7 @@ fun GameBoardScreen(                     .fillMaxWidth()                     .verticalScroll(rememberScrollState())                     .padding(horizontal = Spacing.md, vertical = Spacing.sm),+                horizontalAlignment = Alignment.CenterHorizontally,                 verticalArrangement = Arrangement.spacedBy(Spacing.md),             ) {                 Row(@@ -112,10 +118,11 @@ fun GameBoardScreen(                         stringResource(R.string.how_to_play),                         style = MaterialTheme.typography.bodySmall,                         color = MaterialTheme.colorScheme.onSurfaceVariant,-                        modifier = Modifier.fillMaxWidth(),                     )                 } +                TapModeToggle(state.tapMode, actions::setTapMode)+                 Row(                     Modifier.fillMaxWidth(),                     horizontalArrangement = Arrangement.spacedBy(Spacing.sm),@@ -146,6 +153,28 @@ fun GameBoardScreen(     } } +/**+ * Chooses what a plain tap does.+ *+ * Two segments rather than a switch, because digging and flagging are peers: neither is the off state of+ * the other. Flag mode matters most on a dense field, where placing a run of flags by long press is+ * slow and one slip on a mine ends the game outright.+ */+@OptIn(ExperimentalMaterial3Api::class)+@Composable+private fun TapModeToggle(mode: TapMode, onSelect: (TapMode) -> Unit) {+    SingleChoiceSegmentedButtonRow {+        val options = listOf(TapMode.DIG to R.string.mode_dig, TapMode.FLAG to R.string.mode_flag)+        options.forEachIndexed { index, (value, label) ->+            SegmentedButton(+                shape = SegmentedButtonDefaults.itemShape(index, options.size),+                onClick = { onSelect(value) },+                selected = mode == value,+            ) { Text(stringResource(label)) }+        }+    }+}+ @Composable private fun ResultOverlay(     won: Boolean,
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 8ed0bf9cf9..4ad8c19926 100644--- a/games/minesweeper/src/main/res/values/strings.xml+++ b/games/minesweeper/src/main/res/values/strings.xml@@ -34,6 +34,10 @@      <!-- GameBoardScreen: Hint under the field explaining the two gestures. Imperative sentence -->     <string name="how_to_play">Tap to open, long press to flag</string>+    <!-- TapModeToggle: Tap uncovers a cell. Verb, imperative -->+    <string name="mode_dig">Dig</string>+    <!-- TapModeToggle: Tap plants a flag on a suspected mine. Noun used as a verb, imperative -->+    <string name="mode_flag">Flag</string>     <!-- GameBoardScreen TopAppBar: Subtitle giving the total mine count, after the size name. Quantified noun -->     <plurals name="mine_count">         <!-- Singular, only reachable on the very smallest field at the lowest density -->
games/nonogram/src/main/java/com/vayunmathur/games/nonogram/data/NonogramDataStore.kt
diff --git a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/data/NonogramDataStore.kt b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/data/NonogramDataStore.ktindex 009ad3f237..64fad3ff20 100644--- a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/data/NonogramDataStore.kt+++ b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/data/NonogramDataStore.kt@@ -34,6 +34,12 @@ class NonogramDataStore(private val context: Context) {             ?: GameMode.CASUAL     } +    /** Which mark a tap places. Kept so the choice survives leaving and returning to the board. */+    val markMode: Flow<MarkMode> = context.dataStore.data.map { prefs ->+        prefs[MARK_MODE_KEY]?.let { runCatching { MarkMode.valueOf(it) }.getOrNull() }+            ?: MarkMode.FILL+    }+     /** Lifetime count of completed puzzles, which survives [saveLevel] clearing the board. */     val puzzlesCompleted: Flow<Int> = context.dataStore.data.map { it[COMPLETED_KEY] ?: 0 } @@ -53,6 +59,10 @@ class NonogramDataStore(private val context: Context) {         context.dataStore.edit { it[GAME_MODE_KEY] = mode.name }     } +    suspend fun setMarkMode(mode: MarkMode) {+        context.dataStore.edit { it[MARK_MODE_KEY] = mode.name }+    }+     /**      * Moves to [level] and wipes the board in the same write.      *@@ -155,6 +165,7 @@ class NonogramDataStore(private val context: Context) {         val REVEALED_KEY = stringSetPreferencesKey("revealed_blanks")         val HEARTS_KEY = intPreferencesKey("hearts")         val GAME_MODE_KEY = stringPreferencesKey("game_mode")+        val MARK_MODE_KEY = stringPreferencesKey("mark_mode")         val COMPLETED_KEY = intPreferencesKey("puzzles_completed")          val DAILY_DAY_KEY = longPreferencesKey("daily_day")
games/nonogram/src/main/java/com/vayunmathur/games/nonogram/data/NonogramModels.kt
diff --git a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/data/NonogramModels.kt b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/data/NonogramModels.ktindex 96c671dc96..d7c0e43548 100644--- a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/data/NonogramModels.kt+++ b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/data/NonogramModels.kt@@ -19,6 +19,14 @@ enum class GameMode { CASUAL, DAILY }  */ enum class CellMark { BLANK, FILLED, CROSSED } +/**+ * Which mark a plain tap places.+ *+ * Long press always does the opposite, whatever the mode is, so the mode is a convenience for placing+ * a run of the same mark rather than the only way to reach either one.+ */+enum class MarkMode { FILL, CROSS }+ /** Hearts a level starts with. Three wrong guesses and the board has to be retried. */ const val STARTING_HEARTS = 3 
games/nonogram/src/main/java/com/vayunmathur/games/nonogram/platform/NonogramUiContract.kt
diff --git a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/platform/NonogramUiContract.kt b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/platform/NonogramUiContract.ktindex 6add3db564..d7078f2268 100644--- a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/platform/NonogramUiContract.kt+++ b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/platform/NonogramUiContract.kt@@ -1,6 +1,7 @@ package com.vayunmathur.games.nonogram.platform  import com.vayunmathur.games.nonogram.data.GameMode+import com.vayunmathur.games.nonogram.data.MarkMode import com.vayunmathur.games.nonogram.data.NonogramGameState  /**@@ -14,12 +15,13 @@ import com.vayunmathur.games.nonogram.data.NonogramGameState  * Every member has a no-op default, so `Noop` is the whole implementation a preview needs.  */ interface NonogramGameActions {-    /** Tap: fills a cell of the picture, or spends a heart on one that is not. */+    /** Tap: places whichever mark the current [MarkMode] selects. */     fun tapCell(index: Int) {} -    /** Long press: crosses a cell out as a note, or takes the cross back. Never costs a heart. */+    /** Long press: places the other mark, whatever the mode is. */     fun crossCell(index: Int) {} +    fun setMarkMode(mode: MarkMode) {}     fun nextLevel() {}     fun restartLevel() {}     fun setGameMode(mode: GameMode) {}@@ -31,6 +33,7 @@ interface NonogramGameActions { data class NonogramUiState(     val game: NonogramGameState? = null,     val mode: GameMode = GameMode.CASUAL,+    val markMode: MarkMode = MarkMode.FILL,     val level: Int = 1,     val dailyStreak: Long = 0,     /** True once today's daily has been completed, which swaps the next-level button for a note. */
games/nonogram/src/main/java/com/vayunmathur/games/nonogram/platform/NonogramViewModel.kt
diff --git a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/platform/NonogramViewModel.kt b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/platform/NonogramViewModel.ktindex 717c9104d1..7b134993a5 100644--- a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/platform/NonogramViewModel.kt+++ b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/platform/NonogramViewModel.kt@@ -5,6 +5,7 @@ import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.viewModelScope import com.vayunmathur.games.nonogram.data.DAILY_SIZE import com.vayunmathur.games.nonogram.data.GameMode+import com.vayunmathur.games.nonogram.data.MarkMode import com.vayunmathur.games.nonogram.data.NonogramDataStore import com.vayunmathur.games.nonogram.data.NonogramGameState import com.vayunmathur.games.nonogram.data.NonogramPuzzle@@ -75,8 +76,9 @@ class NonogramViewModel(application: Application) : AndroidViewModel(application             combine(                 dataStore.gameMode,                 dataStore.currentLevel,+                dataStore.markMode,                 dailyStore.currentStreak,-            ) { mode, level, streak -> Session(mode, level, streak) }+            ) { mode, level, markMode, streak -> Session(mode, level, markMode, streak) }                 .collectLatest { session -> load(session) }         }     }@@ -85,6 +87,7 @@ class NonogramViewModel(application: Application) : AndroidViewModel(application     private data class Session(         val mode: GameMode,         val level: Int,+        val markMode: MarkMode,         val streak: Long,     ) @@ -96,6 +99,7 @@ class NonogramViewModel(application: Application) : AndroidViewModel(application         _uiState.value = _uiState.value.copy(             mode = session.mode,             level = session.level,+            markMode = session.markMode,             dailyStreak = session.streak,             generating = true,             generationFailed = false,@@ -176,17 +180,19 @@ class NonogramViewModel(application: Application) : AndroidViewModel(application     )      /**-     * Tap: fills a cell that belongs to the picture, or spends a heart on one that does not.+     * Tap: places whichever mark [MarkMode] selects.      *-     * A wrong guess is recorded as a *revealed* blank, not as an ordinary note, so it cannot be cleared-     * and then tapped again — one wrong cell costs exactly one heart however many times it is prodded.-     * Correct fills are locked for the same reason.-     *-     * The player's own notes stay freely reversible; only a cell the game has settled is locked.+     * In fill mode a cell that belongs to the picture is filled and one that does not costs a heart. In+     * cross mode a tap only ever writes the player's own note, so it is always free — which is the+     * point of the mode: crossing off a long run of cells should not be a gamble.      */     override fun tapCell(index: Int) {         val game = _uiState.value.game ?: return         if (game.isOver || game.isLocked(index)) return+        if (_uiState.value.markMode == MarkMode.CROSS) {+            toggleNote(game, index)+            return+        }          val daily = game.mode == GameMode.DAILY         viewModelScope.launch {@@ -199,19 +205,39 @@ class NonogramViewModel(application: Application) : AndroidViewModel(application     }      /**-     * Long press: crosses a cell out as a note, or takes the note back.+     * Long press: the other mark from whatever the mode is.      *-     * Free either way, even on a cell that does turn out to belong to the picture: a cross is the-     * player's own working, and being wrong in a note is not a guess the game should punish.+     * So a cross-mode player can still fill without switching back, and a fill-mode player can still+     * jot a cross. Crossing is free either way, even on a cell that does belong to the picture: a cross+     * is the player's own working, and being wrong in a note is not a guess the game should punish.      */     override fun crossCell(index: Int) {         val game = _uiState.value.game ?: return         if (game.isOver || game.isLocked(index)) return+        if (_uiState.value.markMode == MarkMode.CROSS) {+            val daily = game.mode == GameMode.DAILY+            viewModelScope.launch {+                if (game.belongsToPicture(index)) {+                    dataStore.fillCell(index, daily)+                } else {+                    dataStore.revealBlank(index, daily)+                }+            }+        } else {+            toggleNote(game, index)+        }+    }++    private fun toggleNote(game: NonogramGameState, index: Int) {         val daily = game.mode == GameMode.DAILY         val alreadyNoted = index in game.crossed         viewModelScope.launch { dataStore.setNote(index, !alreadyNoted, daily) }     } +    override fun setMarkMode(mode: MarkMode) {+        viewModelScope.launch { dataStore.setMarkMode(mode) }+    }+     override fun nextLevel() {         val state = _uiState.value         if (state.mode == GameMode.DAILY) return
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 10a8d0eb0a..9955f908e5 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@@ -24,6 +24,7 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import com.vayunmathur.games.nonogram.R import com.vayunmathur.games.nonogram.data.GameMode+import com.vayunmathur.games.nonogram.data.MarkMode import com.vayunmathur.games.nonogram.data.STARTING_HEARTS import com.vayunmathur.games.nonogram.platform.NonogramGameActions import com.vayunmathur.games.nonogram.platform.NonogramUiState@@ -34,6 +35,7 @@ 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@@ -41,6 +43,9 @@ 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+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@@ -49,6 +54,31 @@ import com.vayunmathur.library.ui.appBarScrollBehavior /** Caps the board on tablets, where a full-width grid would give absurdly large cells. */ private val BoardMaxWidth = 460.dp +/**+ * Chooses what a plain tap does.+ *+ * Two segments rather than a single switch, because filling and crossing are peers: neither is the off+ * state of the other. The active one is filled in so the current mode is obvious at a glance, since+ * getting it wrong in fill mode costs a heart.+ */+@OptIn(ExperimentalMaterial3Api::class)+@Composable+private fun MarkModeToggle(mode: MarkMode, onSelect: (MarkMode) -> Unit) {+    SingleChoiceSegmentedButtonRow {+        val options = listOf(+            MarkMode.FILL to R.string.mode_fill,+            MarkMode.CROSS to R.string.mode_cross,+        )+        options.forEachIndexed { index, (value, label) ->+            SegmentedButton(+                shape = SegmentedButtonDefaults.itemShape(index, options.size),+                onClick = { onSelect(value) },+                selected = mode == value,+            ) { Text(stringResource(label)) }+        }+    }+}+ /**  * The hearts left.  *@@ -184,6 +214,7 @@ fun NonogramGameScreen(                         }                          else -> {+                            MarkModeToggle(state.markMode, actions::setMarkMode)                             if (game.filled.isEmpty() && game.crossed.isEmpty() &&                                 game.revealedBlanks.isEmpty()                             ) {
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 d3481758e5..71b6552418 100644--- a/games/nonogram/src/main/res/values/strings.xml+++ b/games/nonogram/src/main/res/values/strings.xml@@ -22,6 +22,10 @@     <string name="daily_streak">Streak: <xliff:g id="days" example="5">%1$d</xliff:g></string>     <!-- 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 -->+    <string name="mode_fill">Fill</string>+    <!-- MarkModeToggle: Tap crosses a cell off as empty. Verb, imperative -->+    <string name="mode_cross">Cross</string>     <!-- NonogramGameScreen: Shown when the last heart is spent. Declarative, sympathetic -->     <string name="out_of_hearts">Out of hearts!</string> 
metadata_data/games-minesweeper.md
diff --git a/metadata_data/games-minesweeper.md b/metadata_data/games-minesweeper.mdindex dc4a297bba..f8070aa670 100644--- a/metadata_data/games-minesweeper.md+++ b/metadata_data/games-minesweeper.md@@ -2,5 +2,5 @@ A classic mine-clearing puzzle, generated fresh every game  Pick a field size and a mine density and play a field generated on the spot. The first tap is always safe and always opens an area, so no game is lost to a guess-on move one. Tap to open, long press to flag, and tap a satisfied number to clear-around it.+on move one. Switch between digging and flagging, long press for the other one,+and tap a satisfied number to clear around it.
metadata_data/games-nonogram.md
diff --git a/metadata_data/games-nonogram.md b/metadata_data/games-nonogram.mdindex 4607f753fd..45663f12f5 100644--- a/metadata_data/games-nonogram.md+++ b/metadata_data/games-nonogram.md@@ -3,5 +3,6 @@ A picture logic puzzle, with a new one every day Fill the grid from the number clues to reveal the hidden picture. One level is open at a time, plus a fresh daily puzzle shared by everyone on the same date. Every puzzle is generated on device and checked to be solvable by reasoning-alone, so you never have to guess. You get three hearts per board, and a cell-that turns out to be empty costs you one.+alone, so you never have to guess. Switch between filling and crossing out, and+long press for the other one. You get three hearts per board, and a cell that+turns out to be empty costs you one.
metadata_data/photos/games-minesweeper/1.png
diff --git a/metadata_data/photos/games-minesweeper/1.png b/metadata_data/photos/games-minesweeper/1.pngindex 91d42a8bd0..c931413ed9 100644Binary files a/metadata_data/photos/games-minesweeper/1.png and b/metadata_data/photos/games-minesweeper/1.png differ
metadata_data/photos/games-minesweeper/2.png
diff --git a/metadata_data/photos/games-minesweeper/2.png b/metadata_data/photos/games-minesweeper/2.pngindex 03da1533be..f9a879c301 100644Binary files a/metadata_data/photos/games-minesweeper/2.png and b/metadata_data/photos/games-minesweeper/2.png differ
metadata_data/photos/games-minesweeper/3.png
diff --git a/metadata_data/photos/games-minesweeper/3.png b/metadata_data/photos/games-minesweeper/3.pngindex d6013304ff..0d3201a711 100644Binary files a/metadata_data/photos/games-minesweeper/3.png and b/metadata_data/photos/games-minesweeper/3.png differ
metadata_data/photos/games-minesweeper/4.png
diff --git a/metadata_data/photos/games-minesweeper/4.png b/metadata_data/photos/games-minesweeper/4.pngindex b1ab4622a8..61eb1627a7 100644Binary files a/metadata_data/photos/games-minesweeper/4.png and b/metadata_data/photos/games-minesweeper/4.png differ
metadata_data/photos/games-nonogram/1.png
diff --git a/metadata_data/photos/games-nonogram/1.png b/metadata_data/photos/games-nonogram/1.pngindex 11004fa5cd..8f2aa141bb 100644Binary files a/metadata_data/photos/games-nonogram/1.png and b/metadata_data/photos/games-nonogram/1.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 ac1a5c01f6..6a2c9bd813 100644Binary files a/metadata_data/photos/games-nonogram/3.png and b/metadata_data/photos/games-nonogram/3.png differ
metadata_data/photos/games-nonogram/4.png
diff --git a/metadata_data/photos/games-nonogram/4.png b/metadata_data/photos/games-nonogram/4.pngindex a78d164a62..3286e14628 100644Binary files a/metadata_data/photos/games-nonogram/4.png and b/metadata_data/photos/games-nonogram/4.png differ