From 680d4d76e11a1d211ee72002c4785099bdd49f11 Mon Sep 17 00:00:00 2001 From: xtex Date: Mon, 24 Jul 2023 11:25:24 +0800 Subject: [PATCH] fix: shell screen layout --- .../quaedam/shell/ProjectionShellScreen.kt | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/common/src/main/kotlin/quaedam/shell/ProjectionShellScreen.kt b/common/src/main/kotlin/quaedam/shell/ProjectionShellScreen.kt index e52edb5..4db2a7c 100644 --- a/common/src/main/kotlin/quaedam/shell/ProjectionShellScreen.kt +++ b/common/src/main/kotlin/quaedam/shell/ProjectionShellScreen.kt @@ -1,11 +1,11 @@ package quaedam.shell +import dev.architectury.utils.GameInstance import net.minecraft.client.gui.GuiGraphics import net.minecraft.client.gui.components.Button import net.minecraft.client.gui.components.StringWidget import net.minecraft.client.gui.layouts.GridLayout import net.minecraft.client.gui.screens.Screen -import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen import net.minecraft.core.BlockPos import net.minecraft.network.chat.Component import net.minecraft.world.level.Level @@ -14,10 +14,15 @@ import quaedam.shell.network.ServerboundPSHLockReleasePacket class ProjectionShellScreen(val level: Level, val pos: BlockPos, val shell: ProjectionEffectShell) : Screen(Component.translatable("quaedam.screen.projection_shell")) { - val layout = GridLayout() + companion object { + const val BORDER = 15 + } + + var layout = GridLayout() override fun init() { super.init() + layout = GridLayout() layout.spacing(4) val rows = layout.createRowHelper(2) val renderContext = ShellRenderContext(this) @@ -32,17 +37,31 @@ class ProjectionShellScreen(val level: Level, val pos: BlockPos, val shell: Proj if (block is ProjectionShellBlock) { block.applyFromShell(level, pos, shell) } + GameInstance.getClient().setScreen(null) }.build()) } layout.arrangeElements() + layout.x = (width - layout.width) / 2 + layout.y = (height - layout.height) / 2 layout.visitWidgets(::addRenderableWidget) } fun getFont() = font + override fun render(guiGraphics: GuiGraphics, mouseX: Int, mouseY: Int, partialTick: Float) { + renderBackground(guiGraphics) + super.render(guiGraphics, mouseX, mouseY, partialTick) + } + override fun renderBackground(guiGraphics: GuiGraphics) { super.renderBackground(guiGraphics) - guiGraphics.blit(AbstractContainerScreen.INVENTORY_LOCATION, width / 2, height / 2, 0, 0, 176, 166) + guiGraphics.fill( + layout.x - BORDER, + layout.y - BORDER, + layout.x + layout.width + BORDER, + layout.y + layout.height + BORDER, + 0x11c6c6c6 + ) } override fun removed() {