mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 06:15:58 +00:00
feat(input): portrait pad under the game, kit-aware editor reset and leaner controller settings
This commit is contained in:
1 parent
0fba656ee2
commit
40665bbb1a
140 files changed
+1059
-2321
No files matched your search
@@ -7,21 +7,6 @@ object ControllerPrefs {
|
||||
const val STEAM_BLUE = 0xFF1A9FFF.toInt()
|
||||
const val OFF = "off"
|
||||
|
||||
val tints = listOf(
|
||||
STEAM_BLUE to R.string.ctrl_tint_steam_blue,
|
||||
0xFF66C0F4.toInt() to R.string.ctrl_tint_sky,
|
||||
0xFFE8EEF4.toInt() to R.string.ctrl_tint_white,
|
||||
0xFFC77DFF.toInt() to R.string.ctrl_tint_violet,
|
||||
0xFF3DDC84.toInt() to R.string.ctrl_tint_green,
|
||||
0xFFFFA726.toInt() to R.string.ctrl_tint_amber,
|
||||
0xFFFF5252.toInt() to R.string.ctrl_tint_red,
|
||||
0xFFFF6FB5.toInt() to R.string.ctrl_tint_pink,
|
||||
)
|
||||
|
||||
val opacities = listOf(40, 60, 80, 100)
|
||||
|
||||
val sizes = listOf(80, 90, 100, 110, 125)
|
||||
|
||||
val deadZones = listOf(0, 5, 8, 12, 15, 20, 25)
|
||||
const val DEFAULT_DEAD_ZONE_PERCENT = 12
|
||||
|
||||
@@ -39,20 +24,15 @@ object ControllerPrefs {
|
||||
OFF to R.string.ctrl_target_hidden,
|
||||
)
|
||||
|
||||
/** Settings still read: the rest only seed the one-time library and layout migrations. */
|
||||
class Settings(
|
||||
val tint: Int,
|
||||
val opacity: Int,
|
||||
val size: Int,
|
||||
val stickClick: Boolean,
|
||||
val adaptiveSticks: Boolean,
|
||||
val rumble: Boolean,
|
||||
val steamButton: Boolean,
|
||||
val qamButton: Boolean,
|
||||
val keyboardButton: Boolean,
|
||||
val selectSteam: Boolean,
|
||||
val joyConVr: Boolean,
|
||||
val snap: Boolean,
|
||||
val customLayout: Boolean,
|
||||
val mapping: Map<String, String>,
|
||||
val deadZone: Int,
|
||||
)
|
||||
@@ -63,50 +43,17 @@ object ControllerPrefs {
|
||||
val p = prefs(context)
|
||||
return Settings(
|
||||
tint = p.getInt("tint", STEAM_BLUE),
|
||||
opacity = p.getInt("opacity", 100).takeIf { it in opacities } ?: 100,
|
||||
size = p.getInt("size", 100).takeIf { it in sizes } ?: 100,
|
||||
opacity = p.getInt("opacity", 100).coerceIn(1, 100),
|
||||
stickClick = p.getBoolean("stickClick", true),
|
||||
adaptiveSticks = p.getBoolean("adaptiveSticks", true),
|
||||
rumble = rumbleEnabled(context),
|
||||
steamButton = p.getBoolean("steamButton", true),
|
||||
qamButton = p.getBoolean("qamButton", true),
|
||||
keyboardButton = p.getBoolean("keyboardButton", true),
|
||||
selectSteam = p.getBoolean("selectSteam", false),
|
||||
joyConVr = joyConVr(context),
|
||||
snap = snap(context),
|
||||
customLayout = p.all.keys.any { it.startsWith("layout.") },
|
||||
mapping = mappable.associate { (id, _) -> id to target(context, id) },
|
||||
mapping = mappable.associate { (id, _) -> id to (p.getString("map.$id", id)?.takeIf { t -> targets.any { it.first == t } } ?: id) },
|
||||
deadZone = deadZone(context),
|
||||
)
|
||||
}
|
||||
|
||||
fun target(context: Context, id: String): String =
|
||||
prefs(context).getString("map.$id", id)?.takeIf { t -> targets.any { it.first == t } } ?: id
|
||||
|
||||
fun setTarget(context: Context, id: String, target: String) {
|
||||
prefs(context).edit().putString("map.$id", target).apply()
|
||||
}
|
||||
|
||||
fun setTint(context: Context, tint: Int) {
|
||||
prefs(context).edit().putInt("tint", tint).apply()
|
||||
}
|
||||
|
||||
fun setOpacity(context: Context, percent: Int) {
|
||||
prefs(context).edit().putInt("opacity", percent).apply()
|
||||
}
|
||||
|
||||
fun setSize(context: Context, percent: Int) {
|
||||
prefs(context).edit().putInt("size", percent).apply()
|
||||
}
|
||||
|
||||
fun setStickClick(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("stickClick", on).apply()
|
||||
}
|
||||
|
||||
fun setAdaptiveSticks(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("adaptiveSticks", on).apply()
|
||||
}
|
||||
|
||||
fun rumbleEnabled(context: Context): Boolean = prefs(context).getBoolean("rumble", true)
|
||||
|
||||
fun deadZone(context: Context): Int =
|
||||
@@ -120,18 +67,6 @@ object ControllerPrefs {
|
||||
prefs(context).edit().putBoolean("rumble", on).apply()
|
||||
}
|
||||
|
||||
fun setSteamButton(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("steamButton", on).apply()
|
||||
}
|
||||
|
||||
fun setKeyboardButton(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("keyboardButton", on).apply()
|
||||
}
|
||||
|
||||
fun setSelectSteam(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("selectSteam", on).apply()
|
||||
}
|
||||
|
||||
fun joyConVr(context: Context): Boolean = prefs(context).getBoolean("joyConVr", true)
|
||||
|
||||
fun setJoyConVr(context: Context, on: Boolean) {
|
||||
@@ -144,24 +79,6 @@ object ControllerPrefs {
|
||||
prefs(context).edit().putBoolean("snap", on).apply()
|
||||
}
|
||||
|
||||
fun layout(context: Context, width: Int, height: Int): Map<String, Pair<Float, Float>> {
|
||||
val raw = prefs(context).getString("layout.${width}x$height", null) ?: return emptyMap()
|
||||
return raw.split(';').mapNotNull { entry ->
|
||||
val (group, pos) = entry.split(':').takeIf { it.size == 2 } ?: return@mapNotNull null
|
||||
val (x, y) = pos.split(',').mapNotNull { it.toFloatOrNull() }.takeIf { it.size == 2 } ?: return@mapNotNull null
|
||||
group to (x to y)
|
||||
}.toMap()
|
||||
}
|
||||
|
||||
fun setLayout(context: Context, width: Int, height: Int, positions: Map<String, Pair<Float, Float>>) {
|
||||
val raw = positions.entries.joinToString(";") { (group, pos) -> "$group:${pos.first},${pos.second}" }
|
||||
prefs(context).edit().putString("layout.${width}x$height", raw).apply()
|
||||
}
|
||||
|
||||
fun resetLayout(context: Context, width: Int, height: Int) {
|
||||
prefs(context).edit().remove("layout.${width}x$height").apply()
|
||||
}
|
||||
|
||||
fun resetAll(context: Context) {
|
||||
prefs(context).edit().clear().putBoolean("rumble", true).apply()
|
||||
}
|
||||
|
||||
@@ -125,19 +125,6 @@ object InputLibraries {
|
||||
return InputLibrary(profiles, layouts, bindings, selected).validate()
|
||||
}
|
||||
|
||||
fun setAdaptiveSticks(context: Context, layoutId: String, on: Boolean): Boolean = runCatching {
|
||||
update(context) { library ->
|
||||
library.copy(layouts = library.layouts.map { layout ->
|
||||
if (layout.id != layoutId || !layout.editable) layout
|
||||
else layout.copy(elements = layout.elements.map { if (it.kind == InputElementKind.STICK) it.copy(floating = on, hideWhenIdle = on) else it })
|
||||
})
|
||||
}
|
||||
}.onSuccess { ControllerPrefs.setAdaptiveSticks(context, on) }.isSuccess
|
||||
|
||||
fun setQuickButton(context: Context, layoutId: String, button: InputCommand, shown: Boolean): Boolean = runCatching {
|
||||
update(context) { library -> library.layouts.firstOrNull { it.id == layoutId && it.editable }?.let { library.withLayout(it.withQuickButton(button, shown)) } ?: library }
|
||||
}.isSuccess
|
||||
|
||||
fun defaultPositions(context: Context, library: InputLibrary, layout: SavedInputLayout): Pair<List<InputSurfaceElement>, Float>? {
|
||||
val origin = layout.origin ?: layout.id
|
||||
InputStockLayouts.layouts().firstOrNull { it.id == origin }?.let { return it.elements to it.aspect }
|
||||
@@ -252,13 +239,12 @@ object InputLibraries {
|
||||
|
||||
/** Gamepads saved by the old editor follow the virtual controller's kit again; their positions don't map onto the new controls. */
|
||||
private fun kitGamepads(library: InputLibrary): InputLibrary {
|
||||
var result = library
|
||||
for (layout in library.layouts) {
|
||||
return library.copy(layouts = library.layouts.map { layout ->
|
||||
val origin = layout.origin ?: layout.id
|
||||
if (origin != OVERLAY && !origin.startsWith("migrated.layout.")) continue
|
||||
result = result.withLayout(layout.copy(elements = emptyList(), origin = if (layout.id == OVERLAY) null else OVERLAY, aspect = 0f, scale = 1f))
|
||||
}
|
||||
return result.validate()
|
||||
if (origin != OVERLAY && !origin.startsWith("migrated.layout.")) return@map layout
|
||||
val extras = layout.elements.filterNot { KitLayout.isKit(it.id) }
|
||||
layout.copy(elements = extras, origin = if (layout.id == OVERLAY) null else OVERLAY, aspect = if (extras.isEmpty()) 0f else layout.aspect, scale = 1f)
|
||||
}).validate()
|
||||
}
|
||||
|
||||
private fun migrationBindingId(library: InputLibrary, binding: String, layout: String): String {
|
||||
|
||||
@@ -38,8 +38,13 @@ data class InputSurfaceElement(
|
||||
) {
|
||||
val hasClick get() = kind == InputElementKind.STICK || kind == InputElementKind.TRACKPAD
|
||||
|
||||
fun bounded() = copy(x = x.coerceIn(0f, 0.97f), y = y.coerceIn(0f, 0.97f),
|
||||
width = width.coerceIn(0.03f, (1f - x.coerceIn(0f, 0.97f)).coerceAtLeast(0.03f)), height = height.coerceIn(0.03f, (1f - y.coerceIn(0f, 0.97f)).coerceAtLeast(0.03f)))
|
||||
fun bounded() = copy(x = x.coerceIn(0f, 1f - MIN_SIZE), y = y.coerceIn(0f, 1f - MIN_SIZE),
|
||||
width = width.coerceIn(MIN_SIZE, (1f - x.coerceIn(0f, 1f - MIN_SIZE)).coerceAtLeast(MIN_SIZE)),
|
||||
height = height.coerceIn(MIN_SIZE, (1f - y.coerceIn(0f, 1f - MIN_SIZE)).coerceAtLeast(MIN_SIZE)))
|
||||
|
||||
companion object {
|
||||
const val MIN_SIZE = .01f
|
||||
}
|
||||
}
|
||||
|
||||
internal val QUICK_BUTTONS = listOf(InputCommand.STEAM, InputCommand.QUICK_ACCESS, InputCommand.KEYBOARD)
|
||||
@@ -51,15 +56,31 @@ val InputSurfaceElement.quickButton: InputCommand? get() = when {
|
||||
else -> null
|
||||
}
|
||||
|
||||
internal fun List<InputSurfaceElement>.scaled(factor: Float): List<InputSurfaceElement> = map { e ->
|
||||
/** Controls whose boxes touch, grown by 15%, scale around one shared anchor so a cluster such as the face buttons keeps its shape. */
|
||||
internal fun List<InputSurfaceElement>.scaled(factor: Float): List<InputSurfaceElement> {
|
||||
fun anchor(centre: Float) = when { centre < 1f / 3f -> 0f; centre > 2f / 3f -> 1f; else -> .5f }
|
||||
val w = (e.width * factor).coerceIn(.03f, 1f)
|
||||
val h = (e.height * factor).coerceIn(.03f, 1f)
|
||||
val group = IntArray(size) { it }
|
||||
fun root(i: Int): Int = if (group[i] == i) i else root(group[i]).also { group[i] = it }
|
||||
for (i in indices) for (j in i + 1 until size) {
|
||||
val a = this[i]; val b = this[j]
|
||||
val near = kotlin.math.abs(a.x + a.width / 2 - b.x - b.width / 2) < (a.width + b.width) / 2 * 1.15f &&
|
||||
kotlin.math.abs(a.y + a.height / 2 - b.y - b.height / 2) < (a.height + b.height) / 2 * 1.15f
|
||||
if (near) group[root(i)] = root(j)
|
||||
}
|
||||
val anchors = indices.groupBy(::root).mapValues { (_, members) ->
|
||||
anchor(members.map { this[it].x + this[it].width / 2 }.average().toFloat()) to anchor(members.map { this[it].y + this[it].height / 2 }.average().toFloat())
|
||||
}
|
||||
return mapIndexed { i, e -> e.scaledAround(factor, anchors.getValue(root(i))) }
|
||||
}
|
||||
|
||||
private fun InputSurfaceElement.scaledAround(factor: Float, anchor: Pair<Float, Float>): InputSurfaceElement {
|
||||
val e = this
|
||||
val w = (e.width * factor).coerceIn(InputSurfaceElement.MIN_SIZE, 1f)
|
||||
val h = (e.height * factor).coerceIn(InputSurfaceElement.MIN_SIZE, 1f)
|
||||
val cx = e.x + e.width / 2
|
||||
val cy = e.y + e.height / 2
|
||||
val ax = anchor(cx)
|
||||
val ay = anchor(cy)
|
||||
e.copy(x = (ax + (cx - ax) * factor - w / 2).coerceIn(0f, 1f - w), y = (ay + (cy - ay) * factor - h / 2).coerceIn(0f, 1f - h),
|
||||
val (ax, ay) = anchor
|
||||
return e.copy(x = (ax + (cx - ax) * factor - w / 2).coerceIn(0f, 1f - w), y = (ay + (cy - ay) * factor - h / 2).coerceIn(0f, 1f - h),
|
||||
width = w, height = h).bounded()
|
||||
}
|
||||
|
||||
|
||||
@@ -7,24 +7,36 @@ import kotlin.math.min
|
||||
|
||||
/**
|
||||
* Places a virtual controller's default on-screen controls. Each kit is drawn on a 1600 × 900 reference screen; controls keep
|
||||
* their distance from the nearest edge, so wider screens spread them apart instead of stretching them.
|
||||
* their distance from the nearest edge, so wider screens spread them apart instead of stretching them. Clusters such as the face
|
||||
* buttons are placed by their centre so they move as one. In portrait the whole pad sits along the bottom edge, and the row left of
|
||||
* the bottom edge always starts after DroidDeck's corner button.
|
||||
*/
|
||||
object KitLayout {
|
||||
const val DPAD_ID = "kit:dpad"
|
||||
const val KEYBOARD_ID = "builtin:keyboard"
|
||||
|
||||
/** Whether [id] names one of a kit's own controls rather than a key or control the player added. */
|
||||
fun isKit(id: String) = id.startsWith("legacy:") || id == DPAD_ID || id == KEYBOARD_ID
|
||||
private const val REF_W = 1600f
|
||||
private const val REF_H = 900f
|
||||
private const val PORTRAIT_W = 1200f
|
||||
/** The widest pair of side controls on any kit: a larger size never pushes the two halves, or the rows, into each other. */
|
||||
private const val MIN_SPAN = 1200f
|
||||
private const val MAX_HEIGHT_MM = 80f
|
||||
private const val CORNER_DP = 52f
|
||||
private const val GAP_DP = 8f
|
||||
|
||||
private class Spec(val control: InputControl, val cx: Float, val cy: Float, val hw: Float, val hh: Float = hw, val id: String = "legacy:${control.id}",
|
||||
val kind: InputElementKind = InputElementKind.from(control), val shape: InputButtonShape = InputButtonShape.CIRCLE, val icon: Int = 0, val name: String = control.label)
|
||||
val kind: InputElementKind = InputElementKind.from(control), val shape: InputButtonShape = InputButtonShape.CIRCLE, val icon: Int = 0, val name: String = control.label,
|
||||
val ax: Float = cx, val ay: Float = cy)
|
||||
|
||||
private fun shoulders() = listOf(
|
||||
Spec(InputControl.LT, 140f, 66f, 88f, 34f, shape = InputButtonShape.PILL), Spec(InputControl.LB, 140f, 148f, 88f, 28f, shape = InputButtonShape.PILL),
|
||||
Spec(InputControl.RT, 1460f, 66f, 88f, 34f, shape = InputButtonShape.PILL), Spec(InputControl.RB, 1460f, 148f, 88f, 28f, shape = InputButtonShape.PILL))
|
||||
|
||||
private fun face(cx: Float, cy: Float, r: Float, off: Float) = listOf(
|
||||
Spec(InputControl.Y, cx, cy - off, r), Spec(InputControl.X, cx - off, cy, r), Spec(InputControl.B, cx + off, cy, r), Spec(InputControl.A, cx, cy + off, r))
|
||||
Spec(InputControl.Y, cx, cy - off, r, ax = cx, ay = cy), Spec(InputControl.X, cx - off, cy, r, ax = cx, ay = cy),
|
||||
Spec(InputControl.B, cx + off, cy, r, ax = cx, ay = cy), Spec(InputControl.A, cx, cy + off, r, ax = cx, ay = cy))
|
||||
|
||||
private fun dpad(cx: Float, cy: Float, half: Float) =
|
||||
Spec(InputControl.LS, cx, cy, half, id = DPAD_ID, kind = InputElementKind.DPAD, shape = InputButtonShape.ROUNDED, name = "D-pad")
|
||||
@@ -33,8 +45,8 @@ object KitLayout {
|
||||
|
||||
private fun specs(kit: PadKit): List<Spec> = when {
|
||||
kit.steam -> shoulders() + listOf(
|
||||
Spec(InputControl.L4, 30f, 470f, 30f, 62f, shape = InputButtonShape.ROUNDED), Spec(InputControl.L5, 30f, 590f, 30f, 62f, shape = InputButtonShape.ROUNDED),
|
||||
Spec(InputControl.R4, 1570f, 470f, 30f, 62f, shape = InputButtonShape.ROUNDED), Spec(InputControl.R5, 1570f, 590f, 30f, 62f, shape = InputButtonShape.ROUNDED),
|
||||
Spec(InputControl.L4, 30f, 470f, 30f, 58f, shape = InputButtonShape.ROUNDED), Spec(InputControl.L5, 30f, 590f, 30f, 58f, shape = InputButtonShape.ROUNDED),
|
||||
Spec(InputControl.R4, 1570f, 470f, 30f, 58f, shape = InputButtonShape.ROUNDED), Spec(InputControl.R5, 1570f, 590f, 30f, 58f, shape = InputButtonShape.ROUNDED),
|
||||
dpad(215f, 330f, 100f)) + face(1385f, 330f, 50f, 82f) + listOf(
|
||||
Spec(InputControl.LS, 290f, 610f, 96f), Spec(InputControl.RS, 1310f, 610f, 96f),
|
||||
Spec(InputControl.LEFT_PAD, 480f, 345f, 95f, shape = InputButtonShape.ROUNDED), Spec(InputControl.RIGHT_PAD, 1120f, 345f, 95f, shape = InputButtonShape.ROUNDED),
|
||||
@@ -43,11 +55,11 @@ object KitLayout {
|
||||
keyboard(136f))
|
||||
kit.playStation -> shoulders() + listOf(dpad(250f, 395f, 125f)) + face(1350f, 395f, 56f, 92f) + listOf(
|
||||
Spec(InputControl.LS, 565f, 690f, 100f), Spec(InputControl.RS, 1035f, 690f, 100f),
|
||||
Spec(InputControl.L3, 420f, 790f, 42f), Spec(InputControl.R3, 1180f, 790f, 42f),
|
||||
Spec(InputControl.L3, 430f, 590f, 42f, ax = 565f, ay = 690f), Spec(InputControl.R3, 1170f, 590f, 42f, ax = 1035f, ay = 690f),
|
||||
Spec(InputControl.SELECT, 640f, 150f, 50f, 30f, shape = InputButtonShape.PILL), Spec(InputControl.START, 960f, 150f, 50f, 30f, shape = InputButtonShape.PILL),
|
||||
Spec(InputControl.GUIDE, 800f, 250f, 46f), Spec(InputControl.QAM, 220f, 848f, 46f), keyboard(136f))
|
||||
else -> shoulders() + listOf(Spec(InputControl.LS, 235f, 400f, 104f), dpad(470f, 690f, 118f)) + face(1375f, 400f, 58f, 94f) + listOf(
|
||||
Spec(InputControl.RS, 1130f, 690f, 104f), Spec(InputControl.L3, 385f, 290f, 42f), Spec(InputControl.R3, 1290f, 790f, 42f),
|
||||
else -> shoulders() + listOf(Spec(InputControl.LS, 235f, 400f, 104f), dpad(470f, 675f, 118f)) + face(1375f, 400f, 58f, 94f) + listOf(
|
||||
Spec(InputControl.RS, 1130f, 690f, 104f), Spec(InputControl.L3, 385f, 290f, 42f, ax = 235f, ay = 400f), Spec(InputControl.R3, 1290f, 790f, 42f, ax = 1130f, ay = 690f),
|
||||
Spec(InputControl.SELECT, 690f, 162f, 38f), Spec(InputControl.GUIDE, 800f, 162f, 54f), Spec(InputControl.START, 910f, 162f, 38f),
|
||||
Spec(InputControl.QAM, 220f, 848f, 46f), keyboard(136f))
|
||||
}
|
||||
@@ -56,20 +68,29 @@ object KitLayout {
|
||||
fun elements(context: Context, kit: PadKit, width: Int, height: Int, safe: Rect = Rect(), scale: Float = 1f): List<InputSurfaceElement> {
|
||||
if (width <= 0 || height <= 0) return emptyList()
|
||||
val w = width.toFloat(); val h = height.toFloat()
|
||||
val unit = min(w / REF_W, h / REF_H) * cap(context, min(width, height)) * scale
|
||||
val portrait = height > width
|
||||
val unit = (min(w / if (portrait) PORTRAIT_W else REF_W, h / REF_H) * cap(context, min(width, height)) * scale).coerceAtMost(min(w / MIN_SPAN, h / REF_H))
|
||||
fun x(ref: Float) = when {
|
||||
ref < REF_W / 3f -> safe.left + ref * unit
|
||||
ref > REF_W * 2f / 3f -> w - safe.right - (REF_W - ref) * unit
|
||||
else -> w / 2f + (ref - REF_W / 2f) * unit
|
||||
}
|
||||
fun y(ref: Float) = when {
|
||||
portrait -> h - safe.bottom - (REF_H - ref) * unit
|
||||
ref < REF_H / 3f -> safe.top + ref * unit
|
||||
ref > REF_H * 2f / 3f -> h - safe.bottom - (REF_H - ref) * unit
|
||||
else -> h / 2f + (ref - REF_H / 2f) * unit
|
||||
}
|
||||
return specs(kit).map { s ->
|
||||
val cx = x(s.cx); val cy = y(s.cy); val hw = s.hw * unit; val hh = s.hh * unit
|
||||
InputSurfaceElement(s.control, (cx - hw) / w, (cy - hh) / h, 2 * hw / w, 2 * hh / h, s.id, s.kind, s.name,
|
||||
val density = context.resources.displayMetrics.density
|
||||
var edge = safe.left + CORNER_DP * density
|
||||
val specs = specs(kit)
|
||||
val row = specs.filter { it.cy > REF_H * .88f && it.cx < REF_W / 3f }.sortedBy { it.cx }.associateWith { s ->
|
||||
val hw = s.hw * unit
|
||||
max(x(s.cx), edge + hw).also { edge = it + hw + GAP_DP * density }
|
||||
}
|
||||
return specs.map { s ->
|
||||
val cx = row[s] ?: (x(s.ax) + (s.cx - s.ax) * unit); val cy = y(s.ay) + (s.cy - s.ay) * unit; val hw = s.hw * unit; val hh = s.hh * unit
|
||||
InputSurfaceElement(s.control, (cx - hw) / w, (cy - hh) / h, 2 * hw / w, 2 * hh / h, s.id, s.kind, if (s.name == s.control.label) kit.name(s.control) else s.name,
|
||||
floating = s.kind == InputElementKind.STICK, buttonShape = s.shape, icon = s.icon).bounded()
|
||||
}
|
||||
}
|
||||
@@ -80,7 +101,7 @@ object KitLayout {
|
||||
val boxes = GamepadGeometry.layout(w, h, context.resources.displayMetrics.density, portrait)
|
||||
val placed = mutableListOf<InputSurfaceElement>()
|
||||
fun put(control: InputControl, box: GamepadGeometry.Box?, shape: InputButtonShape, id: String = "legacy:${control.id}",
|
||||
kind: InputElementKind = InputElementKind.from(control), name: String = control.label) {
|
||||
kind: InputElementKind = InputElementKind.from(control), name: String = kit.name(control)) {
|
||||
val b = box ?: return
|
||||
placed += InputSurfaceElement(control, b.left / w, b.top / h, b.width / w, b.height / h, id, kind, name, floating = false, buttonShape = shape).bounded()
|
||||
}
|
||||
|
||||
@@ -62,7 +62,8 @@ class OnScreenControls(context: Context, pad: PadBridge?, val dock: OnScreenLayo
|
||||
}
|
||||
|
||||
private fun render() {
|
||||
surface.updateCustomLayout(if (hidden != null) emptyList() else OnScreenLayout.elements(context, layout, viewWidth, viewHeight, safe, dock))
|
||||
val placed = OnScreenLayout.elements(context, layout, viewWidth, viewHeight, safe, dock)
|
||||
surface.updateCustomLayout(if (hidden != null) placed.filter { it.alwaysShown } else placed)
|
||||
surface.updateStyle(layout?.style ?: InputSurfaceStyle())
|
||||
corner.visibility = if (layout == null || dock != null) GONE else VISIBLE
|
||||
corner.alpha = (layout?.style?.opacity ?: 100) / 100f
|
||||
|
||||
@@ -19,16 +19,21 @@ object OnScreenLayout {
|
||||
}
|
||||
}
|
||||
|
||||
/** The built-in gamepad keeps no positions until it is edited; until then it follows the virtual controller's kit. */
|
||||
fun generated(layout: SavedInputLayout) = layout.elements.isEmpty() && (layout.id == InputLibraries.OVERLAY || layout.origin == InputLibraries.OVERLAY)
|
||||
/**
|
||||
* The built-in gamepad keeps no kit positions until its kit is edited; until then the kit follows the virtual controller and
|
||||
* 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) }
|
||||
|
||||
fun elements(context: Context, layout: SavedInputLayout?, width: Int, height: Int, safe: Rect, dock: Dock? = null): List<InputSurfaceElement> {
|
||||
layout ?: return emptyList()
|
||||
if (width <= 0 || height <= 0) return layout.elements
|
||||
if (generated(layout)) {
|
||||
val kit = PadKit.current(context)
|
||||
return if (dock != null) KitLayout.dock(context, kit, width, height, dock.portrait, dock.left, dock.right)
|
||||
else KitLayout.elements(context, kit, width, height, safe, layout.scale)
|
||||
val extras = if (layout.elements.isEmpty()) emptyList() else fit(layout.elements, aspect(context, layout), 1f, width, height, safe)
|
||||
return (if (dock != null) KitLayout.dock(context, kit, width, height, dock.portrait, dock.left, dock.right)
|
||||
else KitLayout.elements(context, kit, width, height, safe, layout.scale)) + extras
|
||||
}
|
||||
return fit(layout.elements, aspect(context, layout), 1f, width, height, safe)
|
||||
}
|
||||
|
||||
@@ -25,6 +25,15 @@ enum class PadKit(val face: FaceGlyphs, val dpad: DpadStyle, val stick: StickCap
|
||||
else -> control.label
|
||||
}
|
||||
|
||||
/** What the player calls [control] on this controller. */
|
||||
fun name(control: InputControl): String = if (!playStation) label(control) else when (control) {
|
||||
InputControl.A -> "Cross"
|
||||
InputControl.B -> "Circle"
|
||||
InputControl.X -> "Square"
|
||||
InputControl.Y -> "Triangle"
|
||||
else -> label(control)
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun of(type: String) = when (type) {
|
||||
SessionPrefs.CONTROLLER_STEAM -> STEAM_CONTROLLER
|
||||
|
||||
@@ -379,15 +379,6 @@ class SteamTouchControls(
|
||||
for (i in -1..1) canvas.drawCircle(x + i * r * 0.3f, y + r * 0.22f, r * 0.08f, p)
|
||||
}
|
||||
|
||||
private fun drawKeyboardGlyph(canvas: Canvas, x: Float, y: Float, r: Float, color: Int) {
|
||||
val p = Paint(Paint.ANTI_ALIAS_FLAG).apply { this.color = color; style = Paint.Style.STROKE; strokeWidth = lineWidth() * 0.8f }
|
||||
val body = RectF(x - r * 0.6f, y - r * 0.34f, x + r * 0.6f, y + r * 0.34f)
|
||||
canvas.drawRoundRect(body, r * 0.08f, r * 0.08f, p)
|
||||
val dot = Paint(Paint.ANTI_ALIAS_FLAG).apply { this.color = color }
|
||||
for (row in 0..1) for (i in 0..5) canvas.drawCircle(body.left + r * 0.15f + i * r * 0.18f, body.top + r * 0.18f + row * r * 0.17f, r * 0.035f, dot)
|
||||
canvas.drawLine(x - r * 0.3f, body.bottom - r * 0.14f, x + r * 0.3f, body.bottom - r * 0.14f, p)
|
||||
}
|
||||
|
||||
private val iconsLoading = HashSet<String>()
|
||||
|
||||
private val inkedIcons = android.util.LruCache<String, android.graphics.Bitmap>(48)
|
||||
@@ -1494,11 +1485,5 @@ class SteamTouchControls(
|
||||
put(SteamTouchConfig.PASTE, 0L)
|
||||
}
|
||||
|
||||
private val LABEL_COLORS = mapOf(
|
||||
SteamTouchConfig.A to Color.rgb(72, 133, 48),
|
||||
SteamTouchConfig.B to Color.rgb(211, 68, 37),
|
||||
SteamTouchConfig.X to Color.rgb(23, 60, 184),
|
||||
SteamTouchConfig.Y to Color.rgb(235, 200, 70),
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user