Skip to content

Commit

Permalink
this was so annoying to fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nextdayy committed Nov 18, 2024
1 parent 3543cbc commit af5498d
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 63 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name=OneConfig
mod_id=oneconfig
version_major=1
version_minor=0
version_patch=0-alpha.36
version_patch=0-alpha.37

polyfrost.defaults.loom=3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ abstract class Hud<T : Drawable> : Cloneable, Config("null", null, "null", null)
* HUD config files are stored in `{profile}/huds/{rnd}-`[id], e.g. `huds/42-my_hud.toml`.
* the random number is omitted for the first instance.
*/
abstract fun id(): String
open fun id(): String = title().replace(' ', '_').lowercase()

abstract fun category(): Category

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import org.polyfrost.polyui.color.Colors
import org.polyfrost.polyui.color.PolyColor
import org.polyfrost.polyui.color.PolyColor.Constants.TRANSPARENT
import org.polyfrost.polyui.color.rgba
import org.polyfrost.polyui.component.Component
import org.polyfrost.polyui.component.Drawable
import org.polyfrost.polyui.component.extensions.*
import org.polyfrost.polyui.component.impl.*
Expand Down Expand Up @@ -86,65 +87,8 @@ object HudManager {
register(TextHud.Simple("", "Text Hud", ""))
}

private val hudsPage = HudsPage(hudProviders.values)

val panel = Block(
Block(
Image("assets/oneconfig/ico/right-arrow.svg").setAlpha(0.1f),
size = Vec2(32f, 1048f),
alignment = alignC,
).named("CloseArea").withStates().ignoreLayout().setPalette(
Colors.Palette(
TRANSPARENT,
PolyColor.Gradient(rgba(100, 100, 100, 0.4f), TRANSPARENT),
PolyColor.Gradient(rgba(100, 100, 100, 0.3f), TRANSPARENT),
TRANSPARENT,
)
).events {
Event.Mouse.Entered then {
Fade(this[0], 1f, false, Animations.Default.create(0.08.seconds)).add()
}
Event.Mouse.Exited then {
Fade(this[0], 0.1f, false, Animations.Default.create(0.08.seconds)).add()
}
Event.Mouse.Companion.Clicked then {
toggle()
}
},
Group(
Image("assets/oneconfig/ico/left-arrow.svg").setDestructivePalette().withStates().onClick {
if (parent.parent[3] !== hudsPage) {
parent.parent[3] = hudsPage
} else {
Platform.screen().close()
}
},
Block(
Image("assets/oneconfig/ico/search.svg"),
TextInput(placeholder = "oneconfig.search.placeholder", visibleSize = Vec2(220f, 12f)),
size = Vec2(256f, 32f),
).withBoarder().withCursor(Cursor.Text).onClick {
polyUI.focus(this[1])
},
alignment = Align(main = Align.Main.SpaceBetween, pad = Vec2(12f, 6f)),
size = Vec2(500f, 32f),
),
Text("oneconfig.hudeditor.title", fontSize = 24f).padded(16f, 0f).setFont { semiBold },
hudsPage,
size = Vec2(500f, 1048f),
alignment = Align(cross = Align.Cross.Start, pad = Vec2(0f, 18f)),
).apply {
rawResize = true
addOperation {
if (polyUI.mouseDown) {
if (slinex != -1f) polyUI.renderer.line(slinex, 0f, slinex, polyUI.size.y, snapLineColor, 1f)
if (sliney != -1f) polyUI.renderer.line(0f, sliney, polyUI.size.x, sliney, snapLineColor, 1f)
} else {
slinex = -1f
sliney = -1f
}
}
}
private lateinit var hudsPage: Component
lateinit var panel: Drawable

@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.InlineOnly
Expand All @@ -167,8 +111,6 @@ object HudManager {
@ApiStatus.Internal
fun initialize() {
polyUI.translator.addDelegate("assets/oneconfig/hud")
polyUI.master.addChild(panel, recalculate = false)
panel.renders = false
// todo use for inspections
// it.master.onClick { (x, y) ->
// val obj = polyUI.inputManager.rayCheckUnsafe(this, x, y) ?: return@onClick false
Expand Down Expand Up @@ -212,6 +154,11 @@ object HudManager {

@ApiStatus.Internal
fun getWithEditor(): Any {
if (!::panel.isInitialized) {
panel = makePanel()
polyUI.master.addChild(panel, recalculate = false)
panel.renders = false
}
toggleHudPicker()
return UIManager.INSTANCE.createPolyUIScreen(polyUI, 0f, 0f, false, true) { editorClose() }
}
Expand Down Expand Up @@ -268,4 +215,65 @@ object HudManager {
}

internal fun canAutoOpen(): Boolean = !polyUI.master.hasChildIn(polyUI.size.x - panel.width - 34f, 0f, panel.width, polyUI.size.y)

fun makePanel(): Drawable {
hudsPage = HudsPage(hudProviders.values)
return Block(
Block(
Image("assets/oneconfig/ico/right-arrow.svg").setAlpha(0.1f),
size = Vec2(32f, 1048f),
alignment = alignC,
).named("CloseArea").withStates().ignoreLayout().setPalette(
Colors.Palette(
TRANSPARENT,
PolyColor.Gradient(rgba(100, 100, 100, 0.4f), TRANSPARENT),
PolyColor.Gradient(rgba(100, 100, 100, 0.3f), TRANSPARENT),
TRANSPARENT,
)
).events {
Event.Mouse.Entered then {
Fade(this[0], 1f, false, Animations.Default.create(0.08.seconds)).add()
}
Event.Mouse.Exited then {
Fade(this[0], 0.1f, false, Animations.Default.create(0.08.seconds)).add()
}
Event.Mouse.Companion.Clicked then {
toggle()
}
},
Group(
Image("assets/oneconfig/ico/left-arrow.svg").setDestructivePalette().withStates().onClick {
if (parent.parent[3] !== hudsPage) {
parent.parent[3] = hudsPage
} else {
Platform.screen().close()
}
},
Block(
Image("assets/oneconfig/ico/search.svg"),
TextInput(placeholder = "oneconfig.search.placeholder", visibleSize = Vec2(220f, 12f)),
size = Vec2(256f, 32f),
).withBoarder().withCursor(Cursor.Text).onClick {
polyUI.focus(this[1])
},
alignment = Align(main = Align.Main.SpaceBetween, pad = Vec2(12f, 6f)),
size = Vec2(500f, 32f),
),
Text("oneconfig.hudeditor.title", fontSize = 24f).padded(16f, 0f).setFont { semiBold },
hudsPage,
size = Vec2(500f, 1048f),
alignment = Align(cross = Align.Cross.Start, pad = Vec2(0f, 18f)),
).apply {
rawResize = true
addOperation {
if (polyUI.mouseDown) {
if (slinex != -1f) polyUI.renderer.line(slinex, 0f, slinex, polyUI.size.y, snapLineColor, 1f)
if (sliney != -1f) polyUI.renderer.line(0f, sliney, polyUI.size.x, sliney, snapLineColor, 1f)
} else {
slinex = -1f
sliney = -1f
}
}
}
}
}

0 comments on commit af5498d

Please sign in to comment.