mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 13:26:02 +00:00
fix(input): D-pad keeps direction overrides, kit bindings survive layout edits and an emptied gamepad stays empty
This commit is contained in:
1 parent
fdcb7eb3c4
commit
952f363b45
11 files changed
+50
-11
No files matched your search
@@ -4479,6 +4479,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
|
||||
private fun controlsBelowWanted(): Boolean {
|
||||
if (!::sessionRoot.isInitialized || glassesScreen != null || bottomGame != null || cardboard.enabled) return false
|
||||
if (SessionPrefs.oscMode(this) == SessionPrefs.OSC_NEVER) return false
|
||||
return SessionPrefs.controlsBelowWanted(this, SessionState.mode, sessionRoot.width, sessionRoot.height,
|
||||
pipUi || isInPictureInPictureMode)
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ object ControlsPresenter {
|
||||
state.mode == SessionPrefs.OSC_AUTO && state.desktop -> Plan(Place.NONE)
|
||||
else -> Plan(
|
||||
when {
|
||||
state.steamLayout -> Place.STEAM
|
||||
state.bottomScreen -> Place.BOTTOM
|
||||
state.steamLayout -> Place.STEAM
|
||||
else -> Place.MAIN
|
||||
},
|
||||
when {
|
||||
|
||||
@@ -277,7 +277,7 @@ object InputLibraries {
|
||||
.put("elementOpacity", e.opacity.toDouble()).put("buttonShape", e.buttonShape.name).put("showLabel", e.showLabel).put("alwaysShown", e.alwaysShown))
|
||||
layouts.put(JSONObject().put("id", layout.id).put("name", layout.name).put("template", layout.template.name).put("elements", elements)
|
||||
.put("tint", layout.style.tint ?: JSONObject.NULL).put("opacity", layout.style.opacity).put("screen", layout.screen.name).put("aspect", layout.aspect.toDouble()).put("scale", layout.scale.toDouble())
|
||||
.put("hidden", JSONArray(layout.style.hidden.map { it.name }.sorted())).put("origin", layout.origin ?: JSONObject.NULL))
|
||||
.put("hidden", JSONArray(layout.style.hidden.map { it.name }.sorted())).put("origin", layout.origin ?: JSONObject.NULL).put("kitless", layout.kitless))
|
||||
}
|
||||
val bindings = JSONArray()
|
||||
for (b in library.bindings) {
|
||||
@@ -321,7 +321,7 @@ object InputLibraries {
|
||||
InputSurfaceStyle(if (!layout.has("tint")) ControllerPrefs.STEAM_BLUE else if (layout.isNull("tint")) null else layout.getInt("tint"), layout.optInt("opacity", 100),
|
||||
layout.optJSONArray("hidden")?.let { hidden -> (0 until hidden.length()).map { InputCommand.valueOf(hidden.getString(it)) }.toSet() }.orEmpty()),
|
||||
InputLayoutScreen.valueOf(layout.optString("screen", InputLayoutScreen.BOTH.name)), layout.optDouble("aspect", 0.0).toFloat(), layout.optionalString("origin"),
|
||||
layout.optDouble("scale", 1.0).toFloat())
|
||||
layout.optDouble("scale", 1.0).toFloat(), layout.optBoolean("kitless", false))
|
||||
}
|
||||
val bindings = doc.getJSONArray("bindings").objects(512).map { b ->
|
||||
val controls = b.getJSONObject("controls").actions(28).mapKeys { requireNotNull(InputControl.fromId(it.key)) }
|
||||
|
||||
@@ -22,6 +22,8 @@ data class SavedInputLayout(
|
||||
val aspect: Float = 0f,
|
||||
val origin: String? = null,
|
||||
val scale: Float = 1f,
|
||||
/** The player removed every kit control from this gamepad, so it must not follow the virtual controller again. */
|
||||
val kitless: Boolean = false,
|
||||
) {
|
||||
val editable get() = template == InputLayoutTemplate.CUSTOM
|
||||
val quickButtons get() = QUICK_BUTTONS.filter { button -> elements.any { it.quickButton == button } }
|
||||
@@ -136,8 +138,8 @@ data class InputLibrary(
|
||||
fun withPreset(value: SavedInputBindings) = copy(bindings = bindings.filterNot { it.id == value.id } + value)
|
||||
fun withLayout(value: SavedInputLayout) = copy(layouts = layouts.filterNot { it.id == value.id } + value,
|
||||
bindings = bindings.map { preset -> if (preset.layoutId != value.id) preset else preset.copy(
|
||||
elements = preset.elements.filter { (id, action) -> value.elements.any { it.id == id && action.validFor(it) } },
|
||||
clicks = preset.clicks.filter { (id, action) -> value.elements.any { it.id == id && it.hasClick && action.validForClick() } }) })
|
||||
elements = preset.elements.filter { (id, action) -> value.element(id)?.let { action.validFor(it) } == true },
|
||||
clicks = preset.clicks.filter { (id, action) -> value.element(id)?.hasClick == true && action.validForClick() }) })
|
||||
|
||||
fun duplicateProfile(id: String, name: String, newId: String = newInputId(), sharePhysical: Boolean = false): InputLibrary {
|
||||
require(profiles.size < 64)
|
||||
|
||||
@@ -5,7 +5,8 @@ class InputSurfaceSource(private val pad: PadBridge, private val role: InputRole
|
||||
private val route = router?.channel(role, element.control, element = element)
|
||||
/** The kit's D-pad keeps each direction's own binding, as the separate direction buttons it replaced did. */
|
||||
private val arms = if (element.id == KitLayout.DPAD_ID && router != null)
|
||||
listOf(InputControl.UP, InputControl.RIGHT, InputControl.DOWN, InputControl.LEFT).map { router.channel(role, it) } else emptyList()
|
||||
listOf(InputControl.UP, InputControl.RIGHT, InputControl.DOWN, InputControl.LEFT).map { router.channel(role, it, element = KitLayout.element("legacy:${it.id}")) }
|
||||
else emptyList()
|
||||
private val deck = DeckControls.source(role, routed = true)
|
||||
private val clickDeck = DeckControls.source(role, routed = true)
|
||||
private val clickOwner = Any()
|
||||
@@ -59,6 +60,7 @@ class InputSurfaceSource(private val pad: PadBridge, private val role: InputRole
|
||||
if (latched) 1f else 0f
|
||||
} else value
|
||||
if (arms.isNotEmpty() && route?.action is InputAction.Native) {
|
||||
route.update(x, y, touching)
|
||||
val values = listOf(y < -.5f, x > .5f, y > .5f, x < -.5f).map { if (it) 1f else 0f }
|
||||
val toPad = arms.mapIndexed { i, arm -> arm.update(values[i])?.takeIf { it.isPad }?.let { it to values[i] } }.filterNotNull()
|
||||
if (toPad.isNotEmpty() || nativePad) writePad(this, null) { state -> state.clear(); for ((t, v) in toPad) state.add(t, v) }
|
||||
@@ -86,6 +88,7 @@ class InputSurfaceSource(private val pad: PadBridge, private val role: InputRole
|
||||
fun cancel() {
|
||||
if (closed) return
|
||||
route?.takeIf { it.action is InputAction.Command }?.release()
|
||||
arms.filter { it.action is InputAction.Command }.forEach { it.release() }
|
||||
update(0f)
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ object OnScreenLayout {
|
||||
* the layout stores only the keys and controls the player added on top.
|
||||
*/
|
||||
fun generated(layout: SavedInputLayout) = (layout.id == InputLibraries.OVERLAY || layout.origin == InputLibraries.OVERLAY) &&
|
||||
layout.elements.none { KitLayout.isKit(it.id) }
|
||||
!layout.kitless && layout.elements.none { KitLayout.isKit(it.id) }
|
||||
|
||||
fun elements(context: Context, layout: SavedInputLayout?, width: Int, height: Int, safe: Rect, dock: Dock? = null): List<InputSurfaceElement> {
|
||||
layout ?: return emptyList()
|
||||
|
||||
@@ -165,8 +165,8 @@ fun InputSurfaceDialog(profile: String, onDismiss: () -> Unit, onChanged: () ->
|
||||
val p = latest.preset(savedBindings.id)
|
||||
val generated = draft.kitAtDefaults && OnScreenLayout.generated(l.copy(elements = emptyList()))
|
||||
val extras = draft.elements.filterNot { KitLayout.isKit(it.id) }
|
||||
latest.withLayout(if (generated) l.copy(elements = extras, aspect = if (extras.isEmpty()) 0f else draft.aspect, scale = draft.layoutScale)
|
||||
else l.copy(elements = draft.elements, aspect = draft.aspect, scale = draft.layoutScale)).withPreset(p.copy(elements = draft.actions.filterKeys { id -> draft.elements.any { it.id == id } },
|
||||
latest.withLayout(if (generated) l.copy(elements = extras, aspect = if (extras.isEmpty()) 0f else draft.aspect, scale = draft.layoutScale, kitless = false)
|
||||
else l.copy(elements = draft.elements, aspect = draft.aspect, scale = draft.layoutScale, kitless = draft.elements.none { KitLayout.isKit(it.id) })).withPreset(p.copy(elements = draft.actions.filterKeys { id -> draft.elements.any { it.id == id } },
|
||||
clicks = draft.clicks.filterKeys { id -> draft.elements.any { it.id == id && it.hasClick } }))
|
||||
}
|
||||
}.onSuccess { onChanged(); onDismiss() }.onFailure { failure = it.message ?: context.getString(R.string.input_save_failed) }
|
||||
|
||||
@@ -576,6 +576,7 @@ class InputSurfaceView(
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||
if (event.actionMasked == MotionEvent.ACTION_CANCEL) { source?.cancel(); held = 0; invalidate(); return true }
|
||||
val bits = when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_MOVE -> {
|
||||
val dx = event.getX(0) - width / 2f
|
||||
|
||||
Reference in new issue
Block a user