mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 21:35:59 +00:00
Feat/store game artwork (#976)
This commit is contained in:
1 parent
fb0f73e300
commit
dc7ed61d38
11 files changed
+119
-17
No files matched your search
@@ -68,6 +68,7 @@ import java.io.File
|
||||
|
||||
private fun AddedGameArt.Slot.shape(): Triple<Dp, Dp, Dp> = when (this) {
|
||||
AddedGameArt.Slot.COVER -> Triple(28.dp, 41.dp, 5.dp)
|
||||
AddedGameArt.Slot.WIDE -> Triple(60.dp, 28.dp, 5.dp)
|
||||
AddedGameArt.Slot.BACKGROUND -> Triple(60.dp, 34.dp, 5.dp)
|
||||
AddedGameArt.Slot.LOGO -> Triple(60.dp, 26.dp, 5.dp)
|
||||
AddedGameArt.Slot.ICON -> Triple(30.dp, 30.dp, 7.dp)
|
||||
@@ -77,6 +78,7 @@ private fun AddedGameArt.Slot.shape(): Triple<Dp, Dp, Dp> = when (this) {
|
||||
private fun AddedGameArt.Slot.label(): String = stringResource(
|
||||
when (this) {
|
||||
AddedGameArt.Slot.COVER -> R.string.art_cover
|
||||
AddedGameArt.Slot.WIDE -> R.string.art_wide_cover
|
||||
AddedGameArt.Slot.BACKGROUND -> R.string.art_background
|
||||
AddedGameArt.Slot.LOGO -> R.string.art_logo
|
||||
AddedGameArt.Slot.ICON -> R.string.art_icon
|
||||
@@ -173,6 +175,25 @@ internal class ArtTarget(
|
||||
@Composable
|
||||
internal fun SteamGameArtEditor(
|
||||
game: com.droiddeck.launcher.frontend.Library.SteamGame, onClose: () -> Unit, onChanged: () -> Unit,
|
||||
) {
|
||||
val target = remember(game.appId) { ArtTarget.of(game) }
|
||||
ArtOnlyEditor(game.name, target, game, { SteamGameArt.describe(it, game) }, onClose, onChanged)
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun StoreGameArtEditor(folder: String, name: String, onClose: () -> Unit, onChanged: () -> Unit) {
|
||||
val app = LocalContext.current.applicationContext
|
||||
var game by remember(folder) { mutableStateOf<AddedGames.Game?>(null) }
|
||||
LaunchedEffect(folder) { game = withContext(Dispatchers.IO) { AddedGameEdits.game(app, folder) } }
|
||||
val g = game
|
||||
val target = remember(g?.appId) { g?.let { ArtTarget.of(it) } }
|
||||
ArtOnlyEditor(name, target, g, { c -> g?.let { AddedGameArt.describe(c, it) }.orEmpty() }, onClose, onChanged)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ArtOnlyEditor(
|
||||
name: String, target: ArtTarget?, refresh: Any?, describe: (Context) -> List<AddedGameArt.SlotState>,
|
||||
onClose: () -> Unit, onChanged: () -> Unit,
|
||||
) {
|
||||
val app = LocalContext.current.applicationContext
|
||||
val colors = MaterialTheme.colorScheme
|
||||
@@ -181,12 +202,11 @@ internal fun SteamGameArtEditor(
|
||||
var version by remember { mutableIntStateOf(0) }
|
||||
var arts by remember { mutableStateOf<List<AddedGameArt.SlotState>>(emptyList()) }
|
||||
var artSlot by remember { mutableStateOf<AddedGameArt.Slot?>(null) }
|
||||
val target = remember(game.appId) { ArtTarget.of(game) }
|
||||
LaunchedEffect(version, game) { arts = withContext(Dispatchers.IO) { SteamGameArt.describe(app, game) } }
|
||||
LaunchedEffect(version, refresh) { if (target != null) arts = withContext(Dispatchers.IO) { describe(app) } }
|
||||
val first = remember { FocusRequester() }
|
||||
LaunchedEffect(Unit) { focusWithinFrames({ false }) { first } }
|
||||
AppDialog(shown, close, "steamArtEditor", wide = false, maxWidth = 460.dp) {
|
||||
DialogTitleRow(game.name, onClose = close)
|
||||
AppDialog(shown, close, "artEditor", wide = false, maxWidth = 460.dp) {
|
||||
DialogTitleRow(name, onClose = close)
|
||||
val maxHeight = (LocalConfiguration.current.screenHeightDp * 0.72f).dp
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(6.dp),
|
||||
@@ -195,7 +215,7 @@ internal fun SteamGameArtEditor(
|
||||
Text(stringResource(R.string.edit_artwork), fontSize = 12.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(start = 4.dp, top = 2.dp))
|
||||
for (slot in AddedGameArt.Slot.values()) key(slot) {
|
||||
val state = arts.firstOrNull { it.slot == slot }
|
||||
FieldRow(slot.label(), focus = if (slot == AddedGameArt.Slot.COVER) first else null, onClick = { artSlot = slot }) {
|
||||
FieldRow(slot.label(), focus = if (slot == AddedGameArt.Slot.COVER) first else null, onClick = { if (target != null) artSlot = slot }) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
SlotThumb(slot, state?.file)
|
||||
if (state != null) ValueText(artSourceLabel(state.source), muted = true) else Loading()
|
||||
@@ -204,8 +224,9 @@ internal fun SteamGameArtEditor(
|
||||
}
|
||||
}
|
||||
}
|
||||
val chosen = target ?: return
|
||||
artSlot?.let { slot ->
|
||||
ArtChooserDialog(target, slot, arts.firstOrNull { it.slot == slot }, onBack = { artSlot = null }, onCloseAll = { artSlot = null; close() }) { version++; onChanged() }
|
||||
ArtChooserDialog(chosen, slot, arts.firstOrNull { it.slot == slot }, onBack = { artSlot = null }, onCloseAll = { artSlot = null; close() }) { version++; onChanged() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -155,6 +155,7 @@ private fun GameActions(g: Library.SteamGame, s: FrontEndState, a: FrontEndActio
|
||||
if (!s.shortcutPicker) GameShortcutMenu(g, a)
|
||||
if (!s.shortcutPicker && g.library == Library.ADDED && g.source == Library.ADDED && g.gameFiles != null) EditGameButton { onEdit(g) }
|
||||
else if (!s.shortcutPicker && g.library != Library.ADDED && g.source == Library.SOURCE_STEAM) EditGameButton { GamesDialogState.steamArt = g }
|
||||
else if (!s.shortcutPicker && g.library == Library.ADDED && g.source != Library.ADDED && g.gameFiles != null) EditGameButton { GamesDialogState.storeArt = g }
|
||||
BusyChip(s)
|
||||
}
|
||||
}
|
||||
@@ -330,6 +331,7 @@ internal object GamesDialogState {
|
||||
var editing by androidx.compose.runtime.mutableStateOf<EditRequest?>(null)
|
||||
var checking by androidx.compose.runtime.mutableStateOf<String?>(null)
|
||||
var steamArt by androidx.compose.runtime.mutableStateOf<Library.SteamGame?>(null)
|
||||
var storeArt by androidx.compose.runtime.mutableStateOf<Library.SteamGame?>(null)
|
||||
var behindEditor: Pair<List<com.droiddeck.launcher.frontend.AddedGames.Game>, Int>? = null
|
||||
}
|
||||
|
||||
@@ -371,6 +373,10 @@ private fun GamesDialogs(a: FrontEndActions, games: List<Library.SteamGame>) {
|
||||
st.steamArt?.let { game ->
|
||||
SteamGameArtEditor(games.firstOrNull { it.appId == game.appId && it.library != Library.ADDED } ?: game, onClose = { st.steamArt = null }, onChanged = { a.onSteamGameArtChanged(game.appId) })
|
||||
}
|
||||
st.storeArt?.let { game ->
|
||||
val folder = game.gameFiles?.path
|
||||
if (folder != null) StoreGameArtEditor(folder, game.name, onClose = { st.storeArt = null }, onChanged = { a.onAddedGamesChanged(listOf(folder)) })
|
||||
}
|
||||
st.editing?.let { request ->
|
||||
AddedGameEditor(
|
||||
request,
|
||||
@@ -391,8 +397,8 @@ private fun EditGameButton(onClick: () -> Unit) {
|
||||
val label = stringResource(R.string.common_edit)
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = Modifier.paneItem("game:edit").size(40.dp).clip(Shape12)
|
||||
.background(if (hot) pal.signal.copy(alpha = 0.18f) else colors.surface.copy(alpha = 0.55f))
|
||||
modifier = Modifier.paneItem("game:edit").downToFirstTile().size(44.dp).clip(Shape12)
|
||||
.background(if (hot) pal.signal.copy(alpha = 0.14f) else Color.White.copy(alpha = 0.03f))
|
||||
.glideBorder(hot, Shape12, pal.signal, pal.line2)
|
||||
.hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, role = androidx.compose.ui.semantics.Role.Button, onClick = onClick)
|
||||
.controllerConfirm(onClick = onClick)
|
||||
|
||||
Reference in new issue
Block a user