Clear the game the player chose and undo quick-button visibility

This commit is contained in:
Kurt Himebauch committed 2026-12-04 18:14:52 -05:00
1 parent 34fffd6cdd
commit 91dfc849f4
3 files changed
+24 -12

No files matched your search

@@ -41,7 +41,7 @@ internal fun DrawerControlsGroup(host: MenuHost, a: DrawerActions, track: (Strin
val library by rememberInputLibrary()
var forAll by remember { mutableStateOf(com.droiddeck.launcher.session.SessionState.inputForAllGames) }
var failure by remember { mutableStateOf<String?>(null) }
var clearing by remember { mutableStateOf(false) }
var clearing by remember { mutableStateOf<Pair<String, String>?>(null) }
val game = a.inputGame
val gameScope = game != null && !forAll
fun update(change: (InputLibrary) -> InputLibrary) {
@@ -84,16 +84,16 @@ internal fun DrawerControlsGroup(host: MenuHost, a: DrawerActions, track: (Strin
modifier = track("input-layout").testTag("input-edit-layout"))
}
if (gameKey != null && own != null) ActionRow(stringResource(R.string.flow_clear_overrides), stringResource(R.string.flow_clear_overrides_hint, game.second),
stringResource(R.string.flow_clear), { clearing = true }, modifier = track("input-game-reset").testTag("input-game-reset"))
if (clearing && gameKey != null) AlertDialog(onDismissRequest = { clearing = false },
title = { Text(stringResource(R.string.flow_clear_title, game.second)) },
text = { Text(stringResource(R.string.flow_clear_body, game.second)) },
confirmButton = { PadTextButton(onClick = { clearing = false; update { it.resetGame(gameKey) } }, modifier = Modifier.testTag("input-game-reset-confirm")) {
Text(stringResource(R.string.flow_clear)) } },
dismissButton = { PadTextButton(onClick = { clearing = false }) { Text(stringResource(R.string.common_cancel)) } })
stringResource(R.string.flow_clear), { clearing = gameKey to game.second }, modifier = track("input-game-reset").testTag("input-game-reset"))
ActionRow(stringResource(R.string.flow_all_settings), null, stringResource(R.string.ctrl_edit), a.onInputSettings,
modifier = track("input-settings").testTag("input-profile-edit"))
}
clearing?.let { (key, name) -> AlertDialog(onDismissRequest = { clearing = null },
title = { Text(stringResource(R.string.flow_clear_title, name)) },
text = { Text(stringResource(R.string.flow_clear_body, name)) },
confirmButton = { PadTextButton(onClick = { clearing = null; update { it.resetGame(key) } }, modifier = Modifier.testTag("input-game-reset-confirm")) {
Text(stringResource(R.string.flow_clear)) } },
dismissButton = { PadTextButton(onClick = { clearing = null }) { Text(stringResource(R.string.common_cancel)) } }) }
failure?.let { message -> AlertDialog(onDismissRequest = { failure = null }, title = { Text(stringResource(R.string.input_save_failed)) },
text = { Text(message) }, confirmButton = { PadTextButton(onClick = { failure = null }) { Text(stringResource(R.string.common_ok)) } }) }
}
@@ -61,7 +61,7 @@ import com.droiddeck.launcher.input.*
import com.droiddeck.launcher.session.SessionState
private data class SurfaceSnapshot(val elements: List<InputSurfaceElement>, val actions: Map<String, InputAction>,
val clicks: Map<String, InputAction>, val scale: Float, val aspect: Float)
val clicks: Map<String, InputAction>, val scale: Float, val aspect: Float, val hidden: Set<InputCommand>)
private class GamepadScaler(private val context: android.content.Context, private val width: Int, private val height: Int,
private val layout: SavedInputLayout) {
@@ -122,8 +122,8 @@ private class SurfaceDraft(val layout: SavedInputLayout, val preset: SavedInputB
val dirty get() = elements != layout.elements || actions != preset.elements || clicks != preset.clicks || layoutScale != layout.scale ||
aspect != layout.aspect || hidden != layout.style.hidden
private var lastAssigned: String? = null
fun checkpoint() { lastAssigned = null; history = (history + SurfaceSnapshot(elements, actions, clicks, layoutScale, aspect)).takeLast(40) }
fun undo() { lastAssigned = null; history.lastOrNull()?.let { elements = it.elements; actions = it.actions; clicks = it.clicks; layoutScale = it.scale; aspect = it.aspect; history = history.dropLast(1) } }
fun checkpoint() { lastAssigned = null; history = (history + SurfaceSnapshot(elements, actions, clicks, layoutScale, aspect, hidden)).takeLast(40) }
fun undo() { lastAssigned = null; history.lastOrNull()?.let { elements = it.elements; actions = it.actions; clicks = it.clicks; layoutScale = it.scale; aspect = it.aspect; hidden = it.hidden; history = history.dropLast(1) } }
private fun adoptDisplayedFrame(context: android.content.Context): Boolean {
if (canvas.width <= 0 || canvas.height <= 0 || shown.isEmpty() || aspect <= 0f || (aspect < 1f) == (canvasAspect < 1f)) return false
val open = toolsExpanded
@@ -546,7 +546,7 @@ private fun SurfaceToolbar(draft: SurfaceDraft, onSave: () -> Unit, onLeave: ()
}
for (button in QUICK_BUTTONS.filter { b -> draft.elements.any { it.quickButton == b } }) {
ToggleRow(host, "editor-quick-${button.name.lowercase()}", stringResource(quickButtonLabel(button)), null, button !in draft.hidden) { shown ->
draft.hidden = if (shown) draft.hidden - button else draft.hidden + button
draft.checkpoint(); draft.hidden = if (shown) draft.hidden - button else draft.hidden + button
}
}
}
@@ -460,6 +460,18 @@ class InputSettingsTest {
com.droiddeck.launcher.input.ControllerPrefs.setSnap(context, true)
}
@Test fun undoRestoresAHiddenQuickButton() {
val library = InputLibraries.read(context)
val before = library.layout("game", InputRole.PRIMARY)!!
compose.setContent { DroidDeckTheme { InputSurfaceDialog("game", {}, {}, role = InputRole.PRIMARY,
layoutId = before.id, bindingsId = library.profile("game").binding(InputRole.PRIMARY)) } }
compose.onNodeWithTag("input-editor-tools").performClick()
compose.onNodeWithTag("setting-editor-quick-keyboard").performScrollTo().performClick()
compose.onNodeWithText(context.getString(R.string.input_editor_undo)).performClick()
compose.onNodeWithText(context.getString(R.string.input_editor_done)).performScrollTo().performClick()
compose.runOnIdle { assertEquals(before.style.hidden, InputLibraries.read(context).layout("game", InputRole.PRIMARY)!!.style.hidden) }
}
@Test fun quickButtonTogglesInTheEditorHideBuiltInButtonsWithoutDeletingThem() {
val library = InputLibraries.read(context)
val before = library.layout("game", InputRole.PRIMARY)!!