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/ColorUtils.kt10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt47
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt15
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/Quad.kt31
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt113
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/shader/Shader.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderHelper.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderManager.kt10
10 files changed, 196 insertions, 50 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ColorUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ColorUtils.kt
index cf851d65f..054e5e19f 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ColorUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ColorUtils.kt
@@ -1,6 +1,8 @@
package at.hannibal2.skyhanni.utils
import java.awt.Color
+import kotlin.math.max
+
object ColorUtils {
@@ -19,4 +21,12 @@ object ColorUtils {
(start.green * (1 - percent) + end.green * percent).toInt(),
(start.blue * (1 - percent) + end.blue * percent).toInt()
)
+
+ fun Color.darker(factor: Double): Color {
+ return Color(
+ max((red * factor).toInt(), 0),
+ max((green * factor).toInt(), 0),
+ max((blue * factor).toInt(), 0),
+ alpha)
+ }
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt
index 1d0b42b92..af893d7dc 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt
@@ -1,5 +1,9 @@
package at.hannibal2.skyhanni.utils
+import at.hannibal2.skyhanni.config.features.skillprogress.SkillProgressBarConfig
+import at.hannibal2.skyhanni.features.chroma.ChromaShaderManager
+import at.hannibal2.skyhanni.features.chroma.ChromaType
+import io.github.moulberry.notenoughupdates.util.Utils
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.FontRenderer
import net.minecraft.client.gui.GuiScreen
@@ -9,6 +13,8 @@ import net.minecraft.item.ItemStack
import org.lwjgl.opengl.GL11
import java.awt.Color
import java.text.DecimalFormat
+import kotlin.math.ceil
+import kotlin.math.min
import kotlin.math.roundToInt
/**
@@ -294,4 +300,45 @@ object GuiRenderUtils {
renderItemStack(item, x, y)
GuiScreen.drawRect(x, y, x + 16, y + 16, colour)
}
+
+ // Taken and edited from NEU <- it's broken
+ fun renderTexturedBar(x: Float, y: Float, xSize: Float, completed: Float, color: Color, useChroma: Boolean, texture: SkillProgressBarConfig.TexturedBar.UsedTexture, height: Float) {
+ GlStateManager.pushMatrix()
+ GlStateManager.translate(x, y, 0f)
+ val w = xSize.toInt()
+ val w_2 = w / 2
+ val k = min(w.toDouble(), ceil((completed * w).toDouble())).toInt()
+ val vanilla = texture == SkillProgressBarConfig.TexturedBar.UsedTexture.MATCH_PACK
+ val vMinEmpty = if (vanilla) 64 / 256f else 0f
+ val vMaxEmpty = if (vanilla) 69 / 256f else .5f
+ val vMinFilled = if (vanilla) 69 / 256f else .5f
+ val vMaxFilled = if (vanilla) 74 / 256f else 1f
+
+ if (useChroma) {
+ ChromaShaderManager.begin(ChromaType.TEXTURED)
+ GlStateManager.color(Color.LIGHT_GRAY.darker().red / 255f, Color.LIGHT_GRAY.darker().green / 255f, Color.LIGHT_GRAY.darker().blue / 255f, 1f)
+ } else {
+ GlStateManager.color(color.darker().red / 255f, color.darker().green / 255f, color.darker().blue / 255f, 1f)
+ }
+
+ Utils.drawTexturedRect(x, y, w_2.toFloat(), height, 0f, w_2 / xSize, vMinEmpty, vMaxEmpty, GL11.GL_NEAREST)
+ Utils.drawTexturedRect(x + w_2, y, w_2.toFloat(), height, 1 - w_2 / xSize, 1f, vMinEmpty, vMaxEmpty, GL11.GL_NEAREST)
+
+ if (useChroma) {
+ GlStateManager.color(Color.WHITE.red / 255f, Color.WHITE.green / 255f, Color.WHITE.blue / 255f, 1f)
+ } else {
+ GlStateManager.color(color.red / 255f, color.green / 255f, color.blue / 255f, 1f)
+ }
+
+ if (k > 0) {
+ Utils.drawTexturedRect(x, y, w_2.coerceAtMost(k).toFloat(), height, 0f, w_2.toDouble().coerceAtMost(k.toDouble() / xSize).toFloat(), vMinFilled, vMaxFilled, GL11.GL_NEAREST)
+ if (completed > 0.5f) {
+ Utils.drawTexturedRect(x + w_2, y, (k - w_2).toFloat(), height, 1 - w_2 / xSize, 1 + (k - w) / xSize, vMinFilled, vMaxFilled, GL11.GL_NEAREST)
+ }
+ }
+ if (useChroma) {
+ ChromaShaderManager.end()
+ }
+ GlStateManager.popMatrix()
+ }
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
index 77979a5aa..502cba763 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
@@ -27,12 +27,14 @@ import net.minecraft.entity.SharedMonsterAttributes
import net.minecraft.launchwrapper.Launch
import net.minecraft.util.ChatComponentText
import net.minecraftforge.fml.common.FMLCommonHandler
+import java.io.Serializable
import java.text.DecimalFormat
import java.text.SimpleDateFormat
import java.util.Timer
import java.util.TimerTask
import java.util.regex.Matcher
import kotlin.time.Duration
+import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
object LorenzUtils {
@@ -142,7 +144,7 @@ object LorenzUtils {
fun getSBMonthByName(month: String): Int {
var monthNr = 0
- for (i in 1..12) {
+ for (i in 1 .. 12) {
val monthName = SkyBlockTime.monthName(i)
if (month == monthName) {
monthNr = i
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
index 60fb67213..4e00a85e7 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
@@ -3,6 +3,8 @@ package at.hannibal2.skyhanni.utils
import java.text.NumberFormat
import java.util.Locale
import java.util.TreeMap
+import kotlin.math.max
+import kotlin.math.min
import kotlin.math.pow
import kotlin.math.roundToInt
@@ -90,7 +92,7 @@ object NumberUtil {
fun Number.ordinal(): String {
val long = this.toLong()
- if (long % 100 in 11..13) return "th"
+ if (long % 100 in 11 .. 13) return "th"
return when (long % 10) {
1L -> "st"
2L -> "nd"
@@ -215,4 +217,15 @@ object NumberUtil {
fun Number.fractionOf(maxValue: Number) = maxValue.toDouble().takeIf { it != 0.0 }?.let { max ->
this.toDouble() / max
}?.coerceIn(0.0, 1.0) ?: 1.0
+
+ fun interpolate(now: Float, last: Float, lastUpdate: Long): Float {
+ var interp = now
+ if (last >= 0 && last != now) {
+ var factor: Float = (SimpleTimeMark.now().toMillis() - lastUpdate) / 1000f
+ factor = factor.coerceIn(0f, 1f)
+ interp = last + (now - last) * factor
+ }
+ return interp
+ }
+
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/Quad.kt b/src/main/java/at/hannibal2/skyhanni/utils/Quad.kt
new file mode 100644
index 000000000..584ca99c8
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/utils/Quad.kt
@@ -0,0 +1,31 @@
+package at.hannibal2.skyhanni.utils
+
+import java.io.Serializable
+
+/**
+ * Represents a tetrad of values
+ *
+ * There is no meaning attached to values in this class, it can be used for any purpose.
+ * Quad exhibits value semantics, i.e. two quads are equal if all four components are equal.
+ *
+ * @param A type of the first value.
+ * @param B type of the second value.
+ * @param C type of the third value.
+ * @param D type of the fourth value.
+ * @property first First value.
+ * @property second Second value.
+ * @property third Third value.
+ * @property fourth Fourth value.
+ */
+data class Quad<out A, out B, out C, out D>(
+ val first: A,
+ val second: B,
+ val third: C,
+ val fourth: D
+) : Serializable {
+
+ /**
+ * Returns string representation of the [Quad] including its [first], [second], [third] and [fourth] values.
+ */
+ override fun toString(): String = "($first, $second, $third, $fourth)"
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
index 193beda2a..914a906e5 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
@@ -549,7 +549,7 @@ object RenderUtils {
val z: Double =
entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * partialTicks - renderManager.viewerPosZ
val pix2 = Math.PI * 2.0
- for (i in 0..90) {
+ for (i in 0 .. 90) {
color.bindColor()
worldRenderer.pos(x + rad * cos(i * pix2 / 45.0), y + il, z + rad * sin(i * pix2 / 45.0)).endVertex()
}
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 5316b68cc..c1b382ba8 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt
@@ -1,14 +1,18 @@
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.ToolTipData
+import at.hannibal2.skyhanni.features.chroma.ChromaShaderManager
+import at.hannibal2.skyhanni.features.chroma.ChromaType
import at.hannibal2.skyhanni.utils.ColorUtils
+import at.hannibal2.skyhanni.utils.ColorUtils.darker
+import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXAligned
+import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderYAligned
import at.hannibal2.skyhanni.utils.LorenzLogger
import at.hannibal2.skyhanni.utils.NEUItems.renderOnScreen
import at.hannibal2.skyhanni.utils.RenderUtils.HorizontalAlignment
import at.hannibal2.skyhanni.utils.RenderUtils.VerticalAlignment
-import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXAligned
-import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderYAligned
import io.github.moulberry.moulconfig.gui.GuiScreenElementWrapper
import io.github.moulberry.notenoughupdates.util.Utils
import net.minecraft.client.Minecraft
@@ -16,6 +20,7 @@ import net.minecraft.client.gui.Gui
import net.minecraft.client.gui.inventory.GuiEditSign
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.item.ItemStack
+import net.minecraft.util.ResourceLocation
import org.lwjgl.input.Mouse
import java.awt.Color
import java.util.Collections
@@ -29,8 +34,8 @@ 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
/**
@@ -43,7 +48,6 @@ interface Renderable {
val logger = LorenzLogger("debug/renderable")
val list = mutableMapOf<Pair<Int, Int>, List<Int>>()
-
var currentRenderPassMousePosition: Pair<Int, Int>? = null
set
@@ -237,12 +241,12 @@ interface Renderable {
var isHovered = false
override fun render(posX: Int, posY: Int) {
- if (isHovered(posX, posY) && condition() && shouldAllowLink(true, bypassChecks)) {
+ isHovered = if (isHovered(posX, posY) && condition() && shouldAllowLink(true, bypassChecks)) {
hovered.render(posX, posY)
- isHovered = true
+ true
} else {
unhovered.render(posX, posY)
- isHovered = false
+ false
}
}
}
@@ -301,25 +305,82 @@ interface Renderable {
percent: Double,
startColor: Color = Color(255, 0, 0),
endColor: Color = Color(0, 255, 0),
- width: Int = 30,
- height: Int = 4,
+ useChroma: Boolean = false,
+ texture: SkillProgressBarConfig.TexturedBar.UsedTexture? = null,
+ width: Int = 182,
+ height: Int = 5,
horizontalAlign: HorizontalAlignment = HorizontalAlignment.LEFT,
- verticalAlign: VerticalAlignment = VerticalAlignment.TOP,
+ verticalAlign: VerticalAlignment = VerticalAlignment.TOP
) = object : Renderable {
override val width = width
override val height = height
override val horizontalAlign = horizontalAlign
override val verticalAlign = verticalAlign
- val progress = (1.0 + percent * (width - 2.0)).toInt()
- val color = ColorUtils.blendRGB(startColor, endColor, percent)
+ private val progress = if (texture == null) {
+ (1.0 + percent * (width - 2.0)).toInt()
+ } else {
+ percent.toInt()
+ }
+
+ private var color = if (texture == null) {
+ ColorUtils.blendRGB(startColor, endColor, percent)
+ } else {
+ startColor
+ }
override fun render(posX: Int, posY: Int) {
- Gui.drawRect(0, 0, width, height, 0xFF43464B.toInt())
- Gui.drawRect(1, 1, width - 1, height - 1, color.darker().rgb)
- Gui.drawRect(1, 1, progress, height - 1, color.rgb)
+ if (texture == null) {
+ Gui.drawRect(0, 0, width, height, 0xFF43464B.toInt())
+
+ if (useChroma) {
+ ChromaShaderManager.begin(ChromaType.STANDARD)
+ }
+
+ val factor = 0.2
+ val bgColor = if (useChroma) Color.GRAY.darker() else color
+ Gui.drawRect(1, 1, width - 1, height - 1, bgColor.darker(factor).rgb)
+ Gui.drawRect(1, 1, progress, height - 1, color.rgb)
+
+ if (useChroma) {
+ ChromaShaderManager.end()
+ }
+ } else {
+ val (textureX, textureY) = if (texture == SkillProgressBarConfig.TexturedBar.UsedTexture.MATCH_PACK) Pair(0, 64) else Pair(0, 0)
+
+ Minecraft.getMinecraft().renderEngine.bindTexture(ResourceLocation(texture.path))
+ Minecraft.getMinecraft().ingameGUI.drawTexturedModalRect(posX, posY, textureX, textureY, width, height)
+
+ if (useChroma) {
+ ChromaShaderManager.begin(ChromaType.TEXTURED)
+ GlStateManager.color(1f, 1f, 1f, 1f)
+ } else {
+ GlStateManager.color(color.red / 255f, color.green / 255f, color.blue / 255f, 1f)
+ }
+ Minecraft.getMinecraft().ingameGUI.drawTexturedModalRect(posX, posY, textureX, textureY + height, progress, height)
+
+ if (useChroma) {
+ ChromaShaderManager.end()
+ }
+ }
}
+ }
+
+ fun fixedSizeLine(
+ content: Renderable,
+ width: Int,
+ horizontalAlign: HorizontalAlignment = HorizontalAlignment.LEFT,
+ verticalAlign: VerticalAlignment = VerticalAlignment.TOP,
+ ) = object : Renderable {
+ val render = content
+ override val width = width
+ override val height = render.height
+ override val horizontalAlign = horizontalAlign
+ override val verticalAlign = verticalAlign
+ override fun render(posX: Int, posY: Int) {
+ render.renderXAligned(0, 0, width)
+ }
}
fun horizontalContainer(
@@ -345,23 +406,5 @@ interface Renderable {
GlStateManager.translate(-width.toFloat() - spacing.toFloat(), 0f, 0f)
}
}
-
- fun fixedSizeLine(
- content: Renderable,
- width: Int,
- horizontalAlign: HorizontalAlignment = HorizontalAlignment.LEFT,
- verticalAlign: VerticalAlignment = VerticalAlignment.TOP,
- ) = object : Renderable {
- val render = content
-
- override val width = width
- override val height = render.height
- override val horizontalAlign = horizontalAlign
- override val verticalAlign = verticalAlign
-
- override fun render(posX: Int, posY: Int) {
- render.renderXAligned(0, 0, width)
- }
- }
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/shader/Shader.kt b/src/main/java/at/hannibal2/skyhanni/utils/shader/Shader.kt
index dedb60ef2..03b2fb3ac 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/shader/Shader.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/shader/Shader.kt
@@ -69,14 +69,14 @@ abstract class Shader(val vertex: String, val fragment: String) {
if (ShaderHelper.glGetProgrami(shaderProgram, ShaderHelper.GL_LINK_STATUS) == GL11.GL_FALSE) {
val errorMessage = "Failed to link vertex shader $vertex and fragment shader $fragment. Features that " +
- "utilise this shader will not work correctly, if at all"
+ "utilise this shader will not work correctly, if at all"
val errorLog = StringUtils.trim(ShaderHelper.glGetShaderInfoLog(shaderProgram, 1024))
if (ShaderManager.inWorld()) {
ErrorManager.logErrorWithData(
- OpenGLException("Shader linking error."),
- errorMessage,
- "Link Error:\n" to errorLog
+ OpenGLException("Shader linking error."),
+ errorMessage,
+ "Link Error:\n" to errorLog
)
} else {
LorenzUtils.consoleLog("$errorMessage $errorLog")
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderHelper.kt b/src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderHelper.kt
index 6e36285b1..fdc34f0ae 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderHelper.kt
@@ -139,9 +139,9 @@ class ShaderHelper {
fun glUniform2f(location: Int, v0: Float, v1: Float) {
if (USING_ARB_SHADERS) ARBShaderObjects.glUniform2fARB(location, v0, v1) else GL20.glUniform2f(
- location,
- v0,
- v1
+ location,
+ v0,
+ v1
)
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderManager.kt b/src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderManager.kt
index 5621a5f87..645471087 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderManager.kt
@@ -86,15 +86,15 @@ object ShaderManager {
if (ShaderHelper.glGetShaderi(shaderID, ShaderHelper.GL_COMPILE_STATUS) == 0) {
val errorMessage = "Failed to compile shader $fileName${type.extension}. Features that utilise this " +
- "shader will not work correctly, if at all"
+ "shader will not work correctly, if at all"
val errorLog = StringUtils.trim(ShaderHelper.glGetShaderInfoLog(shaderID, 1024))
if (inWorld()) {
ErrorManager.logErrorWithData(
- OpenGLException("Shader compilation error."),
- errorMessage,
- "GLSL Compilation Error:\n" to errorLog
- )
+ OpenGLException("Shader compilation error."),
+ errorMessage,
+ "GLSL Compilation Error:\n" to errorLog
+ )
} else {
LorenzUtils.consoleLog("$errorMessage $errorLog")
}