aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/features/inventory/buttons/InventoryButtons.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/features/inventory/buttons/InventoryButtons.kt')
-rw-r--r--src/main/kotlin/features/inventory/buttons/InventoryButtons.kt109
1 files changed, 54 insertions, 55 deletions
diff --git a/src/main/kotlin/features/inventory/buttons/InventoryButtons.kt b/src/main/kotlin/features/inventory/buttons/InventoryButtons.kt
index f49e6ab..47fdbe9 100644
--- a/src/main/kotlin/features/inventory/buttons/InventoryButtons.kt
+++ b/src/main/kotlin/features/inventory/buttons/InventoryButtons.kt
@@ -1,5 +1,3 @@
-
-
package moe.nea.firmament.features.inventory.buttons
import me.shedaniel.math.Rectangle
@@ -13,32 +11,33 @@ import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.HandledScreenClickEvent
import moe.nea.firmament.events.HandledScreenForegroundEvent
import moe.nea.firmament.events.HandledScreenPushREIEvent
-import moe.nea.firmament.util.data.ManagedConfig
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.ScreenUtil
import moe.nea.firmament.util.TimeMark
-import moe.nea.firmament.util.data.DataHolder
import moe.nea.firmament.util.accessors.getRectangle
import moe.nea.firmament.util.data.Config
+import moe.nea.firmament.util.data.DataHolder
+import moe.nea.firmament.util.data.ManagedConfig
import moe.nea.firmament.util.gold
object InventoryButtons {
@Config
- object TConfig : ManagedConfig("inventory-buttons-config", Category.INVENTORY) {
- val _openEditor by button("open-editor") {
- openEditor()
- }
+ object TConfig : ManagedConfig("inventory-buttons-config", Category.INVENTORY) {
+ val _openEditor by button("open-editor") {
+ openEditor()
+ }
val hoverText by toggle("hover-text") { true }
val onlyInv by toggle("only-inv") { false }
- }
+ }
- object DConfig : DataHolder<Data>(serializer(), "inventory-buttons", ::Data)
+ @Config
+ object DConfig : DataHolder<Data>(serializer(), "inventory-buttons", ::Data)
- @Serializable
- data class Data(
- var buttons: MutableList<InventoryButton> = mutableListOf()
- )
+ @Serializable
+ data class Data(
+ var buttons: MutableList<InventoryButton> = mutableListOf()
+ )
fun getValidButtons(screen: HandledScreen<*>): Sequence<InventoryButton> {
return DConfig.data.buttons.asSequence().filter { button ->
@@ -47,41 +46,41 @@ object InventoryButtons {
}
- @Subscribe
- fun onRectangles(it: HandledScreenPushREIEvent) {
- val bounds = it.screen.getRectangle()
- for (button in getValidButtons(it.screen)) {
- val buttonBounds = button.getBounds(bounds)
- it.block(buttonBounds)
- }
- }
+ @Subscribe
+ fun onRectangles(it: HandledScreenPushREIEvent) {
+ val bounds = it.screen.getRectangle()
+ for (button in getValidButtons(it.screen)) {
+ val buttonBounds = button.getBounds(bounds)
+ it.block(buttonBounds)
+ }
+ }
- @Subscribe
- fun onClickScreen(it: HandledScreenClickEvent) {
- val bounds = it.screen.getRectangle()
- for (button in getValidButtons(it.screen)) {
- val buttonBounds = button.getBounds(bounds)
- if (buttonBounds.contains(it.mouseX, it.mouseY)) {
- MC.sendCommand(button.command!! /* non null invariant covered by getValidButtons */)
- break
- }
- }
- }
+ @Subscribe
+ fun onClickScreen(it: HandledScreenClickEvent) {
+ val bounds = it.screen.getRectangle()
+ for (button in getValidButtons(it.screen)) {
+ val buttonBounds = button.getBounds(bounds)
+ if (buttonBounds.contains(it.mouseX, it.mouseY)) {
+ MC.sendCommand(button.command!! /* non null invariant covered by getValidButtons */)
+ break
+ }
+ }
+ }
var lastHoveredComponent: InventoryButton? = null
var lastMouseMove = TimeMark.farPast()
- @Subscribe
- fun onRenderForeground(it: HandledScreenForegroundEvent) {
+ @Subscribe
+ fun onRenderForeground(it: HandledScreenForegroundEvent) {
val bounds = it.screen.getRectangle()
var hoveredComponent: InventoryButton? = null
for (button in getValidButtons(it.screen)) {
- val buttonBounds = button.getBounds(bounds)
- it.context.matrices.pushMatrix()
- it.context.matrices.translate(buttonBounds.minX.toFloat(), buttonBounds.minY.toFloat())
- button.render(it.context)
- it.context.matrices.popMatrix()
+ val buttonBounds = button.getBounds(bounds)
+ it.context.matrices.pushMatrix()
+ it.context.matrices.translate(buttonBounds.minX.toFloat(), buttonBounds.minY.toFloat())
+ button.render(it.context)
+ it.context.matrices.popMatrix()
if (buttonBounds.contains(it.mouseX, it.mouseY) && TConfig.hoverText && hoveredComponent == null) {
hoveredComponent = button
@@ -94,23 +93,23 @@ object InventoryButtons {
)
}
}
- }
+ }
if (hoveredComponent !== lastHoveredComponent)
lastMouseMove = TimeMark.now()
lastHoveredComponent = hoveredComponent
- lastRectangle = bounds
- }
+ lastRectangle = bounds
+ }
- var lastRectangle: Rectangle? = null
- fun openEditor() {
- ScreenUtil.setScreenLater(
- InventoryButtonEditor(
- lastRectangle ?: Rectangle(
- MC.window.scaledWidth / 2 - 88,
- MC.window.scaledHeight / 2 - 83,
- 176, 166,
- )
- )
- )
- }
+ var lastRectangle: Rectangle? = null
+ fun openEditor() {
+ ScreenUtil.setScreenLater(
+ InventoryButtonEditor(
+ lastRectangle ?: Rectangle(
+ MC.window.scaledWidth / 2 - 88,
+ MC.window.scaledHeight / 2 - 83,
+ 176, 166,
+ )
+ )
+ )
+ }
}