From 716d251ca09a4f0cd883413cd0ac524d9dd7d1ed Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Mon, 1 Jan 2024 02:51:17 +0700 Subject: [PATCH] More MGUIGraphics moves --- .../mc/otm/client/AndroidMenuKeyMapping.kt | 12 +++--- .../dbotthepony/mc/otm/client/MatteryGUI.kt | 2 +- .../mc/otm/client/render/MGUIGraphics.kt | 13 +++++++ .../mc/otm/client/render/RenderHelper.kt | 38 ------------------- .../client/screen/panels/EffectListPanel.kt | 7 ++-- 5 files changed, 22 insertions(+), 50 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/AndroidMenuKeyMapping.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/AndroidMenuKeyMapping.kt index cfbb165af..f81bd9c01 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/AndroidMenuKeyMapping.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/AndroidMenuKeyMapping.kt @@ -155,9 +155,9 @@ object AndroidMenuKeyMapping : KeyMapping("key.otm.android_menu", KeyConflictCon RenderSystem.setShaderColor(0f, 0f, 0f, 0.6f) val size = minecraft.window.guiScaledHeight.coerceAtMost(minecraft.window.guiScaledWidth).toFloat() * 0.35f + val wrap = MGUIGraphics(event.guiGraphics) - drawArc( - event.guiGraphics, + wrap.drawArc( minecraft.window.guiScaledWidth / 2f, minecraft.window.guiScaledHeight / 2f, size, @@ -226,8 +226,7 @@ object AndroidMenuKeyMapping : KeyMapping("key.otm.android_menu", KeyConflictCon if (lastSelectedDegree != null && lastSelectedFeature != null) { RenderSystem.setShaderColor(85 / 255f, 197 / 255f, 255 / 255f, 0.3f * lastSelectProgressGlobal) - drawArc( - event.guiGraphics, + wrap.drawArc( minecraft.window.guiScaledWidth / 2f, minecraft.window.guiScaledHeight / 2f, ru.dbotthepony.mc.otm.core.math.linearInterpolation(lastSelectProgressGlobal, size, size * 1.2f), @@ -245,7 +244,6 @@ object AndroidMenuKeyMapping : KeyMapping("key.otm.android_menu", KeyConflictCon val poseStack = event.guiGraphics.pose() poseStack.pushPose() poseStack.translate(minecraft.window.guiScaledWidth.toDouble() / 2f, minecraft.window.guiScaledHeight.toDouble() / 2f, 0.0) - val wrap = MGUIGraphics(event.guiGraphics) for ((index, feature) in features.withIndex()) { var sin = sin((index + 0.5) * degreePerSlice).toFloat() @@ -264,7 +262,7 @@ object AndroidMenuKeyMapping : KeyMapping("key.otm.android_menu", KeyConflictCon if (feature.isOnCooldown && feature.cooldownPercent > 0.0f) { RenderSystem.setShaderColor(1f, 1f, 1f, 0.5f) - drawArc(event.guiGraphics, shift * cos, -shift * sin, iconSize / 2f, 0f, PI / 2.0, PI / 2.0 + PI * 2.0 * feature.cooldownPercent.toDouble()) + wrap.drawArc(shift * cos, -shift * sin, iconSize / 2f, 0f, PI / 2.0, PI / 2.0 + PI * 2.0 * feature.cooldownPercent.toDouble()) RenderSystem.setShaderColor(1f, 1f, 1f, 1f) wrap.draw(formatTickDuration(feature.cooldown), shift * cos, -shift * sin + iconSize / 1.5f, color = RGBAColor.WHITE, gravity = RenderGravity.CENTER_CENTER) @@ -302,7 +300,7 @@ object AndroidMenuKeyMapping : KeyMapping("key.otm.android_menu", KeyConflictCon feature.renderIcon(wrap, x, y, COOLDOWN_ICON_SIZE, COOLDOWN_ICON_SIZE) RenderSystem.setShaderColor(1f, 1f, 1f, 0.5f) - drawArc(event.guiGraphics, x, y, COOLDOWN_ICON_SIZE / 2f, 0f, PI / 2.0, PI / 2.0 + PI * 2.0 * feature.cooldownPercent, alignAtCenter = false) + wrap.drawArc(x, y, COOLDOWN_ICON_SIZE / 2f, 0f, PI / 2.0, PI / 2.0 + PI * 2.0 * feature.cooldownPercent, alignAtCenter = false) RenderSystem.setShaderColor(1f, 1f, 1f, 1f) wrap.draw(formatTickDuration(feature.cooldown), x + COOLDOWN_ICON_SIZE / 2f, y + COOLDOWN_ICON_SIZE + 1f, color = RGBAColor.WHITE, gravity = RenderGravity.TOP_CENTER) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/MatteryGUI.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/MatteryGUI.kt index d92fe7610..4588b2b7c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/MatteryGUI.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/MatteryGUI.kt @@ -369,7 +369,7 @@ object MatteryGUI { val percent = ((stack.item.getUseDuration(stack) - ply.useItemRemainingTicks + minecraft.partialTick) / 5f).coerceIn(0f, 1f) RenderSystem.setShaderColor(1f, 1f, 1f, 0.5f) - drawArc(graphics, x + 8f, y + 8f, 8f, 0f, PI / 2.0, PI / 2.0 + PI * 2.0 * percent, alignAtCenter = true) + drawArc(graphics.pose(), x + 8f, y + 8f, 8f, 0f, PI / 2.0, PI / 2.0 + PI * 2.0 * percent, alignAtCenter = true) RenderSystem.setShaderColor(1f, 1f, 1f, 1f) return true diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/MGUIGraphics.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/MGUIGraphics.kt index 198ca4cd9..3c2dcc7a9 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/MGUIGraphics.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/MGUIGraphics.kt @@ -11,6 +11,8 @@ import net.minecraft.util.FormattedCharSequence import net.minecraft.world.item.ItemStack import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.mc.otm.core.math.RGBAColor +import kotlin.math.PI +import kotlin.math.roundToInt // polyfill class for 1.19.4 and older class MGUIGraphics(val parent: GuiGraphics) { @@ -248,6 +250,17 @@ class MGUIGraphics(val parent: GuiGraphics) { ) } + fun drawArc( + x: Float, + y: Float, + outerRadius: Float, + innerRadius: Float = 0f, + startDegree: Double = 0.0, + endDegree: Double = PI * 2.0, + steps: Int = (outerRadius * (endDegree - startDegree) * 4.0).roundToInt().coerceAtLeast(12), + alignAtCenter: Boolean = true + ) = drawArc(pose, x, y, outerRadius, innerRadius, startDegree, endDegree, steps, alignAtCenter) + companion object { private val defaultUV = UVCoords(0f, 0f, 1f, 1f) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/RenderHelper.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/RenderHelper.kt index 26738c334..84d7d1da4 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/RenderHelper.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/RenderHelper.kt @@ -381,32 +381,6 @@ fun popScissorRect() { val currentScissorRect get() = scissorStack.lastOrNull() -fun TextureAtlasSprite.render( - stack: PoseStack, - x: Float = 0f, - y: Float = 0f, - width: Float, - height: Float, - winding: UVWindingOrder = UVWindingOrder.NORMAL -) { - RenderSystem.setShaderTexture(0, atlasLocation()) - - if (winding.isIdentity) { - renderTexturedRect(stack.last().pose(), x, y, width, height, uv = UVCoords(u0, v0, u1, v1)) - } else { - renderTexturedRect(stack.last().pose(), x, y, width, height, uv = winding.translate(u0, v0, u1, v1)) - } -} - -fun TextureAtlasSprite.render( - graphics: MGUIGraphics, - x: Float = 0f, - y: Float = 0f, - width: Float, - height: Float, - winding: UVWindingOrder = UVWindingOrder.NORMAL -) = render(graphics.pose, x, y, width, height, winding) - fun determineTooltipPosition(x: Float, y: Float, width: Float, height: Float): Pair { val windowWidth = minecraft.window.guiScaledWidth.toFloat() val windowHeight = minecraft.window.guiScaledHeight.toFloat() @@ -479,18 +453,6 @@ fun drawArc( alignAtCenter: Boolean = true ) = drawArc(stack.last().pose(), x, y, outerRadius, innerRadius, startDegree, endDegree, steps, alignAtCenter) -fun drawArc( - graphics: GuiGraphics, - x: Float, - y: Float, - outerRadius: Float, - innerRadius: Float = 0f, - startDegree: Double = 0.0, - endDegree: Double = PI * 2.0, - steps: Int = (outerRadius * (endDegree - startDegree) * 4.0).roundToInt().coerceAtLeast(12), - alignAtCenter: Boolean = true -) = drawArc(graphics.pose(), x, y, outerRadius, innerRadius, startDegree, endDegree, steps, alignAtCenter) - fun uploadArc( matrix: Matrix4f, builder: VertexConsumer, diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EffectListPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EffectListPanel.kt index 70155b260..d682f52f7 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EffectListPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EffectListPanel.kt @@ -13,7 +13,6 @@ import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.mc.otm.client.render.RenderGravity import ru.dbotthepony.mc.otm.client.render.determineTooltipPosition import ru.dbotthepony.mc.otm.client.render.sprites.sprite -import ru.dbotthepony.mc.otm.client.render.render import ru.dbotthepony.mc.otm.client.screen.panels.util.DiscreteScrollBarPanel import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.mc.otm.core.TranslatableComponent @@ -112,7 +111,7 @@ open class EffectListPanel @JvmOverloads constructor( SQUARE_THIN.render(graphics, width = width, height = height) RenderSystem.setShaderColor(1f, 1f, 1f, 0.5f) - minecraft.mobEffectTextures.get(effect.effect).render(graphics, x = 3f, y = 3f, width = width - 6f, height = height - 6f) + graphics.renderSprite(minecraft.mobEffectTextures.get(effect.effect), x = 3f, y = 3f, width = width - 6f, height = height - 6f) RenderSystem.setShaderColor(1f, 1f, 1f, 1f) graphics.draw(formatTickDuration(effect.duration), width / 2f, height / 2f, scale = 0.75f, gravity = RenderGravity.CENTER_CENTER, color = RGBAColor.WHITE) @@ -128,8 +127,8 @@ open class EffectListPanel @JvmOverloads constructor( val renderWidth = 18f val renderHeight = 18f - minecraft.mobEffectTextures.get(effect.effect).render( - graphics.pose, + graphics.renderSprite( + minecraft.mobEffectTextures.get(effect.effect), x = x + 8f, y = y + BAR.height / 2f - renderHeight / 2f, width = renderWidth,