Remove the buttons limit

Signed-off-by: Username404-59 <w.iron.zombie@gmail.com>
This commit is contained in:
Username404-59 2026-02-06 03:10:14 +01:00
parent 174f840226
commit 965421b99f
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
4 changed files with 41 additions and 28 deletions

View File

@ -2,7 +2,6 @@ package fr.username404.snowygui.config
import fr.username404.snowygui.ClickGui import fr.username404.snowygui.ClickGui
import fr.username404.snowygui.gui.elements.ClickBox import fr.username404.snowygui.gui.elements.ClickBox
import fr.username404.snowygui.gui.elements.ClickBox.Companion.buttonsMax
import fr.username404.snowygui.gui.elements.ClickBox.Companion.sortAlphabetically import fr.username404.snowygui.gui.elements.ClickBox.Companion.sortAlphabetically
import fr.username404.snowygui.gui.feature.* import fr.username404.snowygui.gui.feature.*
import fr.username404.snowygui.utils.FontUtil import fr.username404.snowygui.utils.FontUtil
@ -75,9 +74,7 @@ val SnowyConfigScreen: Screen = object: Screen(translationComponent) {
}.build()).addEntry(startStrList( }.build()).addEntry(startStrList(
Category.MACROS.box.name, Category.MACROS.box.name,
macrosButtons.getTitleCommand() macrosButtons.getTitleCommand()
).setInsertInFront(false).setDefaultValue(Configuration.foundMacros.getTitleCommand()).setErrorSupplier { list -> ).setInsertInFront(false).setDefaultValue(Configuration.foundMacros.getTitleCommand()).setCellErrorSupplier { cell ->
supplyComponent(if (list.size > buttonsMax) "$confPrefix.general.macros.toomuchbuttons" else null)
}.setCellErrorSupplier { cell ->
with(cell.split(":")) { with(cell.split(":")) {
supplyComponent( supplyComponent(
when { when {

View File

@ -13,6 +13,8 @@ import net.minecraft.client.gui.GuiGraphics
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import net.minecraft.util.ARGB import net.minecraft.util.ARGB
import kotlin.math.floor import kotlin.math.floor
import kotlin.math.max
import kotlin.math.min
import kotlin.math.roundToInt import kotlin.math.roundToInt
import org.jetbrains.annotations.ApiStatus import org.jetbrains.annotations.ApiStatus
import java.util.TreeSet import java.util.TreeSet
@ -23,7 +25,7 @@ class ClickBox(
x: Double, y: Double, x: Double, y: Double,
val name: Component = MissingComponent, val name: Component = MissingComponent,
override var color: Int = savedColors?.get(name.string) ?: Colors.BLUE.hexValue, override var color: Int = savedColors?.get(name.string) ?: Colors.BLUE.hexValue,
): ColoredElement(x, y, 80, 10, color, 0.5F) { ) : ColoredElement(x, y, 80, 10, color, 0.5F) {
fun isCategory(c: Category): Boolean = (name.string == c.box.name.string) fun isCategory(c: Category): Boolean = (name.string == c.box.name.string)
val buttons: MutableSet<ButtonImpl> = val buttons: MutableSet<ButtonImpl> =
if (sortAlphabetically) if (sortAlphabetically)
@ -47,19 +49,23 @@ class ClickBox(
init { height = 8 } init { height = 8 }
} }
var barStage: Int = 1; private set var barStage: Int = 0; private set
fun scroll(d: Double, e: Double, supplied: Double) { fun scroll(d: Double, e: Double, supplied: Double) {
if (isWithinBounds(d, e, offsetHeight = clickboxHeightOffset.toDouble())) { if (!isWithinBounds(d, e, offsetHeight = clickboxHeightOffset.toDouble())) return
with(buttonsProgressBar) { if (buttons.isEmpty()) return
if ((height > 8 || (supplied < 0)) && (((height < (buttons.size * 8)) && (height < originalHeight)) || (supplied > 0))) {
height -= supplied.toInt() // This allows scrolling until only the last button is visible at the top
if (buttons.isNotEmpty()) (height / 8).let { val maxScroll = max(0, buttons.size - 1)
if (it > 0) barStage = it
} val step = when {
} supplied < 0 -> 1
} supplied > 0 -> -1
else -> 0
} }
if (step == 0) return
barStage = (barStage + step).coerceIn(0, maxScroll)
} }
companion object { companion object {
@ -69,7 +75,6 @@ class ClickBox(
} }
} }
var sortAlphabetically: Boolean by Configuration var sortAlphabetically: Boolean by Configuration
const val buttonsMax: Short = 16 // TODO Remove the buttons limit
const val clickboxHeightOffset: Int = 80 const val clickboxHeightOffset: Int = 80
private const val inclination: Float = 2.5F private const val inclination: Float = 2.5F
} }
@ -115,25 +120,38 @@ class ClickBox(
val barWidth = 3 val barWidth = 3
val leftPadding = 3 val leftPadding = 3
val gapToBar = 1 val gapToBar = 1
val rowHeight = 9
val visibleRows = 8
val maxScroll = max(0, buttons.size - visibleRows)
val actualContentHeight = min(buttons.size, visibleRows) * rowHeight
val minBarH = 8
val currentBarH = if (maxScroll == 0) minBarH
else minBarH + ((actualContentHeight - minBarH).toFloat() * barStage / maxScroll).roundToInt()
buttonsProgressBar.apply { buttonsProgressBar.apply {
this.width = barWidth this.width = barWidth
this.x = this@ClickBox.x + this@ClickBox.width - barWidth this.height = currentBarH.coerceAtMost(actualContentHeight)
this.y = this@ClickBox.y + this@ClickBox.height + 3 this.x = (xi + this@ClickBox.width - barWidth).toDouble()
this.y = (yi + this@ClickBox.height + 3).toDouble()
}.display(guiGraphics) }.display(guiGraphics)
val buttonWidth = (this@ClickBox.width - leftPadding - barWidth - gapToBar).coerceAtLeast(10) val buttonWidth = (this@ClickBox.width - leftPadding - barWidth - gapToBar).coerceAtLeast(10)
val contentStartY = yi + height + 3
val maxContentY = contentStartY + (8 * 9)
buttons.forEachIndexed { num, button -> buttons.forEachIndexed { num, button ->
val fullHeight = (y + height.toDouble())..(this.y + height + clickboxHeightOffset) val rowOffset = num - barStage
val yPos = contentStartY + (rowOffset * 9)
button.also { button.also {
it.x = this.x + leftPadding it.x = (xi + leftPadding).toDouble()
it.y = this.y + 3 + height + (((num + 1) - barStage) * 9) it.y = yPos.toDouble()
it.width = buttonWidth it.width = buttonWidth
it.hidden = (rowOffset < 0) || (yPos + it.height > maxContentY)
it.hidden =
if ((num + 1) <= 8) ((it.y) !in fullHeight)
else ((it.y + it.height) !in fullHeight)
}.display(guiGraphics) }.display(guiGraphics)
} }
} }

View File

@ -7,7 +7,6 @@
"screen.snowy.config.general.macros.missingelement": "Missing element(s) next to the separator", "screen.snowy.config.general.macros.missingelement": "Missing element(s) next to the separator",
"screen.snowy.config.general.macros.toomuchdelimiters": "Too much separators (only one is allowed)", "screen.snowy.config.general.macros.toomuchdelimiters": "Too much separators (only one is allowed)",
"screen.snowy.config.general.macros.toomuchcharacters": "Too much characters (16 is the maximum)", "screen.snowy.config.general.macros.toomuchcharacters": "Too much characters (16 is the maximum)",
"screen.snowy.config.general.macros.toomuchbuttons": "Too much entries (16 is the maximum)",
"screen.snowy.config.colors": "Box colors", "screen.snowy.config.colors": "Box colors",
"screen.snowy.config.behavior": "Behavior", "screen.snowy.config.behavior": "Behavior",
"screen.snowy.config.behavior.sortalphabetically": "Sort buttons alphabetically", "screen.snowy.config.behavior.sortalphabetically": "Sort buttons alphabetically",

View File

@ -7,7 +7,6 @@
"screen.snowy.config.general.macros.missingelement": "Élément(s) manquant(s) avant ou après le séparateur", "screen.snowy.config.general.macros.missingelement": "Élément(s) manquant(s) avant ou après le séparateur",
"screen.snowy.config.general.macros.toomuchdelimiters": "Séparateurs trop nombreux (un seul est autorisé)", "screen.snowy.config.general.macros.toomuchdelimiters": "Séparateurs trop nombreux (un seul est autorisé)",
"screen.snowy.config.general.macros.toomuchcharacters": "Trop de caractères (le maximum est de 16)", "screen.snowy.config.general.macros.toomuchcharacters": "Trop de caractères (le maximum est de 16)",
"screen.snowy.config.general.macros.toomuchbuttons": "Trop d'entrées (le maximum est de 16)",
"screen.snowy.config.colors": "Couleurs des boîtes", "screen.snowy.config.colors": "Couleurs des boîtes",
"screen.snowy.config.behavior": "Comportement", "screen.snowy.config.behavior": "Comportement",
"screen.snowy.config.behavior.sortalphabetically": "Trier les boutons alphabétiquement", "screen.snowy.config.behavior.sortalphabetically": "Trier les boutons alphabétiquement",