diff --git a/build.gradle.kts b/build.gradle.kts index ea381c1c5..1a2925e1f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -48,7 +48,7 @@ allprojects { implementation("com.github.stivais:AuroraUI:0.9.1-beta") // todo: create releases for aurora -// implementation("com.github.stivais:AuroraUI:e8cff5402b") +// implementation("com.github.stivais:AuroraUI:4cbd8bc343") implementation("com.github.odtheking:odin-lwjgl:faeaa48b39") diff --git a/src/main/kotlin/me/odinmain/features/Module.kt b/src/main/kotlin/me/odinmain/features/Module.kt index fa7b6e3e5..6538d6b96 100644 --- a/src/main/kotlin/me/odinmain/features/Module.kt +++ b/src/main/kotlin/me/odinmain/features/Module.kt @@ -1,6 +1,5 @@ package me.odinmain.features -import com.github.stivais.aurora.elements.ElementScope import me.odinmain.OdinMain import me.odinmain.features.huds.HUD import me.odinmain.features.impl.render.ClickGUI @@ -166,7 +165,7 @@ abstract class Module( fun HUD( name: String, - block: ElementScope.() -> Unit + block: HUD.Scope.() -> Unit ): HUD { return HUD( name, diff --git a/src/main/kotlin/me/odinmain/features/huds/HUD.kt b/src/main/kotlin/me/odinmain/features/huds/HUD.kt index d04f313d4..1a3463879 100644 --- a/src/main/kotlin/me/odinmain/features/huds/HUD.kt +++ b/src/main/kotlin/me/odinmain/features/huds/HUD.kt @@ -16,11 +16,11 @@ import kotlin.reflect.jvm.isAccessible class HUD( val name: String, val module: Module, - val builder: ElementScope.() -> Unit + val builder: Scope.() -> Unit ) { val x = NumberSetting("x", 2.5f, 0f, 100f, description = "").hide() val y = NumberSetting("y", 2.5f, 0f, 100f, description = "").hide() - val scale = NumberSetting("Scale", 1f, 0.2f, 5f, increment = 0.1f, description = "") + val scale = NumberSetting("Scale", 1f, 0.2f, 5f, increment = 0.1f, description = "Size of this HUD.") /** * Settings tied to this HUD, these get saved inside the [setting][me.odinmain.features.settings.impl.HUDSetting] @@ -50,14 +50,11 @@ class HUD( module.settings.remove(delegate) } this.settings.add(delegate) - delegate.hide() } return this } - inner class Representation( - val preview: Boolean - ) : BlankElement(Constraints(x.value.percent, y.value.percent, Bounding, Bounding)) { + inner class Representation : BlankElement(Constraints(x.value.percent, y.value.percent, Bounding, Bounding)) { override var enabled: Boolean = true get() = field && this@HUD.module.enabled @@ -68,7 +65,7 @@ class HUD( override fun getDefaultPositions() = Pair(Undefined, Undefined) - fun refresh(scope: ElementScope) { + fun refresh(scope: Scope) { removeAll() builder.invoke(scope) scaleTransformation = this@HUD.scale.value @@ -86,10 +83,9 @@ class HUD( return null } - companion object { - inline val ElementScope.preview get() = element.preview + class Scope(element: HUD.Representation,val preview: Boolean) : ElementScope(element) { - inline fun ElementScope.needs(crossinline block: () -> Boolean) { + inline fun ElementScope<*>.needs(crossinline block: () -> Boolean) { if (!preview) { operation { element.enabled = block() @@ -98,7 +94,7 @@ class HUD( } } - fun ElementScope.refreshHUDs() { + fun refreshHUDs() { element.refresh(this) } } diff --git a/src/main/kotlin/me/odinmain/features/huds/HUDManager.kt b/src/main/kotlin/me/odinmain/features/huds/HUDManager.kt index f41e8de11..b2e8485bd 100644 --- a/src/main/kotlin/me/odinmain/features/huds/HUDManager.kt +++ b/src/main/kotlin/me/odinmain/features/huds/HUDManager.kt @@ -3,6 +3,7 @@ package me.odinmain.features.huds import com.github.stivais.aurora.color.Color import com.github.stivais.aurora.constraints.impl.measurements.Pixel import com.github.stivais.aurora.dsl.* +import com.github.stivais.aurora.elements.Element import com.github.stivais.aurora.elements.ElementScope import com.github.stivais.aurora.elements.Layout.Companion.section import com.github.stivais.aurora.elements.impl.Block.Companion.outline @@ -11,7 +12,6 @@ import com.github.stivais.aurora.elements.impl.popup import com.github.stivais.aurora.utils.loop import com.github.stivais.aurora.utils.withAlpha import me.odinmain.config.Config -import me.odinmain.features.huds.HUD.Companion.refreshHUDs import me.odinmain.features.impl.render.ClickGUI import me.odinmain.features.impl.render.ClickGUI.`gray 26` import me.odinmain.features.impl.render.ClickGUI.`gray 38` @@ -36,7 +36,9 @@ object HUDManager { fun setupHUDs() { UI = UIHandler(Aurora(renderer = NVGRenderer) { HUDs.loop { hud -> - hud.Representation(preview = false).scope(hud.builder) + val representation = hud.Representation() + representation.add() + HUD.Scope(representation, preview = false).apply { hud.builder(this) } } }) UI!!.open() @@ -46,9 +48,17 @@ object HUDManager { var hudOptions: Popup? = null + object : Element(copies()) { + override fun draw() { + renderer.line(snapLineX, 0f, snapLineX, ui.main.height, 1f, Color.WHITE.rgba) + renderer.line(0f, snapLineY, ui.main.width, snapLineY, 1f, Color.WHITE.rgba) + } + }.add() + HUDs.loop { hud -> - val representation = hud.Representation(preview = true) - representation.scope { + val representation = hud.Representation() + representation.add() + HUD.Scope(representation, preview = true).apply { hud.builder(this) onRemove { @@ -56,7 +66,7 @@ object HUDManager { hud.y.value = (element.y / ui.main.height) * 100f } onScroll { (amount) -> - hud.scale.value += 0.1f * amount + hud.scale.set(hud.scale.value + hud.scale.increment * amount) representation.scaleTransformation = hud.scale.value } diff --git a/src/main/kotlin/me/odinmain/features/impl/dungeon/BlessingDisplay.kt b/src/main/kotlin/me/odinmain/features/impl/dungeon/BlessingDisplay.kt index b74c43191..0099b60c2 100644 --- a/src/main/kotlin/me/odinmain/features/impl/dungeon/BlessingDisplay.kt +++ b/src/main/kotlin/me/odinmain/features/impl/dungeon/BlessingDisplay.kt @@ -1,37 +1,39 @@ package me.odinmain.features.impl.dungeon import com.github.stivais.aurora.color.Color -import com.github.stivais.aurora.dsl.at +import com.github.stivais.aurora.utils.loop import me.odinmain.features.Module -import me.odinmain.features.huds.HUD.Companion.needs -import me.odinmain.features.huds.HUD.Companion.preview import me.odinmain.features.settings.Setting.Companion.withDependency import me.odinmain.features.settings.impl.BooleanSetting import me.odinmain.features.settings.impl.ColorSetting import me.odinmain.utils.skyblock.dungeon.Blessing import me.odinmain.utils.skyblock.dungeon.DungeonUtils import me.odinmain.utils.ui.Colors -import me.odinmain.utils.ui.TextHUD import me.odinmain.utils.ui.buildText +import me.odinmain.utils.ui.getFont +import me.odinmain.utils.ui.makeFontSetting object BlessingDisplay : Module( name = "Blessing Display", description = "Displays the current blessings of the dungeon." ) { - private val power by BooleanSetting("Power Blessing", true, description = "Displays the power blessing.") + // general settings + private val textColor by ColorSetting("Text Color", Color.WHITE, allowAlpha = false, description = "The color of the text.") + private val font by makeFontSetting() + private val shadow by BooleanSetting("Shadow", true, description = "Whether to display a shadow behind the text.") + + private var power by BooleanSetting("Power Blessing", true, description = "Displays the power blessing.") + private val powerColor by ColorSetting("Power Color", Colors.MINECRAFT_DARK_RED, allowAlpha = false, description = "The color of the power blessing.").withDependency { power } private val time by BooleanSetting("Time Blessing", true, description = "Displays the time blessing.") + private val timeColor by ColorSetting("Time Color", Colors.MINECRAFT_DARK_PURPLE, allowAlpha = false, description = "The color of the time blessing.").withDependency { time } private val stone by BooleanSetting("Stone Blessing", false, description = "Displays the stone blessing.") + private val stoneColor by ColorSetting("Stone Color", Colors.MINECRAFT_GRAY, allowAlpha = false, description = "The color of the stone blessing.").withDependency { stone } private val life by BooleanSetting("Life Blessing", false, description = "Displays the life blessing.") + private val lifeColor by ColorSetting("Life Color", Color.RED, allowAlpha = false, description = "The color of the life blessing.").withDependency { life } private val wisdom by BooleanSetting("Wisdom Blessing", false, description = "Displays the wisdom blessing.") + private val wisdomColor by ColorSetting("Wisdom Color", Colors.MINECRAFT_BLUE, allowAlpha = false, description = "The color of the wisdom blessing.").withDependency { wisdom } - private val wisdomColor by ColorSetting("Wisdom Color", Colors.MINECRAFT_BLUE, true, description = "The color of the wisdom blessing.").withDependency { wisdom } - private val powerColor by ColorSetting("Power Color", Colors.MINECRAFT_DARK_RED, true, description = "The color of the power blessing.").withDependency { power } - private val timeColor by ColorSetting("Time Color", Colors.MINECRAFT_DARK_PURPLE, true, description = "The color of the time blessing.").withDependency { time } - private val stoneColor by ColorSetting("Stone Color", Colors.MINECRAFT_GRAY, true, description = "The color of the stone blessing.").withDependency { stone } - private val lifeColor by ColorSetting("Life Color", Color.RED, true, description = "The color of the life blessing.").withDependency { life } - - private data class BlessingData(val type: Blessing, val enabled: () -> Boolean, val color: () -> Color) - private val blessings = listOf( + private val blessings = arrayListOf( BlessingData(Blessing.POWER, { power }, { powerColor }), BlessingData(Blessing.TIME, { time }, { timeColor }), BlessingData(Blessing.STONE, { stone }, { stoneColor }), @@ -39,19 +41,24 @@ object BlessingDisplay : Module( BlessingData(Blessing.WISDOM, { wisdom }, { wisdomColor }) ) - private val HUD by TextHUD("Blessings HUD") { color, font, shadow -> - needs { DungeonUtils.inDungeons && blessings.none { it.enabled.invoke()} } - column(at()) { - (0..5).reduce { acc, index -> - val blessing = blessings[index - 1].takeIf { it.enabled.invoke() } ?: return@reduce acc - val level = if (preview) 19 else if (blessing.type.current > 0) blessing.type.current else return@reduce acc + private val HUD by HUD("Blessings HUD") { + needs { DungeonUtils.inDungeons } + column { + blessings.loop { (blessing, enabled, color) -> + if (!enabled()) return@loop buildText( - string = blessing.type.displayString, - supplier = { level }, - font, blessing.color.invoke(), color, shadow - ) - acc + 1 + string = blessing.displayString, + supplier = { if (preview) 19 else blessing.current }, + font = getFont(font), + color1 = color(), color2 = textColor, + shadow + ).needs { blessing.current != 0 } } } - }.setting(description = "Displays the current active blessings in the dungeon.") + }.registerSettings( + ::textColor, ::font, ::shadow, + ::power, ::powerColor, ::time, ::timeColor, ::stone, ::stoneColor, ::life, ::lifeColor, ::wisdom, ::wisdomColor + ).setting(description = "Displays the current active blessings in the dungeon.") + + private data class BlessingData(val type: Blessing, val enabled: () -> Boolean, val color: () -> Color) } \ No newline at end of file diff --git a/src/main/kotlin/me/odinmain/features/impl/dungeon/WarpCooldown.kt b/src/main/kotlin/me/odinmain/features/impl/dungeon/WarpCooldown.kt index a1dc33755..13478e63b 100644 --- a/src/main/kotlin/me/odinmain/features/impl/dungeon/WarpCooldown.kt +++ b/src/main/kotlin/me/odinmain/features/impl/dungeon/WarpCooldown.kt @@ -2,8 +2,6 @@ package me.odinmain.features.impl.dungeon import com.github.stivais.aurora.color.Color import me.odinmain.features.Module -import me.odinmain.features.huds.HUD.Companion.needs -import me.odinmain.features.huds.HUD.Companion.preview import me.odinmain.features.settings.Setting.Companion.withDependency import me.odinmain.features.settings.impl.BooleanSetting import me.odinmain.features.settings.impl.StringSetting diff --git a/src/main/kotlin/me/odinmain/features/impl/render/ClickGUI.kt b/src/main/kotlin/me/odinmain/features/impl/render/ClickGUI.kt index 80a22a43e..d876f1d4e 100644 --- a/src/main/kotlin/me/odinmain/features/impl/render/ClickGUI.kt +++ b/src/main/kotlin/me/odinmain/features/impl/render/ClickGUI.kt @@ -171,7 +171,7 @@ object ClickGUI : Module( for (panel in Category.entries) { val data = panelSettings[panel] ?: throw NullPointerException("This should never happen") - column(constrain(x = data.x.px, y = data.y.px, Bounding, Bounding)) { + column(at(x = data.x.px, y = data.y.px)) { onRemove { data.x = element.x data.y = element.y diff --git a/src/main/kotlin/me/odinmain/features/settings/impl/NumberSetting.kt b/src/main/kotlin/me/odinmain/features/settings/impl/NumberSetting.kt index 6f932057d..338c8f4cf 100644 --- a/src/main/kotlin/me/odinmain/features/settings/impl/NumberSetting.kt +++ b/src/main/kotlin/me/odinmain/features/settings/impl/NumberSetting.kt @@ -46,7 +46,7 @@ class NumberSetting( override var value: E = default /** The amount a setting should increment. */ - private val increment = increment.toDouble() + val increment = increment.toDouble() /** The minimum a setting can be */ private val min = min.toDouble() diff --git a/src/main/kotlin/me/odinmain/utils/ui/utilities.kt b/src/main/kotlin/me/odinmain/utils/ui/utilities.kt index 7902707f8..0c92369e6 100644 --- a/src/main/kotlin/me/odinmain/utils/ui/utilities.kt +++ b/src/main/kotlin/me/odinmain/utils/ui/utilities.kt @@ -22,7 +22,14 @@ import me.odinmain.features.settings.impl.ColorSetting import me.odinmain.features.settings.impl.SelectorSetting import me.odinmain.utils.ui.screens.UIHandler +/** + * Default font used in Odin. + */ val regularFont = Font("Regular", "/assets/odinmain/fonts/Regular.otf") + +/** + * Minecraft's font. + */ val mcFont = Font("Minecraft", "/assets/odinmain/fonts/Minecraft-Regular.otf") /** @@ -30,12 +37,14 @@ val mcFont = Font("Minecraft", "/assets/odinmain/fonts/Minecraft-Regular.otf") */ fun String.image() = Image("/assets/odinmain/$this") -//// todo: better solution -//infix fun TextScope.and(other: TextScope) { -// other.element.constraints.x = Linked(element) -// other.size = size -//} +/** + * Creates a row of texts (intended for HUDs), + * where the first text is a static string, and second is supplied from a function. + * + * @param color1 Color for the static string. + * @param color2 Color for the supplied string. + */ inline fun ElementScope<*>.buildText( string: String, crossinline supplier: () -> Any?, @@ -45,21 +54,19 @@ inline fun ElementScope<*>.buildText( shadow: Boolean, pos: Positions = at(), size: Constraint.Size = 30.px -) { - row(pos) { - text( - string = "$string ", - font, - color1, - size = size - ).shadow = shadow - textSupplied( - supplier, - font, - color2, - size = size - ).shadow = shadow - } +) = row(pos) { + text( + string = "$string ", + font, + color1, + size = size + ).shadow = shadow + textSupplied( + supplier, + font, + color2, + size = size + ).shadow = shadow } /** @@ -71,7 +78,7 @@ inline fun ElementScope<*>.buildText( inline fun Module.TextHUD( name: String, color: Color = Color.RGB(50, 150, 220), - crossinline block: ElementScope.(Color, Font, shadow: Boolean) -> Unit + crossinline block: HUD.Scope.(Color, Font, shadow: Boolean) -> Unit ): HUD { val colorSetting = ColorSetting("Color", color, allowAlpha = false, description = "The color of the text.") val fontSetting = SelectorSetting("Font", arrayListOf("Regular", "Minecraft"), description = "The font of the text.") @@ -137,4 +144,22 @@ fun ElementScope<*>.lifetimeAnimations( handler.close() } } -} \ No newline at end of file +} + +/** + * Creates a commonly used selector setting, which represents fonts used in Odin. + * + * It is intended to be used with [getFont]. + * + * When this setting's value is 0, the font is [regularFont], otherwise it is [mcFont] + */ +fun makeFontSetting(name: String = "Font", description: String = "The font of the text.") = SelectorSetting( + name, + options = arrayListOf("Regular", "Minecraft"), + description = description, +) + +/** + * Gets font based on [makeFontSetting]. + */ +fun getFont(fromIndex: Int) = if (fromIndex == 0) regularFont else mcFont