aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/cc/woverflow/chatting/gui/components/TabButton.kt
blob: e3b96f10e0e68d6852e562dd6657adb9b569e008 (plain)
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
package cc.woverflow.chatting.gui.components

import cc.polyfrost.oneconfig.libs.universal.UKeyboard
import cc.polyfrost.oneconfig.libs.universal.UResolution
import cc.woverflow.chatting.chat.ChatTab
import cc.woverflow.chatting.chat.ChatTabs
import cc.woverflow.chatting.config.ChattingConfig

class TabButton(buttonId: Int, x: Int, widthIn: Int, heightIn: Int, private val chatTab: ChatTab) :
    CleanButton(buttonId, { x }, {
        UResolution.scaledHeight - 26
    }, widthIn, heightIn, chatTab.name, { RenderType.values()[ChattingConfig.textRenderType] }, { packedFGColour: Int, enabled: Boolean, hovered: Boolean ->
        var j = chatTab.color ?: color
        if (packedFGColour != 0) {
            j = packedFGColour
        } else if (!enabled) {
            j = chatTab.selectedColor ?: selectedColor
        } else if (hovered) {
            j = chatTab.hoveredColor ?: hoveredColor
        }
        j
    }) {

    override fun onMousePress() {
        if (UKeyboard.isShiftKeyDown()) {
            if (ChatTabs.currentTabs.contains(chatTab)) {
                ChatTabs.currentTabs.remove(chatTab)
            } else {
                ChatTabs.currentTabs.add(chatTab)
            }
        } else {
            ChatTabs.currentTabs.clear()
            ChatTabs.currentTabs.add(chatTab)
        }
    }

    override fun isEnabled(): Boolean {
        return ChatTabs.currentTabs.contains(chatTab)
    }

    companion object {
        const val color: Int = 14737632
        const val hoveredColor: Int = 16777120
        const val selectedColor: Int = 10526880
    }
}