Skip to content

Commit af5498d

Browse files
committed
this was so annoying to fix
1 parent 3543cbc commit af5498d

File tree

3 files changed

+71
-63
lines changed

3 files changed

+71
-63
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name=OneConfig
33
mod_id=oneconfig
44
version_major=1
55
version_minor=0
6-
version_patch=0-alpha.36
6+
version_patch=0-alpha.37
77

88
polyfrost.defaults.loom=3
99

modules/hud/src/main/kotlin/org/polyfrost/oneconfig/api/hud/v1/Hud.kt

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

8484
abstract fun category(): Category
8585

modules/hud/src/main/kotlin/org/polyfrost/oneconfig/api/hud/v1/HudManager.kt

Lines changed: 69 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import org.polyfrost.polyui.color.Colors
4141
import org.polyfrost.polyui.color.PolyColor
4242
import org.polyfrost.polyui.color.PolyColor.Constants.TRANSPARENT
4343
import org.polyfrost.polyui.color.rgba
44+
import org.polyfrost.polyui.component.Component
4445
import org.polyfrost.polyui.component.Drawable
4546
import org.polyfrost.polyui.component.extensions.*
4647
import org.polyfrost.polyui.component.impl.*
@@ -86,65 +87,8 @@ object HudManager {
8687
register(TextHud.Simple("", "Text Hud", ""))
8788
}
8889

89-
private val hudsPage = HudsPage(hudProviders.values)
90-
91-
val panel = Block(
92-
Block(
93-
Image("assets/oneconfig/ico/right-arrow.svg").setAlpha(0.1f),
94-
size = Vec2(32f, 1048f),
95-
alignment = alignC,
96-
).named("CloseArea").withStates().ignoreLayout().setPalette(
97-
Colors.Palette(
98-
TRANSPARENT,
99-
PolyColor.Gradient(rgba(100, 100, 100, 0.4f), TRANSPARENT),
100-
PolyColor.Gradient(rgba(100, 100, 100, 0.3f), TRANSPARENT),
101-
TRANSPARENT,
102-
)
103-
).events {
104-
Event.Mouse.Entered then {
105-
Fade(this[0], 1f, false, Animations.Default.create(0.08.seconds)).add()
106-
}
107-
Event.Mouse.Exited then {
108-
Fade(this[0], 0.1f, false, Animations.Default.create(0.08.seconds)).add()
109-
}
110-
Event.Mouse.Companion.Clicked then {
111-
toggle()
112-
}
113-
},
114-
Group(
115-
Image("assets/oneconfig/ico/left-arrow.svg").setDestructivePalette().withStates().onClick {
116-
if (parent.parent[3] !== hudsPage) {
117-
parent.parent[3] = hudsPage
118-
} else {
119-
Platform.screen().close()
120-
}
121-
},
122-
Block(
123-
Image("assets/oneconfig/ico/search.svg"),
124-
TextInput(placeholder = "oneconfig.search.placeholder", visibleSize = Vec2(220f, 12f)),
125-
size = Vec2(256f, 32f),
126-
).withBoarder().withCursor(Cursor.Text).onClick {
127-
polyUI.focus(this[1])
128-
},
129-
alignment = Align(main = Align.Main.SpaceBetween, pad = Vec2(12f, 6f)),
130-
size = Vec2(500f, 32f),
131-
),
132-
Text("oneconfig.hudeditor.title", fontSize = 24f).padded(16f, 0f).setFont { semiBold },
133-
hudsPage,
134-
size = Vec2(500f, 1048f),
135-
alignment = Align(cross = Align.Cross.Start, pad = Vec2(0f, 18f)),
136-
).apply {
137-
rawResize = true
138-
addOperation {
139-
if (polyUI.mouseDown) {
140-
if (slinex != -1f) polyUI.renderer.line(slinex, 0f, slinex, polyUI.size.y, snapLineColor, 1f)
141-
if (sliney != -1f) polyUI.renderer.line(0f, sliney, polyUI.size.x, sliney, snapLineColor, 1f)
142-
} else {
143-
slinex = -1f
144-
sliney = -1f
145-
}
146-
}
147-
}
90+
private lateinit var hudsPage: Component
91+
lateinit var panel: Drawable
14892

