make some GridLayout final again

This commit is contained in:
Bixilon 2022-01-25 10:07:44 +01:00
parent 8bd1686593
commit 17e2801465
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
6 changed files with 55 additions and 12 deletions

View File

@ -32,3 +32,8 @@
## ToDo:
- make `TextElement`, `GridLayout` final
- TextInput
- Keyboard navigation
- Chat
- Inventory
- Pause menu

View File

@ -24,7 +24,7 @@ import glm_.vec2.Vec2i
import java.lang.Integer.min
import kotlin.math.max
open class GridLayout(guiRenderer: GUIRenderer, val grid: Vec2i) : Element(guiRenderer) {
class GridLayout(guiRenderer: GUIRenderer, val grid: Vec2i) : Element(guiRenderer) {
val columnConstraints: Array<GridColumnConstraint> = Array(grid.x) { GridColumnConstraint() }
val rowConstraints: Array<GridRowConstraint> = Array(grid.y) { GridRowConstraint() }

View File

@ -24,6 +24,6 @@ class PauseMenu(guiRenderer: GUIRenderer) : Menu(guiRenderer) {
init {
addButton(ButtonElement(guiRenderer, "Back to game") { guiRenderer.gui.pause(false) })
addButton(ConfirmButtonElement(guiRenderer, "§cDisconnect", "§cClick again to disconnect!") { guiRenderer.connection.network.disconnect() })
addButton(ConfirmButtonElement(guiRenderer, "§4Exit", "§4Click again to exit!") { ShutdownManager.shutdown() })
addButton(ConfirmButtonElement(guiRenderer, "§4Exit", "§4Click again to exit!") { guiRenderer.connection.network.disconnect(); ShutdownManager.shutdown() })
}
}

View File

@ -17,26 +17,31 @@ import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.text.ChatColors
import de.bixilon.minosoft.data.text.TextComponent
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
import de.bixilon.minosoft.gui.rendering.gui.elements.Element
import de.bixilon.minosoft.gui.rendering.gui.elements.LayoutedElement
import de.bixilon.minosoft.gui.rendering.gui.elements.text.TextElement
import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDBuilder
import de.bixilon.minosoft.gui.rendering.gui.hud.elements.LayoutedGUIElement
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions
import de.bixilon.minosoft.gui.rendering.renderer.Drawable
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import glm_.vec2.Vec2i
class BreakProgressHUDElement(guiRenderer: GUIRenderer) : TextElement(guiRenderer, ""), LayoutedElement, Drawable {
class BreakProgressHUDElement(guiRenderer: GUIRenderer) : Element(guiRenderer), LayoutedElement, Drawable {
private val textElement = TextElement(guiRenderer, "").apply { parent = this@BreakProgressHUDElement }
private val breakInteractionHandler = guiRenderer.renderWindow.inputHandler.interactionManager.`break`
override val layoutOffset: Vec2i
get() = Vec2i((guiRenderer.scaledSize.x / 2) + CrosshairHUDElement.CROSSHAIR_SIZE / 2 + 5, (guiRenderer.scaledSize.y - super.size.y) / 2)
get() = Vec2i((guiRenderer.scaledSize.x / 2) + CrosshairHUDElement.CROSSHAIR_SIZE / 2 + 5, (guiRenderer.scaledSize.y - textElement.size.y) / 2)
private var percent = -1
override fun draw() {
val breakProgress = breakInteractionHandler.breakProgress
if (breakProgress <= 0 || breakProgress >= 1.0) {
super.text = ""
textElement.text = ""
this.percent = -1
return
}
@ -44,7 +49,7 @@ class BreakProgressHUDElement(guiRenderer: GUIRenderer) : TextElement(guiRendere
if (percent == this.percent) {
return
}
super.text = TextComponent("$percent%").apply {
textElement.text = TextComponent("$percent%").apply {
color = when {
percent <= 30 -> ChatColors.RED
percent <= 70 -> ChatColors.YELLOW
@ -54,6 +59,19 @@ class BreakProgressHUDElement(guiRenderer: GUIRenderer) : TextElement(guiRendere
this.percent = percent
}
override fun forceRender(offset: Vec2i, z: Int, consumer: GUIVertexConsumer, options: GUIVertexOptions?): Int {
return textElement.forceRender(offset, z, consumer, options)
}
override fun onChildChange(child: Element) {
forceSilentApply()
super.onChildChange(this)
}
override fun forceSilentApply() {
cacheUpToDate = false
}
companion object : HUDBuilder<LayoutedGUIElement<BreakProgressHUDElement>> {
override val RESOURCE_LOCATION: ResourceLocation = "minosoft:progress_indicator".toResourceLocation()

View File

@ -38,6 +38,8 @@ import de.bixilon.minosoft.gui.rendering.gui.elements.text.TextElement
import de.bixilon.minosoft.gui.rendering.gui.hud.Initializable
import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDBuilder
import de.bixilon.minosoft.gui.rendering.gui.hud.elements.LayoutedGUIElement
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions
import de.bixilon.minosoft.gui.rendering.modding.events.ResizeWindowEvent
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY
@ -55,15 +57,16 @@ import glm_.vec2.Vec2i
import glm_.vec4.Vec4i
import kotlin.math.abs
class DebugHUDElement(guiRenderer: GUIRenderer) : GridLayout(guiRenderer, Vec2i(3, 1)), LayoutedElement, Initializable {
class DebugHUDElement(guiRenderer: GUIRenderer) : Element(guiRenderer), LayoutedElement, Initializable {
private val connection = renderWindow.connection
private val layout = GridLayout(guiRenderer, Vec2i(3, 1)).apply { parent = this@DebugHUDElement }
override val layoutOffset: Vec2i = Vec2i.EMPTY
init {
columnConstraints[0].apply {
layout.columnConstraints[0].apply {
grow = GridGrow.NEVER
}
columnConstraints[2].apply {
layout.columnConstraints[2].apply {
grow = GridGrow.NEVER
alignment = HorizontalAlignments.RIGHT
}
@ -73,8 +76,8 @@ class DebugHUDElement(guiRenderer: GUIRenderer) : GridLayout(guiRenderer, Vec2i(
override fun init() {
this[Vec2i(0, 0)] = initLeft()
this[Vec2i(2, 0)] = initRight()
layout[Vec2i(0, 0)] = initLeft()
layout[Vec2i(2, 0)] = initRight()
this.prefMaxSize = Vec2i(-1, Int.MAX_VALUE)
this.ignoreDisplaySize = true
@ -285,6 +288,23 @@ class DebugHUDElement(guiRenderer: GUIRenderer) : GridLayout(guiRenderer, Vec2i(
}
}
override fun forceRender(offset: Vec2i, z: Int, consumer: GUIVertexConsumer, options: GUIVertexOptions?): Int {
return layout.forceRender(offset, z, consumer, options)
}
override fun forceSilentApply() {
cacheUpToDate = false
}
override fun onChildChange(child: Element) {
super.onChildChange(child)
forceSilentApply()
}
override fun tick() {
layout.tick()
}
companion object : HUDBuilder<LayoutedGUIElement<DebugHUDElement>> {
override val RESOURCE_LOCATION: ResourceLocation = "minosoft:debug_hud".toResourceLocation()
override val ENABLE_KEY_BINDING_NAME: ResourceLocation = "minosoft:enable_debug_hud".toResourceLocation()

View File

@ -67,7 +67,7 @@
<Text text="Version abc&#10;Other text&#10;"/>
</TextFlow>
<TextArea fx:id="copyrightFX" editable="false"
text="Minosoft&#10;Copyright (C) 2021 Moritz Zwerger and contributors&#10;&#10;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.&#10;&#10;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.&#10;&#10;You should have received a copy of the GNU General Public License along with this program. If not, see &lt;https://www.gnu.org/licenses/&gt;.&#10;&#10;This software is not affiliated with Mojang AB, the original developer of Minecraft."
text="Minosoft&#10;Copyright (C) 2020-2022 Moritz Zwerger and contributors&#10;&#10;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.&#10;&#10;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.&#10;&#10;You should have received a copy of the GNU General Public License along with this program. If not, see &lt;https://www.gnu.org/licenses/&gt;.&#10;&#10;This software is not affiliated with Mojang AB, the original developer of Minecraft."
wrapText="true" GridPane.rowIndex="2">
<GridPane.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>