From 40c7ebcba1bcb773de601cab07b51166f2daa32a Mon Sep 17 00:00:00 2001 From: ImToggle <98242902+ImToggle@users.noreply.github.com> Date: Sat, 29 Jun 2024 11:14:06 +0800 Subject: [PATCH] reset to empty since vanilla mode has been added --- .../crosshair/config/CrosshairEntry.kt | 2 +- .../org/polyfrost/crosshair/config/Drawer.kt | 7 +++- .../crosshair/elements/PresetElement.kt | 34 +++++++++++++++---- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/org/polyfrost/crosshair/config/CrosshairEntry.kt b/src/main/kotlin/org/polyfrost/crosshair/config/CrosshairEntry.kt index ce95e0b..e482bd7 100644 --- a/src/main/kotlin/org/polyfrost/crosshair/config/CrosshairEntry.kt +++ b/src/main/kotlin/org/polyfrost/crosshair/config/CrosshairEntry.kt @@ -8,7 +8,7 @@ import cc.polyfrost.oneconfig.utils.dsl.runAsync import org.polyfrost.crosshair.utils.* class CrosshairEntry( - var img: String = "iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAAGUlEQVR42mNgGH7gPxAMd83/iQCjATYkAQAXJEO9Ljp2dQAAAABJRU5ErkJggg\u003d\u003d", + var img: String = "iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAAEUlEQVR42mNgGAWjYBQMIgAAA5MAAecADfkAAAAASUVORK5CYII\u003d", ) { @Slider(name = "Scale %", min = 0f, max = 200f) diff --git a/src/main/kotlin/org/polyfrost/crosshair/config/Drawer.kt b/src/main/kotlin/org/polyfrost/crosshair/config/Drawer.kt index 281e5c9..f95d00b 100644 --- a/src/main/kotlin/org/polyfrost/crosshair/config/Drawer.kt +++ b/src/main/kotlin/org/polyfrost/crosshair/config/Drawer.kt @@ -56,8 +56,11 @@ object Drawer : BasicOption(null, null, "", "", "", "", 2) { private val colorSelector = ColorSelector() + var inArea = false + init { toBufferedImage(ModConfig.newCurrentCrosshair.img)?.let { it -> + if (it.width == 0 || it.height == 0) return@let loadImage(it, false, ModConfig.newCurrentCrosshair)?.let { CrosshairRenderer.updateTexture(it) } @@ -151,7 +154,9 @@ object Drawer : BasicOption(null, null, "", "", "", "", 2) { val scissor = ScissorHelper.INSTANCE.scissor(vg, (x + 349).toFloat(), y.toFloat(), 644f, 256f) - if (scissor.isInScissor(inputHandler.mouseX(), inputHandler.mouseY())) { + inArea = scissor.isInScissor(inputHandler.mouseX(), inputHandler.mouseY()) + + if (inArea) { inputHandler.unblockDWheel() val dWheel = inputHandler.dWheel.toFloat() diff --git a/src/main/kotlin/org/polyfrost/crosshair/elements/PresetElement.kt b/src/main/kotlin/org/polyfrost/crosshair/elements/PresetElement.kt index ccf5d85..c7ff797 100644 --- a/src/main/kotlin/org/polyfrost/crosshair/elements/PresetElement.kt +++ b/src/main/kotlin/org/polyfrost/crosshair/elements/PresetElement.kt @@ -2,17 +2,23 @@ package org.polyfrost.crosshair.elements -import cc.polyfrost.oneconfig.gui.elements.* -import cc.polyfrost.oneconfig.renderer.asset.* +import cc.polyfrost.oneconfig.gui.elements.BasicButton +import cc.polyfrost.oneconfig.gui.elements.BasicElement +import cc.polyfrost.oneconfig.platform.Platform +import cc.polyfrost.oneconfig.renderer.asset.AssetHelper +import cc.polyfrost.oneconfig.renderer.asset.Image +import cc.polyfrost.oneconfig.renderer.asset.SVG import cc.polyfrost.oneconfig.utils.InputHandler import cc.polyfrost.oneconfig.utils.color.ColorPalette import cc.polyfrost.oneconfig.utils.dsl.nanoVGHelper import org.polyfrost.crosshair.PolyCrosshair import org.polyfrost.crosshair.config.CrosshairEntry import org.polyfrost.crosshair.config.Drawer -import org.polyfrost.crosshair.utils.* +import org.polyfrost.crosshair.utils.copy +import org.polyfrost.crosshair.utils.export +import org.polyfrost.crosshair.utils.toBufferedImage import java.io.File -import java.util.UUID +import java.util.* private val remove = SVG("/assets/polycrosshair/trashcan.svg") private val copy = SVG("/assets/polycrosshair/copy.svg") @@ -33,14 +39,28 @@ class PresetElement(val crosshair: CrosshairEntry) : BasicElement(149, 149, Colo } } + override fun update(x: Float, y: Float, inputHandler: InputHandler) { + hovered = Drawer.inArea && inputHandler.isAreaHovered(x - hitBoxX, y - hitBoxY, (width + hitBoxX).toFloat(), (height + hitBoxY).toFloat()) + pressed = hovered && Platform.getMousePlatform().isButtonDown(0) + clicked = inputHandler.isClicked(false) && hovered + + if (clicked) { + toggled = !toggled + onClick() + } + + currentColor = if (hoverFx) colorAnimation.getColor(hovered, pressed) + else colorAnimation.getColor(false, false) + } + override fun draw(vg: Long, x: Float, y: Float, inputHandler: InputHandler?) { super.draw(vg, x, y, inputHandler) val half = 135 / 2f nanoVGHelper.translate(vg, x + 7 + half, y + 7 + half) nanoVGHelper.rotate(vg, crosshair.rotation.toDouble()) - nanoVGHelper.drawImage(vg, image, - half, - half, 135f, 135f, -1) - nanoVGHelper.rotate(vg, - crosshair.rotation.toDouble()) - nanoVGHelper.translate(vg, - (x + 7 + half), - (y + 7 + half)) + nanoVGHelper.drawImage(vg, image, -half, -half, 135f, 135f, -1) + nanoVGHelper.rotate(vg, -crosshair.rotation.toDouble()) + nanoVGHelper.translate(vg, -(x + 7 + half), -(y + 7 + half)) if (hovered) { copyButton.draw(vg, x + 117, y + 32, inputHandler) removeButton.draw(vg, x + 117, y, inputHandler)