Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
251 changes: 251 additions & 0 deletions app/src/main/app/shell/LaunchOptionsScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
package com.winlator.cmod.app.shell

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Check
import androidx.compose.material.icons.outlined.Close
import androidx.compose.material.icons.outlined.RocketLaunch
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.winlator.cmod.R

/** A single Steam launch option (appinfo `config.launch` entry). */
internal data class StoreLaunchOptionItem(
// Relative path, '/'-separated.
val executable: String,
val arguments: String,
val label: String,
)

// Palette — mirrors the Workshop window so the modal feels native.
private val LoBg = Color(0xFF12121B)
private val LoBorder = Color(0xFF2A2A3A)
private val LoAccent = Color(0xFF1A9FFF)
private val LoAccentGlow = Color(0xFF58A6FF)
private val LoTextPrimary = Color(0xFFF0F4FF)
private val LoTextSecondary = Color(0xFF93A6BC)
private val LoScrim = Color(0xFF000000)

/**
* Steam launch-option picker — a Workshop-shaped modal window listing the
* game's appinfo `config.launch` entries. Tapping a row persists it as the
* game's default; the check mark moves to confirm and the window stays open.
*
* Stateless: data and callbacks are hoisted to the LaunchOptionsDialog wrapper.
*/
@Composable
internal fun StoreLaunchOptionsScreen(
gameTitle: String,
options: List<StoreLaunchOptionItem>,
selectedOption: StoreLaunchOptionItem?,
onSelect: (StoreLaunchOptionItem) -> Unit,
onClose: () -> Unit,
) {
BoxWithConstraints(
modifier =
Modifier
.fillMaxSize()
// Dim the game-detail screen behind so the modal reads as foreground.
.background(LoScrim.copy(alpha = 0.6f))
.windowInsetsPadding(WindowInsets.navigationBars),
contentAlignment = Alignment.Center,
) {
val dialogWidth = (maxWidth - 32.dp).coerceAtMost(560.dp)
val dialogMaxHeight = (maxHeight - 48.dp).coerceIn(220.dp, 640.dp)
Surface(
modifier =
Modifier
.widthIn(min = 320.dp, max = dialogWidth)
.fillMaxWidth()
.heightIn(max = dialogMaxHeight),
shape = RoundedCornerShape(14.dp),
color = LoBg,
border = BorderStroke(1.dp, LoBorder),
tonalElevation = 8.dp,
) {
Column(Modifier.fillMaxWidth()) {
LaunchOptionsHeader(
gameTitle = gameTitle,
optionCount = options.size,
onClose = onClose,
)
HorizontalDivider(color = LoBorder, thickness = 0.5.dp)
LazyColumn(
// fill = false: the window wraps short lists instead of
// stretching to the max height.
modifier = Modifier.fillMaxWidth().weight(1f, fill = false),
contentPadding = PaddingValues(vertical = 4.dp),
) {
itemsIndexed(options) { index, option ->
LaunchOptionPickerRow(
option = option,
selected = option == selectedOption,
onClick = { onSelect(option) },
)
if (index < options.lastIndex) {
HorizontalDivider(
color = Color.White.copy(alpha = 0.06f),
thickness = 1.dp,
modifier = Modifier.padding(horizontal = 14.dp),
)
}
}
}
}
}
}
}

