From 7170c3482b424252cd7060a5a19ff68c4748a36c Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 9 Mar 2021 18:35:57 -0500 Subject: [PATCH] Fix Terminal screen not setting focused element REI expects Screen.getFocused() to be non-null to skip its input handling --- .../phycon/block/terminal/TerminalScreen.kt | 15 +++++++++++++-- .../phycon/screen/console/DeviceConsoleScreen.kt | 10 ++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/net/shadowfacts/phycon/block/terminal/TerminalScreen.kt b/src/main/kotlin/net/shadowfacts/phycon/block/terminal/TerminalScreen.kt index 151b144..1428386 100644 --- a/src/main/kotlin/net/shadowfacts/phycon/block/terminal/TerminalScreen.kt +++ b/src/main/kotlin/net/shadowfacts/phycon/block/terminal/TerminalScreen.kt @@ -62,6 +62,7 @@ class TerminalScreen(handler: TerminalScreenHandler, playerInv: PlayerInventory, if (value && !oldValue) { amountBox.text = "1" } + updateFocusedElement() } private var dialogChildren = mutableListOf() @@ -162,9 +163,20 @@ class TerminalScreen(handler: TerminalScreenHandler, playerInv: PlayerInventory, } dialogChildren.add(request) + updateFocusedElement() requestUpdatedItems() } + private fun updateFocusedElement() { + focused = if (showingAmountDialog) { + amountBox + } else if (searchBox.isFocused) { + searchBox + } else { + null + } + } + private fun requestUpdatedItems() { val player = MinecraftClient.getInstance().player!! player.networkHandler.sendPacket(C2STerminalUpdateDisplayedItems(handler.terminal, searchBox.text, sortButton.mode, scrollPosition)) @@ -260,8 +272,7 @@ class TerminalScreen(handler: TerminalScreenHandler, playerInv: PlayerInventory, override fun onMouseClick(slot: Slot?, invSlot: Int, clickData: Int, type: SlotActionType?) { super.onMouseClick(slot, invSlot, clickData, type) - // don't unfocus the search box on mouse click - searchBox.setSelected(true) + updateFocusedElement() if (slot != null && !slot.stack.isEmpty && handler.isNetworkSlot(slot.id)) { val stack = slot.stack diff --git a/src/main/kotlin/net/shadowfacts/phycon/screen/console/DeviceConsoleScreen.kt b/src/main/kotlin/net/shadowfacts/phycon/screen/console/DeviceConsoleScreen.kt index 3a7c0c4..2b685f3 100644 --- a/src/main/kotlin/net/shadowfacts/phycon/screen/console/DeviceConsoleScreen.kt +++ b/src/main/kotlin/net/shadowfacts/phycon/screen/console/DeviceConsoleScreen.kt @@ -15,6 +15,7 @@ import net.shadowfacts.kiwidsl.dsl import net.shadowfacts.phycon.block.DeviceBlockEntity import net.shadowfacts.phycon.block.miner.MinerBlockEntity import net.shadowfacts.phycon.block.redstone_controller.RedstoneControllerBlockEntity +import net.shadowfacts.phycon.block.redstone_emitter.RedstoneEmitterBlockEntity import net.shadowfacts.phycon.component.ActivationController import net.shadowfacts.phycon.component.NetworkStackProvider import net.shadowfacts.phycon.component.NetworkStackReceiver @@ -80,6 +81,15 @@ class DeviceConsoleScreen( ReceiverViewController(device), )) } + if (device is RedstoneEmitterBlockEntity) { + tabs.add(TabViewController.SimpleTab( + TextureView(Texture(Identifier("textures/item/redstone.png"), 0, 0, 16, 16)).apply { + intrinsicContentSize = Size(16.0, 16.0) + }, + TranslatableText("block.phycon.redstone_emitter"), + RedstoneEmitterViewController(device) + )) + } tabController = TabViewController(tabs)