From 2baaee741f5a73eb005c548d5b457bc80d19019c Mon Sep 17 00:00:00 2001 From: mewhenthe Date: Mon, 20 Apr 2026 19:40:03 +0200 Subject: [PATCH] progressbar stuff --- .config/lite-xl/init.lua | 6 ++ .lite_project.lua | 37 +++++++++ dump.png | Bin 2398 -> 0 bytes .../neocomputers/gui/menu/CaseMenu.kt | 1 + .../neocomputers/gui/render/ProgressBar.kt | 73 ++++++++++++++++++ .../neocomputers/gui/screen/CaseScreen.kt | 2 + .../gui/screen/CombustionGeneratorScreen.kt | 35 ++++++--- .../neocomputers/utils/FontProvider.kt | 13 +--- .../assets/neocomputers/textures/gui/bar.png | Bin 0 -> 598 bytes .../neocomputers/textures/gui/bar_old.png | Bin 0 -> 628 bytes 10 files changed, 144 insertions(+), 23 deletions(-) create mode 100644 .config/lite-xl/init.lua create mode 100644 .lite_project.lua delete mode 100644 dump.png create mode 100644 src/main/kotlin/org/neoflock/neocomputers/gui/render/ProgressBar.kt create mode 100644 src/main/resources/assets/neocomputers/textures/gui/bar.png create mode 100644 src/main/resources/assets/neocomputers/textures/gui/bar_old.png diff --git a/.config/lite-xl/init.lua b/.config/lite-xl/init.lua new file mode 100644 index 0000000..c339465 --- /dev/null +++ b/.config/lite-xl/init.lua @@ -0,0 +1,6 @@ +local core = require "core" +local config = require "config" + + +config.ignore_files = { "^build$", "^buildSrc$", "^gradle$", "^\.kotlin$", "^\.idea$", "^\.vscode$", "^\.gradle$", "^\.architectury-transformer$" } + diff --git a/.lite_project.lua b/.lite_project.lua new file mode 100644 index 0000000..427c560 --- /dev/null +++ b/.lite_project.lua @@ -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 = {"^%.", } + +-- 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 diff --git a/dump.png b/dump.png deleted file mode 100644 index c7b052ea683ecc88da12d7b1cde9d7a21c30e27c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2398 zcmeAS@N?(olHy`uVBq!ia0vp^3m6y}9XQy4EbBkz(hLlos-7;6Ar*1SDG3Qb&Kq#K zIVUtYHDsDRad%EoaAugp@c;k+^9+ZkShYkw>rv~RD9p52^+86K`~`u8h0EUd^z6Y=(;5;wx#srgG3Zq~ z{c>BJWWsX6x#5MGf@#&s#Ru)Bm|iG4gh&hQOp$(@(W9o6)pj65J;lV9H-n=`?Z8DA ziyy)YMbBGiY&nDF-85s=7b?pyZnqEG>lH?3iDW`YR| zn+l8D>IWBF%%fQQmo-8Z0!{#87HVUNbxznK zY&7eEo3$d)I1rN!7&Z=030t`2d@B}*e#nrLSla~A7s28$llGq8<2@D$=rkv4;fTy3)h@haz7|ju*Mbl^<0j#Fs fl_>pk1Or1`r$xSh&zxJpb`yiAtDnm{r-UW|+9|HQ diff --git a/src/main/kotlin/org/neoflock/neocomputers/gui/menu/CaseMenu.kt b/src/main/kotlin/org/neoflock/neocomputers/gui/menu/CaseMenu.kt index 068a2ed..44b6ace 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/gui/menu/CaseMenu.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/gui/menu/CaseMenu.kt @@ -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 diff --git a/src/main/kotlin/org/neoflock/neocomputers/gui/render/ProgressBar.kt b/src/main/kotlin/org/neoflock/neocomputers/gui/render/ProgressBar.kt new file mode 100644 index 0000000..8d8a5d9 --- /dev/null +++ b/src/main/kotlin/org/neoflock/neocomputers/gui/render/ProgressBar.kt @@ -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()!!) + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/neoflock/neocomputers/gui/screen/CaseScreen.kt b/src/main/kotlin/org/neoflock/neocomputers/gui/screen/CaseScreen.kt index bfc23c1..d052891 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/gui/screen/CaseScreen.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/gui/screen/CaseScreen.kt @@ -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 { diff --git a/src/main/kotlin/org/neoflock/neocomputers/gui/screen/CombustionGeneratorScreen.kt b/src/main/kotlin/org/neoflock/neocomputers/gui/screen/CombustionGeneratorScreen.kt index 9ef3637..0074c5b 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/gui/screen/CombustionGeneratorScreen.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/gui/screen/CombustionGeneratorScreen.kt @@ -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(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 { +// 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() + } } \ No newline at end of file diff --git a/src/main/kotlin/org/neoflock/neocomputers/utils/FontProvider.kt b/src/main/kotlin/org/neoflock/neocomputers/utils/FontProvider.kt index 2b85359..7c06242 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/utils/FontProvider.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/utils/FontProvider.kt @@ -15,23 +15,12 @@ import java.nio.charset.StandardCharsets object FontProvider { val map: MutableMap> = 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 = ArrayList(); - 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(); diff --git a/src/main/resources/assets/neocomputers/textures/gui/bar.png b/src/main/resources/assets/neocomputers/textures/gui/bar.png new file mode 100644 index 0000000000000000000000000000000000000000..c2c4b18b03d8b4d6aca0e8d175524e31d22131b9 GIT binary patch literal 598 zcmV-c0;&CpP)b9m~0004nX+uL$Nkc;* zaB^>EX>4Tx04R}tk-tmBKpe$i(@I4v3T6;-$WWc^q9TGztwIqhgj%6h2lJ!9ph-iL z;^HW{799MsSaoo5*44pP5CngK_y>rSqKlOHy`<10#)IQNyu0_fdk1ihilSMeIH2ja znNB8zY;IKuzaj)41DHjxq*%tBD5l^$zU~oV>s^dx`Jel9^r?AE0RjSXTro_Wc!PL) z(>56I6Z1+*Qi;!r$4$B*@gvh^kKY&|nWrm6E9uPZ38|O{aV= z>#@psi?LRzDXn|57e?~>$}-bwjv$FeEJ1_-88wtqfsGigIw=;?w4dDl|y0AM6i)cWV_UC%mLc0_b{ioR3i;ybCnzj`Mx&IL#9v_zYa>ZGW`^%zTnw zZ)?#bpnn^3_Tf=DY;URCRZo`?`QN)IbiS>=vni6YwhFo0mx8SsT<(n z5Ev^`_PWozyE}XP_e`t5AGN)5!CD*bV*mgE24YJ`L;yDcHvl(t+lli4000SaNLh0L z04^f{04^f|c%?sf00007bV*G`2kHbA5eFncR!_CX>@2HM@dakSAh-}0000jNklZ`Vv7c)2@zpNwz kR23v~W>nog{)g`NI=LVgL9H@Q`2YX_07*qoM6N<$f+D-~Qvd(} literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/neocomputers/textures/gui/bar_old.png b/src/main/resources/assets/neocomputers/textures/gui/bar_old.png new file mode 100644 index 0000000000000000000000000000000000000000..89c3e2daf5ca8f374e11698304463234eb29a3cc GIT binary patch literal 628 zcmV-)0*n2LP)EX>4Tx04R}tk-tmBKpe$i(@LdO99mGsAwzYti;6hbDionYs1;guFuC*>G-*jv zTpR`0f`dO6s}3&Cx;nTDg5VDj{{V4PbdeIjmlRsWcyQc@clRE5?*O4yWttgC0Ge(Y znN(8DYVq9qpU2e#OK5l23?T&k?V@fZ=6dG3p_JwWHa-`QDU*w!%7dcvY`=A6US6dr+gvj zvdVdjvsP`e&OP}H!v%e1nd>x1k-{RDAVGwJ1}dn+LY!8e6cZWRPkQ)A9KS>^giI+y*YLyPC2GTDYDGy0}H5V-|HYi@6yeVjf3S?Vf%0~{Oz z<0Z;o_jq@IZ*Tve>GbylF3WO@xv&*!00006VoOIv0RI4*0GiWzJC6VW010qNS#tmY zE+YT{E+YYWr9XB6000McNliru>I4%C1u6b@B?eSad^gZEa<4bO1wgWnpw> zWFU8GbZ8()Nlj2!fese{002x$L_t(o!|l?s4S+BZ1i=HjC+qw8zFe}2$uRLu39G&4 zoI7x!yEBqxt)&K^RaI^o_`^6D2jgHIj048OI2Z@xU>tZG-JPmZf+G)b_6EO*6`+Fv O0000