14993
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
15094
@kotlin.internal.InlineOnly
@@ -167,8 +111,6 @@ object HudManager {
167111
@ApiStatus.Internal
168112
fun initialize() {
169113
polyUI.translator.addDelegate("assets/oneconfig/hud")
170-
polyUI.master.addChild(panel, recalculate = false)
171-
panel.renders = false
172114
// todo use for inspections
173115
// it.master.onClick { (x, y) ->
174116
// val obj = polyUI.inputManager.rayCheckUnsafe(this, x, y) ?: return@onClick false
@@ -212,6 +154,11 @@ object HudManager {
212154

213155
@ApiStatus.Internal
214156
fun getWithEditor(): Any {
157+
if (!::panel.isInitialized) {
158+
panel = makePanel()
159+
polyUI.master.addChild(panel, recalculate = false)
160+
panel.renders = false
161+
}
215162
toggleHudPicker()
216163
return UIManager.INSTANCE.createPolyUIScreen(polyUI, 0f, 0f, false, true) { editorClose() }
217164
}
@@ -268,4 +215,65 @@ object HudManager {
268215
}
269216

270217
internal fun canAutoOpen(): Boolean = !polyUI.master.hasChildIn(polyUI.size.x - panel.width - 34f, 0f, panel.width, polyUI.size.y)
218+
219+
fun makePanel(): Drawable {
220+
hudsPage = HudsPage(hudProviders.values)
221+
return Block(
222+
Block(
223+
Image("assets/oneconfig/ico/right-arrow.svg").setAlpha(0.1f),
224+
size = Vec2(32f, 1048f),
225+
alignment = alignC,
226+
).named("CloseArea").withStates().ignoreLayout().setPalette(
227+
Colors.Palette(
228+
TRANSPARENT,
229+
PolyColor.Gradient(rgba(100, 100, 100, 0.4f), TRANSPARENT),
230+
PolyColor.Gradient(rgba(100, 100, 100, 0.3f), TRANSPARENT),
231+
TRANSPARENT,
232+
)
233+
).events {
234+
Event.Mouse.Entered then {
235+
Fade(this[0], 1f, false, Animations.Default.create(0.08.seconds)).add()
236+
}
237+
Event.Mouse.Exited then {
238+
Fade(this[0], 0.1f, false, Animations.Default.create(0.08.seconds)).add()
239+
}
240+
Event.Mouse.Companion.Clicked then {
241+
toggle()
242+
}
243+
},
244+
Group(
245+
Image("assets/oneconfig/ico/left-arrow.svg").setDestructivePalette().withStates().onClick {
246+
if (parent.parent[3] !== hudsPage) {
247+
parent.parent[3] = hudsPage
248+
} else {
249+
Platform.screen().close()
250+
}
251+
},
252+
Block(
253+
Image("assets/oneconfig/ico/search.svg"),
254+
TextInput(placeholder = "oneconfig.search.placeholder", visibleSize = Vec2(220f, 12f)),
255+
size = Vec2(256f, 32f),
256+
).withBoarder().withCursor(Cursor.Text).onClick {
257+
polyUI.focus(this[1])
258+
},
259+
alignment = Align(main = Align.Main.SpaceBetween, pad = Vec2(12f, 6f)),
260+
size = Vec2(500f, 32f),
261+
),
262+
Text("oneconfig.hudeditor.title", fontSize = 24f).padded(16f, 0f).setFont { semiBold },
263+
hudsPage,
264+
size = Vec2(500f, 1048f),
265+
alignment = Align(cross = Align.Cross.Start, pad = Vec2(0f, 18f)),
266+
).apply {
267+
rawResize = true
268+
addOperation {
269+
if (polyUI.mouseDown) {
270+
if (slinex != -1f) polyUI.renderer.line(slinex, 0f, slinex, polyUI.size.y, snapLineColor, 1f)
271+
if (sliney != -1f) polyUI.renderer.line(0f, sliney, polyUI.size.x, sliney, snapLineColor, 1f)
272+
} else {
273+
slinex = -1f
274+
sliney = -1f
275+
}
276+
}
277+
}
278+
}
271279
}

0 commit comments

Comments
 (0)