Skip to content

Commit

Permalink
added experimental skip story intro
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurKun21 committed Dec 26, 2023
1 parent 6513663 commit 08740de
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,6 @@ private fun BattleConfigContent(
modifier = Modifier
.height(IntrinsicSize.Min)
) {
RaidDelay(
modifier = Modifier.weight(1f),
config = config
)
VerticalDivider()
Box(
modifier = Modifier
.fillMaxHeight()
Expand Down Expand Up @@ -255,6 +250,26 @@ private fun BattleConfigContent(
color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.12f)
)

Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.height(IntrinsicSize.Min)
){
RaidDelay(
modifier = Modifier.weight(1f),
config = config
)
VerticalDivider()
StoryIntro(
modifier = Modifier.weight(1f),
config = config
)
}

Divider(
color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.12f)
)

val cardPriority by vm.cardPriority.collectAsState(null)

cardPriority?.let {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package io.github.fate_grand_automata.ui.battle_config_item

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
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.ui.dialog.FgaDialog
import io.github.fate_grand_automata.ui.prefs.remember

@Composable
fun StoryIntro(
modifier: Modifier = Modifier,
config: BattleConfigCore
){
var storyIntroSkip by config.storyIntroSkip.remember()

val dialog = FgaDialog()

dialog.build(
color = MaterialTheme.colorScheme.background
) {
title(stringResource(R.string.p_battle_config_skip_intro))

message(text = stringResource(R.string.p_battle_config_skip_intro_message))

Row(
verticalAlignment = Alignment.CenterVertically,
) {
Card(
shape = RoundedCornerShape(25),
colors = CardDefaults.cardColors(
containerColor =
if (storyIntroSkip) MaterialTheme.colorScheme.primaryContainer
else MaterialTheme.colorScheme.surfaceVariant
),
onClick = {
storyIntroSkip = true
dialog.hide()
},
modifier = Modifier
.weight(1f)
.padding(horizontal = 2.dp)
) {
Text(
text = stringResource(R.string.state_on).uppercase(),
style = MaterialTheme.typography.bodySmall,
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 4.dp),
textAlign = TextAlign.Center,
fontWeight = if (storyIntroSkip) FontWeight.Bold else null
)
}
Card(
shape = RoundedCornerShape(25),
colors = CardDefaults.cardColors(
containerColor =
if (!storyIntroSkip) MaterialTheme.colorScheme.primaryContainer
else MaterialTheme.colorScheme.surfaceVariant
),
onClick = {
storyIntroSkip = false
dialog.hide()
},
modifier = Modifier
.weight(1f)
.padding(horizontal = 2.dp)
) {
Text(
text = stringResource(R.string.state_off).uppercase(),
style = MaterialTheme.typography.bodySmall,
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 4.dp),
textAlign = TextAlign.Center,
fontWeight = if (!storyIntroSkip) FontWeight.Bold else null
)
}
}
}

Column(
modifier = modifier
.fillMaxHeight()
.clickable(
onClick = { dialog.show() }
)
.padding(16.dp, 5.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Text(
stringResource(R.string.p_battle_config_skip_intro).uppercase(),
style = MaterialTheme.typography.bodySmall
)
Text(
text = when (storyIntroSkip) {
true -> stringResource(R.string.state_on).uppercase()
false -> stringResource(R.string.state_off).uppercase()
},
style = MaterialTheme.typography.bodySmall
)
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/values/localized.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ Skills"</string>
<string name="p_battle_config_raid">"Raid"</string>
<string name="p_battle_config_raid_delay">"Raid Delay"</string>
<string name="p_battle_config_raid_delay_message">This adds extra turn delay used for raids.</string>
<string name="p_battle_config_skip_intro">"Skip Intro"</string>
<string name="p_battle_config_skip_intro_message">"This is an experimental feature to skip intro animations."</string>
<string name="p_battle_config_server">"Server"</string>
<string name="p_battle_config_card_priority">"Card Priority"</string>
<string name="p_battle_config_use_servant_priority">"Use Servant Priority"</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ internal class BattleConfig(

override val raidTurnDelaySeconds by prefs.raidTurnDelaySeconds

override val storyIntroSkip by prefs.storyIntroSkip

override fun export(): Map<String, *> = prefs.export()

override fun import(map: Map<String, *>) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,6 @@ class BattleConfigCore(
val addRaidTurnDelay = maker.bool("add_raid_delay")

val raidTurnDelaySeconds = maker.stringAsInt("raid_delay_seconds", 2)

val storyIntroSkip = maker.bool("story_intro_skip")
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class AutoBattle @Inject constructor(
// for tracking whether to check for servant deaths or not
private var servantDeathPossible = false

// for skipping some intro before the quest starts
private var isIntroSkipped = false

override fun script(): Nothing {
try {
loop()
Expand Down Expand Up @@ -175,6 +178,7 @@ class AutoBattle @Inject constructor(
{ connectionRetry.needsToRetry() } to { connectionRetry.retry() },
{ battle.isIdle() } to {
storySkipPossible = false
isIntroSkipped = false
battle.performBattle()
servantDeathPossible = true
},
Expand All @@ -189,6 +193,7 @@ class AutoBattle @Inject constructor(
{ isRepeatScreen() } to { repeatQuest() },
{ withdraw.needsToWithdraw() } to { withdraw.withdraw() },
{ needsToStorySkip() } to { skipStory() },
{ shouldSkipStoryIntro() } to { locations.battle.battleSafeMiddleOfScreenClick.click() },
{ isFriendRequestScreen() } to { handleFriendRequestScreen() },
{ isBond10CEReward() } to { bond10CEReward() },
{ isCeRewardDetails() } to { ceRewardDetails() },
Expand Down Expand Up @@ -294,6 +299,14 @@ class AutoBattle @Inject constructor(
storySkipPossible = true
}

/**
* There is some intro done before the quest starts.
* Usually it is in-between Support Selection setup and story skip/battle quest start
*
* This is an Experimental feature to skip that
*/
private fun shouldSkipStoryIntro() = prefs.selectedBattleConfig.storyIntroSkip && isIntroSkipped

private fun isInDropsScreen() =
images[Images.MatRewards] in locations.resultMatRewardsRegion

Expand Down Expand Up @@ -423,6 +436,8 @@ class AutoBattle @Inject constructor(

// Selections Support option
private fun support() {
isIntroSkipped = true

support.selectSupport()

if (!isContinuing) {
Expand All @@ -444,6 +459,7 @@ class AutoBattle @Inject constructor(
locations.menuStorySkipRegion.exists(images[Images.StorySkip], similarity = 0.7)

private fun skipStory() {
isIntroSkipped = false
locations.menuStorySkipClick.click()
0.5.seconds.wait()
locations.menuStorySkipYesClick.click()
Expand Down Expand Up @@ -478,9 +494,7 @@ class AutoBattle @Inject constructor(
* 2. A boost item is selected if [IPreferences.boostItemSelectionMode] is set (needed in some events)
* 3. The story is skipped if [IPreferences.storySkip] is activated
*/
private

fun startQuest() {
private fun startQuest() {
partySelection.selectParty()

locations.menuStartQuestClick.click()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ interface IBattleConfig {
val addRaidTurnDelay: Boolean
val raidTurnDelaySeconds : Int

val storyIntroSkip : Boolean

fun export(): Map<String, *>

fun import(map: Map<String, *>)
Expand Down

0 comments on commit 08740de

Please sign in to comment.