mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 13:26:02 +00:00
fix(input): removed kit controls keep their actions in gamepad layouts
This commit is contained in:
1 parent
cd5e824c1b
commit
dcebdac765
4 files changed
+46
-7
No files matched your search
@@ -315,6 +315,11 @@ internal fun InputAction.validFor(element: InputSurfaceElement): Boolean = when
|
||||
else -> target.dimensions == 1 && target != InputControl.LT && target != InputControl.RT
|
||||
}
|
||||
|
||||
/** A saved element, or, in a gamepad that keeps no kit positions, the kit control that [id] names. */
|
||||
/**
|
||||
* A saved element, or the kit control that [id] names: in a layout made from the built-in gamepad every kit control keeps its
|
||||
* binding while it's removed, so Reset or Restore brings it back with its action.
|
||||
*/
|
||||
internal fun SavedInputLayout.element(id: String): InputSurfaceElement? =
|
||||
elements.firstOrNull { it.id == id } ?: KitLayout.element(id)?.takeIf { OnScreenLayout.generated(this) || KitLayout.bindsTo(id, elements) }
|
||||
elements.firstOrNull { it.id == id } ?: KitLayout.element(id)?.takeIf {
|
||||
this.id == InputLibraries.OVERLAY || origin == InputLibraries.OVERLAY || KitLayout.bindsTo(id, elements)
|
||||
}
|
||||
@@ -116,7 +116,10 @@ private class SurfaceDraft(val layout: SavedInputLayout, val preset: SavedInputB
|
||||
}
|
||||
fun hiddenDefaults(): List<InputSurfaceElement> = defaults?.let { refit(it, defaultsFrame) }?.filter { d -> elements.none { it.id == d.id } }.orEmpty()
|
||||
fun add(element: InputSurfaceElement) { checkpoint(); elements = elements + element; selected = element.id; popover = null }
|
||||
fun remove(id: String) { checkpoint(); elements = elements.filterNot { it.id == id }; actions = actions - id; clicks = clicks - id; selected = null }
|
||||
fun remove(id: String) {
|
||||
checkpoint(); elements = elements.filterNot { it.id == id }; selected = null
|
||||
if (!KitLayout.isKit(id)) { actions = actions - id; clicks = clicks - id }
|
||||
}
|
||||
fun resizeSelected(factor: Float) {
|
||||
val e = element ?: return
|
||||
checkpoint()
|
||||
@@ -173,9 +176,10 @@ fun InputSurfaceDialog(profile: String, onDismiss: () -> Unit, onChanged: () ->
|
||||
val p = latest.preset(bindingsTarget)
|
||||
val generated = draft.kitAtDefaults && OnScreenLayout.generated(l.copy(elements = emptyList(), kitless = false))
|
||||
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, 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 -> KitLayout.bindsTo(id, draft.elements) },
|
||||
clicks = draft.clicks.filterKeys { id -> draft.elements.any { it.id == id && it.hasClick } }))
|
||||
val edited = 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) })
|
||||
latest.withLayout(edited).withPreset(p.copy(elements = draft.actions.filterKeys { id -> edited.element(id) != null },
|
||||
clicks = draft.clicks.filterKeys { id -> edited.element(id)?.hasClick == true }))
|
||||
}
|
||||
copy?.use?.invoke(bindingsTarget)
|
||||
}.onSuccess { onChanged(); onDismiss() }.onFailure { failure = it.message ?: context.getString(R.string.input_save_failed) }
|
||||
|
||||
Reference in new issue
Block a user