findSlot now actually searches for slot panel
This commit is contained in:
parent
b51c4780b8
commit
c0c0b01688
@ -169,7 +169,7 @@ dependencies {
|
|||||||
// implementation fg.deobf("com.tterrag.registrate:Registrate:MC${mc_version}-${registrate_version}") // Adds registrate as a dependency
|
// implementation fg.deobf("com.tterrag.registrate:Registrate:MC${mc_version}-${registrate_version}") // Adds registrate as a dependency
|
||||||
|
|
||||||
// Examples using mod jars from ./libs
|
// Examples using mod jars from ./libs
|
||||||
// implementation fg.deobf("blank:EnderRift-1.18.1:2.4.1")
|
// implementation(fg.deobf("blank:MouseTweaks-forge-mc1.19:2.23"))
|
||||||
|
|
||||||
// compile against the JEI API but do not include it at runtime
|
// compile against the JEI API but do not include it at runtime
|
||||||
//compileOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}:api")
|
//compileOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}:api")
|
||||||
|
@ -346,7 +346,22 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
|
|||||||
var returnSlot: Slot? = null
|
var returnSlot: Slot? = null
|
||||||
|
|
||||||
override fun findSlot(x: Double, y: Double): Slot? {
|
override fun findSlot(x: Double, y: Double): Slot? {
|
||||||
return returnSlot
|
if (returnSlot != null) {
|
||||||
|
return returnSlot
|
||||||
|
}
|
||||||
|
|
||||||
|
val xFloat = x.toFloat()
|
||||||
|
val yFloat = y.toFloat()
|
||||||
|
|
||||||
|
for (panel in panels) {
|
||||||
|
val (status, slot) = panel.findSlot(xFloat, yFloat)
|
||||||
|
|
||||||
|
if (status) {
|
||||||
|
return slot
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun render(poseStack: PoseStack, mouseX: Int, mouseY: Int, partialTick: Float) {
|
override fun render(poseStack: PoseStack, mouseX: Int, mouseY: Int, partialTick: Float) {
|
||||||
|
@ -7,6 +7,7 @@ import net.minecraft.client.Minecraft
|
|||||||
import net.minecraft.client.gui.Font
|
import net.minecraft.client.gui.Font
|
||||||
import net.minecraft.client.gui.components.events.GuiEventListener
|
import net.minecraft.client.gui.components.events.GuiEventListener
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
|
import net.minecraft.world.inventory.Slot
|
||||||
import org.apache.logging.log4j.LogManager
|
import org.apache.logging.log4j.LogManager
|
||||||
import ru.dbotthepony.mc.otm.client.render.popScissorRect
|
import ru.dbotthepony.mc.otm.client.render.popScissorRect
|
||||||
import ru.dbotthepony.mc.otm.client.render.pushScissorRect
|
import ru.dbotthepony.mc.otm.client.render.pushScissorRect
|
||||||
@ -35,6 +36,10 @@ enum class DockResizeMode(val changeWidth: Boolean, val changeHeight: Boolean) {
|
|||||||
ALL(true, true), NONE(false, false), WIDTH(true, false), HEIGHT(false, true)
|
ALL(true, true), NONE(false, false), WIDTH(true, false), HEIGHT(false, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ISlotPanel<S : Slot> {
|
||||||
|
val slot: S
|
||||||
|
}
|
||||||
|
|
||||||
open class EditablePanel @JvmOverloads constructor(
|
open class EditablePanel @JvmOverloads constructor(
|
||||||
val screen: MatteryScreen<*>,
|
val screen: MatteryScreen<*>,
|
||||||
parent: EditablePanel?,
|
parent: EditablePanel?,
|
||||||
@ -433,33 +438,69 @@ open class EditablePanel @JvmOverloads constructor(
|
|||||||
return depth
|
return depth
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun tickHover(mouse_x: Float, mouse_y: Float): Boolean {
|
open fun tickHover(mouseX: Float, mouseY: Float): Boolean {
|
||||||
if ((boundingHeight > height || boundingWidth > width || boundingX < 0 || boundingY < 0) && parent == null) {
|
if ((boundingHeight > height || boundingWidth > width || boundingX < 0 || boundingY < 0) && parent == null) {
|
||||||
var hit = false
|
var hit = false
|
||||||
|
|
||||||
for (child in children) {
|
for (child in children) {
|
||||||
if (child.tickHover(mouse_x, mouse_y)) {
|
if (child.tickHover(mouseX, mouseY)) {
|
||||||
hit = true
|
hit = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isHovered = mouse_x >= absoluteX &&
|
isHovered = mouseX >= absoluteX &&
|
||||||
mouse_x <= absoluteX + width &&
|
mouseX <= absoluteX + width &&
|
||||||
mouse_y >= absoluteY &&
|
mouseY >= absoluteY &&
|
||||||
mouse_y <= absoluteY + height
|
mouseY <= absoluteY + height
|
||||||
|
|
||||||
return hit
|
return hit
|
||||||
}
|
}
|
||||||
|
|
||||||
isHovered =
|
isHovered =
|
||||||
mouse_x >= absoluteX &&
|
mouseX >= absoluteX &&
|
||||||
mouse_x <= absoluteX + width &&
|
mouseX <= absoluteX + width &&
|
||||||
mouse_y >= absoluteY &&
|
mouseY >= absoluteY &&
|
||||||
mouse_y <= absoluteY + height
|
mouseY <= absoluteY + height
|
||||||
|
|
||||||
return isHovered
|
return isHovered
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun findSlot(mouseX: Float, mouseY: Float): Pair<Boolean, Slot?> {
|
||||||
|
if (!acceptMouseInput) {
|
||||||
|
return (mouseX >= absoluteX &&
|
||||||
|
mouseX <= absoluteX + width &&
|
||||||
|
mouseY >= absoluteY &&
|
||||||
|
mouseY <= absoluteY + height) to null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trapMouseInput && this is ISlotPanel<*>) {
|
||||||
|
return true to this.slot
|
||||||
|
}
|
||||||
|
|
||||||
|
for (child in children) {
|
||||||
|
val (status, slot) = child.findSlot(mouseX, mouseY)
|
||||||
|
|
||||||
|
if (status) {
|
||||||
|
return true to slot
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
mouseX >= absoluteX &&
|
||||||
|
mouseX <= absoluteX + width &&
|
||||||
|
mouseY >= absoluteY &&
|
||||||
|
mouseY <= absoluteY + height
|
||||||
|
) {
|
||||||
|
if (this is ISlotPanel<*>) {
|
||||||
|
return true to this.slot
|
||||||
|
}
|
||||||
|
|
||||||
|
return true to null
|
||||||
|
}
|
||||||
|
|
||||||
|
return false to null
|
||||||
|
}
|
||||||
|
|
||||||
fun renderTooltips(stack: PoseStack, mouse_x: Float, mouse_y: Float, flag: Float): Boolean {
|
fun renderTooltips(stack: PoseStack, mouse_x: Float, mouse_y: Float, flag: Float): Boolean {
|
||||||
if (!isVisible()) {
|
if (!isVisible()) {
|
||||||
return false
|
return false
|
||||||
|
@ -21,13 +21,13 @@ import javax.annotation.Nonnull
|
|||||||
open class SlotPanel<T : Slot>(
|
open class SlotPanel<T : Slot>(
|
||||||
screen: MatteryScreen<*>,
|
screen: MatteryScreen<*>,
|
||||||
parent: EditablePanel?,
|
parent: EditablePanel?,
|
||||||
val slot: T,
|
final override val slot: T,
|
||||||
x: Float = 0f,
|
x: Float = 0f,
|
||||||
y: Float = 0f,
|
y: Float = 0f,
|
||||||
width: Float = AbstractSlotPanel.SIZE,
|
width: Float = AbstractSlotPanel.SIZE,
|
||||||
height: Float = AbstractSlotPanel.SIZE,
|
height: Float = AbstractSlotPanel.SIZE,
|
||||||
noItemIcon: SkinElement? = null
|
noItemIcon: SkinElement? = null
|
||||||
) : AbstractSlotPanel(screen, parent, x, y, width, height, noItemIcon) {
|
) : AbstractSlotPanel(screen, parent, x, y, width, height, noItemIcon), ISlotPanel<T> {
|
||||||
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
||||||
screen.returnSlot = slot
|
screen.returnSlot = slot
|
||||||
return true
|
return true
|
||||||
|
Loading…
Reference in New Issue
Block a user