Skip to content

Commit

Permalink
autohide improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
martimavocado committed Oct 13, 2024
1 parent 2977375 commit 5d6230b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider;
import io.github.notenoughupdates.moulconfig.annotations.ConfigLink;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;
import io.github.notenoughupdates.moulconfig.annotations.SearchTag;

import java.util.List;

Expand All @@ -30,7 +31,8 @@ public class FlowstateHelperConfig {
public boolean colorfulTimer = false;

@Expose
@ConfigOption(name = "Auto Hide", desc = "Automatically hides the GUI after a certain time idle, in seconds.")
@ConfigOption(name = "Auto Hide", desc = "Automatically hides the GUI after being idle or having the max bonus, in seconds.")
@SearchTag("autohide")
@ConfigEditorSlider(
minValue = -1,
maxValue = 30,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ object FlowstateHelper {
private var displayDirty = false
private var displayHibernating = true
private var timeSinceHibernation = SimpleTimeMark.farPast()
private var timeSinceMax = SimpleTimeMark.farPast()
private var displayMaxed = false

private var flowstateCache: Int? = null

Expand All @@ -64,6 +66,8 @@ object FlowstateHelper {
private fun attemptClearDisplay() {
if (streakEndTimer.isInFuture()) return
blockBreakStreak = 0
timeSinceMax = SimpleTimeMark.farPast()
displayMaxed = false
displayDirty = true
if (!displayHibernating) timeSinceHibernation = SimpleTimeMark.now()
displayHibernating = true
Expand All @@ -73,31 +77,47 @@ object FlowstateHelper {
@SubscribeEvent
fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
if (!MiningAPI.inCustomMiningIsland() || !config.enabled) return
if (flowstateCache == null || !streakEndTimer.isInFuture()) return
if (flowstateCache == null && !streakEndTimer.isInFuture()) return

if (displayHibernating && config.autoHide > -1 && timeSinceHibernation.passedSince() > config.autoHide.seconds) return
if (shouldAutoHide()) return
if (display.isEmpty() || streakEndTimer.isInFuture()) {
createDisplay()
}

config.position.renderRenderables(display, extraSpace = 1, "Flowstate Helper")
}

private fun shouldAutoHide(): Boolean {
if (config.autoHide < 0) return false
val autoHide = config.autoHide.seconds
if (streakEndTimer.minus(10.seconds - autoHide).isInPast()) return true
if (displayMaxed && timeSinceMax.passedSince() > autoHide) return true
return false
}

private fun createDisplay() {
if (displayDirty) {
displayDirty = false
FlowstateElements.STREAK.create()
FlowstateElements.SPEED.create()
}
FlowstateElements.TIMER.create()
FlowstateElements.COMPACT.create()
if (!displayHibernating) {
FlowstateElements.TIMER.create()
FlowstateElements.COMPACT.create()
}
display = config.appearance.map { it.renderable }
}

fun getSpeedBonus(): Int {
val flowstateLevel = flowstateCache ?: 0
if (blockBreakStreak >= 200) return 200 * flowstateLevel
return blockBreakStreak * flowstateLevel

return if (blockBreakStreak >= 200) {
if (!displayMaxed) {
displayMaxed = true
timeSinceMax = SimpleTimeMark.now()
}
200 * flowstateLevel
} else blockBreakStreak * flowstateLevel
}

@SubscribeEvent
Expand Down

0 comments on commit 5d6230b

Please sign in to comment.