60 lines
2.0 KiB
Kotlin
60 lines
2.0 KiB
Kotlin
package net.shadowfacts.phycon.network.block.terminal
|
|
|
|
import com.mojang.blaze3d.platform.GlStateManager
|
|
import net.minecraft.client.gui.DrawableHelper
|
|
import net.minecraft.client.gui.screen.ingame.HandledScreen
|
|
import net.minecraft.client.util.math.MatrixStack
|
|
import net.minecraft.entity.player.PlayerInventory
|
|
import net.minecraft.screen.slot.Slot
|
|
import net.minecraft.text.Text
|
|
import net.minecraft.util.Identifier
|
|
import net.shadowfacts.phycon.PhysicalConnectivity
|
|
|
|
/**
|
|
* @author shadowfacts
|
|
*/
|
|
// todo: translate title
|
|
class TerminalScreen(handler: TerminalScreenHandler, playerInv: PlayerInventory, title: Text): HandledScreen<TerminalScreenHandler>(handler, playerInv, title) {
|
|
companion object {
|
|
val BACKGROUND = Identifier(PhysicalConnectivity.MODID, "textures/gui/terminal.png")
|
|
}
|
|
|
|
init {
|
|
backgroundWidth = 252
|
|
backgroundHeight = 222
|
|
}
|
|
|
|
override fun drawForeground(matrixStack: MatrixStack, mouseX: Int, mouseY: Int) {
|
|
textRenderer.draw(matrixStack, title, 65f, 6f, 0x404040)
|
|
textRenderer.draw(matrixStack, playerInventory.displayName, 65f, backgroundHeight - 94f, 0x404040)
|
|
// todo: translate this
|
|
textRenderer.draw(matrixStack, "Buffer", 7f, 6f, 0x404040)
|
|
}
|
|
|
|
override fun drawBackground(matrixStack: MatrixStack, delta: Float, mouseX: Int, mouseY: Int) {
|
|
renderBackground(matrixStack)
|
|
|
|
GlStateManager.color4f(1f, 1f, 1f, 1f)
|
|
client!!.textureManager.bindTexture(BACKGROUND)
|
|
val x = (width - backgroundWidth) / 2
|
|
val y = (height - backgroundHeight) / 2
|
|
drawTexture(matrixStack, x, y, 0, 0, backgroundWidth, backgroundHeight)
|
|
}
|
|
|
|
@ExperimentalUnsignedTypes
|
|
fun drawSlotUnderlay(matrixStack: MatrixStack, slot: Slot) {
|
|
if (!handler.isBufferSlot(slot.id)) {
|
|
return
|
|
}
|
|
|
|
val mode = handler.terminal.internalBuffer.getMode(slot.id - handler.bufferSlotsStart)
|
|
val color: UInt = when (mode) {
|
|
TerminalBufferInventory.Mode.TO_NETWORK -> 0xFFFF0000u
|
|
TerminalBufferInventory.Mode.FROM_NETWORK -> 0xFF00FF00u
|
|
else -> return
|
|
}
|
|
DrawableHelper.fill(matrixStack, slot.x, slot.y, slot.x + 16, slot.y + 16, color.toInt())
|
|
}
|
|
|
|
}
|