diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/FrameGen.kt b/app/src/main/java/com/droiddeck/launcher/gpu/FrameGen.kt index 90ea864783..236c17a008 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/FrameGen.kt +++ b/app/src/main/java/com/droiddeck/launcher/gpu/FrameGen.kt @@ -40,9 +40,11 @@ object FrameGen { } /** "Off", "Win-FG 2×", "LSFG 3×" - for the main screen. */ - fun label(context: Context): String = when (engine(context)) { - ENGINE_WINFG -> "Win-FG ${multiplier(context)}×" - ENGINE_LSFG -> "LSFG ${multiplier(context)}×" + fun label(context: Context): String = label(engine(context), multiplier(context)) + + fun label(engine: String, multiplier: Int): String = when (engine) { + ENGINE_WINFG -> "Win-FG $multiplier×" + ENGINE_LSFG -> "LSFG $multiplier×" else -> "Off" } @@ -82,47 +84,5 @@ object FrameGen { return problem } - /** - * Off, or an engine at 2x/3x/4x; saved on pick, then [onChanged]. The LSFG rows are greyed - * and unpickable until Lossless Scaling is installed in the Steam client - the engine cannot - * run without its DLL, so offering it would only produce a setting that silently does nothing. - */ - fun showPicker(activity: android.app.Activity, onChanged: () -> Unit) { - val lsfgReady = LsfgNative.isInstalled(activity) - val lsfgNote = if (lsfgReady) "" else " - install Lossless Scaling in Steam" - val choices = listOf("Off", - "Win-FG 2×", "Win-FG 3×", "Win-FG 4×", - "LSFG 2×$lsfgNote", "LSFG 3×$lsfgNote", "LSFG 4×$lsfgNote") - val current = when (engine(activity)) { - ENGINE_WINFG -> multiplier(activity) - 1 - ENGINE_LSFG -> if (lsfgReady) multiplier(activity) + 2 else 0 - else -> 0 - } - val adapter = object : android.widget.ArrayAdapter( - activity, android.R.layout.simple_list_item_single_choice, choices) { - override fun isEnabled(position: Int) = lsfgReady || position < 4 - override fun areAllItemsEnabled() = lsfgReady - override fun getView(position: Int, convertView: android.view.View?, parent: android.view.ViewGroup): android.view.View { - val view = super.getView(position, convertView, parent) - view.isEnabled = isEnabled(position) - view.alpha = if (isEnabled(position)) 1f else 0.38f - return view - } - } - android.app.AlertDialog.Builder(activity) - .setTitle(com.droiddeck.launcher.R.string.frame_gen_title) - .setSingleChoiceItems(adapter, current) { dialog, which -> - when (which) { - 0 -> set(activity, ENGINE_OFF, 2) - in 1..3 -> set(activity, ENGINE_WINFG, which + 1) - else -> set(activity, ENGINE_LSFG, which - 2) - } - dialog.dismiss() - onChanged() - } - .setNeutralButton(android.R.string.ok, null) - .show() - } - private const val TAG = "FrameGen" } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrameGenMenu.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrameGenMenu.kt new file mode 100644 index 0000000000..2d533fd527 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrameGenMenu.kt @@ -0,0 +1,22 @@ +package com.droiddeck.launcher.ui + +import androidx.compose.runtime.Composable +import com.droiddeck.launcher.gpu.FrameGen + +/** + * The frame generation picker, anchored to whatever opened it (host key "fg"). One copy for Setup, + * a game's launch settings and the session drawer, so they say the same thing. + */ +@Composable +internal fun FrameGenMenu( + host: MenuHost, engine: String, multiplier: Int, lsfgReady: Boolean, + onPick: (engine: String, multiplier: Int) -> Unit, +) { + AnchoredMenu(host.open == "fg", onDismiss = { if (host.open == "fg") host.open = null }, title = "Frame generation") { firstItemFocus -> + val need = if (lsfgReady) null else "Needs Lossless Scaling installed in Steam" + fun pick(e: String, m: Int) { onPick(e, m); host.open = null } + MenuItem("Off", checked = engine == FrameGen.ENGINE_OFF, focusRequester = firstItemFocus) { pick(FrameGen.ENGINE_OFF, 2) } + for (m in 2..4) MenuItem(FrameGen.label(FrameGen.ENGINE_WINFG, m), checked = engine == FrameGen.ENGINE_WINFG && multiplier == m) { pick(FrameGen.ENGINE_WINFG, m) } + for (m in 2..4) MenuItem(FrameGen.label(FrameGen.ENGINE_LSFG, m), checked = engine == FrameGen.ENGINE_LSFG && multiplier == m, enabled = lsfgReady, detail = need) { pick(FrameGen.ENGINE_LSFG, m) } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt index 9c6b7a9fc6..36028b5f94 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt @@ -370,12 +370,7 @@ private fun ToolCard(t: ToolSpec, modifier: Modifier) { @Composable private fun FrameGenMenu(s: FrontEndState, a: FrontEndActions, host: MenuHost) { - AnchoredMenu(host.open == "fg", onDismiss = { if (host.open == "fg") host.open = null }, title = "Frame generation") { firstItemFocus -> - val need = if (s.lsfgReady) null else "Install Lossless Scaling in Steam" - MenuItem("Off", checked = s.frameGenEngine == FrameGen.ENGINE_OFF, focusRequester = firstItemFocus) { a.onFrameGenPick(FrameGen.ENGINE_OFF, 2); host.open = null } - for (m in 2..4) MenuItem("Win-FG ${m}×", checked = s.frameGenEngine == FrameGen.ENGINE_WINFG && s.frameGenMultiplier == m) { a.onFrameGenPick(FrameGen.ENGINE_WINFG, m); host.open = null } - for (m in 2..4) MenuItem("LSFG ${m}×", checked = s.frameGenEngine == FrameGen.ENGINE_LSFG && s.frameGenMultiplier == m, enabled = s.lsfgReady, detail = need) { a.onFrameGenPick(FrameGen.ENGINE_LSFG, m); host.open = null } - } + FrameGenMenu(host, s.frameGenEngine, s.frameGenMultiplier, s.lsfgReady, a.onFrameGenPick) } /** diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt index 90d7cbdf3f..7ba0ac9ce9 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt @@ -316,20 +316,11 @@ fun SessionDrawer(open: Boolean, page: Int, controllerActive: Boolean, onPageCha chipModifier = focus.track(page, "fill"), onChange = a.onFillScreen, ) val fgOpen = host.open == "fg" - val fgLabel = when (a.frameGenEngine) { - FrameGen.ENGINE_WINFG -> "Win-FG ${a.frameGenMultiplier}×" - FrameGen.ENGINE_LSFG -> "LSFG ${a.frameGenMultiplier}×" - else -> "Off" - } + val fgLabel = FrameGen.label(a.frameGenEngine, a.frameGenMultiplier) SettingsRow("Frame generation", null, highlighted = fgOpen) { Box { ValueChip(fgLabel, fgOpen, modifier = focus.track(page, "fg")) { host.open = if (fgOpen) null else "fg" } - AnchoredMenu(fgOpen, onDismiss = { if (host.open == "fg") host.open = null }, title = "Frame generation") { firstItemFocus -> - val need = if (a.lsfgReady) null else "Requires Lossless Scaling" - MenuItem("Off", checked = a.frameGenEngine == FrameGen.ENGINE_OFF, focusRequester = firstItemFocus) { a.onFrameGenPick(FrameGen.ENGINE_OFF, 2); host.open = null } - for (m in 2..4) MenuItem("Win-FG ${m}×", checked = a.frameGenEngine == FrameGen.ENGINE_WINFG && a.frameGenMultiplier == m) { a.onFrameGenPick(FrameGen.ENGINE_WINFG, m); host.open = null } - for (m in 2..4) MenuItem("LSFG ${m}×", checked = a.frameGenEngine == FrameGen.ENGINE_LSFG && a.frameGenMultiplier == m, enabled = a.lsfgReady, detail = need) { a.onFrameGenPick(FrameGen.ENGINE_LSFG, m); host.open = null } - } + FrameGenMenu(host, a.frameGenEngine, a.frameGenMultiplier, a.lsfgReady, a.onFrameGenPick) } } }