Start a major refactor, split the ClickButton.kt class into the ButtonInfo annotation and the ButtonImpl.kt class
This commit is contained in:
parent
4305204898
commit
3ccee1aa6f
|
@ -104,6 +104,7 @@ allprojects {
|
||||||
apply(plugin = "architectury-plugin")
|
apply(plugin = "architectury-plugin")
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(kotlin("stdlib-jdk8", kotlinVer))
|
implementation(kotlin("stdlib-jdk8", kotlinVer))
|
||||||
|
implementation(kotlin("reflect", kotlinVer))
|
||||||
}
|
}
|
||||||
tasks {
|
tasks {
|
||||||
withType(ShadowJar::class) {
|
withType(ShadowJar::class) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
architectury { common(); injectInjectables = false }
|
architectury { common(); injectInjectables = false }
|
||||||
dependencies {
|
dependencies {
|
||||||
modImplementation("net.fabricmc:fabric-loader:${rootProject.property("fabric_loader_version")}")
|
modImplementation("net.fabricmc:fabric-loader:${rootProject.property("fabric_loader_version")}")
|
||||||
|
implementation(kotlin("reflect"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package fr.username404.snowygui.mixins;
|
package fr.username404.snowygui.mixins;
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import fr.username404.snowygui.misc.Storage;
|
import fr.username404.snowygui.gui.feature.NoHurtCamera;
|
||||||
import net.minecraft.client.renderer.GameRenderer;
|
import net.minecraft.client.renderer.GameRenderer;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
@ -12,6 +12,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
public class RendererMixin {
|
public class RendererMixin {
|
||||||
@Inject(method = "bobHurt", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "bobHurt", at = @At("HEAD"), cancellable = true)
|
||||||
private void onHurt(PoseStack poseStack, float f, CallbackInfo ci) {
|
private void onHurt(PoseStack poseStack, float f, CallbackInfo ci) {
|
||||||
if (!Storage.INSTANCE.getHurtCamera()) ci.cancel();
|
if (NoHurtCamera.INSTANCE.getToggled()) ci.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,18 @@
|
||||||
package fr.username404.snowygui
|
package fr.username404.snowygui
|
||||||
|
|
||||||
|
import fr.username404.snowygui.gui.ColoredElement
|
||||||
import fr.username404.snowygui.gui.Element
|
import fr.username404.snowygui.gui.Element
|
||||||
import fr.username404.snowygui.gui.SnowyScreen
|
import fr.username404.snowygui.gui.SnowyScreen
|
||||||
import fr.username404.snowygui.gui.elements.ClickBox
|
import fr.username404.snowygui.gui.elements.ClickBox
|
||||||
import fr.username404.snowygui.gui.elements.ClickButton
|
|
||||||
import fr.username404.snowygui.misc.Storage.addComponents
|
|
||||||
import net.minecraft.network.chat.TranslatableComponent
|
|
||||||
|
|
||||||
private var baseXAxis: Double = 4.0
|
|
||||||
internal fun newBox(translationKey: String, color: Int = 0x6C9E9D): ClickBox {
|
|
||||||
val result = ClickBox(baseXAxis, 4.0, name = TranslatableComponent(translationKey), color = color)
|
|
||||||
baseXAxis += 86
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
object ClickGui: SnowyScreen() {
|
object ClickGui: SnowyScreen() {
|
||||||
private var GuiDragging: Boolean = false
|
private var GuiDragging: Boolean = false
|
||||||
override val components = mutableSetOf<Element>()
|
override val components = mutableSetOf<Element>()
|
||||||
internal fun addComps(vararg toAdd: Element) = components.addAll(toAdd)
|
|
||||||
|
|
||||||
inline fun boxContext(args: ClickBox.() -> Unit) = components.filterIsInstance<ClickBox>().forEach(args)
|
inline fun boxContext(args: ClickBox.() -> Unit) = components.filterIsInstance<ClickBox>().forEach(args)
|
||||||
private inline fun buttonsContext(args: ClickButton.() -> Unit) = boxContext { buttons.values.forEach(args) }
|
private inline fun buttonsContext(args: ColoredElement.() -> Unit) = boxContext { buttons.forEach(args) }
|
||||||
override fun mouseClicked(d: Double, e: Double, i: Int): Boolean { buttonsContext { mouseClicked(d, e, i) }; return false }
|
override fun mouseClicked(d: Double, e: Double, i: Int): Boolean { buttonsContext { this.mouseClicked(d, e, i) }; return false }
|
||||||
override fun mouseReleased(d: Double, e: Double, i: Int): Boolean { buttonsContext { mouseReleased(d, e, i) }; return false }
|
override fun mouseReleased(d: Double, e: Double, i: Int): Boolean { buttonsContext { this.mouseReleased(d, e, i) }; return false }
|
||||||
override fun mouseScrolled(d: Double, e: Double, f: Double): Boolean { boxContext { scroll(d, e, f) }; return false }
|
override fun mouseScrolled(d: Double, e: Double, f: Double): Boolean { boxContext { scroll(d, e, f) }; return false }
|
||||||
override fun mouseDragged(d: Double, e: Double, i: Int, f: Double, g: Double): Boolean {
|
override fun mouseDragged(d: Double, e: Double, i: Int, f: Double, g: Double): Boolean {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
|
@ -36,5 +26,4 @@ object ClickGui: SnowyScreen() {
|
||||||
}
|
}
|
||||||
return super.mouseDragged(d, e, i, f, g)
|
return super.mouseDragged(d, e, i, f, g)
|
||||||
}
|
}
|
||||||
init { addComponents() }
|
|
||||||
}
|
}
|
|
@ -1,15 +1,11 @@
|
||||||
package fr.username404.snowygui.config
|
package fr.username404.snowygui.config
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack
|
import com.mojang.blaze3d.vertex.PoseStack
|
||||||
import fr.username404.snowygui.gui.Element
|
import net.minecraft.client.gui.screens.Screen
|
||||||
import fr.username404.snowygui.gui.SnowyScreen
|
import net.minecraft.network.chat.TranslatableComponent
|
||||||
|
|
||||||
open class SnowyConfigScreen: SnowyScreen("screen.snowygui.config") { // TODO Actual config screen
|
open class SnowyConfigScreen: Screen(TranslatableComponent("screen.snowygui.config")) { // TODO Actual config screen
|
||||||
override fun render(poseStack: PoseStack?, i: Int, j: Int, f: Float) {
|
override fun render(poseStack: PoseStack?, i: Int, j: Int, f: Float) {
|
||||||
renderBackground(poseStack)
|
renderBackground(poseStack)
|
||||||
super.render(poseStack, i, j, f)
|
|
||||||
}
|
}
|
||||||
override val components: MutableSet<Element> = mutableSetOf(
|
|
||||||
// TODO Add components to the config gui
|
|
||||||
)
|
|
||||||
}
|
}
|
|
@ -5,7 +5,6 @@ import com.typesafe.config.ConfigException
|
||||||
import com.typesafe.config.ConfigFactory.*
|
import com.typesafe.config.ConfigFactory.*
|
||||||
import com.typesafe.config.ConfigRenderOptions
|
import com.typesafe.config.ConfigRenderOptions
|
||||||
import com.typesafe.config.ConfigValueFactory
|
import com.typesafe.config.ConfigValueFactory
|
||||||
import fr.username404.snowygui.ClickGui
|
|
||||||
import fr.username404.snowygui.Snowy
|
import fr.username404.snowygui.Snowy
|
||||||
import io.github.config4k.extract
|
import io.github.config4k.extract
|
||||||
import kotlinx.coroutines.coroutineScope
|
import kotlinx.coroutines.coroutineScope
|
||||||
|
@ -70,13 +69,15 @@ object Configuration {
|
||||||
Runtime.getRuntime().addShutdownHook(
|
Runtime.getRuntime().addShutdownHook(
|
||||||
Thread {
|
Thread {
|
||||||
runBlocking {
|
runBlocking {
|
||||||
|
/**
|
||||||
ClickGui.boxContext {
|
ClickGui.boxContext {
|
||||||
enabledFeatures.putAll(
|
enabledFeatures.putAll(
|
||||||
buttons.map { button ->
|
this.buttons.map {
|
||||||
button.key to button.value.toggled
|
(it::class.java.getDeclaredField("name").get(this) as String) to (it::class.java.getDeclaredMethod("getToggled").invoke(it)) as Boolean // TODO Fix button configuration
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
**/
|
||||||
writeConfig(obtained.withValue("enabledFeatures", ConfigValueFactory.fromMap(enabledFeatures))).join() // TODO Fix formatting of enabledFeatures
|
writeConfig(obtained.withValue("enabledFeatures", ConfigValueFactory.fromMap(enabledFeatures))).join() // TODO Fix formatting of enabledFeatures
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ package fr.username404.snowygui.gui
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.*
|
import com.mojang.blaze3d.vertex.*
|
||||||
import fr.username404.snowygui.Snowy
|
import fr.username404.snowygui.Snowy
|
||||||
|
import fr.username404.snowygui.gui.feature.Colors
|
||||||
|
import net.minecraft.client.gui.components.events.GuiEventListener
|
||||||
import org.lwjgl.opengl.GL20
|
import org.lwjgl.opengl.GL20
|
||||||
|
|
||||||
fun interface Renderable {
|
fun interface Renderable {
|
||||||
|
@ -25,7 +27,7 @@ fun interface Renderable {
|
||||||
abstract class Element(
|
abstract class Element(
|
||||||
@JvmField val xOrigin: Double, @JvmField val yOrigin: Double,
|
@JvmField val xOrigin: Double, @JvmField val yOrigin: Double,
|
||||||
val originalWidth: Int, val originalHeight: Int
|
val originalWidth: Int, val originalHeight: Int
|
||||||
): Renderable {
|
): Renderable, GuiEventListener {
|
||||||
open var width = originalWidth; open var height = originalHeight
|
open var width = originalWidth; open var height = originalHeight
|
||||||
open var x = xOrigin; open var y = yOrigin
|
open var x = xOrigin; open var y = yOrigin
|
||||||
internal fun withinBounds(coordinateX: Double, coordinateY: Double, offsetWidth: Double = 0.0, offsetHeight: Double = 0.0): Boolean =
|
internal fun withinBounds(coordinateX: Double, coordinateY: Double, offsetWidth: Double = 0.0, offsetHeight: Double = 0.0): Boolean =
|
||||||
|
@ -55,18 +57,17 @@ abstract class Element(
|
||||||
|
|
||||||
abstract class ColoredElement(
|
abstract class ColoredElement(
|
||||||
x: Double, y: Double, width: Int, height: Int,
|
x: Double, y: Double, width: Int, height: Int,
|
||||||
color: Int = TransparentColor, protected var opacity: Float,
|
color: Colors = Colors.TRANSPARENT, protected var opacity: Float,
|
||||||
) : Element(x, y, width, height) {
|
) : Element(x, y, width, height) {
|
||||||
open var color = color; protected set
|
open var color = color; protected set
|
||||||
companion object {
|
companion object {
|
||||||
const val TransparentColor: Int = -0x1
|
|
||||||
@JvmStatic protected fun VertexConsumer.colorIt(color: Int, opacity: Float = 1F): VertexConsumer {
|
@JvmStatic protected fun VertexConsumer.colorIt(color: Int, opacity: Float = 1F): VertexConsumer {
|
||||||
with(hextoRGB(color)) {
|
with(hextoRGB(color)) {
|
||||||
return this@colorIt.color(get(0), get(1), get(2), opacity)
|
return this@colorIt.color(get(0), get(1), get(2), opacity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
internal fun VertexConsumer.colorEnd(color: Int = this@ColoredElement.color) = colorIt(color, opacity).endVertex()
|
internal fun VertexConsumer.colorEnd(color: Int = this@ColoredElement.color.hexValue) = colorIt(color, opacity).endVertex()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hextoRGB(hex: Int): MutableList<Float> {
|
fun hextoRGB(hex: Int): MutableList<Float> {
|
||||||
|
|
|
@ -7,27 +7,21 @@ import fr.username404.snowygui.gui.ColoredElement
|
||||||
import fr.username404.snowygui.gui.Renderable.Rendering.buffer
|
import fr.username404.snowygui.gui.Renderable.Rendering.buffer
|
||||||
import fr.username404.snowygui.gui.Renderable.Rendering.defaultRectFunc
|
import fr.username404.snowygui.gui.Renderable.Rendering.defaultRectFunc
|
||||||
import fr.username404.snowygui.gui.Renderable.Rendering.tessellator
|
import fr.username404.snowygui.gui.Renderable.Rendering.tessellator
|
||||||
import fr.username404.snowygui.gui.elements.ClickButton.Companion.Type
|
import fr.username404.snowygui.gui.feature.Colors
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import net.minecraft.client.Minecraft
|
import net.minecraft.client.Minecraft
|
||||||
import net.minecraft.network.chat.TranslatableComponent
|
import net.minecraft.network.chat.TranslatableComponent
|
||||||
|
import org.jetbrains.annotations.ApiStatus
|
||||||
import org.lwjgl.opengl.GL20
|
import org.lwjgl.opengl.GL20
|
||||||
|
|
||||||
|
@ApiStatus.Internal
|
||||||
class ClickBox(
|
class ClickBox(
|
||||||
x: Double, y: Double,
|
x: Double = baseXAxis, y: Double,
|
||||||
color: Int = 0x6C9E9D,
|
color: Colors = Colors.BLUE,
|
||||||
private val name: TranslatableComponent? = null
|
val name: TranslatableComponent? = null
|
||||||
): ColoredElement(x, y, 80, 10, color, 0.5F) {
|
): ColoredElement(x, y, 80, 10, color, 0.5F) {
|
||||||
val buttons = mutableMapOf<String, ClickButton>() // Can contain up to 16 buttons
|
val buttons = mutableSetOf<ColoredElement>()
|
||||||
fun addButtons(vararg collect: Pair<String, (ClickButton.() -> Unit)?>, kind: Type = Type.TOGGLE): ClickBox {
|
|
||||||
buttons.putAll(
|
|
||||||
collect.map {
|
|
||||||
it.first to ClickButton(title = it.first, action = it.second, getColorFrom = this, kind = kind)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
@JvmField
|
@JvmField
|
||||||
val buttonsProgressBar: ColoredElement = object: ColoredElement(
|
val buttonsProgressBar: ColoredElement = object: ColoredElement(
|
||||||
(x + width), y + height + 3,
|
(x + width), y + height + 3,
|
||||||
|
@ -59,6 +53,7 @@ class ClickBox(
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
var baseXAxis: Double = 4.0; private set
|
||||||
const val clickboxHeightOffset: Int = 80
|
const val clickboxHeightOffset: Int = 80
|
||||||
private const val inclination: Double = 2.5
|
private const val inclination: Double = 2.5
|
||||||
}
|
}
|
||||||
|
@ -95,7 +90,7 @@ class ClickBox(
|
||||||
x = this@ClickBox.x + this@ClickBox.width - 3
|
x = this@ClickBox.x + this@ClickBox.width - 3
|
||||||
y = this@ClickBox.y + this@ClickBox.height + 3
|
y = this@ClickBox.y + this@ClickBox.height + 3
|
||||||
}.display(poseStack)
|
}.display(poseStack)
|
||||||
buttons.values.forEachIndexed { num, button ->
|
buttons.forEachIndexed { num, button ->
|
||||||
val fullHeight = (y + height.toDouble())..(y + height + clickboxHeightOffset)
|
val fullHeight = (y + height.toDouble())..(y + height + clickboxHeightOffset)
|
||||||
button.also {
|
button.also {
|
||||||
it.x = x + 3
|
it.x = x + 3
|
||||||
|
@ -105,9 +100,10 @@ class ClickBox(
|
||||||
}
|
}
|
||||||
} else null
|
} else null
|
||||||
if ((name != null) && (poseStack != null)) {
|
if ((name != null) && (poseStack != null)) {
|
||||||
Minecraft.getInstance().font.draw(poseStack, name.string, x.toFloat() + 5, y.toFloat() + 1.5F, TransparentColor)
|
Minecraft.getInstance().font.draw(poseStack, name.string, x.toFloat() + 5, y.toFloat() + 1.5F, Colors.TRANSPARENT.hexValue)
|
||||||
renderButtons?.join()
|
renderButtons?.join()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
init { baseXAxis += 86 }
|
||||||
}
|
}
|
|
@ -1,29 +1,24 @@
|
||||||
package fr.username404.snowygui.gui.elements
|
package fr.username404.snowygui.gui.feature
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem
|
import com.mojang.blaze3d.systems.RenderSystem
|
||||||
import com.mojang.blaze3d.vertex.PoseStack
|
import com.mojang.blaze3d.vertex.PoseStack
|
||||||
|
import fr.username404.snowygui.ClickGui
|
||||||
import fr.username404.snowygui.config.Configuration
|
import fr.username404.snowygui.config.Configuration
|
||||||
import fr.username404.snowygui.gui.ColoredElement
|
import fr.username404.snowygui.gui.ColoredElement
|
||||||
import fr.username404.snowygui.gui.FontUtil
|
import fr.username404.snowygui.gui.FontUtil
|
||||||
import fr.username404.snowygui.gui.Renderable.Rendering.defaultRectFunc
|
import fr.username404.snowygui.gui.Renderable.Rendering.defaultRectFunc
|
||||||
import net.minecraft.client.gui.components.events.GuiEventListener
|
import fr.username404.snowygui.gui.elements.ClickBox
|
||||||
|
import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type
|
||||||
|
import org.jetbrains.annotations.ApiStatus
|
||||||
|
import kotlin.reflect.full.findAnnotation
|
||||||
|
|
||||||
class ClickButton(
|
|
||||||
x: Double = 0.0, y: Double = 0.0,
|
@ApiStatus.Internal
|
||||||
width: Int = 73, height: Int = 8, getColorFrom: ColoredElement? = null,
|
abstract class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) {
|
||||||
private val kind: Type = Type.TOGGLE,
|
private val info = this::class.findAnnotation<ButtonInfo>() ?: throw Exception("Missing @Button annotaton")
|
||||||
private val title: String = "",
|
override var color: Colors = info.color
|
||||||
private val action: (ClickButton.() -> Unit)? = null,
|
val title = this@ButtonImpl::class.simpleName
|
||||||
): ColoredElement(x, y, width, height, opacity = 0.60F), GuiEventListener {
|
protected open fun execAction() = Unit
|
||||||
override var color: Int = getColorFrom?.color ?: super.color
|
|
||||||
companion object {
|
|
||||||
enum class Type {
|
|
||||||
TOGGLE,
|
|
||||||
CLICK // TODO Fix the CLICK behaviour
|
|
||||||
}
|
|
||||||
internal var lightningFactor: Float = 0.33F
|
|
||||||
}
|
|
||||||
private fun execAction() { action?.invoke(this) }
|
|
||||||
private var wasWithinBounds: Boolean = false
|
private var wasWithinBounds: Boolean = false
|
||||||
var toggled: Boolean = false; private set(value) {
|
var toggled: Boolean = false; private set(value) {
|
||||||
if (value) lightUp() else if (field) lightDown()
|
if (value) lightUp() else if (field) lightDown()
|
||||||
|
@ -32,11 +27,11 @@ class ClickButton(
|
||||||
execAction()
|
execAction()
|
||||||
} else field = value
|
} else field = value
|
||||||
}
|
}
|
||||||
private fun lightUp() { opacity += lightningFactor }
|
private fun lightUp() { opacity += ButtonInfo.lightningFactor }
|
||||||
private fun lightDown() { opacity -= lightningFactor }
|
private fun lightDown() { opacity -= ButtonInfo.lightningFactor }
|
||||||
override fun mouseClicked(d: Double, e: Double, i: Int): Boolean {
|
override fun mouseClicked(d: Double, e: Double, i: Int): Boolean {
|
||||||
wasWithinBounds = withinBounds(d, e).also {
|
wasWithinBounds = withinBounds(d, e).also {
|
||||||
if (it && (kind == Type.TOGGLE)) {
|
if (it && (info.kind == Type.TOGGLE)) {
|
||||||
toggled = !toggled
|
toggled = !toggled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +39,7 @@ class ClickButton(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun mouseReleased(d: Double, e: Double, i: Int): Boolean {
|
override fun mouseReleased(d: Double, e: Double, i: Int): Boolean {
|
||||||
if (wasWithinBounds && (kind == Type.CLICK)) {
|
if (wasWithinBounds && (info.kind == Type.CLICK)) {
|
||||||
toggled = true
|
toggled = true
|
||||||
}; return false
|
}; return false
|
||||||
}
|
}
|
||||||
|
@ -54,15 +49,20 @@ class ClickButton(
|
||||||
defaultRectFunc()
|
defaultRectFunc()
|
||||||
RenderSystem.enableTexture()
|
RenderSystem.enableTexture()
|
||||||
RenderSystem.disableBlend()
|
RenderSystem.disableBlend()
|
||||||
if (poseStack != null) {
|
if (poseStack != null && title != null) {
|
||||||
FontUtil.drawScaled(poseStack, title, x + 1, y + 1, 0.75F)
|
FontUtil.drawScaled(poseStack, title, x + 1, y + 1, 0.75F)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
init {
|
init {
|
||||||
if (kind == Type.TOGGLE) {
|
if (info.kind == Type.TOGGLE) {
|
||||||
Configuration.enabledFeatures[title]?.let {
|
Configuration.enabledFeatures[title]?.let {
|
||||||
toggled = it
|
toggled = it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ButtonInfo
|
||||||
|
ClickGui.components.filterIsInstance<ClickBox>().find {
|
||||||
|
it.name!!.key == info.parent.translationKey
|
||||||
|
}?.buttons!!.add(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package fr.username404.snowygui.gui.feature
|
||||||
|
|
||||||
|
import fr.username404.snowygui.ClickGui
|
||||||
|
import fr.username404.snowygui.gui.elements.ClickBox
|
||||||
|
import net.minecraft.network.chat.TranslatableComponent
|
||||||
|
|
||||||
|
@Target(AnnotationTarget.CLASS)
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
annotation class ButtonInfo(
|
||||||
|
val parent: Category,
|
||||||
|
val kind: Type = Type.TOGGLE,
|
||||||
|
val color: Colors = Colors.BLUE
|
||||||
|
) {
|
||||||
|
companion object {
|
||||||
|
internal var lightningFactor: Float = 0.33F
|
||||||
|
enum class Type {
|
||||||
|
TOGGLE,
|
||||||
|
CLICK // TODO Fix the CLICK behaviour
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}; enum class Category(val translationKey: String) {
|
||||||
|
MISC("snowy.clickbox.misc"),
|
||||||
|
RISKY("snowy.clickbox.risky");
|
||||||
|
init { ClickGui.components.add(ClickBox(y = 0.0, name = TranslatableComponent(translationKey))) }
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package fr.username404.snowygui.gui.feature
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack
|
||||||
|
import fr.username404.snowygui.Snowy.Companion.onEvent
|
||||||
|
import fr.username404.snowygui.gui.FontUtil
|
||||||
|
import kotlinx.datetime.TimeZone
|
||||||
|
import kotlinx.datetime.toLocalDateTime
|
||||||
|
import kotlinx.datetime.Clock as DatetimeClock
|
||||||
|
|
||||||
|
@ButtonInfo(Category.MISC)
|
||||||
|
object Clock: ButtonImpl() {
|
||||||
|
private val currentTimezone = TimeZone.currentSystemDefault()
|
||||||
|
init {
|
||||||
|
onEvent("HudRender") {
|
||||||
|
if (toggled) {
|
||||||
|
with(DatetimeClock.System.now().toLocalDateTime(currentTimezone)) {
|
||||||
|
FontUtil.drawScaled(it.first() as PoseStack,
|
||||||
|
"$hour:$minute:${second.let { if (it >= 10) it else "0$it" }}",
|
||||||
|
5.0, 5.0,
|
||||||
|
0.85F, color = 0xe69500
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package fr.username404.snowygui.gui.feature
|
||||||
|
|
||||||
|
enum class Colors(val hexValue: Int) {
|
||||||
|
TRANSPARENT(-0x1),
|
||||||
|
BLUE(0x6C9E9D),
|
||||||
|
RED(0x660000);
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package fr.username404.snowygui.gui.feature
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft
|
||||||
|
|
||||||
|
@ButtonInfo(Category.MISC)
|
||||||
|
object GammaBoost: ButtonImpl() {
|
||||||
|
private var oldGamma = 0.0
|
||||||
|
override fun execAction() {
|
||||||
|
with(Minecraft.getInstance().options) {
|
||||||
|
gamma = if (toggled) {
|
||||||
|
if (gamma < 1400.0) oldGamma = gamma
|
||||||
|
1400.0
|
||||||
|
} else oldGamma
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package fr.username404.snowygui.gui.feature
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft
|
||||||
|
|
||||||
|
@ButtonInfo(Category.RISKY, color = Colors.RED)
|
||||||
|
object NoHurtCamera: ButtonImpl()
|
||||||
|
|
||||||
|
@ButtonInfo(Category.RISKY, color = Colors.RED)
|
||||||
|
object NoGravity: ButtonImpl() {
|
||||||
|
override fun execAction() {
|
||||||
|
Minecraft.getInstance().player?.isNoGravity = this.toggled
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,58 +0,0 @@
|
||||||
package fr.username404.snowygui.misc
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack
|
|
||||||
import fr.username404.snowygui.ClickGui
|
|
||||||
import fr.username404.snowygui.Snowy.Companion.onEvent
|
|
||||||
import fr.username404.snowygui.config.Configuration
|
|
||||||
import fr.username404.snowygui.gui.FontUtil
|
|
||||||
import fr.username404.snowygui.newBox
|
|
||||||
import io.github.config4k.getValue
|
|
||||||
import kotlinx.datetime.Clock
|
|
||||||
import kotlinx.datetime.TimeZone
|
|
||||||
import kotlinx.datetime.toLocalDateTime
|
|
||||||
import net.minecraft.client.Minecraft
|
|
||||||
|
|
||||||
object Storage {
|
|
||||||
val currentTimezone = TimeZone.currentSystemDefault()
|
|
||||||
private var oldGamma = 0.0
|
|
||||||
private const val redColor = 0x660000
|
|
||||||
var clock: Boolean = false; private set
|
|
||||||
var hurtCamera: Boolean = true; private set
|
|
||||||
|
|
||||||
private val riskyCheats: Boolean by Configuration.obtained
|
|
||||||
fun ClickGui.addComponents() {
|
|
||||||
addComps(
|
|
||||||
newBox("snowy.clickbox.misc").addButtons(
|
|
||||||
"GammaBoost" to {
|
|
||||||
with(Minecraft.getInstance().options) {
|
|
||||||
gamma = if (toggled) {
|
|
||||||
if (gamma < 1400.0) oldGamma = gamma
|
|
||||||
1400.0
|
|
||||||
} else oldGamma
|
|
||||||
}
|
|
||||||
}, "Clock" to { clock = toggled },
|
|
||||||
),
|
|
||||||
)
|
|
||||||
if (riskyCheats) {
|
|
||||||
addComps(
|
|
||||||
newBox("snowy.clickbox.risky", color = redColor).addButtons(
|
|
||||||
"NoGravity" to { Minecraft.getInstance().player?.let { it.isNoGravity = toggled } },
|
|
||||||
"NoHurtCamera" to { hurtCamera = !toggled },
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
init {
|
|
||||||
onEvent("HudRender") {
|
|
||||||
if (clock) {
|
|
||||||
with(Clock.System.now().toLocalDateTime(currentTimezone)) {
|
|
||||||
FontUtil.drawScaled(it.first() as PoseStack,
|
|
||||||
"$hour:$minute:${second.let { if (it >= 10) it else "0$it" }}",
|
|
||||||
5.0, 5.0,
|
|
||||||
0.85F, color = 0xe69500
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue