Fix REI not receiving keyboard shortcuts while focused
This commit is contained in:
parent
2466923d96
commit
93b082ee55
|
@ -3,7 +3,9 @@ package net.shadowfacts.phycon.plugin.rei
|
|||
import me.shedaniel.math.Rectangle
|
||||
import me.shedaniel.rei.api.BaseBoundsHandler
|
||||
import me.shedaniel.rei.api.DisplayHelper
|
||||
import me.shedaniel.rei.api.REIHelper
|
||||
import me.shedaniel.rei.api.plugins.REIPluginV0
|
||||
import net.fabricmc.api.ClientModInitializer
|
||||
import net.minecraft.client.MinecraftClient
|
||||
import net.minecraft.util.Identifier
|
||||
import net.shadowfacts.phycon.block.terminal.TerminalScreen
|
||||
|
@ -11,9 +13,22 @@ import net.shadowfacts.phycon.block.terminal.TerminalScreen
|
|||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
object PhyConPlugin: REIPluginV0 {
|
||||
object PhyConPlugin: ClientModInitializer, REIPluginV0 {
|
||||
const val MODID = "phycon_rei"
|
||||
|
||||
override fun onInitializeClient() {
|
||||
TerminalScreen.registerClickHandler { mouseX, mouseY, button ->
|
||||
REIHelper.getInstance().searchTextField?.also {
|
||||
if (it.bounds.contains(mouseX, mouseY)) {
|
||||
this.terminalVC.searchField.resignFirstResponder()
|
||||
} else {
|
||||
this.terminalVC.searchField.becomeFirstResponder()
|
||||
}
|
||||
}
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
override fun getPluginIdentifier() = Identifier(MODID, "rei_plugin")
|
||||
|
||||
override fun registerBounds(helper: DisplayHelper) {
|
||||
|
|
|
@ -14,6 +14,12 @@
|
|||
"license": "LGPL-3.0",
|
||||
"environment": "client",
|
||||
"entrypoints": {
|
||||
"client": [
|
||||
{
|
||||
"adapter": "kotlin",
|
||||
"value": "net.shadowfacts.phycon.plugin.rei.PhyConPlugin"
|
||||
}
|
||||
],
|
||||
"rei_plugins": [
|
||||
{
|
||||
"adapter": "kotlin",
|
||||
|
|
|
@ -24,6 +24,7 @@ import net.shadowfacts.phycon.networking.C2STerminalUpdateDisplayedItems
|
|||
import net.shadowfacts.phycon.util.SortMode
|
||||
import java.math.RoundingMode
|
||||
import java.text.DecimalFormat
|
||||
import java.util.LinkedList
|
||||
import kotlin.math.ceil
|
||||
import kotlin.math.min
|
||||
|
||||
|
@ -34,6 +35,12 @@ class TerminalScreen(handler: TerminalScreenHandler, playerInv: PlayerInventory,
|
|||
|
||||
companion object {
|
||||
private val BACKGROUND = Identifier(PhysicalConnectivity.MODID, "textures/gui/terminal.png")
|
||||
|
||||
private val clickHandlers = LinkedList<TerminalScreen.(Double, Double, Int) -> Boolean?>()
|
||||
|
||||
fun registerClickHandler(handler: TerminalScreen.(Double, Double, Int) -> Boolean?) {
|
||||
clickHandlers.add(handler)
|
||||
}
|
||||
}
|
||||
|
||||
val backgroundWidth: Int
|
||||
|
@ -145,6 +152,17 @@ class TerminalScreen(handler: TerminalScreenHandler, playerInv: PlayerInventory,
|
|||
}
|
||||
}
|
||||
|
||||
override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
|
||||
for (handler in clickHandlers) {
|
||||
val res = handler(mouseX, mouseY, button)
|
||||
if (res != null) {
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
return super.mouseClicked(mouseX, mouseY, button)
|
||||
}
|
||||
|
||||
override fun onMouseClick(slot: Slot?, invSlot: Int, clickData: Int, type: SlotActionType?) {
|
||||
super.onMouseClick(slot, invSlot, clickData, type)
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import net.minecraft.text.TranslatableText
|
|||
import net.minecraft.util.math.MathHelper
|
||||
import net.shadowfacts.cacao.geometry.Point
|
||||
import net.shadowfacts.cacao.util.Color
|
||||
import net.shadowfacts.cacao.util.MouseButton
|
||||
import net.shadowfacts.cacao.view.Label
|
||||
import net.shadowfacts.cacao.view.View
|
||||
import net.shadowfacts.cacao.view.textfield.TextField
|
||||
|
@ -136,7 +137,7 @@ class TerminalViewController(
|
|||
}
|
||||
|
||||
class TerminalSearchField: TextField("") {
|
||||
override fun resignFirstResponder() {
|
||||
override fun mouseClickedOutside(point: Point, mouseButton: MouseButton) {
|
||||
// no-op
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue