package at.hannibal2.skyhanni.utils.renderables
import at.hannibal2.skyhanni.config.core.config.gui.GuiPositionEditor
import at.hannibal2.skyhanni.config.features.skillprogress.SkillProgressBarConfig
import at.hannibal2.skyhanni.data.GuiData
import at.hannibal2.skyhanni.data.HighlightOnHoverSlot
import at.hannibal2.skyhanni.data.ToolTipData
import at.hannibal2.skyhanni.features.chroma.ChromaShaderManager
import at.hannibal2.skyhanni.features.chroma.ChromaType
import at.hannibal2.skyhanni.features.misc.DarkenShader
import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper
import at.hannibal2.skyhanni.utils.CollectionUtils.contains
import at.hannibal2.skyhanni.utils.ColorUtils
import at.hannibal2.skyhanni.utils.ColorUtils.addAlpha
import at.hannibal2.skyhanni.utils.ColorUtils.darker
import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyClicked
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzLogger
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.NEUItems.renderOnScreen
import at.hannibal2.skyhanni.utils.RenderUtils
import at.hannibal2.skyhanni.utils.RenderUtils.HorizontalAlignment
import at.hannibal2.skyhanni.utils.RenderUtils.VerticalAlignment
import at.hannibal2.skyhanni.utils.guide.GuideGUI
import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.calculateTableXOffsets
import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.calculateTableYOffsets
import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXAligned
import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXYAligned
import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderYAligned
import at.hannibal2.skyhanni.utils.shader.ShaderManager
import io.github.notenoughupdates.moulconfig.gui.GuiScreenElementWrapper
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.Gui
import net.minecraft.client.gui.GuiIngameMenu
import net.minecraft.client.gui.inventory.GuiEditSign
import net.minecraft.client.gui.inventory.GuiInventory.drawEntityOnScreen
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import net.minecraft.util.ResourceLocation
import java.awt.Color
import java.util.Collections
import kotlin.math.max
interface Renderable {
val width: Int
val height: Int
val horizontalAlign: HorizontalAlignment
val verticalAlign: VerticalAlignment
fun isHovered(posX: Int, posY: Int) = currentRenderPassMousePosition?.let { (x, y) ->
x in (posX..posX + width) && y in (posY..posY + height) // TODO: adjust for variable height?
} ?: false
/**
* Pos x and pos y are relative to the mouse position.
* (the GL matrix stack should already be pre transformed)
*/
fun render(posX: Int, posY: Int)
companion object {
val logger = LorenzLogger("debug/renderable")
var currentRenderPassMousePosition: Pair<Int, Int>? = null
set
fun <T> withMousePosition(posX: Int, posY: Int, block: () -> T): T {
val last = currentRenderPassMousePosition
try {
currentRenderPassMousePosition = Pair(posX, posY)
return block()
} finally {
currentRenderPassMousePosition = last
}
}
fun fromAny(any: Any?, itemScale: Double = NEUItems.itemFontSize): Renderable? = when (any) {
null -> placeholder(12)
is Renderable -> any
is String -> string(any)
is ItemStack -> itemStack(any, itemScale)
else -> null
}
fun link(text: String, bypassChecks: Boolean = false, onClick: () -> Unit): Renderable =
link(string(text), onClick, bypassChecks = bypassChecks)
fun optionalLink(
text: String,
onClick: () -> Unit,
bypassChecks: Boolean = false,
highlightsOnHoverSlots: List<Int> = emptyList(),
condition: () -> Boolean = { true },
): Renderable =
link(string(text), onClick, bypassChecks, highlightsOnHoverSlots = highlightsOnHoverSlots, condition)
fun link(
renderable: Renderable,
onClick: () -> Unit,
bypassChecks: Boolean = false,
highlightsOnHoverSlots: List<Int> = emptyList(),
condition: () -> Boolean = { true },
underlineColor: Color = Color.WHITE,
): Renderable {
return clickable(
hoverable(
underlined(renderable, underlineColor), renderable, bypassChecks,
condition = condition,
highlightsOnHoverSlots = highlightsOnHoverSlots,
),