mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 09:56:37 -04:00
rendering: ProgressBar
This commit is contained in:
parent
192c3a1e0e
commit
0135b49f15
@ -224,7 +224,7 @@ class RenderWindow(
|
||||
// Make the OpenGL context current
|
||||
glfwMakeContextCurrent(windowId)
|
||||
// Enable v-sync
|
||||
glfwSwapInterval(0)
|
||||
glfwSwapInterval(1)
|
||||
|
||||
|
||||
// Make the window visible
|
||||
|
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 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.hud.atlas
|
||||
|
||||
data class ProgressBarAtlasElement(
|
||||
val emptyAtlasElement: HUDAtlasElement,
|
||||
val fullAtlasElement: HUDAtlasElement,
|
||||
)
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 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.hud.elements
|
||||
|
||||
import de.bixilon.minosoft.gui.rendering.hud.atlas.HUDAtlasElement
|
||||
import glm_.vec2.Vec2
|
||||
|
||||
class ProgressBar(
|
||||
private val emptyAtlasElement: HUDAtlasElement,
|
||||
private val fullAtlasElement: HUDAtlasElement,
|
||||
private val hudElement: HUDElement,
|
||||
) {
|
||||
val size: Vec2 = emptyAtlasElement.binding.size
|
||||
|
||||
// fun draw(elementMesh: ElementMesh, start: Vec2, end: Vec2, progress: Float, z: Int = 1) {
|
||||
//// elementMesh.addElement(start, end, emptyAtlasElement, z)
|
||||
|
||||
// if (progress == 0.0f) {
|
||||
// return
|
||||
// }
|
||||
|
||||
// val xDiff = abs(end.x - start.x)
|
||||
|
||||
// val ourXDiff = xDiff * progress
|
||||
|
||||
// val textureStart = Vec2((fullAtlasElement.binding.start.x * fullAtlasElement.texture.widthFactor) / fullAtlasElement.texture.width.toFloat(), (fullAtlasElement.binding.start.y * fullAtlasElement.texture.heightFactor) / fullAtlasElement.texture.height.toFloat())
|
||||
// var textureEnd = Vec2(((fullAtlasElement.binding.end.x + 1) * fullAtlasElement.texture.widthFactor) / (fullAtlasElement.texture.width + 1.0f), ((fullAtlasElement.binding.end.y + 1) * fullAtlasElement.texture.heightFactor) / (fullAtlasElement.texture.height + 1.0f))
|
||||
|
||||
// textureEnd = Vec2((textureEnd.x - textureStart.x) * progress, textureEnd.y)
|
||||
|
||||
// elementMesh.addElement(start, Vec2(start.x + ourXDiff, end.y), object : TextureLike {
|
||||
// override val texture: Texture
|
||||
// get() = fullAtlasElement.texture
|
||||
// override val uvStart: Vec2
|
||||
// get() = textureStart
|
||||
// override val uvEnd: Vec2
|
||||
// get() = textureEnd
|
||||
|
||||
// }, z + 1)
|
||||
// }
|
||||
}
|
@ -19,10 +19,11 @@ import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
import de.bixilon.minosoft.gui.rendering.hud.HUDElementProperties
|
||||
import de.bixilon.minosoft.gui.rendering.hud.HUDRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.hud.atlas.HUDAtlasElement
|
||||
import de.bixilon.minosoft.gui.rendering.hud.atlas.ProgressBarAtlasElement
|
||||
import de.bixilon.minosoft.gui.rendering.hud.elements.HUDElement
|
||||
import de.bixilon.minosoft.gui.rendering.hud.elements.ProgressBar
|
||||
import de.bixilon.minosoft.gui.rendering.hud.elements.primitive.ElementListElement
|
||||
import de.bixilon.minosoft.gui.rendering.hud.elements.primitive.ImageElement
|
||||
import de.bixilon.minosoft.gui.rendering.hud.elements.primitive.ProgressBar
|
||||
import glm_.vec2.Vec2
|
||||
|
||||
class HotbarHUDElement(
|
||||
@ -40,17 +41,16 @@ class HotbarHUDElement(
|
||||
private lateinit var hotbarBaseAtlasElement: HUDAtlasElement
|
||||
private lateinit var hotbarSelectedSlotFrameAtlasElement: HUDAtlasElement
|
||||
|
||||
private lateinit var experienceBar: ProgressBar
|
||||
private lateinit var experienceBarAtlasElement: ProgressBarAtlasElement
|
||||
|
||||
|
||||
override fun init() {
|
||||
hotbarBaseAtlasElement = hudRenderer.hudAtlasElements[ResourceLocation("minecraft:hotbar_base")]!!
|
||||
hotbarSelectedSlotFrameAtlasElement = hudRenderer.hudAtlasElements[ResourceLocation("minecraft:hotbar_selected_slot_frame")]!!
|
||||
|
||||
experienceBar = ProgressBar(
|
||||
experienceBarAtlasElement = ProgressBarAtlasElement(
|
||||
hudRenderer.hudAtlasElements[ResourceLocation("minecraft:experience_bar_empty")]!!,
|
||||
hudRenderer.hudAtlasElements[ResourceLocation("minecraft:experience_bar_full")]!!,
|
||||
this
|
||||
)
|
||||
|
||||
for ((slotIndex, resourceLocation) in KeyBindingsNames.SELECT_HOTBAR_SLOTS.withIndex()) {
|
||||
@ -70,12 +70,13 @@ class HotbarHUDElement(
|
||||
elementList.forceX = hotbarBaseAtlasElement.binding.size.x.toInt()
|
||||
|
||||
|
||||
// if (hudRenderer.connection.player.gamemode != Gamemodes.CREATIVE) {
|
||||
// // experience bar
|
||||
// val experienceBarEnd = Vec2(hotbarBaseAtlasElement.binding.size.x, experienceBar.size.y)
|
||||
if (hudRenderer.connection.player.gamemode != Gamemodes.CREATIVE) {
|
||||
// experience bar
|
||||
val experienceBarEnd = Vec2(hotbarBaseAtlasElement.binding.size.x, experienceBarAtlasElement.emptyAtlasElement.binding.size.y)
|
||||
|
||||
// experienceBar.draw(elementList, Vec2(), experienceBarEnd, hudRenderer.connection.player.experienceBarProgress, 3)
|
||||
// }
|
||||
val experienceBar = ProgressBar(Vec2(), experienceBarEnd, experienceBarAtlasElement, hudRenderer.connection.player.experienceBarProgress, 1)
|
||||
elementList.addChild(experienceBar)
|
||||
}
|
||||
|
||||
|
||||
val hotbarStart = Vec2(0, elementList.size.y + ELEMENT_PADDING)
|
||||
|
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 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.hud.elements.primitive
|
||||
|
||||
import de.bixilon.minosoft.gui.rendering.hud.HUDMesh
|
||||
import de.bixilon.minosoft.gui.rendering.hud.atlas.ProgressBarAtlasElement
|
||||
import de.bixilon.minosoft.gui.rendering.hud.atlas.TextureLike
|
||||
import de.bixilon.minosoft.gui.rendering.textures.Texture
|
||||
import glm_.mat4x4.Mat4
|
||||
import glm_.vec2.Vec2
|
||||
|
||||
class ProgressBar(
|
||||
start: Vec2,
|
||||
val end: Vec2,
|
||||
private val atlasElement: ProgressBarAtlasElement,
|
||||
val progress: Float = 0.0f,
|
||||
val z: Int = 1,
|
||||
) : Element(start) {
|
||||
|
||||
init {
|
||||
recalculateSize()
|
||||
}
|
||||
|
||||
override fun recalculateSize() {
|
||||
size = atlasElement.emptyAtlasElement.binding.size
|
||||
}
|
||||
|
||||
// fun draw(elementMesh: ElementMesh, start: Vec2, end: Vec2, progress: Float, z: Int = 1) {
|
||||
// elementMesh.addElement(start, end, emptyAtlasElement, z)
|
||||
|
||||
// if (progress == 0.0f) {
|
||||
// return
|
||||
// }
|
||||
|
||||
// val xDiff = abs(end.x - start.x)
|
||||
|
||||
// val ourXDiff = xDiff * progress
|
||||
|
||||
// val textureStart = Vec2((fullAtlasElement.binding.start.x * fullAtlasElement.texture.widthFactor) / fullAtlasElement.texture.width.toFloat(), (fullAtlasElement.binding.start.y * fullAtlasElement.texture.heightFactor) / fullAtlasElement.texture.height.toFloat())
|
||||
// var textureEnd = Vec2(((fullAtlasElement.binding.end.x + 1) * fullAtlasElement.texture.widthFactor) / (fullAtlasElement.texture.width + 1.0f), ((fullAtlasElement.binding.end.y + 1) * fullAtlasElement.texture.heightFactor) / (fullAtlasElement.texture.height + 1.0f))
|
||||
|
||||
// textureEnd = Vec2((textureEnd.x - textureStart.x) * progress, textureEnd.y)
|
||||
|
||||
// elementMesh.addElement(start, Vec2(start.x + ourXDiff, end.y), object : TextureLike {
|
||||
// override val texture: Texture
|
||||
// get() = fullAtlasElement.texture
|
||||
// override val uvStart: Vec2
|
||||
// get() = textureStart
|
||||
// override val uvEnd: Vec2
|
||||
// get() = textureEnd
|
||||
|
||||
// }, z + 1)
|
||||
// }
|
||||
|
||||
override fun prepareVertices(start: Vec2, scaleFactor: Float, hudMesh: HUDMesh, matrix: Mat4, z: Int) {
|
||||
val emptyImageElement = ImageElement(this.start, end, atlasElement.emptyAtlasElement, z)
|
||||
|
||||
emptyImageElement.prepareVertices(start, scaleFactor, hudMesh, matrix, z)
|
||||
|
||||
if (progress == 0.0f) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
val fullImageElement = ImageElement(this.start, Vec2(end.x * progress, end.y), object : TextureLike {
|
||||
override val texture: Texture
|
||||
get() = atlasElement.fullAtlasElement.texture
|
||||
override val uvStart: Vec2
|
||||
get() = atlasElement.fullAtlasElement.uvStart
|
||||
override val uvEnd: Vec2
|
||||
get() = Vec2((atlasElement.fullAtlasElement.uvEnd.x - atlasElement.fullAtlasElement.uvStart.x) * progress + atlasElement.fullAtlasElement.uvStart.x, atlasElement.fullAtlasElement.uvEnd.y)
|
||||
|
||||
}, z + 1)
|
||||
|
||||
fullImageElement.prepareVertices(start, scaleFactor, hudMesh, matrix, z)
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user