diff --git a/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt b/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt index 14dab21..5979fa0 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt @@ -2,7 +2,6 @@ package fr.username404.snowygui.config import fr.username404.snowygui.ClickGui 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.feature.* import fr.username404.snowygui.utils.FontUtil @@ -75,9 +74,7 @@ val SnowyConfigScreen: Screen = object: Screen(translationComponent) { }.build()).addEntry(startStrList( Category.MACROS.box.name, macrosButtons.getTitleCommand() - ).setInsertInFront(false).setDefaultValue(Configuration.foundMacros.getTitleCommand()).setErrorSupplier { list -> - supplyComponent(if (list.size > buttonsMax) "$confPrefix.general.macros.toomuchbuttons" else null) - }.setCellErrorSupplier { cell -> + ).setInsertInFront(false).setDefaultValue(Configuration.foundMacros.getTitleCommand()).setCellErrorSupplier { cell -> with(cell.split(":")) { supplyComponent( when { diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt index 7037c1e..6ae4f6a 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt @@ -13,6 +13,8 @@ import net.minecraft.client.gui.GuiGraphics import net.minecraft.network.chat.Component import net.minecraft.util.ARGB import kotlin.math.floor +import kotlin.math.max +import kotlin.math.min import kotlin.math.roundToInt import org.jetbrains.annotations.ApiStatus import java.util.TreeSet @@ -23,7 +25,7 @@ class ClickBox( x: Double, y: Double, val name: Component = MissingComponent, 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) val buttons: MutableSet = if (sortAlphabetically) @@ -47,19 +49,23 @@ class ClickBox( init { height = 8 } } - var barStage: Int = 1; private set + var barStage: Int = 0; private set fun scroll(d: Double, e: Double, supplied: Double) { - if (isWithinBounds(d, e, offsetHeight = clickboxHeightOffset.toDouble())) { - with(buttonsProgressBar) { - if ((height > 8 || (supplied < 0)) && (((height < (buttons.size * 8)) && (height < originalHeight)) || (supplied > 0))) { - height -= supplied.toInt() - if (buttons.isNotEmpty()) (height / 8).let { - if (it > 0) barStage = it - } - } - } + if (!isWithinBounds(d, e, offsetHeight = clickboxHeightOffset.toDouble())) return + if (buttons.isEmpty()) return + + // This allows scrolling until only the last button is visible at the top + val maxScroll = max(0, buttons.size - 1) + + val step = when { + supplied < 0 -> 1 + supplied > 0 -> -1 + else -> 0 } + if (step == 0) return + + barStage = (barStage + step).coerceIn(0, maxScroll) } companion object { @@ -69,7 +75,6 @@ class ClickBox( } } var sortAlphabetically: Boolean by Configuration - const val buttonsMax: Short = 16 // TODO Remove the buttons limit const val clickboxHeightOffset: Int = 80 private const val inclination: Float = 2.5F } @@ -115,25 +120,38 @@ class ClickBox( val barWidth = 3 val leftPadding = 3 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 { this.width = barWidth - this.x = this@ClickBox.x + this@ClickBox.width - barWidth - this.y = this@ClickBox.y + this@ClickBox.height + 3 + this.height = currentBarH.coerceAtMost(actualContentHeight) + this.x = (xi + this@ClickBox.width - barWidth).toDouble() + this.y = (yi + this@ClickBox.height + 3).toDouble() }.display(guiGraphics) val buttonWidth = (this@ClickBox.width - leftPadding - barWidth - gapToBar).coerceAtLeast(10) + + val contentStartY = yi + height + 3 + val maxContentY = contentStartY + (8 * 9) buttons.forEachIndexed { num, button -> - val fullHeight = (y + height.toDouble())..(this.y + height + clickboxHeightOffset) + val rowOffset = num - barStage + val yPos = contentStartY + (rowOffset * 9) + button.also { - it.x = this.x + leftPadding - it.y = this.y + 3 + height + (((num + 1) - barStage) * 9) - + it.x = (xi + leftPadding).toDouble() + it.y = yPos.toDouble() it.width = buttonWidth - - it.hidden = - if ((num + 1) <= 8) ((it.y) !in fullHeight) - else ((it.y + it.height) !in fullHeight) + it.hidden = (rowOffset < 0) || (yPos + it.height > maxContentY) }.display(guiGraphics) } } diff --git a/common/src/main/resources/assets/snowygui/lang/en_us.json b/common/src/main/resources/assets/snowygui/lang/en_us.json index 2ce6b76..2d1b43d 100644 --- a/common/src/main/resources/assets/snowygui/lang/en_us.json +++ b/common/src/main/resources/assets/snowygui/lang/en_us.json @@ -7,7 +7,6 @@ "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.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.behavior": "Behavior", "screen.snowy.config.behavior.sortalphabetically": "Sort buttons alphabetically", diff --git a/common/src/main/resources/assets/snowygui/lang/fr_fr.json b/common/src/main/resources/assets/snowygui/lang/fr_fr.json index 0aa901c..db4e20e 100644 --- a/common/src/main/resources/assets/snowygui/lang/fr_fr.json +++ b/common/src/main/resources/assets/snowygui/lang/fr_fr.json @@ -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.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.toomuchbuttons": "Trop d'entrées (le maximum est de 16)", "screen.snowy.config.colors": "Couleurs des boîtes", "screen.snowy.config.behavior": "Comportement", "screen.snowy.config.behavior.sortalphabetically": "Trier les boutons alphabétiquement",