mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 22:05:59 +00:00
feat(input): describe on-screen layout choices, scope per-game layouts and delete unused ones (#2939)
* feat(input): describe on-screen layout choices, scope per-game layouts and delete unused ones - The layout menu says what each choice is: "DroidDeck controls" work in every game and are edited here; "Steam touch controls" are each game's controls from Steam, for Steam games only. - Layouts made with "+ New for <game>" (or "Just this game") are listed only for that game, marked "Just for <game>". Older ones are recognised by carrying the name of the game that draws them. - Saved layouts nothing uses get a delete button in the menu. Deleting one also removes a profile that still uses it but can no longer be chosen, such as copies made by the old profile screen. - A game set to Steam touch controls that runs without Steam shows a note under Layout instead of silently using the default. * fix(input): a layout the built-in profile still lists can be deleted once another is chosen Applying a layout used to write it into the Game profile; choosing another now goes on top, so the profile's part is no longer drawn. Only parts a mode actually draws count as in use, and deleting points the built-in profile back at the stock layout.
This commit is contained in:
1 parent
83dc5f37e9
commit
d5c83eae15
9 files changed
+304
-26
No files matched your search
@@ -646,8 +646,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
private var oscRearButtons by mutableStateOf(false)
|
||||
private var oscTrackpads by mutableStateOf(false)
|
||||
private var onScreenButtonsVisible by mutableStateOf(false)
|
||||
private var layoutOptions by mutableStateOf<List<Pair<String, String>>>(emptyList())
|
||||
private var layoutOptions by mutableStateOf<List<com.droiddeck.launcher.input.ControlsChoice.Option>>(emptyList())
|
||||
private var layoutChoice by mutableStateOf("")
|
||||
private var layoutHint by mutableStateOf<String?>(null)
|
||||
private var layoutEditor by mutableStateOf<Triple<String, String, String>?>(null)
|
||||
private var layoutEditorScope: String? = null
|
||||
private var layoutEditorSplit: com.droiddeck.launcher.ui.InputEditorSplit? = null
|
||||
@@ -1746,7 +1747,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
layoutGame = controlsGameName(),
|
||||
layoutOptions = layoutOptions,
|
||||
layoutChoice = layoutChoice,
|
||||
layoutHint = layoutHint,
|
||||
onLayout = ::chooseLayout,
|
||||
onDeleteLayout = ::deleteLayout,
|
||||
oscRearButtons = oscRearButtons.takeIf {
|
||||
unfoldedPanel == null && !usesSteamTouchLayout() && com.droiddeck.launcher.input.PadKit.current(this).steam &&
|
||||
primaryInputLayout?.let(com.droiddeck.launcher.input.OnScreenLayout::hasBuiltInKit) == true
|
||||
@@ -4432,8 +4435,15 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
private fun refreshLayoutOptions() {
|
||||
val steam = SessionState.mode == SessionService.MODE_STEAM
|
||||
val game = controlsGameId()
|
||||
layoutOptions = com.droiddeck.launcher.input.ControlsChoice.options(this, game, steam, controlsGameName())
|
||||
layoutChoice = com.droiddeck.launcher.input.ControlsChoice.current(this, game, steam, loadingMode() == SessionService.MODE_DESKTOP)
|
||||
val desktop = loadingMode() == SessionService.MODE_DESKTOP
|
||||
layoutOptions = com.droiddeck.launcher.input.ControlsChoice.options(this, game, steam, controlsGameName(), desktop)
|
||||
layoutChoice = com.droiddeck.launcher.input.ControlsChoice.current(this, game, steam, desktop)
|
||||
layoutHint = if (com.droiddeck.launcher.input.ControlsChoice.steamUnavailable(this, game, steam)) getString(R.string.osc_layout_steam_unavailable) else null
|
||||
}
|
||||
|
||||
private fun deleteLayout(id: String) {
|
||||
runCatching { com.droiddeck.launcher.input.ControlsChoice.delete(this, id) }.onFailure { Log.w(TAG, "could not delete layout $id", it) }
|
||||
refreshLayoutOptions()
|
||||
}
|
||||
|
||||
private fun chooseLayout(id: String) {
|
||||
|
||||
@@ -24,14 +24,84 @@ object ControlsChoice {
|
||||
return if (chosen == null) library else library.selectPart(desktop, InputRole.PRIMARY, chosen)
|
||||
}
|
||||
|
||||
fun options(context: Context, game: Long?, steamMode: Boolean, gameName: String? = null): List<Pair<String, String>> {
|
||||
data class Option(val id: String, val name: String, val detail: String? = null, val deletable: Boolean = false)
|
||||
|
||||
/** Layouts made for one game, so they're listed only for that game. Layouts made before that was recorded are recognised by carrying the name of the game that draws them. */
|
||||
private fun owners(context: Context, library: InputLibrary): Map<String, Set<Long>> {
|
||||
val named = GameControls.games(context).mapNotNull { game ->
|
||||
val layout = own(library, GameControls.bindings(context, game))?.let { library.preset(it).layoutId } ?: return@mapNotNull null
|
||||
val name = GameControls.name(context, game) ?: return@mapNotNull null
|
||||
(layout to game).takeIf { library.layouts.any { it.id == layout && it.name == name } }
|
||||
}
|
||||
return (named + GameControls.madeFor(context).toList()).groupBy({ it.first }, { it.second }).mapValues { it.value.toSet() }
|
||||
}
|
||||
|
||||
private fun defaults(library: InputLibrary) =
|
||||
listOf(false, true).mapNotNull { library.activeLayout(it, InputRole.PRIMARY)?.id }.toSet()
|
||||
|
||||
private fun deletable(context: Context, library: InputLibrary, layout: SavedInputLayout): Boolean {
|
||||
if (!layout.editable || layout.id == InputLibraries.OVERLAY || layout.id in defaults(library)) return false
|
||||
if (GameControls.games(context).any { game -> own(library, GameControls.bindings(context, game))?.let { library.preset(it).layoutId } == layout.id }) return false
|
||||
return library.profiles.none { p -> p.parts.any { (role, part) -> part.layout == layout.id && drawn(library, p.id, role) } } &&
|
||||
library.bindings.none { it.layoutId == layout.id && library.selectedBindings(it.id) }
|
||||
}
|
||||
|
||||
/** Whether [profile]'s [role] part is what a mode shows, rather than one a choice made since covers. */
|
||||
private fun drawn(library: InputLibrary, profile: String, role: InputRole) =
|
||||
listOf(false, true).any { desktop -> library.activeId(desktop) == profile && library.selection(desktop).parts[role] == null }
|
||||
|
||||
private fun keeps(library: InputLibrary, profile: String) =
|
||||
profile == InputProfile.GAME || profile == InputProfile.DESKTOP || listOf(false, true).any { library.activeId(it) == profile }
|
||||
|
||||
fun options(context: Context, game: Long?, steamMode: Boolean, gameName: String? = null, desktop: Boolean = false): List<Option> {
|
||||
val library = InputLibraries.read(context)
|
||||
val own = game != null && game in GameControls.games(context)
|
||||
return (if (own) listOf(DEFAULT to context.getString(R.string.osc_default)) else emptyList()) +
|
||||
listOf(InputLibraries.OVERLAY to context.getString(R.string.osc_layout_gamepad)) +
|
||||
(if (steamMode) listOf(GameControls.STEAM to context.getString(R.string.osc_layout_steam)) else emptyList()) +
|
||||
library.layouts.filter { it.editable && it.supports(InputRole.PRIMARY) && it.id != InputLibraries.OVERLAY }.map { it.id to it.name } +
|
||||
(if (game != null && !gameName.isNullOrBlank()) listOf(NEW to context.getString(R.string.osc_layout_new_for, gameName)) else emptyList())
|
||||
val current = current(context, game, steamMode, desktop)
|
||||
val owners = owners(context, library)
|
||||
val defaults = defaults(library)
|
||||
val forGame = gameName?.takeIf { game != null && it.isNotBlank() }
|
||||
val saved = library.layouts.filter { it.editable && it.supports(InputRole.PRIMARY) && it.id != InputLibraries.OVERLAY }
|
||||
.filter { l -> l.id == current || l.id in defaults || owners[l.id].isNullOrEmpty() || game in owners[l.id].orEmpty() }
|
||||
.map { l ->
|
||||
val mine = game != null && game in owners[l.id].orEmpty() && l.id !in defaults
|
||||
Option(l.id, l.name, if (mine && forGame != null) context.getString(R.string.osc_layout_detail_game, forGame) else null,
|
||||
l.id != current && deletable(context, library, l))
|
||||
}
|
||||
return (if (own) listOf(Option(DEFAULT, context.getString(R.string.osc_default))) else emptyList()) +
|
||||
Option(InputLibraries.OVERLAY, context.getString(R.string.osc_layout_gamepad), context.getString(R.string.osc_layout_gamepad_detail)) +
|
||||
(if (steamMode) listOf(Option(GameControls.STEAM, context.getString(R.string.osc_layout_steam), context.getString(R.string.osc_layout_steam_detail))) else emptyList()) +
|
||||
saved +
|
||||
(if (forGame != null) listOf(Option(NEW, context.getString(R.string.osc_layout_new_for, forGame))) else emptyList())
|
||||
}
|
||||
|
||||
/** Whether [game] chose Steam's touch controls but runs where they can't be shown. */
|
||||
fun steamUnavailable(context: Context, game: Long?, steamMode: Boolean) = !steamMode && GameControls.steamLayout(context, game)
|
||||
|
||||
/** Deletes the saved layout [id] and its actions. A profile that can no longer be chosen goes with it; one that can falls back to the stock layout. */
|
||||
fun delete(context: Context, id: String) {
|
||||
val games = GameControls.games(context).mapNotNull { GameControls.bindings(context, it) }.toSet()
|
||||
InputLibraries.update(context) { library ->
|
||||
val layout = library.layouts.first { it.id == id }
|
||||
require(deletable(context, library, layout))
|
||||
val users = library.usersOfLayout(id)
|
||||
val orphans = users.filterNot { keeps(library, it.id) }
|
||||
var result = users.filter { keeps(library, it.id) }.fold(library) { acc, p ->
|
||||
p.parts.filterValues { it.layout == id }.keys.fold(acc) { lib, role ->
|
||||
lib.chooseLayout(p.id, role, when {
|
||||
role == InputRole.PRIMARY -> InputLibraries.OVERLAY
|
||||
p.base == InputProfile.DESKTOP -> InputLibraries.TRACKPAD
|
||||
else -> InputLibraries.DECK
|
||||
})
|
||||
}
|
||||
}
|
||||
result = orphans.fold(result) { acc, p -> acc.removeProfile(p.id) }
|
||||
val loose = orphans.flatMap { p -> p.parts.values.map { it.bindings } }.toSet()
|
||||
.filter { b -> b !in games && result.usersOfBindings(b).isEmpty() && !result.selectedBindings(b) && result.bindings.any { it.id == b } }
|
||||
.filterNot { b -> InputStockLayouts.presets(InputStockLayouts.layouts()).any { it.id == b } }
|
||||
result = loose.fold(result) { acc, b -> acc.removeBindings(b) }
|
||||
result.removeLayout(id)
|
||||
}
|
||||
GameControls.forgetLayout(context, id)
|
||||
}
|
||||
|
||||
fun current(context: Context, game: Long?, steamMode: Boolean, desktop: Boolean = false): String =
|
||||
@@ -61,6 +131,7 @@ object ControlsChoice {
|
||||
val layoutId = newInputId()
|
||||
val bindingsId = newInputId()
|
||||
InputLibraries.update(context) { latest -> copyForGame(context, latest, game, name, desktop, layoutId, bindingsId) }
|
||||
GameControls.markMadeFor(context, layoutId, game)
|
||||
GameControls.choose(context, game, bindingsId, steam = false, name = name)
|
||||
return layoutId to bindingsId
|
||||
}
|
||||
@@ -80,7 +151,10 @@ object ControlsChoice {
|
||||
}
|
||||
|
||||
/** Uses [bindingsId], made by [copyForGame], for [game] only. */
|
||||
fun useForGame(context: Context, game: Long, name: String, bindingsId: String) = GameControls.choose(context, game, bindingsId, steam = false, name = name)
|
||||
fun useForGame(context: Context, game: Long, name: String, bindingsId: String) {
|
||||
InputLibraries.read(context).bindings.firstOrNull { it.id == bindingsId }?.layoutId?.let { GameControls.markMadeFor(context, it, game) }
|
||||
GameControls.choose(context, game, bindingsId, steam = false, name = name)
|
||||
}
|
||||
|
||||
/** The profile, layout and actions the editor opens for [game], or null when its layout can't be edited here. */
|
||||
fun editTarget(context: Context, game: Long?, desktop: Boolean): Triple<String, String, String>? {
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.droiddeck.launcher.session.SessionPrefs
|
||||
/** Which on-screen layout each game uses. Games without a choice use the default profile's main-screen layout. */
|
||||
object GameControls {
|
||||
const val STEAM = "steam"
|
||||
private const val MADE_FOR = "layout-for."
|
||||
|
||||
private fun prefs(context: Context) = context.getSharedPreferences("game-controls", Context.MODE_PRIVATE)
|
||||
|
||||
@@ -28,6 +29,15 @@ object GameControls {
|
||||
.filter { it.endsWith(".steam") || it.endsWith(".bindings") }
|
||||
.mapNotNull { it.substringBeforeLast('.').toLongOrNull() }.distinct().sorted()
|
||||
|
||||
/** Layouts made for one game, by layout id. */
|
||||
fun madeFor(context: Context): Map<String, Long> = prefs(context).all.mapNotNull { (key, value) ->
|
||||
if (key.startsWith(MADE_FOR) && value is Long) key.removePrefix(MADE_FOR) to value else null
|
||||
}.toMap()
|
||||
|
||||
fun markMadeFor(context: Context, layout: String, game: Long) { prefs(context).edit().putLong(MADE_FOR + layout, game).apply() }
|
||||
|
||||
fun forgetLayout(context: Context, layout: String) { prefs(context).edit().remove(MADE_FOR + layout).apply() }
|
||||
|
||||
fun name(context: Context, game: Long): String? = prefs(context).getString("$game.name", null)
|
||||
|
||||
fun clear(context: Context, game: Long) {
|
||||
|
||||
@@ -199,9 +199,9 @@ private fun DefaultControlsGroup(host: MenuHost, revision: Int, onEdit: (Triple<
|
||||
var touch by remember { mutableStateOf(SessionPrefs.touchMode(context)) }
|
||||
var below by remember { mutableStateOf(SessionPrefs.unfoldedControls(context)) }
|
||||
SettingsGroup(stringResource(R.string.osc_group_for, stringResource(R.string.osc_default))) {
|
||||
ChoiceRow(host, "osc-layout", stringResource(R.string.osc_layout), null, options, choice) { id ->
|
||||
LayoutChoiceRow(host, "osc-layout", options, choice, onPick = { id ->
|
||||
runCatching { ControlsChoice.choose(context, null, id, desktop = false) }.onSuccess { onChanged() }.onFailure(onFailure)
|
||||
}
|
||||
}, onDelete = { id -> runCatching { ControlsChoice.delete(context, id) }.onSuccess { onChanged() }.onFailure(onFailure) })
|
||||
if (choice != GameControls.STEAM) ActionRow(stringResource(R.string.osc_edit_layout), null, stringResource(R.string.ctrl_edit), {
|
||||
host.open = null
|
||||
ControlsChoice.editTarget(context, null, desktop = false)?.let(onEdit)
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.hoverable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.interaction.collectIsFocusedAsState
|
||||
import androidx.compose.foundation.interaction.collectIsHoveredAsState
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Delete
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Icon
|
||||
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.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.input.ControlsChoice
|
||||
|
||||
/** The on-screen controls layout menu: each option with what it is, and a delete button on saved layouts nothing uses. */
|
||||
@Composable
|
||||
fun LayoutChoiceRow(
|
||||
host: MenuHost, key: String, options: List<ControlsChoice.Option>, selected: String, hint: String? = null,
|
||||
chipModifier: Modifier = Modifier, onPick: (String) -> Unit, onDelete: (String) -> Unit,
|
||||
) {
|
||||
val label = stringResource(R.string.osc_layout)
|
||||
val open = host.open == key
|
||||
var deleting by remember { mutableStateOf<ControlsChoice.Option?>(null) }
|
||||
SettingsRow(label, hint, highlighted = open) {
|
||||
Box {
|
||||
ValueChip(options.firstOrNull { it.id == selected }?.name ?: "-", open,
|
||||
modifier = chipModifier.testTag("setting-$key")) { host.open = if (open) null else key }
|
||||
AnchoredMenu(open, onDismiss = { if (host.open == key) host.open = null }, title = label) { firstItemFocus ->
|
||||
options.forEachIndexed { index, option ->
|
||||
MenuItem(option.name, checked = option.id == selected, detail = option.detail,
|
||||
focusRequester = if (index == 0) firstItemFocus else null,
|
||||
trailing = if (option.deletable) ({ DeleteButton(option.id, option.name) { host.open = null; deleting = option } }) else null) {
|
||||
onPick(option.id)
|
||||
host.open = null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
deleting?.let { option ->
|
||||
AlertDialog(onDismissRequest = { deleting = null },
|
||||
title = { Text(stringResource(R.string.osc_delete_layout)) },
|
||||
text = { Text(stringResource(R.string.input_delete_layout_detail, option.name)) },
|
||||
confirmButton = { PadTextButton(onClick = { deleting = null; onDelete(option.id) }, modifier = Modifier.testTag("osc-delete-confirm")) {
|
||||
Text(stringResource(R.string.common_delete))
|
||||
} },
|
||||
dismissButton = { PadTextButton(onClick = { deleting = null }) { Text(stringResource(R.string.common_cancel)) } })
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DeleteButton(id: String, name: String, onClick: () -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val source = remember { MutableInteractionSource() }
|
||||
val hot = source.collectIsFocusedAsState().value || source.collectIsHoveredAsState().value
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = Modifier.size(36.dp).clip(RoundedCornerShape(8.dp))
|
||||
.background(if (hot) colors.error.copy(alpha = 0.16f) else Color.Transparent)
|
||||
.glideBorder(hot, RoundedCornerShape(8.dp), colors.error)
|
||||
.hoverable(source).clickable(role = Role.Button, interactionSource = source, indication = null, onClick = onClick)
|
||||
.controllerConfirm(onClick = onClick)
|
||||
.testTag("osc-delete-$id"),
|
||||
) {
|
||||
Icon(Icons.Outlined.Delete, contentDescription = stringResource(R.string.common_delete_named, name),
|
||||
tint = if (hot) colors.error else colors.onSurfaceVariant, modifier = Modifier.size(19.dp))
|
||||
}
|
||||
}
|
||||
@@ -291,9 +291,11 @@ class DrawerActions(
|
||||
val achievementsProgress: Pair<Int, Int>? = null,
|
||||
val onOsc: (String) -> Unit,
|
||||
val layoutGame: String? = null,
|
||||
val layoutOptions: List<Pair<String, String>> = emptyList(),
|
||||
val layoutOptions: List<com.droiddeck.launcher.input.ControlsChoice.Option> = emptyList(),
|
||||
val layoutChoice: String = "",
|
||||
val layoutHint: String? = null,
|
||||
val onLayout: (String) -> Unit = {},
|
||||
val onDeleteLayout: (String) -> Unit = {},
|
||||
val onEditLayout: (() -> Unit)? = null,
|
||||
val oscRearButtons: Boolean? = null,
|
||||
val oscTrackpads: Boolean = false,
|
||||
@@ -669,8 +671,8 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
}
|
||||
SessionDrawerPage.CONTROLLER -> {
|
||||
SettingsGroup(a.layoutGame?.let { stringResource(R.string.osc_group_for, it) } ?: stringResource(R.string.mode_osc)) {
|
||||
if (a.layoutOptions.isNotEmpty()) ChoiceRow(host, "osc-layout", stringResource(R.string.osc_layout), null,
|
||||
a.layoutOptions, a.layoutChoice, chipModifier = focus.track(page, "osc-layout"), onPick = a.onLayout)
|
||||
if (a.layoutOptions.isNotEmpty()) LayoutChoiceRow(host, "osc-layout", a.layoutOptions, a.layoutChoice, a.layoutHint,
|
||||
chipModifier = focus.track(page, "osc-layout"), onPick = a.onLayout, onDelete = a.onDeleteLayout)
|
||||
a.onEditLayout?.let { edit ->
|
||||
ActionRow(stringResource(R.string.osc_edit_layout), null, stringResource(R.string.ctrl_edit), { host.open = null; edit() },
|
||||
modifier = focus.track(page, "osc-edit"))
|
||||
|
||||
@@ -326,8 +326,13 @@
|
||||
<string name="mode_osc_note">Auto shows the controls when no controller is connected.</string>
|
||||
<string name="osc_group_for">On-screen controls · %1$s</string>
|
||||
<string name="osc_layout">Layout</string>
|
||||
<string name="osc_layout_gamepad">Gamepad</string>
|
||||
<string name="osc_layout_steam">Steam layout</string>
|
||||
<string name="osc_layout_gamepad">DroidDeck controls</string>
|
||||
<string name="osc_layout_gamepad_detail">Works in every game. Edit them here.</string>
|
||||
<string name="osc_layout_steam">Steam touch controls</string>
|
||||
<string name="osc_layout_steam_detail">Each game\'s touch controls from Steam. Steam games only; edit them in Steam.</string>
|
||||
<string name="osc_layout_steam_unavailable">Steam touch controls only work in games launched through Steam, so these are shown instead.</string>
|
||||
<string name="osc_layout_detail_game">Just for %1$s</string>
|
||||
<string name="osc_delete_layout">Delete layout</string>
|
||||
<string name="osc_edit_layout">Edit layout</string>
|
||||
<string name="osc_show">Show</string>
|
||||
<string name="osc_rear_buttons">Rear buttons</string>
|
||||
|
||||
@@ -89,10 +89,10 @@ class ControlsChoiceTest {
|
||||
}
|
||||
|
||||
@Test fun newIsOfferedOnlyForAGame() {
|
||||
assertTrue(ControlsChoice.options(context, null, steamMode = true).none { it.first == ControlsChoice.NEW })
|
||||
assertEquals(ControlsChoice.NEW to context.getString(R.string.osc_layout_new_for, "Castle Crashers"),
|
||||
ControlsChoice.options(context, 7, steamMode = true, gameName = "Castle Crashers").last())
|
||||
assertEquals(listOf(InputLibraries.OVERLAY, GameControls.STEAM), ControlsChoice.options(context, null, steamMode = true).map { it.first }.take(2))
|
||||
assertTrue(ControlsChoice.options(context, null, steamMode = true).none { it.id == ControlsChoice.NEW })
|
||||
val last = ControlsChoice.options(context, 7, steamMode = true, gameName = "Castle Crashers").last()
|
||||
assertEquals(ControlsChoice.NEW to context.getString(R.string.osc_layout_new_for, "Castle Crashers"), last.id to last.name)
|
||||
assertEquals(listOf(InputLibraries.OVERLAY, GameControls.STEAM), ControlsChoice.options(context, null, steamMode = true).map { it.id })
|
||||
}
|
||||
|
||||
@Test fun newForTheGameInTheControllerPageCopiesTheLayoutAndOpensTheEditorOnIt() {
|
||||
@@ -101,8 +101,8 @@ class ControlsChoiceTest {
|
||||
ReflectionHelpers.getField<MutableState<Long?>>(activity, "frameGenActiveGameId\$delegate").value = 77L
|
||||
ReflectionHelpers.getField<MutableState<String?>>(activity, "frameGenActiveGameName\$delegate").value = "Castle Crashers"
|
||||
ReflectionHelpers.callInstanceMethod<Any?>(activity, "refreshInputProfile")
|
||||
val options = ReflectionHelpers.getField<MutableState<List<Pair<String, String>>>>(activity, "layoutOptions\$delegate").value
|
||||
assertEquals(ControlsChoice.NEW to "+ New for Castle Crashers", options.last())
|
||||
val options = ReflectionHelpers.getField<MutableState<List<ControlsChoice.Option>>>(activity, "layoutOptions\$delegate").value
|
||||
assertEquals(ControlsChoice.NEW to "+ New for Castle Crashers", options.last().let { it.id to it.name })
|
||||
ReflectionHelpers.callInstanceMethod<Any?>(activity, "chooseLayout", ReflectionHelpers.ClassParameter.from(String::class.java, ControlsChoice.NEW))
|
||||
val editor = ReflectionHelpers.getField<MutableState<Triple<String, String, String>?>>(activity, "layoutEditor\$delegate").value!!
|
||||
assertEquals(GameControls.bindings(activity, 77), editor.third)
|
||||
@@ -115,11 +115,87 @@ class ControlsChoiceTest {
|
||||
}
|
||||
|
||||
@Test fun aGameWithItsOwnLayoutCanGoBackToTheDefault() {
|
||||
assertTrue(ControlsChoice.options(context, 42L, steamMode = true, gameName = "Game").none { it.first == ControlsChoice.DEFAULT })
|
||||
assertTrue(ControlsChoice.options(context, 42L, steamMode = true, gameName = "Game").none { it.id == ControlsChoice.DEFAULT })
|
||||
ControlsChoice.newForGame(context, 42L, "Game", desktop = false)
|
||||
assertTrue(ControlsChoice.options(context, 42L, steamMode = true, gameName = "Game").first().first == ControlsChoice.DEFAULT)
|
||||
assertTrue(ControlsChoice.options(context, 42L, steamMode = true, gameName = "Game").first().id == ControlsChoice.DEFAULT)
|
||||
ControlsChoice.choose(context, 42L, ControlsChoice.DEFAULT, desktop = false)
|
||||
assertFalse(ControlsChoice.hasOwn(context, 42L))
|
||||
assertTrue(ControlsChoice.options(context, 42L, steamMode = true, gameName = "Game").none { it.first == ControlsChoice.DEFAULT })
|
||||
assertTrue(ControlsChoice.options(context, 42L, steamMode = true, gameName = "Game").none { it.id == ControlsChoice.DEFAULT })
|
||||
}
|
||||
|
||||
@Test fun aLayoutMadeForOneGameIsListedOnlyForThatGame() {
|
||||
val (layoutId, _) = ControlsChoice.newForGame(context, 7, "Castle Crashers", desktop = false)
|
||||
val mine = ControlsChoice.options(context, 7, steamMode = true, gameName = "Castle Crashers").first { it.id == layoutId }
|
||||
assertEquals(context.getString(R.string.osc_layout_detail_game, "Castle Crashers"), mine.detail)
|
||||
assertFalse(mine.deletable)
|
||||
assertTrue(ControlsChoice.options(context, 8, steamMode = true, gameName = "Portal").none { it.id == layoutId })
|
||||
assertTrue(ControlsChoice.options(context, null, steamMode = true).none { it.id == layoutId })
|
||||
ControlsChoice.useDefault(context, 7)
|
||||
assertTrue(ControlsChoice.options(context, 8, steamMode = true, gameName = "Portal").none { it.id == layoutId })
|
||||
assertTrue(ControlsChoice.options(context, 7, steamMode = true, gameName = "Castle Crashers").first { it.id == layoutId }.deletable)
|
||||
}
|
||||
|
||||
@Test fun anUnusedLayoutCanBeDeletedButNotOneInUse() {
|
||||
val source = bigSticks()
|
||||
assertTrue(ControlsChoice.options(context, null, steamMode = true).first { it.id == source }.deletable)
|
||||
ControlsChoice.choose(context, null, source, desktop = false)
|
||||
assertFalse(ControlsChoice.options(context, null, steamMode = true).first { it.id == source }.deletable)
|
||||
ControlsChoice.choose(context, null, InputLibraries.OVERLAY, desktop = false)
|
||||
ControlsChoice.choose(context, 7, source, desktop = false, gameName = "Castle Crashers")
|
||||
assertFalse(ControlsChoice.options(context, null, steamMode = true).first { it.id == source }.deletable)
|
||||
assertNull(ControlsChoice.options(context, 8, steamMode = true, gameName = "Portal").first { it.id == source }.detail)
|
||||
ControlsChoice.useDefault(context, 7)
|
||||
ControlsChoice.delete(context, source)
|
||||
val library = InputLibraries.read(context)
|
||||
assertTrue(library.layouts.none { it.id == source })
|
||||
assertTrue(library.bindings.none { it.layoutId == source })
|
||||
assertTrue(ControlsChoice.options(context, null, steamMode = true).none { it.id == source })
|
||||
}
|
||||
|
||||
@Test fun deletingALayoutAlsoRemovesAProfileThatCanNoLongerBeChosen() {
|
||||
InputLibraries.update(context) { it.duplicateProfile(InputProfile.GAME, "Game2") }
|
||||
val profile = InputLibraries.read(context).profiles.first { it.name == "Game2" }
|
||||
val layout = InputLibraries.read(context).layout(profile.id, InputRole.PRIMARY)!!
|
||||
assertEquals("Game2 / primary", layout.name)
|
||||
assertTrue(ControlsChoice.options(context, null, steamMode = true).first { it.id == layout.id }.deletable)
|
||||
ControlsChoice.delete(context, layout.id)
|
||||
val library = InputLibraries.read(context)
|
||||
assertTrue(library.profiles.none { it.id == profile.id })
|
||||
assertTrue(library.layouts.none { it.id == layout.id })
|
||||
assertTrue(profile.parts.values.none { part -> library.bindings.any { it.id == part.bindings } })
|
||||
assertEquals(InputLibraries.OVERLAY, ControlsChoice.current(context, null, steamMode = true))
|
||||
}
|
||||
|
||||
@Test fun steamTouchSavedForAGameFallsBackOutsideSteamWithANote() {
|
||||
ControlsChoice.choose(context, 7, GameControls.STEAM, desktop = false, gameName = "Portal")
|
||||
assertEquals(GameControls.STEAM, ControlsChoice.current(context, 7, steamMode = true))
|
||||
assertFalse(ControlsChoice.steamUnavailable(context, 7, steamMode = true))
|
||||
assertEquals(InputLibraries.OVERLAY, ControlsChoice.current(context, 7, steamMode = false))
|
||||
assertTrue(ControlsChoice.steamUnavailable(context, 7, steamMode = false))
|
||||
assertFalse(ControlsChoice.steamUnavailable(context, 8, steamMode = false))
|
||||
assertTrue(ControlsChoice.options(context, 7, steamMode = false, gameName = "Portal").none { it.id == GameControls.STEAM })
|
||||
}
|
||||
|
||||
@Test fun aLayoutNamedAfterTheGameThatDrawsItCountsAsThatGamesOwn() {
|
||||
val source = bigSticks()
|
||||
InputLibraries.update(context) { it.withLayout(it.layouts.first { l -> l.id == source }.copy(name = "ARMSX1")) }
|
||||
ControlsChoice.choose(context, 7, source, desktop = false, gameName = "ARMSX1")
|
||||
assertTrue(ControlsChoice.options(context, 8, steamMode = true, gameName = "Portal").none { it.id == source })
|
||||
assertEquals(context.getString(R.string.osc_layout_detail_game, "ARMSX1"),
|
||||
ControlsChoice.options(context, 7, steamMode = true, gameName = "ARMSX1").first { it.id == source }.detail)
|
||||
}
|
||||
|
||||
@Test fun aLayoutTheGameProfileStillListsCanBeDeletedOnceAnotherIsChosen() {
|
||||
val source = bigSticks()
|
||||
InputLibraries.update(context) { it.chooseLayout(InputProfile.GAME, InputRole.PRIMARY, source) }
|
||||
assertEquals(source, ControlsChoice.current(context, null, steamMode = true))
|
||||
assertFalse(ControlsChoice.options(context, null, steamMode = true).first { it.id == source }.deletable)
|
||||
ControlsChoice.choose(context, null, InputLibraries.OVERLAY, desktop = false)
|
||||
assertTrue(ControlsChoice.options(context, null, steamMode = true).first { it.id == source }.deletable)
|
||||
ControlsChoice.delete(context, source)
|
||||
val library = InputLibraries.read(context)
|
||||
assertTrue(library.layouts.none { it.id == source })
|
||||
assertEquals(InputLibraries.OVERLAY, library.profile(InputProfile.GAME).parts.getValue(InputRole.PRIMARY).layout)
|
||||
assertEquals(InputLibraries.OVERLAY, ControlsChoice.current(context, null, steamMode = true))
|
||||
}
|
||||
}
|
||||
@@ -156,6 +156,20 @@ class InputSettingsTest {
|
||||
compose.runOnIdle { assertEquals(SessionPrefs.OSC_NEVER, SessionPrefs.oscMode(context)) }
|
||||
}
|
||||
|
||||
@Test fun theLayoutMenuDescribesEachChoiceAndDeletesAnUnusedLayout() {
|
||||
InputLibraries.update(context) { it.copyLayout(InputLibraries.OVERLAY, "Big sticks", "big-sticks") }
|
||||
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }
|
||||
compose.onNodeWithTag("setting-osc-layout").performScrollTo().performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.osc_layout_gamepad_detail)).assertExists()
|
||||
compose.onNodeWithText(context.getString(R.string.osc_layout_steam_detail)).assertExists()
|
||||
compose.onNodeWithTag("osc-delete-${InputLibraries.OVERLAY}").assertDoesNotExist()
|
||||
compose.onNodeWithTag("osc-delete-big-sticks").performClick()
|
||||
compose.onNodeWithTag("osc-delete-confirm").performClick()
|
||||
compose.runOnIdle { assertTrue(InputLibraries.read(context).layouts.none { it.id == "big-sticks" }) }
|
||||
compose.onNodeWithTag("setting-osc-layout").performScrollTo().performClick()
|
||||
compose.onNodeWithText("Big sticks").assertDoesNotExist()
|
||||
}
|
||||
|
||||
@Test fun choosingTheDefaultLayoutAppliesToGamesWithoutTheirOwn() {
|
||||
InputLibraries.update(context) { it.copyLayout(InputLibraries.OVERLAY, "Big sticks", "big-sticks") }
|
||||
ControlsChoice.newForGame(context, 7, "Castle Crashers", desktop = false)
|
||||
|
||||
Reference in new issue
Block a user