feat: Add the Game Jolt store (#1986)

This commit is contained in:
FX1922 authored and GitHub committed 2026-11-02 10:05:30 -05:00
1 parent 0050b5eb6b
commit 3583643a11
74 files changed
+3215 -275

No files matched your search

@@ -701,6 +701,7 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
StoreTheme(com.droiddeck.launcher.stores.Store.XBOX) { XboxStoreDialogs() }
com.droiddeck.launcher.stores.StoresState.pendingInstall?.let { item -> StoreTheme(item.store) { InstallWhere(item) } }
com.droiddeck.launcher.stores.StoresState.itchPicking?.let { item -> StoreTheme(item.store) { ItchBuildPicker(item) { com.droiddeck.launcher.stores.StoresState.itchPicking = null } } }
com.droiddeck.launcher.stores.StoresState.gameJoltPicking?.let { item -> StoreTheme(item.store) { GameJoltBuildPicker(item) { com.droiddeck.launcher.stores.StoresState.gameJoltPicking = null } } }
StepsLayer(screenAt)
appToChooseDisplay?.let { app ->
@@ -98,6 +98,7 @@ import com.droiddeck.launcher.stores.StoreInstallRoot
import com.droiddeck.launcher.stores.StoreLanguage
import com.droiddeck.launcher.stores.StoreSizes
import com.droiddeck.launcher.stores.StoresState
import com.droiddeck.launcher.stores.gamejolt.GameJoltApi
import com.droiddeck.launcher.stores.battlenet.BattleNetInstall
import com.droiddeck.launcher.stores.download.DownloadQueue
import com.droiddeck.launcher.stores.download.DownloadState
@@ -139,7 +140,7 @@ internal enum class GameTab { ABOUT, ACHIEVEMENTS, LAUNCH, SAVES, INSTALL }
@Composable
internal fun GameDetail(
key: String, s: FrontEndState, a: FrontEndActions, lead: FocusRequester, backLabel: String, hopRail: String?, onBack: () -> Unit,
key: String, s: FrontEndState, a: FrontEndActions, lead: FocusRequester, backLabel: String, hopRail: String?, onBack: () -> Unit, inStore: Boolean = false,
) {
val narrow = LocalNarrowPane.current
val stacked = narrow || LocalConfiguration.current.screenWidthDp < 700
@@ -218,6 +219,7 @@ internal fun GameDetail(
if (!s.shortcutPicker) CompositionLocalProvider(LocalPillButtons provides true) {
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
if (installed != null && installed.sidecar.store == Store.ITCH) ItchCheckButton(installed)
if (installed != null && installed.sidecar.store == Store.GAMEJOLT) GameJoltCheckButton(installed)
RemoveButton(title, game, installed, a)
}
}
@@ -232,7 +234,7 @@ internal fun GameDetail(
color = MaterialTheme.colorScheme.error, maxLines = 3, overflow = TextOverflow.Ellipsis,
)
Spacer(Modifier.height(2.dp))
GameCapsule(scores) { GameActions(store, id, game, item, installed, s, a, Modifier.focusRequester(lead), compactMenu = stacked) }
GameCapsule(scores) { GameActions(store, id, game, item, installed, s, a, Modifier.focusRequester(lead), compactMenu = stacked, inStore = inStore) }
}
}
if (StoresMotion.heroLands) header() else Rise(1) { header() }
@@ -382,7 +384,7 @@ private fun GameTitle(title: String, logo: Any?, titleSize: TextUnit) {
@Composable
internal fun GameActions(
store: Store?, id: String?, game: Library.SteamGame?, item: CatalogItem?, installed: InstalledStoreGame?,
s: FrontEndState, a: FrontEndActions, leadOn: Modifier, compactMenu: Boolean = false,
s: FrontEndState, a: FrontEndActions, leadOn: Modifier, compactMenu: Boolean = false, inStore: Boolean = false,
) {
val ctx = LocalContext.current
val storeKey = if (store != null && id != null) "${store.id}:$id" else null
@@ -409,10 +411,16 @@ internal fun GameActions(
if (compactMenu) GameMoreMenu(game, a) else {
FileButtons(game, a)
GameShortcutMenu(game, a)
EditArtButton(game)
}
}
if (store == Store.ITCH && installed != null) ItchUpdateButton(installed, download == null && StoresState.uninstalling[installed.key] == null)
if (store == Store.GAMEJOLT && installed != null) GameJoltUpdateButton(installed, download == null && StoresState.uninstalling[installed.key] == null)
if (store == Store.GAMEJOLT && installed != null) GameJoltVersionButton(installed, download == null && StoresState.uninstalling[installed.key] == null)
if (inStore && store == Store.GAMEJOLT && installed != null) {
SecondaryButton(stringResource(R.string.stores_view_on, Store.GAMEJOLT.shortLabel)) {
openUrl(ctx, item?.storeUrl.orEmpty().ifBlank { GameJoltApi.pageUrl("game", installed.sidecar.id) })
}
}
if (store == Store.GOG && installed != null) GogMaintenanceActions(installed)
if (store == Store.XBOX && id != null) XboxInstalledStream(id, game?.name ?: item?.title.orEmpty(), item)
if (store == Store.XBOX && installed != null && id != null) {
@@ -435,6 +443,7 @@ internal fun GameActions(
}
SecondaryButton(stringResource(R.string.bnet_open)) { a.onBattleNet() }
}
if (game != null && !compactMenu) EditArtButton(game)
}
download != null -> {
ActionChip(downloadLabel(download), ok = false)
@@ -482,7 +491,7 @@ internal fun GameActions(
}
if (!item.accessible) SecondaryButton(buyLabel(item)) { openStoreUrl(ctx, item) }
}
item != null && item.store == Store.ITCH && item.isFree -> {
item != null && (item.store == Store.ITCH || item.store == Store.GAMEJOLT) && item.isFree -> {
InstallButton(stringResource(R.string.stores_install), leadOn) { StoresState.requestInstall(ctx, item) }
SecondaryButton(stringResource(R.string.stores_view_on, item.store.shortLabel)) { openStoreUrl(ctx, item) }
}
@@ -0,0 +1,157 @@
package com.droiddeck.launcher.ui
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.LinearProgressIndicator
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.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.droiddeck.launcher.R
import com.droiddeck.launcher.stores.gamejolt.GameJoltBrowse
import com.droiddeck.launcher.stores.gamejolt.GameJoltBrowseState
import com.droiddeck.launcher.stores.gamejolt.GameJoltQuery
@Composable
internal fun GameJoltBrowseBar(showMature: Boolean) {
val ctx = LocalContext.current
val query = GameJoltBrowseState.query
var picking by remember { mutableStateOf(false) }
LaunchedEffect(Unit) { if (GameJoltBrowseState.items.isEmpty()) GameJoltBrowseState.more(ctx) }
fun toggle(set: Set<String>, value: String): Set<String> = if (value in set) set - value else set + value
Column(Modifier.fillMaxWidth().padding(top = 6.dp, bottom = 8.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {
ChipRow {
BrowseDropdown(sectionLabel(query.section)) { first, close ->
GameJoltBrowse.sections.forEachIndexed { index, section ->
MenuItem(sectionLabel(section), query.section == section, focusRequester = if (index == 0) first else null) {
GameJoltBrowseState.choose(ctx, query.copy(section = section))
close()
}
}
}
BrowseDropdown(priceLabel(query.price)) { first, close ->
GameJoltBrowse.prices.forEachIndexed { index, price ->
MenuItem(priceLabel(price), query.price == price, focusRequester = if (index == 0) first else null) {
GameJoltBrowseState.choose(ctx, query.copy(price = price))
close()
}
}
}
val anyPlatform = stringResource(R.string.stores_itch_platform_any)
BrowseDropdown(browseSummary(GameJoltBrowse.systems.filter { it in query.os }.map { systemLabel(it) }, anyPlatform)) { first, _ ->
MenuItem(anyPlatform, query.os.isEmpty(), focusRequester = first) { GameJoltBrowseState.choose(ctx, query.copy(os = emptySet())) }
for (os in GameJoltBrowse.systems) MenuItem(systemLabel(os), os in query.os) { GameJoltBrowseState.choose(ctx, query.copy(os = toggle(query.os, os))) }
}
BrowseDropdown(browseSummary(GameJoltBrowse.browsers.filter { it in query.browser }.map { browserLabel(it) }, stringResource(R.string.stores_gamejolt_filter_browser))) { first, _ ->
GameJoltBrowse.browsers.forEachIndexed { index, browser ->
MenuItem(browserLabel(browser), browser in query.browser, focusRequester = if (index == 0) first else null) { GameJoltBrowseState.choose(ctx, query.copy(browser = toggle(query.browser, browser))) }
}
}
val maturities = GameJoltBrowse.maturities.filter { showMature || it != "adult" }
BrowseDropdown(browseSummary(maturities.filter { it in query.maturity }.map { maturityLabel(it) }, stringResource(R.string.stores_gamejolt_filter_maturity))) { first, _ ->
maturities.forEachIndexed { index, maturity ->
MenuItem(maturityLabel(maturity), maturity in query.maturity, focusRequester = if (index == 0) first else null) { GameJoltBrowseState.choose(ctx, query.copy(maturity = toggle(query.maturity, maturity))) }
}
}
BrowseDropdown(browseSummary(GameJoltBrowse.statuses.filter { it in query.status }.map { statusLabel(it) }, stringResource(R.string.stores_gamejolt_filter_status))) { first, _ ->
GameJoltBrowse.statuses.forEachIndexed { index, status ->
MenuItem(statusLabel(status), status in query.status, focusRequester = if (index == 0) first else null) { GameJoltBrowseState.choose(ctx, query.copy(status = toggle(query.status, status))) }
}
}
val partners = stringResource(R.string.stores_gamejolt_partners)
BrowseDropdown(if (query.partners) partners else stringResource(R.string.stores_gamejolt_filter_partners)) { first, _ ->
MenuItem(partners, query.partners, focusRequester = first) { GameJoltBrowseState.choose(ctx, query.copy(partners = !query.partners)) }
}
}
ChipRow {
for (tag in query.tags) BrowseChip("$tag ✕", true) { GameJoltBrowseState.choose(ctx, query.copy(tags = query.tags - tag)) }
BrowseChip(stringResource(R.string.stores_itch_tag_add), false) { picking = true }
}
}
if (picking) TextEntryDialog(
stringResource(R.string.stores_itch_tag_title), "", number = false, confirm = stringResource(R.string.common_ok),
onSubmit = { value -> GameJoltBrowse.tagSlug(value).takeIf { it.isNotEmpty() }?.let { GameJoltBrowseState.choose(ctx, query.copy(tags = (query.tags + it).distinct())) } },
onDismiss = { picking = false }, id = "gamejolt-tag",
)
}
@Composable
internal fun GameJoltLoadMore() {
val ctx = LocalContext.current
val count = GameJoltBrowseState.items.size
LaunchedEffect(Unit) { GameJoltBrowseState.more(ctx) }
if (GameJoltBrowseState.loading) LinearProgressIndicator(Modifier.fillMaxWidth().padding(vertical = 12.dp))
else if (GameJoltBrowseState.failed) Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {
BrowseChip(stringResource(R.string.stores_dl_retry), false) { GameJoltBrowseState.more(ctx, retry = true) }
}
else if (!GameJoltBrowseState.ended && count > 0) Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {
BrowseChip(stringResource(R.string.stores_itch_load_more), false) { GameJoltBrowseState.more(ctx) }
}
}
@Composable
private fun sectionLabel(section: String): String = stringResource(
when (section) {
GameJoltBrowse.SECTION_HOT -> R.string.stores_gamejolt_section_hot
GameJoltBrowse.SECTION_BEST -> R.string.stores_gamejolt_section_best
GameJoltBrowse.SECTION_NEW -> R.string.stores_gamejolt_section_new
else -> R.string.stores_gamejolt_section_featured
},
)
@Composable
private fun priceLabel(price: String): String = stringResource(
when (price) {
GameJoltBrowse.PRICE_FREE -> R.string.stores_itch_price_free
GameJoltBrowse.PRICE_SALE -> R.string.stores_itch_price_sale
GameJoltBrowse.PRICE_PAID -> R.string.stores_itch_price_paid
GameJoltBrowse.PRICE_UNDER_5 -> R.string.stores_itch_price_under_5
GameJoltBrowse.PRICE_UNDER_15 -> R.string.stores_itch_price_under_15
GameJoltBrowse.PRICE_UNDER_30 -> R.string.stores_gamejolt_price_under_30
else -> R.string.stores_itch_price_any
},
)
@Composable
private fun systemLabel(os: String): String = stringResource(
when (os) {
"windows" -> R.string.stores_itch_platform_windows
"mac" -> R.string.stores_itch_platform_macos
"linux" -> R.string.stores_itch_platform_linux
else -> R.string.stores_gamejolt_os_other
},
)
@Composable
private fun browserLabel(browser: String): String = when (browser) {
"html" -> "HTML"
"flash" -> "Flash"
else -> "Unity"
}
@Composable
private fun maturityLabel(maturity: String): String = stringResource(
when (maturity) {
"everyone" -> R.string.stores_gamejolt_maturity_everyone
"teen" -> R.string.stores_gamejolt_maturity_teen
else -> R.string.stores_gamejolt_maturity_adult
},
)
@Composable
private fun statusLabel(status: String): String = stringResource(
when (status) {
"complete" -> R.string.stores_gamejolt_status_complete
else -> R.string.stores_gamejolt_status_early
},
)
@@ -0,0 +1,129 @@
package com.droiddeck.launcher.ui
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.droiddeck.launcher.R
import com.droiddeck.launcher.stores.CatalogItem
import com.droiddeck.launcher.stores.InstalledStoreGame
import com.droiddeck.launcher.stores.Store
import com.droiddeck.launcher.stores.StoresState
import com.droiddeck.launcher.stores.formatBytes
import com.droiddeck.launcher.stores.gamejolt.GameJoltApi
import com.droiddeck.launcher.stores.gamejolt.GameJoltBuild
import com.droiddeck.launcher.stores.gamejolt.GameJoltBuilds
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
private const val CHOOSE = "choose"
@Composable
internal fun GameJoltVersionButton(installed: InstalledStoreGame, enabled: Boolean) {
SecondaryButton(stringResource(R.string.stores_itch_pick_title), enabled = enabled) {
val sidecar = installed.sidecar
val paid = sidecar.extra["paid"] == "1"
StoresState.gameJoltPicking = CatalogItem(
store = Store.GAMEJOLT, id = sidecar.id, title = sidecar.title, imageUrl = sidecar.cover, isFree = !paid,
storeUrl = GameJoltApi.pageUrl("game", sidecar.id),
extra = mapOf("gameId" to (sidecar.extra["gameId"] ?: sidecar.id), CHOOSE to "1"),
)
}
}
@Composable
internal fun GameJoltBuildPicker(requested: CatalogItem, onDismiss: () -> Unit) {
val item = requested.copy(owned = requested.owned || StoresState.library[Store.GAMEJOLT].orEmpty().any { it.id == requested.id && it.owned })
val ctx = LocalContext.current
val app = ctx.applicationContext
val colors = MaterialTheme.colorScheme
val shown = rememberShown(onDismiss)
val close = { shown.targetState = false }
var loaded by remember(requested) { mutableStateOf<List<GameJoltBuild>?>(null) }
var failed by remember(requested) { mutableStateOf(false) }
val install: (GameJoltBuild) -> Unit = install@{ build ->
if (!shown.targetState) return@install
val tagged = item.copy(
extra = item.extra + mapOf("buildId" to build.id),
sizeBytes = build.size.takeIf { it > 0 } ?: item.sizeBytes,
)
close()
StoresState.requestInstall(ctx, tagged)
}
LaunchedEffect(requested) {
val gameId = item.extra["gameId"].orEmpty().ifEmpty { item.id }
val result = withContext(Dispatchers.IO) { GameJoltBuilds.load(app, gameId) }
if (result == null) { failed = true; return@LaunchedEffect }
loaded = result
if ((item.isFree || item.owned) && item.extra[CHOOSE] != "1" && shown.targetState) result.singleOrNull()?.takeIf { it.installable }?.let { install(it) }
}
AppDialog(shown, close, "gameJoltBuilds", wide = false, maxWidth = 460.dp) {
DialogTitleRow(stringResource(R.string.stores_itch_pick_title), close)
Text(item.title, fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis)
val list = loaded
when {
failed -> Text(stringResource(R.string.stores_gamejolt_pick_failed), fontSize = 13.sp, color = colors.onSurfaceVariant)
list == null -> LinearProgressIndicator(Modifier.fillMaxWidth().padding(vertical = 8.dp))
list.isEmpty() -> Text(stringResource(R.string.stores_itch_pick_none), fontSize = 13.sp, color = colors.onSurfaceVariant)
else -> Column(verticalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth()) {
for (build in list) key(build.id) { BuildRow(item, build) { install(build) } }
}
}
}
}
@Composable
private fun BuildRow(item: CatalogItem, build: GameJoltBuild, onInstall: () -> Unit) {
val ctx = LocalContext.current
val colors = MaterialTheme.colorScheme
val linux = "linux" in build.platforms && !build.installable
val canInstall = build.installable && (item.isFree || item.owned)
val names = build.platforms.map { platformName(it) }
val detail = listOfNotNull(
names.joinToString(", "),
build.size.takeIf { it > 0 }?.let { formatBytes(it) },
build.version.takeIf { it.isNotBlank() },
).joinToString(" · ")
ListRow(enabled = !linux, onClick = { if (canInstall) onInstall() else openStoreUrl(ctx, item) }) {
Column(Modifier.weight(1f)) {
Text(build.filename.ifBlank { build.packageTitle.ifBlank { item.title } }, fontSize = 13.sp, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis)
Text(detail, fontSize = 11.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
val label = when {
canInstall -> stringResource(R.string.stores_install)
linux -> stringResource(R.string.stores_itch_build_linux_soon)
else -> stringResource(R.string.stores_gamejolt_build_open)
}
Text(label, fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1)
}
}
@Composable
private fun platformName(platform: String): String = stringResource(
when (platform) {
"windows" -> R.string.stores_itch_build_windows
"linux" -> R.string.stores_itch_build_linux
"osx" -> R.string.stores_itch_build_macos
"other" -> R.string.stores_gamejolt_os_other
else -> R.string.stores_itch_build_web
},
)
@@ -0,0 +1,61 @@
package com.droiddeck.launcher.ui
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.droiddeck.launcher.R
import com.droiddeck.launcher.stores.InstalledStoreGame
import com.droiddeck.launcher.stores.gamejolt.GameJoltUpdate
import com.droiddeck.launcher.stores.gamejolt.GameJoltUpdates
@Composable
internal fun GameJoltCheckButton(installed: InstalledStoreGame) {
val ctx = LocalContext.current
IconAction(Icons.Filled.Refresh, stringResource(R.string.store_check_updates), "game:check-updates", enabled = GameJoltUpdates.checkingKey == null, frosted = true) {
GameJoltUpdates.checkGame(ctx, installed)
}
}
@Composable
internal fun GameJoltUpdateButton(installed: InstalledStoreGame, enabled: Boolean) {
val ctx = LocalContext.current
val update = GameJoltUpdates.available[installed.key] ?: return
var asking by remember { mutableStateOf(false) }
SecondaryButton(stringResource(R.string.common_update), enabled = enabled) {
if (update.replaced) asking = true else GameJoltUpdates.start(ctx, installed, update)
}
if (asking) GameJoltReplacedDialog(installed, update) { asking = false }
}
@Composable
private fun GameJoltReplacedDialog(installed: InstalledStoreGame, update: GameJoltUpdate, onDismiss: () -> Unit) {
val ctx = LocalContext.current
val shown = rememberShown(onDismiss)
val close = { shown.targetState = false }
AppDialog(shown, close, "gameJoltUpdate", wide = false, maxWidth = 460.dp) {
DialogTitleRow(installed.sidecar.title, close)
Text(
stringResource(R.string.stores_itch_update_replaced, update.filename.ifBlank { update.buildId }),
fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant,
)
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
PrimaryButton(stringResource(R.string.common_update)) {
close()
GameJoltUpdates.start(ctx, installed, update)
}
SecondaryButton(stringResource(R.string.common_cancel)) { close() }
}
}
}
@@ -8,6 +8,7 @@ import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
@@ -19,6 +20,7 @@ import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@@ -27,6 +29,7 @@ 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.focus.FocusRequester
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
@@ -44,16 +47,29 @@ internal fun ItchBrowseBar() {
var picking by remember { mutableStateOf(false) }
Column(Modifier.fillMaxWidth().padding(top = 6.dp, bottom = 8.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {
ChipRow {
for (sort in ItchBrowse.sorts) BrowseChip(sortLabel(sort), query.sort == sort) { ItchBrowseState.choose(ctx, query.copy(sort = sort)) }
}
ChipRow {
for (price in ItchBrowse.prices) BrowseChip(priceLabel(price), query.price == price) { ItchBrowseState.choose(ctx, query.copy(price = price)) }
}
ChipRow {
BrowseChip(stringResource(R.string.stores_itch_platform_any), query.platforms.isEmpty()) { ItchBrowseState.choose(ctx, query.copy(platforms = emptySet())) }
for (platform in ItchBrowse.platformNames) {
val on = platform in query.platforms
BrowseChip(platformLabel(platform), on) { ItchBrowseState.choose(ctx, query.copy(platforms = if (on) query.platforms - platform else query.platforms + platform)) }
BrowseDropdown(sortLabel(query.sort)) { first, close ->
ItchBrowse.sorts.forEachIndexed { index, sort ->
MenuItem(sortLabel(sort), query.sort == sort, focusRequester = if (index == 0) first else null) {
ItchBrowseState.choose(ctx, query.copy(sort = sort))
close()
}
}
}
BrowseDropdown(priceLabel(query.price)) { first, close ->
ItchBrowse.prices.forEachIndexed { index, price ->
MenuItem(priceLabel(price), query.price == price, focusRequester = if (index == 0) first else null) {
ItchBrowseState.choose(ctx, query.copy(price = price))
close()
}
}
}
val anyPlatform = stringResource(R.string.stores_itch_platform_any)
BrowseDropdown(browseSummary(ItchBrowse.platformNames.filter { it in query.platforms }.map { platformLabel(it) }, anyPlatform)) { first, _ ->
MenuItem(anyPlatform, query.platforms.isEmpty(), focusRequester = first) { ItchBrowseState.choose(ctx, query.copy(platforms = emptySet())) }
for (platform in ItchBrowse.platformNames) {
val on = platform in query.platforms
MenuItem(platformLabel(platform), on) { ItchBrowseState.choose(ctx, query.copy(platforms = if (on) query.platforms - platform else query.platforms + platform)) }
}
}
}
ChipRow {
@@ -83,7 +99,7 @@ internal fun ItchLoadMore() {
}
@Composable
private fun ChipRow(content: @Composable () -> Unit) {
internal fun ChipRow(content: @Composable () -> Unit) {
Row(
horizontalArrangement = Arrangement.spacedBy(6.dp), verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().horizontalScroll(rememberScrollState()).selectableGroup(),
@@ -91,7 +107,22 @@ private fun ChipRow(content: @Composable () -> Unit) {
}
@Composable
private fun BrowseChip(label: String, selected: Boolean, onClick: () -> Unit) {
internal fun BrowseDropdown(text: String, content: @Composable ColumnScope.(FocusRequester, () -> Unit) -> Unit) {
var expanded by remember { mutableStateOf(false) }
Box {
CompositionLocalProvider(LocalChipMinWidth provides 0.dp) { ValueChip(text, expanded) { expanded = !expanded } }
AnchoredMenu(expanded, onDismiss = { expanded = false }, compact = true, minWidth = 160.dp) { first -> content(first) { expanded = false } }
}
}
internal fun browseSummary(labels: List<String>, empty: String): String = when (labels.size) {
0 -> empty
1, 2 -> labels.joinToString(", ")
else -> "${labels.first()} +${labels.size - 1}"
}
@Composable
internal fun BrowseChip(label: String, selected: Boolean, onClick: () -> Unit) {
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
val shape = RoundedCornerShape(8.dp)
@@ -102,7 +102,8 @@ import com.droiddeck.launcher.stores.download.DownloadEntry
import com.droiddeck.launcher.stores.download.DownloadStage
import com.droiddeck.launcher.stores.download.DownloadState
import com.droiddeck.launcher.stores.formatBytes
import com.droiddeck.launcher.stores.itch.ItchCollection
import com.droiddeck.launcher.stores.gamejolt.GameJoltCollections
import com.droiddeck.launcher.stores.gamejolt.GameJoltUpdates
import com.droiddeck.launcher.stores.itch.ItchCollections
import com.droiddeck.launcher.stores.itch.ItchUpdates
import com.droiddeck.launcher.stores.gog.GogMaintenance
@@ -142,20 +143,20 @@ internal fun libraryEntries(
return out.distinctBy { it.key }
}
internal fun collectionEntries(all: List<LibraryEntry>, items: List<CatalogItem>): List<LibraryEntry> {
internal fun collectionEntries(all: List<LibraryEntry>, items: List<CatalogItem>, store: Store = Store.ITCH): List<LibraryEntry> {
val keys = items.map { it.key }.toSet()
val itch = all.filter { it.source == Store.ITCH.id }
val have = itch.mapNotNull { it.storeKey }.toSet()
return itch.filter { it.storeKey in keys } +
items.filter { it.key !in have }.map { LibraryEntry(GameRef.key(it), Store.ITCH.id, it.title, null, it, false) }
val own = all.filter { it.source == store.id }
val have = own.mapNotNull { it.storeKey }.toSet()
return own.filter { it.storeKey in keys } +
items.filter { it.key !in have }.map { LibraryEntry(GameRef.key(it), store.id, it.title, null, it, false) }
}
internal fun installedFirst(entries: List<LibraryEntry>): List<LibraryEntry> = entries.partition { it.installed }.let { (on, off) -> on + off }
internal const val LIBRARY_ALL = "all"
internal fun librarySources(entries: List<LibraryEntry>, order: List<String>): List<String> =
internal fun librarySources(entries: List<LibraryEntry>, order: List<String>, always: Set<String> = emptySet()): List<String> =
(listOf(Library.SOURCE_STEAM) + arrangeStoreTabs(order, emptySet()).map { it.store.id } + Library.ADDED)
.filter { source -> entries.any { it.source == source } }
.filter { source -> source in always || entries.any { it.source == source } }
internal object LibraryDisplay {
val scales = listOf(0.75f, 0.875f, 1f, 1.2f, 1.45f)
@@ -225,7 +226,11 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String,
var showUninstalled by remember(LibraryView.ownedRequest) { mutableStateOf(SessionPrefs.libraryShowUninstalled(ctx)) }
var collectionShows by remember { mutableStateOf<Pair<String, Boolean>?>(null) }
val setShowUninstalled = { show: Boolean ->
val picked = ItchCollections.selected.takeIf { LibraryView.source == Store.ITCH.id }
val picked = when (LibraryView.source) {
Store.ITCH.id -> ItchCollections.selected
Store.GAMEJOLT.id -> GameJoltCollections.selected
else -> null
}
if (picked != null) collectionShows = picked to show
else {
showUninstalled = show
@@ -233,21 +238,32 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String,
}
}
val itchSignedIn = owned.containsKey(Store.ITCH)
val listed = librarySources(all, SessionPrefs.storesTabOrder(ctx))
val sources = if (itchSignedIn && Store.ITCH.id !in listed) listed + Store.ITCH.id else listed
val gameJoltSignedIn = owned.containsKey(Store.GAMEJOLT)
val sources = librarySources(all, SessionPrefs.storesTabOrder(ctx), listOfNotNull(Store.ITCH.id.takeIf { itchSignedIn }, Store.GAMEJOLT.id.takeIf { gameJoltSignedIn }).toSet())
val source = LibraryView.source.takeIf { it == LIBRARY_ALL || it in sources } ?: LIBRARY_ALL
val q = LibraryView.query.trim().lowercase()
val xboxFilter = if (source == Store.XBOX.id) XboxLibraryFilter.current else XboxLibraryFilter.ALL
LaunchedEffect(source, itchSignedIn) { if (source == Store.ITCH.id && itchSignedIn) {
ItchCollections.load(ctx)
ItchUpdates.check(ctx)
} }
val collection = if (source == Store.ITCH.id) ItchCollections.chosen() else null
val pool = if (collection == null) all else collectionEntries(all, ItchCollections.gamesOf(collection.id).orEmpty())
LaunchedEffect(source, itchSignedIn, gameJoltSignedIn) {
if (source == Store.ITCH.id && itchSignedIn) {
ItchCollections.load(ctx)
ItchUpdates.check(ctx)
}
if (source == Store.GAMEJOLT.id && gameJoltSignedIn) {
GameJoltCollections.load(ctx)
GameJoltUpdates.check(ctx)
}
}
val collectionId = when (source) {
Store.ITCH.id -> ItchCollections.chosen()?.id
Store.GAMEJOLT.id -> GameJoltCollections.chosen()?.id
else -> null
}
val collectionItems = collectionId?.let { if (source == Store.GAMEJOLT.id) GameJoltCollections.gamesOf(it) else ItchCollections.gamesOf(it) }
val pool = if (collectionId == null) all else collectionEntries(all, collectionItems.orEmpty(), Store.byId(source) ?: Store.ITCH)
val matching = pool.filter {
(source == LIBRARY_ALL || it.source == source) && (q.isEmpty() || it.title.lowercase().contains(q)) && keepsXbox(xboxFilter, it)
}
val listUninstalled = if (collection == null) showUninstalled else collectionShows?.takeIf { it.first == collection.id }?.second ?: true
val listUninstalled = if (collectionId == null) showUninstalled else collectionShows?.takeIf { it.first == collectionId }?.second ?: true
val candidates = if (listUninstalled) matching else matching.filter { it.installed }
val hiddenUninstalled = if (listUninstalled) 0 else matching.count { !it.installed }
val sort = s.storesSort
@@ -332,7 +348,7 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String,
kotlinx.coroutines.delay(Motion.ms(240).toLong())
focusWithinFrames({ ff.last?.startsWith("card:") == true }) { if (ff.firstTileAttached > 0) ff.firstTile else FocusRequester.Default }
}
if (all.isEmpty() && open == null && !itchSignedIn) {
if (all.isEmpty() && open == null && !itchSignedIn && !gameJoltSignedIn) {
LibraryEmpty(s, a, modifier)
return
}
@@ -453,7 +469,7 @@ private fun LibraryGrid(
contentPadding = PaddingValues(top = 4.dp, bottom = 16.dp),
) {
item(key = "header", span = { GridItemSpan(maxLineSpan) }) {
Rise(0) { LibraryHeader(s, a, total, searchCleared, source == Store.XBOX.id, showUninstalled, onShowUninstalled, collections = source == Store.ITCH.id) }
Rise(0) { LibraryHeader(s, a, total, searchCleared, source == Store.XBOX.id, showUninstalled, onShowUninstalled, collections = Store.byId(source)?.takeIf { it == Store.ITCH || it == Store.GAMEJOLT }) }
}
item(key = "filters", span = { GridItemSpan(maxLineSpan) }) {
Rise(1) { LibraryFilters(sources, source, onSource) }
@@ -514,7 +530,7 @@ private fun LazyGridScope.libraryGrid(entries: List<LibraryEntry>, empty: Int, t
@Composable
private fun LibraryHeader(
s: FrontEndState, a: FrontEndActions, total: Int, searchCleared: Boolean, xbox: Boolean,
showUninstalled: Boolean?, onShowUninstalled: (Boolean) -> Unit, collections: Boolean,
showUninstalled: Boolean?, onShowUninstalled: (Boolean) -> Unit, collections: Store?,
) {
val colors = MaterialTheme.colorScheme
val narrow = LocalNarrowPane.current
@@ -532,7 +548,7 @@ private fun LibraryHeader(
) {
DisplayButton()
if (showUninstalled != null || xbox) LibraryFilterButton(showUninstalled, onShowUninstalled, xbox)
if (collections) CollectionsButton()
if (collections != null) CollectionsButton(collections)
SortButton(s, a)
ViewButton(s, a)
GameFileFolderActions(s, a)
@@ -725,7 +741,7 @@ internal fun LibraryMarker(e: LibraryEntry, download: DownloadEntry?, showDownlo
}
}
private fun libraryUpdateAvailable(e: LibraryEntry): Boolean = e.storeKey?.let { it in ItchUpdates.available } == true ||
private fun libraryUpdateAvailable(e: LibraryEntry): Boolean = e.storeKey?.let { it in ItchUpdates.available || it in GameJoltUpdates.available } == true ||
e.source == Store.GOG.id && (e.item?.id ?: e.game?.storeId)?.let { GogMaintenance.checks[it]?.state } == GogMaintenance.State.AVAILABLE
@Composable
@@ -863,16 +879,21 @@ private fun LibraryFilterButton(showUninstalled: Boolean?, onShowUninstalled: (B
}
@Composable
private fun CollectionsButton() {
private fun CollectionsButton(store: Store) {
val pal = LocalPalette.current
val ctx = LocalContext.current
val title = stringResource(R.string.itch_collections)
val all = stringResource(R.string.stores_tab_all)
var at by remember { mutableStateOf<Rect?>(null) }
val gameJolt = store == Store.GAMEJOLT
val chosenTitle = if (gameJolt) GameJoltCollections.chosen()?.title else ItchCollections.chosen()?.title
val selectedId = if (gameJolt) GameJoltCollections.selected else ItchCollections.selected
Box(Modifier.onGloballyPositioned { at = it.boundsInRoot() }) {
HeaderIconButton(title + " · " + (ItchCollections.chosen()?.title ?: all), CollectionsIcon, "itch-collections") {
HeaderIconButton(title + " · " + (chosenTitle ?: all), CollectionsIcon, "${store.id}-collections") {
val from = at ?: return@HeaderIconButton
val choices = listOf<ItchCollection?>(null) + ItchCollections.list
val choices = listOf<Pair<String, String>?>(null) + if (gameJolt) GameJoltCollections.list.map { c ->
c.id to (c.title + (GameJoltCollections.gamesOf(c.id)?.let { " (" + it.size + ")" }.orEmpty()))
} else ItchCollections.list.map { c -> c.id to (c.title + " (" + c.count + ")") }
Steps.ask(StepAsk(
anchor = from, side = StepSide.Left, accent = pal.signal, pillCorner = 8.dp, items = choices.size,
handle = { Icon(CollectionsIcon, null, tint = pal.signal, modifier = Modifier.size(18.dp)) },
@@ -880,12 +901,12 @@ private fun CollectionsButton() {
StepTitle(title)
StepList {
choices.forEachIndexed { i, c ->
val picked = c?.id == ItchCollections.selected
val picked = c?.first == selectedId
StepChoice(
c?.let { it.title + " (" + it.count + ")" } ?: all, selected = picked, enabled = open,
c?.second ?: all, selected = picked, enabled = open,
modifier = Modifier.fillMaxWidth().stepItem(i).then(if (picked) Modifier.focusRequester(first) else Modifier),
) {
ItchCollections.select(ctx, c?.id)
if (gameJolt) GameJoltCollections.select(ctx, c?.first) else ItchCollections.select(ctx, c?.first)
Steps.fold()
}
}
@@ -26,6 +26,7 @@ import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.size
import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.stateDescription
import androidx.compose.foundation.shape.CircleShape
@@ -371,11 +372,12 @@ fun MenuItem(
.background(if (hot && enabled) Color.White.copy(alpha = 0.07f) else Color.Transparent)
.glideBorder(hot && enabled, RoundedCornerShape(8.dp), pal.signal)
.alpha(if (enabled) 1f else 0.4f)
.semantics { selected = checked }
.hoverable(src).clickable(role = androidx.compose.ui.semantics.Role.Button, interactionSource = src, indication = LocalIndication.current, enabled = enabled, onClick = onClick)
.controllerConfirm(enabled = enabled, onClick = onClick)
.padding(horizontal = 10.dp, vertical = 9.dp),
) {
Text("✓", fontSize = 12.sp, color = pal.signal, modifier = Modifier.width(18.dp).alpha(if (checked) 1f else 0f))
Text("✓", fontSize = 12.sp, color = pal.signal, modifier = Modifier.width(18.dp).alpha(if (checked) 1f else 0f).clearAndSetSemantics {})
if (leading != null) {
leading()
Spacer(Modifier.width(8.dp))
@@ -31,6 +31,7 @@ internal fun sourceColours(source: String): SourceColours = when (source) {
Store.AMAZON.id -> SourceColours(Color(0xFF3A2A0A), Color(0xFFFFC266), Color(0xFFFF9900))
Store.XBOX.id -> SourceColours(Color(0xFF17381B), Color(0xFFC6EDC2), Color(0xFF70C850))
Store.ITCH.id -> SourceColours(Color(0xFF3A1A1E), Color(0xFFFFB3B3), Color(0xFFFF5C5C))
Store.GAMEJOLT.id -> SourceColours(Color(0xFF232E00), Color(0xFFE3FF66), Color(0xFFCCFF00))
Store.BATTLENET.id -> SourceColours(Color(0xFF0A2440), Color(0xFF9DD1FF), Color(0xFF148EFF))
Library.SOURCE_STEAM -> SourceColours(Color(0xFF16293D), Color(0xFF7CC4FF), Color(0xFF1A9FFF))
FLATHUB -> SourceColours(Color(0xFF0B2E2B), Color(0xFF9FE3DD), FlathubTeal)
@@ -45,6 +46,7 @@ internal fun sourceLabel(source: String): String = when (source) {
Store.AMAZON.id -> Store.AMAZON.label
Store.XBOX.id -> Store.XBOX.label
Store.ITCH.id -> Store.ITCH.label
Store.GAMEJOLT.id -> Store.GAMEJOLT.label
Store.BATTLENET.id -> Store.BATTLENET.label
else -> stringResource(R.string.source_added)
}
@@ -130,6 +130,7 @@ import coil.compose.AsyncImage
import com.droiddeck.launcher.R
import com.droiddeck.launcher.session.SessionPrefs
import com.droiddeck.launcher.stores.CatalogItem
import com.droiddeck.launcher.stores.gamejolt.GameJoltBrowseState
import com.droiddeck.launcher.stores.itch.ItchBrowseState
import com.droiddeck.launcher.stores.Store
import com.droiddeck.launcher.stores.StoreTab
@@ -389,7 +390,7 @@ internal fun StoresPage(s: FrontEndState, a: FrontEndActions, modifier: Modifier
}
}
},
) { key -> GameDetail(key, s, a, heroFocus, backLabel, hopRail = null, onBack = { closeGame() }) }
) { key -> GameDetail(key, s, a, heroFocus, backLabel, hopRail = null, onBack = { closeGame() }, inStore = true) }
}
FlightLayer(hostAt)
StoresMotion.step?.let { ask ->
@@ -827,8 +828,10 @@ private fun Storefront(
fun shown(i: CatalogItem) = s.storesShowMature || !i.mature || i.accessible
fun shelf(l: List<CatalogItem>?) = l?.filter(::shown)
LaunchedEffect(store, q) { StoresState.search(ctx, store, q) }
val browsing = store == Store.ITCH && q.isEmpty() && ItchBrowseState.active
val browseItems = if (browsing) ItchBrowseState.items else emptyList()
val gameJolt = store == Store.GAMEJOLT
LaunchedEffect(gameJolt, s.storesShowMature) { if (gameJolt) GameJoltBrowseState.sync(ctx, s.storesShowMature) }
val browsing = q.isEmpty() && ((store == Store.ITCH && ItchBrowseState.active) || gameJolt)
val browseItems = if (!browsing) emptyList() else if (gameJolt) GameJoltBrowseState.items else ItchBrowseState.items
val catalog = store == Store.BATTLENET && q.isEmpty()
val visible = remember(found, library, shelves, q, s.storesShowMature, browsing, browseItems, catalog) {
if (catalog) shelf(shelves?.trending) ?: emptyList()
@@ -840,8 +843,10 @@ private fun Storefront(
.filter { (it.title.lowercase().contains(q) || it.key in foundKeys) && shown(it) }
}
val nothing = stringResource(when {
browsing && ItchBrowseState.loading -> R.string.stores_shelves_loading
browsing && ItchBrowseState.failed -> R.string.stores_itch_browse_failed
browsing && gameJolt && GameJoltBrowseState.loading -> R.string.stores_shelves_loading
browsing && gameJolt && GameJoltBrowseState.failed -> R.string.stores_gamejolt_browse_failed
browsing && !gameJolt && ItchBrowseState.loading -> R.string.stores_shelves_loading
browsing && !gameJolt && ItchBrowseState.failed -> R.string.stores_itch_browse_failed
catalog && shelves == null -> R.string.stores_shelves_loading
else -> R.string.stores_nothing_matches
})
@@ -857,7 +862,8 @@ private fun Storefront(
val bareTab = if (searching) visible.isEmpty() else shelves == null || shelves.isEmpty
val barLine = StoresState.status[store]?.takeIf { bareTab && syncCount(it) != null }
val itchBar = store == Store.ITCH && q.isEmpty()
val headerItems = 2 + (if (barLine != null) 1 else 0) + (if (StoresState.problems[store] != null) 1 else 0) + (if (itchBar) 1 else 0) + (if (catalog) 1 else 0)
val gameJoltBar = gameJolt && q.isEmpty()
val headerItems = 2 + (if (barLine != null) 1 else 0) + (if (StoresState.problems[store] != null) 1 else 0) + (if (itchBar || gameJoltBar) 1 else 0) + (if (catalog) 1 else 0)
val card: @Composable (CatalogItem) -> Unit = { item ->
val first = if (searching) item.key == visible.firstOrNull()?.key else !firstPlaced
firstPlaced = true
@@ -906,12 +912,14 @@ private fun Storefront(
barLine?.let { line -> item(key = "sync", span = { GridItemSpan(maxLineSpan) }) { Rise(3) { SyncBar(line) } } }
StoresState.problems[store]?.let { line -> item(key = "problem", span = { GridItemSpan(maxLineSpan) }) { Rise(3) { Box(Modifier.padding(bottom = 8.dp)) { Note(line) } } } }
if (itchBar) item(key = "itch-browse-bar", span = { GridItemSpan(maxLineSpan) }) { ItchBrowseBar() }
if (gameJoltBar) item(key = "gamejolt-browse-bar", span = { GridItemSpan(maxLineSpan) }) { GameJoltBrowseBar(s.storesShowMature) }
if (catalog) item(key = "catalog-label", span = { GridItemSpan(maxLineSpan) }) {
Box(Modifier.padding(top = 10.dp)) { SectionLabel(stringResource(R.string.bnet_store)) }
}
if (searching) {
storeGrid(visible, nothing, card)
if (browsing) item(key = "itch-more", span = { GridItemSpan(maxLineSpan) }) { ItchLoadMore() }
if (browsing && gameJolt) item(key = "gamejolt-more", span = { GridItemSpan(maxLineSpan) }) { GameJoltLoadMore() }
else if (browsing) item(key = "itch-more", span = { GridItemSpan(maxLineSpan) }) { ItchLoadMore() }
} else item(key = "shelves", span = { GridItemSpan(maxLineSpan) }) {
Column {
Shelf(stringResource(R.string.stores_shelf_new), shelf(shelves?.whatsNew), card)
@@ -1147,6 +1155,7 @@ internal fun storePalette(base: Palette, store: Store?): Palette {
Store.AMAZON -> Color(0xFFFF9900) to Color(0xFFE07800)
Store.XBOX -> Color(0xFF70C850) to Color(0xFF107C10)
Store.ITCH -> Color(0xFFFF5C5C) to Color(0xFFD93B3B)
Store.GAMEJOLT -> Color(0xFFCCFF00) to Color(0xFFA3CC00)
Store.BATTLENET -> Color(0xFF148EFF) to Color(0xFF0B6BD3)
null -> return base
}