Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wyvest moment 🤫🧏‍♂️ #1

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/main/kotlin/org/polyfrost/crosshair/PolyCrosshair.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -26,6 +31,8 @@ object PolyCrosshair {

val dir = File(path)

private var lastGuiScale = 1f

@Mod.EventHandler
fun onFMLInitialization(event: FMLInitializationEvent) {
clearCaches()
Expand All @@ -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()
Expand Down
25 changes: 15 additions & 10 deletions src/main/kotlin/org/polyfrost/crosshair/config/CrosshairEntry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
31 changes: 13 additions & 18 deletions src/main/kotlin/org/polyfrost/crosshair/config/Drawer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand All @@ -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) }
}

}
Expand Down Expand Up @@ -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
Expand All @@ -130,7 +125,7 @@ object Drawer : BasicOption(null, null, "", "", "", "", 2) {

for (posY in 0..<ModConfig.canvaSize) {
for (posX in 0..<ModConfig.canvaSize) {
pixels[Utils.posToIndex(posX, posY)].draw(vg, x.toFloat(), y.toFloat(), inputHandler)
pixels[posToIndex(posX, posY)].draw(vg, x.toFloat(), y.toFloat(), inputHandler)
}
}

Expand Down Expand Up @@ -221,11 +216,11 @@ object Drawer : BasicOption(null, null, "", "", "", "", 2) {
for (posY in 0..<ModConfig.canvaSize) {
for (posX in 0..<ModConfig.canvaSize) {
val c = loadedImage.image.getRGB(posX, posY)
pixels[Utils.posToIndex(posX, posY)].isToggled = c shr 24 != 0
pixels[Utils.posToIndex(posX, posY)].color = c
pixels[posToIndex(posX, posY)].isToggled = c shr 24 != 0
pixels[posToIndex(posX, posY)].color = c
}
}
if (save) Utils.save(loadedImage)
if (save) save(loadedImage)
return loadedImage
}

Expand All @@ -236,7 +231,7 @@ object Drawer : BasicOption(null, null, "", "", "", "", 2) {
return null
}
for (i in ModConfig.drawer) {
val pos = Utils.indexToPos(i.key)
val pos = indexToPos(i.key)
if (pos.x >= ModConfig.canvaSize || pos.y >= ModConfig.canvaSize) {
pixels[i.key].isToggled = false
continue
Expand All @@ -249,15 +244,15 @@ object Drawer : BasicOption(null, null, "", "", "", "", 2) {

fun reset() {
val newEntry = CrosshairEntry()
Utils.toBufferedImage(newEntry.img)?.let {
toBufferedImage(newEntry.img)?.let {
loadImage(it, false, newEntry)
}
}

fun move(x: Int, y: Int) {
val newPositions = HashMap<Pos, Int>()
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
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
Expand Down
20 changes: 14 additions & 6 deletions src/main/kotlin/org/polyfrost/crosshair/config/ModConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Int, Int>()

var currentCrosshair = ""

@DualOption(
name = "Mode",
left = "Vanilla",
right = "Custom",
size = 2
)
var mode = false

@CustomOption
var crosshairs = ArrayList<String>()

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/kotlin/org/polyfrost/crosshair/config/Pixel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
}
}

Expand Down
Loading
Loading