Button to go back to vanilla inventory screen

This commit is contained in:
DBotThePony 2022-09-07 14:22:14 +07:00
parent 3797265107
commit fcbe68297c
Signed by: DBot
GPG Key ID: DCC23B5715498507
7 changed files with 49 additions and 16 deletions

View File

@ -49,6 +49,7 @@ private fun misc(provider: MatteryLanguageProvider) {
gui("recipe.ticks", "%s Ticks") gui("recipe.ticks", "%s Ticks")
gui("exosuit", "Exosuit Inventory") gui("exosuit", "Exosuit Inventory")
gui("exosuit.go_back", "Open vanilla 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.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.") gui("exosuit.probe2", "There is fingerprint reader built into one of sides which gently glow when touched.")

View File

@ -39,8 +39,10 @@ object ClientEventHandler {
} }
} }
var ignoreInventoryOpen = false
fun screenOpen(event: ScreenEvent.Opening) { fun screenOpen(event: ScreenEvent.Opening) {
if (minecraft.player?.isCreative == true) { if (ignoreInventoryOpen || minecraft.player?.isCreative == true) {
return return
} }

View File

@ -17,4 +17,5 @@ object Widgets18 {
val PATTERN_SLOT_BACKGROUND = GRID.next() val PATTERN_SLOT_BACKGROUND = GRID.next()
val EQUIPMENT_BATTERY_SLOT_BACKGROUND = GRID.next() val EQUIPMENT_BATTERY_SLOT_BACKGROUND = GRID.next()
val MATTER_CAPACITOR_SLOT_BACKGROUND = GRID.next() val MATTER_CAPACITOR_SLOT_BACKGROUND = GRID.next()
val RETURN_ARROW_LEFT = GRID.next()
} }

View File

@ -1,9 +1,10 @@
package ru.dbotthepony.mc.otm.client.screen package ru.dbotthepony.mc.otm.client.screen
import com.mojang.blaze3d.platform.InputConstants
import com.mojang.blaze3d.vertex.PoseStack import com.mojang.blaze3d.vertex.PoseStack
import it.unimi.dsi.fastutil.ints.Int2ObjectAVLTreeMap import net.minecraft.client.gui.screens.inventory.InventoryScreen
import it.unimi.dsi.fastutil.ints.Int2ObjectFunction import ru.dbotthepony.mc.otm.client.ClientEventHandler
import net.minecraft.world.inventory.Slot import ru.dbotthepony.mc.otm.client.render.Widgets18
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.client.render.element import ru.dbotthepony.mc.otm.client.render.element
import ru.dbotthepony.mc.otm.client.screen.panels.* import ru.dbotthepony.mc.otm.client.screen.panels.*
@ -127,6 +128,23 @@ class ExoSuitInventoryScreen(menu: ExoSuitInventoryMenu) : MatteryScreen<ExoSuit
scrollPanel.dock = Dock.RIGHT scrollPanel.dock = Dock.RIGHT
scrollPanel.setDockMargin(right = 3f) scrollPanel.setDockMargin(right = 3f)
LargeSquareButtonPanel(this, frame, x = frame.width + 2f, skinElement = Widgets18.RETURN_ARROW_LEFT, onPress = {
try {
ClientEventHandler.ignoreInventoryOpen = true
val minecraft = minecraft!!
val mouseX = minecraft.mouseHandler.xpos()
val mouseY = minecraft.mouseHandler.ypos()
onClose()
minecraft.setScreen(InventoryScreen(minecraft.player!!))
InputConstants.grabOrReleaseMouse(minecraft.window.window, 212993, mouseX, mouseY)
} finally {
ClientEventHandler.ignoreInventoryOpen = false
}
}).also { it.tooltip = TranslatableComponent("otm.gui.exosuit.go_back") }
return frame return frame
} }

View File

