feat: hint when no options available

This commit is contained in:
xtex 2023-07-25 11:46:08 +08:00
parent 33e206f9fe
commit 590cfe4f2a
Signed by: xtex
GPG Key ID: B918086ED8045B91
3 changed files with 28 additions and 12 deletions

View File

@ -24,19 +24,27 @@ class ProjectionShellScreen(val level: Level, val pos: BlockPos, val shell: Proj
super.init() super.init()
layout = GridLayout() layout = GridLayout()
layout.spacing(4) layout.spacing(4)
val rows = layout.createRowHelper(2)
val renderContext = ShellRenderContext(this) val renderContext = ShellRenderContext(this)
shell.rows.forEach { if (shell.rows.isNotEmpty()) {
rows.addChild(StringWidget(150, 20, it.text, font)) val rows = layout.createRowHelper(2)
rows.addChild(it.renderer(renderContext)) shell.rows.forEach {
} rows.addChild(StringWidget(150, 20, it.text, font))
run { // Buttons rows.addChild(it.renderer(renderContext))
rows.addChild(StringWidget(Component.empty(), font)) }
rows.addChild(Button.builder(Component.translatable("quaedam.screen.projection_shell.save")) { run { // Buttons
val block = level.getBlockState(pos).block rows.addChild(StringWidget(Component.empty(), font))
if (block is ProjectionShellBlock) { rows.addChild(Button.builder(Component.translatable("quaedam.screen.projection_shell.save")) {
block.applyFromShell(level, pos, shell) 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) GameInstance.getClient().setScreen(null)
}.build().apply(::setInitialFocus)) }.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.x = (width - layout.width) / 2
layout.y = (height - layout.height) / 2 layout.y = (height - layout.height) / 2
layout.visitWidgets(::addRenderableWidget) 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 fun getFont() = font

View File

@ -11,6 +11,8 @@
"quaedam.screen.projection_shell.lock_revoked": "Timeout! Connection Lost", "quaedam.screen.projection_shell.lock_revoked": "Timeout! Connection Lost",
"quaedam.screen.projection_shell.lock_failed": "Permission denied!", "quaedam.screen.projection_shell.lock_failed": "Permission denied!",
"quaedam.screen.projection_shell.save": "Save", "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.skylight.factor": "Factor",
"quaedam.shell.noise.amount": "Amount", "quaedam.shell.noise.amount": "Amount",
"quaedam.shell.swarm.max_count": "Max Count" "quaedam.shell.swarm.max_count": "Max Count"

View File

@ -11,6 +11,8 @@
"quaedam.screen.projection_shell.lock_revoked": "超时!连接丢失", "quaedam.screen.projection_shell.lock_revoked": "超时!连接丢失",
"quaedam.screen.projection_shell.lock_failed": "正被使用", "quaedam.screen.projection_shell.lock_failed": "正被使用",
"quaedam.screen.projection_shell.save": "保存", "quaedam.screen.projection_shell.save": "保存",
"quaedam.screen.projection_shell.empty": "无可用选项!",
"quaedam.screen.projection_shell.close": "关闭",
"quaedam.shell.skylight.factor": "因子", "quaedam.shell.skylight.factor": "因子",
"quaedam.shell.noise.amount": "数量", "quaedam.shell.noise.amount": "数量",
"quaedam.shell.swarm.max_count": "最大数量" "quaedam.shell.swarm.max_count": "最大数量"