furnace: show container title

This commit is contained in:
Bixilon 2022-05-03 19:37:16 +02:00
parent 36af4bb474
commit 38b8f8e64a
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 55 additions and 19 deletions

View File

@ -13,29 +13,14 @@
package de.bixilon.minosoft.gui.rendering.gui.gui.screen.container package de.bixilon.minosoft.gui.rendering.gui.gui.screen.container
import de.bixilon.kotlinglm.vec2.Vec2i
import de.bixilon.minosoft.data.container.types.CraftingContainer import de.bixilon.minosoft.data.container.types.CraftingContainer
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
import de.bixilon.minosoft.gui.rendering.gui.gui.screen.container.text.ContainerText
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions
import de.bixilon.minosoft.util.KUtil.toResourceLocation import de.bixilon.minosoft.util.KUtil.toResourceLocation
import kotlin.reflect.KClass import kotlin.reflect.KClass
class CraftingContainerScreen(guiRenderer: GUIRenderer, container: CraftingContainer) : BackgroundedContainerScreen<CraftingContainer>(guiRenderer, container, guiRenderer.atlasManager["minecraft:crafting_container".toResourceLocation()]) { class CraftingContainerScreen(guiRenderer: GUIRenderer, container: CraftingContainer) : LabeledContainerScreen<CraftingContainer>(guiRenderer, container, guiRenderer.atlasManager["minecraft:crafting_container".toResourceLocation()]) {
private val title = ContainerText.of(guiRenderer, atlasElement?.areas?.get("crafting_text"), container.title)
private val inventoryTitle = ContainerText.createInventoryTitle(guiRenderer, atlasElement?.areas?.get("inventory_text"))
override fun forceRender(offset: Vec2i, consumer: GUIVertexConsumer, options: GUIVertexOptions?) {
super.forceRender(offset, consumer, options)
val centerOffset = offset + (size - containerBackground.size) / 2
if (container.title != null) {
title?.render(centerOffset, consumer, options)
}
inventoryTitle?.render(centerOffset, consumer, options)
}
companion object : ContainerGUIFactory<CraftingContainerScreen, CraftingContainer> { companion object : ContainerGUIFactory<CraftingContainerScreen, CraftingContainer> {
override val clazz: KClass<CraftingContainer> = CraftingContainer::class override val clazz: KClass<CraftingContainer> = CraftingContainer::class

View File

@ -0,0 +1,43 @@
/*
* Minosoft
* Copyright (C) 2020-2022 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.container
import de.bixilon.kotlinglm.vec2.Vec2i
import de.bixilon.minosoft.data.container.Container
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
import de.bixilon.minosoft.gui.rendering.gui.atlas.AtlasElement
import de.bixilon.minosoft.gui.rendering.gui.atlas.AtlasSlot
import de.bixilon.minosoft.gui.rendering.gui.gui.screen.container.text.ContainerText
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
abstract class LabeledContainerScreen<C : Container>(
guiRenderer: GUIRenderer,
container: C,
atlasElement: AtlasElement?,
items: Int2ObjectOpenHashMap<AtlasSlot> = atlasElement?.slots ?: Int2ObjectOpenHashMap(),
) : BackgroundedContainerScreen<C>(guiRenderer, container, atlasElement, items) {
protected val titleText = ContainerText.of(guiRenderer, atlasElement?.areas?.get("title"), container.title)
protected val inventoryTitleText = ContainerText.createInventoryTitle(guiRenderer, atlasElement?.areas?.get("inventory_text"))
override fun forceRenderContainerScreen(offset: Vec2i, consumer: GUIVertexConsumer, options: GUIVertexOptions?) {
super.forceRenderContainerScreen(offset, consumer, options)
if (container.title != null) {
titleText?.render(offset, consumer, options)
}
inventoryTitleText?.render(offset, consumer, options)
}
}

View File

@ -16,10 +16,10 @@ package de.bixilon.minosoft.gui.rendering.gui.gui.screen.container.processing
import de.bixilon.minosoft.data.container.types.processing.ProcessingContainer import de.bixilon.minosoft.data.container.types.processing.ProcessingContainer
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
import de.bixilon.minosoft.gui.rendering.gui.atlas.AtlasElement import de.bixilon.minosoft.gui.rendering.gui.atlas.AtlasElement
import de.bixilon.minosoft.gui.rendering.gui.gui.screen.container.BackgroundedContainerScreen import de.bixilon.minosoft.gui.rendering.gui.gui.screen.container.LabeledContainerScreen
abstract class ProcessingContainerScreen<C : ProcessingContainer>( abstract class ProcessingContainerScreen<C : ProcessingContainer>(
guiRenderer: GUIRenderer, guiRenderer: GUIRenderer,
container: C, container: C,
atlasElement: AtlasElement?, atlasElement: AtlasElement?,
) : BackgroundedContainerScreen<C>(guiRenderer, container, atlasElement) ) : LabeledContainerScreen<C>(guiRenderer, container, atlasElement)

View File

@ -1315,7 +1315,7 @@
} }
}, },
"areas": { "areas": {
"crafting_text": { "title": {
"start": [29, 3], "start": [29, 3],
"end": [172, 16] "end": [172, 16]
}, },
@ -1540,6 +1540,14 @@
"process": { "process": {
"start": [79, 35], "start": [79, 35],
"end": [103, 50] "end": [103, 50]
},
"title": {
"start": [29, 3],
"end": [172, 16]
},
"inventory_text": {
"start": [3, 70],
"end": [172, 83]
} }
} }
} }