more stuff, case button except it sucks, I HATE MINECRAFT
This commit is contained in:
@@ -24,15 +24,19 @@ import kotlin.math.ceil
|
||||
|
||||
// #66CC66
|
||||
|
||||
object ProgressBar { // TODO: variable length
|
||||
object ProgressBar {
|
||||
|
||||
val BAR: ResourceLocation = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "textures/gui/bar.png")
|
||||
|
||||
// NOTE: OC never uses a different width and height, changing height is not recommended
|
||||
// NOTE: OC never uses a different width and height
|
||||
fun render(guiGraphics: GuiGraphics, x: Int, y: Int, value: Long, max: Long, mouseX: Int, mouseY: Int, width: Int=142, height: Int=14, tooltipfunc: (Int) -> String?) {
|
||||
guiGraphics.blit(BAR, x, y, 1, height, 0F, 0F, 1, 14, 3, 14)
|
||||
guiGraphics.blit(BAR, x+1, y, width-2, height, 1F, 0F, 1, 14, 3, 14)
|
||||
guiGraphics.blit(BAR, x+width-1, y, 1, height, 2F, 0F, 1, 14, 3, 14)
|
||||
RenderSystem.disableBlend()
|
||||
guiGraphics.fill(x, y, x+width-1, y+1, 0xFF373737.toInt()) // top left corner + top edge
|
||||
guiGraphics.fill(x, y+1, x+1, y+height-1, 0xFF373737.toInt()) // left edge
|
||||
|
||||
guiGraphics.fill(x, y+height-1, x+1, y+height, 0xFF8B8B8B.toInt()) // bottom left corner
|
||||
guiGraphics.fill(x+width-1, y, x+width, y+1, 0xFF8B8B8B.toInt()) // top right corner
|
||||
|
||||
guiGraphics.fill(x+1, y+height-1, x+width, y+height, 0xFFFFFFFF.toInt()) // bottom right corner + bottom edge
|
||||
guiGraphics.fill(x+width-1, y+height-1, x+width, y+1, 0xFFFFFFFF.toInt()) // right edge
|
||||
|
||||
val frac = value.toFloat() / max.toFloat()
|
||||
val linew = ceil(frac*(width-2).toFloat())
|
||||
|
||||
@@ -4,40 +4,65 @@ import com.mojang.blaze3d.vertex.BufferBuilder
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat
|
||||
import com.mojang.blaze3d.vertex.Tesselator
|
||||
import com.mojang.blaze3d.vertex.VertexFormat
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.client.gui.components.Button
|
||||
import net.minecraft.client.gui.components.ImageButton
|
||||
import net.minecraft.client.gui.components.WidgetSprites
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import org.neoflock.neocomputers.NeoComputers
|
||||
import org.neoflock.neocomputers.gui.menu.CaseMenu
|
||||
import org.neoflock.neocomputers.gui.widget.DynamicSlot
|
||||
import org.neoflock.neocomputers.gui.widget.ProgressBar
|
||||
import org.neoflock.neocomputers.gui.widget.ButtonSprites
|
||||
import org.neoflock.neocomputers.gui.widget.ImagerButton
|
||||
import org.neoflock.neocomputers.utils.GenericContainerScreen
|
||||
|
||||
class CaseScreen : GenericContainerScreen<CaseMenu> {
|
||||
private val PCB: ResourceLocation = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "textures/gui/computer.png")
|
||||
private val BTN: ResourceLocation = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "textures/gui/button_power.png")
|
||||
// private val BTN_ENABLED: ResourceLocation = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "textures/gui/button/power/enabled.png") // gonna do this later
|
||||
// private val BTN_DISABLED: ResourceLocation = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "textures/gui/button/power/disabled.png")
|
||||
// private val BTN_ENABLED_HOVER: ResourceLocation = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "textures/gui/button/power/enabled_hover.png")
|
||||
// private val BTN_DISABLED_HOVER: ResourceLocation = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "textures/gui/power/disabled_hover.png")
|
||||
|
||||
|
||||
private var btn: ImagerButton? = null;
|
||||
override fun shouldCenterTitle(): Boolean = false
|
||||
|
||||
constructor(abstractContainerMenu: CaseMenu, inventory: Inventory, component: Component) : super(abstractContainerMenu, inventory, component)
|
||||
constructor(abstractContainerMenu: CaseMenu, inventory: Inventory, component: Component) : super(abstractContainerMenu, inventory, component) {
|
||||
btn = ImagerButton(
|
||||
15, 15,
|
||||
18, 18,
|
||||
ButtonSprites(BTN, 18, 18, 36, 36)
|
||||
) {
|
||||
var btn = it as ImagerButton
|
||||
btn.pressed = !btn.pressed
|
||||
}
|
||||
// addRenderableWidget(btn!!)
|
||||
}
|
||||
override fun renderBg(guiGraphics: GuiGraphics, f: Float, i: Int, j: Int) {
|
||||
super.renderBg(guiGraphics, f, i ,j)
|
||||
val relX = (this.width - this.imageWidth) / 2
|
||||
val relY = (this.height - this.imageHeight) / 2
|
||||
|
||||
guiGraphics.blit(PCB, relX, relY, 0, 0, this.imageWidth, this.imageHeight)
|
||||
|
||||
// this.renderSlots(relX, relY)
|
||||
|
||||
|
||||
btn!!.x = relX+70
|
||||
btn!!.y = relY+33
|
||||
btn!!.render(guiGraphics, i, j, f) // minecraft SUCKSSS
|
||||
guiGraphics.blit(PCB, relX, relY, 0, 0, this.imageWidth, this.imageHeight)
|
||||
}
|
||||
|
||||
// private fun renderSlots(relX: Int, relY: Int) { // TODO: put this in some generic screen class
|
||||
// for (slot in menu.slots) {
|
||||
// if (slot is DynamicSlot) {
|
||||
// slot.draw(relX, relY)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean { // todo: make a better widget system than mojang, practically not even using the fact it's a widget atp
|
||||
NeoComputers.LOGGER.info(String.format("btn: %d %d %d %d, mouse %s %s", btn!!.x, btn!!.y, btn!!.x+btn!!.width, btn!!.y+btn!!.height, mouseX.toString(), mouseY.toString()))
|
||||
if (button != 0) return false
|
||||
if (btn!!.x < mouseX.toInt() && mouseX.toInt() < btn!!.x+btn!!.width && btn!!.y < mouseY.toInt() && mouseY.toInt() < btn!!.y+btn!!.height) {
|
||||
btn!!.playDownSound(Minecraft.getInstance().soundManager)
|
||||
btn!!.onClick(mouseX, mouseY)
|
||||
return true
|
||||
} else return false
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.neoflock.neocomputers.gui.widget
|
||||
|
||||
import net.minecraft.client.gui.Gui
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.client.gui.components.Button
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import org.neoflock.neocomputers.NeoComputers
|
||||
|
||||
data class ButtonSprites(val sheet: ResourceLocation, val spriteWidth: Int, val spriteHeight: Int, val texWidth: Int, val texHeight: Int)
|
||||
|
||||
// minecraft sux
|
||||
class ImagerButton(x: Int, y: Int, width: Int, height: Int, val sprites: ButtonSprites, onPress: Button.OnPress) : Button(x, y, width, height, Component.literal(""), onPress, DEFAULT_NARRATION) {
|
||||
// public void renderWidget(GuiGraphics guiGraphics, int i, int j, float f) {
|
||||
// ResourceLocation resourceLocation = this.sprites.get(this.isActive(), this.isHoveredOrFocused());
|
||||
// guiGraphics.blitSprite(resourceLocation, this.getX(), this.getY(), this.width, this.height);
|
||||
// }
|
||||
var pressed = false
|
||||
|
||||
override fun renderWidget(graphics: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
|
||||
val u = if (pressed) 18F else 0F // no clue why it's swapped? prob cooked the coordinates, we gotta get parchment so bad
|
||||
val v = if (this.isHoveredOrFocused) 18F else 0F
|
||||
|
||||
graphics.blit(sprites.sheet, x, y, width, height, u, v, sprites.spriteWidth, sprites.spriteHeight, sprites.texWidth, sprites.texHeight)
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 598 B |
Binary file not shown.
|
Before Width: | Height: | Size: 628 B |
Binary file not shown.
|
Before Width: | Height: | Size: 4.4 KiB |
Reference in New Issue
Block a user