package net.shadowfacts.phycon.client.screen import net.minecraft.client.gui.widget.AbstractPressableButtonWidget import net.shadowfacts.phycon.util.FriendlyNameable import net.shadowfacts.phycon.util.RotatableEnum import net.shadowfacts.phycon.util.next import net.shadowfacts.phycon.util.prev import kotlin.reflect.KMutableProperty /** * @author shadowfacts */ class EnumButton( val prop: KMutableProperty, x: Int, y: Int, width: Int, height: Int, val onChange: () -> Unit ): AbstractPressableButtonWidget( x, y, width, height, prop.getter.call().friendlyName ) where E: Enum, E: RotatableEnum, E: FriendlyNameable { private var currentButton: Int? = null override fun mouseClicked(d: Double, e: Double, button: Int): Boolean { currentButton = button val res = super.mouseClicked(d, e, button) currentButton = null return res } override fun isValidClickButton(i: Int): Boolean { return i == 0 || i == 1 } override fun onPress() { val newVal = if ((currentButton ?: 0) == 0) prop.getter.call().next else prop.getter.call().prev prop.setter.call(newVal) message = newVal.friendlyName onChange() } }