package net.shadowfacts.phycon.block.terminal import net.minecraft.util.Identifier import net.shadowfacts.cacao.geometry.Point import net.shadowfacts.cacao.geometry.Size import net.shadowfacts.cacao.util.EnumHelper import net.shadowfacts.cacao.util.MouseButton import net.shadowfacts.cacao.util.texture.Texture import net.shadowfacts.cacao.view.TextureView import net.shadowfacts.cacao.view.button.AbstractButton import net.shadowfacts.phycon.PhysicalConnectivity import net.shadowfacts.phycon.util.SortMode /** * @author shadowfacts */ class SortModeButton( initialValue: SortMode, ): AbstractButton( TextureView(TEXTURES[initialValue]!!).apply { intrinsicContentSize = Size(16.0, 16.0) } ) { companion object { private val ID = Identifier(PhysicalConnectivity.MODID, "textures/gui/terminal.png") private val TEXTURES = mapOf( SortMode.COUNT_HIGH_FIRST to Texture(ID, 0, 230), SortMode.COUNT_LOW_FIRST to Texture(ID, 16, 230), SortMode.ALPHABETICAL to Texture(ID, 32, 230), ) } private val textureView: TextureView get() = content as TextureView var value: SortMode = initialValue set(value) { field = value textureView.texture = TEXTURES[value]!! } override fun mouseClicked(point: Point, mouseButton: MouseButton): Boolean { if (!disabled) { value = when (mouseButton) { MouseButton.LEFT -> EnumHelper.next(value) MouseButton.RIGHT -> EnumHelper.previous(value) else -> { return false } } } return super.mouseClicked(point, mouseButton) } }