Remove redundant kotlinx.coroutines usage in ClickBox.kt

Signed-off-by: Username404 <w.iron.zombie@gmail.com>
This commit is contained in:
Username404 2023-04-28 20:46:18 +02:00
parent 312b875267
commit 76b28db14b
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
1 changed files with 35 additions and 41 deletions

View File

@ -15,9 +15,6 @@ import fr.username404.snowygui.utils.RenderingUtil.endDraw
import fr.username404.snowygui.utils.RenderingUtil.prepareDraw
import fr.username404.snowygui.utils.RenderingUtil.tessellator
import io.github.config4k.extract
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import net.minecraft.client.Minecraft
import net.minecraft.network.chat.Component
import org.jetbrains.annotations.ApiStatus
@ -80,50 +77,47 @@ class ClickBox(
private const val inclination: Double = 2.5
}
override fun render(poseStack: PoseStack?) {
runBlocking {
prepareDraw()
with(buffer) {
begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR)
// Render the header:
vertex(x, y + height, 0.0).colorEnd()
vertex(x + width + inclination, y + height, 0.0).colorEnd()
vertex(x + width, y, 0.0).colorEnd()
vertex(x + inclination, y, 0.0).colorEnd()
val currentHeight = y + (height + clickboxHeightOffset)
prepareDraw()
with(buffer) {
begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR)
// Render the header:
vertex(x, y + height, 0.0).colorEnd()
vertex(x + width + inclination, y + height, 0.0).colorEnd()
vertex(x + width, y, 0.0).colorEnd()
vertex(x + inclination, y, 0.0).colorEnd()
// Render the box:
val currentHeight = y + (height + clickboxHeightOffset)
vertex(x, currentHeight, 0.0).colorEnd()
vertex(x + width + inclination, currentHeight, 0.0).colorEnd()
vertex(x + width + inclination, y + height, 0.0).colorEnd()
tessellator.end()
// Render the box:
vertex(x, currentHeight, 0.0).colorEnd()
vertex(x + width + inclination, currentHeight, 0.0).colorEnd()
vertex(x + width + inclination, y + height, 0.0).colorEnd()
tessellator.end()
colorShader()
begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR)
vertex(x + inclination, y + height, 0.0).colorEnd(Colors.WHITE_LINES.hexValue)
vertex(x + width, y + height, 0.0).colorEnd(Colors.WHITE_LINES.hexValue)
tessellator.end()
}
endDraw()
colorShader()
begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR)
vertex(x + inclination, y + height, 0.0).colorEnd(Colors.WHITE_LINES.hexValue)
vertex(x + width, y + height, 0.0).colorEnd(Colors.WHITE_LINES.hexValue)
tessellator.end()
}
endDraw()
val renderButtons = if (buttons.isNotEmpty()) launch(start = CoroutineStart.UNDISPATCHED) {
buttonsProgressBar.apply {
x = this@ClickBox.x + this@ClickBox.width - 3
y = this@ClickBox.y + this@ClickBox.height + 3
if (buttons.isNotEmpty()) {
buttonsProgressBar.apply {
x = this@ClickBox.x + this@ClickBox.width - 3
y = this@ClickBox.y + this@ClickBox.height + 3
}.display(poseStack)
buttons.forEachIndexed { num, button ->
val fullHeight = (y + height.toDouble())..(y + height + clickboxHeightOffset)
button.also {
it.x = x + 3
it.y = y + 3 + height + (((num + 1) - barStage) * 9)
it.hidden = if ((num + 1) <= 8) ((it.y) !in fullHeight) else ((it.y + it.height) !in fullHeight)
}.display(poseStack)
buttons.forEachIndexed { num, button ->
val fullHeight = (y + height.toDouble())..(y + height + clickboxHeightOffset)
button.also {
it.x = x + 3
it.y = y + 3 + height + (((num + 1) - barStage) * 9)
it.hidden = if ((num + 1) <= 8) ((it.y) !in fullHeight) else ((it.y + it.height) !in fullHeight)
}.display(poseStack)
}
} else null
if (poseStack != null) {
Minecraft.getInstance().font.draw(poseStack, name.string, x.toFloat() + 5, y.toFloat() + 1.5F, Colors.TRANSPARENT.hexValue)
renderButtons?.join()
}
}
if (poseStack != null) {
Minecraft.getInstance().font.draw(poseStack, name.string, x.toFloat() + 5, y.toFloat() + 1.5F, Colors.TRANSPARENT.hexValue)
}
}
init {
savedColors?.get(name.string)?.let {