mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 05:46:03 +00:00
Add opt-in GOG achievements through Comet (#651)
This commit is contained in:
1 parent
3ed756b067
commit
8f36eb7f54
35 files changed
+1364
-45
No files matched your search
@@ -0,0 +1,96 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.slideInVertically
|
||||
import androidx.compose.animation.slideOutVertically
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import coil.compose.AsyncImage
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.session.SessionEvents
|
||||
import com.droiddeck.launcher.stores.AchievementNotifications
|
||||
import kotlinx.coroutines.delay
|
||||
|
||||
@Composable
|
||||
internal fun AchievementNotificationOverlay() {
|
||||
val unlock = AchievementNotifications.pending.firstOrNull()
|
||||
var visible by remember(unlock) { mutableStateOf(false) }
|
||||
LaunchedEffect(unlock) {
|
||||
if (unlock == null) return@LaunchedEffect
|
||||
visible = true
|
||||
SessionEvents.record("achievement.notification-shown", mapOf("achievementId" to unlock.id))
|
||||
delay(5_000)
|
||||
visible = false
|
||||
delay(Motion.ms(220).toLong())
|
||||
AchievementNotifications.dismiss(unlock)
|
||||
}
|
||||
Box(Modifier.fillMaxSize().padding(20.dp), contentAlignment = Alignment.BottomEnd) {
|
||||
AnimatedVisibility(
|
||||
visible, enter = fadeIn(Motion.tw(220)) + slideInVertically(Motion.tw(300)) { it / 2 },
|
||||
exit = fadeOut(Motion.tw(180)) + slideOutVertically(Motion.tw(220)) { it / 3 },
|
||||
) { if (unlock != null) AchievementNotificationCard(unlock) }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AchievementNotificationCard(unlock: AchievementNotifications.Unlock) {
|
||||
val pal = LocalPalette.current
|
||||
val shape = RoundedCornerShape(16.dp)
|
||||
Row(
|
||||
Modifier.widthIn(max = 360.dp).clip(shape).background(pal.surface.copy(alpha = 0.97f))
|
||||
.border(1.dp, pal.signal.copy(alpha = 0.65f), shape).padding(14.dp)
|
||||
.testTag("achievement-notification"),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
Box(Modifier.size(48.dp).clip(RoundedCornerShape(10.dp)).background(pal.surfaceVariant), contentAlignment = Alignment.Center) {
|
||||
Trophy(26.dp, description = null)
|
||||
if (unlock.icon != null) AsyncImage(unlock.icon, null, contentScale = ContentScale.Crop, modifier = Modifier.fillMaxSize())
|
||||
}
|
||||
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(3.dp)) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(5.dp)) {
|
||||
Trophy(13.dp, description = null)
|
||||
Text(stringResource(R.string.achievement_unlocked).uppercase(), fontSize = 10.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 0.8.sp, color = pal.signal)
|
||||
}
|
||||
Text(unlock.name, color = pal.onBackground, fontSize = 15.sp, fontWeight = FontWeight.Bold, maxLines = 2, overflow = TextOverflow.Ellipsis)
|
||||
if (unlock.game.isNotBlank()) Text(unlock.game, color = pal.onSurfaceVariant, fontSize = 12.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(widthDp = 420, heightDp = 150)
|
||||
@Composable
|
||||
private fun AchievementNotificationPreview() = DroidDeckTheme {
|
||||
Box(Modifier.padding(20.dp)) {
|
||||
AchievementNotificationCard(AchievementNotifications.Unlock("1", "first", "First Steps", "", null, "Hollow Valley"))
|
||||
}
|
||||
}
|
||||
@@ -495,8 +495,8 @@ internal fun LaunchSettings(s: FrontEndState, a: FrontEndActions, host: MenuHost
|
||||
if (controller != null) add { m -> SettingCard(stringResource(R.string.setup_card_controls), stringResource(R.string.setup_card_controls_hint), "card:controls", m, controller.onMapping) }
|
||||
// An Epic game's own launch choices, kept in its sidecar so a launch from the Steam client
|
||||
// honours them too (droiddeck-store-launch reads the same file).
|
||||
// Epic's launch choices; cloud saves live in the game's Cloud saves view, so a GOG game has no card.
|
||||
val cardStore = com.droiddeck.launcher.stores.Store.byId(game?.source.orEmpty())?.takeIf { it == com.droiddeck.launcher.stores.Store.EPIC }
|
||||
// Store launch choices; cloud saves have their own view.
|
||||
val cardStore = com.droiddeck.launcher.stores.Store.byId(game?.source.orEmpty())?.takeIf { it == com.droiddeck.launcher.stores.Store.EPIC || it == com.droiddeck.launcher.stores.Store.GOG }
|
||||
if (cardStore != null && game?.gameFiles != null) add { m ->
|
||||
Box(m) {
|
||||
StoreLaunchCard(host, game.gameFiles!!, cardStore)
|
||||
@@ -537,7 +537,14 @@ private fun StoreLaunchCard(host: MenuHost, folder: java.io.File, store: com.dro
|
||||
val options = sidecar?.epic ?: com.droiddeck.launcher.stores.EpicOptions()
|
||||
val epic = store == com.droiddeck.launcher.stores.Store.EPIC
|
||||
val key = "store-" + store.id
|
||||
val value = buildList {
|
||||
val value = if (!epic) stringResource(when {
|
||||
!com.droiddeck.launcher.stores.gog.GogComet.enabled(appContext) || sidecar?.achievements == false -> R.string.gog_achievements_off
|
||||
com.droiddeck.launcher.stores.gog.GogComet.status == "sign-in-needed" -> R.string.gog_achievements_signin
|
||||
com.droiddeck.launcher.stores.gog.GogComet.status in listOf("service-unavailable", "credentials-unavailable", "not-installed") -> R.string.gog_achievements_unavailable
|
||||
com.droiddeck.launcher.stores.gog.GogComet.status == "uploaded" -> R.string.gog_achievements_uploaded
|
||||
com.droiddeck.launcher.stores.gog.GogComet.status == "pending-upload" || com.droiddeck.launcher.stores.gog.GogComet.status == "unlocked-locally" -> R.string.gog_achievements_pending
|
||||
else -> R.string.gog_achievements_on
|
||||
}) else buildList {
|
||||
if (epic && options.offline) add(stringResource(R.string.epic_card_offline))
|
||||
else if (epic && options.eos) add(stringResource(R.string.epic_card_eos))
|
||||
}.ifEmpty { listOf(stringResource(R.string.epic_card_none)) }.joinToString(" · ")
|
||||
@@ -556,6 +563,16 @@ private fun StoreLaunchCard(host: MenuHost, folder: java.io.File, store: com.dro
|
||||
host.open = if (host.open == key) null else key
|
||||
}
|
||||
AnchoredMenu(host.open == key, onDismiss = { if (host.open == key) host.open = null }, title = store.shortLabel) { first ->
|
||||
if (!epic) {
|
||||
MenuItem(stringResource(R.string.gog_achievements), checked = sidecar?.achievements != false, focusRequester = first,
|
||||
detail = if (!com.droiddeck.launcher.stores.gog.GogComet.enabled(appContext)) stringResource(R.string.gog_achievements_enable_store) else null) {
|
||||
val on = sidecar?.achievements == false
|
||||
Thread({
|
||||
val written = runCatching { com.droiddeck.launcher.stores.StoreGameSidecar.updateAchievements(folder, on) }.getOrNull()
|
||||
com.droiddeck.launcher.stores.StoresState.post { sidecar = written ?: sidecar }
|
||||
}, "gog-game-achievements").start()
|
||||
}
|
||||
}
|
||||
if (epic) {
|
||||
MenuItem(stringResource(R.string.epic_eos), checked = options.eos, focusRequester = first) { set { it.copy(eos = !it.eos) } }
|
||||
MenuItem(stringResource(R.string.epic_offline), checked = options.offline) { set { it.copy(offline = !it.offline) } }
|
||||
|
||||
@@ -78,7 +78,7 @@ internal class AchievementsState(val list: List<Achievement>?, val reason: Reaso
|
||||
internal fun rememberAchievements(game: StoreAchievements.Game?): AchievementsState? {
|
||||
val ctx = LocalContext.current.applicationContext
|
||||
var state by remember(game) { mutableStateOf(if (game == null) null else AchievementsState.READING) }
|
||||
LaunchedEffect(game) {
|
||||
LaunchedEffect(game, StoreAchievements.revision) {
|
||||
if (game == null) return@LaunchedEffect
|
||||
val source = StoreAchievements.forSource(game.source) ?: return@LaunchedEffect
|
||||
val cached = withContext(Dispatchers.IO) { source.cached(ctx, game) }
|
||||
@@ -101,8 +101,8 @@ internal fun achievementsNote(state: AchievementsState, label: String): String?
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun Trophy(size: Dp = 18.dp, modifier: Modifier = Modifier) {
|
||||
Icon(Icons.Filled.EmojiEvents, stringResource(R.string.achievements_all), modifier.size(size), tint = TrophyGold)
|
||||
internal fun Trophy(size: Dp = 18.dp, modifier: Modifier = Modifier, description: String? = stringResource(R.string.achievements_all)) {
|
||||
Icon(Icons.Filled.EmojiEvents, description, modifier.size(size), tint = TrophyGold)
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
||||
@@ -553,6 +553,14 @@ internal fun storesSettingsStep(at: Rect, s: androidx.compose.runtime.State<Fron
|
||||
}
|
||||
// The queue's two knobs as one compact row, the same control the Downloads page has.
|
||||
Column(Modifier.fillMaxWidth().padding(horizontal = 14.dp, vertical = 11.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) { DownloadControls(st, a) }
|
||||
val context = androidx.compose.ui.platform.LocalContext.current
|
||||
var gogAchievements by androidx.compose.runtime.remember { androidx.compose.runtime.mutableStateOf(com.droiddeck.launcher.stores.gog.GogComet.enabled(context)) }
|
||||
SettingsRow(stringResource(R.string.gog_achievements), stringResource(R.string.gog_achievements_hint)) {
|
||||
ToggleSwitch(gogAchievements, label = stringResource(R.string.gog_achievements)) {
|
||||
gogAchievements = it
|
||||
com.droiddeck.launcher.stores.gog.GogComet.setEnabled(context, it)
|
||||
}
|
||||
}
|
||||
StoresEngineRow()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user