Skip to content

Commit

Permalink
HUD stuff and bump polyui
Browse files Browse the repository at this point in the history
  • Loading branch information
nextdayy committed May 26, 2024
1 parent dc045ca commit 4493383
Show file tree
Hide file tree
Showing 25 changed files with 179 additions and 124 deletions.
9 changes: 5 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ plugins {
`java-library`
}

val modMajor = project.properties["mod_major_version"]
val modMinor = project.properties["mod_minor_version"]
val major = project.properties["version_major"]
val minor = project.properties["version_minor"]
val patch = project.properties["version_patch"]

version = "$modMajor$modMinor"
group = "org.polyfrost.oneconfig"
version = "$major.$minor.$patch"
group = properties["group"].toString()

allprojects {
apply(plugin = rootProject.libs.plugins.licenser.get().pluginId)
Expand Down
17 changes: 11 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
mod_name=OneConfig
group=org.polyfrost.oneconfig
name=OneConfig
mod_id=oneconfig
mod_major_version=1.0.0-alpha
mod_minor_version=2
version_major=1
version_minor=0
version_patch=0-alpha3

polyfrost.defaults.loom=2
org.gradle.daemon=true

org.gradle.parallel=true
org.gradle.configureoncommand=true
org.gradle.parallel.threads=4
org.gradle.caching=true
org.gradle.configuration-cache=true
org.gradle.configureondemand=true
org.gradle.workers.max=4
org.gradle.jvmargs=-Xmx4G
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ kotlinx-coroutines = "1.8.0"
kotlinx-atomicfu = "0.24.0"
kotlinx-abi = "0.14.0"

pgt = "0.5.1"
pgt = "0.5.2"
shadow = "8.1.1"
licenser = "2.0.1"

polyui = "1.1.71"
polyui = "1.2.01"

log4j-api = "2.0-beta9" # used because this is the version that 1.8.9 supports, so we have to compile against the same (annoying)
log4j-impl = "2.23.1" # unvulnerable version
Expand Down
3 changes: 0 additions & 3 deletions modules/config-impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@

dependencies {
implementation(libs.bundles.nightconfig)
implementation(libs.polyui)
api(project(":modules:utils"))
api(project(":modules:config"))
api(project(":modules:ui"))
api(project(":modules:events"))
}

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import org.polyfrost.polyui.renderer.data.PolyImage
import org.polyfrost.polyui.unit.Align
import org.polyfrost.polyui.unit.Vec2
import org.polyfrost.polyui.unit.seconds
import org.polyfrost.polyui.utils.LinkedList
import org.polyfrost.polyui.utils.fastEach
import org.polyfrost.polyui.utils.image
import org.polyfrost.polyui.utils.mapToArray
import org.polyfrost.polyui.utils.rgba
Expand Down Expand Up @@ -83,7 +83,7 @@ open class ConfigVisualizer {
initialPage: String = "General",
): Drawable {
val now = System.nanoTime()
val options = HashMap<String, HashMap<String, LinkedList<Drawable>>>(4)
val options = HashMap<String, HashMap<String, ArrayList<Drawable>>>(4)

// asm: step 1: sort the tree into a map of:
// categories
Expand All @@ -105,7 +105,7 @@ open class ConfigVisualizer {
)
}

protected open fun flattenSubcategories(options: Map<String, Map<String, LinkedList<Drawable>>>): Map<String, Drawable> {
protected open fun flattenSubcategories(options: Map<String, Map<String, ArrayList<Drawable>>>): Map<String, Drawable> {
return options.mapValues { (_, subcategories) ->
Group(
alignment = alignCV,
Expand All @@ -121,7 +121,7 @@ open class ConfigVisualizer {
}
}

protected open /* suspend? */ fun processNode(node: Node, options: HashMap<String, HashMap<String, LinkedList<Drawable>>>) {
protected open /* suspend? */ fun processNode(node: Node, options: HashMap<String, HashMap<String, ArrayList<Drawable>>>) {
val icon =
when (val it = node.getMetadata<Any?>("icon")) {
null -> null
Expand All @@ -134,7 +134,7 @@ open class ConfigVisualizer {
val category = node.getMetadata<String>("category")?.strv() ?: "General"
val subcategory = node.getMetadata<String>("subcategory")?.strv() ?: "General"

val list = options.getOrPut(category) { HashMap(4) }.getOrPut(subcategory) { LinkedList() }
val list = options.getOrPut(category) { HashMap(4) }.getOrPut(subcategory) { ArrayList(8) }
if (node is Property<*>) {
val vis = node.getVisualizer() ?: return
list.add(wrap(vis.visualize(node), node.title, node.description, icon))
Expand All @@ -152,7 +152,7 @@ open class ConfigVisualizer {
return Group(
children = categories.mapToArray { (category, options) ->
Button(text = category).events {
Event.Mouse.Clicked(0) then {
Event.Mouse.Clicked then {
parent[0] = options
}
}
Expand All @@ -176,7 +176,7 @@ open class ConfigVisualizer {
wrap(Image("chevron-down.svg".image()).also { it.rotation = PI }, title, desc, icon).events {
self.color = PolyColor.TRANSPARENT.toAnimatable()
var open = false
Event.Mouse.Clicked(0) then {
Event.Mouse.Clicked then {
open = !open
Rotate(this[1], if (!open) PI else 0.0, false, Animations.EaseOutQuad.create(0.2.seconds)).add()
val value = parent[1].height
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fun interface Visualizer {
size = Vec2(300f, 32f),
text = text ?: "oneconfig.button.default",
).events {
Event.Mouse.Clicked(0) then {
Event.Mouse.Clicked then {
action.run()
}
}
Expand Down Expand Up @@ -112,7 +112,7 @@ fun interface Visualizer {
visibleSize = Vec2(300f, 32f),
text = prop.getAs<Number>().toString(),
).events {
Event.Change.Text() then {
Event.Change.Text then {
if (it.text.isEmpty()) return@then
try {
val v = it.text.toFloat()
Expand Down Expand Up @@ -141,7 +141,7 @@ fun interface Visualizer {
initial = prop.type.enumConstants.indexOf(prop.get()),
optionLateralPadding = 20f,
).events {
Event.Change.Number() then {
Event.Change.Number then {
prop.setAs(it.amount)
}
}
Expand All @@ -157,7 +157,7 @@ fun interface Visualizer {
initial = prop.getAs(),
optionLateralPadding = 20f,
).events {
Event.Change.Number() then {
Event.Change.Number then {
prop.setAs(it.amount)
}
}
Expand All @@ -176,7 +176,7 @@ fun interface Visualizer {
max = max,
initialValue = prop.getAs<Number>().toFloat(),
).events {
Event.Change.Number() then {
Event.Change.Number then {
prop.setAs(it.amount)
}
}
Expand All @@ -192,7 +192,7 @@ fun interface Visualizer {
size = 21f,
state = state,
).events {
Event.Change.State() then {
Event.Change.State then {
prop.setAs(it.state)
}
}
Expand All @@ -208,7 +208,7 @@ fun interface Visualizer {
visibleSize = Vec2(200f, 12f),
text = prop.getAs(),
).events {
Event.Change.Text() then {
Event.Change.Text then {
prop.setAs(it.text)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@

package org.polyfrost.oneconfig.api.config.v1;

import java.util.HashMap;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.UnmodifiableView;
import org.jetbrains.annotations.VisibleForTesting;

import java.util.HashMap;
import java.util.Map;


public abstract class Node {
protected static final Logger LOGGER = LogManager.getLogger("OneConfig/Config");
Expand Down Expand Up @@ -77,8 +78,12 @@ public String getID() {
* It may only contain alphanumeric characters, and underscores.
* <br>note that <b>this operation is permanent</b> and cannot be undone/changed!
*/
public void setID(String id) {
if (id == null) throw new IllegalArgumentException("input ID cannot be null");
public void setID(@NotNull String id) {
//noinspection ConstantValue
if (id == null) {
this.id = null;
return;
}
if (this.id != null) throw new IllegalStateException("ID is already set");
String s = id.trim().replaceAll("[^\\w$\\-./\\\\]", "_");
if (s.isEmpty()) throw new IllegalArgumentException("ID cannot be empty (or contain only whitespace)");
Expand Down
5 changes: 3 additions & 2 deletions modules/hud/api/hud.api
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
public abstract class org/polyfrost/oneconfig/api/hud/v1/Hud : org/polyfrost/oneconfig/api/config/v1/Config, java/lang/Cloneable {
public fun <init> ()V
protected fun addSpecifics (Lorg/polyfrost/oneconfig/api/config/v1/Tree;)V
protected fun addToSerialized (Lorg/polyfrost/oneconfig/api/config/v1/Tree;)V
public fun backgroundColor ()Lorg/polyfrost/polyui/color/PolyColor;
public abstract fun category ()Lorg/polyfrost/oneconfig/api/hud/v1/Hud$Category;
public synthetic fun clone ()Ljava/lang/Object;
Expand Down Expand Up @@ -80,6 +80,7 @@ public abstract class org/polyfrost/oneconfig/api/hud/v1/LegacyHud : org/polyfro
public abstract class org/polyfrost/oneconfig/api/hud/v1/TextHud : org/polyfrost/oneconfig/api/hud/v1/Hud {
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
protected fun addToSerialized (Lorg/polyfrost/oneconfig/api/config/v1/Tree;)V
public synthetic fun create ()Lorg/polyfrost/polyui/component/Drawable;
protected fun create ()Lorg/polyfrost/polyui/component/impl/Text;
public final fun getPrefix ()Ljava/lang/String;
Expand Down Expand Up @@ -118,7 +119,7 @@ public final class org/polyfrost/oneconfig/api/hud/v1/internal/HudpagesKt {
public static final field angleSnapMargin D
public static final field minMargin F
public static final field snapMargin F
public static final fun HudsPage (Lorg/polyfrost/polyui/utils/LinkedList;)Lorg/polyfrost/polyui/component/Drawable;
public static final fun HudsPage (Ljava/util/ArrayList;)Lorg/polyfrost/polyui/component/Drawable;
public static final fun createInspectionsScreen (Lorg/polyfrost/oneconfig/api/hud/v1/Hud;)Lorg/polyfrost/polyui/component/Drawable;
public static final fun getAlignC ()Lorg/polyfrost/polyui/unit/Align;
public static final fun textOptions (Lorg/polyfrost/polyui/component/impl/Text;)Lorg/polyfrost/polyui/component/Drawable;
Expand Down
5 changes: 0 additions & 5 deletions modules/hud/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@
*/

dependencies {
api(project(":modules:config"))
api(project(":modules:events"))
api(project(":modules:config-impl"))
api(project(":modules:utils"))
api(project(":modules:ui"))
implementation(libs.polyui)
compileOnly("org.polyfrost:universalcraft-1.8.9-forge:${libs.versions.universalcraft.get()}")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.polyfrost.oneconfig.api.config.v1.Tree
import org.polyfrost.polyui.color.PolyColor
import org.polyfrost.polyui.component.Drawable
import org.polyfrost.polyui.unit.Vec2
import org.polyfrost.polyui.utils.fastAll
import kotlin.io.path.exists
import kotlin.random.Random

Expand Down Expand Up @@ -85,15 +86,15 @@ abstract class Hud<T : Drawable> : Cloneable, Config("null", null, "null", null)
tree.addMetadata("frontendIgnore", true)
tree["x"] = ktProperty(out.hud::x)
tree["y"] = ktProperty(out.hud::y)
tree["skewX"] = ktProperty(out.hud::skewX)
tree["skewY"] = ktProperty(out.hud::skewY)
out.addToSerialized(tree)
tree["hidden"] = ktProperty(out::hidden)
tree["alpha"] = ktProperty(out.hud::alpha)
tree["scaleX"] = ktProperty(out.hud::scaleX)
tree["scaleY"] = ktProperty(out.hud::scaleY)
tree["rotation"] = ktProperty(out.hud::rotation)
tree["alpha"] = ktProperty(out.hud::alpha)
tree["hidden"] = ktProperty(out::hidden)
tree["skewX"] = ktProperty(out.hud::skewX)
tree["skewY"] = ktProperty(out.hud::skewY)
tree["hudClass"] = simple(value = out::class.java.name)
addSpecifics(tree)
if (with != null) tree.overwrite(with)
else HudManager.LOGGER.info("generated new HUD config for ${out.title()} -> ${tree.id}")
out.tree = tree
Expand All @@ -116,7 +117,7 @@ abstract class Hud<T : Drawable> : Cloneable, Config("null", null, "null", null)
return p
}

protected open fun addSpecifics(tree: Tree) {}
protected open fun addToSerialized(tree: Tree) {}

@Transient
private var it: T? = null
Expand Down Expand Up @@ -145,7 +146,7 @@ abstract class Hud<T : Drawable> : Cloneable, Config("null", null, "null", null)
it.enabled = value
if (siblings.size == 1) {
it.parent.enabled = value
} else if (!value && siblings.allAre { !it.enabled }) {
} else if (!value && siblings.fastAll { !it.enabled }) {
it.parent.enabled = false
}
it.parent.recalculate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ import org.polyfrost.polyui.unit.Align
import org.polyfrost.polyui.unit.Vec2
import org.polyfrost.polyui.unit.by
import org.polyfrost.polyui.unit.seconds
import org.polyfrost.polyui.utils.LinkedList
import org.polyfrost.polyui.utils.fastEach
import org.polyfrost.polyui.utils.ref
import org.polyfrost.polyui.utils.rgba
import org.polyfrost.universal.UResolution
import kotlin.math.PI

object HudManager {
internal val LOGGER = LogManager.getLogger("OneConfig/HUD")
private val huds = LinkedList<Hud<out Drawable>>()
private val huds = ArrayList<Hud<out Drawable>>()
private val hudProviders = HashMap<Class<out Hud<out Drawable>>, Hud<out Drawable>>()
private val snapLineColor = rgba(170, 170, 170, 0.8f)

Expand Down Expand Up @@ -151,7 +151,7 @@ object HudManager {
Event.Mouse.Exited then {
Fade(this[0], 0.1f, false, Animations.EaseInOutQuad.create(0.08.seconds)).add()
}
Event.Mouse.Clicked(0) then {
Event.Mouse.Clicked then {
// asm: makes close button easier to use
if (polyUI.mouseY < 40f) {
false
Expand Down Expand Up @@ -217,9 +217,9 @@ object HudManager {
}

private fun editorClose() {
panelExists = false
toggleHudPicker()
ConfigManager.active().saveAll()
panelExists = false
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
package org.polyfrost.oneconfig.api.hud.v1

import org.jetbrains.annotations.ApiStatus
import org.polyfrost.polyui.PolyUI
import org.polyfrost.polyui.component.Drawable
import org.polyfrost.polyui.component.namedId
import org.polyfrost.polyui.unit.Vec2
Expand Down Expand Up @@ -71,19 +70,13 @@ abstract class LegacyHud : Hud<Drawable>() {
}

return object : Drawable(size = size) {
override fun preRender() {}
override fun preRender(delta: Long) {}

override fun render() {
render(UMatrixStack.Compat.get(), x, y)
}

override fun postRender() {}

override fun setup(polyUI: PolyUI): Boolean {
if (initialized) return false
initialized = true
return true
}
}.namedId("LegacyHud")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

package org.polyfrost.oneconfig.api.hud.v1

import org.polyfrost.oneconfig.api.config.v1.Properties
import org.polyfrost.oneconfig.api.config.v1.Tree
import org.polyfrost.polyui.component.impl.Text
import org.polyfrost.polyui.unit.milliseconds
import org.polyfrost.polyui.unit.minutes
Expand Down Expand Up @@ -58,6 +60,11 @@ abstract class TextHud(
return true
}

override fun addToSerialized(tree: Tree) {
tree["font"] = Properties.ktProperty(hud::_font)
tree["fontSize"] = Properties.ktProperty(hud::uFontSize)
}

override fun initialize() {
update()
}
Expand Down
Loading

0 comments on commit 4493383

Please sign in to comment.