aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt16
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt22
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt123
4 files changed, 88 insertions, 79 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
index 40f6a9c94..d0064c4b9 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
@@ -170,7 +170,11 @@ object LorenzUtils {
fun getPlayerName(): String = Minecraft.getMinecraft().thePlayer.name
- fun fillTable(data: List<DisplayTableEntry>, padding: Int = 1, itemScale: Double = 1.0): Renderable {
+ fun fillTable(
+ data: List<DisplayTableEntry>,
+ padding: Int = 1,
+ itemScale: Double = NEUItems.itemFontSize,
+ ): Renderable {
val sorted = data.sortedByDescending { it.sort }
val outerList = mutableListOf<List<Renderable>>()
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
index ce834e28c..0dea5fac5 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
@@ -159,22 +159,24 @@ object NEUItems {
fun isVanillaItem(item: ItemStack): Boolean =
manager.auctionManager.isVanillaItem(item.getInternalName().asString())
- fun ItemStack.renderOnScreen(x: Float, y: Float, scaleMultiplier: Double = 1.0) {
+ const val itemFontSize = 2.0 / 3.0
+
+ fun ItemStack.renderOnScreen(x: Float, y: Float, scaleMultiplier: Double = itemFontSize) {
val item = checkBlinkItem()
val isSkull = item.item === Items.skull
- val baseScale = (if (isSkull) 0.8f else 0.6f)
+ val baseScale = (if (isSkull) 4f / 3f else 1f)
val finalScale = baseScale * scaleMultiplier
- val diff = ((finalScale - baseScale) * 10).toFloat()
val translateX: Float
val translateY: Float
if (isSkull) {
- translateX = x - 2 - diff
- translateY = y - 2 - diff
+ val skulldiff = ((scaleMultiplier) * 2.5).toFloat()
+ translateX = x - skulldiff
+ translateY = y - skulldiff
} else {
- translateX = x - diff
- translateY = y - diff
+ translateX = x
+ translateY = y
}
GlStateManager.pushMatrix()
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
index f38354f17..4e8f41757 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
@@ -528,7 +528,7 @@ object RenderUtils {
fun Position.renderStringsAndItems(
list: List<List<Any?>>,
extraSpace: Int = 0,
- itemScale: Double = 1.0,
+ itemScale: Double = NEUItems.itemFontSize,
posLabel: String,
) {
if (list.isEmpty()) return
@@ -556,13 +556,17 @@ object RenderUtils {
* Accepts a single line to print.
* This line is a list of things to print. Can print String or ItemStack objects.
*/
- fun Position.renderSingleLineWithItems(list: List<Any?>, itemScale: Double = 1.0, posLabel: String) {
+ fun Position.renderSingleLineWithItems(
+ list: List<Any?>,
+ itemScale: Double = NEUItems.itemFontSize,
+ posLabel: String
+ ) {
if (list.isEmpty()) return
val longestX = renderLine(list, 0, itemScale)
GuiEditManager.add(this, posLabel, longestX, 10)
}
- private fun Position.renderLine(line: List<Any?>, offsetY: Int, itemScale: Double = 1.0): Int {
+ private fun Position.renderLine(line: List<Any?>, offsetY: Int, itemScale: Double = NEUItems.itemFontSize): Int {
GlStateManager.pushMatrix()
val (x, y) = transform()
GlStateManager.translate(0f, offsetY.toFloat(), 0F)
@@ -739,9 +743,11 @@ object RenderUtils {
worldrenderer.pos(x1, y1, z1).endVertex()
worldrenderer.pos(x2, y2, z2).endVertex()
- val x3 = x + radius * sin(Math.PI * (phi + 1) / segments) * cos(2.0 * Math.PI * (theta + 1) / (segments * 2))
+ val x3 =
+ x + radius * sin(Math.PI * (phi + 1) / segments) * cos(2.0 * Math.PI * (theta + 1) / (segments * 2))
val y3 = y + radius * cos(Math.PI * (phi + 1) / segments)
- val z3 = z + radius * sin(Math.PI * (phi + 1) / segments) * sin(2.0 * Math.PI * (theta + 1) / (segments * 2))
+ val z3 =
+ z + radius * sin(Math.PI * (phi + 1) / segments) * sin(2.0 * Math.PI * (theta + 1) / (segments * 2))
val x4 = x + radius * sin(Math.PI * phi / segments) * cos(2.0 * Math.PI * (theta + 1) / (segments * 2))
val y4 = y + radius * cos(Math.PI * phi / segments)
@@ -800,9 +806,11 @@ object RenderUtils {
val y2 = y + radius * cos(Math.PI * (phi + 1) / segments)
val z2 = z + radius * sin(Math.PI * (phi + 1) / segments) * sin(2.0 * Math.PI * theta / (segments * 2))
- val x3 = x + radius * sin(Math.PI * (phi + 1) / segments) * cos(2.0 * Math.PI * (theta + 1) / (segments * 2))
+ val x3 =
+ x + radius * sin(Math.PI * (phi + 1) / segments) * cos(2.0 * Math.PI * (theta + 1) / (segments * 2))
val y3 = y + radius * cos(Math.PI * (phi + 1) / segments)
- val z3 = z + radius * sin(Math.PI * (phi + 1) / segments) * sin(2.0 * Math.PI * (theta + 1) / (segments * 2))
+ val z3 =
+ z + radius * sin(Math.PI * (phi + 1) / segments) * sin(2.0 * Math.PI * (theta + 1) / (segments * 2))
val x4 = x + radius * sin(Math.PI * phi / segments) * cos(2.0 * Math.PI * (theta + 1) / (segments * 2))
val y4 = y + radius * cos(Math.PI * phi / segments)
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt
index 3b1249808..542b62c42 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt
@@ -10,6 +10,7 @@ import at.hannibal2.skyhanni.utils.ColorUtils
import at.hannibal2.skyhanni.utils.ColorUtils.darker
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.HorizontalAlignment
import at.hannibal2.skyhanni.utils.RenderUtils.VerticalAlignment
@@ -18,8 +19,8 @@ import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.calculateTableYOf
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 io.github.notenoughupdates.moulconfig.gui.GuiScreenElementWrapper
import io.github.moulberry.notenoughupdates.util.Utils
+import io.github.notenoughupdates.moulconfig.gui.GuiScreenElementWrapper
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.Gui
import net.minecraft.client.gui.inventory.GuiEditSign
@@ -39,8 +40,7 @@ interface Renderable {
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?
+ x in (posX..posX + width) && y in (posY..posY + height) // TODO: adjust for variable height?
} ?: false
/**
@@ -65,7 +65,7 @@ interface Renderable {
}
}
- fun fromAny(any: Any?, itemScale: Double = 1.0): Renderable? = when (any) {
+ fun fromAny(any: Any?, itemScale: Double = NEUItems.itemFontSize): Renderable? = when (any) {
null -> placeholder(12)
is Renderable -> any
is String -> string(any)
@@ -81,8 +81,7 @@ interface Renderable {
onClick: () -> Unit,
bypassChecks: Boolean = false,
condition: () -> Boolean = { true },
- ): Renderable =
- link(string(text), onClick, bypassChecks, condition)
+ ): Renderable = link(string(text), onClick, bypassChecks, condition)
fun link(
renderable: Renderable,
@@ -119,28 +118,25 @@ interface Renderable {
button: Int = 0,
bypassChecks: Boolean = false,
condition: () -> Boolean = { true },
- ) =
- object : Renderable {
- override val width = render.width
- override val height = render.height
- override val horizontalAlign = render.horizontalAlign
- override val verticalAlign = render.verticalAlign
+ ) = object : Renderable {
+ override val width = render.width
+ override val height = render.height
+ override val horizontalAlign = render.horizontalAlign
+ override val verticalAlign = render.verticalAlign
- private var wasDown = false
+ private var wasDown = false
- override fun render(posX: Int, posY: Int) {
- val isDown = Mouse.isButtonDown(button)
- if (isDown > wasDown && isHovered(posX, posY) && condition() && shouldAllowLink(
- true,
- bypassChecks
- )
- ) {
- onClick()
- }
- wasDown = isDown
- render.render(posX, posY)
+ override fun render(posX: Int, posY: Int) {
+ val isDown = Mouse.isButtonDown(button)
+ if (isDown > wasDown && isHovered(posX, posY) && condition() &&
+ shouldAllowLink(true, bypassChecks)
+ ) {
+ onClick()
}
+ wasDown = isDown
+ render.render(posX, posY)
}
+ }
fun hoverTips(
content: Any,
@@ -248,43 +244,40 @@ interface Renderable {
unhovered: Renderable,
bypassChecks: Boolean = false,
condition: () -> Boolean = { true },
- ) =
- object : Renderable {
- override val width: Int
- get() = max(hovered.width, unhovered.width)
- override val height = 10
- override val horizontalAlign get() = if (isHovered) hovered.horizontalAlign else unhovered.horizontalAlign
- override val verticalAlign get() = if (isHovered) hovered.verticalAlign else unhovered.verticalAlign
+ ) = object : Renderable {
+ override val width: Int
+ get() = max(hovered.width, unhovered.width)
+ override val height = 10
+ override val horizontalAlign get() = if (isHovered) hovered.horizontalAlign else unhovered.horizontalAlign
+ override val verticalAlign get() = if (isHovered) hovered.verticalAlign else unhovered.verticalAlign
- var isHovered = false
+ var isHovered = false
- override fun render(posX: Int, posY: Int) {
- isHovered = if (isHovered(posX, posY) && condition() && shouldAllowLink(true, bypassChecks)) {
- hovered.render(posX, posY)
- true
- } else {
- unhovered.render(posX, posY)
- false
- }
+ override fun render(posX: Int, posY: Int) {
+ isHovered = if (isHovered(posX, posY) && condition() && shouldAllowLink(true, bypassChecks)) {
+ hovered.render(posX, posY)
+ true
+ } else {
+ unhovered.render(posX, posY)
+ false
}
}
+ }
fun itemStack(
- any: ItemStack,
- scale: Double = 1.0,
+ item: ItemStack,
+ scale: Double = NEUItems.itemFontSize,
+ xSpacing: Int = 2,
horizontalAlign: HorizontalAlignment = HorizontalAlignment.LEFT,
- verticalAlign: VerticalAlignment = VerticalAlignment.TOP,
+ verticalAlign: VerticalAlignment = VerticalAlignment.CENTER,
) = object : Renderable {
- override val width: Int
- get() = 12
- override val height = 10
+ override val width = (15.5 * scale + 1.5).toInt() + xSpacing
+ override val height = (15.5 * scale + 1.5).toInt()
override val horizontalAlign = horizontalAlign
override val verticalAlign = verticalAlign
override fun render(posX: Int, posY: Int) {
- GlStateManager.pushMatrix()
- any.renderOnScreen(0F, 0F, scaleMultiplier = scale)
- GlStateManager.popMatrix()
+ item.renderOnScreen(xSpacing / 2.0f, 0F, scaleMultiplier = scale)
}
}
@@ -297,7 +290,7 @@ interface Renderable {
scale: Double = 1.0,
color: Color = Color.WHITE,
horizontalAlign: HorizontalAlignment = HorizontalAlignment.LEFT,
- verticalAlign: VerticalAlignment = VerticalAlignment.TOP,
+ verticalAlign: VerticalAlignment = VerticalAlignment.CENTER,
) = object : Renderable {
override val width by lazy { (Minecraft.getMinecraft().fontRendererObj.getStringWidth(text) * scale).toInt() + 1 }
@@ -449,18 +442,12 @@ interface Renderable {
}
} else {
val (textureX, textureY) = if (texture == SkillProgressBarConfig.TexturedBar.UsedTexture.MATCH_PACK) Pair(
- 0,
- 64
+ 0, 64
) else Pair(0, 0)
Minecraft.getMinecraft().renderEngine.bindTexture(ResourceLocation(texture.path))
Minecraft.getMinecraft().ingameGUI.drawTexturedModalRect(
- posX,
- posY,
- textureX,
- textureY,
- width,
- height
+ posX, posY, textureX, textureY, width, height
)
if (useChroma) {
@@ -470,12 +457,7 @@ interface Renderable {
GlStateManager.color(color.red / 255f, color.green / 255f, color.blue / 255f, 1f)
}
Minecraft.getMinecraft().ingameGUI.drawTexturedModalRect(
- posX,
- posY,
- textureX,
- textureY + height,
- progress,
- height
+ posX, posY, textureX, textureY + height, progress, height
)
if (useChroma) {
@@ -485,6 +467,19 @@ interface Renderable {
}
}
+ fun Renderable.renderBounds(color: Color = LorenzColor.GREEN.toColor()) = object : Renderable {
+ override val width = this@renderBounds.width
+ override val height = this@renderBounds.height
+ override val horizontalAlign = this@renderBounds.horizontalAlign
+ override val verticalAlign = this@renderBounds.verticalAlign
+
+ override fun render(posX: Int, posY: Int) {
+ Gui.drawRect(0, 0, width, height, color.rgb)
+ this@renderBounds.render(posX, posY)
+ }
+
+ }
+
fun fixedSizeLine(
content: Renderable,
width: Int,