From dd2234be71530cf136d64301229a1ab00811cd0e Mon Sep 17 00:00:00 2001 From: Username404 Date: Sat, 17 Jul 2021 23:37:10 +0200 Subject: [PATCH] Replace duplicated code using the RenderingUtil.kt methods --- .../snowygui/gui/elements/ClickBox.kt | 17 ++++++----------- .../snowygui/gui/feature/ButtonImpl.kt | 9 ++++----- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt index 6f24fa1..9569d6c 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt @@ -1,6 +1,5 @@ package fr.username404.snowygui.gui.elements -import com.mojang.blaze3d.systems.RenderSystem import com.mojang.blaze3d.vertex.DefaultVertexFormat import com.mojang.blaze3d.vertex.PoseStack import fr.username404.snowygui.Snowy.Companion.MissingComponent @@ -10,6 +9,8 @@ import fr.username404.snowygui.gui.feature.ButtonImpl import fr.username404.snowygui.gui.feature.Category import fr.username404.snowygui.gui.feature.Colors import fr.username404.snowygui.utils.RenderingUtil.buffer +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 @@ -46,12 +47,9 @@ class ClickBox( ) { override val color: Int get() = this@ClickBox.color override fun render(poseStack: PoseStack?) { - RenderSystem.disableTexture() - RenderSystem.enableBlend() - RenderSystem.defaultBlendFunc() + prepareDraw() defaultRectFunc() - RenderSystem.disableBlend() - RenderSystem.enableTexture() + endDraw() } init { height = 8 } } @@ -82,9 +80,7 @@ class ClickBox( } override fun render(poseStack: PoseStack?) { runBlocking { - RenderSystem.disableTexture() - RenderSystem.enableBlend() - RenderSystem.defaultBlendFunc() + prepareDraw() with(buffer) { begin(GL20.GL_POLYGON, DefaultVertexFormat.POSITION_COLOR) // Render the header: @@ -105,8 +101,7 @@ class ClickBox( vertex(x + width, y + height, 0.0).colorEnd(Colors.WHITE_LINES.hexValue) tessellator.end() } - RenderSystem.enableTexture() - RenderSystem.disableBlend() + endDraw() val renderButtons = if (buttons.isNotEmpty()) launch(start = CoroutineStart.UNDISPATCHED) { buttonsProgressBar.apply { diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt index 44a8d79..dcea4e6 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt @@ -1,6 +1,5 @@ package fr.username404.snowygui.gui.feature -import com.mojang.blaze3d.systems.RenderSystem import com.mojang.blaze3d.vertex.PoseStack import fr.username404.snowygui.ClickGui import fr.username404.snowygui.Snowy @@ -8,6 +7,8 @@ import fr.username404.snowygui.config.Configuration import fr.username404.snowygui.gui.ColoredElement import fr.username404.snowygui.utils.FontUtil import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type +import fr.username404.snowygui.utils.RenderingUtil.endDraw +import fr.username404.snowygui.utils.RenderingUtil.prepareDraw import kotlin.reflect.full.findAnnotation sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) { @@ -89,11 +90,9 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) { }; return false } override fun render(poseStack: PoseStack?) { - RenderSystem.disableTexture() - RenderSystem.enableBlend() + prepareDraw() defaultRectFunc() - RenderSystem.enableTexture() - RenderSystem.disableBlend() + endDraw() if (poseStack != null) { FontUtil.drawScaled(poseStack, title, x + 1, y + 1, 0.75F) }