1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
package at.hannibal2.skyhanni.utils.guide
import at.hannibal2.skyhanni.utils.RenderUtils.HorizontalAlignment
import at.hannibal2.skyhanni.utils.RenderUtils.VerticalAlignment
import at.hannibal2.skyhanni.utils.SoundUtils
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXYAligned
import net.minecraft.client.gui.Gui
import net.minecraft.item.ItemStack
class GuideTab(
val item: ItemStack,
val tip: Renderable,
val isVertical: Boolean = false,
var lastTab: GuideGUI.tabWrapper,
val onClick: (GuideTab) -> Unit
) {
fun fakeClick() = click()
private fun click() {
onClick.invoke(this)
this.select()
if (lastTab.tab != this) {
lastTab.tab?.unSelect()
lastTab.tab = this
}
}
fun select() {
selectColor = selectedColor
}
fun unSelect() {
selectColor = notSelectedColor
}
fun isSelected() = selectColor == selectedColor
val width = if (isVertical) tabLongSide else tabShortSide
val height = if (isVertical) tabShortSide else tabLongSide
private var selectColor = notSelectedColor
private val renderable = Renderable.clickAndHover(object : Renderable {
override val width = this@GuideTab.width
override val height = this@GuideTab.height
override val horizontalAlign: HorizontalAlignment = HorizontalAlignment.LEFT
override val verticalAlign: VerticalAlignment = VerticalAlignment.TOP
val itemRender = Renderable.itemStack(
item, 1.0, horizontalAlign = HorizontalAlignment.CENTER, verticalAlign = VerticalAlignment.CENTER
)
override fun render(posX: Int, posY: Int) {
Gui.drawRect(0, 0, width, height, selectColor)
itemRender.renderXYAligned(posX, posY, width, height)
}
}, listOf(tip), onClick = {
click()
SoundUtils.playClickSound()
})
fun render(posX: Int, posY: Int) {
renderable.render(posX, posY)
}
}
|