Add a Zoom button
This commit is contained in:
parent
05dcbee261
commit
35775b98f2
|
@ -18,7 +18,7 @@ abstract class Snowy {
|
|||
@JvmStatic
|
||||
protected val FeaturePackage: String = "fr.username404.snowygui.gui.feature"
|
||||
lateinit var annotatedButtons: Set<Class<out ButtonImpl>>
|
||||
fun onEvent(e: String, lambda: argsLambda) = useKey(e).add(lambda)
|
||||
fun onEvent(e: Any, lambda: argsLambda) = useKey(e.toString()).add(lambda)
|
||||
@JvmField
|
||||
val logs: Logger = LogManager.getLogger()
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import fr.username404.snowygui.gui.feature.Category
|
|||
import fr.username404.snowygui.gui.feature.Colors
|
||||
import fr.username404.snowygui.gui.feature.Macro
|
||||
import fr.username404.snowygui.gui.feature.riskyCheats
|
||||
import fr.username404.snowygui.gui.feature.Zoom
|
||||
import net.minecraft.client.gui.screens.Screen
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.network.chat.TextComponent
|
||||
|
@ -48,9 +49,18 @@ val SnowyConfigScreen: Screen = object: Screen(translationComponent) {
|
|||
.setTitle(translationComponent).apply {
|
||||
with(entryBuilder()) {
|
||||
getOrCreateCategory(TranslatableComponent("$confPrefix.general")).addEntry(startSubCategory(TranslatableComponent("$confPrefix.behavior")).apply {
|
||||
add(startBooleanToggle(TranslatableComponent("$confPrefix.behavior.sortalphabetically"), sortAlphabetically)
|
||||
.setDefaultValue(true).requireRestart()
|
||||
.setSaveConsumer { sortAlphabetically = it }.build()
|
||||
addAll(
|
||||
setOf(
|
||||
startBooleanToggle(TranslatableComponent("$confPrefix.behavior.sortalphabetically"), sortAlphabetically)
|
||||
.setDefaultValue(true).requireRestart()
|
||||
.setSaveConsumer { sortAlphabetically = it }.build(),
|
||||
startDoubleField(TranslatableComponent("$confPrefix.behavior.zoom.factor"), Zoom.zoomFactor).setSaveConsumer {
|
||||
Zoom.zoomFactor = it
|
||||
}.setMin(1.1).build(),
|
||||
startBooleanToggle(TranslatableComponent("$confPrefix.behavior.zoom.smoothcamera"), Zoom.smoothCameraOnZoom).setSaveConsumer {
|
||||
Zoom.smoothCameraOnZoom = it
|
||||
}.build()
|
||||
)
|
||||
)
|
||||
}.build())
|
||||
.addEntry(
|
||||
|
|
|
@ -27,6 +27,7 @@ import kotlinx.coroutines.runBlocking
|
|||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlin.reflect.full.isSuperclassOf
|
||||
|
||||
object Configuration {
|
||||
@Deprecated("Use the getValue or setValue methods instead", level = DeprecationLevel.ERROR)
|
||||
|
@ -65,9 +66,7 @@ object Configuration {
|
|||
parseString(
|
||||
"""
|
||||
|Snowy {
|
||||
| displayInitMessage = false
|
||||
| macros = []
|
||||
| riskyCheats = false
|
||||
| sortAlphabetically = true
|
||||
|}
|
||||
""".trimMargin()
|
||||
|
@ -136,7 +135,20 @@ object Configuration {
|
|||
@Suppress("DEPRECATION_ERROR")
|
||||
if (ModifiableValues.containsKey(property.name))
|
||||
ModifiableValues[property.name] as T
|
||||
else invoke().getValue(ref, property)
|
||||
else try {
|
||||
invoke().getValue(ref, property)
|
||||
} catch (e: ConfigException) {
|
||||
when {
|
||||
Number::class.isSuperclassOf(T::class) -> when (T::class) {
|
||||
Double::class -> 2.0
|
||||
Int::class, UInt::class, Short::class, UShort::class -> 2
|
||||
Float::class -> 2F
|
||||
else -> throw e
|
||||
} as T
|
||||
T::class == Boolean::class -> false as T
|
||||
else -> throw e
|
||||
}
|
||||
}
|
||||
|
||||
operator fun <T> setValue(ref: Any?, property: KProperty<*>, value: T) = @Suppress("DEPRECATION_ERROR")
|
||||
ModifiableValues.setValue(ref, property, value)
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package fr.username404.snowygui.gui.feature
|
||||
|
||||
import fr.username404.snowygui.config.Configuration
|
||||
import net.minecraft.client.Minecraft
|
||||
|
||||
@ButtonInfo(Category.MISC)
|
||||
object Zoom: ButtonImpl() {
|
||||
internal var smoothCameraOnZoom: Boolean by Configuration
|
||||
internal var zoomFactor: Double by Configuration
|
||||
@JvmStatic
|
||||
fun getNewZoom(fov: Double): Double = fov / zoomFactor
|
||||
override fun execAction() {
|
||||
Minecraft.getInstance().options.smoothCamera = toggled && smoothCameraOnZoom
|
||||
}
|
||||
}
|
|
@ -12,6 +12,8 @@
|
|||
"screen.snowy.config.colors": "Box colors",
|
||||
"screen.snowy.config.behavior": "Behavior",
|
||||
"screen.snowy.config.behavior.sortalphabetically": "Sort buttons alphabetically",
|
||||
"screen.snowy.config.behavior.zoom.factor": "Zoom factor",
|
||||
"screen.snowy.config.behavior.zoom.smoothcamera": "Smooth camera on zoom",
|
||||
"category.snowy.keycategory": "SnowyGUI",
|
||||
"key.snowy.opengui": "Open the snowy gui",
|
||||
"key.snowy.configkey": "Open the snowy configuration screen",
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
"screen.snowy.config.colors": "Couleurs des boîtes",
|
||||
"screen.snowy.config.behavior": "Comportement",
|
||||
"screen.snowy.config.behavior.sortalphabetically": "Trier les boutons alphabétiquement",
|
||||
"screen.snowy.config.behavior.zoom.factor": "Facteur de zoom",
|
||||
"screen.snowy.config.behavior.zoom.smoothcamera": "Caméra fluide pendant le zoom",
|
||||
"category.snowy.keycategory": "SnowyGUI",
|
||||
"key.snowy.opengui": "Ouvrir l'interface de snowy",
|
||||
"key.snowy.configkey": "Ouvrir l'écran de configuration de snowy",
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package fr.username404.snowygui.mixins;
|
||||
|
||||
import fr.username404.snowygui.gui.feature.Zoom;
|
||||
import net.minecraft.client.Options;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(GameRenderer.class)
|
||||
abstract class ZoomMixin {
|
||||
@Redirect(
|
||||
at = @At(value = "FIELD", target = "Lnet/minecraft/client/Options;fov:D", opcode = Opcodes.GETFIELD, ordinal = 0),
|
||||
method = "getFov(Lnet/minecraft/client/Camera;FZ)D"
|
||||
)
|
||||
private double getFov(Options options) {
|
||||
return Zoom.INSTANCE.getToggled() ? Zoom.getNewZoom(options.fov) : options.fov;
|
||||
}
|
||||
}
|
|
@ -29,7 +29,8 @@
|
|||
]
|
||||
},
|
||||
"mixins": [
|
||||
"snowygui-mixins.json"
|
||||
"snowygui-mixins.json",
|
||||
"snowygui-mixins-fabric.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.11.0",
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"required": true,
|
||||
"package": "fr.username404.snowygui.mixins",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"client": [
|
||||
"ZoomMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
},
|
||||
"minVersion": "0.8"
|
||||
}
|
|
@ -49,6 +49,9 @@ class ForgeInit: Snowy() {
|
|||
addListener(this@ForgeInit::initSetup)
|
||||
addListener(this@ForgeInit::configSetup)
|
||||
}
|
||||
FORGE_BUS.register(HudHandler)
|
||||
with(FORGE_BUS) {
|
||||
register(HudHandler)
|
||||
register(ZoomHandler)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
@file:Suppress("UNUSED")
|
||||
package fr.username404.snowygui.forge
|
||||
|
||||
import fr.username404.snowygui.EventSnowy
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package fr.username404.snowygui.forge
|
||||
|
||||
import fr.username404.snowygui.gui.feature.Zoom
|
||||
import net.minecraftforge.client.event.EntityViewRenderEvent
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent
|
||||
|
||||
object ZoomHandler {
|
||||
@SubscribeEvent
|
||||
fun onFOVEvent(event: EntityViewRenderEvent.FOVModifier) {
|
||||
if (Zoom.toggled) event.fov = Zoom.getNewZoom(event.fov)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue