Skip to content

Commit 1a3e932

Browse files
committed
Implement splicing table scrolling (close #35)
1 parent a1384c4 commit 1a3e932

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

Common/src/main/kotlin/gay/object/hexdebug/config/HexDebugConfig.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ object HexDebugConfig {
8080

8181
@Tooltip
8282
val showDebugClientLineNumber: Boolean = false
83+
84+
@Tooltip
85+
val invertSplicingTableScrollDirection: Boolean = false
8386
}
8487

8588
@Config(name = "server")

Common/src/main/kotlin/gay/object/hexdebug/gui/splicing/SplicingTableScreen.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import at.petrak.hexcasting.client.gui.GuiSpellcasting
55
import at.petrak.hexcasting.common.lib.HexSounds
66
import com.mojang.blaze3d.systems.RenderSystem
77
import gay.`object`.hexdebug.HexDebug
8+
import gay.`object`.hexdebug.config.HexDebugConfig
89
import gay.`object`.hexdebug.gui.splicing.widgets.*
910
import gay.`object`.hexdebug.splicing.IOTA_BUTTONS
1011
import gay.`object`.hexdebug.splicing.Selection
@@ -24,7 +25,10 @@ import net.minecraft.world.InteractionHand
2425
import net.minecraft.world.entity.player.Inventory
2526
import java.awt.Color
2627
import java.util.function.BiConsumer
28+
import kotlin.math.absoluteValue
29+
import kotlin.math.min
2730
import kotlin.math.pow
31+
import kotlin.math.roundToInt
2832

2933
@Suppress("SameParameterValue")
3034
class SplicingTableScreen(
@@ -467,6 +471,41 @@ class SplicingTableScreen(
467471
)
468472
}
469473

474+
// TODO: limit scroll to certain regions? (let's see if anyone complains first)
475+
override fun mouseScrolled(mouseX: Double, mouseY: Double, delta: Double): Boolean {
476+
if (super.mouseScrolled(mouseX, mouseY, delta)) return true
477+
478+
val adjustedDelta = if (HexDebugConfig.client.invertSplicingTableScrollDirection) {
479+
delta * -1
480+
} else {
481+
delta
482+
}
483+
484+
val action = if (adjustedDelta > 0) {
485+
when {
486+
hasControlDown() -> SplicingTableAction.VIEW_LEFT_FULL
487+
hasShiftDown() -> SplicingTableAction.VIEW_LEFT_PAGE
488+
else -> SplicingTableAction.VIEW_LEFT
489+
}
490+
} else {
491+
when {
492+
hasControlDown() -> SplicingTableAction.VIEW_RIGHT_FULL
493+
hasShiftDown() -> SplicingTableAction.VIEW_RIGHT_PAGE
494+
else -> SplicingTableAction.VIEW_RIGHT
495+
}
496+
}
497+
498+
if (!action.test()) return false
499+
500+
// hack: limit scrolls per tick to 4 (arbitrary) to prevent DoS
501+
// (this could be easily solved by adding a new packet, but lazy)
502+
repeat(min(delta.absoluteValue.roundToInt(), 4)) {
503+
menu.table.runAction(action, null)
504+
}
505+
506+
return true
507+
}
508+
470509
// staff delegation stuff
471510

472511
override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {

Common/src/main/resources/assets/hexdebug/lang/en_us.flatten.json5

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@
8181
showDebugClientLineNumber: {
8282
"": "Show Debug Client Line Number",
8383
"@Tooltip": "If true, show the line number (usually 1-indexed) from the debug client (eg. VSCode) in Debugger status messages; otherwise, show the list index (0-indexed)."
84+
},
85+
invertSplicingTableScrollDirection: {
86+
"": "Invert Splicing Table Scroll Direction",
87+
"@Tooltip": "Whether scrolling up (as opposed to down) will increase the view index of the splicing table, and vice versa.",
8488
}
8589
},
8690
server: {

0 commit comments

Comments
 (0)