mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 03:15:35 -04:00
implement atlases, fixes
This commit is contained in:
parent
6b3d29ed88
commit
a5770dc789
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* Minosoft
|
||||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
* 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 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.
|
||||||
*
|
*
|
||||||
@ -56,9 +56,11 @@ open class ProgressElement(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun forceSilentApply() {
|
override fun forceSilentApply() {
|
||||||
val emptyAtlasElement = emptyAtlasElement ?: return
|
val full = fullAtlasElement ?: return
|
||||||
val fullAtlasElement = fullAtlasElement ?: return
|
|
||||||
progressImage = ImageElement(guiRenderer, fullAtlasElement.texture, uvStart = fullAtlasElement.uvStart, uvEnd = Vec2(interpolateLinear(progress, fullAtlasElement.uvStart.x, fullAtlasElement.uvEnd.x), fullAtlasElement.uvEnd.y), size = Vec2((fullAtlasElement.size.x * progress), emptyAtlasElement.size.y))
|
val uvEnd = Vec2(interpolateLinear(progress, full.uvStart.x, full.uvEnd.x), full.uvEnd.y)
|
||||||
|
val size = this.size
|
||||||
|
progressImage = ImageElement(guiRenderer, full.texture, uvStart = full.uvStart, uvEnd = uvEnd, size = Vec2((size.x * progress), size.y))
|
||||||
|
|
||||||
cacheUpToDate = false
|
cacheUpToDate = false
|
||||||
}
|
}
|
||||||
|
@ -208,6 +208,7 @@ class HotbarElement(guiRenderer: GUIRenderer) : Element(guiRenderer), LayoutedEl
|
|||||||
gui.atlas.load(HotbarBaseElement.ATLAS)
|
gui.atlas.load(HotbarBaseElement.ATLAS)
|
||||||
gui.atlas.load(HotbarProtectionElement.ATLAS)
|
gui.atlas.load(HotbarProtectionElement.ATLAS)
|
||||||
gui.atlas.load(HotbarHungerElement.ATLAS)
|
gui.atlas.load(HotbarHungerElement.ATLAS)
|
||||||
|
gui.atlas.load(HotbarExperienceBarElement.ATLAS)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun build(guiRenderer: GUIRenderer): LayoutedGUIElement<HotbarElement> {
|
override fun build(guiRenderer: GUIRenderer): LayoutedGUIElement<HotbarElement> {
|
||||||
|
@ -61,6 +61,7 @@ class HotbarExperienceBarElement(guiRenderer: GUIRenderer) : Element(guiRenderer
|
|||||||
val bars = atlasElements[barIndex]
|
val bars = atlasElements[barIndex]
|
||||||
|
|
||||||
val progress = ProgressElement(guiRenderer, bars, progress)
|
val progress = ProgressElement(guiRenderer, bars, progress)
|
||||||
|
progress.prefMaxSize = SIZE
|
||||||
progress.render(offset, consumer, options)
|
progress.render(offset, consumer, options)
|
||||||
|
|
||||||
if (level > 0) {
|
if (level > 0) {
|
||||||
@ -91,7 +92,7 @@ class HotbarExperienceBarElement(guiRenderer: GUIRenderer) : Element(guiRenderer
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val ATLAS = minecraft("hud/hotbar/experience")
|
val ATLAS = minecraft("hud/hotbar/experience")
|
||||||
private val TEXT_PROPERTIES = TextRenderProperties(HorizontalAlignments.CENTER, shadow = false)
|
private val TEXT_PROPERTIES = TextRenderProperties(HorizontalAlignments.CENTER, shadow = false)
|
||||||
private val SIZE = Vec2(182, 5)
|
private val SIZE = Vec2(182, 5)
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ class HotbarHungerElement(guiRenderer: GUIRenderer) : Element(guiRenderer), Poll
|
|||||||
|
|
||||||
if (hungerProfile.saturationBar) {
|
if (hungerProfile.saturationBar) {
|
||||||
val container = when {
|
val container = when {
|
||||||
hungerEffect -> atlas.hungerContainer
|
hungerEffect -> atlas.getContainer(true)
|
||||||
saturationLeft == 1 -> {
|
saturationLeft == 1 -> {
|
||||||
saturationLeft -= 1
|
saturationLeft -= 1
|
||||||
atlas.getSaturationContainer(true)
|
atlas.getSaturationContainer(true)
|
||||||
@ -79,7 +79,7 @@ class HotbarHungerElement(guiRenderer: GUIRenderer) : Element(guiRenderer), Poll
|
|||||||
atlas.getSaturationContainer(false)
|
atlas.getSaturationContainer(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> atlas.container
|
else -> atlas.getContainer(false)
|
||||||
}
|
}
|
||||||
AtlasImageElement(guiRenderer, container).render(hungerOffset, consumer, options)
|
AtlasImageElement(guiRenderer, container).render(hungerOffset, consumer, options)
|
||||||
}
|
}
|
||||||
@ -134,11 +134,13 @@ class HotbarHungerElement(guiRenderer: GUIRenderer) : Element(guiRenderer), Poll
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class HungerAtlas(val atlas: Atlas?) {
|
private class HungerAtlas(val atlas: Atlas?) {
|
||||||
val container = atlas["container"]
|
private val container = arrayOf(atlas["container"], atlas["container_hunger"])
|
||||||
val hungerContainer = atlas["container_hunger"]
|
private val saturation = arrayOf(atlas["container_saturation_half"], atlas["container_saturation_full"])
|
||||||
|
private val hunger = arrayOf(arrayOf(atlas["full"], atlas["half"]), arrayOf(atlas["full_hunger"], atlas["half_hunger"]))
|
||||||
|
|
||||||
fun getHunger(half: Boolean, hunger: Boolean): AtlasElement = TODO()
|
fun getHunger(half: Boolean, hunger: Boolean): AtlasElement? = this.hunger[if (hunger) 1 else 0][if (half) 1 else 0]
|
||||||
fun getSaturationContainer(half: Boolean): AtlasElement = TODO()
|
fun getContainer(hunger: Boolean): AtlasElement? = container[if (hunger) 1 else 0]
|
||||||
|
fun getSaturationContainer(half: Boolean): AtlasElement? = saturation[if (half) 0 else 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -13,20 +13,41 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.gui.rendering.gui.hud.elements.hotbar.health
|
package de.bixilon.minosoft.gui.rendering.gui.hud.elements.hotbar.health
|
||||||
|
|
||||||
|
import de.bixilon.kutil.primitive.IntUtil.toInt
|
||||||
import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
|
import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
|
||||||
import de.bixilon.minosoft.gui.rendering.gui.atlas.Atlas
|
import de.bixilon.minosoft.gui.rendering.gui.atlas.Atlas
|
||||||
|
import de.bixilon.minosoft.gui.rendering.gui.atlas.Atlas.Companion.get
|
||||||
import de.bixilon.minosoft.gui.rendering.gui.atlas.AtlasElement
|
import de.bixilon.minosoft.gui.rendering.gui.atlas.AtlasElement
|
||||||
|
|
||||||
class HeartAtlas(val atlas: Atlas?) {
|
class HeartAtlas(private val atlas: Atlas?) {
|
||||||
val normal = HartType()
|
val normal = HartType("")
|
||||||
val poisoned = HartType()
|
val poisoned = HartType("poisoned")
|
||||||
val withered = HartType()
|
val withered = HartType("withered")
|
||||||
val absorption = HartType()
|
val absorption = HartType("absorption")
|
||||||
val frozen = HartType()
|
val frozen = HartType("frozen")
|
||||||
|
|
||||||
class HartType {
|
|
||||||
fun get(full: Boolean, hardcore: Boolean, blinking: Boolean): AtlasElement = TODO()
|
|
||||||
|
|
||||||
|
val container = atlas["container"] // TODO: There are multiple containers
|
||||||
|
|
||||||
|
inner class HartType(type: String) {
|
||||||
|
val hearts = Array(2) { full ->
|
||||||
|
Array(2) { hardcore ->
|
||||||
|
Array(2) { blinking ->
|
||||||
|
val name = StringBuilder()
|
||||||
|
if (type.isNotEmpty()) {
|
||||||
|
name.append(type)
|
||||||
|
name.append('_')
|
||||||
|
}
|
||||||
|
name.append(if (full > 0) "full" else "half")
|
||||||
|
if (hardcore > 0) name.append("_hardcore")
|
||||||
|
if (blinking > 0) name.append("_blinking")
|
||||||
|
|
||||||
|
atlas?.get(name.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // frozen_full_hardcore_blinking
|
||||||
|
|
||||||
|
fun get(full: Boolean, hardcore: Boolean, blinking: Boolean): AtlasElement? = this.hearts[full.toInt()][hardcore.toInt()][blinking.toInt()]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ import de.bixilon.minosoft.data.text.ChatComponent
|
|||||||
import de.bixilon.minosoft.data.text.TextComponent
|
import de.bixilon.minosoft.data.text.TextComponent
|
||||||
import de.bixilon.minosoft.data.text.formatting.color.RGBColor.Companion.asColor
|
import de.bixilon.minosoft.data.text.formatting.color.RGBColor.Companion.asColor
|
||||||
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
|
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
|
||||||
import de.bixilon.minosoft.gui.rendering.gui.atlas.Atlas.Companion.get
|
|
||||||
import de.bixilon.minosoft.gui.rendering.gui.elements.Pollable
|
import de.bixilon.minosoft.gui.rendering.gui.elements.Pollable
|
||||||
import de.bixilon.minosoft.gui.rendering.gui.elements.primitive.AtlasImageElement
|
import de.bixilon.minosoft.gui.rendering.gui.elements.primitive.AtlasImageElement
|
||||||
import de.bixilon.minosoft.gui.rendering.gui.hud.elements.hotbar.AbstractHotbarHealthElement
|
import de.bixilon.minosoft.gui.rendering.gui.hud.elements.hotbar.AbstractHotbarHealthElement
|
||||||
@ -36,7 +35,6 @@ import java.lang.Float.min
|
|||||||
class HotbarHealthElement(guiRenderer: GUIRenderer) : AbstractHotbarHealthElement(guiRenderer), Pollable {
|
class HotbarHealthElement(guiRenderer: GUIRenderer) : AbstractHotbarHealthElement(guiRenderer), Pollable {
|
||||||
|
|
||||||
private val atlas = HeartAtlas(guiRenderer.atlas[HeartAtlas.ATLAS])
|
private val atlas = HeartAtlas(guiRenderer.atlas[HeartAtlas.ATLAS])
|
||||||
private val blackHeartContainer = atlas.atlas["container"] // TODO: There are multiple containers
|
|
||||||
|
|
||||||
private var hardcode = false
|
private var hardcode = false
|
||||||
private var poison = false
|
private var poison = false
|
||||||
@ -55,7 +53,7 @@ class HotbarHealthElement(guiRenderer: GUIRenderer) : AbstractHotbarHealthElemen
|
|||||||
return super.forceRender(offset, consumer, options)
|
return super.forceRender(offset, consumer, options)
|
||||||
}
|
}
|
||||||
// ToDo: Damage animation, regeneration, caching, stacking
|
// ToDo: Damage animation, regeneration, caching, stacking
|
||||||
drawCanisters(offset, consumer, options, blackHeartContainer)
|
drawCanisters(offset, consumer, options, atlas.container)
|
||||||
|
|
||||||
|
|
||||||
var healthLeft = totalHealth
|
var healthLeft = totalHealth
|
||||||
|
@ -32,7 +32,7 @@ import java.lang.Float.max
|
|||||||
class HotbarVehicleHealthElement(guiRenderer: GUIRenderer) : AbstractHotbarHealthElement(guiRenderer), Pollable {
|
class HotbarVehicleHealthElement(guiRenderer: GUIRenderer) : AbstractHotbarHealthElement(guiRenderer), Pollable {
|
||||||
private val atlasManager = guiRenderer.atlas
|
private val atlasManager = guiRenderer.atlas
|
||||||
|
|
||||||
private val atlas = VehicleHeartAtlas(guiRenderer.atlas[HeartAtlas.ATLAS])
|
private val atlas = guiRenderer.atlas[HeartAtlas.ATLAS]?.let { VehicleHeartAtlas(it) }
|
||||||
|
|
||||||
private var shown = false
|
private var shown = false
|
||||||
override var totalHealth = 0.0f
|
override var totalHealth = 0.0f
|
||||||
@ -45,7 +45,7 @@ class HotbarVehicleHealthElement(guiRenderer: GUIRenderer) : AbstractHotbarHealt
|
|||||||
if (text) {
|
if (text) {
|
||||||
return super.forceRender(offset, consumer, options)
|
return super.forceRender(offset, consumer, options)
|
||||||
}
|
}
|
||||||
drawCanisters(offset, consumer, options, atlas.getContainer(false))
|
drawCanisters(offset, consumer, options, atlas?.getContainer(false))
|
||||||
|
|
||||||
var healthLeft = totalHealth
|
var healthLeft = totalHealth
|
||||||
var heart = 0
|
var heart = 0
|
||||||
@ -56,7 +56,7 @@ class HotbarVehicleHealthElement(guiRenderer: GUIRenderer) : AbstractHotbarHealt
|
|||||||
|
|
||||||
|
|
||||||
val halfHeart = healthLeft < 1.5f
|
val halfHeart = healthLeft < 1.5f
|
||||||
val image = atlas.getHeart(halfHeart)?.let { AtlasImageElement(guiRenderer, it) }
|
val image = atlas?.getHeart(halfHeart)?.let { AtlasImageElement(guiRenderer, it) }
|
||||||
|
|
||||||
image?.render(offset + Vec2(column, (rows - 1) - row) * HEART_SIZE, consumer, options)
|
image?.render(offset + Vec2(column, (rows - 1) - row) * HEART_SIZE, consumer, options)
|
||||||
|
|
||||||
|
@ -16,9 +16,12 @@ package de.bixilon.minosoft.gui.rendering.gui.hud.elements.hotbar.health
|
|||||||
import de.bixilon.minosoft.gui.rendering.gui.atlas.Atlas
|
import de.bixilon.minosoft.gui.rendering.gui.atlas.Atlas
|
||||||
import de.bixilon.minosoft.gui.rendering.gui.atlas.AtlasElement
|
import de.bixilon.minosoft.gui.rendering.gui.atlas.AtlasElement
|
||||||
|
|
||||||
class VehicleHeartAtlas(val atlas: Atlas?) {
|
class VehicleHeartAtlas(atlas: Atlas) {
|
||||||
|
private val half = atlas["half_vehicle"]
|
||||||
|
private val full = atlas["full_vehicle"]
|
||||||
|
private val container = atlas["container_vehicle"]
|
||||||
|
|
||||||
fun getContainer(half: Boolean): AtlasElement = TODO()
|
fun getContainer(half: Boolean): AtlasElement? = container
|
||||||
|
|
||||||
fun getHeart(half: Boolean): AtlasElement = TODO()
|
fun getHeart(half: Boolean): AtlasElement? = if (half) this.half else this.full
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
"empty": {
|
"empty": {
|
||||||
"0": {
|
"0": {
|
||||||
"texture": "gui/icons",
|
"texture": "gui/icons",
|
||||||
"start": [0, 64]
|
"start": [0, 64],
|
||||||
|
"end": [182, 69]
|
||||||
},
|
},
|
||||||
"18": {
|
"18": {
|
||||||
"texture": "gui/sprites/hud/experience_bar_background",
|
"texture": "gui/sprites/hud/experience_bar_background",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user