Skip to content

Commit

Permalink
implement HUD buttons and fix some other small bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
nextdayy committed Nov 7, 2024
1 parent 676d93a commit 95a0bcc
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 34 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ kotlin = "2.0.20"
kotlinx-coroutines = "1.8.1"
kotlinx-atomicfu = "0.24.0"
fabric-language-kotlin = "1.12.2+kotlin.2.0.20"
polyui = "1.7.11"
polyui = "1.7.24"
annotations = "24.1.0"
hypixel-modapi = "1.0"
hypixel-data = "0.1.2" # Dep of hypixel-modapi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import kotlin.math.atan2
import kotlin.math.min

val alignC = Align(main = Align.Main.Center, cross = Align.Cross.Center)
val alignNoPad = Align(pad = Vec2.ZERO)
private val mcFont = FontFamily("Minecraft", "assets/oneconfig/fonts/minecraft")
const val angleSnapMargin = PI / 12.0
const val minMargin = 4f
Expand Down Expand Up @@ -129,6 +130,7 @@ private fun createSettings(hud: Hud<*>): Drawable {

private fun createDesigner(hud: Hud<*>): Drawable {
val isLegacy = hud is LegacyHud
val parent = hud.get().parent
return Group(
Text("oneconfig.hudeditor.general.title", fontSize = 16f).setFont { medium },
subheading("oneconfig.hudeditor.padding.title", "oneconfig.hudeditor.padding.info"),
Expand All @@ -141,12 +143,32 @@ private fun createDesigner(hud: Hud<*>): Drawable {
"oneconfig.align.end",
"oneconfig.align.spacebetween",
"oneconfig.align.spaceevenly",
).minimumSize(70f by 32f).titled("oneconfig.hudeditor.padding.mode.main"),
).minimumSize(70f by 32f).titled("oneconfig.hudeditor.padding.mode.main").onChange { index: Int ->
val a = parent.alignment
parent.alignment = Align(Align.Main.entries[index], a.cross, a.mode, a.pad, a.maxRowSize)
false
},
Dropdown(
"oneconfig.align.start", "oneconfig.align.center", "oneconfig.align.end",
).minimumSize(70f by 32f).titled("oneconfig.hudeditor.padding.mode.cross"),
BoxedTextInput("assets/oneconfig/ico/info.svg".image(), placeholder = "8", size = Vec2(72f, 0f), post = "px").titled("oneconfig.hudeditor.padding.main"),
BoxedTextInput("assets/oneconfig/ico/info.svg".image(), placeholder = "6", size = Vec2(72f, 0f), post = "px").titled("oneconfig.hudeditor.padding.cross"),
).minimumSize(70f by 32f).titled("oneconfig.hudeditor.padding.mode.cross").onChange { index: Int ->
val a = parent.alignment
parent.alignment = Align(a.main, Align.Cross.entries[index], a.mode, a.pad, a.maxRowSize)
false
},
BoxedNumericInput("assets/oneconfig/ico/info.svg".image(), initialValue = parent.alignment.pad.x, size = Vec2(72f, 0f), post = "px").also {
it[0].onChange { value: Float ->
val a = parent.alignment
parent.alignment = Align(a.main, a.cross, a.mode, Vec2(value, a.pad.y), a.maxRowSize)
false
}
}.titled("oneconfig.hudeditor.padding.main"),
BoxedNumericInput("assets/oneconfig/ico/info.svg".image(), initialValue = parent.alignment.pad.y, size = Vec2(72f, 0f), post = "px").also {
it[0].onChange { value: Float ->
val a = parent.alignment
parent.alignment = Align(a.main, a.cross, a.mode, Vec2(a.pad.x, value), a.maxRowSize)
false
}
}.titled("oneconfig.hudeditor.padding.cross"),
size = Vec2(328f, 0f),
),
),
Expand Down Expand Up @@ -305,6 +327,7 @@ private fun interactiveAlignment(hud: Hud<*>): Drawable {
}

