@@ -41,6 +41,7 @@ import org.polyfrost.polyui.color.Colors
4141import org.polyfrost.polyui.color.PolyColor
4242import org.polyfrost.polyui.color.PolyColor.Constants.TRANSPARENT
4343import org.polyfrost.polyui.color.rgba
44+ import org.polyfrost.polyui.component.Component
4445import org.polyfrost.polyui.component.Drawable
4546import org.polyfrost.polyui.component.extensions.*
4647import 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