Skip to content

Commit

Permalink
Combine preferred servant/CE with friend names
Browse files Browse the repository at this point in the history
  • Loading branch information
reconman committed Dec 29, 2023
1 parent 2bfc379 commit c340fb8
Show file tree
Hide file tree
Showing 27 changed files with 251 additions and 299 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ class ScriptManager @Inject constructor(
prefs = preferences,
prefsCore = prefsCore,
onClose = { dialog?.dismiss() },
onCopy = { clipboardManager.set(context, exception) }
onCopy = {
clipboardManager.set(context, exception)
}
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
Expand All @@ -43,22 +42,17 @@ import io.github.fate_grand_automata.scripts.models.CardPriorityPerWave
import io.github.fate_grand_automata.scripts.models.CardScore
import io.github.fate_grand_automata.ui.Heading
import io.github.fate_grand_automata.ui.HeadingButton
import io.github.fate_grand_automata.ui.OnResume
import io.github.fate_grand_automata.ui.VerticalDivider
import io.github.fate_grand_automata.ui.card_priority.getColorRes
import io.github.fate_grand_automata.ui.dialog.FgaDialog
import io.github.fate_grand_automata.ui.icon
import io.github.fate_grand_automata.ui.pref_support.SupportViewModel
import io.github.fate_grand_automata.ui.prefs.EditTextPreference
import io.github.fate_grand_automata.ui.prefs.Preference
import io.github.fate_grand_automata.util.toSp
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

@Composable
fun BattleConfigScreen(
vm: BattleConfigScreenViewModel = viewModel(),
supportVm: SupportViewModel = viewModel(),
navigate: (BattleConfigDestination) -> Unit
) {
val context = LocalContext.current
Expand All @@ -69,7 +63,6 @@ fun BattleConfigScreen(

BattleConfigContent(
config = vm.battleConfigCore,
friendEntries = supportVm.friends,
onExport = { battleConfigExport.launch("${vm.battleConfig.name}.fga") },
onCopy = {
val id = vm.createCopyAndReturnId(context)
Expand All @@ -81,16 +74,6 @@ fun BattleConfigScreen(
},
navigate = navigate
)

val scope = rememberCoroutineScope()

OnResume {
scope.launch(Dispatchers.IO) {
if (supportVm.shouldExtractSupportImages) {
supportVm.performSupportImageExtraction(context)
} else supportVm.refresh(context)
}
}
}

sealed class BattleConfigDestination {
Expand All @@ -105,7 +88,6 @@ sealed class BattleConfigDestination {
@Composable
private fun BattleConfigContent(
config: BattleConfigCore,
friendEntries: Map<String, String>,
onExport: () -> Unit,
onCopy: () -> Unit,
onDelete: () -> Unit,
Expand Down Expand Up @@ -254,10 +236,9 @@ private fun BattleConfigContent(
val maxSkillText by vm.maxSkillText.collectAsState("")

SupportGroup(
config = config,
config = config.support,
goToPreferred = { navigate(BattleConfigDestination.PreferredSupport) },
maxSkillText = maxSkillText,
friendEntries = friendEntries
maxSkillText = maxSkillText
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -39,13 +40,12 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import io.github.fate_grand_automata.R
import io.github.fate_grand_automata.prefs.core.BattleConfigCore
import io.github.fate_grand_automata.prefs.core.SupportPrefsCore
import io.github.fate_grand_automata.scripts.enums.SupportClass
import io.github.fate_grand_automata.scripts.enums.SupportSelectionModeEnum
import io.github.fate_grand_automata.scripts.enums.canAlsoCheckAll
import io.github.fate_grand_automata.ui.DimmedIcon
import io.github.fate_grand_automata.ui.icon
import io.github.fate_grand_automata.ui.pref_support.SupportSelectPreference
import io.github.fate_grand_automata.ui.prefs.ListPreference
import io.github.fate_grand_automata.ui.prefs.Preference
import io.github.fate_grand_automata.ui.prefs.PreferenceGroupHeader
Expand All @@ -57,12 +57,11 @@ import java.io.File

@Composable
fun SupportGroup(
config: BattleConfigCore,
config: SupportPrefsCore,
maxSkillText: String,
friendEntries: Map<String, String>,
goToPreferred: () -> Unit
) {
val supportMode by config.support.selectionMode.remember()
val supportMode by config.selectionMode.remember()

Card(
modifier = Modifier
Expand All @@ -77,7 +76,7 @@ fun SupportGroup(
title = stringResource(R.string.p_battle_config_support)
)

var supportClass by config.support.supportClass.remember()
var supportClass by config.supportClass.remember()

SupportClassPicker(
selected = supportClass,
Expand All @@ -87,24 +86,23 @@ fun SupportGroup(
val canAlsoCheckAll = supportClass.canAlsoCheckAll && supportMode != SupportSelectionModeEnum.Manual

AnimatedVisibility(canAlsoCheckAll) {
config.support.alsoCheckAll.SwitchPreference(
config.alsoCheckAll.SwitchPreference(
title = stringResource(R.string.p_battle_config_support_also_check_all)
)
}

val preferredMode = supportMode == SupportSelectionModeEnum.Preferred
val friendMode = supportMode == SupportSelectionModeEnum.Friend

Row {
config.support.selectionMode.ListPreference(
config.selectionMode.ListPreference(
title = stringResource(R.string.p_battle_config_support_selection_mode),
entries = SupportSelectionModeEnum.values()
entries = SupportSelectionModeEnum.entries
.associateWith { stringResource(it.stringRes) },
modifier = Modifier.weight(1f)
)

if (preferredMode || friendMode) {
config.support.fallbackTo.SingleSelectChipPreference(
if (preferredMode) {
config.fallbackTo.SingleSelectChipPreference(
title = stringResource(R.string.p_battle_config_support_fallback_selection_mode),
entries = listOf(
SupportSelectionModeEnum.First,
Expand All @@ -116,23 +114,34 @@ fun SupportGroup(
}

AnimatedVisibility(preferredMode) {
val servants by config.support.preferredServants.remember()
val ces by config.support.preferredCEs.remember()
val cesFormatted by derivedStateOf {
ces
.map { File(it).nameWithoutExtension }
.toSet()
}

Column {
val servants by config.preferredServants.remember()
val ces by config.preferredCEs.remember()
val cesFormatted by remember {
derivedStateOf {
ces
.map { File(it).nameWithoutExtension }
.toSet()
}
}
val friendNames by config.friendNames.remember()
val friendNamesFormatted by remember {
derivedStateOf {
friendNames
.map { File(it).nameWithoutExtension }
.toSet()
}
}

Preference(
title = { Text(stringResource(R.string.p_support_mode_preferred)) },
summary = {
PreferredSummary(
config = config,
maxSkillText = maxSkillText,
servants = servants,
ces = cesFormatted
ces = cesFormatted,
friendNames = friendNamesFormatted
)
},
onClick = goToPreferred
Expand All @@ -145,31 +154,6 @@ fun SupportGroup(
}
}
}

AnimatedVisibility(friendMode) {
Column {
if (friendEntries.isNotEmpty()) {
config.support.friendNames.SupportSelectPreference(
title = stringResource(R.string.p_battle_config_support_friend_names),
entries = friendEntries
)
} else {
Preference(
icon = icon(R.drawable.ic_info),
title = stringResource(R.string.p_battle_config_support_friend_names),
summary = stringResource(R.string.p_battle_config_support_friend_name_hint)
)
}

val friendNames by config.support.friendNames.remember()

AnimatedVisibility(friendNames.isEmpty()) {
PreferenceError(
stringResource(R.string.support_selection_friend_not_set)
)
}
}
}
}
}
}
Expand All @@ -191,7 +175,7 @@ fun SupportClassPicker(
contentPadding = PaddingValues(5.dp),
horizontalArrangement = Arrangement.SpaceEvenly
) {
items(SupportClass.values().drop(1)) {
items(SupportClass.entries.drop(1)) {
val isSelected = selected == it
val transition = updateTransition(isSelected, label = "Selected")
val alpha by transition.animateFloat(label = "alpha") { selected ->
Expand Down Expand Up @@ -244,10 +228,11 @@ val DiamondShape = CutCornerShape(50)

@Composable
fun PreferredSummary(
config: BattleConfigCore,
config: SupportPrefsCore,
maxSkillText: String,
servants: Set<String>,
ces: Set<String>
ces: Set<String>,
friendNames: Set<String>
) {
Column(
modifier = Modifier
Expand Down Expand Up @@ -310,7 +295,7 @@ fun PreferredSummary(
)

if (ces.isNotEmpty()) {
val mlb by config.support.mlb.remember()
val mlb by config.mlb.remember()

if (mlb) {
Icon(
Expand All @@ -322,5 +307,31 @@ fun PreferredSummary(
}
}
}

val friendsOnly by config.friendsOnly.remember()

if (friendsOnly) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.padding(vertical = 2.dp)
) {
DimmedIcon(
icon(R.drawable.ic_friend),
contentDescription = "friend"
)

val text = if (friendNames.isNotEmpty())
friendNames.joinToString()
else stringResource(R.string.battle_config_support_any)

Text(
text,
modifier = Modifier
.weight(1f)
.padding(start = 16.dp)
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ private fun AutoBattle.ExitReason.text(): String = when (this) {
AutoBattle.ExitReason.InventoryFull -> stringResource(R.string.inventory_full)
is AutoBattle.ExitReason.LimitRuns -> stringResource(R.string.times_ran, count)
AutoBattle.ExitReason.SupportSelectionManual -> stringResource(R.string.support_selection_manual)
AutoBattle.ExitReason.SupportSelectionFriendNotSet -> stringResource(R.string.support_selection_friend_not_set)
AutoBattle.ExitReason.SupportSelectionPreferredNotSet -> stringResource(R.string.support_selection_preferred_not_set)
is AutoBattle.ExitReason.SkillCommandParseError -> "AutoSkill Parse error:\n\n${cause?.message}"
is AutoBattle.ExitReason.CardPriorityParseError -> msg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ fun FgaApp(
battleConfigComposable(NavConstants.battleConfigItem) { _, id ->
BattleConfigScreen(
vm = hiltViewModel(),
supportVm = supportVm,
navigate = {
when (it) {
BattleConfigDestination.Back -> navController.popBackStack()
Expand Down
Loading

0 comments on commit c340fb8

Please sign in to comment.