mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 21:06:09 +00:00
fix(dual-screen): tap-only In-game stats styles; Automatic leaves DiRT 3 and Showdown off
- The Layout row is gone; tapping the top strip or the dash changes its style, and one line under the page says so. - DiRT 3 and DiRT Showdown can stop at the end of a race with WinSock error 10038 while their UDP output is on (a known game bug; the community workaround by RoccoC/DiRTTelemetryErrorFix intercepts that error). Automatic now leaves those two off and puts back one it had switched on; their switch says why, and turning it on by hand is remembered. - A switch locked while its game runs keeps its on colours instead of looking off. - The Circuit dash hides the fuel and tyre cards when the game sends neither (DiRT Showdown).
This commit is contained in:
1 parent
5be04466af
commit
66abf0c707
7 files changed
+77
-86
No files matched your search
@@ -132,6 +132,13 @@ object SessionPrefs {
|
||||
prefs(context).edit().putStringSet("telemetryOff", keys.toSet()).apply()
|
||||
}
|
||||
|
||||
/** Games the user switched on by hand, as TelemetryOutput keys; Automatic keeps them on. */
|
||||
fun telemetryOnByHand(context: Context): Set<String> = prefs(context).getStringSet("telemetryOnByHand", null)?.toSet().orEmpty()
|
||||
|
||||
fun setTelemetryOnByHand(context: Context, keys: Set<String>) {
|
||||
prefs(context).edit().putStringSet("telemetryOnByHand", keys.toSet()).apply()
|
||||
}
|
||||
|
||||
fun dualScreenLauncher(context: Context): Boolean = prefs(context).getBoolean("dualScreenLauncher", true)
|
||||
|
||||
fun setDualScreenLauncher(context: Context, on: Boolean) {
|
||||
|
||||
@@ -26,7 +26,7 @@ object SettingsReset {
|
||||
"upscaler", "upscaleSharpness", "screenEffects", "textureAnisotropy", "textureLodBias",
|
||||
"steamDownloadsInBackground", "steam_offline", "bootMovie", "bootMovieSound", "bootMovieVolume", "bootMovieSeconds",
|
||||
"bootMovieApplyNext", "bootMovieSteamSeen",
|
||||
"questDefaultsV1", "telemetryAuto", "telemetryOff", "statsStrip", "statsDash",
|
||||
"questDefaultsV1", "telemetryAuto", "telemetryOff", "telemetryOnByHand", "statsStrip", "statsDash",
|
||||
)
|
||||
|
||||
internal val SESSION_PREFIXES = listOf(
|
||||
|
||||
@@ -10,7 +10,10 @@ import java.io.File
|
||||
* In-game stats listener; the file as it was is kept beside it, and its element is put back when turned off.
|
||||
*/
|
||||
object TelemetryOutput {
|
||||
data class Game(val name: String, val prefixId: String, val file: File, val on: Boolean)
|
||||
data class Game(val name: String, val prefixId: String, val file: File, val on: Boolean) {
|
||||
/** DiRT 3 and DiRT Showdown can stop at the end of a race with WinSock error 10038 while this output is on. */
|
||||
val raceEndCrash: Boolean get() = name.lowercase().replace(" ", "") in RACE_END_CRASH
|
||||
}
|
||||
|
||||
data class MenuGame(val name: String, val setting: String, val port: Int)
|
||||
|
||||
@@ -28,6 +31,7 @@ object TelemetryOutput {
|
||||
private const val ADDRESS = "127.0.0.1"
|
||||
private const val EXTRADATA = "3"
|
||||
private val TAGS = listOf("udp", "motion")
|
||||
private val RACE_END_CRASH = setOf("dirtshowdown", "dirt3")
|
||||
// Byte-for-byte: every byte maps to one char and back, whatever the file's own encoding is.
|
||||
private val BYTES = Charsets.ISO_8859_1
|
||||
|
||||
@@ -62,16 +66,24 @@ object TelemetryOutput {
|
||||
true
|
||||
}.getOrDefault(false)
|
||||
|
||||
/** Automatic: turns the output on for every found game the user has not switched off and that is not running. */
|
||||
/**
|
||||
* Automatic: turns the output on for every found game the user has not switched off and that is not running.
|
||||
* Games with the race-end crash are left to the user, and ones Automatic switched on go back to their own setting.
|
||||
*/
|
||||
fun applyAutomatic(context: Context, running: String?) {
|
||||
if (!SessionPrefs.telemetryAuto(context)) return
|
||||
automaticTargets(scan(Library.compatdataDirs(context)), SessionPrefs.telemetryOff(context), running).forEach { set(it, true) }
|
||||
val games = scan(Library.compatdataDirs(context))
|
||||
automaticTargets(games, SessionPrefs.telemetryOff(context), running).forEach { set(it, true) }
|
||||
automaticRestores(games, SessionPrefs.telemetryOnByHand(context), running).forEach { set(it, false) }
|
||||
}
|
||||
|
||||
internal fun key(game: Game) = "${game.prefixId}/${game.name}"
|
||||
|
||||
internal fun automaticTargets(games: List<Game>, off: Set<String>, running: String?): List<Game> =
|
||||
games.filter { !it.on && key(it) !in off && !isRunning(it.prefixId, running) }
|
||||
games.filter { !it.on && !it.raceEndCrash && key(it) !in off && !isRunning(it.prefixId, running) }
|
||||
|
||||
internal fun automaticRestores(games: List<Game>, onByHand: Set<String>, running: String?): List<Game> =
|
||||
games.filter { it.raceEndCrash && it.on && key(it) !in onByHand && File(it.file.path + ORIGINAL_SUFFIX).isFile && !isRunning(it.prefixId, running) }
|
||||
|
||||
/** Games DroidDeck changed, which go back to their own setting when Automatic is switched off. */
|
||||
internal fun restoreTargets(games: List<Game>, running: String?): List<Game> =
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.horizontalScroll
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
@@ -20,6 +17,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.SwitchDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
@@ -273,12 +271,18 @@ fun BottomTelemetryPage(fps: () -> Float?, runningGame: () -> String? = { null }
|
||||
}
|
||||
for (game in outputs) {
|
||||
val locked = TelemetryOutput.isRunning(game.prefixId, running)
|
||||
SwitchRow(game.name, if (locked) stringResource(R.string.bottom_telemetry_send_close, game.name) else null, game.on, !locked) { want ->
|
||||
val hint = listOfNotNull(
|
||||
if (locked) stringResource(R.string.bottom_telemetry_send_close, game.name) else null,
|
||||
if (game.raceEndCrash) stringResource(R.string.bottom_telemetry_send_crash) else null,
|
||||
).joinToString("\n").ifEmpty { null }
|
||||
SwitchRow(game.name, hint, game.on, !locked) { want ->
|
||||
scope.launch {
|
||||
val ok = withContext(Dispatchers.IO) {
|
||||
val key = TelemetryOutput.key(game)
|
||||
val off = SessionPrefs.telemetryOff(context)
|
||||
val byHand = SessionPrefs.telemetryOnByHand(context)
|
||||
SessionPrefs.setTelemetryOff(context, if (want) off - key else off + key)
|
||||
SessionPrefs.setTelemetryOnByHand(context, if (want) byHand + key else byHand - key)
|
||||
TelemetryOutput.set(game, want)
|
||||
}
|
||||
outputFailed = if (ok) null else game.name
|
||||
@@ -300,54 +304,7 @@ fun BottomTelemetryPage(fps: () -> Float?, runningGame: () -> String? = { null }
|
||||
Text(stringResource(R.string.bottom_telemetry_port_busy, busyPorts.sorted().joinToString()), fontSize = 13.sp,
|
||||
color = colors.error, modifier = Modifier.padding(horizontal = 4.dp))
|
||||
}
|
||||
LayoutPicker(strip, dash,
|
||||
onStrip = { strip = it; SessionPrefs.setStatsStrip(context, it.id) },
|
||||
onDash = { dash = it; SessionPrefs.setStatsDash(context, it.id) })
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LayoutPicker(strip: StatsStrip, dash: StatsDash, onStrip: (StatsStrip) -> Unit, onDash: (StatsDash) -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
TelemetryCard(stringResource(R.string.stats_layout)) {
|
||||
PickRow(stringResource(R.string.stats_layout_top), StatsStrip.entries.map { it to stringResource(stripLabel(it)) }, strip, onStrip)
|
||||
PickRow(stringResource(R.string.stats_layout_dash), StatsDash.entries.map { it to stringResource(dashLabel(it)) }, dash, onDash)
|
||||
Text(stringResource(R.string.stats_layout_hint), fontSize = 12.sp, color = colors.onSurfaceVariant)
|
||||
}
|
||||
}
|
||||
|
||||
private fun stripLabel(s: StatsStrip): Int = when (s) {
|
||||
StatsStrip.PANEL -> R.string.stats_strip_panel
|
||||
StatsStrip.TILES -> R.string.stats_strip_tiles
|
||||
StatsStrip.RINGS -> R.string.stats_strip_rings
|
||||
}
|
||||
|
||||
private fun dashLabel(d: StatsDash): Int = when (d) {
|
||||
StatsDash.AUTO -> R.string.stats_dash_auto
|
||||
StatsDash.SPEEDOMETER -> R.string.stats_dash_speedometer
|
||||
StatsDash.CIRCUIT -> R.string.stats_dash_circuit
|
||||
StatsDash.TRACE -> R.string.stats_dash_trace
|
||||
StatsDash.DIALS -> R.string.stats_dash_dials
|
||||
StatsDash.GLANCE -> R.string.stats_dash_glance
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun <T> PickRow(title: String, options: List<Pair<T, String>>, selected: T, onPick: (T) -> Unit) {
|
||||
val pal = LocalPalette.current
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val shape = RoundedCornerShape(50)
|
||||
Row(Modifier.fillMaxWidth().horizontalScroll(rememberScrollState()), verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
Text(title, fontSize = 13.sp, color = colors.onSurfaceVariant, modifier = Modifier.width(44.dp))
|
||||
for ((value, label) in options) {
|
||||
val on = value == selected
|
||||
Text(label, fontSize = 13.sp, fontWeight = if (on) FontWeight.Bold else FontWeight.Normal,
|
||||
color = if (on) colors.background else colors.onBackground, maxLines = 1,
|
||||
modifier = Modifier.clip(shape).background(if (on) pal.primary else Color.Transparent)
|
||||
.border(1.dp, if (on) pal.primary else pal.line, shape)
|
||||
.clickable { onPick(value) }
|
||||
.padding(horizontal = 12.dp, vertical = 6.dp))
|
||||
}
|
||||
Text(stringResource(R.string.stats_tap_hint), fontSize = 12.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(horizontal = 4.dp))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,7 +331,12 @@ private fun SwitchRow(title: String, hint: String?, checked: Boolean, enabled: B
|
||||
Text(title, fontSize = 15.sp, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
if (hint != null) Text(hint, fontSize = 12.sp, color = colors.onSurfaceVariant)
|
||||
}
|
||||
Switch(checked, null, enabled = enabled)
|
||||
val pal = LocalPalette.current
|
||||
Switch(checked, null, enabled = enabled, colors = SwitchDefaults.colors(
|
||||
disabledCheckedTrackColor = pal.primary.copy(alpha = 0.45f),
|
||||
disabledCheckedThumbColor = colors.background,
|
||||
disabledCheckedBorderColor = pal.primary.copy(alpha = 0.45f),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -240,17 +240,14 @@ private fun CircuitDash(t: Telemetry) {
|
||||
fontSize = 12.sp, fontFamily = FontFamily.Monospace, color = colors.onSurfaceVariant)
|
||||
}
|
||||
}
|
||||
Column(Modifier.weight(0.9f).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
StatsCard(stringResource(R.string.bottom_telemetry_fuel), Modifier.fillMaxWidth().weight(1f)) {
|
||||
val fuel = t.fuel
|
||||
if (fuel != null) {
|
||||
Bar(fuel, colors.onBackground, Modifier.fillMaxWidth().height(14.dp))
|
||||
Text("${(fuel * 100).roundToInt()}%", fontSize = 13.sp, fontFamily = FontFamily.Monospace, color = colors.onSurfaceVariant)
|
||||
} else Text("–", fontSize = 13.sp, color = colors.onSurfaceVariant)
|
||||
}
|
||||
t.tireTempsC?.takeIf { it.size == 4 }?.let { tires ->
|
||||
StatsCard(stringResource(R.string.stats_tires), Modifier.fillMaxWidth().weight(1.3f)) { Tires(tires, Modifier.fillMaxWidth().weight(1f)) }
|
||||
val fuel = t.fuel
|
||||
val tires = t.tireTempsC?.takeIf { it.size == 4 }
|
||||
if (fuel != null || tires != null) Column(Modifier.weight(0.9f).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
if (fuel != null) StatsCard(stringResource(R.string.bottom_telemetry_fuel), Modifier.fillMaxWidth().weight(1f)) {
|
||||
Bar(fuel, colors.onBackground, Modifier.fillMaxWidth().height(14.dp))
|
||||
Text("${(fuel * 100).roundToInt()}%", fontSize = 13.sp, fontFamily = FontFamily.Monospace, color = colors.onSurfaceVariant)
|
||||
}
|
||||
if (tires != null) StatsCard(stringResource(R.string.stats_tires), Modifier.fillMaxWidth().weight(1.3f)) { Tires(tires, Modifier.fillMaxWidth().weight(1f)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1915,19 +1915,8 @@
|
||||
<string name="stats_fuel_t">Fuel, t</string>
|
||||
<string name="stats_fuel_main">Main %1$s t</string>
|
||||
<string name="stats_fuel_reserve">Reserve %1$s t</string>
|
||||
<string name="stats_layout">Layout</string>
|
||||
<string name="stats_layout_top">Top</string>
|
||||
<string name="stats_layout_dash">Dash</string>
|
||||
<string name="stats_layout_hint">Tapping the top strip or the dash also switches to the next style.</string>
|
||||
<string name="stats_strip_panel">Panel</string>
|
||||
<string name="stats_strip_tiles">Tiles</string>
|
||||
<string name="stats_strip_rings">Rings</string>
|
||||
<string name="stats_dash_auto">Auto</string>
|
||||
<string name="stats_dash_speedometer">Speedometer</string>
|
||||
<string name="stats_dash_circuit">Circuit</string>
|
||||
<string name="stats_dash_trace">Trace</string>
|
||||
<string name="stats_dash_dials">Dials</string>
|
||||
<string name="stats_dash_glance">Glance</string>
|
||||
<string name="stats_tap_hint">Tap the top strip or the dash to change its style.</string>
|
||||
<string name="bottom_telemetry_send_crash">This game can stop at the end of a race while this is on, so Automatic leaves it off.</string>
|
||||
<string name="bottom_telemetry_send_title">Send dashboard data</string>
|
||||
<string name="bottom_telemetry_send_auto">Automatic</string>
|
||||
<string name="bottom_telemetry_send_auto_hint">Turns it on for every game listed here, including games found later. Games you switch off stay off.</string>
|
||||
|
||||
@@ -79,13 +79,13 @@ class TelemetryOutputTest {
|
||||
|
||||
@Test fun automaticSkipsGamesThatAreOnSwitchedOffOrRunning() {
|
||||
val f = File("x")
|
||||
val showdownGame = TelemetryOutput.Game("DiRT Showdown", "2848447563", f, on = false)
|
||||
val dirt4 = TelemetryOutput.Game("DiRT 4", "421020", f, on = false)
|
||||
val rally = TelemetryOutput.Game("DiRT Rally 2.0", "690790", f, on = false)
|
||||
val grid = TelemetryOutput.Game("GRID", "703860", f, on = true)
|
||||
val games = listOf(showdownGame, rally, grid)
|
||||
assertEquals(listOf(showdownGame, rally), TelemetryOutput.automaticTargets(games, emptySet(), null))
|
||||
assertEquals(listOf(rally), TelemetryOutput.automaticTargets(games, setOf("2848447563/DiRT Showdown"), null))
|
||||
assertEquals(listOf(showdownGame), TelemetryOutput.automaticTargets(games, emptySet(), "690790"))
|
||||
val games = listOf(dirt4, rally, grid)
|
||||
assertEquals(listOf(dirt4, rally), TelemetryOutput.automaticTargets(games, emptySet(), null))
|
||||
assertEquals(listOf(rally), TelemetryOutput.automaticTargets(games, setOf("421020/DiRT 4"), null))
|
||||
assertEquals(listOf(dirt4), TelemetryOutput.automaticTargets(games, emptySet(), "690790"))
|
||||
assertEquals("690790/DiRT Rally 2.0", TelemetryOutput.key(rally))
|
||||
}
|
||||
|
||||
@@ -101,6 +101,30 @@ class TelemetryOutputTest {
|
||||
assertTrue(TelemetryOutput.restoreTargets(TelemetryOutput.scan(listOf(compatdata)), "2848447563").isEmpty())
|
||||
}
|
||||
|
||||
@Test fun automaticLeavesTheRaceEndCrashGamesToTheUser() {
|
||||
val f = File("x")
|
||||
val showdownGame = TelemetryOutput.Game("DiRT Showdown", "2848447563", f, on = false)
|
||||
val dirt3 = TelemetryOutput.Game("DiRT3", "321040", f, on = false)
|
||||
val rally = TelemetryOutput.Game("DiRT Rally 2.0", "690790", f, on = false)
|
||||
assertTrue(showdownGame.raceEndCrash)
|
||||
assertTrue(dirt3.raceEndCrash)
|
||||
assertFalse(rally.raceEndCrash)
|
||||
assertEquals(listOf(rally), TelemetryOutput.automaticTargets(listOf(showdownGame, dirt3, rally), emptySet(), null))
|
||||
}
|
||||
|
||||
@Test fun automaticPutsBackAShowdownItSwitchedOnButNotOneTheUserDid() {
|
||||
val compatdata = tmp.newFolder("steamapps", "compatdata")
|
||||
val config = configFile(compatdata, "2848447563", "DiRT Showdown").apply { writeText(showdown) }
|
||||
val game = TelemetryOutput.scan(listOf(compatdata)).single()
|
||||
assertTrue(TelemetryOutput.set(game, true))
|
||||
val on = TelemetryOutput.scan(listOf(compatdata))
|
||||
assertEquals(on, TelemetryOutput.automaticRestores(on, emptySet(), null))
|
||||
assertTrue(TelemetryOutput.automaticRestores(on, setOf("2848447563/DiRT Showdown"), null).isEmpty())
|
||||
assertTrue(TelemetryOutput.automaticRestores(on, emptySet(), "2848447563").isEmpty())
|
||||
on.forEach { TelemetryOutput.set(it, false) }
|
||||
assertEquals(showdown, config.readText())
|
||||
}
|
||||
|
||||
private fun configFile(compatdata: File, id: String, game: String): File =
|
||||
File(compatdata, "$id/pfx/drive_c/users/steamuser/Documents/My Games/$game/hardwaresettings/hardware_settings_config.xml")
|
||||
.apply { parentFile!!.mkdirs() }
|
||||
|
||||
Reference in new issue
Block a user