@Composable
private fun LaunchOptionsHeader(
gameTitle: String,
optionCount: Int,
onClose: () -> Unit,
) {
Row(
modifier = Modifier.fillMaxWidth().padding(start = 16.dp, end = 8.dp, top = 10.dp, bottom = 10.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(10.dp),
) {
Box(
Modifier
.size(34.dp)
.clip(RoundedCornerShape(9.dp))
.background(LoAccent.copy(alpha = 0.16f)),
contentAlignment = Alignment.Center,
) {
Icon(
Icons.Outlined.RocketLaunch,
contentDescription = null,
tint = LoAccentGlow,
modifier = Modifier.size(19.dp),
)
}
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(1.dp)) {
Text(
stringResource(R.string.store_game_launch_options).uppercase(),
color = LoTextSecondary,
fontSize = 9.sp,
fontWeight = FontWeight.Bold,
letterSpacing = 0.9.sp,
)
Text(
gameTitle,
style = MaterialTheme.typography.titleSmall,
color = LoTextPrimary,
fontWeight = FontWeight.Bold,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}
Surface(
modifier =
Modifier.semantics {
contentDescription = "$optionCount launch options"
},
color = LoAccent.copy(alpha = 0.14f),
shape = RoundedCornerShape(7.dp),
) {
Text(
optionCount.toString(),
color = LoAccentGlow,
fontSize = 11.sp,
fontWeight = FontWeight.Bold,
modifier = Modifier.padding(horizontal = 9.dp, vertical = 3.dp),
)
}
IconButton(onClick = onClose, modifier = Modifier.size(36.dp)) {
Icon(
Icons.Outlined.Close,
contentDescription = "Close",
tint = LoTextSecondary,
modifier = Modifier.size(20.dp),
)
}
}
}

@Composable
private fun LaunchOptionPickerRow(
option: StoreLaunchOptionItem,
selected: Boolean,
onClick: () -> Unit,
) {
Row(
modifier =
Modifier
.fillMaxWidth()
.clickable(onClick = onClick)
.padding(horizontal = 14.dp, vertical = 11.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(11.dp),
) {
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) {
Text(
option.label,
color = if (selected) LoAccentGlow else LoTextPrimary,
fontSize = 13.sp,
fontWeight = FontWeight.SemiBold,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
)
Text(
buildString {
append(option.executable)
if (option.arguments.isNotBlank()) {
append(" · ")
append(option.arguments)
}
},
color = LoTextSecondary,
fontSize = 11.sp,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}
if (selected) {
Icon(
Icons.Outlined.Check,
contentDescription = null,
tint = LoAccentGlow,
modifier = Modifier.size(18.dp),
)
}
}
}
14 changes: 14 additions & 0 deletions app/src/main/app/shell/LibraryGameLaunchScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import androidx.compose.material.icons.outlined.Delete
import androidx.compose.material.icons.outlined.DesktopWindows
import androidx.compose.material.icons.outlined.History
import androidx.compose.material.icons.outlined.Refresh
import androidx.compose.material.icons.outlined.RocketLaunch
import androidx.compose.material.icons.outlined.Home
import androidx.compose.material.icons.outlined.PlayArrow
import androidx.compose.material.icons.outlined.Save
Expand Down Expand Up @@ -133,6 +134,8 @@ internal fun LibraryGameLaunchScreen(
showVerifyFiles: Boolean = true,
showCheckForUpdate: Boolean = true,
showWorkshop: Boolean = true,
showLaunchOptions: Boolean = false,
onLaunchOptions: () -> Unit = {},
playEnabled: Boolean = true,
playDisabledLabel: String? = null,
onBack: () -> Unit,
Expand Down Expand Up @@ -268,10 +271,12 @@ internal fun LibraryGameLaunchScreen(
showVerifyFiles = showVerifyFiles,
showCheckForUpdate = showCheckForUpdate,
showWorkshop = showWorkshop,
showLaunchOptions = showLaunchOptions,
areSteamActionsEnabled = areSteamActionsEnabled,
onVerifyFiles = onVerifyFiles,
onCheckForUpdate = onCheckForUpdate,
onWorkshop = onWorkshop,
onLaunchOptions = onLaunchOptions,
)
}

Expand Down Expand Up @@ -803,10 +808,12 @@ private fun SourceTag(
showVerifyFiles: Boolean = true,
showCheckForUpdate: Boolean = true,
showWorkshop: Boolean = true,
showLaunchOptions: Boolean = false,
areSteamActionsEnabled: Boolean = true,
onVerifyFiles: () -> Unit = {},
onCheckForUpdate: () -> Unit = {},
onWorkshop: () -> Unit = {},
onLaunchOptions: () -> Unit = {},
) {
var menuOpen by remember { mutableStateOf(false) }
var anchorHeightPx by remember { mutableStateOf(0) }
Expand Down Expand Up @@ -877,6 +884,13 @@ private fun SourceTag(
enabled = areSteamActionsEnabled,
) { menuOpen = false; onWorkshop() }
}
if (showLaunchOptions) {
LaunchSourceMenuItem(
icon = Icons.Outlined.RocketLaunch,
label = stringResource(R.string.store_game_launch_options),
enabled = areSteamActionsEnabled,
) { menuOpen = false; onLaunchOptions() }
}
}
}
}
Expand Down
18 changes: 17 additions & 1 deletion app/src/main/app/shell/StoreGameDetailScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import androidx.compose.material.icons.outlined.ExpandMore
import androidx.compose.material.icons.outlined.Extension
import androidx.compose.material.icons.outlined.Folder
import androidx.compose.material.icons.outlined.Refresh
import androidx.compose.material.icons.outlined.RocketLaunch
import androidx.compose.material.icons.outlined.SportsEsports
import androidx.compose.material.icons.outlined.Storage
import androidx.compose.material.icons.outlined.SystemUpdate
Expand Down Expand Up @@ -149,6 +150,8 @@ internal fun StoreGameDetailScreen(
showWorkshop: Boolean = false,
showVerifyFiles: Boolean = false,
areSteamActionsEnabled: Boolean = true,
showLaunchOptions: Boolean = false,
onLaunchOptions: () -> Unit = {},
dlcs: List<StoreDlcItem> = emptyList(),
selectedDlcIds: Set<Int> = emptySet(),
isDlcSelectionEnabled: Boolean = true,
Expand Down Expand Up @@ -186,7 +189,9 @@ internal fun StoreGameDetailScreen(
val showUpdateCta = updateCheckAvailable && isUpdateAvailable
val verifyFilesAvailable = showVerifyFiles && isInstalled
val workshopAvailable = showWorkshop && isInstalled
val sourceMenuEnabled = updateCheckAvailable || verifyFilesAvailable || workshopAvailable
val launchOptionsAvailable = showLaunchOptions && isInstalled
val sourceMenuEnabled =
updateCheckAvailable || verifyFilesAvailable || workshopAvailable || launchOptionsAvailable
val showDlcCard = dlcs.isNotEmpty()
val showActionColumn =
showDownloadCta || showUpdateCta ||
Expand Down Expand Up @@ -293,6 +298,7 @@ internal fun StoreGameDetailScreen(
showCheckForUpdate = updateCheckAvailable,
showVerifyFiles = verifyFilesAvailable,
showWorkshop = workshopAvailable,
showLaunchOptions = launchOptionsAvailable,
isCheckingForUpdate = isCheckingForUpdate,
areSteamActionsEnabled = areSteamActionsEnabled,
isUpdateCheckEnabled =
Expand All @@ -303,6 +309,7 @@ internal fun StoreGameDetailScreen(
onVerifyFiles = onVerifyFiles,
onCheckForUpdate = onCheckForUpdate,
onWorkshop = onWorkshop,
onLaunchOptions = onLaunchOptions,
)
}

Expand Down Expand Up @@ -780,12 +787,14 @@ private fun StoreSourceTag(
showCheckForUpdate: Boolean = false,
showVerifyFiles: Boolean = false,
showWorkshop: Boolean = false,
showLaunchOptions: Boolean = false,
isCheckingForUpdate: Boolean = false,
areSteamActionsEnabled: Boolean = true,
isUpdateCheckEnabled: Boolean = true,
onVerifyFiles: () -> Unit = {},
onCheckForUpdate: () -> Unit = {},
onWorkshop: () -> Unit = {},
onLaunchOptions: () -> Unit = {},
) {
var menuOpen by remember { mutableStateOf(false) }
var anchorHeightPx by remember { mutableIntStateOf(0) }
Expand Down Expand Up @@ -861,6 +870,13 @@ private fun StoreSourceTag(
enabled = areSteamActionsEnabled,
) { menuOpen = false; onWorkshop() }
}
if (showLaunchOptions) {
StoreSourceMenuItem(
icon = Icons.Outlined.RocketLaunch,
label = stringResource(R.string.store_game_launch_options),
enabled = areSteamActionsEnabled,
) { menuOpen = false; onLaunchOptions() }
}
}
}
}
Expand Down
Loading