Skip to content

Commit

Permalink
Improve support list refresh behavior (#1782)
Browse files Browse the repository at this point in the history
Co-authored-by: arthur <16458204+ArthurKun021@users.noreply.github.com>
  • Loading branch information
ArthurKun21 and ArthurKun21 committed Apr 5, 2024
1 parent 252593d commit b6c4959
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 7 deletions.
Binary file added app/src/main/assets/En/support_refresh.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/support_scrollbar_bottom.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/support_scrollbar_moved.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/support_scrollbar_top.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 @@ -102,6 +102,10 @@ class ImageLoader @Inject constructor(
Images.SupportExtra -> "support_extra.png"
Images.SupportNotFound -> "support_not_found.png"
Images.Support -> "support.png"
Images.SupportScrollBarTop -> "support_scrollbar_top.png"
Images.SupportScrollBarMoved -> "support_scrollbar_moved.png"
Images.SupportScrollBarBottom -> "support_scrollbar_bottom.png"
Images.SupportRefresh -> "support_refresh.png"
Images.ServantCheckSupport -> "servant_check_support.png"
Images.BattleMenu -> "battle_menu.png"
Images.EmptyEnhance -> "empty_enhance.png"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ enum class Images {
SupportExtra,
SupportNotFound,
Support,
SupportScrollBarTop,
SupportScrollBarMoved,
SupportScrollBarBottom,
SupportRefresh,
ServantCheckSupport,
BattleMenu,
EmptyEnhance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,19 @@ class SupportScreenLocations @Inject constructor(
SupportClass.Extra -> 1264
SupportClass.Mix -> 1402
}.let { x -> Location(x, 256) + headerOffset }

val topScrollbarRegion = when(isWide) {
true -> Region(1305, 335, 70, 35).xFromCenter()
false -> Region(1195, 335, 70, 35).xFromCenter()
}

val bottomScrollbarRegion = when(isWide) {
true -> Region(1305, 1400, 70, 35).xFromCenter()
false -> Region(1195, 1400, 70, 35).xFromCenter()
}

val refreshRegion = when(isWide){
true -> Region(380, 195, 175, 165).xFromCenter()
false -> Region(490, 195, 175, 165).xFromCenter()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface SupportScreen {
fun click(supportClass: SupportClass)
fun delay(duration: Duration)
fun refresh()
fun refreshAvailable(): Boolean
fun isAnyDialogOpen(): Boolean
fun noSupportsPresent(): Boolean
fun someSupportsPresent(): Boolean
Expand Down Expand Up @@ -48,6 +49,8 @@ class RealSupportScreen @Inject constructor(

locations.support.updateYesClick.click()
}
override fun refreshAvailable() =
images[Images.SupportRefresh] in locations.support.refreshRegion

override fun isAnyDialogOpen() =
images[Images.SupportExtra] !in locations.support.extraRegion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ class SupportScreenRefresher @Inject constructor(
private val supportRefreshThreshold = 10.seconds

fun refreshSupportList() {
performRefresh()
val refreshAvailable = screen.refreshAvailable()
if (refreshAvailable){
screen.refresh()
} else {
performRefresh()
}

waitForSupportScreenToLoad()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class SupportSelectionLoop @Inject constructor(
result = null
}
// Refresh support list if not exceeded max refreshes
numberOfUpdates < commonSupportPrefs.maxUpdates -> {
// or if Early Refresh due to lack of scrollbar
result is SupportSelectionResult.EarlyRefresh || numberOfUpdates < commonSupportPrefs.maxUpdates -> {
refresher.refreshSupportList()
onAllList = false

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.fate_grand_automata.scripts.supportSelection

import io.github.fate_grand_automata.scripts.IFgoAutomataApi
import io.github.fate_grand_automata.scripts.Images
import io.github.fate_grand_automata.scripts.entrypoints.AutoBattle
import io.github.fate_grand_automata.scripts.prefs.ISupportPreferences
import io.github.lib_automata.Region
Expand Down Expand Up @@ -40,8 +41,22 @@ class PreferredSupportSelection @Inject constructor(
matched.click()
SupportSelectionResult.Done
} else {
// nope, not found this time. keep scrolling
SupportSelectionResult.ScrollDown
var topScrollbar = false
var movedSrollBar = false
var bottomScrollbar = false
useSameSnapIn {
topScrollbar = images[Images.SupportScrollBarTop] in locations.support.topScrollbarRegion
if (!topScrollbar) {
movedSrollBar = images[Images.SupportScrollBarMoved] in locations.support.topScrollbarRegion
bottomScrollbar = images[Images.SupportScrollBarBottom] in
locations.support.bottomScrollbarRegion
}
}
when {
topScrollbar -> SupportSelectionResult.ScrollDown
movedSrollBar && !bottomScrollbar -> SupportSelectionResult.ScrollDown
else -> SupportSelectionResult.EarlyRefresh
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package io.github.fate_grand_automata.scripts.supportSelection

sealed class SupportSelectionResult {
object Refresh: SupportSelectionResult()
object ScrollDown: SupportSelectionResult()
object Done: SupportSelectionResult()
data object Refresh: SupportSelectionResult()
data object ScrollDown: SupportSelectionResult()
data object EarlyRefresh: SupportSelectionResult()
data object Done: SupportSelectionResult()
}

0 comments on commit b6c4959

Please sign in to comment.