@ -80,12 +80,12 @@ abstract class SquareButtonPanel(
width: Float, width: Float,
height: Float, height: Float,
val skinElement: (() -> SkinElement)? = null, val skinElement: (() -> SkinElement)? = null,
val lambdaOnPress: ((clickButton: Int) -> Unit)? = null, val onPress: ((clickButton: Int) -> Unit)? = null,
) : EditablePanel(screen, parent, x, y, width, height) { ) : EditablePanel(screen, parent, x, y, width, height) {
protected var pressed = false protected var pressed = false
protected open fun click(clickButton: Int) { protected open fun click(clickButton: Int) {
lambdaOnPress?.invoke(clickButton) onPress?.invoke(clickButton)
} }
abstract val PRESSED: SkinElement abstract val PRESSED: SkinElement
@ -154,7 +154,7 @@ abstract class EnumSquareButtonPanel<T : Enum<T>>(
val enum: Class<T>, val enum: Class<T>,
val prop: KMutableProperty0<T>, val prop: KMutableProperty0<T>,
val defaultValue: T, val defaultValue: T,
val lambdaOnChange: ((newValue: T) -> Unit)? = null, val onChange: ((newValue: T) -> Unit)? = null,
) : SquareButtonPanel(screen, parent, x, y, width, height, null, null) { ) : SquareButtonPanel(screen, parent, x, y, width, height, null, null) {
private var building = true private var building = true
@ -256,18 +256,18 @@ abstract class EnumSquareButtonPanel<T : Enum<T>>(
when (clickButton) { when (clickButton) {
InputConstants.MOUSE_BUTTON_LEFT -> { InputConstants.MOUSE_BUTTON_LEFT -> {
prop.set(prop.get().next(enum.enumConstants)) prop.set(prop.get().next(enum.enumConstants))
lambdaOnChange?.invoke(prop.get()) onChange?.invoke(prop.get())
} }
InputConstants.MOUSE_BUTTON_RIGHT -> { InputConstants.MOUSE_BUTTON_RIGHT -> {
prop.set(prop.get().prev(enum.enumConstants)) prop.set(prop.get().prev(enum.enumConstants))
lambdaOnChange?.invoke(prop.get()) onChange?.invoke(prop.get())
} }
InputConstants.MOUSE_BUTTON_MIDDLE -> { InputConstants.MOUSE_BUTTON_MIDDLE -> {
if (prop.get() != defaultValue) { if (prop.get() != defaultValue) {
prop.set(defaultValue) prop.set(defaultValue)
lambdaOnChange?.invoke(prop.get()) onChange?.invoke(prop.get())
} }
} }
} }
@ -321,8 +321,19 @@ open class LargeSquareButtonPanel(
width: Float = SIZE, width: Float = SIZE,
height: Float = SIZE, height: Float = SIZE,
skinElement: (() -> SkinElement)? = null, skinElement: (() -> SkinElement)? = null,
lambdaOnPress: ((clickButton: Int) -> Unit)? = null, onPress: ((clickButton: Int) -> Unit)? = null,
) : SquareButtonPanel(screen, parent, x, y, width, height, skinElement, lambdaOnPress) { ) : SquareButtonPanel(screen, parent, x, y, width, height, skinElement, onPress) {
constructor(
screen: MatteryScreen<*>,
parent: EditablePanel?,
x: Float = 0f,
y: Float = 0f,
width: Float = SIZE,
height: Float = SIZE,
skinElement: SkinElement,
onPress: ((clickButton: Int) -> Unit)? = null,
) : this(screen, parent, x, y, width, height, { skinElement }, onPress)
final override val IDLE = Widgets18.BUTTON_IDLE final override val IDLE = Widgets18.BUTTON_IDLE
final override val HOVERED = Widgets18.BUTTON_HOVERED final override val HOVERED = Widgets18.BUTTON_HOVERED
final override val PRESSED = Widgets18.BUTTON_PRESSED final override val PRESSED = Widgets18.BUTTON_PRESSED
@ -341,8 +352,8 @@ open class LargeEnumSquareButtonPanel<T : Enum<T>>(
enum: Class<T>, enum: Class<T>,
prop: KMutableProperty0<T>, prop: KMutableProperty0<T>,
defaultValue: T, defaultValue: T,
lambdaOnChange: ((newValue: T) -> Unit)? = null, onChange: ((newValue: T) -> Unit)? = null,
) : EnumSquareButtonPanel<T>(screen, parent, x, y, width, height, enum, prop, defaultValue, lambdaOnChange) { ) : EnumSquareButtonPanel<T>(screen, parent, x, y, width, height, enum, prop, defaultValue, onChange) {
final override val IDLE = Widgets18.BUTTON_IDLE final override val IDLE = Widgets18.BUTTON_IDLE
final override val HOVERED = Widgets18.BUTTON_HOVERED final override val HOVERED = Widgets18.BUTTON_HOVERED
final override val PRESSED = Widgets18.BUTTON_PRESSED final override val PRESSED = Widgets18.BUTTON_PRESSED

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB