mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
feat: Change artwork for Steam games; remove “Show more” from the SteamGridDB search. (#939)
This commit is contained in:
1 parent
8726e43658
commit
bab09b798a
12 files changed
+292
-78
No files matched your search
@@ -610,6 +610,7 @@ class MainActivity : ComponentActivity() {
|
||||
val known = steamGames.mapNotNull { it.gameFiles?.path }.toSet()
|
||||
updateAddedGames(folders, then = { if (folders.any { it !in known }) fetchAddedGameArt() })
|
||||
},
|
||||
onSteamGameArtChanged = { appId -> refreshSteamGameArt(appId) },
|
||||
onAddedGameRemoved = { folder, appId, name -> removeAddedGame(folder, appId, name) },
|
||||
onAddedGamesArt = { on -> SessionPrefs.setAddedGamesArt(this, on); addedGamesArt = on; if (on) refreshAddedGames() },
|
||||
onSgdbKey = { key ->
|
||||
@@ -1440,6 +1441,13 @@ class MainActivity : ComponentActivity() {
|
||||
}, "added-games-update").start()
|
||||
}
|
||||
|
||||
private fun refreshSteamGameArt(appId: Int) {
|
||||
Thread({
|
||||
val fresh = com.droiddeck.launcher.frontend.Library.steamGames(this).firstOrNull { it.appId == appId } ?: return@Thread
|
||||
ui.post { steamGames = steamGames.map { if (it.appId == appId && it.library != Library.ADDED) fresh else it } }
|
||||
}, "steam-art-update").start()
|
||||
}
|
||||
|
||||
private fun removeAddedGame(folder: String, appId: Long?, name: String) {
|
||||
steamGames = steamGames.filterNot { it.library == Library.ADDED && it.gameFiles?.path == folder }
|
||||
Thread({ com.droiddeck.launcher.frontend.AddedGames.remove(this, java.io.File(folder), appId, name) }, "added-game-remove").start()
|
||||
|
||||
@@ -42,7 +42,7 @@ object AddedGameArt {
|
||||
|
||||
private val CHOSEN = Regex("""chosen-(\w+)\.(\w+)""")
|
||||
|
||||
private fun chosen(cache: File, slot: Slot): File? =
|
||||
internal fun chosen(cache: File, slot: Slot): File? =
|
||||
cache.listFiles { f -> CHOSEN.matchEntire(f.name)?.groupValues?.get(1) == slot.key }?.firstOrNull()
|
||||
|
||||
private val IMAGE = listOf("png", "jpg", "jpeg")
|
||||
@@ -117,36 +117,37 @@ object AddedGameArt {
|
||||
folderImages(game.folder).forEach { out.add(Option(FOLDER, it.path, it.path)) }
|
||||
val cache = cacheDir(context, game)
|
||||
val steamId = SteamMatch.resolve(context, game.folder.path, game.exe, game.name, legacy = File(cache, "steam-appid")).appId?.toString()
|
||||
val remote = when (slot) { Slot.COVER -> "library_600x900.jpg"; Slot.BACKGROUND -> "library_hero.jpg"; Slot.LOGO -> "logo.png"; Slot.ICON -> null }
|
||||
if (steamId != null && remote != null) {
|
||||
val url = "$CDN$steamId/$remote".takeIf { exists(it) } ?: steamAssetUrl(steamId, remote)
|
||||
if (url != null) out.add(Option(STEAM, url, url))
|
||||
}
|
||||
var status = SteamGridDb.Status.OK
|
||||
val key = SteamGridDb.key(context)
|
||||
if (key.isEmpty()) {
|
||||
status = SteamGridDb.Status.NO_KEY
|
||||
} else {
|
||||
cache.mkdirs()
|
||||
try {
|
||||
val gridId = remembered(File(cache, "sgdb-id"), SteamGridDb.keyChangedAt(context), retryMiss = true) {
|
||||
SteamGridDb.gameId(key, steamId?.toIntOrNull(), game.name)?.toString()
|
||||
}?.toIntOrNull()
|
||||
if (gridId == null) status = SteamGridDb.Status.NO_GAME
|
||||
else SteamGridDb.images(key, gridId, slot, if (slot == Slot.ICON) 3 else 5)
|
||||
.forEach { (thumb, full) -> out.add(Option(SGDB, thumb, full)) }
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "${game.name}: SteamGridDB failed (${e.javaClass.simpleName})")
|
||||
status = (e as? SteamGridDb.Failed)?.status ?: SteamGridDb.Status.SERVER
|
||||
}
|
||||
}
|
||||
if (steamId != null) steamOption(steamId, slot)?.let { out.add(it) }
|
||||
val (found, status) = sgdbChoices(context, File(cache, "sgdb-id"), steamId?.toIntOrNull(), game.name, slot)
|
||||
out.addAll(found)
|
||||
return Choices(out, status)
|
||||
}
|
||||
|
||||
internal fun steamOption(steamId: String, slot: Slot): Option? {
|
||||
val remote = when (slot) { Slot.COVER -> "library_600x900.jpg"; Slot.BACKGROUND -> "library_hero.jpg"; Slot.LOGO -> "logo.png"; Slot.ICON -> null } ?: return null
|
||||
val url = "$CDN$steamId/$remote".takeIf { exists(it) } ?: steamAssetUrl(steamId, remote) ?: return null
|
||||
return Option(STEAM, url, url)
|
||||
}
|
||||
|
||||
internal fun sgdbChoices(context: Context, marker: File, steamId: Int?, name: String, slot: Slot): Pair<List<Option>, SteamGridDb.Status> {
|
||||
val key = SteamGridDb.key(context)
|
||||
if (key.isEmpty()) return emptyList<Option>() to SteamGridDb.Status.NO_KEY
|
||||
marker.parentFile?.mkdirs()
|
||||
return try {
|
||||
val gridId = remembered(marker, SteamGridDb.keyChangedAt(context), retryMiss = true) {
|
||||
SteamGridDb.gameId(key, steamId, name)?.toString()
|
||||
}?.toIntOrNull() ?: return emptyList<Option>() to SteamGridDb.Status.NO_GAME
|
||||
SteamGridDb.images(key, gridId, slot, if (slot == Slot.ICON) 3 else 5).map { (thumb, full) -> Option(SGDB, thumb, full) } to SteamGridDb.Status.OK
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "$name: SteamGridDB failed (${e.javaClass.simpleName})")
|
||||
emptyList<Option>() to ((e as? SteamGridDb.Failed)?.status ?: SteamGridDb.Status.SERVER)
|
||||
}
|
||||
}
|
||||
|
||||
fun searchGames(context: Context, term: String): Found<SteamGridDb.Game> = sgdb(context) { SteamGridDb.search(it, term) }
|
||||
|
||||
fun gameImages(context: Context, id: Int, slot: Slot, page: Int): Found<Option> = sgdb(context) { key ->
|
||||
SteamGridDb.page(key, id, slot, page).map { (thumb, full) -> Option(SGDB, thumb, full) }
|
||||
fun gameImages(context: Context, id: Int, slot: Slot): Found<Option> = sgdb(context) { key ->
|
||||
SteamGridDb.page(key, id, slot).map { (thumb, full) -> Option(SGDB, thumb, full) }
|
||||
}
|
||||
|
||||
private fun <T> sgdb(context: Context, call: (String) -> List<T>): Found<T> {
|
||||
@@ -161,17 +162,21 @@ object AddedGameArt {
|
||||
}
|
||||
|
||||
fun choose(context: Context, game: AddedGames.Game, slot: Slot, option: Option): Boolean {
|
||||
if (!store(cacheDir(context, game), slot, option)) return false
|
||||
SessionPrefs.setAddedGameArtSource(context, game.folder.path, slot.key, option.group + "|" + option.full)
|
||||
return true
|
||||
}
|
||||
|
||||
internal fun store(cache: File, slot: Slot, option: Option): Boolean {
|
||||
val bytes = if (option.full.startsWith("https://")) get(option.full) else runCatching { File(option.full).readBytes() }.getOrNull()
|
||||
bytes ?: return false
|
||||
val ext = option.full.substringAfterLast('.', "png").substringBefore('?').lowercase().takeIf { it in CHOOSABLE + "ico" } ?: "png"
|
||||
val cache = cacheDir(context, game).apply { mkdirs() }
|
||||
cache.mkdirs()
|
||||
chosen(cache, slot)?.delete()
|
||||
val dst = File(cache, "chosen-${slot.key}.${if (ext == "jpeg") "jpg" else ext}")
|
||||
val tmp = File(cache, dst.name + ".tmp")
|
||||
tmp.writeBytes(bytes)
|
||||
if (!tmp.renameTo(dst)) return false
|
||||
SessionPrefs.setAddedGameArtSource(context, game.folder.path, slot.key, option.group + "|" + option.full)
|
||||
return true
|
||||
return tmp.renameTo(dst)
|
||||
}
|
||||
|
||||
fun chosenSource(context: Context, game: AddedGames.Game, slot: Slot): Pair<String, String> {
|
||||
|
||||
@@ -116,13 +116,13 @@ object Library {
|
||||
val installDir = INSTALL_DIR.find(text)?.groupValues?.get(1)?.trim()
|
||||
?.takeIf { it.isNotEmpty() && it != "." && it != ".." && '/' !in it && '\\' !in it }
|
||||
val gameFiles = installDir?.let { File(steamapps, "common/$it").takeIf(File::isDirectory) }
|
||||
out[appId] = SteamGame(
|
||||
out[appId] = SteamGameArt.withOverrides(context, SteamGame(
|
||||
appId, name, art, label, hero = hero, lastPlayed = lastPlayed,
|
||||
gameFiles = gameFiles,
|
||||
protonPrefix = protonPrefix(context, appId.toLong(), library, roots),
|
||||
icon = steamCacheImage(cache, appId, listOf("icon.jpg", "icon.png"))
|
||||
?: File(cache, appId.toString()).listFiles()?.firstOrNull { it.isFile && STEAM_ICON.matches(it.name) },
|
||||
)
|
||||
))
|
||||
}
|
||||
}
|
||||
return out.values.toList()
|
||||
@@ -152,7 +152,7 @@ object Library {
|
||||
)
|
||||
}
|
||||
|
||||
private fun steamCacheImage(cache: File, appId: Int, names: List<String>): File? {
|
||||
internal fun steamCacheImage(cache: File, appId: Int, names: List<String>): File? {
|
||||
val appDir = File(cache, appId.toString())
|
||||
val dirs = listOf(appDir) + appDir.listFiles()
|
||||
.orEmpty().filter { it.isDirectory }.sortedBy { it.name }
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.droiddeck.launcher.frontend
|
||||
|
||||
import android.content.Context
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import com.droiddeck.launcher.stores.SteamLiveShortcuts
|
||||
import java.io.File
|
||||
|
||||
object SteamGameArt {
|
||||
internal fun dir(context: Context, appId: Int) = File(context.filesDir, "steam-art/$appId")
|
||||
|
||||
private fun sourceFile(context: Context, appId: Int, slot: AddedGameArt.Slot) = File(dir(context, appId), "source-${slot.key}")
|
||||
|
||||
fun chosenFile(context: Context, appId: Int, slot: AddedGameArt.Slot): File? = AddedGameArt.chosen(dir(context, appId), slot)
|
||||
|
||||
fun withOverrides(context: Context, game: Library.SteamGame): Library.SteamGame {
|
||||
if (game.library == Library.ADDED || !dir(context, game.appId).isDirectory) return game
|
||||
val cover = chosenFile(context, game.appId, AddedGameArt.Slot.COVER)
|
||||
val hero = chosenFile(context, game.appId, AddedGameArt.Slot.BACKGROUND)
|
||||
val icon = chosenFile(context, game.appId, AddedGameArt.Slot.ICON)
|
||||
if (cover == null && hero == null && icon == null) return game
|
||||
return Library.SteamGame(
|
||||
game.appId, game.name, cover ?: game.art, game.library, game.gameId,
|
||||
hero ?: game.hero, game.lastPlayed, game.gameFiles, game.protonPrefix, icon ?: game.icon, game.source, game.storeId,
|
||||
)
|
||||
}
|
||||
|
||||
fun chosenSource(context: Context, appId: Int, slot: AddedGameArt.Slot): Pair<String, String> {
|
||||
val value = sourceFile(context, appId, slot).takeIf { it.isFile }?.readText()?.trim().orEmpty()
|
||||
return value.substringBefore('|') to value.substringAfter('|', "")
|
||||
}
|
||||
|
||||
fun describe(context: Context, game: Library.SteamGame): List<AddedGameArt.SlotState> {
|
||||
val cache = File(LinuxRuntime.rootDir(context), "root/.local/share/Steam/appcache/librarycache")
|
||||
val own = withOverrides(context, game)
|
||||
return AddedGameArt.Slot.values().map { slot ->
|
||||
chosenFile(context, game.appId, slot)?.let {
|
||||
return@map AddedGameArt.SlotState(slot, it, chosenSource(context, game.appId, slot).first.ifEmpty { AddedGameArt.FILE }, true)
|
||||
}
|
||||
val auto = when (slot) {
|
||||
AddedGameArt.Slot.COVER -> own.art
|
||||
AddedGameArt.Slot.BACKGROUND -> own.hero
|
||||
AddedGameArt.Slot.ICON -> own.icon
|
||||
AddedGameArt.Slot.LOGO -> Library.steamCacheImage(cache, game.appId, listOf("logo.png"))
|
||||
}
|
||||
AddedGameArt.SlotState(slot, auto, if (auto != null) AddedGameArt.STEAM else AddedGameArt.AUTO, false)
|
||||
}
|
||||
}
|
||||
|
||||
fun choices(context: Context, game: Library.SteamGame, slot: AddedGameArt.Slot): AddedGameArt.Choices {
|
||||
val out = ArrayList<AddedGameArt.Option>()
|
||||
AddedGameArt.steamOption(game.appId.toString(), slot)?.let { out.add(it) }
|
||||
val (found, status) = AddedGameArt.sgdbChoices(context, File(dir(context, game.appId), "sgdb-id"), game.appId, game.name, slot)
|
||||
out.addAll(found)
|
||||
return AddedGameArt.Choices(out, status)
|
||||
}
|
||||
|
||||
fun choose(context: Context, game: Library.SteamGame, slot: AddedGameArt.Slot, option: AddedGameArt.Option): Boolean {
|
||||
val folder = dir(context, game.appId)
|
||||
if (!AddedGameArt.store(folder, slot, option)) return false
|
||||
sourceFile(context, game.appId, slot).writeText(option.group + "|" + option.full)
|
||||
push(context, game, slot)
|
||||
return true
|
||||
}
|
||||
|
||||
fun reset(context: Context, game: Library.SteamGame, slot: AddedGameArt.Slot) {
|
||||
AddedGameArt.chosen(dir(context, game.appId), slot)?.delete()
|
||||
sourceFile(context, game.appId, slot).delete()
|
||||
push(context, game, slot)
|
||||
}
|
||||
|
||||
private fun push(context: Context, game: Library.SteamGame, slot: AddedGameArt.Slot) {
|
||||
val type = slot.assetType ?: return
|
||||
val file = chosenFile(context, game.appId, slot)
|
||||
AddedGamesPublisher.later(context) { SteamLiveShortcuts.setArt(context, game.appId.toLong(), type, file) }
|
||||
}
|
||||
}
|
||||
@@ -118,23 +118,21 @@ object SteamGridDb {
|
||||
.filter { it.optInt("id") > 0 && it.optString("name").isNotEmpty() }
|
||||
.map { Game(it.optInt("id"), it.optString("name"), it.optBoolean("verified")) }
|
||||
|
||||
internal fun path(id: Int, slot: AddedGameArt.Slot, page: Int): String {
|
||||
val base = when (slot) {
|
||||
internal fun path(id: Int, slot: AddedGameArt.Slot): String =
|
||||
when (slot) {
|
||||
AddedGameArt.Slot.COVER -> "grids/game/$id?dimensions=600x900&$QUERY"
|
||||
AddedGameArt.Slot.BACKGROUND -> "heroes/game/$id?$QUERY"
|
||||
AddedGameArt.Slot.LOGO -> "logos/game/$id?$QUERY"
|
||||
AddedGameArt.Slot.ICON -> "icons/game/$id?$QUERY"
|
||||
}
|
||||
return if (page > 0) "$base&page=$page" else base
|
||||
}
|
||||
|
||||
fun page(key: String, id: Int, slot: AddedGameArt.Slot, page: Int): List<Pair<String, String>> {
|
||||
val items = json(key, "$API/${path(id, slot, page)}")?.optJSONArray("data") ?: return emptyList()
|
||||
fun page(key: String, id: Int, slot: AddedGameArt.Slot): List<Pair<String, String>> {
|
||||
val items = json(key, "$API/${path(id, slot)}")?.optJSONArray("data") ?: return emptyList()
|
||||
return ranked(items, pngOnly = slot == AddedGameArt.Slot.LOGO || slot == AddedGameArt.Slot.ICON)
|
||||
}
|
||||
|
||||
fun images(key: String, id: Int, slot: AddedGameArt.Slot, limit: Int): List<Pair<String, String>> =
|
||||
page(key, id, slot, 0).take(limit)
|
||||
page(key, id, slot).take(limit)
|
||||
|
||||
internal fun ranked(items: JSONArray, pngOnly: Boolean): List<Pair<String, String>> =
|
||||
(0 until items.length()).map { items.getJSONObject(it) }
|
||||
|
||||
@@ -41,6 +41,7 @@ import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import android.content.Context
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.pluralStringResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -57,6 +58,7 @@ import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.frontend.AddedGameArt
|
||||
import com.droiddeck.launcher.frontend.AddedGameEdits
|
||||
import com.droiddeck.launcher.frontend.AddedGames
|
||||
import com.droiddeck.launcher.frontend.SteamGameArt
|
||||
import com.droiddeck.launcher.frontend.SteamGridDb
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -142,6 +144,71 @@ internal class EditPreview(
|
||||
}
|
||||
}
|
||||
|
||||
internal class ArtTarget(
|
||||
val name: String,
|
||||
val chosenRef: (Context, AddedGameArt.Slot) -> String,
|
||||
val choices: (Context, AddedGameArt.Slot) -> AddedGameArt.Choices,
|
||||
val set: (Context, AddedGameArt.Slot, AddedGameArt.Option) -> Unit,
|
||||
val reset: (Context, AddedGameArt.Slot) -> Unit,
|
||||
) {
|
||||
companion object {
|
||||
fun of(game: AddedGames.Game) = ArtTarget(
|
||||
game.name,
|
||||
{ c, slot -> AddedGameArt.chosenSource(c, game, slot).second },
|
||||
{ c, slot -> AddedGameArt.choices(c, game, slot) },
|
||||
{ c, slot, option -> AddedGameEdits.setArt(c, game.folder.path, slot, option) },
|
||||
{ c, slot -> AddedGameEdits.resetArt(c, game.folder.path, slot) },
|
||||
)
|
||||
|
||||
fun of(game: com.droiddeck.launcher.frontend.Library.SteamGame) = ArtTarget(
|
||||
game.name,
|
||||
{ c, slot -> SteamGameArt.chosenSource(c, game.appId, slot).second },
|
||||
{ c, slot -> SteamGameArt.choices(c, game, slot) },
|
||||
{ c, slot, option -> SteamGameArt.choose(c, game, slot, option) },
|
||||
{ c, slot -> SteamGameArt.reset(c, game, slot) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun SteamGameArtEditor(
|
||||
game: com.droiddeck.launcher.frontend.Library.SteamGame, onClose: () -> Unit, onChanged: () -> Unit,
|
||||
) {
|
||||
val app = LocalContext.current.applicationContext
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val shown = rememberShown(onClose)
|
||||
val close = { shown.targetState = false }
|
||||
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) { arts = withContext(Dispatchers.IO) { SteamGameArt.describe(app, game) } }
|
||||
val first = remember { FocusRequester() }
|
||||
LaunchedEffect(Unit) { focusWithinFrames({ false }) { first } }
|
||||
AppDialog(shown, close, "steamArtEditor", wide = false, maxWidth = 460.dp) {
|
||||
DialogTitleRow(game.name, onClose = close)
|
||||
val maxHeight = (LocalConfiguration.current.screenHeightDp * 0.72f).dp
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(6.dp),
|
||||
modifier = Modifier.fillMaxWidth().heightIn(max = maxHeight).verticalScroll(rememberScrollState()),
|
||||
) {
|
||||
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 }) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
SlotThumb(slot, state?.file)
|
||||
if (state != null) ValueText(artSourceLabel(state.source), muted = true) else Loading()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
artSlot?.let { slot ->
|
||||
ArtChooserDialog(target, slot, arts.firstOrNull { it.slot == slot }, onBack = { artSlot = null }, onCloseAll = { artSlot = null; close() }) { version++; onChanged() }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Loading() {
|
||||
androidx.compose.material3.CircularProgressIndicator(Modifier.size(14.dp), strokeWidth = 2.dp)
|
||||
@@ -283,7 +350,7 @@ internal fun AddedGameEditor(
|
||||
})
|
||||
artSlot?.let { slot ->
|
||||
val current = arts.firstOrNull { it.slot == slot }
|
||||
ArtChooserDialog(g, slot, current, onBack = { artSlot = null }, onCloseAll = { artSlot = null; close() }) { version++; onChanged() }
|
||||
ArtChooserDialog(ArtTarget.of(g), slot, current, onBack = { artSlot = null }, onCloseAll = { artSlot = null; close() }) { version++; onChanged() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,7 +415,7 @@ internal fun TextEntryDialog(title: String, initial: String, onDismiss: () -> Un
|
||||
@OptIn(ExperimentalLayoutApi::class)
|
||||
@Composable
|
||||
private fun ArtChooserDialog(
|
||||
game: AddedGames.Game, slot: AddedGameArt.Slot, current: AddedGameArt.SlotState?,
|
||||
target: ArtTarget, slot: AddedGameArt.Slot, current: AddedGameArt.SlotState?,
|
||||
onBack: () -> Unit, onCloseAll: () -> Unit, onChanged: () -> Unit,
|
||||
) {
|
||||
val ctx = LocalContext.current
|
||||
@@ -361,9 +428,9 @@ private fun ArtChooserDialog(
|
||||
var sgdb by remember { mutableStateOf(SteamGridDb.Status.OK) }
|
||||
var picking by remember { mutableStateOf(false) }
|
||||
var searching by remember { mutableStateOf(false) }
|
||||
val chosenRef = remember(current) { AddedGameArt.chosenSource(app, game, slot).second }
|
||||
val chosenRef = remember(current) { target.chosenRef(app, slot) }
|
||||
LaunchedEffect(slot) {
|
||||
val found = withContext(Dispatchers.IO) { runCatching { AddedGameArt.choices(app, game, slot) }.getOrNull() }
|
||||
val found = withContext(Dispatchers.IO) { runCatching { target.choices(app, slot) }.getOrNull() }
|
||||
options = found?.options ?: emptyList()
|
||||
sgdb = found?.sgdb ?: SteamGridDb.Status.SERVER
|
||||
}
|
||||
@@ -371,7 +438,7 @@ private fun ArtChooserDialog(
|
||||
LaunchedEffect(Unit) { focusWithinFrames({ false }) { first } }
|
||||
val apply: (AddedGameArt.Option) -> Unit = { option ->
|
||||
scope.launch {
|
||||
withContext(Dispatchers.IO) { AddedGameEdits.setArt(app, game.folder.path, slot, option) }
|
||||
withContext(Dispatchers.IO) { target.set(app, slot, option) }
|
||||
onChanged()
|
||||
back()
|
||||
}
|
||||
@@ -408,7 +475,7 @@ private fun ArtChooserDialog(
|
||||
PickerRow(Icons.Outlined.Image, stringResource(R.string.art_pick_image), null, focus = if (opts?.isEmpty() != false) first else null) { picking = true }
|
||||
PickerRow(null, stringResource(R.string.art_reset), null) {
|
||||
scope.launch {
|
||||
withContext(Dispatchers.IO) { AddedGameEdits.resetArt(app, game.folder.path, slot) }
|
||||
withContext(Dispatchers.IO) { target.reset(app, slot) }
|
||||
onChanged()
|
||||
back()
|
||||
}
|
||||
@@ -419,7 +486,7 @@ private fun ArtChooserDialog(
|
||||
apply(AddedGameArt.Option(AddedGameArt.FILE, file.path, file.path))
|
||||
})
|
||||
if (searching) SgdbSearchDialog(
|
||||
game, slot, current,
|
||||
target, slot, current,
|
||||
onBack = { searching = false }, onCloseAll = { searching = false; onCloseAll() }, onPick = apply,
|
||||
)
|
||||
}
|
||||
@@ -446,7 +513,7 @@ private fun SgdbNote(status: SteamGridDb.Status) {
|
||||
@OptIn(ExperimentalLayoutApi::class)
|
||||
@Composable
|
||||
private fun SgdbSearchDialog(
|
||||
game: AddedGames.Game, slot: AddedGameArt.Slot, current: AddedGameArt.SlotState?,
|
||||
target: ArtTarget, slot: AddedGameArt.Slot, current: AddedGameArt.SlotState?,
|
||||
onBack: () -> Unit, onCloseAll: () -> Unit, onPick: (AddedGameArt.Option) -> Unit,
|
||||
) {
|
||||
val app = LocalContext.current.applicationContext
|
||||
@@ -454,28 +521,23 @@ private fun SgdbSearchDialog(
|
||||
val scope = rememberCoroutineScope()
|
||||
val shown = rememberShown(onBack)
|
||||
val back = { shown.targetState = false }
|
||||
var query by remember { mutableStateOf(game.name) }
|
||||
var query by remember { mutableStateOf(target.name) }
|
||||
var matches by remember { mutableStateOf<List<SteamGridDb.Game>?>(null) }
|
||||
var picked by remember { mutableStateOf<SteamGridDb.Game?>(null) }
|
||||
var images by remember { mutableStateOf<List<AddedGameArt.Option>>(emptyList()) }
|
||||
var page by remember { mutableIntStateOf(0) }
|
||||
var more by remember { mutableStateOf(false) }
|
||||
var busy by remember { mutableStateOf(true) }
|
||||
var status by remember { mutableStateOf(SteamGridDb.Status.OK) }
|
||||
val chosenRef = remember(current) { AddedGameArt.chosenSource(app, game, slot).second }
|
||||
val chosenRef = remember(current) { target.chosenRef(app, slot) }
|
||||
val slotName = slot.label()
|
||||
val showImages: (SteamGridDb.Game) -> Unit = { found ->
|
||||
scope.launch {
|
||||
picked = found
|
||||
images = emptyList()
|
||||
page = 0
|
||||
more = false
|
||||
busy = true
|
||||
status = SteamGridDb.Status.OK
|
||||
val result = withContext(Dispatchers.IO) { AddedGameArt.gameImages(app, found.id, slot, 0) }
|
||||
val result = withContext(Dispatchers.IO) { AddedGameArt.gameImages(app, found.id, slot) }
|
||||
images = result.items
|
||||
status = result.status
|
||||
more = result.items.isNotEmpty()
|
||||
busy = false
|
||||
}
|
||||
}
|
||||
@@ -492,19 +554,6 @@ private fun SgdbSearchDialog(
|
||||
if (sure != null) showImages(sure)
|
||||
}
|
||||
}
|
||||
val loadMore: () -> Unit = {
|
||||
val found = picked
|
||||
if (found != null && !busy) scope.launch {
|
||||
busy = true
|
||||
val result = withContext(Dispatchers.IO) { AddedGameArt.gameImages(app, found.id, slot, page + 1) }
|
||||
val fresh = result.items.filter { next -> images.none { it.full == next.full } }
|
||||
images = images + fresh
|
||||
page += 1
|
||||
more = fresh.isNotEmpty()
|
||||
if (result.status != SteamGridDb.Status.OK) status = result.status
|
||||
busy = false
|
||||
}
|
||||
}
|
||||
LaunchedEffect(Unit) { search() }
|
||||
AppDialog(shown, back, "sgdbSearch", wide = false, maxWidth = 460.dp) {
|
||||
DialogTitleRow(stringResource(R.string.art_sgdb_title, slotName), onClose = { onCloseAll() }, leading = {
|
||||
@@ -542,7 +591,6 @@ private fun SgdbSearchDialog(
|
||||
if (images.isEmpty() && !busy && status == SteamGridDb.Status.OK) {
|
||||
Text(stringResource(R.string.art_sgdb_none), fontSize = 12.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(start = 2.dp, top = 4.dp))
|
||||
}
|
||||
if (more && !busy) PickerRow(null, stringResource(R.string.art_sgdb_more), null) { loadMore() }
|
||||
if (list.size > 1) PickerRow(null, stringResource(R.string.art_sgdb_other_games), null) { picked = null }
|
||||
}
|
||||
if (busy) androidx.compose.material3.LinearProgressIndicator(Modifier.fillMaxWidth().padding(vertical = 8.dp))
|
||||
|
||||
@@ -67,7 +67,7 @@ internal fun GamesPage(s: FrontEndState, a: FrontEndActions, selected: String, o
|
||||
val games = remember(s.steamGames) { s.steamGames.sortedByDescending { it.lastPlayed } }
|
||||
val narrow = LocalNarrowPane.current
|
||||
val current = games.firstOrNull { "app:${it.appId}" == selected } ?: games.firstOrNull()
|
||||
GamesDialogs(a)
|
||||
GamesDialogs(a, s.steamGames)
|
||||
val onAdd: (() -> Unit)? = if (s.shortcutPicker) null else ({ GamesDialogState.adding = true })
|
||||
val pageContext = androidx.compose.ui.platform.LocalContext.current
|
||||
val onEdit: (Library.SteamGame) -> Unit = { g ->
|
||||
@@ -154,6 +154,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 }
|
||||
BusyChip(s)
|
||||
}
|
||||
}
|
||||
@@ -328,11 +329,12 @@ internal object GamesDialogState {
|
||||
var summary by androidx.compose.runtime.mutableStateOf<Pair<List<com.droiddeck.launcher.frontend.AddedGames.Game>, Int>?>(null)
|
||||
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 behindEditor: Pair<List<com.droiddeck.launcher.frontend.AddedGames.Game>, Int>? = null
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GamesDialogs(a: FrontEndActions) {
|
||||
private fun GamesDialogs(a: FrontEndActions, games: List<Library.SteamGame>) {
|
||||
val ctx = androidx.compose.ui.platform.LocalContext.current
|
||||
val scope = androidx.compose.runtime.rememberCoroutineScope()
|
||||
val st = GamesDialogState
|
||||
@@ -366,6 +368,9 @@ private fun GamesDialogs(a: FrontEndActions) {
|
||||
a.onAddedGameRemoved(folder, appId, name)
|
||||
}, onDismiss = { st.summary = null; st.checking = null })
|
||||
}
|
||||
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.editing?.let { request ->
|
||||
AddedGameEditor(
|
||||
request,
|
||||
|
||||
@@ -155,6 +155,7 @@ class FrontEndActions(
|
||||
val onSyncGameFiles: () -> Unit = {},
|
||||
val onAddGameExe: (path: String) -> Unit = {},
|
||||
val onAddedGamesChanged: (folders: List<String>) -> Unit = {},
|
||||
val onSteamGameArtChanged: (appId: Int) -> Unit = {},
|
||||
val onAddedGameRemoved: (folder: String, appId: Long?, name: String) -> Unit = { _, _, _ -> },
|
||||
val onAddedGamesArt: (Boolean) -> Unit = {},
|
||||
val onSgdbKey: (String) -> Unit = {},
|
||||
|
||||
Reference in new issue
Block a user