@@ -13,7 +13,6 @@ import gay.`object`.hexdebug.utils.falpha
1313import gay.`object`.hexdebug.utils.fblue
1414import gay.`object`.hexdebug.utils.fgreen
1515import gay.`object`.hexdebug.utils.fred
16- import net.minecraft.ChatFormatting
1716import net.minecraft.client.Minecraft
1817import net.minecraft.client.gui.GuiGraphics
1918import net.minecraft.client.gui.components.AbstractButton
@@ -69,20 +68,8 @@ class SplicingTableScreen(
6968 private val staffMinY get() = topPos
7069 private val staffMaxY get() = topPos + staffHeight
7170
72- private val iotaButtons = mutableListOf<AbstractButton >()
73- private val edgeButtons = mutableListOf<AbstractButton >()
7471 private val predicateButtons = mutableListOf<Pair <AbstractButton , () - > Boolean >> ()
7572
76- private val listReadButtons = sequenceOf(
77- iotaButtons,
78- edgeButtons,
79- ).flatten()
80-
81- private val allButtons = sequenceOf(
82- listReadButtons,
83- predicateButtons.asSequence().map { it.first },
84- ).flatten()
85-
8673 private var viewStartIndex = 0
8774 set(value) {
8875 val clamped = if (data.list?.let { it.size > IOTA_BUTTONS } == true ) {
@@ -104,24 +91,8 @@ class SplicingTableScreen(
10491
10592 titleLabelX = (imageWidth - font.width(title)) / 2
10693
107- iotaButtons.clear()
108- edgeButtons.clear()
10994 predicateButtons.clear()
11095
111- iotaButtons + = (0 until IOTA_BUTTONS ).map { offset ->
112- Button .builder(Component .empty()) { onSelectIota(viewStartIndex + offset) }
113- .pos(leftPos + 20 + offset * 26 , topPos - 18 )
114- .size(22 , 16 )
115- .build()
116- }
117-
118- edgeButtons + = (0 .. IOTA_BUTTONS ).map { offset ->
119- Button .builder(Component .empty()) { onSelectEdge(viewStartIndex + offset) }
120- .pos(leftPos + 16 + offset * 26 , topPos - 18 )
121- .size(4 , 16 )
122- .build()
123- }
124-
12596 clearGridButton = object : SpriteButton (
12697 x = (staffMinX + staffMaxX) / 2 - 19 ,
12798 y = staffMaxY - 10 ,
@@ -340,14 +311,20 @@ class SplicingTableScreen(
340311 }.toTypedArray(),
341312 )
342313
343- allButtons.forEach(::addRenderableWidget)
314+ for ((button, _) in predicateButtons) {
315+ addRenderableWidget(button)
316+ }
344317
345318 val iotaButtons = (0 until IOTA_BUTTONS ).map { offset ->
346319 addRenderableWidget(IotaButton (offset))
347320 }
348321
349322 for (button in iotaButtons) {
350- addRenderableOnly(IotaSelection (button))
323+ addRenderableOnly(IotaRangeSelection (button))
324+ }
325+
326+ for (offset in 0 until IOTA_BUTTONS + 1 ) {
327+ addRenderableWidget(IotaEdgeSelection (offset))
351328 }
352329
353330 addRenderableWidget(
@@ -396,7 +373,6 @@ class SplicingTableScreen(
396373 if (viewStartIndex != 0 ) viewStartIndex = 0
397374 }
398375 updateActiveButtons()
399- updateIotaButtons()
400376 for (child in children()) {
401377 if (child is SplicingTableButton ) {
402378 child.reload()
@@ -405,52 +381,8 @@ class SplicingTableScreen(
405381 }
406382
407383 private fun updateActiveButtons () {
408- val data = data
409- if (data.isListReadable) {
410- setActive(listReadButtons, true )
411- for ((button, predicate) in predicateButtons) {
412- button.active = predicate()
413- }
414- } else {
415- setActive(allButtons, false )
416- }
417- }
418-
419- private fun setActive (buttons : Sequence <AbstractButton >, active : Boolean ) {
420- for (button in buttons) {
421- button.active = active
422- }
423- }
424-
425- private fun updateIotaButtons () {
426- iotaButtons.forEachIndexed { offset, button ->
427- val index = viewStartIndex + offset
428- val formats = if (isIotaSelected(index)) {
429- arrayOf(ChatFormatting .BOLD , ChatFormatting .UNDERLINE )
430- } else {
431- arrayOf()
432- }
433- button.apply {
434- val iotaView = data.list?.getOrNull(index)
435- if (null != iotaView) {
436- message = index.toString().asTranslatedComponent.withStyle(* formats)
437- tooltip = Tooltip .create(iotaView.name)
438- } else {
439- message = Component .empty()
440- tooltip = null
441- active = false
442- }
443- }
444- }
445-
446- edgeButtons.forEachIndexed { offset, button ->
447- val index = viewStartIndex + offset
448- button.apply {
449- setAlpha(if (isEdgeSelected(index)) 1f else 0.3f )
450- if (! (data.isInRange(index) || data.isInRange(index - 1 ))) {
451- active = false
452- }
453- }
384+ for ((button, predicate) in predicateButtons) {
385+ button.active = data.isListReadable && predicate()
454386 }
455387 }
456388
@@ -752,66 +684,47 @@ class SplicingTableScreen(
752684 override val iotaView get() = data.list?.getOrNull(index)
753685
754686 override fun onPress () {
687+ HexDebug .LOGGER .info(" button pressed" )
755688 onSelectIota(index)
756689 }
757690
691+ override fun testHitbox (mouseX : Double , mouseY : Double ): Boolean {
692+ // skip hitbox if hovering over an edge selection
693+ // FIXME: hack
694+ return super .testHitbox(mouseX, mouseY) && mouseX >= x + 2 && mouseX < x + width - 2
695+ }
696+
758697 init {
759698 reload()
760699 }
761700 }
762701
763- inner class IotaSelection (button : IotaButton ) : Renderable {
702+ // TODO: hover texture?
703+ inner class IotaRangeSelection (button : IotaButton ) : Renderable {
764704 private val offset by button::offset
765705 private val index by button::index
766- private val backgroundType by button::backgroundType
767706
768707 override fun render (guiGraphics : GuiGraphics , mouseX : Int , mouseY : Int , partialTick : Float ) {
769- if (! data.isInRange(index) || backgroundType == null ) return
770- RenderSystem .enableBlend()
771- when (val selection = selection) {
772- is Selection .Range -> if (index in selection) {
773- drawRangeSelection(
774- guiGraphics, offset,
775- leftEdge = index == selection.start,
776- rightEdge = index == selection.end,
777- )
708+ val selection = selection
709+ if (data.isInRange(index) && selection is Selection .Range && index in selection) {
710+ RenderSystem .enableBlend()
711+ blitSprite(
712+ guiGraphics,
713+ x = leftPos + 15 + 18 * offset,
714+ y = topPos + 18 ,
715+ uOffset = 352 ,
716+ vOffset = 24 ,
717+ width = 18 ,
718+ height = 25 ,
719+ )
720+ if (index == selection.start) {
721+ drawSelectionEndCap(guiGraphics, offset, SelectionEndCap .LEFT )
778722 }
779- is Selection . Edge -> if (index == selection.index ) {
780- drawEdgeSelection (guiGraphics, offset)
723+ if (index == selection.end ) {
724+ drawSelectionEndCap (guiGraphics, offset, SelectionEndCap . RIGHT )
781725 }
782- null -> {}
726+ RenderSystem .disableBlend()
783727 }
784- RenderSystem .disableBlend()
785- }
786-
787- private fun drawRangeSelection (guiGraphics : GuiGraphics , offset : Int , leftEdge : Boolean , rightEdge : Boolean ) {
788- blitSprite(
789- guiGraphics,
790- x = leftPos + 15 + 18 * offset,
791- y = topPos + 18 ,
792- uOffset = 352 ,
793- vOffset = 24 ,
794- width = 18 ,
795- height = 25 ,
796- )
797- if (leftEdge) {
798- drawSelectionEndCap(guiGraphics, offset, SelectionEndCap .LEFT )
799- }
800- if (rightEdge) {
801- drawSelectionEndCap(guiGraphics, offset, SelectionEndCap .RIGHT )
802- }
803- }
804-
805- private fun drawEdgeSelection (guiGraphics : GuiGraphics , offset : Int ) {
806- blitSprite(
807- guiGraphics,
808- x = leftPos + 13 + 18 * offset,
809- y = topPos + 23 ,
810- uOffset = 375 ,
811- vOffset = 29 ,
812- width = 4 ,
813- height = 15 ,
814- )
815728 }
816729
817730 private fun drawSelectionEndCap (guiGraphics : GuiGraphics , offset : Int , endCap : SelectionEndCap ) {
@@ -826,6 +739,40 @@ class SplicingTableScreen(
826739 )
827740 }
828741 }
742+
743+ inner class IotaEdgeSelection (private val offset : Int ) : SplicingTableButton(
744+ x = leftPos + 13 + 18 * offset,
745+ y = topPos + 23 ,
746+ width = 4 ,
747+ height = 15 ,
748+ message = null ,
749+ ) {
750+ override val uOffset = 375
751+ override val vOffset = 29
752+
753+ override val uOffsetHovered get() = uOffset
754+ override val vOffsetHovered get() = vOffset + 405
755+
756+ override val uOffsetDisabled get() = uOffset
757+ override val vOffsetDisabled get() = vOffset
758+
759+ private val index get() = viewStartIndex + offset
760+
761+ override fun testVisible () = data.isInRange(index) || data.isInRange(index - 1 )
762+
763+ override fun renderWidget (guiGraphics : GuiGraphics , mouseX : Int , mouseY : Int , partialTick : Float ) {
764+ if (isHovered || index == (selection as ? Selection .Edge )?.index) {
765+ RenderSystem .enableBlend()
766+ super .renderWidget(guiGraphics, mouseX, mouseY, partialTick)
767+ RenderSystem .disableBlend()
768+ }
769+ }
770+
771+ override fun onPress () {
772+ HexDebug .LOGGER .info(" edge pressed" )
773+ onSelectEdge(index)
774+ }
775+ }
829776}
830777
831778fun GuiGraphics.setColor (color : Color ) = setColor(color.fred, color.fgreen, color.fblue, color.falpha)
0 commit comments