mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 06:15:58 +00:00
feat: add persistent per-game compatibility profiles (#449)
* feat(profiles): add persistent per-game compatibility profiles * fix(profiles): show Windows component overrides Include per-game Windows component selections in the resolved profile summary so the session overlay marks those games as custom and shows the selected components. * fix(session): detect Proton games across runtime paths * fix(profiles): select the active Gamescope game * fix(profiles): improve per-game reset feedback * fix(profiles): align session components with game overrides * fix(session): prefer selected Steam game during refresh * fix(session): resume profile following when reopening games * chore: keep local dev testing outside the repository * test(session): remove local dev package path * fix(session): preserve profiles when refresh fails * fix(session): reject empty game profile reset scope * perf(session): cache drawer inventory by refresh revision * fix(profiles): align game presets and profile reset behavior * fix(profiles): preserve originals and normalize shortcut ids * fix(profiles): keep editor scope stable after rebase * fix(tests): host Compose tests in both build variants * fix(profiles): recover interrupted component selection saves --------- Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
1 parent
78fcb60fd5
commit
435beb7f19
46 files changed
+3501
-150
No files matched your search
@@ -37,6 +37,7 @@ import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Delete
|
||||
import androidx.compose.material.icons.outlined.Refresh
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@@ -80,6 +81,19 @@ import com.droiddeck.launcher.session.ComponentsManager
|
||||
import com.droiddeck.launcher.session.ComponentsManager.CatalogItem
|
||||
import com.droiddeck.launcher.session.ComponentsManager.Snapshot
|
||||
import kotlinx.coroutines.delay
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import com.droiddeck.launcher.core.FexPreset
|
||||
import com.droiddeck.launcher.core.GameEnvironment
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import com.droiddeck.launcher.session.GameEnvironmentStore
|
||||
import com.droiddeck.launcher.session.GameProfileManager
|
||||
import com.droiddeck.launcher.session.ProtonDefault
|
||||
import com.droiddeck.launcher.session.WinComponents
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.text.DateFormat
|
||||
import java.util.Date
|
||||
|
||||
@@ -108,6 +122,13 @@ private class InstalledItem(
|
||||
val protonVersion: String?,
|
||||
)
|
||||
|
||||
private data class ProfileEditorState(
|
||||
val environment: GameEnvironment.Config,
|
||||
val protonChoice: ProtonDefault.GameChoice?,
|
||||
val protonId: String?,
|
||||
val components: Map<String, String>,
|
||||
)
|
||||
|
||||
private val GOLD = Color(0xFFF2C66D)
|
||||
private val QUEUED = Color(0xFFFFB86B)
|
||||
private val ROW_SHAPE = RoundedCornerShape(10.dp)
|
||||
@@ -142,6 +163,9 @@ fun ComponentsPage(
|
||||
onRefresh: () -> Unit,
|
||||
onImport: () -> Unit,
|
||||
onBack: () -> Unit,
|
||||
games: List<Library.SteamGame> = emptyList(),
|
||||
generalFexPreset: String = "",
|
||||
onGeneralFexPreset: (String) -> Unit = {},
|
||||
requestInitialFocus: Boolean = true,
|
||||
/** The GPU drivers layer ([GPU_TAB]): what it shows and does. */
|
||||
gpu: GpuDriversState = GpuDriversState(),
|
||||
@@ -160,6 +184,209 @@ fun ComponentsPage(
|
||||
val inputMode = LocalInputModeManager.current
|
||||
val layer = if (comp in LAYERS) comp else GPU_TAB
|
||||
BackHandler(onBack = onBack)
|
||||
var scopeMenu by remember { mutableStateOf(false) }
|
||||
var selectedGameKey by remember { mutableStateOf<String?>(null) }
|
||||
var fexMenu by remember { mutableStateOf(false) }
|
||||
var gameProtonMenu by remember { mutableStateOf(false) }
|
||||
var gameProtonId by remember { mutableStateOf<String?>(null) }
|
||||
var gameProtonChoice by remember { mutableStateOf<ProtonDefault.GameChoice?>(null) }
|
||||
var gameComponents by remember { mutableStateOf<Map<String, String>>(emptyMap()) }
|
||||
var gameComponentMenu by remember { mutableStateOf<String?>(null) }
|
||||
var environmentEditor by remember { mutableStateOf(false) }
|
||||
var winComponentsOpen by remember { mutableStateOf<Boolean?>(null) }
|
||||
var winComponentsRevision by remember { mutableStateOf(0) }
|
||||
var environment by remember { mutableStateOf<GameEnvironment.Config?>(null) }
|
||||
var profileLoading by remember { mutableStateOf(false) }
|
||||
var profileLoadGeneration by remember { mutableStateOf(0L) }
|
||||
var environmentBusy by remember { mutableStateOf(false) }
|
||||
var environmentError by remember { mutableStateOf(false) }
|
||||
var profileNotice by remember { mutableStateOf<String?>(null) }
|
||||
var confirm by remember { mutableStateOf<Pair<String, () -> Unit>?>(null) }
|
||||
var confirmTitle by remember { mutableStateOf("") }
|
||||
var confirmVerb by remember { mutableStateOf(R.string.comp_swap) }
|
||||
fun ask(title: String, body: String, verb: Int, action: () -> Unit) {
|
||||
confirmTitle = title
|
||||
confirmVerb = verb
|
||||
confirm = body to action
|
||||
}
|
||||
val coroutine = rememberCoroutineScope()
|
||||
val selectedGame = games.firstOrNull { it.profileKey == selectedGameKey }
|
||||
LaunchedEffect(Unit) {
|
||||
runCatching { withContext(Dispatchers.IO) { GameEnvironmentStore.read(ctx) } }
|
||||
.onSuccess { environment = it }
|
||||
.onFailure { environmentError = true }
|
||||
}
|
||||
LaunchedEffect(games, selectedGameKey) {
|
||||
if (selectedGameKey != null && games.none { it.profileKey == selectedGameKey }) selectedGameKey = null
|
||||
}
|
||||
LaunchedEffect(selectedGame?.profileKey, snapshot) {
|
||||
profileLoadGeneration++
|
||||
val generation = profileLoadGeneration
|
||||
val game = selectedGame
|
||||
profileNotice = null
|
||||
environmentError = false
|
||||
gameProtonChoice = null
|
||||
gameProtonId = null
|
||||
gameComponents = emptyMap()
|
||||
gameProtonMenu = false
|
||||
gameComponentMenu = null
|
||||
fexMenu = false
|
||||
if (game == null) {
|
||||
profileLoading = false
|
||||
return@LaunchedEffect
|
||||
}
|
||||
profileLoading = true
|
||||
try {
|
||||
val (choice, id, components) = withContext(Dispatchers.IO) {
|
||||
val choice = ProtonDefault.gameChoice(ctx, game.profileKey)
|
||||
Triple(
|
||||
choice,
|
||||
ProtonDefault.gameSelectedId(ctx, game.profileKey, snapshot?.protons.orEmpty().map { it.proton }),
|
||||
ComponentsManager.gameComponents(ctx, game.profileKey),
|
||||
)
|
||||
}
|
||||
if (profileLoadGeneration == generation && selectedGameKey == game.profileKey) {
|
||||
gameProtonChoice = choice
|
||||
gameProtonId = id
|
||||
gameComponents = components
|
||||
}
|
||||
} catch (error: CancellationException) {
|
||||
throw error
|
||||
} catch (error: Exception) {
|
||||
if (profileLoadGeneration == generation && selectedGameKey == game.profileKey) {
|
||||
environmentError = true
|
||||
profileNotice = ctx.getString(
|
||||
R.string.comp_game_load_failed,
|
||||
game.name,
|
||||
error.message ?: error.javaClass.simpleName,
|
||||
)
|
||||
}
|
||||
} finally {
|
||||
if (profileLoadGeneration == generation) profileLoading = false
|
||||
}
|
||||
}
|
||||
fun setGameFexPreset(preset: String?) {
|
||||
val game = selectedGame ?: return
|
||||
environmentBusy = true
|
||||
profileNotice = null
|
||||
coroutine.launch {
|
||||
runCatching {
|
||||
withContext(Dispatchers.IO) {
|
||||
GameEnvironmentStore.setGameFexPreset(ctx, game.profileKey, preset)
|
||||
}
|
||||
}.onSuccess { saved ->
|
||||
environment = saved
|
||||
if (selectedGameKey == game.profileKey) {
|
||||
environmentError = false
|
||||
profileNotice = ctx.getString(R.string.comp_game_saved_next, game.name)
|
||||
}
|
||||
}.onFailure {
|
||||
if (selectedGameKey == game.profileKey) {
|
||||
environmentError = true
|
||||
profileNotice = ctx.getString(R.string.comp_game_save_failed, it.message ?: it.javaClass.simpleName)
|
||||
}
|
||||
}
|
||||
environmentBusy = false
|
||||
}
|
||||
}
|
||||
fun setGameProton(id: String?) {
|
||||
val game = selectedGame ?: return
|
||||
val proton = id?.let { wanted -> snapshot?.protons?.firstOrNull { it.proton.id == wanted }?.proton }
|
||||
environmentBusy = true
|
||||
profileNotice = null
|
||||
coroutine.launch {
|
||||
runCatching { withContext(Dispatchers.IO) { ProtonDefault.requestGame(ctx, game.profileKey, proton) } }
|
||||
.onSuccess { outcome ->
|
||||
if (selectedGameKey == game.profileKey) {
|
||||
gameProtonChoice = proton?.let { ProtonDefault.GameChoice(it.valve, it.dir.name) }
|
||||
gameProtonId = id
|
||||
environmentError = false
|
||||
profileNotice = ctx.getString(
|
||||
when (outcome) {
|
||||
ProtonDefault.Outcome.LIVE -> R.string.comp_game_proton_live
|
||||
ProtonDefault.Outcome.NEXT_START -> R.string.comp_game_proton_next
|
||||
ProtonDefault.Outcome.NOT_RUNNABLE -> R.string.comp_game_proton_not_runnable
|
||||
},
|
||||
game.name,
|
||||
)
|
||||
}
|
||||
}
|
||||
.onFailure {
|
||||
if (selectedGameKey == game.profileKey) {
|
||||
environmentError = true
|
||||
profileNotice = ctx.getString(R.string.comp_game_save_failed, it.message ?: it.javaClass.simpleName)
|
||||
}
|
||||
}
|
||||
environmentBusy = false
|
||||
}
|
||||
}
|
||||
fun setGameComponent(comp: String, file: String?) {
|
||||
val game = selectedGame ?: return
|
||||
environmentBusy = true
|
||||
profileNotice = null
|
||||
coroutine.launch {
|
||||
runCatching { withContext(Dispatchers.IO) { ComponentsManager.setGameComponent(ctx, game.profileKey, comp, file) } }
|
||||
.onSuccess {
|
||||
val components = ComponentsManager.gameComponents(ctx, game.profileKey)
|
||||
if (selectedGameKey == game.profileKey) {
|
||||
gameComponents = components
|
||||
environmentError = false
|
||||
profileNotice = ctx.getString(R.string.comp_game_saved_next, game.name)
|
||||
}
|
||||
}
|
||||
.onFailure {
|
||||
if (selectedGameKey == game.profileKey) {
|
||||
environmentError = true
|
||||
profileNotice = ctx.getString(R.string.comp_game_save_failed, it.message ?: it.javaClass.simpleName)
|
||||
}
|
||||
}
|
||||
environmentBusy = false
|
||||
}
|
||||
}
|
||||
fun resetGameProfile() {
|
||||
val game = selectedGame ?: return
|
||||
environmentBusy = true
|
||||
profileNotice = null
|
||||
coroutine.launch {
|
||||
runCatching {
|
||||
withContext(Dispatchers.IO) {
|
||||
val resetFailure = runCatching { GameProfileManager.reset(ctx, game.profileKey) }.exceptionOrNull()
|
||||
val config = GameEnvironmentStore.read(ctx)
|
||||
val choice = ProtonDefault.gameChoice(ctx, game.profileKey)
|
||||
val id = ProtonDefault.gameSelectedId(
|
||||
ctx,
|
||||
game.profileKey,
|
||||
snapshot?.protons.orEmpty().map { it.proton },
|
||||
)
|
||||
val components = ComponentsManager.gameComponents(ctx, game.profileKey)
|
||||
ProfileEditorState(config, choice, id, components) to resetFailure
|
||||
}
|
||||
}.onSuccess { (state, resetFailure) ->
|
||||
environment = state.environment
|
||||
if (selectedGameKey == game.profileKey) {
|
||||
gameProtonChoice = state.protonChoice
|
||||
gameProtonId = state.protonId
|
||||
gameComponents = state.components
|
||||
winComponentsRevision++
|
||||
environmentError = resetFailure != null
|
||||
profileNotice = if (resetFailure == null) {
|
||||
ctx.getString(R.string.comp_game_reset_done, game.name)
|
||||
} else {
|
||||
ctx.getString(
|
||||
R.string.comp_game_reset_failed,
|
||||
resetFailure.message ?: resetFailure.javaClass.simpleName,
|
||||
)
|
||||
}
|
||||
}
|
||||
}.onFailure {
|
||||
if (selectedGameKey == game.profileKey) {
|
||||
environmentError = true
|
||||
profileNotice = ctx.getString(R.string.comp_game_reset_failed, it.message ?: it.javaClass.simpleName)
|
||||
}
|
||||
}
|
||||
environmentBusy = false
|
||||
}
|
||||
}
|
||||
|
||||
val views = snapshot?.protons ?: emptyList()
|
||||
val view = views.firstOrNull { it.proton.id == protonId } ?: views.firstOrNull()
|
||||
@@ -247,7 +474,7 @@ fun ComponentsPage(
|
||||
val layerFocus = remember { LAYERS.associateWith { FocusRequester() } }
|
||||
// Arrived (from the rail, a hop, a game's card): a pad starts on the chosen layer.
|
||||
LaunchedEffect(requestInitialFocus) {
|
||||
if (!requestInitialFocus || inputMode.inputMode != InputMode.Keyboard) return@LaunchedEffect
|
||||
if (!requestInitialFocus || selectedGame != null || inputMode.inputMode != InputMode.Keyboard) return@LaunchedEffect
|
||||
delay(Motion.ms(200).toLong())
|
||||
focusSoon { layerFocus.getValue(layer) }
|
||||
}
|
||||
@@ -259,7 +486,7 @@ fun ComponentsPage(
|
||||
LaunchedEffect(layer) {
|
||||
if (seenLayer[0] == layer) return@LaunchedEffect
|
||||
seenLayer[0] = layer
|
||||
if (!pageFocused || inputMode.inputMode != InputMode.Keyboard) return@LaunchedEffect
|
||||
if (selectedGame != null || !pageFocused || inputMode.inputMode != InputMode.Keyboard) return@LaunchedEffect
|
||||
if (narrowOpen != null) runCatching { firstRow.requestFocus() }
|
||||
else focusSoon { layerFocus.getValue(layer) }
|
||||
}
|
||||
@@ -534,6 +761,21 @@ fun ComponentsPage(
|
||||
Column(Modifier.weight(1f)) { slide { k -> RowGroup(availableTitle(k)) { availableRows(k) } } }
|
||||
}
|
||||
Box(Modifier.padding(top = 14.dp)) { slide { k -> actions(k) } }
|
||||
if (l == "fex") {
|
||||
SettingsGroup(stringResource(R.string.fex_preset_title)) {
|
||||
SettingsRow(stringResource(R.string.fex_preset_title), null) {
|
||||
FexPresetChip(
|
||||
preset = generalFexPreset,
|
||||
inherited = false,
|
||||
open = fexMenu,
|
||||
enabled = true,
|
||||
onToggle = { fexMenu = !fexMenu },
|
||||
onDismiss = { fexMenu = false },
|
||||
onPick = { it?.let(onGeneralFexPreset) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (l == PROTON_TAB) {
|
||||
Spacer(Modifier.height(10.dp))
|
||||
if (!protons.runtimeReady) EmptyLine(stringResource(R.string.content_needs_runtime))
|
||||
@@ -550,7 +792,10 @@ fun ComponentsPage(
|
||||
Box(Modifier.fillMaxSize().onGloballyPositioned { pageAt = it.positionInRoot() }.onFocusChanged { pageFocused = it.hasFocus }) {
|
||||
Column(
|
||||
Modifier.fillMaxSize().padding(horizontal = if (narrow) 16.dp else 22.dp, vertical = if (narrow) 12.dp else 18.dp)
|
||||
.bumpers(onPrevious = { pick(layerStep(layer, -1)) }, onNext = { pick(layerStep(layer, 1)) }),
|
||||
.then(if (selectedGame == null) Modifier.bumpers(
|
||||
onPrevious = { pick(layerStep(layer, -1)) },
|
||||
onNext = { pick(layerStep(layer, 1)) },
|
||||
) else Modifier),
|
||||
) {
|
||||
// ---- header: the title, the device, when the lists were checked and the one refresh ----
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.fillMaxWidth()) {
|
||||
@@ -569,29 +814,109 @@ fun ComponentsPage(
|
||||
}
|
||||
if (narrow) Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(top = 6.dp)) { DeviceChip(gpu) }
|
||||
Spacer(Modifier.height(14.dp))
|
||||
Row(Modifier.weight(1f).fillMaxWidth()) {
|
||||
// ---- the stack ----
|
||||
Box(
|
||||
(if (narrow) Modifier.fillMaxWidth() else Modifier.width(250.dp)).fillMaxHeight()
|
||||
.onGloballyPositioned { stackAt = it.positionInRoot() },
|
||||
) {
|
||||
val tint = rememberUpdatedState(pal.signal)
|
||||
val local = cardsAt[layer]?.translate(-stackAt)
|
||||
ChipGlide(LAYERS.indexOf(layer), local, tint, GlideAxis.Vertical, corner = 12.dp)
|
||||
Stack(
|
||||
layer, view, gpu, focus = layerFocus, landed = landed, rings = rings,
|
||||
onPlaced = { l, r -> cardsAt[l] = r },
|
||||
onFocus = { l -> pick(l) },
|
||||
onOpen = { l ->
|
||||
pick(l)
|
||||
if (narrow) narrowOpen = l
|
||||
else runCatching { firstRow.requestFocus() }
|
||||
if (games.isNotEmpty()) {
|
||||
SettingsGroup(stringResource(R.string.comp_profile_configure)) {
|
||||
SettingsRow(
|
||||
stringResource(R.string.comp_profile),
|
||||
if (selectedGame == null) {
|
||||
stringResource(R.string.comp_scope_general_detail)
|
||||
} else {
|
||||
stringResource(R.string.comp_profile_game_detail, selectedGame.name)
|
||||
},
|
||||
)
|
||||
) {
|
||||
Box {
|
||||
ValueChip(
|
||||
selectedGame?.name ?: stringResource(R.string.comp_scope_general),
|
||||
scopeMenu,
|
||||
modifier = Modifier.widthIn(max = 320.dp).heightIn(min = 44.dp),
|
||||
) { scopeMenu = !scopeMenu }
|
||||
AnchoredMenu(
|
||||
scopeMenu,
|
||||
onDismiss = { scopeMenu = false },
|
||||
title = stringResource(R.string.comp_profile_configure),
|
||||
) { first ->
|
||||
MenuItem(
|
||||
stringResource(R.string.comp_scope_general),
|
||||
checked = selectedGame == null,
|
||||
detail = stringResource(R.string.comp_scope_general_detail),
|
||||
focusRequester = first,
|
||||
) {
|
||||
selectedGameKey = null
|
||||
scopeMenu = false
|
||||
}
|
||||
games.sortedBy { it.name.lowercase() }.forEach { game ->
|
||||
MenuItem(game.name, checked = selectedGameKey == game.profileKey) {
|
||||
selectedGameKey = game.profileKey
|
||||
scopeMenu = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!narrow) {
|
||||
Spacer(Modifier.width(16.dp))
|
||||
Box(Modifier.weight(1f).fillMaxHeight()) { detail(layer, false) }
|
||||
}
|
||||
|
||||
if (selectedGame != null) {
|
||||
GameComponentOverrides(
|
||||
game = selectedGame,
|
||||
config = environment,
|
||||
generalFexPreset = generalFexPreset,
|
||||
generalProton = view?.proton,
|
||||
protons = views.map { it.proton },
|
||||
protonId = gameProtonId,
|
||||
protonChoice = gameProtonChoice,
|
||||
packages = snapshot?.packages.orEmpty(),
|
||||
componentChoices = gameComponents,
|
||||
componentMenu = gameComponentMenu,
|
||||
protonMenu = gameProtonMenu,
|
||||
fexMenu = fexMenu,
|
||||
busy = environmentBusy || profileLoading,
|
||||
error = environmentError,
|
||||
notice = profileNotice,
|
||||
winComponentsRevision = winComponentsRevision,
|
||||
onFexMenu = { fexMenu = it },
|
||||
onFexPreset = ::setGameFexPreset,
|
||||
onProtonMenu = { gameProtonMenu = it },
|
||||
onProton = ::setGameProton,
|
||||
onComponentMenu = { gameComponentMenu = it },
|
||||
onComponent = ::setGameComponent,
|
||||
onEnvironment = { environmentEditor = true },
|
||||
onWinComponents = { winComponentsOpen = false },
|
||||
onReset = {
|
||||
ask(
|
||||
ctx.getString(R.string.comp_game_reset_title, selectedGame.name),
|
||||
ctx.getString(R.string.comp_game_reset_body),
|
||||
R.string.comp_game_reset,
|
||||
::resetGameProfile,
|
||||
)
|
||||
},
|
||||
modifier = Modifier.weight(1f).fillMaxWidth(),
|
||||
)
|
||||
} else {
|
||||
Row(Modifier.weight(1f).fillMaxWidth()) {
|
||||
// ---- the stack ----
|
||||
Box(
|
||||
(if (narrow) Modifier.fillMaxWidth() else Modifier.width(250.dp)).fillMaxHeight()
|
||||
.onGloballyPositioned { stackAt = it.positionInRoot() },
|
||||
) {
|
||||
val tint = rememberUpdatedState(pal.signal)
|
||||
val local = cardsAt[layer]?.translate(-stackAt)
|
||||
ChipGlide(LAYERS.indexOf(layer), local, tint, GlideAxis.Vertical, corner = 12.dp)
|
||||
Stack(
|
||||
layer, view, gpu, focus = layerFocus, landed = landed, rings = rings,
|
||||
onPlaced = { l, r -> cardsAt[l] = r },
|
||||
onFocus = { l -> pick(l) },
|
||||
onOpen = { l ->
|
||||
pick(l)
|
||||
if (narrow) narrowOpen = l
|
||||
else runCatching { firstRow.requestFocus() }
|
||||
},
|
||||
)
|
||||
}
|
||||
if (!narrow) {
|
||||
Spacer(Modifier.width(16.dp))
|
||||
Box(Modifier.weight(1f).fillMaxHeight()) { detail(layer, false) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -636,6 +961,50 @@ fun ComponentsPage(
|
||||
if (from == null) body() else PageFlood(from, driverLeaving) { body() }
|
||||
}
|
||||
}
|
||||
confirm?.let { (body, action) ->
|
||||
AlertDialog(
|
||||
onDismissRequest = { confirm = null },
|
||||
title = { Text(confirmTitle) },
|
||||
text = { Text(body, fontSize = 14.sp) },
|
||||
// Opens on Cancel, so a stray A press on a controller never swaps or deletes anything.
|
||||
confirmButton = {
|
||||
val del = confirmVerb == R.string.common_delete || confirmVerb == R.string.comp_game_reset
|
||||
FocusText(stringResource(confirmVerb), if (del) colors.error else pal.signal) { confirm = null; action() }
|
||||
},
|
||||
dismissButton = {
|
||||
val cancelFocus = remember { FocusRequester() }
|
||||
LaunchedEffect(Unit) { runCatching { cancelFocus.requestFocus() } }
|
||||
FocusText(stringResource(R.string.common_cancel), colors.onBackground, modifier = Modifier.focusRequester(cancelFocus)) { confirm = null }
|
||||
},
|
||||
)
|
||||
}
|
||||
if (environmentEditor && selectedGame != null) {
|
||||
GameEnvironmentEditor(
|
||||
byPad = androidx.compose.ui.platform.LocalInputModeManager.current.inputMode == androidx.compose.ui.input.InputMode.Keyboard,
|
||||
initialScope = selectedGame.profileKey,
|
||||
) {
|
||||
environmentEditor = false
|
||||
coroutine.launch {
|
||||
runCatching { withContext(Dispatchers.IO) { GameEnvironmentStore.read(ctx) } }
|
||||
.onSuccess { environment = it; environmentError = false }
|
||||
.onFailure { environmentError = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
val winOpen = winComponentsOpen
|
||||
if (winOpen != null && selectedGame != null) {
|
||||
WinComponentsDialog(
|
||||
selectedGame.profileKey,
|
||||
selectedGame.name,
|
||||
selectedGame.gameFiles,
|
||||
winOpen,
|
||||
compat = selectedGame.protonPrefix,
|
||||
steamAppId = selectedGame.appId.takeIf { selectedGame.library != Library.ADDED },
|
||||
) {
|
||||
winComponentsOpen = null
|
||||
winComponentsRevision++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The Installed rows of one component layer for the Proton the page shows. */
|
||||
@@ -798,6 +1167,253 @@ private fun EmptyLine(text: String) {
|
||||
Text(text, fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(horizontal = 14.dp, vertical = 12.dp))
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GameComponentOverrides(
|
||||
game: Library.SteamGame,
|
||||
config: GameEnvironment.Config?,
|
||||
generalFexPreset: String,
|
||||
generalProton: ComponentsManager.Proton?,
|
||||
protons: List<ComponentsManager.Proton>,
|
||||
protonId: String?,
|
||||
protonChoice: ProtonDefault.GameChoice?,
|
||||
packages: List<ComponentsManager.Package>,
|
||||
componentChoices: Map<String, String>,
|
||||
componentMenu: String?,
|
||||
protonMenu: Boolean,
|
||||
fexMenu: Boolean,
|
||||
busy: Boolean,
|
||||
error: Boolean,
|
||||
notice: String?,
|
||||
winComponentsRevision: Int,
|
||||
onFexMenu: (Boolean) -> Unit,
|
||||
onFexPreset: (String?) -> Unit,
|
||||
onProtonMenu: (Boolean) -> Unit,
|
||||
onProton: (String?) -> Unit,
|
||||
onComponentMenu: (String?) -> Unit,
|
||||
onComponent: (String, String?) -> Unit,
|
||||
onEnvironment: () -> Unit,
|
||||
onWinComponents: () -> Unit,
|
||||
onReset: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val override = config?.let { GameEnvironment.gameFexPreset(it, game.profileKey) }
|
||||
val proton = protons.firstOrNull { it.id == protonId }
|
||||
val effectiveProton = if (protonChoice == null) generalProton else proton
|
||||
val picks = remember(game.profileKey, winComponentsRevision) { WinComponents.picks(context, game.profileKey) }
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(14.dp),
|
||||
modifier = modifier.verticalScroll(rememberScrollState()).padding(top = 14.dp, bottom = 16.dp),
|
||||
) {
|
||||
Text(
|
||||
stringResource(R.string.comp_game_hint),
|
||||
fontSize = 13.sp,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
SettingsGroup(stringResource(R.string.fex_preset_title)) {
|
||||
SettingsRow(
|
||||
stringResource(R.string.comp_game_fex),
|
||||
stringResource(if (override == null) R.string.comp_game_fex_inherited else R.string.comp_game_fex_override),
|
||||
) {
|
||||
FexPresetChip(
|
||||
preset = override ?: generalFexPreset,
|
||||
inherited = override == null,
|
||||
open = fexMenu,
|
||||
enabled = config != null && !busy,
|
||||
allowInheritance = true,
|
||||
onToggle = { onFexMenu(!fexMenu) },
|
||||
onDismiss = { onFexMenu(false) },
|
||||
onPick = onFexPreset,
|
||||
)
|
||||
}
|
||||
GamePackageRow(
|
||||
comp = "fex",
|
||||
packages = packages,
|
||||
selectedFile = componentChoices["fex"],
|
||||
open = componentMenu == "fex",
|
||||
busy = busy,
|
||||
onMenu = onComponentMenu,
|
||||
onPick = onComponent,
|
||||
)
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.comp_game_compatibility)) {
|
||||
SettingsRow(
|
||||
stringResource(R.string.comp_proton),
|
||||
stringResource(if (protonChoice == null) R.string.comp_game_proton_inherited else R.string.comp_game_proton_override),
|
||||
) {
|
||||
Box {
|
||||
ValueChip(
|
||||
proton?.name ?: protonChoice?.dir ?: stringResource(R.string.comp_game_use_general),
|
||||
protonMenu,
|
||||
enabled = protons.isNotEmpty() && !busy,
|
||||
modifier = Modifier.widthIn(max = 280.dp),
|
||||
) { onProtonMenu(!protonMenu) }
|
||||
AnchoredMenu(
|
||||
protonMenu,
|
||||
onDismiss = { onProtonMenu(false) },
|
||||
title = stringResource(R.string.comp_proton),
|
||||
) { first ->
|
||||
MenuItem(
|
||||
stringResource(R.string.comp_game_use_general),
|
||||
checked = protonChoice == null,
|
||||
focusRequester = first,
|
||||
) { onProton(null); onProtonMenu(false) }
|
||||
protons.forEach { option ->
|
||||
MenuItem(option.name, checked = proton?.id == option.id) {
|
||||
onProton(option.id)
|
||||
onProtonMenu(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
GamePackageRow(
|
||||
comp = "dxvk",
|
||||
packages = packages,
|
||||
selectedFile = componentChoices["dxvk"],
|
||||
open = componentMenu == "dxvk",
|
||||
busy = busy,
|
||||
proton = effectiveProton,
|
||||
onMenu = onComponentMenu,
|
||||
onPick = onComponent,
|
||||
onRuntimeOptions = onEnvironment,
|
||||
)
|
||||
GamePackageRow(
|
||||
comp = "vkd3d",
|
||||
packages = packages,
|
||||
selectedFile = componentChoices["vkd3d"],
|
||||
open = componentMenu == "vkd3d",
|
||||
busy = busy,
|
||||
proton = effectiveProton,
|
||||
onMenu = onComponentMenu,
|
||||
onPick = onComponent,
|
||||
onRuntimeOptions = onEnvironment,
|
||||
)
|
||||
SettingsRow(
|
||||
stringResource(R.string.game_env_title),
|
||||
stringResource(R.string.comp_game_environment_other_hint),
|
||||
) {
|
||||
SecondaryButton(stringResource(R.string.game_env_edit), enabled = !busy, onClick = onEnvironment)
|
||||
}
|
||||
SettingsRow(
|
||||
stringResource(R.string.wincomp_title),
|
||||
if (picks.isEmpty()) stringResource(R.string.wincomp_card_none)
|
||||
else picks.joinToString(", ") { com.droiddeck.launcher.session.WinComponentNames.of(it) },
|
||||
) {
|
||||
SecondaryButton(stringResource(R.string.game_env_edit), onClick = onWinComponents)
|
||||
}
|
||||
}
|
||||
notice?.let {
|
||||
Text(
|
||||
it,
|
||||
fontSize = 13.sp,
|
||||
color = if (error) MaterialTheme.colorScheme.error else LocalPalette.current.good,
|
||||
)
|
||||
}
|
||||
if (error && notice == null) Text(stringResource(R.string.game_env_error), fontSize = 13.sp, color = MaterialTheme.colorScheme.error)
|
||||
if (!busy) {
|
||||
FocusText(
|
||||
stringResource(R.string.comp_game_reset),
|
||||
MaterialTheme.colorScheme.error,
|
||||
onClick = onReset,
|
||||
)
|
||||
}
|
||||
if (busy) LinearProgressIndicator(Modifier.fillMaxWidth())
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GamePackageRow(
|
||||
comp: String,
|
||||
packages: List<ComponentsManager.Package>,
|
||||
selectedFile: String?,
|
||||
open: Boolean,
|
||||
busy: Boolean,
|
||||
proton: ComponentsManager.Proton? = null,
|
||||
onMenu: (String?) -> Unit,
|
||||
onPick: (String, String?) -> Unit,
|
||||
onRuntimeOptions: (() -> Unit)? = null,
|
||||
) {
|
||||
val choices = packages.filter { it.comp == comp }
|
||||
val selected = choices.firstOrNull { it.file == selectedFile }
|
||||
val title = ComponentsManager.LABEL[comp] ?: comp
|
||||
SettingsRow(
|
||||
title,
|
||||
if (selected == null) {
|
||||
if (proton == null) stringResource(R.string.comp_game_component_general)
|
||||
else stringResource(R.string.comp_game_component_runtime, proton.name)
|
||||
} else stringResource(R.string.comp_game_component_override, selected.version),
|
||||
) {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
Box {
|
||||
ValueChip(
|
||||
selected?.version ?: stringResource(R.string.comp_game_use_general),
|
||||
open,
|
||||
enabled = !busy,
|
||||
modifier = Modifier.widthIn(max = 240.dp),
|
||||
) { onMenu(if (open) null else comp) }
|
||||
AnchoredMenu(open, onDismiss = { onMenu(null) }, title = title) { first ->
|
||||
MenuItem(
|
||||
stringResource(R.string.comp_game_use_general),
|
||||
checked = selected == null,
|
||||
focusRequester = first,
|
||||
) { onPick(comp, null); onMenu(null) }
|
||||
choices.forEach { option ->
|
||||
MenuItem(option.version, checked = option.file == selectedFile, detail = option.description) {
|
||||
onPick(comp, option.file)
|
||||
onMenu(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (onRuntimeOptions != null) {
|
||||
SecondaryButton(stringResource(R.string.comp_game_runtime_options), enabled = !busy, onClick = onRuntimeOptions)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun FexPresetChip(
|
||||
preset: String,
|
||||
inherited: Boolean,
|
||||
open: Boolean,
|
||||
enabled: Boolean,
|
||||
onToggle: () -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
onPick: (String?) -> Unit,
|
||||
allowInheritance: Boolean = false,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val chosen = FexPreset.all.firstOrNull { it.id == preset }
|
||||
val label = when {
|
||||
preset == GameEnvironment.CUSTOM_FEX_PRESET -> stringResource(R.string.comp_game_fex_custom)
|
||||
chosen == null -> stringResource(FexPreset.byId("").label)
|
||||
inherited -> stringResource(R.string.comp_game_use_general)
|
||||
else -> stringResource(chosen.label)
|
||||
}
|
||||
Box {
|
||||
ValueChip(label, open, enabled = enabled, modifier = modifier.widthIn(max = 260.dp), onClick = onToggle)
|
||||
AnchoredMenu(open && enabled, onDismiss = onDismiss, title = stringResource(R.string.fex_preset_title)) { first ->
|
||||
if (allowInheritance) {
|
||||
MenuItem(
|
||||
stringResource(R.string.comp_game_use_general),
|
||||
checked = inherited,
|
||||
focusRequester = first,
|
||||
) { onPick(null); onDismiss() }
|
||||
}
|
||||
FexPreset.all.forEachIndexed { index, option ->
|
||||
MenuItem(
|
||||
stringResource(option.label),
|
||||
checked = !inherited && option.id == preset,
|
||||
detail = stringResource(option.detail),
|
||||
focusRequester = if (index == 0 && !allowInheritance) first else null,
|
||||
) { onPick(option.id); onDismiss() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun ToolIcon(icon: ImageVector, description: String, busy: Boolean = false, enabled: Boolean = true, onClick: () -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
|
||||
@@ -478,10 +478,7 @@ internal fun LaunchSettings(s: FrontEndState, a: FrontEndActions, host: MenuHost
|
||||
val inputMode = androidx.compose.ui.platform.LocalInputModeManager.current
|
||||
// The game's prefix is compatdata/<id>, as droiddeck-game-env reads it: a Steam title's appid, an
|
||||
// added game's shortcut appid (unsigned). Recommended scans the game's own folder either way.
|
||||
val wincompKey = game?.let {
|
||||
if (it.library == com.droiddeck.launcher.frontend.Library.ADDED) Integer.toUnsignedString(it.appId)
|
||||
else it.appId.takeIf { id -> id > 0 }?.toString()
|
||||
}
|
||||
val wincompKey = game?.takeIf { it.library == com.droiddeck.launcher.frontend.Library.ADDED || it.appId > 0 }?.profileKey
|
||||
var wincompOpen by remember(wincompKey) { mutableStateOf<Boolean?>(null) }
|
||||
val wincompPicks = remember(wincompKey, wincompOpen) { wincompKey?.let { com.droiddeck.launcher.session.WinComponents.picks(context, it) }.orEmpty() }
|
||||
val cards = buildList<@Composable (Modifier) -> Unit> {
|
||||
|
||||
@@ -52,7 +52,11 @@ import kotlinx.coroutines.withContext
|
||||
// dialog, with each variable's actions in a menu off its value as everywhere else.
|
||||
|
||||
@Composable
|
||||
fun GameEnvironmentRow(modifier: Modifier = Modifier, showHint: Boolean = true) {
|
||||
fun GameEnvironmentRow(
|
||||
modifier: Modifier = Modifier,
|
||||
showHint: Boolean = true,
|
||||
initialScope: String = "",
|
||||
) {
|
||||
var open by remember { mutableStateOf(false) }
|
||||
// Opened with a pad, the editor starts with focus in it; the dialog is a window of its own and
|
||||
// would otherwise give the pad nothing to move from.
|
||||
@@ -64,7 +68,7 @@ fun GameEnvironmentRow(modifier: Modifier = Modifier, showHint: Boolean = true)
|
||||
open = true
|
||||
}
|
||||
}
|
||||
if (open) GameEnvironmentEditor(byPad) { open = false }
|
||||
if (open) GameEnvironmentEditor(byPad, initialScope) { open = false }
|
||||
}
|
||||
|
||||
/** With a pad driving, focus [target] once the dialog is laid out, and keep the dialog in pad mode. */
|
||||
@@ -81,19 +85,19 @@ internal fun PadFocus(byPad: Boolean, target: FocusRequester) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GameEnvironmentEditor(byPad: Boolean, onClose: () -> Unit) {
|
||||
internal fun GameEnvironmentEditor(byPad: Boolean, initialScope: String = "", onClose: () -> Unit) {
|
||||
val context = LocalContext.current
|
||||
val coroutine = rememberCoroutineScope()
|
||||
val shown = rememberShown(onClose)
|
||||
val close = { shown.targetState = false }
|
||||
var config by remember { mutableStateOf<GameEnvironment.Config?>(null) }
|
||||
var games by remember { mutableStateOf(emptyList<Pair<String, String>>()) }
|
||||
var scope by remember { mutableStateOf("") }
|
||||
var scope by remember { mutableStateOf(initialScope) }
|
||||
var otherId by remember { mutableStateOf<String?>(null) }
|
||||
var menu by remember { mutableStateOf<String?>(null) }
|
||||
var busy by remember { mutableStateOf(false) }
|
||||
var error by remember { mutableStateOf(false) }
|
||||
var editing by remember { mutableStateOf<Pair<String, String>?>(null) }
|
||||
var editing by remember { mutableStateOf<EnvironmentVariableEdit?>(null) }
|
||||
val preset = SessionPrefs.fexPreset(context)
|
||||
val forceSsbs = SessionPrefs.forceSsbs(context)
|
||||
val firstFocus = remember { FocusRequester() }
|
||||
@@ -168,7 +172,7 @@ private fun GameEnvironmentEditor(byPad: Boolean, onClose: () -> Unit) {
|
||||
VariableRow(
|
||||
name, value, inherited = !own.containsKey(name), open = menu == "var:$name", enabled = !busy,
|
||||
onToggle = { menu = if (menu == "var:$name") null else "var:$name" }, onDismiss = { if (menu == "var:$name") menu = null },
|
||||
onEdit = { menu = null; editByPad = dialogInput.inputMode == InputMode.Keyboard; editing = name to (value ?: "") },
|
||||
onEdit = { menu = null; editByPad = dialogInput.inputMode == InputMode.Keyboard; editing = EnvironmentVariableEdit(scope, profileName, name, value ?: "") },
|
||||
// A value set here or inherited can be switched off for this profile; one set here can go back to inheriting.
|
||||
onUnset = if (value != null) ({ menu = null; save(current.withEntries(scope, own + (name to null))) }) else null,
|
||||
onRestore = if (own.containsKey(name)) ({ menu = null; save(current.withEntries(scope, own - name)) }) else null,
|
||||
@@ -185,9 +189,9 @@ private fun GameEnvironmentEditor(byPad: Boolean, onClose: () -> Unit) {
|
||||
SecondaryButton(stringResource(R.string.game_env_add), enabled = !busy) { menu = if (menu == "add") null else "add" }
|
||||
AnchoredMenu(menu == "add", onDismiss = { if (menu == "add") menu = null }, title = stringResource(R.string.game_env_add)) { first ->
|
||||
for ((i, option) in GameEnvironmentOptions.all.withIndex()) MenuItem(option.name, checked = false, focusRequester = if (i == 0) first else null) {
|
||||
menu = null; editByPad = dialogInput.inputMode == InputMode.Keyboard; editing = option.name to option.value
|
||||
menu = null; editByPad = dialogInput.inputMode == InputMode.Keyboard; editing = EnvironmentVariableEdit(scope, profileName, option.name, option.value)
|
||||
}
|
||||
MenuItem(stringResource(R.string.game_env_custom), checked = false) { menu = null; editByPad = dialogInput.inputMode == InputMode.Keyboard; editing = "" to "" }
|
||||
MenuItem(stringResource(R.string.game_env_custom), checked = false) { menu = null; editByPad = dialogInput.inputMode == InputMode.Keyboard; editing = EnvironmentVariableEdit(scope, profileName, "", "") }
|
||||
}
|
||||
}
|
||||
if (current != null && current.entries(scope).isNotEmpty()) FocusText(stringResource(R.string.game_env_reset), LocalPalette.current.signal) {
|
||||
@@ -197,19 +201,21 @@ private fun GameEnvironmentEditor(byPad: Boolean, onClose: () -> Unit) {
|
||||
PrimaryButton(stringResource(R.string.game_env_done), enabled = !busy, onClick = close)
|
||||
}
|
||||
}
|
||||
editing?.let { (name, value) ->
|
||||
VariableDialog(name, value, profileName, editByPad, onDismiss = { editing = null }) { key, content ->
|
||||
editing?.let { edit ->
|
||||
VariableDialog(edit.name, edit.value, edit.profileName, editByPad, onDismiss = { editing = null }) { key, content ->
|
||||
config?.let {
|
||||
val entries = it.entries(scope).toMutableMap()
|
||||
if (name.isNotEmpty() && name != key) entries[name] = null
|
||||
val entries = it.entries(edit.scope).toMutableMap()
|
||||
if (edit.name.isNotEmpty() && edit.name != key) entries[edit.name] = null
|
||||
entries[key] = content
|
||||
save(it.withEntries(scope, entries))
|
||||
save(it.withEntries(edit.scope, entries))
|
||||
}
|
||||
editing = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private data class EnvironmentVariableEdit(val scope: String, val profileName: String, val name: String, val value: String)
|
||||
|
||||
/** The panel the profile and the variables sit in, as a settings group does. */
|
||||
@Composable
|
||||
private fun Panel(content: @Composable androidx.compose.foundation.layout.ColumnScope.() -> Unit) =
|
||||
|
||||
@@ -18,6 +18,7 @@ import androidx.compose.ui.input.key.type
|
||||
import androidx.compose.ui.layout.LayoutCoordinates
|
||||
import androidx.compose.ui.layout.onSizeChanged
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.res.pluralStringResource
|
||||
import androidx.compose.ui.unit.IntOffset
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
import kotlin.math.roundToInt
|
||||
@@ -88,6 +89,9 @@ import com.droiddeck.launcher.HomeApp
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.animateColorAsState
|
||||
import androidx.compose.animation.core.Spring
|
||||
import com.droiddeck.launcher.core.GameEnvironment
|
||||
import com.droiddeck.launcher.session.ProfileValue
|
||||
import com.droiddeck.launcher.session.SelectedGameProfile
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.ui.draw.rotate
|
||||
import androidx.compose.ui.semantics.stateDescription
|
||||
@@ -205,8 +209,8 @@ class DrawerActions(
|
||||
/** The compositor's post chain (gpu/ScreenEffects), changed live. */
|
||||
val effects: ScreenEffects = ScreenEffects.OFF,
|
||||
/** Texture filtering for DirectX 9-11 games (core/TextureFiltering); lands on their next launch. */
|
||||
val textureAnisotropy: Int = 0,
|
||||
val textureLodBias: String = TextureFiltering.LOD_BIAS_OFF,
|
||||
val textureAnisotropy: Int? = 0,
|
||||
val textureLodBias: String? = TextureFiltering.LOD_BIAS_OFF,
|
||||
val secondScreenMode: SecondScreenMode,
|
||||
val secondScreenDisplays: List<SecondScreenDisplay>,
|
||||
val selectedSecondScreenDisplay: Int,
|
||||
@@ -235,8 +239,8 @@ class DrawerActions(
|
||||
val onUpscaler: (Int) -> Unit = {},
|
||||
val onUpscaleSharpness: (Int) -> Unit = {},
|
||||
val onEffects: (ScreenEffects) -> Unit = {},
|
||||
val onTextureAnisotropy: (Int) -> Unit = {},
|
||||
val onTextureLodBias: (String) -> Unit = {},
|
||||
val onTextureAnisotropy: (Int?) -> Unit = {},
|
||||
val onTextureLodBias: (String?) -> Unit = {},
|
||||
val onSecondScreenMode: (SecondScreenMode) -> Unit,
|
||||
val onSecondScreenDisplay: (Int) -> Unit,
|
||||
val onLaunchAndroidApp: (HomeApp.LaunchableApp, Int?) -> Unit,
|
||||
@@ -257,8 +261,22 @@ class DrawerActions(
|
||||
val components: ComponentsManager.Snapshot? = null,
|
||||
/** Re-reads the Protons (and runs swaps that waited for a game to close). */
|
||||
val onComponentsRefresh: () -> Unit = {},
|
||||
/** Installed games available for profile inspection in the session drawer. */
|
||||
val gameProfiles: List<Pair<Long, String>> = emptyList(),
|
||||
/** The selected game profile, or null for the Default profile. */
|
||||
val selectedGameProfileId: Long? = null,
|
||||
val selectedGameProfile: SelectedGameProfile? = null,
|
||||
val gameProfilesLoaded: Boolean = false,
|
||||
val gameProfileRefreshFailed: Boolean = false,
|
||||
val onSelectedGameProfile: (Long?) -> Unit = {},
|
||||
val onGameProfilesPageOpened: () -> Unit = {},
|
||||
val onSelectedGameProfileRefresh: () -> Unit = {},
|
||||
val gameFexPresetSaving: Boolean = false,
|
||||
val onGameFexPreset: (Long, String?) -> Unit = { _, _ -> },
|
||||
/** Swaps [value] ("orig:<build>" or a stored package file) into a Proton's component. */
|
||||
val onComponentSwap: (protonId: String, comp: String, value: String) -> Unit = { _, _, _ -> },
|
||||
/** Saves a stored package for a game, or null to inherit that component from the Default profile. */
|
||||
val onGameComponent: (appId: Long, comp: String, file: String?) -> Unit = { _, _, _ -> },
|
||||
)
|
||||
|
||||
@OptIn(ExperimentalComposeUiApi::class)
|
||||
@@ -286,7 +304,19 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
}
|
||||
BackHandler(enabled = open && confirmStop) { confirmStop = false }
|
||||
LaunchedEffect(page) { host.open = null; appToChooseDisplay = null }
|
||||
LaunchedEffect(open, page) { if (open && page == SessionDrawerPage.GAMES) a.onComponentsRefresh() }
|
||||
LaunchedEffect(a.selectedGameProfileId) {
|
||||
if (host.open == "fex") host.open = null
|
||||
}
|
||||
LaunchedEffect(open, page) {
|
||||
if (open && page == SessionDrawerPage.GAMES) {
|
||||
a.onGameProfilesPageOpened()
|
||||
a.onComponentsRefresh()
|
||||
while (true) {
|
||||
a.onSelectedGameProfileRefresh()
|
||||
delay(1_000)
|
||||
}
|
||||
}
|
||||
}
|
||||
LaunchedEffect(open, controllerActive) {
|
||||
if (open && !controllerActive) focusManager.clearFocus(force = true)
|
||||
}
|
||||
@@ -479,14 +509,17 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
SecondScreenGroup(host, a) { key -> focus.track(page, key) }
|
||||
}
|
||||
SessionDrawerPage.GAMES -> {
|
||||
if (a.steam) SelectedGameProfileGroup(host, a) { key -> focus.track(page, key) }
|
||||
Text(stringResource(R.string.fex_next_launch), fontSize = 12.sp,
|
||||
color = colors.onSurfaceVariant, modifier = Modifier.padding(horizontal = 14.dp, vertical = 8.dp))
|
||||
TextureFilteringGroup(host, a) { key -> focus.track(page, key) }
|
||||
if (a.steam) SettingsGroup(stringResource(R.string.game_settings_title)) {
|
||||
ChoiceRow(host, "fex", stringResource(R.string.fex_preset_title), null,
|
||||
FexPreset.all.map { it.id to stringResource(it.label) }, a.fexPreset,
|
||||
chipModifier = focus.track(page, "fex"), onPick = a.onFexPreset)
|
||||
GameEnvironmentRow(modifier = focus.track(page, "game-env"), showHint = false)
|
||||
DrawerFexPresetRow(host, a, focus.track(page, "fex"))
|
||||
GameEnvironmentRow(
|
||||
modifier = focus.track(page, "game-env"),
|
||||
showHint = false,
|
||||
initialScope = a.selectedGameProfileId?.toString().orEmpty(),
|
||||
)
|
||||
}
|
||||
ComponentsDrawerPage(host, a) { key -> focus.track(page, key) }
|
||||
}
|
||||
@@ -874,20 +907,187 @@ private fun SecondScreenGroup(host: MenuHost, a: DrawerActions, track: (String)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DrawerFexPresetRow(host: MenuHost, a: DrawerActions, modifier: Modifier) {
|
||||
val appId = a.selectedGameProfileId
|
||||
val profile = a.selectedGameProfile?.takeIf { it.appId == appId }
|
||||
val inherited = profile?.fexPreset?.inherited == true
|
||||
val hint = if (profile == null) null else stringResource(
|
||||
if (inherited) R.string.comp_game_fex_inherited else R.string.comp_game_fex_override,
|
||||
)
|
||||
SettingsRow(stringResource(R.string.fex_preset_title), hint, highlighted = host.open == "fex") {
|
||||
if (appId != null && profile == null) {
|
||||
ValueChip("-", false, enabled = false, modifier = modifier) {}
|
||||
} else {
|
||||
FexPresetChip(
|
||||
preset = profile?.fexPreset?.value ?: a.fexPreset,
|
||||
inherited = inherited,
|
||||
open = host.open == "fex",
|
||||
enabled = !a.gameFexPresetSaving,
|
||||
onToggle = { host.open = if (host.open == "fex") null else "fex" },
|
||||
onDismiss = { if (host.open == "fex") host.open = null },
|
||||
onPick = { preset ->
|
||||
if (appId == null) {
|
||||
preset?.let(a.onFexPreset)
|
||||
} else {
|
||||
a.onGameFexPreset(appId, preset)
|
||||
}
|
||||
},
|
||||
allowInheritance = appId != null,
|
||||
modifier = modifier,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Texture filtering on the Games page: DXVK options for the next DirectX 9-11 launch. */
|
||||
@Composable
|
||||
private fun TextureFilteringGroup(host: MenuHost, a: DrawerActions, track: (String) -> Modifier) {
|
||||
val inherited = a.selectedGameProfileId != null
|
||||
val anisotropyChoices: List<Pair<Int?, String>> =
|
||||
(if (inherited) listOf(null to stringResource(R.string.comp_game_use_general)) else emptyList()) +
|
||||
SessionPrefs.textureAnisotropyChoices(LocalContext.current).map { (value, label) -> value as Int? to label }
|
||||
val lodBiasChoices: List<Pair<String?, String>> =
|
||||
(if (inherited) listOf(null to stringResource(R.string.comp_game_use_general)) else emptyList()) +
|
||||
SessionPrefs.textureLodBiasChoices(LocalContext.current).map { (value, label) -> value as String? to label }
|
||||
SettingsGroup(stringResource(R.string.drawer_texture)) {
|
||||
ChoiceRow(host, "anisotropy", stringResource(R.string.drawer_anisotropy), null,
|
||||
SessionPrefs.textureAnisotropyChoices(LocalContext.current), a.textureAnisotropy, chipModifier = track("anisotropy"), onPick = a.onTextureAnisotropy)
|
||||
anisotropyChoices, a.textureAnisotropy, chipModifier = track("anisotropy"), onPick = a.onTextureAnisotropy)
|
||||
ChoiceRow(host, "texture-sharpness", stringResource(R.string.drawer_texture_sharpness), null,
|
||||
SessionPrefs.textureLodBiasChoices(LocalContext.current), a.textureLodBias, note = stringResource(R.string.drawer_texture_sharpness_note),
|
||||
lodBiasChoices, a.textureLodBias, note = stringResource(R.string.drawer_texture_sharpness_note),
|
||||
chipModifier = track("texture-sharpness"), onPick = a.onTextureLodBias)
|
||||
}
|
||||
}
|
||||
|
||||
private fun signed(v: Int) = if (v > 0) "+$v" else "$v"
|
||||
|
||||
@Composable
|
||||
private fun SelectedGameProfileGroup(host: MenuHost, a: DrawerActions, track: (String) -> Modifier) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val options: List<Pair<Long?, String>> = listOf(null to stringResource(R.string.comp_scope_general)) +
|
||||
a.gameProfiles.map { (id, name) -> Pair(id, name) }
|
||||
val profile = a.selectedGameProfile
|
||||
SettingsGroup(stringResource(R.string.drawer_selected_profile)) {
|
||||
DrawerStackedChoice(
|
||||
host = host,
|
||||
key = "game-profile",
|
||||
label = stringResource(R.string.comp_profile),
|
||||
hint = if (a.selectedGameProfileId == null) stringResource(R.string.comp_scope_general_detail)
|
||||
else stringResource(R.string.drawer_profile_inspect_hint),
|
||||
options = options,
|
||||
selected = a.selectedGameProfileId,
|
||||
chipModifier = track("game-profile"),
|
||||
onPick = a.onSelectedGameProfile,
|
||||
)
|
||||
if (a.gameProfileRefreshFailed) {
|
||||
Text(
|
||||
stringResource(
|
||||
if (a.gameProfilesLoaded) {
|
||||
R.string.drawer_profile_refresh_failed_stale
|
||||
} else {
|
||||
R.string.drawer_profile_refresh_failed_initial
|
||||
},
|
||||
),
|
||||
fontSize = 13.sp,
|
||||
color = colors.error,
|
||||
modifier = Modifier.padding(horizontal = 14.dp, vertical = 8.dp),
|
||||
)
|
||||
}
|
||||
if (a.selectedGameProfileId == null) return@SettingsGroup
|
||||
if (profile == null) {
|
||||
if (!a.gameProfileRefreshFailed) Text(
|
||||
stringResource(R.string.drawer_selected_profile_none),
|
||||
fontSize = 13.sp,
|
||||
color = colors.onSurfaceVariant,
|
||||
modifier = Modifier.padding(14.dp),
|
||||
)
|
||||
return@SettingsGroup
|
||||
}
|
||||
val hasOverrides = profile.hasOverrides ||
|
||||
a.textureAnisotropy != null ||
|
||||
a.textureLodBias != null
|
||||
Column(modifier = Modifier.fillMaxWidth().padding(horizontal = 14.dp, vertical = 11.dp)) {
|
||||
Text(
|
||||
stringResource(
|
||||
if (hasOverrides) R.string.drawer_profile_custom
|
||||
else R.string.drawer_profile_default,
|
||||
),
|
||||
fontSize = 12.sp,
|
||||
color = colors.onSurfaceVariant,
|
||||
modifier = Modifier.padding(bottom = if (hasOverrides) 5.dp else 0.dp),
|
||||
)
|
||||
if (!profile.fexPreset.inherited) {
|
||||
ProfileSummaryRow(stringResource(R.string.comp_game_fex), fexProfileLabel(profile.fexPreset))
|
||||
}
|
||||
if (!profile.proton.inherited) {
|
||||
ProfileSummaryRow(stringResource(R.string.comp_proton), profileValueLabel(profile.proton))
|
||||
}
|
||||
for (component in ComponentsManager.COMPONENTS) {
|
||||
val value = profile.components.getValue(component)
|
||||
if (!value.inherited) {
|
||||
ProfileSummaryRow(ComponentsManager.LABEL.getValue(component), profileValueLabel(value))
|
||||
}
|
||||
}
|
||||
if (profile.environmentOverrides > 0) {
|
||||
ProfileSummaryRow(
|
||||
stringResource(R.string.game_env_title),
|
||||
pluralStringResource(
|
||||
R.plurals.drawer_profile_environment_overrides,
|
||||
profile.environmentOverrides,
|
||||
profile.environmentOverrides,
|
||||
),
|
||||
)
|
||||
}
|
||||
if (profile.windowsComponentNames.isNotEmpty()) {
|
||||
ProfileSummaryRow(
|
||||
stringResource(R.string.wincomp_title),
|
||||
profile.windowsComponentNames.joinToString(", "),
|
||||
)
|
||||
}
|
||||
a.textureAnisotropy?.let { value ->
|
||||
ProfileSummaryRow(
|
||||
stringResource(R.string.drawer_anisotropy),
|
||||
SessionPrefs.textureAnisotropyChoices(LocalContext.current)
|
||||
.firstOrNull { it.first == value }?.second.orEmpty(),
|
||||
)
|
||||
}
|
||||
a.textureLodBias?.let { value ->
|
||||
ProfileSummaryRow(
|
||||
stringResource(R.string.drawer_texture_sharpness),
|
||||
SessionPrefs.textureLodBiasChoices(LocalContext.current)
|
||||
.firstOrNull { it.first == value }?.second.orEmpty(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun fexProfileLabel(value: ProfileValue): String {
|
||||
return when (value.value) {
|
||||
GameEnvironment.CUSTOM_FEX_PRESET -> stringResource(R.string.comp_game_fex_custom)
|
||||
else -> stringResource(FexPreset.byId(value.value).label)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun profileValueLabel(value: ProfileValue) =
|
||||
value.value.ifEmpty { stringResource(R.string.comp_no_proton_short) }
|
||||
|
||||
@Composable
|
||||
private fun ProfileSummaryRow(label: String, value: String) {
|
||||
Row(modifier = Modifier.fillMaxWidth().padding(top = 3.dp)) {
|
||||
Text(label, fontSize = 12.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.width(96.dp))
|
||||
Text(
|
||||
value,
|
||||
fontSize = 12.sp,
|
||||
color = MaterialTheme.colorScheme.onBackground,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The Games tab's components: quick swaps between what is already installed, per Proton. A swap
|
||||
* into the Proton a running game uses waits until that game closes; downloading, importing and
|
||||
@@ -903,6 +1103,54 @@ private fun ComponentsDrawerPage(host: MenuHost, a: DrawerActions, track: (Strin
|
||||
}
|
||||
return
|
||||
}
|
||||
val gameProfile = a.selectedGameProfileId?.let { appId ->
|
||||
a.selectedGameProfile?.takeIf { it.appId == appId }
|
||||
}
|
||||
if (a.selectedGameProfileId != null) {
|
||||
if (gameProfile == null) {
|
||||
SettingsGroup(stringResource(R.string.drawer_page_components)) {
|
||||
Text(
|
||||
stringResource(R.string.comp_reading),
|
||||
fontSize = 13.sp,
|
||||
color = colors.onSurfaceVariant,
|
||||
modifier = Modifier.padding(14.dp),
|
||||
)
|
||||
}
|
||||
return
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.drawer_page_components)) {
|
||||
Column(modifier = Modifier.fillMaxWidth().padding(horizontal = 14.dp, vertical = 11.dp)) {
|
||||
ProfileSummaryRow(stringResource(R.string.comp_proton), gameProfile.proton.value)
|
||||
}
|
||||
for (comp in ComponentsManager.COMPONENTS) {
|
||||
val value = gameProfile.components.getValue(comp)
|
||||
val options: List<Pair<String?, String>> =
|
||||
listOf(null to stringResource(R.string.comp_game_use_general)) +
|
||||
snap.packages.filter { it.comp == comp }.map { it.file to it.version }
|
||||
DrawerStackedChoice(
|
||||
host = host,
|
||||
key = "game-cmp-$comp",
|
||||
label = ComponentsManager.LABEL.getValue(comp),
|
||||
hint = if (value.inherited) {
|
||||
stringResource(R.string.drawer_component_inherited, value.value)
|
||||
} else {
|
||||
null
|
||||
},
|
||||
options = options,
|
||||
selected = gameProfile.componentFiles[comp],
|
||||
chipModifier = track("cmp-$comp"),
|
||||
onPick = { file -> a.onGameComponent(gameProfile.appId, comp, file) },
|
||||
)
|
||||
}
|
||||
}
|
||||
Text(
|
||||
stringResource(R.string.drawer_game_components_note, gameProfile.name),
|
||||
fontSize = 12.sp,
|
||||
color = colors.onSurfaceVariant,
|
||||
modifier = Modifier.padding(horizontal = 4.dp, vertical = 12.dp),
|
||||
)
|
||||
return
|
||||
}
|
||||
val running = snap.protons.filter { it.inUseByGame }
|
||||
var pick by rememberSaveable { mutableStateOf<String?>(null) }
|
||||
val view = snap.protons.firstOrNull { it.proton.id == pick } ?: running.firstOrNull() ?: snap.protons.firstOrNull()
|
||||
|
||||
Reference in new issue
Block a user