progressbar stuff
This commit is contained in:
6
.config/lite-xl/init.lua
Normal file
6
.config/lite-xl/init.lua
Normal file
@@ -0,0 +1,6 @@
|
||||
local core = require "core"
|
||||
local config = require "config"
|
||||
|
||||
|
||||
config.ignore_files = { "^build$", "^buildSrc$", "^gradle$", "^\.kotlin$", "^\.idea$", "^\.vscode$", "^\.gradle$", "^\.architectury-transformer$" }
|
||||
|
||||
37
.lite_project.lua
Normal file
37
.lite_project.lua
Normal file
@@ -0,0 +1,37 @@
|
||||
-- Put project's module settings here.
|
||||
-- This module will be loaded when opening a project, after the user module
|
||||
-- configuration.
|
||||
-- It will be automatically reloaded when saved.
|
||||
|
||||
local config = require "core.config"
|
||||
|
||||
config.ignore_files = {"^buildSrc$", "^gradle$", "\\.kotlin", "\\.idea", "\\.vscode", "\\.gradle", "\\.architectury-transformer" }
|
||||
|
||||
|
||||
-- you can add some patterns to ignore files within the project
|
||||
-- config.ignore_files = {"^%.", <some-patterns>}
|
||||
|
||||
-- Patterns are normally applied to the file's or directory's name, without
|
||||
-- its path. See below about how to apply filters on a path.
|
||||
--
|
||||
-- Here some examples:
|
||||
--
|
||||
-- "^%." matches any file of directory whose basename begins with a dot.
|
||||
--
|
||||
-- When there is an '/' or a '/$' at the end, the pattern will only match
|
||||
-- directories. When using such a pattern a final '/' will be added to the name
|
||||
-- of any directory entry before checking if it matches.
|
||||
--
|
||||
-- "^%.git/" matches any directory named ".git" anywhere in the project.
|
||||
--
|
||||
-- If a "/" appears anywhere in the pattern (except when it appears at the end or
|
||||
-- is immediately followed by a '$'), then the pattern will be applied to the full
|
||||
-- path of the file or directory. An initial "/" will be prepended to the file's
|
||||
-- or directory's path to indicate the project's root.
|
||||
--
|
||||
-- "^/node_modules/" will match a directory named "node_modules" at the project's root.
|
||||
-- "^/build.*/" will match any top level directory whose name begins with "build".
|
||||
-- "^/subprojects/.+/" will match any directory inside a top-level folder named "subprojects".
|
||||
|
||||
-- You may activate some plugins on a per-project basis to override the user's settings.
|
||||
-- config.plugins.trimwitespace = true
|
||||
@@ -7,6 +7,7 @@ import net.minecraft.world.entity.player.Player
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu
|
||||
import net.minecraft.world.inventory.MenuType
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import org.neoflock.neocomputers.NeoComputers
|
||||
import org.neoflock.neocomputers.gui.widget.DynamicSlot
|
||||
import org.neoflock.neocomputers.utils.GenericContainerMenu
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package org.neoflock.neocomputers.gui.widget
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder
|
||||
import com.mojang.blaze3d.vertex.BufferUploader
|
||||
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.AbstractWidget
|
||||
import net.minecraft.client.gui.narration.NarrationElementOutput
|
||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent
|
||||
import net.minecraft.client.renderer.GameRenderer
|
||||
import net.minecraft.client.renderer.RenderType
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.world.item.Item
|
||||
import org.neoflock.neocomputers.NeoComputers
|
||||
import java.util.function.Supplier
|
||||
import kotlin.math.ceil
|
||||
|
||||
// #66CC66
|
||||
|
||||
object ProgressBar { // TODO: variable length
|
||||
|
||||
val BAR: ResourceLocation = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "textures/gui/bar.png")
|
||||
// val BAROLD: ResourceLocation = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "textures/gui/bar_old.png")
|
||||
// val font: Font = Minecraft.getInstance().font
|
||||
|
||||
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?) { // NOTE: OC never uses a different width and height, changing height is not recommended
|
||||
// RenderSystem.setShader { GameRenderer.getPositionTexShader() }
|
||||
// RenderSystem.setShaderTexture(0, BAROLD)
|
||||
// drawQuad(x, y, width, height, 0F, 0F, 15F, 15F)
|
||||
renderEmptyBar(x, y, width, height)
|
||||
|
||||
val frac = value.toFloat() / max.toFloat()
|
||||
val linew = ceil(frac*(width-2).toFloat())
|
||||
guiGraphics.fill(
|
||||
RenderType.guiOverlay(),
|
||||
x + 1,
|
||||
y + 1,
|
||||
x + 1 + (linew.toInt()),
|
||||
y + height-1,
|
||||
0xFF66CC66.toInt()
|
||||
)
|
||||
|
||||
val tooltip = tooltipfunc((ceil(frac) * 100F).toInt()) ?: return
|
||||
if (mouseX > x && mouseX < x+width && mouseY > y && mouseY < y+height )
|
||||
guiGraphics.renderTooltip(Minecraft.getInstance().font, Component.literal(tooltip), mouseX, mouseY)
|
||||
}
|
||||
|
||||
private fun renderEmptyBar(x: Int, y: Int, width: Int, height: Int) {
|
||||
RenderSystem.setShader { GameRenderer.getPositionTexShader() }
|
||||
RenderSystem.setShaderTexture(0, BAR)
|
||||
drawQuad(x, y, 1, height, 0F, 0F, 1F, 14F, 3F, 14F)
|
||||
drawQuad(x+1, y, width-2, height, 1F, 0F, 2F, 14F, 3F, 14F)
|
||||
drawQuad(x+width-1, y, 1, height, 2F, 0F, 3F, 14F, 3F, 14F)
|
||||
|
||||
}
|
||||
|
||||
private fun drawQuad(x: Int, y: Int, width: Int, height: Int, u1: Float, v1: Float, u2: Float, v2: Float, texwidth: Float=15F, texheight: Float=15F) { // this should really become a util func
|
||||
var t: Tesselator = Tesselator.getInstance()
|
||||
var builder: BufferBuilder = t.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX)
|
||||
|
||||
builder.addVertex(x.toFloat(), (y+height).toFloat(), 1f).setUv(u1/texwidth, v2/texheight)
|
||||
builder.addVertex((x+width).toFloat(), (y+height).toFloat(), 1f).setUv(u2/texwidth, v2/texheight)
|
||||
builder.addVertex((x+width).toFloat(), y.toFloat(), 1f).setUv(u2/texwidth, v1/texheight)
|
||||
builder.addVertex(x.toFloat(), y.toFloat(), 1f).setUv(u1/texwidth,v1/texheight)
|
||||
|
||||
BufferUploader.drawWithShader(builder.build()!!)
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.mojang.blaze3d.vertex.DefaultVertexFormat
|
||||
import com.mojang.blaze3d.vertex.Tesselator
|
||||
import com.mojang.blaze3d.vertex.VertexFormat
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.client.gui.components.ImageButton
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
@@ -12,6 +13,7 @@ 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.utils.GenericContainerScreen
|
||||
|
||||
class CaseScreen : GenericContainerScreen<CaseMenu> {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.neoflock.neocomputers.gui.screen
|
||||
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.client.renderer.RenderType
|
||||
import net.minecraft.network.FriendlyByteBuf
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||
import net.minecraft.network.chat.Component
|
||||
@@ -9,11 +10,13 @@ import net.minecraft.world.entity.player.Inventory
|
||||
import org.neoflock.neocomputers.NeoComputers
|
||||
import org.neoflock.neocomputers.entity.BlockEntities
|
||||
import org.neoflock.neocomputers.gui.menu.CombustionGeneratorMenu
|
||||
import org.neoflock.neocomputers.gui.widget.ProgressBar
|
||||
import org.neoflock.neocomputers.utils.GenericContainerScreen
|
||||
import kotlin.math.ceil
|
||||
|
||||
class CombustionGeneratorScreen(abstractContainerMenu: CombustionGeneratorMenu, inventory: Inventory, component: Component) : GenericContainerScreen<CombustionGeneratorMenu>(abstractContainerMenu, inventory, component) {
|
||||
// override fun findMenuTexture(): ResourceLocation = ResourceLocation.withDefaultNamespace("textures/gui/container/dispenser.png")
|
||||
override fun findMenuTexture(): ResourceLocation = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "textures/gui/background.png")
|
||||
class CombustionGeneratorScreen : GenericContainerScreen<CombustionGeneratorMenu> {
|
||||
// val bar: ProgressBar = ProgressBar(x = -50, y = -50) { Pair(energy, energyCapacity) } // hide it type shi
|
||||
constructor(abstractContainerMenu: CombustionGeneratorMenu, inventory: Inventory, component: Component) : super(abstractContainerMenu, inventory, component)
|
||||
|
||||
var energy: Long = 0
|
||||
var energyCapacity: Long = 1
|
||||
@@ -21,17 +24,26 @@ class CombustionGeneratorScreen(abstractContainerMenu: CombustionGeneratorMenu,
|
||||
override fun render(graphics: GuiGraphics, mouseX: Int, mouseY: Int, something: Float) {
|
||||
super.render(graphics, mouseX, mouseY, something)
|
||||
|
||||
val lineBg = 0xFF002200.toInt()
|
||||
val lineFg = 0xFF00FF00.toInt()
|
||||
var relX: Int = (this.width - this.imageWidth) / 2;
|
||||
var relY: Int = (this.height - this.imageHeight) / 2;
|
||||
|
||||
val lineX = imageX + 8
|
||||
val lineY = imageY + 6
|
||||
val lineHeight = 60
|
||||
ProgressBar.render(graphics, relX+17, relY+55, energy, energyCapacity, mouseX, mouseY, 50, 14) {
|
||||
String.format("Energy: %d%% (%d/%d)", it, energy, energyCapacity)
|
||||
}
|
||||
// bar.x = imageX + 17
|
||||
// bar.y = imageY + 50
|
||||
|
||||
val power = energy.toDouble() / energyCapacity
|
||||
// val lineBg = 0xFF002200.toInt()
|
||||
// val lineFg = 0xFF00FF00.toInt()
|
||||
|
||||
graphics.fill(lineX, lineY, lineX + 2, lineY + lineHeight, lineFg)
|
||||
graphics.fill(lineX, lineY, lineX + 2, lineY + (lineHeight * (1.0 - power)).toInt(), lineBg)
|
||||
// val lineX = imageX + 8
|
||||
// val lineY = imageY + 6
|
||||
// val lineHeight = 60
|
||||
|
||||
// val power = energy.toDouble() / energyCapacity
|
||||
|
||||
// graphics.fill(lineX, lineY, lineX + 2, lineY + lineHeight, lineFg)
|
||||
// graphics.fill(lineX, lineY, lineX + 2, lineY + (lineHeight * (1.0 - power)).toInt(), lineBg)
|
||||
}
|
||||
|
||||
override fun getBoundBlockEntityType() = setOf(BlockEntities.COMBUSTGEN_ENTITY.get())
|
||||
@@ -39,5 +51,6 @@ class CombustionGeneratorScreen(abstractContainerMenu: CombustionGeneratorMenu,
|
||||
override fun processScreenStatePacket(buf: FriendlyByteBuf) {
|
||||
energy = buf.readLong()
|
||||
energyCapacity = buf.readLong()
|
||||
|
||||
}
|
||||
}
|
||||
@@ -15,23 +15,12 @@ import java.nio.charset.StandardCharsets
|
||||
object FontProvider {
|
||||
val map: MutableMap<Char, ArrayList<Byte>> = mutableMapOf();
|
||||
|
||||
fun load(loc: ResourceLocation) { // TODO: optimize, this can totally be optimized
|
||||
fun load(loc: ResourceLocation) {
|
||||
var man: ResourceManager = Minecraft.getInstance().resourceManager
|
||||
var resource: Resource = man.getResourceOrThrow(loc)
|
||||
var stream = resource.open()
|
||||
var bfr = stream.bufferedReader();
|
||||
while (stream.available() > 0) {
|
||||
|
||||
/*var key = Integer.parseInt(String(stream.readNBytes(5), StandardCharsets.UTF_8), 16).toChar()
|
||||
stream.skip(1)
|
||||
var bytes: ArrayList<Byte> = ArrayList<Byte>();
|
||||
while (true) { // shut up will you
|
||||
var b1 = stream.read()
|
||||
if (b1 == 10) break // 10 is line break
|
||||
var b2 = stream.read()
|
||||
var value: Byte = Integer.parseInt(arrayOf(b1.toChar(), b2.toChar()).joinToString(""), 16).toByte()
|
||||
bytes.add(value)
|
||||
} */
|
||||
var line: String = bfr.readLine()
|
||||
var splitLine = line.split(":");
|
||||
var key = splitLine[0].hexToInt().toChar();
|
||||
|
||||
BIN
src/main/resources/assets/neocomputers/textures/gui/bar.png
Normal file
BIN
src/main/resources/assets/neocomputers/textures/gui/bar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 598 B |
BIN
src/main/resources/assets/neocomputers/textures/gui/bar_old.png
Normal file
BIN
src/main/resources/assets/neocomputers/textures/gui/bar_old.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 628 B |
Reference in New Issue
Block a user