generated from isXander/FabricKotlinTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scroll zoom has individual settings now fix scroll zoom with some transitions hold/toggle zoom key cinematic cam on zoom update gradle
- Loading branch information
Showing
11 changed files
with
186 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/dev/isxander/zoomify/config/ZoomKeyBehaviour.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package dev.isxander.zoomify.config | ||
|
||
enum class ZoomKeyBehaviour(val translationKey: String) { | ||
HOLD("zoomify.zoom_key_behaviour.hold"), | ||
TOGGLE("zoomify.zoom_key_behaviour.toggle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/kotlin/dev/isxander/zoomify/zoom/SingleZoomHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package dev.isxander.zoomify.zoom | ||
|
||
import dev.isxander.zoomify.utils.TransitionType | ||
import dev.isxander.zoomify.utils.lerp | ||
|
||
open class SingleZoomHelper(private val _initialZoom: () -> Double, zoomSpeed: () -> Double, transition: () -> TransitionType) : ZoomHelper<SingleZoomHelper.SingleZoomParams>(zoomSpeed, transition) { | ||
val initialZoom: Double | ||
get() = _initialZoom() | ||
|
||
private var prevZoomDivisor = 0.0 | ||
private var ticks = 0.0 | ||
|
||
override fun getZoomDivisor(params: SingleZoomParams): Double { | ||
val zooming = params.zooming | ||
val tickDelta = params.tickDelta | ||
|
||
val targetZoom = if (zooming) 1.0 else 0.0 | ||
|
||
if (transition == TransitionType.INSTANT) { | ||
prevZoomDivisor = targetZoom | ||
} else if (targetZoom > prevZoomDivisor) { | ||
prevZoomDivisor += zoomSpeed / 20 * tickDelta | ||
prevZoomDivisor = prevZoomDivisor.coerceAtMost(targetZoom) | ||
} else if (targetZoom < prevZoomDivisor) { | ||
prevZoomDivisor -= tickDelta * (zoomSpeed / 20) | ||
prevZoomDivisor = prevZoomDivisor.coerceAtLeast(targetZoom) | ||
} | ||
|
||
ticks++ | ||
return lerp(1.0, initialZoom, transition.takeUnless { it == TransitionType.INSTANT }?.apply(prevZoomDivisor) ?: prevZoomDivisor) | ||
} | ||
|
||
data class SingleZoomParams(val zooming: Boolean, val tickDelta: Float) : ZoomParams() | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/kotlin/dev/isxander/zoomify/zoom/TieredZoomHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package dev.isxander.zoomify.zoom | ||
|
||
import dev.isxander.zoomify.utils.TransitionType | ||
import dev.isxander.zoomify.utils.lerp | ||
|
||
open class TieredZoomHelper(zoomSpeed: () -> Double, transition: () -> TransitionType, private val _maxTiers: () -> Int, private val _maxZoom: () -> Double) : ZoomHelper<TieredZoomHelper.TieredZoomParams>(zoomSpeed, transition) { | ||
val maxTiers: Int | ||
get() = _maxTiers() | ||
|
||
val maxZoom: Double | ||
get() = _maxZoom() | ||
|
||
private var prevZoomDivisor = 0.0 | ||
|
||
override fun getZoomDivisor(params: TieredZoomParams): Double { | ||
val tier = params.tier | ||
val tickDelta = params.tickDelta | ||
|
||
val targetZoom = tier.toDouble() / maxTiers | ||
|
||
if (transition == TransitionType.INSTANT) { | ||
prevZoomDivisor = targetZoom | ||
} else if (targetZoom > prevZoomDivisor) { | ||
prevZoomDivisor += tickDelta * (zoomSpeed / 20) | ||
prevZoomDivisor = prevZoomDivisor.coerceAtMost(targetZoom) | ||
} else if (targetZoom < prevZoomDivisor) { | ||
prevZoomDivisor -= tickDelta * (zoomSpeed / 20) | ||
prevZoomDivisor = prevZoomDivisor.coerceAtLeast(targetZoom) | ||
} | ||
|
||
return lerp(0.0, maxZoom, transition.takeUnless { it == TransitionType.INSTANT }?.apply(prevZoomDivisor) ?: prevZoomDivisor) | ||
} | ||
|
||
data class TieredZoomParams(val tier: Int, val tickDelta: Float) : ZoomParams() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package dev.isxander.zoomify.zoom | ||
|
||
import dev.isxander.zoomify.utils.TransitionType | ||
|
||
abstract class ZoomHelper<T : ZoomHelper.ZoomParams>(private val _zoomSpeed: () -> Double, private val _transition: () -> TransitionType) { | ||
val zoomSpeed: Double | ||
get() = _zoomSpeed() | ||
|
||
val transition: TransitionType | ||
get() = _transition() | ||
|
||
abstract fun getZoomDivisor(params: T): Double | ||
|
||
abstract class ZoomParams | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters