From 090cafe9dc04a97dd3a1abe05ff4ca03516b85a3 Mon Sep 17 00:00:00 2001 From: nextdayy <79922345+nextdayy@users.noreply.github.com> Date: Sat, 30 Nov 2024 18:23:18 +0000 Subject: [PATCH] fixes --- .../org/polyfrost/crosshair/CrosshairHUD.kt | 37 ++++++++++++++----- .../polyfrost/crosshair/PolyCrosshairUI.kt | 2 +- src/main/resources/mixins.polycrosshair.json | 1 - 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/org/polyfrost/crosshair/CrosshairHUD.kt b/src/main/kotlin/org/polyfrost/crosshair/CrosshairHUD.kt index 31f0fd5..2785f5b 100644 --- a/src/main/kotlin/org/polyfrost/crosshair/CrosshairHUD.kt +++ b/src/main/kotlin/org/polyfrost/crosshair/CrosshairHUD.kt @@ -8,6 +8,8 @@ import org.polyfrost.polyui.unit.Vec2 import org.polyfrost.polyui.utils.getResourceStream import java.nio.file.Files import java.nio.file.Paths +import java.nio.file.StandardCopyOption +import kotlin.io.path.exists object CrosshairHUD : Hud() { @Switch(title = "Show in F3") @@ -23,25 +25,40 @@ object CrosshairHUD : Hud() { private var showInThirdPerson = true @Include - var currentCrosshair: String = "null" + var currentCrosshair: String? = null + set(value) { + field = value + setCrosshair(value) + } + + private val target = Paths.get("polycrosshair.png") override fun category() = Category.COMBAT - override fun create(): Image { - if (currentCrosshair == "null") { - Files.copy(getResourceStream("assets/polycrosshair/default.png"), Paths.get("polycrosshair.png")) - } else { - Files.copy(Paths.get(currentCrosshair), Paths.get("polycrosshair.png")) - } - return Image("polycrosshair.png") + override fun initialize() { + setCrosshair(currentCrosshair) } - fun reload() { - get().renderer.delete(get().image) + override fun hasBackground() = false + + override fun create() = Image(target.toUri().toString()) + + private fun setCrosshair(crosshair: String?) { + if (crosshair.isNullOrEmpty() || !Paths.get(crosshair).exists()) { + Files.copy(getResourceStream("assets/polycrosshair/default.png"), target, StandardCopyOption.REPLACE_EXISTING) + } else Files.copy(Paths.get(crosshair), target, StandardCopyOption.REPLACE_EXISTING) + val it = get() + if (!it.initialized) return + it.renderer.delete(it.image) + val size = it.polyUI.size + it.x = size.x / 2f - it.size.x / 2f + it.y = size.y / 2f - it.size.y / 2f } override fun defaultPosition() = Vec2(1920f / 2f - 7f, 1080f / 2f - 7f) + override fun multipleInstancesAllowed() = false + override fun id() = "polycrosshair.json" override fun title() = "PolyCrosshair" diff --git a/src/main/kotlin/org/polyfrost/crosshair/PolyCrosshairUI.kt b/src/main/kotlin/org/polyfrost/crosshair/PolyCrosshairUI.kt index 872cdbf..bd971e0 100644 --- a/src/main/kotlin/org/polyfrost/crosshair/PolyCrosshairUI.kt +++ b/src/main/kotlin/org/polyfrost/crosshair/PolyCrosshairUI.kt @@ -91,7 +91,7 @@ fun open() { ), Group( Text("v2.0.0").setPalette { text.secondary }, - Image("assets/oneconfig/ico/close.svg").onInit { size = size.coerceAtLeast(24f by 24f) } + Image("assets/oneconfig/ico/close.svg").onInit { size = Vec2(24f, 24f) } .setDestructivePalette().withStates().onClick { // will save the crosshair needsToSave = true diff --git a/src/main/resources/mixins.polycrosshair.json b/src/main/resources/mixins.polycrosshair.json index b8ffed2..aa5e943 100644 --- a/src/main/resources/mixins.polycrosshair.json +++ b/src/main/resources/mixins.polycrosshair.json @@ -7,7 +7,6 @@ "maxShiftBy": 5 }, "client": [ - "EntityRendererMixin", "GuiIngameAccessor", "GuiIngameMixin" ],