mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
feat(battlenet): import, list and delete World of Warcraft addons (#2111)
World of Warcraft, Classic and Forever get an Addons tab in the Library. It imports addon zips into the right Interface/AddOns folder, lists the installed addons, and deletes one after a confirmation.
This commit is contained in:
1 parent
b9dbd006be
commit
a309428a2a
39 files changed
+1142
-1
No files matched your search
@@ -219,6 +219,8 @@ class FrontEndActions(
|
||||
val onGameComponents: (Library.SteamGame) -> Unit = { onComponents(true) },
|
||||
val onComponentsTab: (String) -> Unit = {},
|
||||
val onSaveImport: (Library.SteamGame) -> Unit = {},
|
||||
val onAddonImport: (Library.SteamGame, com.droiddeck.launcher.runtime.WowAddons.Target) -> Unit = { _, _ -> },
|
||||
val onAddonDelete: (com.droiddeck.launcher.runtime.WowAddons.Target, String) -> Unit = { _, _ -> },
|
||||
val onSaveExport: (Library.SteamGame, com.droiddeck.launcher.session.GameSaves.Layout) -> Unit = { _, _ -> },
|
||||
val onPerformance: () -> Unit,
|
||||
val onRoms: () -> Unit,
|
||||
|
||||
@@ -73,6 +73,7 @@ import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.pluralStringResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
@@ -86,7 +87,9 @@ import coil.compose.AsyncImage
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.frontend.GameRemoval
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import com.droiddeck.launcher.runtime.WowAddons
|
||||
import com.droiddeck.launcher.session.GameSaves
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import com.droiddeck.launcher.stores.CatalogItem
|
||||
import com.droiddeck.launcher.stores.CloudSaves
|
||||
import com.droiddeck.launcher.stores.InstalledStoreGame
|
||||
@@ -136,7 +139,7 @@ internal class GameRef(val appId: Int?, val store: Store?, val storeId: String?)
|
||||
}
|
||||
}
|
||||
|
||||
internal enum class GameTab { ABOUT, ACHIEVEMENTS, LAUNCH, SAVES, INSTALL }
|
||||
internal enum class GameTab { ABOUT, ACHIEVEMENTS, LAUNCH, SAVES, ADDONS, INSTALL }
|
||||
|
||||
@Composable
|
||||
internal fun GameDetail(
|
||||
@@ -180,12 +183,14 @@ internal fun GameDetail(
|
||||
.takeUnless { it.trim().equals(title.trim(), ignoreCase = true) }.orEmpty()
|
||||
val scored = scores != null && (scores.metacritic != Lookup.None || scores.hltb != Lookup.None)
|
||||
val prefix = game?.protonPrefix?.takeIf { it.isDirectory }
|
||||
val addonTargets = remember(game?.gameId, game?.gameFiles) { game?.let(WowAddons::targets).orEmpty() }
|
||||
val tabs = buildList {
|
||||
if (description.isNotBlank() || developer.isNotBlank() || publisher.isNotBlank() || releaseDate.isNotBlank() || scored || (!s.shortcutPicker && title.isNotBlank() && title != id)) add(GameTab.ABOUT)
|
||||
if (achievementState != null) add(GameTab.ACHIEVEMENTS)
|
||||
val cloud = game?.library == Library.XBOX_CLOUD
|
||||
if (game != null && !cloud) add(GameTab.LAUNCH)
|
||||
if (game != null && game.library == Library.ADDED && prefix != null) add(GameTab.SAVES)
|
||||
if (addonTargets.isNotEmpty()) add(GameTab.ADDONS)
|
||||
if ((game != null && !cloud) || installed != null) add(GameTab.INSTALL)
|
||||
}
|
||||
var picked by remember(key) { mutableStateOf<GameTab?>(null) }
|
||||
@@ -248,6 +253,7 @@ internal fun GameDetail(
|
||||
} ?: stringResource(R.string.achievements_title)
|
||||
GameTab.LAUNCH -> stringResource(R.string.game_tab_launch)
|
||||
GameTab.SAVES -> stringResource(if (Store.byId(source).let { it == Store.GOG || it == Store.EPIC }) R.string.game_tab_saves_cloud else R.string.games_saves)
|
||||
GameTab.ADDONS -> stringResource(R.string.game_tab_addons)
|
||||
GameTab.INSTALL -> stringResource(R.string.game_tab_install)
|
||||
}
|
||||
}
|
||||
@@ -263,6 +269,7 @@ internal fun GameDetail(
|
||||
GameTab.ACHIEVEMENTS -> achievementState?.let { st -> AchievementsTab(StoreAchievements.forSource(store?.id)?.label.orEmpty(), st) }
|
||||
GameTab.LAUNCH -> if (game != null) LaunchTab(game, s, a, hopRail)
|
||||
GameTab.SAVES -> if (game != null && prefix != null) SavesTab(game, prefix, a)
|
||||
GameTab.ADDONS -> if (game != null) AddonsTab(game, addonTargets, a)
|
||||
GameTab.INSTALL -> InstallTab(game, installed, item, store)
|
||||
}
|
||||
}
|
||||
@@ -857,6 +864,44 @@ private fun SavesTab(g: Library.SteamGame, prefix: File, a: FrontEndActions) {
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AddonsTab(g: Library.SteamGame, targets: List<WowAddons.Target>, a: FrontEndActions) {
|
||||
Column(Modifier.fillMaxWidth().tabPanel(), verticalArrangement = Arrangement.spacedBy(2.dp)) {
|
||||
targets.forEach { target ->
|
||||
val names by produceState(emptyList<String>(), target.addOns, WowAddons.imports) {
|
||||
value = withContext(Dispatchers.IO) { WowAddons.installed(target) }
|
||||
}
|
||||
if (targets.size > 1) SectionLabel(target.flavor)
|
||||
MenuItem(
|
||||
stringResource(R.string.games_import_addons), checked = false,
|
||||
detail = pluralStringResource(R.plurals.games_addons_count, names.size, names.size),
|
||||
) { a.onAddonImport(g, target) }
|
||||
MenuItem(stringResource(R.string.games_open_addons_folder), checked = false) {
|
||||
target.addOns.mkdirs()
|
||||
a.onBrowseFiles(target.addOns)
|
||||
}
|
||||
names.forEach { name -> AddonRow(name, target, a) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AddonRow(name: String, target: WowAddons.Target, a: FrontEndActions) {
|
||||
var asking by remember(target.addOns, name) { mutableStateOf(false) }
|
||||
val delete = stringResource(R.string.common_delete)
|
||||
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(start = 16.dp, top = 2.dp, bottom = 2.dp)) {
|
||||
Text(name, fontSize = 14.sp, color = MaterialTheme.colorScheme.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f))
|
||||
if (!SessionState.running) IconAction(Icons.Outlined.Delete, delete, "addon:delete:${target.flavor}:$name", danger = true) { asking = true }
|
||||
}
|
||||
if (asking) ConfirmDialog(
|
||||
title = stringResource(R.string.games_delete_addon_title, name),
|
||||
text = stringResource(R.string.games_delete_addon_body),
|
||||
confirm = delete,
|
||||
onConfirm = { a.onAddonDelete(target, name) },
|
||||
onDismiss = { asking = false },
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CloudRows(g: Library.SteamGame) {
|
||||
val store = Store.byId(g.source)?.takeIf { it != Store.AMAZON } ?: return
|
||||
|
||||
Reference in new issue
Block a user