mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +00:00
Merge remote-tracking branch 'origin/main' into docs/bottom-screen-research
This commit is contained in:
commit
868646e7e4
6 files changed
+294
-32
No files matched your search
@@ -1770,6 +1770,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
wowChat = wowChat.remembered,
|
||||
onWowChat = wowChat::choose,
|
||||
controller = controllerSettings,
|
||||
onControllerSize = { percent -> updateControllerPrefs { ControllerPrefs.setSize(this@SessionActivity, percent) } },
|
||||
onRumble = { on -> updateControllerPrefs { ControllerPrefs.setRumble(this@SessionActivity, on) } },
|
||||
onSteamMenu = if (SessionState.mode == SessionService.MODE_STEAM) ({ sendSteamGuide() }) else null,
|
||||
onQam = if (SessionState.mode == SessionService.MODE_STEAM) ({ triggerSteamQam() }) else null,
|
||||
@@ -2111,6 +2112,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
change()
|
||||
controllerSettings = ControllerPrefs.read(this)
|
||||
onScreenControls?.reload()
|
||||
bottomInputControls?.reload()
|
||||
unfoldedPanel?.reload()
|
||||
}
|
||||
|
||||
private fun routeBackAction() {
|
||||
@@ -2847,7 +2850,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
|
||||
private fun installProton(): String? {
|
||||
uiHandler.post { loading.percent = -1; loading.say(getString(PROTON_LINES.downloading), PROTON_LINES.topic, readable = true) }
|
||||
if (com.droiddeck.launcher.session.SessionPrefs.ownProtonFirst(this)) return installOwnProton()
|
||||
val catalog = com.droiddeck.launcher.runtime.DesktopCatalog
|
||||
val cancellation = com.droiddeck.launcher.core.Downloader.Cancellation { SessionState.stopRequested }
|
||||
SessionState.installCancellation = cancellation
|
||||
@@ -2860,24 +2862,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
}
|
||||
|
||||
private fun installOwnProton(): String? {
|
||||
val extras = com.droiddeck.launcher.session.ProtonExtras
|
||||
while ((extras.prefetching || extras.installInProgress) && !SessionState.stopRequested) {
|
||||
try { Thread.sleep(250) } catch (_: InterruptedException) { Thread.currentThread().interrupt(); return "interrupted" }
|
||||
}
|
||||
if (SessionState.stopRequested) return "cancelled"
|
||||
if (!com.droiddeck.launcher.runtime.DesktopCatalog.ownProtonMissing(this)) return null
|
||||
val cancellation = com.droiddeck.launcher.core.Downloader.Cancellation { SessionState.stopRequested }
|
||||
SessionState.installCancellation = cancellation
|
||||
return try {
|
||||
extras.install(this, extras.tools.first { it.id == extras.OWN }, cancellation) { label, percent ->
|
||||
uiHandler.post { loading.percent = percent; loading.say(label, PROTON_LINES.topic, readable = true) }
|
||||
}.also { if (it == null) com.droiddeck.launcher.session.Onboarding.recheck(this) }
|
||||
} finally {
|
||||
if (SessionState.installCancellation === cancellation) SessionState.installCancellation = null
|
||||
}
|
||||
}
|
||||
|
||||
override fun surfaceCreated(holder: SurfaceHolder) {
|
||||
if (holder !== outputHolder()) return
|
||||
if (installingRuntime || SessionState.stopRequested || ended) return
|
||||
|
||||
@@ -20,7 +20,7 @@ object ControllerPrefs {
|
||||
|
||||
val opacities = listOf(40, 60, 80, 100)
|
||||
|
||||
val sizes = listOf(80, 90, 100, 110, 125)
|
||||
val sizes = listOf(80, 85, 90, 95, 100, 105, 110, 115, 120, 125)
|
||||
|
||||
val deadZones = listOf(0, 5, 8, 12, 15, 20, 25)
|
||||
const val DEFAULT_DEAD_ZONE_PERCENT = 12
|
||||
|
||||
@@ -5,7 +5,7 @@ import android.graphics.Rect
|
||||
import kotlin.math.*
|
||||
|
||||
internal class LegacyGamepadLayout(private val context: Context, private val width: Int, private val height: Int, private val safe: Rect = Rect(),
|
||||
private val scale: Float = 1f) {
|
||||
private val scale: Float = 1f, private val sizeOverride: Int? = null) {
|
||||
private val resources get() = context.resources
|
||||
private val settings = ControllerPrefs.read(context)
|
||||
private var fit = 1f
|
||||
@@ -41,7 +41,7 @@ internal class LegacyGamepadLayout(private val context: Context, private val wid
|
||||
|
||||
private fun dp(value: Float) = value * resources.displayMetrics.density
|
||||
|
||||
private fun scaled(value: Float) = dp(value) * settings.size / 100f * scale * fit
|
||||
private fun scaled(value: Float) = dp(value) * (sizeOverride ?: settings.size) / 100f * scale * fit
|
||||
|
||||
private fun fitScale(): Float {
|
||||
val metrics = resources.displayMetrics
|
||||
|
||||
@@ -44,9 +44,10 @@ object OnScreenLayout {
|
||||
val (reference, matched) = reference(context, layout, width, height)
|
||||
if (buttonsOnly && dock == null) return generator.buttonsOnly(stored) + fit(stored.filter { it.alwaysShown }, reference.first, reference.second, width, height, safe)
|
||||
if (dock?.portrait == true && !dock.grips && !matched && layout.aspect > 0f && layout.aspect < 1f && stored.any(::isGamepad))
|
||||
return cluster(stored.filterNot { it.alwaysShown || isGamepad(it) && (it.id == KEYBOARD_ID || it.control in BAR) }, layout.aspect, width, height, safe)
|
||||
val generated = matched || PadKit.forOverlay(context, layout) != null && stored.any(::isGamepad) &&
|
||||
(dock != null || height > width && layout.aspect >= 1f || height <= width && layout.aspect > 0f && layout.aspect < 1f)
|
||||
return scaleDocked(context, cluster(stored.filterNot { it.alwaysShown || isGamepad(it) && (it.id == KEYBOARD_ID || it.control in BAR) }, layout.aspect, width, height, safe), ControllerPrefs.read(context).size / 100f, width, height, safe)
|
||||
val oppositeOrientation = layout.aspect > 0f && ((layout.aspect < 1f) != (height > width))
|
||||
val generated = matched ||
|
||||
dock == null && oppositeOrientation && stored.any(::isGamepad)
|
||||
val gamepad = if (generated) stored.filter(::isGamepad) else emptyList()
|
||||
val others = fit(stored.filterNot { generated && isGamepad(it) || dock != null && it.alwaysShown }, reference.first, reference.second, width, height, safe)
|
||||
val regenerated = when {
|
||||
@@ -57,22 +58,144 @@ object OnScreenLayout {
|
||||
val placed = regenerated + gamepad.filter { g -> dock == null && optional(g) && regenerated.none { it.id == g.id } }
|
||||
val byId = (placed + others).associateBy { it.id }
|
||||
val ordered = stored.mapNotNull { byId[it.id] } + placed.filter { p -> stored.none { it.id == p.id } }
|
||||
val kit = PadKit.forOverlay(context, layout) ?: return ordered
|
||||
val kit = PadKit.forOverlay(context, layout) ?: return if (dock == null) ordered else scaleDocked(context, ordered, ControllerPrefs.read(context).size / 100f, width, height, safe)
|
||||
val controllerScale = layout.scale * ControllerPrefs.read(context).size / 100f
|
||||
if (generated &&
|
||||
ControllerPrefs.layout(context, reference.first.toInt(), reference.second.toInt()).isEmpty() &&
|
||||
ControllerPrefs.layout(context, width, height).isEmpty()) {
|
||||
if (dock != null || height > width) {
|
||||
return ControllerPortraitGeometry(width.toFloat(), height.toFloat(), safe, context.resources.displayMetrics.density)
|
||||
.place(ordered, kit, dock != null, layout.scale, rearButtons == true, trackpads == true)
|
||||
val placed = ControllerPortraitGeometry(width.toFloat(), height.toFloat(), safe, context.resources.displayMetrics.density)
|
||||
.place(ordered, kit, dock != null, controllerScale, rearButtons == true, trackpads == true)
|
||||
return if (dock != null) {
|
||||
scaleDocked(context, placed, ControllerPrefs.read(context).size / 100f, width, height, safe)
|
||||
} else placed
|
||||
}
|
||||
return ControllerOverlayGeometry(width, height, safe, context.resources.displayMetrics, layout.scale)
|
||||
return ControllerOverlayGeometry(width, height, safe, context.resources.displayMetrics, controllerScale)
|
||||
.place(ordered, kit, rearButtons == true, trackpads == true)
|
||||
}
|
||||
if (dock != null || !kit.steam) return ordered
|
||||
if (dock != null || !kit.steam) {
|
||||
if (dock == null) return ordered
|
||||
return scaleDocked(context, ordered, ControllerPrefs.read(context).size / 100f, width, height, safe)
|
||||
}
|
||||
return FloatingSteamOverlay(width, height, safe, context.resources.displayMetrics.density)
|
||||
.place(ordered, lowerShortcuts = generated, rearButtons = rearButtons, trackpads = trackpads)
|
||||
}
|
||||
|
||||
private fun scaleDocked(context: Context, elements: List<InputSurfaceElement>, scale: Float, width: Int, height: Int, safe: Rect): List<InputSurfaceElement> {
|
||||
val usableWidth = (width - safe.left - safe.right).coerceAtLeast(1).toFloat() / width
|
||||
val usableHeight = (height - safe.top - safe.bottom).coerceAtLeast(1).toFloat() / height
|
||||
val leftBound = safe.left.toFloat() / width
|
||||
val rightBound = (width - safe.right).toFloat() / width
|
||||
val topBound = safe.top.toFloat() / height
|
||||
val bottomBound = (height - safe.bottom).toFloat() / height
|
||||
val scaled = elements.map { element ->
|
||||
if (!isGamepad(element)) return@map element
|
||||
val w = (element.width * scale).coerceIn(min(.001f, usableWidth), usableWidth)
|
||||
val h = (element.height * scale).coerceIn(min(.001f, usableHeight), usableHeight)
|
||||
val x = (element.x + element.width / 2f - w / 2f)
|
||||
.coerceIn(leftBound, (rightBound - w).coerceAtLeast(leftBound))
|
||||
val y = (element.y + element.height / 2f - h / 2f)
|
||||
.coerceIn(topBound, (bottomBound - h).coerceAtLeast(topBound))
|
||||
element.copy(x = x, y = y, width = w, height = h).bounded()
|
||||
}.toMutableList()
|
||||
if (scale > 1f) {
|
||||
val gap = 4f / width
|
||||
fun spacePair(leftControl: InputControl, rightControl: InputControl) {
|
||||
val li = scaled.indexOfFirst { isGamepad(it) && it.control == leftControl }
|
||||
val ri = scaled.indexOfFirst { isGamepad(it) && it.control == rightControl }
|
||||
if (li < 0 || ri < 0) return
|
||||
var left = scaled[li]
|
||||
var right = scaled[ri]
|
||||
val available = (rightBound - leftBound).coerceAtLeast(.001f)
|
||||
var gapSize = gap.coerceAtMost(available / 4f)
|
||||
if (left.width + right.width + gapSize > available) {
|
||||
val factor = ((available - gapSize).coerceAtLeast(0f) / (left.width + right.width)).coerceAtMost(1f)
|
||||
left = left.copy(width = left.width * factor)
|
||||
right = right.copy(width = right.width * factor)
|
||||
}
|
||||
val total = left.width + gapSize + right.width
|
||||
val center = ((left.x + left.width / 2f) + (right.x + right.width / 2f)) / 2f
|
||||
val start = (center - total / 2f).coerceIn(leftBound, (rightBound - total).coerceAtLeast(leftBound))
|
||||
scaled[li] = left.copy(x = start)
|
||||
scaled[ri] = right.copy(x = start + left.width + gapSize)
|
||||
}
|
||||
spacePair(InputControl.LT, InputControl.LB)
|
||||
spacePair(InputControl.RB, InputControl.RT)
|
||||
}
|
||||
if (scale > 1f && ControllerPrefs.layout(context, width, height).isEmpty()) {
|
||||
repeat(scaled.size) {
|
||||
for (i in scaled.indices) {
|
||||
if (!isGamepad(scaled[i])) continue
|
||||
for (j in i + 1 until scaled.size) {
|
||||
if (!isGamepad(scaled[j])) continue
|
||||
val a = scaled[i]
|
||||
val b = scaled[j]
|
||||
val overlapX = min(a.x + a.width, b.x + b.width) - max(a.x, b.x)
|
||||
val overlapY = min(a.y + a.height, b.y + b.height) - max(a.y, b.y)
|
||||
if (overlapX <= 0f || overlapY <= 0f) continue
|
||||
|
||||
val centerAX = a.x + a.width / 2f
|
||||
val centerBX = b.x + b.width / 2f
|
||||
val centerAY = a.y + a.height / 2f
|
||||
val centerBY = b.y + b.height / 2f
|
||||
if (overlapX / min(a.width, b.width) <= overlapY / min(a.height, b.height)) {
|
||||
val gapX = 2f / width
|
||||
val available = (rightBound - leftBound).coerceAtLeast(.001f)
|
||||
val leftFirst = centerAX <= centerBX
|
||||
val factor = ((available - gapX).coerceAtLeast(0f) / (a.width + b.width)).coerceIn(0f, 1f)
|
||||
val aw = a.width * factor
|
||||
val ah = a.height * factor
|
||||
val bw = b.width * factor
|
||||
val bh = b.height * factor
|
||||
val total = aw + gapX + bw
|
||||
val center = ((centerAX + centerBX) / 2f).coerceIn(
|
||||
leftBound + total / 2f,
|
||||
(rightBound - total / 2f).coerceAtLeast(leftBound + total / 2f))
|
||||
val firstX = center - total / 2f
|
||||
val secondX = firstX + (if (leftFirst) aw else bw) + gapX
|
||||
scaled[i] = if (leftFirst) {
|
||||
a.copy(x = firstX, y = centerAY - ah / 2f, width = aw, height = ah)
|
||||
} else {
|
||||
a.copy(x = secondX, y = centerAY - ah / 2f, width = aw, height = ah)
|
||||
}
|
||||
scaled[j] = if (leftFirst) {
|
||||
b.copy(x = secondX, y = centerBY - bh / 2f, width = bw, height = bh)
|
||||
} else {
|
||||
b.copy(x = firstX, y = centerBY - bh / 2f, width = bw, height = bh)
|
||||
}
|
||||
} else {
|
||||
val gapY = 2f / height
|
||||
val available = (bottomBound - topBound).coerceAtLeast(.001f)
|
||||
val topFirst = centerAY <= centerBY
|
||||
val factor = ((available - gapY).coerceAtLeast(0f) / (a.height + b.height)).coerceIn(0f, 1f)
|
||||
val aw = a.width * factor
|
||||
val ah = a.height * factor
|
||||
val bw = b.width * factor
|
||||
val bh = b.height * factor
|
||||
val total = ah + gapY + bh
|
||||
val center = ((centerAY + centerBY) / 2f).coerceIn(
|
||||
topBound + total / 2f,
|
||||
(bottomBound - total / 2f).coerceAtLeast(topBound + total / 2f))
|
||||
val firstY = center - total / 2f
|
||||
val secondY = firstY + (if (topFirst) ah else bh) + gapY
|
||||
scaled[i] = if (topFirst) {
|
||||
a.copy(x = centerAX - aw / 2f, y = firstY, width = aw, height = ah)
|
||||
} else {
|
||||
a.copy(x = centerAX - aw / 2f, y = secondY, width = aw, height = ah)
|
||||
}
|
||||
scaled[j] = if (topFirst) {
|
||||
b.copy(x = centerBX - bw / 2f, y = secondY, width = bw, height = bh)
|
||||
} else {
|
||||
b.copy(x = centerBX - bw / 2f, y = firstY, width = bw, height = bh)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return scaled
|
||||
}
|
||||
|
||||
fun oriented(layout: SavedInputLayout, width: Int, height: Int): SavedInputLayout = oriented(layout, height > width)
|
||||
|
||||
private fun oriented(layout: SavedInputLayout, portrait: Boolean): SavedInputLayout {
|
||||
@@ -181,7 +304,14 @@ object OnScreenLayout {
|
||||
?.let { (it * height).roundToInt().coerceAtLeast(1) to height }
|
||||
for ((w, h) in listOfNotNull(named, width to height, aspectSize, long to short, short to long).distinct()) {
|
||||
val generator = LegacyGamepadLayout(display, w, h, scale = layout.scale)
|
||||
if (matches(gamepad, generator.elements()) || matches(gamepad, generator.elements(previousStickGeometry = true))) return (w.toFloat() to h.toFloat()) to true
|
||||
val sizedGenerator = LegacyGamepadLayout(
|
||||
display, w, h, scale = layout.scale,
|
||||
sizeOverride = ControllerPrefs.read(context).size
|
||||
)
|
||||
if (matches(gamepad, generator.elements()) || matches(gamepad, generator.elements(previousStickGeometry = true)) ||
|
||||
matches(gamepad, sizedGenerator.elements()) || matches(gamepad, sizedGenerator.elements(previousStickGeometry = true))) {
|
||||
return (w.toFloat() to h.toFloat()) to true
|
||||
}
|
||||
}
|
||||
}
|
||||
val aspect = layout.aspect.takeIf { it > 0f } ?: (long.toFloat() / short)
|
||||
|
||||
@@ -315,6 +315,7 @@ class DrawerActions(
|
||||
val onOsc: (String) -> Unit,
|
||||
val onEditSteamTouch: (() -> Unit)? = null,
|
||||
val controller: com.droiddeck.launcher.input.ControllerPrefs.Settings? = null,
|
||||
val onControllerSize: (Int) -> Unit = {},
|
||||
val onRumble: (Boolean) -> Unit = {},
|
||||
val onSuspendPolicy: (String) -> Unit,
|
||||
val onSteamDownloadsInBackground: (Boolean) -> Unit = {},
|
||||
@@ -749,9 +750,11 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
type, chipModifier = focus.track(page, "pad-type"), onPick = a.onPadType)
|
||||
}
|
||||
a.controller?.let { c ->
|
||||
SliderRow(stringResource(R.string.ctrl_size), null, c.size, 80..125, step = 5,
|
||||
format = { "$it%" }, modifier = focus.track(page, "controller-size"),
|
||||
onChange = a.onControllerSize)
|
||||
ToggleRow(host, "rumble", stringResource(R.string.ctrl_rumble), null, c.rumble,
|
||||
chipModifier = focus.track(page, "rumble"), onChange = a.onRumble)
|
||||
|
||||
}
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.input_touchscreen)) {
|
||||
|
||||
@@ -96,6 +96,115 @@ class OnScreenLayoutTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun changingControllerSizeRegeneratesAnUneditedBuiltInLandscapeOverlay() {
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_DECK)
|
||||
val layout = gamepad()
|
||||
val w = 1200
|
||||
val h = 540
|
||||
ControllerPrefs.setSize(context, 100)
|
||||
val original = OnScreenLayout.elements(context, layout, w, h, Rect())
|
||||
ControllerPrefs.setSize(context, 115)
|
||||
val resized = OnScreenLayout.elements(context, layout, w, h, Rect())
|
||||
assertNotEquals(original.single { it.id == "legacy:a" }.width, resized.single { it.id == "legacy:a" }.width, .0001f)
|
||||
assertNotEquals(original.single { it.id == "legacy:ls" }.height, resized.single { it.id == "legacy:ls" }.height, .0001f)
|
||||
}
|
||||
|
||||
@Test fun unchangedSizeDoesNotCollapseCoincidentEditedPortraitControls() {
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_DECK)
|
||||
val stock = gamepad()
|
||||
val coincident = stock.elements.map { element ->
|
||||
if (element.id == "legacy:a" || element.id == "legacy:b") {
|
||||
element.copy(x = .2f, y = .2f, width = .1f, height = .1f)
|
||||
} else element
|
||||
}
|
||||
val edited = stock.copy(elements = coincident, aspect = .5f)
|
||||
ControllerPrefs.setSize(context, 100)
|
||||
val placed = OnScreenLayout.elements(
|
||||
context, edited, 540, 1080, Rect(),
|
||||
dock = OnScreenLayout.Dock(true, false),
|
||||
)
|
||||
assertTrue(placed.at(InputControl.A).width > 0f)
|
||||
assertTrue(placed.at(InputControl.B).width > 0f)
|
||||
}
|
||||
|
||||
@Test fun changingControllerSizeResizesDefaultDockedControlsWithoutASavedLayout() {
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_DECK)
|
||||
val layout = gamepad()
|
||||
val w = 1200
|
||||
val h = 540
|
||||
val dock = OnScreenLayout.Dock(false, false)
|
||||
ControllerPrefs.setSize(context, 100)
|
||||
val original = OnScreenLayout.elements(context, layout, w, h, Rect(), dock = dock)
|
||||
ControllerPrefs.setSize(context, 125)
|
||||
val resized = OnScreenLayout.elements(context, layout, w, h, Rect(), dock = dock)
|
||||
assertNotEquals(original.at(InputControl.LS).width, resized.at(InputControl.LS).width, .0001f)
|
||||
assertNotEquals(original.at(InputControl.A).height, resized.at(InputControl.A).height, .0001f)
|
||||
assertInside(resized, w, h)
|
||||
}
|
||||
|
||||
@Test fun changingControllerSizeRegeneratesSavedLandscapeBuiltInOverlay() {
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_DECK)
|
||||
val layout = gamepad().copy(aspect = 2f)
|
||||
val w = 1200
|
||||
val h = 540
|
||||
ControllerPrefs.setSize(context, 100)
|
||||
val original = OnScreenLayout.elements(context, layout, w, h, Rect())
|
||||
ControllerPrefs.setSize(context, 125)
|
||||
val resized = OnScreenLayout.elements(context, layout, w, h, Rect())
|
||||
assertNotEquals(original.at(InputControl.A).width, resized.at(InputControl.A).width, .0001f)
|
||||
}
|
||||
|
||||
@Test fun enlargedDefaultDockedControlsDoNotOverlapTheActionButtonAndRightStick() {
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_DECK)
|
||||
ControllerPrefs.setSize(context, 125)
|
||||
val placed = OnScreenLayout.elements(
|
||||
context, gamepad(), 1200, 540, Rect(),
|
||||
dock = OnScreenLayout.Dock(false, false),
|
||||
)
|
||||
val stick = placed.at(InputControl.RS)
|
||||
val button = placed.at(InputControl.A)
|
||||
val overlapX = minOf(stick.x + stick.width, button.x + button.width) - maxOf(stick.x, button.x)
|
||||
val overlapY = minOf(stick.y + stick.height, button.y + button.height) - maxOf(stick.y, button.y)
|
||||
assertFalse("RS and A hit rectangles must not overlap", overlapX > 0f && overlapY > 0f)
|
||||
}
|
||||
|
||||
@Test fun changingControllerSizeResizesDockedControlsWithASavedLayout() {
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_DECK)
|
||||
val layout = gamepad()
|
||||
val w = 1200
|
||||
val h = 540
|
||||
ControllerPrefs.setLayout(context, w, h, mapOf("ls" to (.12f to .7f)))
|
||||
val dock = OnScreenLayout.Dock(false, false)
|
||||
ControllerPrefs.setSize(context, 100)
|
||||
val original = OnScreenLayout.elements(context, layout, w, h, Rect(), dock = dock)
|
||||
ControllerPrefs.setSize(context, 120)
|
||||
val resized = OnScreenLayout.elements(context, layout, w, h, Rect(), dock = dock)
|
||||
val before = original.single { it.id == "legacy:a" }
|
||||
val after = resized.single { it.id == "legacy:a" }
|
||||
assertTrue(after.width > before.width)
|
||||
assertTrue(after.height > before.height)
|
||||
assertEquals(before.x + before.width / 2f, after.x + after.width / 2f, .001f)
|
||||
assertEquals(before.y + before.height / 2f, after.y + after.height / 2f, .001f)
|
||||
assertEquals(mapOf("ls" to (.12f to .7f)), ControllerPrefs.layout(context, w, h))
|
||||
}
|
||||
|
||||
@Test fun enlargedDockedControlsStayInsideSafeAreaAndKeepShoulderGaps() {
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_DECK)
|
||||
val w = 1080
|
||||
val h = 200
|
||||
val safe = Rect(20, 0, 20, 24)
|
||||
ControllerPrefs.setLayout(context, w, h, mapOf("ls" to (.12f to .7f)))
|
||||
ControllerPrefs.setSize(context, 125)
|
||||
val placed = OnScreenLayout.elements(context, gamepad(), w, h, safe, dock = OnScreenLayout.Dock(false, false))
|
||||
assertInside(placed, w, h, safe)
|
||||
for ((left, right) in listOf(InputControl.LT to InputControl.LB, InputControl.RB to InputControl.RT)) {
|
||||
val a = placed.single { it.control == left }
|
||||
val b = placed.single { it.control == right }
|
||||
assertTrue("$left should remain left of $right", a.x + a.width <= b.x)
|
||||
assertTrue("$left and $right should retain a gap", (b.x - a.x - a.width) * w >= 3.5f)
|
||||
}
|
||||
}
|
||||
|
||||
@Test @Config(qualifiers = "w745dp-h343dp-land-420dpi")
|
||||
fun aBuiltInGamepadSavedAtTheDisplaySizeRegeneratesForTheMeasuredSurface() {
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_NONE)
|
||||
@@ -574,6 +683,12 @@ class OnScreenLayoutTest {
|
||||
val normal = at(1f)
|
||||
for (scale in listOf(.8f, 1.25f)) {
|
||||
val placed = at(scale)
|
||||
for (control in listOf(InputControl.A, InputControl.B, InputControl.X, InputControl.Y, InputControl.LS, InputControl.RS)) {
|
||||
val before = normal.at(control)
|
||||
val after = placed.at(control)
|
||||
assertEquals("$kit $scale ${control.id} aspect ratio", before.width / before.height,
|
||||
after.width / after.height, .02f)
|
||||
}
|
||||
assertEquals("$kit $scale", normal.at(InputControl.A).width * scale, placed.at(InputControl.A).width, .002f)
|
||||
assertEquals("$kit $scale", normal.at(InputControl.LS).height * scale, placed.at(InputControl.LS).height, .002f)
|
||||
if (scale > 1f) for (cluster in listOf(face, dpad)) {
|
||||
@@ -699,4 +814,34 @@ class OnScreenLayoutTest {
|
||||
assertFalse(kit.artwork(layout.elements.first { it.control == InputControl.A }.copy(image = "picture")))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun dockedSizeAppliesWithoutAKitAndToThePortraitCluster() {
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_NONE)
|
||||
val stock = gamepad()
|
||||
val dock = OnScreenLayout.Dock(false, false)
|
||||
|
||||
ControllerPrefs.setSize(context, 100)
|
||||
val defaultNormal = OnScreenLayout.elements(context, stock, 1200, 540, Rect(), dock = dock)
|
||||
ControllerPrefs.setSize(context, 125)
|
||||
val defaultLarge = OnScreenLayout.elements(context, stock, 1200, 540, Rect(), dock = dock)
|
||||
assertTrue(defaultLarge.at(InputControl.A).width > defaultNormal.at(InputControl.A).width)
|
||||
|
||||
val portraitEdited = stock.copy(
|
||||
elements = stock.elements.map {
|
||||
if (it.control == InputControl.A) it.copy(x = it.x + .07f) else it
|
||||
},
|
||||
aspect = .5f,
|
||||
)
|
||||
val portraitDock = OnScreenLayout.Dock(true, false)
|
||||
ControllerPrefs.setSize(context, 100)
|
||||
val clusterNormal = OnScreenLayout.elements(
|
||||
context, portraitEdited, 540, 1200, Rect(), dock = portraitDock,
|
||||
)
|
||||
ControllerPrefs.setSize(context, 125)
|
||||
val clusterLarge = OnScreenLayout.elements(
|
||||
context, portraitEdited, 540, 1200, Rect(), dock = portraitDock,
|
||||
)
|
||||
assertTrue(clusterLarge.at(InputControl.A).width > clusterNormal.at(InputControl.A).width)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user