Fix REI not receiving keyboard shortcuts while focused

This commit is contained in:
Shadowfacts 2021-03-22 17:50:48 -04:00
parent 2466923d96
commit 93b082ee55
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
4 changed files with 42 additions and 2 deletions

View File

@ -3,7 +3,9 @@ package net.shadowfacts.phycon.plugin.rei
import me.shedaniel.math.Rectangle import me.shedaniel.math.Rectangle
import me.shedaniel.rei.api.BaseBoundsHandler import me.shedaniel.rei.api.BaseBoundsHandler
import me.shedaniel.rei.api.DisplayHelper import me.shedaniel.rei.api.DisplayHelper
import me.shedaniel.rei.api.REIHelper
import me.shedaniel.rei.api.plugins.REIPluginV0 import me.shedaniel.rei.api.plugins.REIPluginV0
import net.fabricmc.api.ClientModInitializer
import net.minecraft.client.MinecraftClient import net.minecraft.client.MinecraftClient
import net.minecraft.util.Identifier import net.minecraft.util.Identifier
import net.shadowfacts.phycon.block.terminal.TerminalScreen import net.shadowfacts.phycon.block.terminal.TerminalScreen
@ -11,9 +13,22 @@ import net.shadowfacts.phycon.block.terminal.TerminalScreen
/** /**
* @author shadowfacts * @author shadowfacts
*/ */
object PhyConPlugin: REIPluginV0 { object PhyConPlugin: ClientModInitializer, REIPluginV0 {
const val MODID = "phycon_rei" 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 getPluginIdentifier() = Identifier(MODID, "rei_plugin")
override fun registerBounds(helper: DisplayHelper) { override fun registerBounds(helper: DisplayHelper) {

View File

@ -14,6 +14,12 @@
"license": "LGPL-3.0", "license": "LGPL-3.0",
"environment": "client", "environment": "client",
"entrypoints": { "entrypoints": {
"client": [
{
"adapter": "kotlin",
"value": "net.shadowfacts.phycon.plugin.rei.PhyConPlugin"
}
],
"rei_plugins": [ "rei_plugins": [
{ {
"adapter": "kotlin", "adapter": "kotlin",

View File

@ -24,6 +24,7 @@ import net.shadowfacts.phycon.networking.C2STerminalUpdateDisplayedItems
import net.shadowfacts.phycon.util.SortMode import net.shadowfacts.phycon.util.SortMode
import java.math.RoundingMode import java.math.RoundingMode
import java.text.DecimalFormat import java.text.DecimalFormat
import java.util.LinkedList
import kotlin.math.ceil import kotlin.math.ceil
import kotlin.math.min import kotlin.math.min
@ -34,6 +35,12 @@ class TerminalScreen(handler: TerminalScreenHandler, playerInv: PlayerInventory,
companion object { companion object {
private val BACKGROUND = Identifier(PhysicalConnectivity.MODID, "textures/gui/terminal.png") 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 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?) { override fun onMouseClick(slot: Slot?, invSlot: Int, clickData: Int, type: SlotActionType?) {
super.onMouseClick(slot, invSlot, clickData, type) super.onMouseClick(slot, invSlot, clickData, type)

View File

@ -4,6 +4,7 @@ import net.minecraft.text.TranslatableText
import net.minecraft.util.math.MathHelper import net.minecraft.util.math.MathHelper
import net.shadowfacts.cacao.geometry.Point import net.shadowfacts.cacao.geometry.Point
import net.shadowfacts.cacao.util.Color import net.shadowfacts.cacao.util.Color
import net.shadowfacts.cacao.util.MouseButton
import net.shadowfacts.cacao.view.Label import net.shadowfacts.cacao.view.Label
import net.shadowfacts.cacao.view.View import net.shadowfacts.cacao.view.View
import net.shadowfacts.cacao.view.textfield.TextField import net.shadowfacts.cacao.view.textfield.TextField
@ -136,7 +137,7 @@ class TerminalViewController(
} }
class TerminalSearchField: TextField("") { class TerminalSearchField: TextField("") {
override fun resignFirstResponder() { override fun mouseClickedOutside(point: Point, mouseButton: MouseButton) {
// no-op // no-op
} }
} }