Skip to content

Commit

Permalink
Auto-detect skill confirmation (#1658)
Browse files Browse the repository at this point in the history
  • Loading branch information
reconman authored Aug 11, 2023
1 parent 332941f commit 6a7a752
Show file tree
Hide file tree
Showing 21 changed files with 13 additions and 215 deletions.
Binary file added app/src/main/assets/Cn/skill_use.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/En/skill_use.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/Jp/skill_use.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/Kr/skill_use.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/Tw/skill_use.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ import io.github.fate_grand_automata.util.stringRes
fun LazyListScope.battleGroup(
prefs: PrefsCore
) {
item {
prefs.skillConfirmation.SwitchPreference(
title = stringResource(R.string.p_skill_confirmation),
icon = icon(Icons.Default.RadioButtonChecked)
)
}

item {
prefs.gameServerRaw.ListPreference(
title = stringResource(R.string.p_game_server),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@ import android.provider.Settings
import android.widget.Toast
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
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
Expand All @@ -25,9 +20,6 @@ import io.github.fate_grand_automata.BuildConfig
import io.github.fate_grand_automata.R
import io.github.fate_grand_automata.ui.Heading
import io.github.fate_grand_automata.ui.openLinkIntent
import io.github.fate_grand_automata.ui.prefs.SwitchState
import io.github.fate_grand_automata.ui.prefs.TriStateSwitch
import io.github.fate_grand_automata.ui.prefs.remember
import io.github.fate_grand_automata.util.OpenDocTreePersistable
import io.github.fate_grand_automata.util.SupportImageExtractor
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -99,44 +91,6 @@ class PickDirectory(vm: OnboardingViewModel) : OnboardingItem(vm) {
}
}

class SkillConfirmation(vm: OnboardingViewModel) : OnboardingItem(vm) {
// to remember the setting when back arrow is clicked
private var switchState = SwitchState.UNKNOWN

override fun shouldSkip(): Boolean {
// only show on first installation
return vm.prefsCore.onboardingCompletedVersion.get() > 0
}

@Composable
override fun UI(onFinished: () -> Unit) {
Heading(stringResource(R.string.p_skill_confirmation))

Text(
text = stringResource(R.string.p_skill_confirmation_onboarding_description),
style = MaterialTheme.typography.bodyLarge
)

var prefsState by vm.prefsCore.skillConfirmation.remember()
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(5.dp),
modifier = Modifier.padding(vertical = 15.dp)
) {
Text(stringResource(R.string.p_off))
TriStateSwitch(
onCheckedChange = {
prefsState = it
switchState = if (it) SwitchState.ON else SwitchState.OFF
onFinished()
},
checked = switchState
)
Text(stringResource(R.string.p_on))
}
}
}

class DisableBatteryOptimization(vm: OnboardingViewModel) : OnboardingItem(vm) {
override fun shouldSkip(): Boolean =
vm.powerManager.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ fun OnboardingContent(
listOf(
WelcomeScreen(vm),
PickDirectory(vm),
SkillConfirmation(vm),
DisableBatteryOptimization(vm),
YoutubeVideo(vm)
).filter { !it.shouldSkip() }
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class ImageLoader @Inject constructor(
Images.CEMercyLv1 -> "mercy_0.png"
Images.CEProsperityLv1 -> "prosperity_0.png"
Images.CESynchronizationLv1 -> "synchronization_0.png"
Images.SkillUse -> "skill_use.png"
}

override operator fun get(img: Images): Pattern = synchronized(regionCachedPatterns) {
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/res/values-b+zh+CN/localized.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@
<string name="p_spam_summary">选择危险敌人时施放选项需开启自动选取敌人</string>
<string name="p_auto_choose_target">自动选取敌人</string>
<string name="p_story_skip">跳过剧情</string>
<string name="p_skill_confirmation">技能确认</string>
<string name="p_enable_withdraw">启用撤退</string>
<string name="p_stop_on_ce_get">获得礼装时自动停止</string>
<string name="p_stop_on_first_clear_rewards">获得首通奖励时自动停止</string>
Expand Down Expand Up @@ -407,9 +406,6 @@

<string name="p_welcome">欢迎使用FGA!</string>
<string name="p_welcome_description">该页面将会引导您完成最重要的设置步骤</string>
<string name="p_skill_confirmation_onboarding_description">游戏中是否开启了“技能使用确认”选项?\n\n如果您目前无法确定,则暂时选择“已开启”</string>
<string name="p_on">已开启</string>
<string name="p_off">未开启</string>
<string name="p_battery_optimization">电池优化</string>
<string name="p_battery_optimization_description">FGA需要取消“电池优化”的限制,否则在工作一段时间后,它会随机停止运行\n\n在点击下方按钮后,将应用程序筛选器由“未优化”切换到“所有应用”,并将下方FGA设置变更为“不优化”</string>
<string name="p_battery_optimization_action">关闭电池优化</string>
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/res/values-b+zh+TW/localized.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
<string name="p_spam_summary">選擇 Danger 敵人時施放選項需開啟自動選取敵人</string>
<string name="p_auto_choose_target">自動選取敵人</string>
<string name="p_story_skip">跳過劇情</string>
<string name="p_skill_confirmation">技能確認</string>
<string name="p_enable_withdraw">啟用撤退</string>
<string name="p_stop_on_ce_get">禮裝獲得自動停止</string>
<string name="p_stop_on_ce_get_summary">首次通關及絆禮裝獲得時自動停止腳本</string>
Expand Down Expand Up @@ -404,9 +403,6 @@
<string name="ce_bomb_ce_fully_upgraded">概念禮裝已達到等級上限,請鎖定或放置於靈基保管室</string>
<string name="p_welcome">歡迎使用 FGA!</string>
<string name="p_welcome_description">以下將介紹幾個最重要的初始化設定</string>
<string name="p_skill_confirmation_onboarding_description">「技能使用確認」是否已開啟?\n\n若不確定請選擇已開啟。</string>
<string name="p_on">開啟</string>
<string name="p_off">關閉</string>
<string name="p_battery_optimization">電池效能最佳化</string>
<string name="p_battery_optimization_description">FGA 需要在關閉電池最佳化的情況下才可正常運作,否則可能會被系統關閉\n\n點選按鈕後,請選擇 FGA 並將設定調整為「不進行最佳化」</string>
<string name="p_battery_optimization_action">關閉電池效能最佳化(系統設定)</string>
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/res/values-ko/localized.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@
<string name="p_spam_summary">위험 모드는 자동 표적 활성화가 필요합니다</string>
<string name="p_auto_choose_target">대상 자동 선택</string>
<string name="p_story_skip">스토리 스킵</string>
<string name="p_skill_confirmation">스킬 사용 확인</string>
<string name="p_enable_withdraw">퇴각 활성화</string>
<string name="p_stop_on_ce_get">예장 획득시 정지</string>
<string name="p_stop_on_first_clear_rewards">초회 클리어 보상 수령시 정지</string>
Expand Down Expand Up @@ -407,9 +406,6 @@
<string name="p_game_area_custom_bottom">하단 좌표</string>
<string name="p_welcome">FGA에 오신걸 환영합니다!</string>
<string name="p_welcome_description">FGA 사용에 필요한 설정법을 안내드리겠습니다.</string>
<string name="p_skill_confirmation_onboarding_description">"스킬 사용 확인"이 켜져있으신가요?\n스킬을 사용하기 전에 정말 사용할 것인지 확인창이 나온다면 켜져있는 것입니다.\n이 설정은 나중에 변경할 수 있습니다.</string>
<string name="p_on">켜짐</string>
<string name="p_off">꺼짐</string>
<string name="p_battery_optimization">배터리 최적화</string>
<string name="p_battery_optimization_description">FGA를 구동하려면 배터리 설정의 제한을 풀어야합니다. 그러지 않으면 어느순간 갑자기 동작이 멈추게됩니다.\n\n아래 버튼을 누르신 후 필터에서 \"최적화 안 함\" 대신 \"모든 앱\"을 선택 후 FGA를 눌러서 "최적화 안 함"을 선택해주세요.</string>
<string name="p_battery_optimization_action">배터리 최적화 비활성화</string>
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/res/values/localized.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@
<string name="p_spam_summary">Danger mode requires Auto-targeting</string>
<string name="p_auto_choose_target">Auto choose target</string>
<string name="p_story_skip">Story Skip</string>
<string name="p_skill_confirmation">Skill Confirmation</string>
<string name="p_enable_withdraw">Enable Withdraw</string>
<string name="p_stop_on_ce_get">Stop on CE GET</string>
<string name="p_stop_on_first_clear_rewards">Stop on first-clear rewards</string>
Expand Down Expand Up @@ -410,9 +409,6 @@

<string name="p_welcome">Welcome to FGA!</string>
<string name="p_welcome_description">This screen will guide you through the most important setup steps.</string>
<string name="p_skill_confirmation_onboarding_description">Is "Confirm Skill Use" turned ON or OFF in FGO?\n\nON is the default FGO where it asks you to press OK each time you want to use a skill.\n\nYou can change this setting later on.</string>
<string name="p_on">ON</string>
<string name="p_off">OFF</string>
<string name="p_battery_optimization">Battery optimization</string>
<string name="p_battery_optimization_description">FGA requires unrestricted battery settings, otherwise it will randomly stop working after some time.\n\nAfter pressing on the button, switch the app filter from \"Not optimized\" to \"All apps\" and set FGA to \"Do not optimize\".</string>
<string name="p_battery_optimization_action">Disable battery optimization</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class PreferencesImpl @Inject constructor(

override var gameServer = GameServer.default

override val skillConfirmation by prefs.skillConfirmation

private var battleConfigList by prefs.battleConfigList

override val battleConfigs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class PrefsCore @Inject constructor(
GAME_SERVER_AUTO_DETECT
)

val skillConfirmation = maker.bool("skill_conf", true)

val battleConfigList = maker.stringSet("autoskill_list")
val selectedAutoSkillConfig = maker.string("autoskill_selected")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ enum class Images {
CEMercyLv1,
CEProsperityLv1,
CESynchronizationLv1,
SkillUse
}
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,17 @@ class AutoBattle @Inject constructor(
* Will show a toast informing the user of number of runs and how many apples have been used so far.
* Also shows CE drop count (if any have dropped).
*/
private fun showRefillsAndRunsMessage() =
private fun showRefillsAndRunsMessage() {
messages.notify(
ScriptNotify.BetweenRuns(
refills = refill.timesRefilled,
runs = state.runs,
ceDrops = ceDropsTracker.count
)
)
// delay so refill with copper is not disturbed
2.5.seconds.wait()
}

private fun afterSelectingQuest() {
1.5.seconds.wait()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class BattleScreenLocations @Inject constructor(
val skillOkClick = Location(400, 850).xFromCenter()
val orderChangeOkClick = Location(0, 1260).xFromCenter()
val extraInfoWindowCloseClick = Location(-300, 940).xFromRight()
val skillUseRegion = Region(-210, 320, 420, 85).xFromCenter()

fun servantOpenDetailsClick(slot: FieldSlot) =
Location(locate(slot.skill2()).x, 810)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Caster @Inject constructor(
private val state: BattleState,
private val servantTracker: ServantTracker
) : IFgoAutomataApi by api {
private var skillConfirmation: Boolean? = null

// TODO: Shouldn't be here ideally.
// Once we add more spam modes, Skill spam and NP spam can have their own variants.
fun canSpam(spam: SpamEnum): Boolean {
Expand All @@ -40,7 +42,10 @@ class Caster @Inject constructor(
}

private fun confirmSkillUse() {
if (prefs.skillConfirmation) {
if (skillConfirmation == null) {
skillConfirmation = images[Images.SkillUse] in locations.battle.skillUseRegion
}
if (skillConfirmation == true) {
locations.battle.skillOkClick.click()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import kotlin.time.Duration
interface IPreferences {
var scriptMode: ScriptModeEnum
var gameServer: GameServer
val skillConfirmation: Boolean
val battleConfigs: List<IBattleConfig>
var selectedBattleConfig: IBattleConfig
val storySkip: Boolean
Expand Down

0 comments on commit 6a7a752

Please sign in to comment.