mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +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
@@ -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