Skip to content

Commit

Permalink
fixed blessing display, fixed hud editor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Stivais committed Dec 3, 2024
1 parent ff2a4f1 commit 4a3b25a
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 70 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/me/odinmain/features/Module.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -166,7 +165,7 @@ abstract class Module(

fun HUD(
name: String,
block: ElementScope<HUD.Representation>.() -> Unit
block: HUD.Scope.() -> Unit
): HUD {
return HUD(
name,
Expand Down
18 changes: 7 additions & 11 deletions src/main/kotlin/me/odinmain/features/huds/HUD.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import kotlin.reflect.jvm.isAccessible
class HUD(
val name: String,
val module: Module,
val builder: ElementScope<HUD.Representation>.() -> 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]
Expand Down Expand Up @@ -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
Expand All @@ -68,7 +65,7 @@ class HUD(

override fun getDefaultPositions() = Pair(Undefined, Undefined)

fun refresh(scope: ElementScope<Representation>) {
fun refresh(scope: Scope) {
removeAll()
builder.invoke(scope)
scaleTransformation = this@HUD.scale.value
Expand All @@ -86,10 +83,9 @@ class HUD(
return null
}

companion object {
inline val ElementScope<HUD.Representation>.preview get() = element.preview
class Scope(element: HUD.Representation,val preview: Boolean) : ElementScope<HUD.Representation>(element) {

inline fun ElementScope<HUD.Representation>.needs(crossinline block: () -> Boolean) {
inline fun ElementScope<*>.needs(crossinline block: () -> Boolean) {
if (!preview) {
operation {
element.enabled = block()
Expand All @@ -98,7 +94,7 @@ class HUD(
}
}

fun ElementScope<HUD.Representation>.refreshHUDs() {
fun refreshHUDs() {
element.refresh(this)
}
}
Expand Down
20 changes: 15 additions & 5 deletions src/main/kotlin/me/odinmain/features/huds/HUDManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`
Expand All @@ -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()
Expand All @@ -46,17 +48,25 @@ 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 {
hud.x.value = (element.x / ui.main.width) * 100f
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
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,64 @@
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 }),
BlessingData(Blessing.LIFE, { life }, { lifeColor }),
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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class NumberSetting<E>(
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()
Expand Down
69 changes: 47 additions & 22 deletions src/main/kotlin/me/odinmain/utils/ui/utilities.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,29 @@ 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")

/**
* Utility function to get an image from a string representing a path inside /assets/odinmain/
*/
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?,
Expand All @@ -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
}

/**
Expand All @@ -71,7 +78,7 @@ inline fun ElementScope<*>.buildText(
inline fun Module.TextHUD(
name: String,
color: Color = Color.RGB(50, 150, 220),
crossinline block: ElementScope<HUD.Representation>.(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.")
Expand Down Expand Up @@ -137,4 +144,22 @@ fun ElementScope<*>.lifetimeAnimations(
handler.close()
}
}
}
}

/**
* 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

0 comments on commit 4a3b25a

Please sign in to comment.