Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nextdayy committed Nov 30, 2024
1 parent 79256d5 commit 090cafe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
37 changes: 27 additions & 10 deletions src/main/kotlin/org/polyfrost/crosshair/CrosshairHUD.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Image>() {
@Switch(title = "Show in F3")
Expand All @@ -23,25 +25,40 @@ object CrosshairHUD : Hud<Image>() {
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"
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/polyfrost/crosshair/PolyCrosshairUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/mixins.polycrosshair.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"maxShiftBy": 5
},
"client": [
"EntityRendererMixin",
"GuiIngameAccessor",
"GuiIngameMixin"
],
Expand Down

0 comments on commit 090cafe

Please sign in to comment.