From 590cfe4f2a39eec6282b19528e71f48d1c648955 Mon Sep 17 00:00:00 2001 From: xtex Date: Tue, 25 Jul 2023 11:46:08 +0800 Subject: [PATCH] feat: hint when no options available --- .../quaedam/shell/ProjectionShellScreen.kt | 36 ++++++++++++------- .../resources/assets/quaedam/lang/en_us.json | 2 ++ .../resources/assets/quaedam/lang/zh_cn.json | 2 ++ 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/common/src/main/kotlin/quaedam/shell/ProjectionShellScreen.kt b/common/src/main/kotlin/quaedam/shell/ProjectionShellScreen.kt index d495a9d..7a24a5c 100644 --- a/common/src/main/kotlin/quaedam/shell/ProjectionShellScreen.kt +++ b/common/src/main/kotlin/quaedam/shell/ProjectionShellScreen.kt @@ -24,19 +24,27 @@ class ProjectionShellScreen(val level: Level, val pos: BlockPos, val shell: Proj super.init() layout = GridLayout() layout.spacing(4) - val rows = layout.createRowHelper(2) val renderContext = ShellRenderContext(this) - shell.rows.forEach { - rows.addChild(StringWidget(150, 20, it.text, font)) - rows.addChild(it.renderer(renderContext)) - } - run { // Buttons - rows.addChild(StringWidget(Component.empty(), font)) - rows.addChild(Button.builder(Component.translatable("quaedam.screen.projection_shell.save")) { - val block = level.getBlockState(pos).block - if (block is ProjectionShellBlock) { - block.applyFromShell(level, pos, shell) - } + if (shell.rows.isNotEmpty()) { + val rows = layout.createRowHelper(2) + shell.rows.forEach { + rows.addChild(StringWidget(150, 20, it.text, font)) + rows.addChild(it.renderer(renderContext)) + } + run { // Buttons + rows.addChild(StringWidget(Component.empty(), font)) + rows.addChild(Button.builder(Component.translatable("quaedam.screen.projection_shell.save")) { + val block = level.getBlockState(pos).block + if (block is ProjectionShellBlock) { + block.applyFromShell(level, pos, shell) + } + GameInstance.getClient().setScreen(null) + }.build().apply(::setInitialFocus)) + } + } else { + val rows = layout.createRowHelper(1) + rows.addChild(StringWidget(Component.translatable("quaedam.screen.projection_shell.empty"), font)) + rows.addChild(Button.builder(Component.translatable("quaedam.screen.projection_shell.close")) { GameInstance.getClient().setScreen(null) }.build().apply(::setInitialFocus)) } @@ -44,6 +52,10 @@ class ProjectionShellScreen(val level: Level, val pos: BlockPos, val shell: Proj layout.x = (width - layout.width) / 2 layout.y = (height - layout.height) / 2 layout.visitWidgets(::addRenderableWidget) + addRenderableOnly(StringWidget(level.getBlockState(pos).block.name, font).apply { + x = (this@ProjectionShellScreen.width - width) / 2 + y = layout.y - 2 * BORDER - font.lineHeight + }) } fun getFont() = font diff --git a/common/src/main/resources/assets/quaedam/lang/en_us.json b/common/src/main/resources/assets/quaedam/lang/en_us.json index 36ae2c1..087cb41 100644 --- a/common/src/main/resources/assets/quaedam/lang/en_us.json +++ b/common/src/main/resources/assets/quaedam/lang/en_us.json @@ -11,6 +11,8 @@ "quaedam.screen.projection_shell.lock_revoked": "Timeout! Connection Lost", "quaedam.screen.projection_shell.lock_failed": "Permission denied!", "quaedam.screen.projection_shell.save": "Save", + "quaedam.screen.projection_shell.empty": "No Options Available!", + "quaedam.screen.projection_shell.close": "Close", "quaedam.shell.skylight.factor": "Factor", "quaedam.shell.noise.amount": "Amount", "quaedam.shell.swarm.max_count": "Max Count" diff --git a/common/src/main/resources/assets/quaedam/lang/zh_cn.json b/common/src/main/resources/assets/quaedam/lang/zh_cn.json index a081c3b..c491595 100644 --- a/common/src/main/resources/assets/quaedam/lang/zh_cn.json +++ b/common/src/main/resources/assets/quaedam/lang/zh_cn.json @@ -11,6 +11,8 @@ "quaedam.screen.projection_shell.lock_revoked": "超时!连接丢失", "quaedam.screen.projection_shell.lock_failed": "正被使用", "quaedam.screen.projection_shell.save": "保存", + "quaedam.screen.projection_shell.empty": "无可用选项!", + "quaedam.screen.projection_shell.close": "关闭", "quaedam.shell.skylight.factor": "因子", "quaedam.shell.noise.amount": "数量", "quaedam.shell.swarm.max_count": "最大数量"