Fix Terminal screen not setting focused element

REI expects Screen.getFocused() to be non-null to skip its input
handling
This commit is contained in:
Shadowfacts 2021-03-09 18:35:57 -05:00
parent cd6299b876
commit 7170c3482b
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 23 additions and 2 deletions

View File

@ -62,6 +62,7 @@ class TerminalScreen(handler: TerminalScreenHandler, playerInv: PlayerInventory,
if (value && !oldValue) {
amountBox.text = "1"
}
updateFocusedElement()
}
private var dialogChildren = mutableListOf<AbstractButtonWidget>()
@ -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

View File

@ -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)