Remove the buttons limit
Signed-off-by: Username404-59 <w.iron.zombie@gmail.com>
This commit is contained in:
parent
174f840226
commit
965421b99f
@ -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 {
|
||||
|
||||
@ -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
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user