exopack curios compat improvements
This commit is contained in:
parent
68fedf0257
commit
8b7e3821b4
@ -261,11 +261,13 @@ class ExopackInventoryScreen(menu: ExopackInventoryMenu) : MatteryScreen<Exopack
|
||||
setMousePos(mouseX, mouseY)
|
||||
}).also { it.tooltips.add(TranslatableComponent("otm.gui.exopack.go_back")) }
|
||||
|
||||
/*
|
||||
if (isCuriosLoaded) {
|
||||
LargeRectangleButtonPanel(this, frame, x = closeButtonPanel.x - 2f - LargeRectangleButtonPanel.SIZE, y = closeButtonPanel.y, icon = Widgets18.CURIOS_INVENTORY, onPress = {
|
||||
openCuriosScreen(minecraft!!.player!!.containerMenu.carried)
|
||||
}).also { it.tooltips.add(TranslatableComponent("otm.gui.exopack.go_curios")) }
|
||||
}
|
||||
*/
|
||||
|
||||
val controls = DeviceControls(this, frame)
|
||||
|
||||
|
@ -9,6 +9,8 @@ import ru.dbotthepony.mc.otm.client.screen.panels.slot.InventorySlotPanel
|
||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel
|
||||
import ru.dbotthepony.mc.otm.client.screen.panels.util.BackgroundPanel
|
||||
import ru.dbotthepony.mc.otm.compat.cos.CosmeticToggleButton
|
||||
import ru.dbotthepony.mc.otm.compat.curios.CurioSlotPanel
|
||||
import ru.dbotthepony.mc.otm.compat.curios.CurioToggleButton
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||
import ru.dbotthepony.mc.otm.menu.PlayerSlot
|
||||
|
||||
@ -38,10 +40,14 @@ fun <S : MatteryScreen<*>> makeCuriosPanel(screen: S, parent: FramePanel<S>, slo
|
||||
val row = EditablePanel(screen, if (curiosRect is ScrollbarBackgroundPanel) curiosRect.canvas else curiosRect, height = AbstractSlotPanel.SIZE)
|
||||
row.dock = Dock.TOP
|
||||
|
||||
SlotPanel(screen, row, slot).dock = Dock.RIGHT
|
||||
CurioSlotPanel(screen, row, slot).also {
|
||||
it.dock = Dock.RIGHT
|
||||
|
||||
CurioToggleButton(screen, it, slot, x = it.width - 8f)
|
||||
}
|
||||
|
||||
if (cosmetic != null) {
|
||||
SlotPanel(screen, row, cosmetic).dock = Dock.LEFT
|
||||
CurioSlotPanel(screen, row, cosmetic).dock = Dock.LEFT
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,26 @@
|
||||
package ru.dbotthepony.mc.otm.compat.curios
|
||||
|
||||
import com.google.common.collect.Streams
|
||||
import com.mojang.blaze3d.platform.InputConstants
|
||||
import net.minecraft.client.gui.screens.Screen
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.world.entity.player.Player
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.neoforged.fml.ModList
|
||||
import net.neoforged.fml.loading.FMLEnvironment
|
||||
import net.neoforged.neoforge.network.PacketDistributor
|
||||
import ru.dbotthepony.kommons.math.RGBAColor
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||
import ru.dbotthepony.mc.otm.capability.matteryPlayer
|
||||
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
||||
import ru.dbotthepony.mc.otm.client.render.sprites.MatterySprite
|
||||
import ru.dbotthepony.mc.otm.client.render.sprites.sprite
|
||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||
import ru.dbotthepony.mc.otm.client.screen.panels.button.RectangleButtonPanel
|
||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel
|
||||
import ru.dbotthepony.mc.otm.container.util.awareStream
|
||||
import ru.dbotthepony.mc.otm.container.util.iterator
|
||||
import ru.dbotthepony.mc.otm.core.collect.AwareItemStack
|
||||
@ -21,6 +33,7 @@ import top.theillusivec4.curios.api.event.SlotModifiersUpdatedEvent
|
||||
import top.theillusivec4.curios.common.inventory.CosmeticCurioSlot
|
||||
import top.theillusivec4.curios.common.inventory.CurioSlot
|
||||
import top.theillusivec4.curios.common.network.client.CPacketOpenCurios
|
||||
import top.theillusivec4.curios.common.network.client.CPacketToggleRender
|
||||
import java.util.stream.Stream
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
@ -142,3 +155,78 @@ val Slot.isCurioSlot: Boolean get() {
|
||||
private val Slot.isCurioSlotImpl: Boolean get() {
|
||||
return this is CurioSlot || this is CosmeticCurioSlot
|
||||
}
|
||||
|
||||
class CurioSlotPanel<out S : MatteryScreen<*>, out T : Slot>(
|
||||
screen: S,
|
||||
parent: EditablePanel<*>?,
|
||||
slot: T,
|
||||
x: Float = 0f,
|
||||
y: Float = 0f,
|
||||
width: Float = SIZE,
|
||||
height: Float = SIZE,
|
||||
) : SlotPanel<S, T>(screen, parent, slot, x, y, width, height) {
|
||||
override fun innerRenderTooltips(
|
||||
graphics: MGUIGraphics,
|
||||
mouseX: Float,
|
||||
mouseY: Float,
|
||||
partialTick: Float
|
||||
): Boolean {
|
||||
if (slot.isCurioSlot && !slot.hasItem()) {
|
||||
graphics.parent.renderTooltip(
|
||||
font,
|
||||
Component.literal((slot as CurioSlot).getSlotName()),
|
||||
mouseX.toInt(),
|
||||
mouseY.toInt()
|
||||
)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
return super.innerRenderTooltips(graphics, mouseX, mouseY, partialTick)
|
||||
}
|
||||
}
|
||||
|
||||
class CurioToggleButton<out S : Screen>(
|
||||
screen: S,
|
||||
parent: EditablePanel<*>?,
|
||||
val slot: Slot,
|
||||
x: Float = 0f,
|
||||
y: Float = 0f,
|
||||
width: Float = 8f,
|
||||
height: Float = 8f
|
||||
) : RectangleButtonPanel<S>(screen, parent, x, y, width, height) {
|
||||
override val PRESSED: MatterySprite
|
||||
get() = BUTTON_ACTIVE
|
||||
override val HOVERED: MatterySprite
|
||||
get() = BUTTON_ACTIVE
|
||||
override val IDLE: MatterySprite
|
||||
get() = BUTTON_INACTIVE
|
||||
override val DISABLED: MatterySprite
|
||||
get() = BUTTON_INACTIVE
|
||||
|
||||
override fun onClick(mouseButton: Int) {
|
||||
if (!slot.isCurioSlot) return
|
||||
|
||||
if (mouseButton == InputConstants.MOUSE_BUTTON_LEFT) {
|
||||
PacketDistributor.sendToServer(CPacketToggleRender((slot as CurioSlot).identifier, slot.slotIndex))
|
||||
}
|
||||
}
|
||||
|
||||
override fun innerRender(graphics: MGUIGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||
if (!slot.isCurioSlot) return
|
||||
|
||||
val color = if (isHovered) RGBAColor.WHITE else RGBAColor.HALF_TRANSPARENT
|
||||
if ((slot as CurioSlot).getRenderStatus()) {
|
||||
BUTTON_ACTIVE.render(graphics, width = width, height = height, color = color)
|
||||
} else {
|
||||
BUTTON_INACTIVE.render(graphics, width = width, height = height, color = color)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val CURIO_INVENTORY = ResourceLocation.fromNamespaceAndPath(CuriosApi.MODID, "textures/gui/curios/inventory.png")
|
||||
|
||||
val BUTTON_ACTIVE = CURIO_INVENTORY.sprite(75f, 0f, 8f, 8f)
|
||||
val BUTTON_INACTIVE = CURIO_INVENTORY.sprite(75f + 8f, 0f, 8f, 8f)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user