From 0ff0ad6d643b90c3d22575296262237ba6d32b8f Mon Sep 17 00:00:00 2001 From: Bixilon Date: Mon, 3 Jul 2023 15:43:02 +0200 Subject: [PATCH] fix some tests --- build.gradle.kts | 2 +- doc/gui/ReadME.md | 11 +++++++++++ .../rendering/gui/elements/ElementUpdateTest.kt | 15 ++++++++++++++- .../gui/elements/text/TextElementTest.kt | 2 ++ .../gui/rendering/gui/test/GuiRenderTestUtil.kt | 3 +++ .../gui/rendering/gui/elements/Element.kt | 3 ++- .../rendering/gui/elements/text/TextElement.kt | 2 +- 7 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 doc/gui/ReadME.md diff --git a/build.gradle.kts b/build.gradle.kts index d8bc495bb..b2ab2a2d5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -222,7 +222,7 @@ testing { options { val options = this as TestNGOptions options.preserveOrder = true - options.excludeGroups("input", "font", "command", "registry", "biome", "version", "fluid", "world", "raycasting", "pixlyzer", "item", "block", "physics", "light", "packet", "container", "item_stack", "signature", "private_key", "interaction", "item_digging", "world_renderer", "rendering") + options.excludeGroups("input", "command", "registry", "biome", "version", "fluid", "world", "raycasting", "pixlyzer", "item", "block", "physics", "light", "packet", "container", "item_stack", "signature", "private_key", "interaction", "item_digging", "world_renderer", "rendering") } } } diff --git a/doc/gui/ReadME.md b/doc/gui/ReadME.md new file mode 100644 index 000000000..01d008cd1 --- /dev/null +++ b/doc/gui/ReadME.md @@ -0,0 +1,11 @@ +# GUI/HUD + +Minosoft integrates a custom gui system that can be used to display pretty much anything in 2d space on the screen. + +## Stages + +GUI has 3 rendering stages: + +- update mode (you can make changes async, prepare the next data, `tick`, ...) +- layout mode (called eventually every frame, all currently stored data is applied and put in the layout) +- rendering mode (the current layout will be rendered, might be called every frame if you do animations) diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/gui/elements/ElementUpdateTest.kt b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/gui/elements/ElementUpdateTest.kt index b8a25a903..96461adcd 100644 --- a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/gui/elements/ElementUpdateTest.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/gui/elements/ElementUpdateTest.kt @@ -1,3 +1,16 @@ +/* + * Minosoft + * Copyright (C) 2020-2023 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + package de.bixilon.minosoft.gui.rendering.gui.elements import org.testng.annotations.Test @@ -6,6 +19,6 @@ import org.testng.annotations.Test class ElementUpdateTest { init { - TODO() + // TODO() } } diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextElementTest.kt b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextElementTest.kt index 0c5e05cc7..db4fe060c 100644 --- a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextElementTest.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextElementTest.kt @@ -66,12 +66,14 @@ class TextElementTest { fun `size if text changed`() { val element = TextElement(GuiRenderTestUtil.create(), "bc\nbc", background = TextBackground(size = Vec4(1)), properties = TextRenderProperties(shadow = false)) element.text = "bcd\nbcd\nbcd" + element.update() element.assetSize(Vec2(7.0f, 35.0f)) } fun `size if background cleared`() { val element = TextElement(GuiRenderTestUtil.create(), "bcd\nbcd\nbcd", background = TextBackground(size = Vec4(1)), properties = TextRenderProperties(shadow = false)) element.background = null + element.update() element.assetSize(Vec2(5.0f, 33.0f)) } diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/gui/test/GuiRenderTestUtil.kt b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/gui/test/GuiRenderTestUtil.kt index e718de403..dacd004a9 100644 --- a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/gui/test/GuiRenderTestUtil.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/gui/test/GuiRenderTestUtil.kt @@ -21,6 +21,7 @@ import de.bixilon.minosoft.gui.rendering.RenderContext import de.bixilon.minosoft.gui.rendering.font.manager.FontManager import de.bixilon.minosoft.gui.rendering.font.types.dummy.DummyFontType import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer +import de.bixilon.minosoft.gui.rendering.gui.atlas.AtlasManager import de.bixilon.minosoft.gui.rendering.gui.atlas.CodeTexturePart import de.bixilon.minosoft.gui.rendering.gui.elements.Element import de.bixilon.minosoft.gui.rendering.gui.properties.GUIScreen @@ -48,6 +49,8 @@ object GuiRenderTestUtil { renderer::screen.forceSet(DataObserver(GUIScreen(Vec2i(size), size))) renderer::context.forceSet(createContext()) + renderer::atlasManager.forceSet(AtlasManager(renderer.context)) + renderer.atlasManager::class.java.getDeclaredField("elements").apply { isAccessible = true }.set(renderer.atlasManager, mutableMapOf()) return renderer } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/Element.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/Element.kt index bea834d40..935b088d8 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/Element.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/Element.kt @@ -35,6 +35,7 @@ import de.bixilon.minosoft.gui.rendering.util.vec.vec4.Vec4Util.EMPTY import de.bixilon.minosoft.gui.rendering.util.vec.vec4.Vec4Util.spaceSize import org.jetbrains.annotations.Contract import kotlin.reflect.KProperty0 +import kotlin.reflect.jvm.isAccessible abstract class Element(val guiRenderer: GUIRenderer, initialCacheSize: Int = 1000) : InputElement, DragTarget, CachedElement, ParentedElement, UpdatableElement, Tickable { override val context = guiRenderer.context @@ -166,7 +167,7 @@ abstract class Element(val guiRenderer: GUIRenderer, initialCacheSize: Int = 100 open fun onClose() = Unit - protected inline fun KProperty0.delegate(): GuiDelegate = this.getDelegate().unsafeCast() + protected inline fun KProperty0.delegate(): GuiDelegate = this.apply { isAccessible = true }.getDelegate().unsafeCast() protected inline fun KProperty0.acknowledge(): T = delegate().acknowledge() protected inline fun KProperty0.rendering(): T = delegate().rendering() } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextElement.kt index 7ff478748..e8bcc0ae1 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextElement.kt @@ -130,7 +130,7 @@ open class TextElement( override fun forceRender(offset: Vec2, consumer: GUIVertexConsumer, options: GUIVertexOptions?) { if (empty) return val info = this.info - val properties = this::properties.rendering() + val properties = this::textProperties.rendering() val initialOffset = Vec2(offset + this::margin.rendering().offset) val textOffset = Vec2(initialOffset)