Skip to content

Commit

Permalink
hud fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Stivais committed Dec 2, 2024
1 parent 35676b6 commit 775b0d1
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 36 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ blossom {

allprojects {
repositories {
// mavenLocal()
mavenLocal()
mavenCentral()
maven("https://jitpack.io")
maven("https://repo.spongepowered.org/maven/")
Expand Down Expand Up @@ -46,9 +46,9 @@ allprojects {
annotationProcessor("org.spongepowered:mixin:0.8.5-SNAPSHOT")
implementation("org.spongepowered:mixin:0.7.11-SNAPSHOT") { isTransitive = false }

//implementation("com.github.stivais:AuroraUI:0.9.1-beta")
// implementation("com.github.stivais:AuroraUI:0.9.1-beta")
// todo: create releases for aurora
implementation("com.github.stivais:AuroraUI:90cb4e84e8")
implementation("com.github.stivais:AuroraUI:e8cff5402b")

implementation("com.github.odtheking:odin-lwjgl:faeaa48b39")

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/me/odinmain/features/Module.kt
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ abstract class Module(

fun HUD(
name: String,
block: ElementScope<*>.() -> Unit
block: ElementScope<HUD.Representation>.() -> Unit
): HUD {
return HUD(
name,
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/me/odinmain/features/huds/HUD.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class HUD(
override fun getDefaultPositions() = Pair(Undefined, Undefined)

fun refresh(scope: ElementScope<Representation>) {
// removeAll()
removeAll()
builder.invoke(scope)
scaleTransformation = this@HUD.scale.value
redraw = true
Expand Down
17 changes: 9 additions & 8 deletions src/main/kotlin/me/odinmain/features/huds/HUDManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ object HUDManager {
representation.scope {
hud.builder(this)

onAdd {
element.constraints.x = element.x.px
element.constraints.y = element.y.px
}
onRemove {
hud.x.value = (element.x / ui.main.width) * 100f
hud.y.value = (element.y / ui.main.height) * 100f
Expand Down Expand Up @@ -173,10 +169,16 @@ object HUDManager {
pressed: Boolean,
selectedHUDs: ArrayList<HUD.Representation>
): Popup {
redraw()
// get bounding box of selectedHUDs
var minX = 9999f; var minY = 9999f // I wish I could rust :(
var maxX = 0f; var maxY = 0f
selectedHUDs.loop {
// check if it has converted to pixel for mutability, if not convert it
if (it.constraints.x !is Pixel) {
it.constraints.x = it.x.px
it.constraints.y = it.y.px
}
minX = minOf(minX, it.x)
maxX = maxOf(maxX, it.x + it.screenWidth())
minY = minOf(minY, it.y)
Expand Down Expand Up @@ -220,7 +222,7 @@ object HUDManager {
val centerX = parent.width / 2
val centerY = parent.height / 2

// Check for center snapLineping
// Check for center snapLine
if (abs(newX + element.screenWidth() / 2 - centerX) <= SNAP_THRESHOLD) {
newX = centerX - element.screenWidth() / 2
snapLineX = centerX
Expand Down Expand Up @@ -269,10 +271,9 @@ object HUDManager {
if (lastX != px.pixels) (it.constraints.x as Pixel).pixels += px.pixels - lastX
if (lastY != py.pixels) (it.constraints.y as Pixel).pixels += py.pixels - lastY
}
redraw()
true
} else {
false
}
} else false
}
}
}
Expand Down
37 changes: 17 additions & 20 deletions src/main/kotlin/me/odinmain/features/impl/dungeon/WarpCooldown.kt
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
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.impl.BooleanSetting
import me.odinmain.utils.ui.TextHUD
import me.odinmain.utils.ui.buildText

object WarpCooldown : Module (
name = "Warp Cooldown",
description = "Displays the time until you can warp into a dungeon again."
) {
private val showUnit by BooleanSetting("Show unit", default = false, description = "Displays unit of time for the cooldown.").hide()

// private val HUD by TextHUD("Warp HUD") { color, font ->
// if (preview) {
// text(
// "Warp ",
// color = color,
// font = font,
// size = 30.px
// ) and text("30${if (showUnit) "s" else ""}", font = font)
// } else {
// needs { lastUpdate - System.currentTimeMillis() >= 0 }
// text(
// "Warp ",
// color = color,
// font = font,
// size = 30.px
// ) and text({ "${(lastUpdate - System.currentTimeMillis()) / 1000}${if (showUnit) "s" else ""}" }, font = font)
// }
// }.registerSettings(
// ::showUnit
// ).setting("Displays the cooldown.")
private val HUD by TextHUD("Warp HUD") { color, font, shadow ->
needs { lastUpdate - System.currentTimeMillis() >= 0 }
buildText(
string = "Warp",
supplier = { getString(preview) },
font, color, Color.WHITE, shadow
)
}.registerSettings(::showUnit).setting(description = "Displays the cooldown.")

private var lastUpdate: Long = System.currentTimeMillis()

Expand All @@ -37,4 +30,8 @@ object WarpCooldown : Module (
lastUpdate = System.currentTimeMillis() + 30_000
}
}

private fun getString(isPreview: Boolean): String {
return "${if (isPreview) "30" else (lastUpdate - System.currentTimeMillis()) / 1000}${if (showUnit) "s" else ""}"
}
}
41 changes: 38 additions & 3 deletions src/main/kotlin/me/odinmain/utils/ui/utilities.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@ package me.odinmain.utils.ui

import com.github.stivais.aurora.animations.Animation
import com.github.stivais.aurora.color.Color
import com.github.stivais.aurora.constraints.Constraint
import com.github.stivais.aurora.constraints.Positions
import com.github.stivais.aurora.dsl.at
import com.github.stivais.aurora.dsl.onMouseEnter
import com.github.stivais.aurora.dsl.onRemove
import com.github.stivais.aurora.dsl.px
import com.github.stivais.aurora.elements.ElementScope
import com.github.stivais.aurora.elements.impl.Text.Companion.shadow
import com.github.stivais.aurora.elements.impl.Text.Companion.textSupplied
import com.github.stivais.aurora.renderer.data.Font
import com.github.stivais.aurora.renderer.data.Image
import com.github.stivais.aurora.transforms.impl.Alpha
import com.github.stivais.aurora.transforms.impl.Scale
import me.odinmain.features.Module
import me.odinmain.features.huds.HUD
import me.odinmain.features.settings.impl.BooleanSetting
import me.odinmain.features.settings.impl.ColorSetting
import me.odinmain.features.settings.impl.SelectorSetting
import me.odinmain.utils.ui.screens.UIHandler
Expand All @@ -29,6 +36,32 @@ fun String.image() = Image("/assets/odinmain/$this")
// other.size = size
//}

inline fun ElementScope<*>.buildText(
string: String,
crossinline supplier: () -> Any?,
font: Font,
color1: Color,
color2: Color,
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
}
}

/**
* Makes a HUD, that uses common settings found in text-based HUDs.
*
Expand All @@ -38,21 +71,23 @@ fun String.image() = Image("/assets/odinmain/$this")
inline fun Module.TextHUD(
name: String,
color: Color = Color.RGB(50, 150, 220),
crossinline block: ElementScope<*>.(Color, Font) -> Unit
crossinline block: ElementScope<HUD.Representation>.(Color, Font, shadow: Boolean) -> Unit
): HUD {
val colorSetting = ColorSetting("Color", color, allowAlpha = false)
val fontSetting = SelectorSetting("Font", arrayListOf("Regular", "Minecraft"))
// copy of selector setting, where each entry is a different font representing it
val shadowSetting = BooleanSetting("Shadow", true)

val hud = HUD(name) {
val font = when (fontSetting.value) {
1 -> mcFont
else -> regularFont
}
block(colorSetting.value, font)
block(colorSetting.value, font, shadowSetting.value)
}
hud.registerSettings(
colorSetting,
fontSetting,
shadowSetting
)
return hud
}
Expand Down

0 comments on commit 775b0d1

Please sign in to comment.