mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-08 06:50:22 -04:00
basic menu tests
This commit is contained in:
parent
3ee66e7f5f
commit
aadd6af56a
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.gui.rendering.gui.gui.screen.menu
|
||||
|
||||
import de.bixilon.kotlinglm.vec2.Vec2
|
||||
import de.bixilon.minosoft.gui.rendering.font.renderer.element.TextRenderProperties
|
||||
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.gui.elements.text.TextElement
|
||||
import de.bixilon.minosoft.gui.rendering.gui.test.GuiRenderTestUtil
|
||||
import de.bixilon.minosoft.gui.rendering.gui.test.GuiTestConsumer
|
||||
import org.testng.Assert.assertEquals
|
||||
import org.testng.annotations.Test
|
||||
|
||||
@Test(groups = ["gui"])
|
||||
class MenuTest {
|
||||
|
||||
fun initialize() {
|
||||
menu(GuiRenderTestUtil.create())
|
||||
}
|
||||
|
||||
fun `assert correct screen size`() {
|
||||
val menu = menu(GuiRenderTestUtil.create())
|
||||
assertEquals(menu.size, Vec2(1920, 1080))
|
||||
}
|
||||
|
||||
fun `basic rendering`() {
|
||||
val menu = menu(GuiRenderTestUtil.create())
|
||||
|
||||
val consumer = GuiTestConsumer()
|
||||
menu.render(Vec2(0, 0), consumer, null)
|
||||
|
||||
consumer.assert(GuiTestConsumer.RendererdQuad(Vec2(0, 0), Vec2(1920, 1080)))
|
||||
// TODO
|
||||
}
|
||||
|
||||
// TODO: test correct layout, mouse, keyboard action, tabbing, element width (e.g. buttons), changing of elements,
|
||||
|
||||
|
||||
fun menu(guiRenderer: GUIRenderer) = object : Menu(guiRenderer) {
|
||||
|
||||
init {
|
||||
this += TextElement(guiRenderer, "bcd", background = null, properties = TextRenderProperties(shadow = false))
|
||||
}
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@ import de.bixilon.kotlinglm.vec2.Vec2
|
||||
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
|
||||
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.gui.abstractions.children.ChildedElement
|
||||
import de.bixilon.minosoft.gui.rendering.gui.abstractions.children.manager.ChildrenManager
|
||||
import de.bixilon.minosoft.gui.rendering.gui.abstractions.children.manager.collection.SetChildrenManager
|
||||
import de.bixilon.minosoft.gui.rendering.gui.elements.Element
|
||||
import de.bixilon.minosoft.gui.rendering.gui.elements.ScreenPositionedElement
|
||||
@ -28,14 +29,18 @@ import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2Util.EMPTY
|
||||
abstract class Screen(
|
||||
guiRenderer: GUIRenderer,
|
||||
) : Element(guiRenderer), ScreenPositionedElement, ChildedElement {
|
||||
override val children = SetChildrenManager(this)
|
||||
override val children: ChildrenManager = SetChildrenManager(this)
|
||||
protected val background = AtlasImageElement(guiRenderer, context.textures.whiteTexture, size = guiRenderer.screen.scaled, tint = RGBColor(0.0f, 0.0f, 0.0f, 0.8f))
|
||||
override val screenOffset: Vec2 = Vec2(0, 0)
|
||||
|
||||
|
||||
init {
|
||||
construct()
|
||||
}
|
||||
|
||||
override fun construct() {
|
||||
background.parent = this
|
||||
super.construct()
|
||||
}
|
||||
|
||||
override fun update() {
|
||||
|
@ -17,7 +17,6 @@ import de.bixilon.kotlinglm.vec2.Vec2
|
||||
import de.bixilon.kotlinglm.vec2.Vec2i
|
||||
import de.bixilon.minosoft.config.key.KeyCodes
|
||||
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.gui.abstractions.children.manager.collection.SetChildrenManager
|
||||
import de.bixilon.minosoft.gui.rendering.gui.elements.Element
|
||||
import de.bixilon.minosoft.gui.rendering.gui.gui.AbstractLayout
|
||||
import de.bixilon.minosoft.gui.rendering.gui.gui.screen.Screen
|
||||
@ -32,7 +31,6 @@ abstract class Menu(
|
||||
guiRenderer: GUIRenderer,
|
||||
val preferredElementWidth: Float = 150.0f,
|
||||
) : Screen(guiRenderer), AbstractLayout<Element> {
|
||||
override val children = SetChildrenManager(this)
|
||||
private val elements: MutableList<Element> = mutableListOf()
|
||||
|
||||
private var maxElementWidth = -1.0f
|
||||
@ -41,6 +39,10 @@ abstract class Menu(
|
||||
override var activeElement: Element? = null
|
||||
override var activeDragElement: Element? = null
|
||||
|
||||
init {
|
||||
super.construct()
|
||||
}
|
||||
|
||||
override fun update() {
|
||||
val elementWidth = maxOf(minOf(preferredElementWidth, size.x / 3), 0.0f)
|
||||
var maxElementWidth = elementWidth
|
||||
@ -219,4 +221,6 @@ abstract class Menu(
|
||||
private companion object {
|
||||
const val BUTTON_Y_MARGIN = 5.0f
|
||||
}
|
||||
|
||||
override fun construct() = Unit
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user