diff --git a/src/main/kotlin/org/polyfrost/crosshair/PolyCrosshair.kt b/src/main/kotlin/org/polyfrost/crosshair/PolyCrosshair.kt index dedb4bc..c436390 100644 --- a/src/main/kotlin/org/polyfrost/crosshair/PolyCrosshair.kt +++ b/src/main/kotlin/org/polyfrost/crosshair/PolyCrosshair.kt @@ -3,12 +3,17 @@ package org.polyfrost.crosshair import cc.polyfrost.oneconfig.config.core.ConfigUtils import cc.polyfrost.oneconfig.events.EventManager import cc.polyfrost.oneconfig.events.event.ShutdownEvent +import cc.polyfrost.oneconfig.events.event.Stage +import cc.polyfrost.oneconfig.events.event.TickEvent import cc.polyfrost.oneconfig.libs.eventbus.Subscribe +import cc.polyfrost.oneconfig.libs.universal.UResolution import net.minecraftforge.common.MinecraftForge import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.event.FMLInitializationEvent +import org.polyfrost.crosshair.config.Drawer.loadImage import org.polyfrost.crosshair.config.ModConfig import org.polyfrost.crosshair.render.CrosshairRenderer +import org.polyfrost.crosshair.utils.toBufferedImage import java.io.File @Mod( @@ -26,6 +31,8 @@ object PolyCrosshair { val dir = File(path) + private var lastGuiScale = 1f + @Mod.EventHandler fun onFMLInitialization(event: FMLInitializationEvent) { clearCaches() @@ -35,6 +42,19 @@ object PolyCrosshair { EventManager.INSTANCE.register(this) } + @Subscribe + fun onTick(event: TickEvent) { + if (event.stage != Stage.END) return + if (UResolution.scaleFactor.toFloat() != lastGuiScale) { + lastGuiScale = UResolution.scaleFactor.toFloat() + toBufferedImage(ModConfig.newCurrentCrosshair.img)?.let { it -> + loadImage(it, false, ModConfig.newCurrentCrosshair)?.let { + CrosshairRenderer.updateTexture(it) + } + } + } + } + @Subscribe fun onShutDown(e: ShutdownEvent) { clearCaches() diff --git a/src/main/kotlin/org/polyfrost/crosshair/config/CrosshairEntry.kt b/src/main/kotlin/org/polyfrost/crosshair/config/CrosshairEntry.kt index 3ccc9f2..dd63709 100644 --- a/src/main/kotlin/org/polyfrost/crosshair/config/CrosshairEntry.kt +++ b/src/main/kotlin/org/polyfrost/crosshair/config/CrosshairEntry.kt @@ -5,29 +5,34 @@ import cc.polyfrost.oneconfig.config.annotations.Slider import cc.polyfrost.oneconfig.config.annotations.Switch import cc.polyfrost.oneconfig.config.core.ConfigUtils import cc.polyfrost.oneconfig.utils.dsl.runAsync -import org.polyfrost.crosshair.utils.Utils +import org.polyfrost.crosshair.utils.* class CrosshairEntry( var img: String = "iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAAGUlEQVR42mNgGH7gPxAMd83/iQCjATYkAQAXJEO9Ljp2dQAAAABJRU5ErkJggg\u003d\u003d", - @Switch(name = "Pad to Even Size", description = "By default, PolyCrosshair will pad the image when rendering to ensure the size is even. However, sometimes this can cause issues with certain images. If you're experiencing issues, try disabling this.", size = 2) - var padToEvenSize: Boolean = true, +) { + @Slider(name = "Scale %", min = 0f, max = 200f) - var scale: Int = 100, + var scale = 100 + @Slider(name = "Rotation", min = -180f, max = 180f) - var rotation: Int = 0, + var rotation = 0 + @Slider(name = "X Offset", min = -1920f, max = 1920f) - var offsetX: Int = 0, + var offsetX = 0 + @Slider(name = "Y Offset", min = -1080f, max = 1080f) - var offsetY: Int = 0 -) { + var offsetY = 0 + + @Switch(name = "Centered") + var centered = false - @Button(name = "Transform", text = "Reset", size = 2) + @Button(name = "Transform", text = "Reset", size = 1) var transformReset = Runnable { runAsync { val img = ModConfig.newCurrentCrosshair.img ModConfig.newCurrentCrosshair.loadFrom(CrosshairEntry()) ModConfig.newCurrentCrosshair.img = img - Utils.save(Drawer.saveFromDrawer(false)) + save(Drawer.saveFromDrawer(false)) } } diff --git a/src/main/kotlin/org/polyfrost/crosshair/config/Drawer.kt b/src/main/kotlin/org/polyfrost/crosshair/config/Drawer.kt index 7cc7e5c..cdf2553 100644 --- a/src/main/kotlin/org/polyfrost/crosshair/config/Drawer.kt +++ b/src/main/kotlin/org/polyfrost/crosshair/config/Drawer.kt @@ -23,8 +23,7 @@ import org.polyfrost.crosshair.PolyCrosshair import org.polyfrost.crosshair.elements.ColorSelector import org.polyfrost.crosshair.elements.PresetElement import org.polyfrost.crosshair.render.CrosshairRenderer -import org.polyfrost.crosshair.utils.Pos -import org.polyfrost.crosshair.utils.Utils +import org.polyfrost.crosshair.utils.* import java.awt.Image import java.awt.Toolkit import java.awt.datatransfer.DataFlavor @@ -63,7 +62,7 @@ object Drawer : BasicOption(null, null, "", "", "", "", 2) { private val colorSelector = ColorSelector() init { - Utils.toBufferedImage(ModConfig.newCurrentCrosshair.img)?.let { it -> + toBufferedImage(ModConfig.newCurrentCrosshair.img)?.let { it -> loadImage(it, false, ModConfig.newCurrentCrosshair)?.let { CrosshairRenderer.updateTexture(it) } @@ -75,12 +74,12 @@ object Drawer : BasicOption(null, null, "", "", "", "", 2) { } saveButton.setClickAction { runAsync { - Utils.save(saveFromDrawer(false)) + save(saveFromDrawer(false)) } } exportButton.setClickAction { runAsync { - saveFromDrawer(false)?.let { Utils.copy(it.image) } + saveFromDrawer(false)?.let { copy(it.image) } } } @@ -113,10 +112,6 @@ object Drawer : BasicOption(null, null, "", "", "", "", 2) { } override fun draw(vg: Long, x: Int, y: Int, inputHandler: InputHandler) { -// var y = y -// modeSwitch.draw(vg, x.toFloat(), y.toFloat(), inputHandler) -// if (ModConfig.mode) return -// y += 48 if (moveQueue.isNotEmpty()) { var x = 0 var y = 0 @@ -130,7 +125,7 @@ object Drawer : BasicOption(null, null, "", "", "", "", 2) { for (posY in 0..= ModConfig.canvaSize || pos.y >= ModConfig.canvaSize) { pixels[i.key].isToggled = false continue @@ -249,7 +244,7 @@ object Drawer : BasicOption(null, null, "", "", "", "", 2) { fun reset() { val newEntry = CrosshairEntry() - Utils.toBufferedImage(newEntry.img)?.let { + toBufferedImage(newEntry.img)?.let { loadImage(it, false, newEntry) } } @@ -257,7 +252,7 @@ object Drawer : BasicOption(null, null, "", "", "", "", 2) { fun move(x: Int, y: Int) { val newPositions = HashMap() for (i in ModConfig.drawer) { - val pos = Utils.indexToPos(i.key) + val pos = indexToPos(i.key) val posX = pos.x + x val posY = pos.y + y pixels[i.key].isToggled = false @@ -285,7 +280,7 @@ object Drawer : BasicOption(null, null, "", "", "", "", 2) { override fun finishUpAndClose() { val image = saveFromDrawer(true) ?: return - ModConfig.newCurrentCrosshair.img = Utils.toBase64(image.image) + ModConfig.newCurrentCrosshair.img = toBase64(image.image) CrosshairRenderer.updateTexture(image) } @@ -297,7 +292,7 @@ object Drawer : BasicOption(null, null, "", "", "", "", 2) { if (keyCode == UKeyboard.KEY_S) { if (UKeyboard.isCtrlKeyDown()) { runAsync { - Utils.save(saveFromDrawer(false)) + save(saveFromDrawer(false)) } } else { moveQueue.add(MoveType.DOWN) diff --git a/src/main/kotlin/org/polyfrost/crosshair/config/ModConfig.kt b/src/main/kotlin/org/polyfrost/crosshair/config/ModConfig.kt index 91a4809..0b29fe3 100644 --- a/src/main/kotlin/org/polyfrost/crosshair/config/ModConfig.kt +++ b/src/main/kotlin/org/polyfrost/crosshair/config/ModConfig.kt @@ -9,20 +9,25 @@ import cc.polyfrost.oneconfig.config.elements.* import cc.polyfrost.oneconfig.utils.Notifications import club.sk1er.patcher.config.OldPatcherConfig import org.polyfrost.crosshair.PolyCrosshair -import org.polyfrost.crosshair.utils.Utils +import org.polyfrost.crosshair.utils.* import java.lang.reflect.Field import java.util.stream.Collectors object ModConfig : Config(Mod(PolyCrosshair.NAME, ModType.HUD, "/${PolyCrosshair.MODID}.svg"), "${PolyCrosshair.MODID}/config.json") { - @Exclude - var mode = false - @Exclude var drawer = HashMap() var currentCrosshair = "" + @DualOption( + name = "Mode", + left = "Vanilla", + right = "Custom", + size = 2 + ) + var mode = false + @CustomOption var crosshairs = ArrayList() @@ -59,16 +64,18 @@ object ModConfig : Config(Mod(PolyCrosshair.NAME, ModType.HUD, "/${PolyCrosshair newCrosshairs.addAll(crosshairs.stream().map { CrosshairEntry(it) }.collect(Collectors.toList())) crosshairs.clear() } - val options = listOf("hostile", "passive", "player", "hostileColor", "passiveColor", "playerColor", "dynamicOpacity") + var options = listOf("hostile", "passive", "player", "hostileColor", "passiveColor", "playerColor", "dynamicOpacity") for (i in options) { hideIf(i) { !renderConfig.dynamicColor } } addDependency(options[3], options[0]) addDependency(options[4], options[1]) addDependency(options[5], options[2]) + options = listOf("mirror", "canvaSize") + options.forEach { hideIf(it) { !mode } } addListener("canvaSize") { for (i in drawer) { - val pos = Utils.indexToPos(i.key) + val pos = indexToPos(i.key) if (pos.x >= canvaSize || pos.y >= canvaSize) { Drawer.pixels[i.key].isToggled = false } @@ -109,6 +116,7 @@ object ModConfig : Config(Mod(PolyCrosshair.NAME, ModType.HUD, "/${PolyCrosshair mod: Mod, migrate: Boolean, ): BasicOption? { + Drawer.addHideCondition { !mode } ConfigUtils.getSubCategory(page, "General", "").options.add(Drawer) return null } diff --git a/src/main/kotlin/org/polyfrost/crosshair/config/Pixel.kt b/src/main/kotlin/org/polyfrost/crosshair/config/Pixel.kt index 55d8418..d470ae6 100644 --- a/src/main/kotlin/org/polyfrost/crosshair/config/Pixel.kt +++ b/src/main/kotlin/org/polyfrost/crosshair/config/Pixel.kt @@ -7,7 +7,8 @@ import cc.polyfrost.oneconfig.gui.elements.BasicElement import cc.polyfrost.oneconfig.utils.InputHandler import cc.polyfrost.oneconfig.utils.color.ColorPalette import cc.polyfrost.oneconfig.utils.dsl.nanoVGHelper -import org.polyfrost.crosshair.utils.Utils +import org.polyfrost.crosshair.utils.indexToPos +import org.polyfrost.crosshair.utils.posToIndex import kotlin.math.abs import kotlin.math.max @@ -38,7 +39,7 @@ class Pixel(val index: Int) : BasicElement(16, 16, ColorPalette.PRIMARY, true, 0 } override fun update(x: Float, y: Float, inputHandler: InputHandler) { - val pos = Utils.indexToPos(index) + val pos = indexToPos(index) val size = ModConfig.canvaSize backgroundColor = if (size % 2 == 1 && pos.x == size / 2 && pos.x == pos.y) { OneColor("703A3AFF").rgb @@ -97,7 +98,7 @@ class Pixel(val index: Int) : BasicElement(16, 16, ColorPalette.PRIMARY, true, 0 } fun setPixel(x: Int, y: Int, toggle: Boolean, color: Int) { - Drawer.pixels[Utils.posToIndex(x, y)].set(toggle, color) + Drawer.pixels[posToIndex(x, y)].set(toggle, color) } fun set(toggle: Boolean, color: Int) { diff --git a/src/main/kotlin/org/polyfrost/crosshair/elements/PresetElement.kt b/src/main/kotlin/org/polyfrost/crosshair/elements/PresetElement.kt index 61cdbfc..ccf5d85 100644 --- a/src/main/kotlin/org/polyfrost/crosshair/elements/PresetElement.kt +++ b/src/main/kotlin/org/polyfrost/crosshair/elements/PresetElement.kt @@ -6,12 +6,11 @@ import cc.polyfrost.oneconfig.gui.elements.* import cc.polyfrost.oneconfig.renderer.asset.* import cc.polyfrost.oneconfig.utils.InputHandler import cc.polyfrost.oneconfig.utils.color.ColorPalette -import cc.polyfrost.oneconfig.utils.dsl.nanoVG 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.Utils +import org.polyfrost.crosshair.utils.* import java.io.File import java.util.UUID @@ -21,16 +20,16 @@ private val copy = SVG("/assets/polycrosshair/copy.svg") class PresetElement(val crosshair: CrosshairEntry) : BasicElement(149, 149, ColorPalette.SECONDARY, true) { val removeButton = BasicButton(32, 32, remove, 2, ColorPalette.TERTIARY) val copyButton = BasicButton(32, 32, copy, 2, ColorPalette.TERTIARY) - val bufferedImage = Utils.toBufferedImage(crosshair.img) + val bufferedImage = toBufferedImage(crosshair.img) val fileName = UUID.randomUUID().toString() - val image = Image(Utils.export(bufferedImage, fileName), AssetHelper.DEFAULT_FLAGS or 32) + val image = Image(export(bufferedImage, fileName), AssetHelper.DEFAULT_FLAGS or 32) init { removeButton.setClickAction { Drawer.removeQueue.add(crosshair) } copyButton.setClickAction { - Utils.copy(bufferedImage) + copy(bufferedImage) } } diff --git a/src/main/kotlin/org/polyfrost/crosshair/render/CrosshairRenderer.kt b/src/main/kotlin/org/polyfrost/crosshair/render/CrosshairRenderer.kt index dfa6737..9c3ca87 100644 --- a/src/main/kotlin/org/polyfrost/crosshair/render/CrosshairRenderer.kt +++ b/src/main/kotlin/org/polyfrost/crosshair/render/CrosshairRenderer.kt @@ -7,8 +7,8 @@ import cc.polyfrost.oneconfig.libs.universal.UResolution import cc.polyfrost.oneconfig.utils.dsl.mc import net.minecraft.client.gui.Gui import net.minecraft.client.renderer.EntityRenderer -import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.renderer.Tessellator +import net.minecraft.client.renderer.GlStateManager as GL import net.minecraft.client.renderer.texture.DynamicTexture import net.minecraft.client.renderer.vertex.DefaultVertexFormats import net.minecraft.entity.monster.IMob @@ -17,35 +17,31 @@ import net.minecraft.entity.passive.EntityAnimal import net.minecraft.entity.passive.EntityVillager import net.minecraft.entity.passive.EntityWaterMob import net.minecraft.entity.player.EntityPlayer -import net.minecraft.util.MovingObjectPosition import net.minecraftforge.client.event.RenderGameOverlayEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.lwjgl.opengl.GL11 import org.polyfrost.crosshair.config.ModConfig import org.polyfrost.crosshair.mixin.GuiIngameAccessor import java.awt.image.BufferedImage -import kotlin.math.roundToInt +import kotlin.math.ceil object CrosshairRenderer { + private var drawingImage = BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB) private var texture = DynamicTexture(15, 15) private var textureLocation = mc.textureManager.getDynamicTextureLocation("polycrosshair", texture) private var whiteTexture = DynamicTexture(15, 15) private var whiteTextureLocation = mc.textureManager.getDynamicTextureLocation("polycrosshair", whiteTexture) fun updateTexture(image: OneImage) { - val paddedImage = if (ModConfig.canvaSize % 2 == 1 && ModConfig.newCurrentCrosshair.padToEvenSize) { - addPixel(image.image) - } else { - image.image - } - texture = DynamicTexture(paddedImage) + drawingImage = scaleImage(image.image, UResolution.scaleFactor.toFloat() * ModConfig.newCurrentCrosshair.scale / 100f) + texture = DynamicTexture(drawingImage) textureLocation = mc.textureManager.getDynamicTextureLocation("polycrosshair", texture) - whiteTexture = DynamicTexture(paddedImage.width, paddedImage.height) - for (posY in 0..