diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt index 6f594b346..ca6e91217 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt @@ -50,6 +50,7 @@ private fun misc(provider: MatteryLanguageProvider) { gui("exosuit", "Exosuit Inventory") gui("exosuit.go_back", "Open vanilla inventory") + gui("exosuit.go_in", "Open ExoSuit inventory") gui("exosuit.probe1", "This little device feels unnatural to touch, it is almost certainly resilient to any possible attempt to break it open.") gui("exosuit.probe2", "There is fingerprint reader built into one of sides which gently glow when touched.") diff --git a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java index 9b3eb9588..932ee25c0 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java +++ b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java @@ -6,7 +6,6 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.common.Mod; @@ -149,6 +148,7 @@ public final class OverdriveThatMatters { EVENT_BUS.addListener(EventPriority.NORMAL, ClientEventHandler.INSTANCE::inputEvent); EVENT_BUS.addListener(EventPriority.NORMAL, ClientEventHandler.INSTANCE::screenOpen); + EVENT_BUS.addListener(EventPriority.NORMAL, ClientEventHandler.INSTANCE::postScreenInit); if (ModList.get().isLoaded("mekanism")) { EVENT_BUS.addListener(EventPriority.NORMAL, TooltipsKt::tooltipEvent); diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/ClientEventHandler.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/ClientEventHandler.kt index efc13f91b..f078f3ddb 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/ClientEventHandler.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/ClientEventHandler.kt @@ -1,10 +1,15 @@ package ru.dbotthepony.mc.otm.client +import com.mojang.blaze3d.platform.InputConstants import net.minecraft.client.gui.screens.inventory.InventoryScreen import net.minecraftforge.client.event.MovementInputUpdateEvent import net.minecraftforge.client.event.ScreenEvent import ru.dbotthepony.mc.otm.capability.matteryPlayer +import ru.dbotthepony.mc.otm.client.render.Widgets18 import ru.dbotthepony.mc.otm.client.screen.ExoSuitInventoryScreen +import ru.dbotthepony.mc.otm.client.screen.panels.LargeSquareButtonPanel +import ru.dbotthepony.mc.otm.client.screen.panels.Panel2Widget +import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.registry.AndroidFeatures object ClientEventHandler { @@ -41,6 +46,27 @@ object ClientEventHandler { var ignoreInventoryOpen = false + fun postScreenInit(event: ScreenEvent.Init.Post) { + val player = minecraft.player?.matteryPlayer ?: return + + val screen = event.screen as? InventoryScreen ?: return + + if (player.hasExoSuit) { + event.addListener(Panel2Widget(LargeSquareButtonPanel(event.screen as InventoryScreen, null, + x = screen.guiLeft + screen.xSize + 2f, + y = screen.guiTop.toFloat(), + skinElement = Widgets18.RETURN_ARROW_LEFT, onPress = { + val mouseX = minecraft.mouseHandler.xpos() + val mouseY = minecraft.mouseHandler.ypos() + + event.screen.onClose() + minecraft.setScreen(ExoSuitInventoryScreen(player.exoSuitMenu)) + + InputConstants.grabOrReleaseMouse(minecraft.window.window, 212993, mouseX, mouseY) + }).also { it.tooltip = TranslatableComponent("otm.gui.exosuit.go_in") })) + } + } + fun screenOpen(event: ScreenEvent.Opening) { if (ignoreInventoryOpen || minecraft.player?.isCreative == true) { return diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ExoSuitInventoryScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ExoSuitInventoryScreen.kt index f3cda1b92..418faf689 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ExoSuitInventoryScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ExoSuitInventoryScreen.kt @@ -15,7 +15,7 @@ import yalter.mousetweaks.api.MouseTweaksDisableWheelTweak @MouseTweaksDisableWheelTweak class ExoSuitInventoryScreen(menu: ExoSuitInventoryMenu) : MatteryScreen(menu, TranslatableComponent("otm.gui.exosuit")) { - override fun makeMainFrame(): FramePanel> { + override fun makeMainFrame(): FramePanel> { val frame = FramePanel(this, width = 200f, height = 180f, title = this.title) val toolbeltLine = EditablePanel(this, frame, height = 18f) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt index 0db847885..8b0568af3 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt @@ -7,7 +7,6 @@ import net.minecraft.client.Minecraft import net.minecraft.client.gui.Font import net.minecraft.client.gui.components.events.GuiEventListener import net.minecraft.client.gui.screens.Screen -import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen import net.minecraft.network.chat.Component import net.minecraft.world.inventory.Slot import org.apache.logging.log4j.LogManager @@ -503,18 +502,18 @@ open class EditablePanel @JvmOverloads constructor( return false to null } - fun renderTooltips(stack: PoseStack, mouse_x: Float, mouse_y: Float, flag: Float): Boolean { + fun renderTooltips(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float): Boolean { if (!isVisible()) { return false } for (child in children) { - if (child.isVisible() && child.renderTooltips(stack, mouse_x, mouse_y, flag)) { + if (child.isVisible() && child.renderTooltips(stack, mouseX, mouseY, partialTick)) { return true } } - if (innerRenderTooltips(stack, mouse_x, mouse_y, flag)) { + if (innerRenderTooltips(stack, mouseX, mouseY, partialTick)) { return true } @@ -526,8 +525,8 @@ open class EditablePanel @JvmOverloads constructor( screen.renderComponentTooltip( stack, listOf(tooltip), - mouse_x.toInt(), - mouse_y.toInt(), + mouseX.toInt(), + mouseY.toInt(), font ) @@ -536,8 +535,8 @@ open class EditablePanel @JvmOverloads constructor( screen.renderComponentTooltip( stack, tooltipList, - mouse_x.toInt(), - mouse_y.toInt(), + mouseX.toInt(), + mouseY.toInt(), font ) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/Panel2Widget.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/Panel2Widget.kt new file mode 100644 index 000000000..235e271ed --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/Panel2Widget.kt @@ -0,0 +1,71 @@ +package ru.dbotthepony.mc.otm.client.screen.panels + +import com.mojang.blaze3d.vertex.PoseStack +import net.minecraft.client.gui.components.Widget +import net.minecraft.client.gui.components.events.GuiEventListener +import net.minecraft.client.gui.screens.Screen + +class Panel2Widget>( + val panel: P +) : GuiEventListener, Widget { + init { + require(panel.parent == null) { "Widget wrapped panels can't have a parent ($panel has parent ${panel.parent})" } + } + + override fun render(poseStack: PoseStack, mouseX: Int, mouseY: Int, partialTick: Float) { + panel.tick() + + val xFloat = mouseX.toFloat() + val yFloat = mouseY.toFloat() + + panel.tickHover(xFloat, yFloat) + panel.render(poseStack, xFloat, yFloat, partialTick) + panel.renderTooltips(poseStack, xFloat, yFloat, partialTick) + } + + override fun mouseMoved(mouseX: Double, mouseY: Double) { + panel.mouseMoved(mouseX, mouseY) + } + + override fun mouseClicked(p_94737_: Double, p_94738_: Double, p_94739_: Int): Boolean { + return panel.mouseClickedChecked(p_94737_, p_94738_, p_94739_) + } + + override fun mouseReleased(p_94753_: Double, p_94754_: Double, p_94755_: Int): Boolean { + return panel.mouseReleasedChecked(p_94753_, p_94754_, p_94755_) + } + + override fun mouseDragged( + p_94740_: Double, + p_94741_: Double, + p_94742_: Int, + p_94743_: Double, + p_94744_: Double + ): Boolean { + return panel.mouseDraggedChecked(p_94740_, p_94741_, p_94742_, p_94743_, p_94744_) + } + + override fun mouseScrolled(p_94734_: Double, p_94735_: Double, p_94736_: Double): Boolean { + return panel.mouseScrolledChecked(p_94734_, p_94735_, p_94736_) + } + + override fun keyPressed(p_94745_: Int, p_94746_: Int, p_94747_: Int): Boolean { + return panel.keyPressed(p_94745_, p_94746_, p_94747_) + } + + override fun keyReleased(p_94750_: Int, p_94751_: Int, p_94752_: Int): Boolean { + return panel.keyReleased(p_94750_, p_94751_, p_94752_) + } + + override fun charTyped(p_94732_: Char, p_94733_: Int): Boolean { + return panel.charTyped(p_94732_, p_94733_) + } + + override fun changeFocus(p_94756_: Boolean): Boolean { + return false + } + + override fun isMouseOver(p_94748_: Double, p_94749_: Double): Boolean { + return panel.isMouseOver(p_94748_, p_94749_) + } +}