generated from Polyfrost/OneConfigExampleMod
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
764 additions
and
604 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
src/dummy/java/cc/polyfrost/oneconfig/internal/assets/Images.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package cc.polyfrost.oneconfig.internal.assets; | ||
|
||
import cc.polyfrost.oneconfig.renderer.asset.Image; | ||
//import cc.polyfrost.oneconfig.renderer.asset.Image; | ||
|
||
public class Images { | ||
public static final Image ALPHA_GRID = new Image("/assets/oneconfig/options/AlphaGrid.png"); | ||
// public static final Image ALPHA_GRID = new Image("/assets/oneconfig/options/AlphaGrid.png"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 28 additions & 26 deletions
54
src/main/kotlin/org/polyfrost/crosshair/config/CrosshairEntry.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,48 @@ | ||
package org.polyfrost.crosshair.config | ||
|
||
import cc.polyfrost.oneconfig.config.annotations.Button | ||
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.* | ||
|
||
class CrosshairEntry( | ||
var img: String = "iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAAEUlEQVR42mNgGAWjYBQMIgAAA5MAAecADfkAAAAASUVORK5CYII\u003d", | ||
) { | ||
|
||
@Slider(name = "Scale %", min = 0f, max = 200f) | ||
import org.polyfrost.oneconfig.api.config.v1.annotations.Button | ||
import org.polyfrost.oneconfig.api.config.v1.annotations.Slider | ||
import org.polyfrost.oneconfig.api.config.v1.annotations.Switch | ||
import org.polyfrost.oneconfig.utils.v1.dsl.runAsync | ||
|
||
class CrosshairEntry(var base64: String) { | ||
|
||
companion object { | ||
|
||
const val DEFAULT = "iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAAEUlEQVR42mNgGAWjYBQMIgAAA5MAAecADfkAAAAASUVORK5CYII\u003d" | ||
|
||
} | ||
|
||
@Slider(title = "Scale %", min = 0f, max = 200f) | ||
var scale = 100 | ||
|
||
@Slider(name = "Rotation", min = -180f, max = 180f) | ||
@Slider(title = "Rotation", min = -180f, max = 180f) | ||
var rotation = 0 | ||
|
||
@Slider(name = "X Offset", min = -1920f, max = 1920f) | ||
@Slider(title = "X Offset", min = -1920f, max = 1920f) | ||
var offsetX = 0 | ||
|
||
@Slider(name = "Y Offset", min = -1080f, max = 1080f) | ||
@Slider(title = "Y Offset", min = -1080f, max = 1080f) | ||
var offsetY = 0 | ||
|
||
@Switch(name = "Centered", description = "In vanilla Minecraft, the crosshair is not centered. Enable this option to center the crosshair.") | ||
@Switch(title = "Centered", description = "In vanilla Minecraft, the crosshair is not centered. Enable this option to center the crosshair.") | ||
var centered = false | ||
|
||
@Button(name = "Transform", text = "Reset", size = 1) | ||
@Button(title = "Transform", text = "Reset") | ||
var transformReset = Runnable { | ||
runAsync { | ||
val img = PolyCrosshairConfig.newCurrentCrosshair.img | ||
PolyCrosshairConfig.newCurrentCrosshair.loadFrom(CrosshairEntry()) | ||
PolyCrosshairConfig.newCurrentCrosshair.img = img | ||
save(Drawer.saveFromDrawer(false)) | ||
val base64 = PolyCrosshairConfig.currentCustomCrosshair.base64 | ||
PolyCrosshairConfig.currentCustomCrosshair.loadFrom(CrosshairEntry(DEFAULT)) | ||
PolyCrosshairConfig.currentCustomCrosshair.base64 = base64 | ||
// save(Drawer.saveFromDrawer(false)) | ||
} | ||
} | ||
|
||
fun loadFrom(entry: CrosshairEntry) { | ||
val newFields = ConfigUtils.getClassFields(entry::class.java) | ||
val fields = ConfigUtils.getClassFields(this::class.java) | ||
for (i in 0..<fields.size) { | ||
fields[i].set(this, ConfigUtils.getField(newFields[i], entry)) | ||
} | ||
// val newFields = ConfigUtils.getClassFields(entry::class.java) | ||
// val fields = ConfigUtils.getClassFields(this::class.java) | ||
// for (i in 0..<fields.size) { | ||
// fields[i].set(this, ConfigUtils.getField(newFields[i], entry)) | ||
// } | ||
} | ||
} |
138 changes: 138 additions & 0 deletions
138
src/main/kotlin/org/polyfrost/crosshair/config/CrosshairVisualizer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package org.polyfrost.crosshair.config | ||
|
||
import org.polyfrost.oneconfig.api.config.v1.Property | ||
import org.polyfrost.oneconfig.api.config.v1.Visualizer | ||
import org.polyfrost.polyui.animate.Animations | ||
import org.polyfrost.polyui.color.PolyColor | ||
import org.polyfrost.polyui.color.argb | ||
import org.polyfrost.polyui.color.mutable | ||
import org.polyfrost.polyui.color.rgba | ||
import org.polyfrost.polyui.component.Drawable | ||
import org.polyfrost.polyui.component.extensions.onClick | ||
import org.polyfrost.polyui.component.extensions.setPalette | ||
import org.polyfrost.polyui.component.extensions.withBoarder | ||
import org.polyfrost.polyui.component.impl.Block | ||
import org.polyfrost.polyui.component.impl.Button | ||
import org.polyfrost.polyui.component.impl.ColorPicker | ||
import org.polyfrost.polyui.component.impl.Group | ||
import org.polyfrost.polyui.operations.Recolor | ||
import org.polyfrost.polyui.utils.ref | ||
import kotlin.math.abs | ||
import kotlin.math.max | ||
|
||
class CrosshairVisualizer : Visualizer { | ||
|
||
override fun visualize(prop: Property<*>): Drawable { | ||
val crosshairs = prop.getAs<List<CrosshairEntry>>() | ||
val size = prop.getMetadata<Int>("size") ?: 15 | ||
|
||
val pickedColor = rgba(255, 255, 255).mutable().ref() | ||
val pixels = mutableListOf<CrosshairPixel>() | ||
|
||
fun List<CrosshairPixel>.getAt(x: Int, y: Int): CrosshairPixel { | ||
return this[x + y * size] | ||
} | ||
|
||
for (index in 0 until size * size) { | ||
pixels.add(CrosshairPixel(index, size).onClick { event -> | ||
val state = event.button == 0 | ||
val newPixelValue = if (state) pickedColor.element else CrosshairPixel.indexToColor(index, size) | ||
set(newPixelValue, state) | ||
|
||
val mirrorMode = PolyCrosshairConfig.MirrorMode.values()[PolyCrosshairConfig.mirror] | ||
if (mirrorMode != PolyCrosshairConfig.MirrorMode.OFF) { // NOTE: We do not need to run any mathematical calculations unnecessarily if we are not mirroring. | ||
val canvasCenter = (size + 1) / 2f - 1 | ||
val disX = abs(index % size - canvasCenter) | ||
val disY = abs(index / size - canvasCenter) | ||
|
||
when (mirrorMode) { | ||
PolyCrosshairConfig.MirrorMode.HORIZONTAL -> { | ||
pixels.getAt(size - disX.toInt() - 1, index / size).set(newPixelValue, state) | ||
} | ||
|
||
PolyCrosshairConfig.MirrorMode.VERTICAL -> { | ||
pixels.getAt(index % size, size - disY.toInt() - 1).set(newPixelValue, state) | ||
} | ||
|
||
PolyCrosshairConfig.MirrorMode.QUADRANT -> { | ||
if (size % 2 == 1 && (disX.toInt() == 0 || disY.toInt() == 0)) { | ||
val dis = max(disX, disY).toInt() | ||
pixels.getAt(size - dis - 1, canvasCenter.toInt()).set(newPixelValue, state) | ||
pixels.getAt(dis, canvasCenter.toInt()).set(newPixelValue, state) | ||
pixels.getAt(canvasCenter.toInt(), size - dis - 1).set(newPixelValue, state) | ||
pixels.getAt(canvasCenter.toInt(), dis).set(newPixelValue, state) | ||
} else { | ||
pixels.getAt(size - disX.toInt() - 1, index / size).set(newPixelValue, state) | ||
pixels.getAt(index % size, size - disY.toInt() - 1).set(newPixelValue, state) | ||
pixels.getAt(size - disX.toInt() - 1, size - disY.toInt() - 1).set(newPixelValue, state) | ||
} | ||
} | ||
|
||
PolyCrosshairConfig.MirrorMode.OFF -> { | ||
throw IllegalStateException("What the heckers?! This should never happen!") | ||
} | ||
} | ||
} | ||
|
||
true | ||
}) | ||
} | ||
|
||
return Group( | ||
Block( | ||
children = pixels.toTypedArray(), | ||
), | ||
|
||
Group( | ||
Group( | ||
Button(text = "Export"), | ||
Button(text = "Import") | ||
), | ||
|
||
Group( | ||
Block(color = pickedColor.element) | ||
.withBoarder(3f, color = { page.border20 }) | ||
.onClick { ColorPicker(pickedColor, null, null, polyUI); true }, | ||
Button(text = "Reset").setPalette { state.danger }, | ||
Button(text = "Save").setPalette { onBrand.fg } | ||
) | ||
) | ||
) | ||
} | ||
|
||
} | ||
|
||
private class CrosshairPixel( | ||
private val index: Int, | ||
private val canvasSize: Int | ||
) : Block( | ||
color = indexToColor(index, canvasSize) | ||
) { | ||
|
||
companion object { | ||
|
||
fun indexToColor(index: Int, size: Int): PolyColor { | ||
return argb(if (size % 2 == 1 && index % size == size / 2 && index % size == index / size) { | ||
0x703A3AFF | ||
} else if ((index % size + index / size) % 2 == 0) { | ||
0x333333FF | ||
} else { | ||
0x444444FF | ||
}) | ||
} | ||
|
||
} | ||
|
||
private var state = false | ||
|
||
fun set(color: PolyColor, state: Boolean) { | ||
Recolor( | ||
drawable = this, | ||
toColor = color, | ||
animation = Animations.Default.create(0L), // Instant | ||
).add() | ||
|
||
this.state = if (color.a == 0) false else state | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/org/polyfrost/crosshair/config/Crosshairs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.polyfrost.crosshair.config | ||
|
||
import org.polyfrost.oneconfig.api.config.v1.annotations.Option | ||
|
||
@Option(display = CrosshairVisualizer::class) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
@Target(AnnotationTarget.FIELD) | ||
@MustBeDocumented | ||
annotation class Crosshairs( | ||
val category: String = "General", | ||
val subcategory: String = "General", | ||
) |
Oops, something went wrong.