mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +00:00
fix(input): declutter the floating gamepad overlay (#2933)
This commit is contained in:
1 parent
f5d879f222
commit
e58b463f54
9 files changed
+244
-30
No files matched your search
@@ -113,6 +113,56 @@ class KitLayoutTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun aSideCutoutOnlyMovesTheOverlappingCluster() {
|
||||
val w = 2400
|
||||
val h = 1080
|
||||
val plain = KitLayout.elements(context, PadKit.STEAM_DECK, w, h, rearButtons = false, trackpads = false)
|
||||
val left = Rect(10, 380, 120, 480)
|
||||
val right = Rect(w - 120, 380, w, 480)
|
||||
val adjusted = KitLayout.elements(context, PadKit.STEAM_DECK, w, h, Rect(120, 0, 120, 0),
|
||||
cutouts = listOf(left, right), rearButtons = false, trackpads = false)
|
||||
val face = setOf("legacy:a", "legacy:b", "legacy:x", "legacy:y")
|
||||
val xOffsets = plain.zip(adjusted).associate { (before, after) ->
|
||||
assertEquals(before.id, after.id)
|
||||
assertEquals(before.y, after.y, .00001f)
|
||||
assertEquals(before.width, after.width, .00001f)
|
||||
assertEquals(before.height, after.height, .00001f)
|
||||
assertTrue(after.x * w >= left.right || (after.x + after.width) * w <= left.left ||
|
||||
after.y * h >= left.bottom || (after.y + after.height) * h <= left.top)
|
||||
assertTrue(after.x * w >= right.right || (after.x + after.width) * w <= right.left ||
|
||||
after.y * h >= right.bottom || (after.y + after.height) * h <= right.top)
|
||||
before.id to (after.x - before.x) * w
|
||||
}
|
||||
assertTrue(xOffsets.getValue(KitLayout.DPAD_ID) in 1f..100f)
|
||||
assertTrue(xOffsets.getValue("legacy:b") in -100f..-1f)
|
||||
for ((id, offset) in xOffsets) if (id in face) assertEquals(xOffsets.getValue("legacy:b"), offset, .01f)
|
||||
else if (id != KitLayout.DPAD_ID) assertEquals(id, 0f, offset, .01f)
|
||||
assertTrue(overlapping(adjusted, w, h).isEmpty())
|
||||
}
|
||||
|
||||
@Test fun aCutoutShiftDoesNotCoverAnAddedControl() {
|
||||
val w = 2400
|
||||
val h = 1080
|
||||
val safe = Rect(120, 0, 0, 0)
|
||||
val extra = InputSurfaceElement(InputControl.B, .05f, .4f, .025f, .06f, id = "added")
|
||||
val layout = SavedInputLayout(InputLibraries.OVERLAY, "Gamepad", listOf(extra), aspect = w.toFloat() / h)
|
||||
val fallback = OnScreenLayout.elements(context, layout, w, h, safe, rearButtons = false, trackpads = false)
|
||||
val placed = OnScreenLayout.elements(context, layout, w, h, safe, cutouts = listOf(Rect(0, 380, 120, 480)),
|
||||
rearButtons = false, trackpads = false)
|
||||
assertEquals(fallback, placed)
|
||||
assertTrue(overlapping(placed, w, h).isEmpty())
|
||||
}
|
||||
|
||||
@Test fun startAndSelectAreOnTheFloatingOverlayBottomRow() {
|
||||
for (kit in PadKit.entries) for ((w, h) in sizes) {
|
||||
val buttons = KitLayout.elements(context, kit, w, h)
|
||||
val keyboard = buttons.single { it.id == KitLayout.KEYBOARD_ID }
|
||||
for (button in buttons.filter { it.control == InputControl.SELECT || it.control == InputControl.START }) {
|
||||
assertTrue("$kit $w x $h ${button.id}", button.y + button.height / 2 in keyboard.y..(keyboard.y + keyboard.height))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun widerScreensSpreadTheControlsInsteadOfStretchingThem() {
|
||||
for (kit in PadKit.entries) {
|
||||
val narrow = KitLayout.elements(context, kit, 1920, 1080).associateBy { it.id }
|
||||
|
||||
@@ -32,6 +32,36 @@ class ShowLayoutTest {
|
||||
view.releaseInputs()
|
||||
}
|
||||
|
||||
@Test fun overlayExtrasAreIndependentAndKeepTheirPreferencesWhenRecreated() {
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_DECK)
|
||||
val kit = SavedInputLayout(InputLibraries.OVERLAY, "Gamepad")
|
||||
val grips = setOf(InputControl.L4, InputControl.L5, InputControl.R4, InputControl.R5)
|
||||
val trackpads = setOf(InputControl.LEFT_PAD, InputControl.RIGHT_PAD)
|
||||
fun controls(dock: OnScreenLayout.Dock? = null, layout: SavedInputLayout = kit): OnScreenControls =
|
||||
OnScreenControls(context, null, dock).also { it.updateLayout(layout); sized(it, 1920, 1080) }
|
||||
fun shown(view: OnScreenControls) = view.inputSurface.shownElements.map { it.control }.toSet()
|
||||
val overlay = controls()
|
||||
assertTrue(shown(overlay).intersect(grips + trackpads).isEmpty())
|
||||
SessionPrefs.setOscRearButtons(context, true)
|
||||
overlay.reload()
|
||||
assertTrue(shown(overlay).containsAll(grips))
|
||||
assertTrue(shown(overlay).intersect(trackpads).isEmpty())
|
||||
SessionPrefs.setOscTrackpads(context, true)
|
||||
SessionPrefs.setOscRearButtons(context, false)
|
||||
assertTrue(shown(controls()).containsAll(trackpads))
|
||||
assertTrue(shown(controls()).intersect(grips).isEmpty())
|
||||
|
||||
SessionPrefs.setOscTrackpads(context, false)
|
||||
val customPad = InputSurfaceElement(InputControl.LEFT_PAD, .4f, .4f, .15f, .15f, id = "custom-pad")
|
||||
val edited = kit.copy(elements = listOf(customPad,
|
||||
InputSurfaceElement(InputControl.RIGHT_PAD, .6f, .4f, .15f, .15f, id = "legacy:right-pad")))
|
||||
assertEquals(listOf(customPad.id), controls(layout = edited).inputSurface.shownElements.map { it.id })
|
||||
|
||||
val dock = OnScreenLayout.Dock(portrait = true, grips = true)
|
||||
val panel = OnScreenControls(context, null, dock).also { it.updateLayout(kit); sized(it, 1080, 1300) }
|
||||
assertTrue(shown(panel).containsAll(grips + trackpads))
|
||||
}
|
||||
|
||||
@Test fun aSavedLayoutIsDrawnAsSaved() {
|
||||
val saved = listOf(InputSurfaceElement(InputControl.A, .4f, .4f, .1f, .1f))
|
||||
val view = InputSurfaceView(context)
|
||||
|
||||
Reference in new issue
Block a user