From 38b8f8e64a20ff7b6a868d8f54e4631030270bcb Mon Sep 17 00:00:00 2001 From: Bixilon Date: Tue, 3 May 2022 19:37:16 +0200 Subject: [PATCH] furnace: show container title --- .../container/CraftingContainerScreen.kt | 17 +------- .../container/LabeledContainerScreen.kt | 43 +++++++++++++++++++ .../processing/ProcessingContainerScreen.kt | 4 +- .../assets/minosoft/mapping/atlas.json | 10 ++++- 4 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/container/LabeledContainerScreen.kt diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/container/CraftingContainerScreen.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/container/CraftingContainerScreen.kt index 30d61aa9a..f62961e0d 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/container/CraftingContainerScreen.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/container/CraftingContainerScreen.kt @@ -13,29 +13,14 @@ 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.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 kotlin.reflect.KClass -class CraftingContainerScreen(guiRenderer: GUIRenderer, container: CraftingContainer) : BackgroundedContainerScreen(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")) +class CraftingContainerScreen(guiRenderer: GUIRenderer, container: CraftingContainer) : LabeledContainerScreen(guiRenderer, container, guiRenderer.atlasManager["minecraft:crafting_container".toResourceLocation()]) { - 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 { override val clazz: KClass = CraftingContainer::class diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/container/LabeledContainerScreen.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/container/LabeledContainerScreen.kt new file mode 100644 index 000000000..3439abf5f --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/container/LabeledContainerScreen.kt @@ -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 . + * + * 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( + guiRenderer: GUIRenderer, + container: C, + atlasElement: AtlasElement?, + items: Int2ObjectOpenHashMap = atlasElement?.slots ?: Int2ObjectOpenHashMap(), +) : BackgroundedContainerScreen(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) + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/container/processing/ProcessingContainerScreen.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/container/processing/ProcessingContainerScreen.kt index 4a31e6920..f21b5528a 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/container/processing/ProcessingContainerScreen.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/container/processing/ProcessingContainerScreen.kt @@ -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.gui.rendering.gui.GUIRenderer 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( guiRenderer: GUIRenderer, container: C, atlasElement: AtlasElement?, -) : BackgroundedContainerScreen(guiRenderer, container, atlasElement) +) : LabeledContainerScreen(guiRenderer, container, atlasElement) diff --git a/src/main/resources/assets/minosoft/mapping/atlas.json b/src/main/resources/assets/minosoft/mapping/atlas.json index 5fdd286ce..2c70431bd 100644 --- a/src/main/resources/assets/minosoft/mapping/atlas.json +++ b/src/main/resources/assets/minosoft/mapping/atlas.json @@ -1315,7 +1315,7 @@ } }, "areas": { - "crafting_text": { + "title": { "start": [29, 3], "end": [172, 16] }, @@ -1540,6 +1540,14 @@ "process": { "start": [79, 35], "end": [103, 50] + }, + "title": { + "start": [29, 3], + "end": [172, 16] + }, + "inventory_text": { + "start": [3, 70], + "end": [172, 83] } } }