fun textOptions(text: Text): Drawable {
var prevWeight: Font.Weight = Font.Weight.Regular
return Group(
subheading("oneconfig.hudeditor.text.title", "oneconfig.hudeditor.text.info"),
Block(
Expand All @@ -326,17 +349,16 @@ fun textOptions(text: Text): Drawable {
ex.parent.recalculate()
false
}.titled("oneconfig.hudeditor.text.font"),
BoxedTextInput("assets/oneconfig/ico/info.svg".image(), placeholder = "1-100", initialValue = text.fontSize.toString(), size = Vec2(72f, 0f), post = "px")
.apply {
(this[1][0] as TextInput).numeric(1f, 100f).on(Event.Change.Number) { (it) ->
text.fontSize = it.toFloat()
text._parent?.recalculate()
val ex = (parent.parent.parent[1][0] as? Text) ?: return@on true
ex.fontSize = text.fontSize
ex.parent.recalculate()
true
}
}.titled("oneconfig.hudeditor.text.size"),
BoxedNumericInput("assets/oneconfig/ico/info.svg".image(), initialValue = text.fontSize, min = 1f, size = Vec2(72f, 0f), post = "px").also {
it[0].onChange { value: Float ->
text.fontSize = value
text._parent?.recalculate()
val ex = (parent.parent.parent[1][0] as? Text) ?: return@onChange false
ex.fontSize = text.fontSize
ex.parent.recalculate()
false
}
}.titled("oneconfig.hudeditor.text.size"),
Radiobutton(
"assets/oneconfig/ico/info.svg".image(),
"assets/oneconfig/ico/info.svg".image(),
Expand All @@ -352,10 +374,6 @@ fun textOptions(text: Text): Drawable {
"oneconfig.fweight.300",
"oneconfig.fweight.400",
"oneconfig.fweight.500",
"oneconfig.fweight.600",
"oneconfig.fweight.700",
"oneconfig.fweight.800",
"oneconfig.fweight.900"
).onChange { it: Int ->
text.fontWeight = Font.byWeight((it + 1) * 100)
text._parent?.recalculate()
Expand All @@ -364,15 +382,23 @@ fun textOptions(text: Text): Drawable {
ex.parent.recalculate()
false
}.titled("oneconfig.hudeditor.text.weight"),
Radiobutton(
"assets/oneconfig/ico/info.svg".image(),
"assets/oneconfig/ico/info.svg".image(),
"assets/oneconfig/ico/info.svg".image(),
optionLateralPadding = 2f,
optionVerticalPadding = 2f,
).onChange { it: Int ->
false
}.titled("oneconfig.hudeditor.text.effects"),
Group(
Block(Image("assets/oneconfig/ico/info.svg"), alignment = alignNoPad).radius(2f).toggleable(text.fontWeight.value > 500).onToggle {
if(it) {
prevWeight = text.fontWeight
text.fontWeight = when(text.fontWeight) {
Font.Weight.Thin, Font.Weight.ExtraLight, Font.Weight.Light -> Font.Weight.SemiBold
Font.Weight.Regular -> Font.Weight.Bold
Font.Weight.Medium -> Font.Weight.ExtraBold
else -> text.fontWeight
}
} else {
text.fontWeight = prevWeight
}
},
Block(Image("assets/oneconfig/ico/info.svg"), alignment = alignNoPad).radius(2f).toggleable(text.italic).onToggle { text.italic = it },
Block(Image("assets/oneconfig/ico/info.svg"), alignment = alignNoPad).radius(2f).toggleable(text.strikethrough).onToggle { text.strikethrough = it },
).titled("oneconfig.hudeditor.text.effects"),
*colorOptions(text),
size = Vec2(476f, 0f),
alignment = Align(pad = Vec2(0f, 8f))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ object OneConfigUI {
Group(
Block(
size = Vec2(225f, 32f),
).ignoreLayout().afterParentInit {
val modsBtn = parent[3]
Move(this, modsBtn.x, modsBtn.y, false).add()
).ignoreLayout().afterParentInit(Int.MAX_VALUE) {
// move to mod button
this.at = parent[3].at
},
Image("assets/oneconfig/brand/oneconfig.svg".image()).named("Logo"),
Text("oneconfig.sidebar.title.options", fontSize = 11f).setPalette { text.secondary }.padded(0f, 24f, 0f, 0f),
Expand Down Expand Up @@ -131,7 +131,7 @@ object OneConfigUI {
Image(
"assets/oneconfig/ico/bell.svg".image(),
),
Image(playerHead).radius(6f).named("ProfileImage").withBoarder(
Image(playerHead, size = Vec2(24f, 24f)).radius(6f).named("ProfileImage").withBoarder(
rgba(255, 255, 255, 0.14f),
width = 1f,
).addHoverInfo(Text(Platform.player().playerName.ifEmpty { "Steve" })),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ object Notifications {
Image("polyui/chevron-down.svg".image(), size = Vec2(32f, 32f)),
Text(title, fontSize = 14f).setFont { medium },
Text(description, fontSize = 12f),
size = Vec2(235f, 100f),
),
progressFunc = Animations.Linear.create(durationNanos)
)
Expand Down

0 comments on commit 95a0bcc

Please sign in to comment.