Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
j10a1n15 committed Nov 26, 2023
1 parent fb243c9 commit f92c440
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,86 +66,8 @@ class CustomScoreboard {
if (!isCustomScoreboardEnabled()) return
val display = display ?: return
val position = config.position
val border = 5

val x = position.getAbsX()
val y = position.getAbsY()

val elementWidth = position.getDummySize().x
val elementHeight = position.getDummySize().y

val scaledWidth = ScaledResolution(Minecraft.getMinecraft()).scaledWidth
val scaledHeight = ScaledResolution(Minecraft.getMinecraft()).scaledHeight

position.set(
Position(
when (config.displayConfig.alignRight) {
true -> scaledWidth - elementWidth - (border * 2)
false -> x
},
when (config.displayConfig.alignCenterVertically) {
true -> scaledHeight / 2 - elementHeight / 2
false -> y
},
position.getScale(),
position.isCenter
)
)
/*if (config.backgroundConfig.enabled) {
ShaderManager.enableShader("rounded_rectangle")
} else {
ShaderManager.disableShader()
}*/

val textureLocation = ResourceLocation("skyhanni", "scoreboard.png")
val rareTextureLocation = ResourceLocation("skyhanni", "rareScoreboardBackground.png")

if (config.backgroundConfig.enabled && config.backgroundConfig.useCustomBackgroundImage) {
if (cooldown > 0) {
cooldown--

// Display rare texture during cooldown
Minecraft.getMinecraft().textureManager.bindTexture(rareTextureLocation)
drawTexturedRect(
(x - border).toFloat(),
(y - border).toFloat(),
(elementWidth + border * 3).toFloat(),
(elementHeight + border * 3).toFloat(),
GL11.GL_NEAREST
)
} else if (Math.random() * 86400.0 * 20 == 1.0) {
// Randomly switch to rare texture with a 1 in 86400 chance (once per day)
Minecraft.getMinecraft().textureManager.bindTexture(rareTextureLocation)
cooldown = 200

drawTexturedRect(
(x - border).toFloat(),
(y - border).toFloat(),
(elementWidth + border * 2).toFloat(),
(elementHeight + border * 2).toFloat(),
GL11.GL_NEAREST
)
} else {
// Draw the default texture
Minecraft.getMinecraft().textureManager.bindTexture(textureLocation)
drawTexturedRect(
(x - border).toFloat(),
(y - border).toFloat(),
(elementWidth + border * 3).toFloat(),
(elementHeight + border * 3).toFloat(),
GL11.GL_NEAREST
)
}
} else if (config.backgroundConfig.enabled) {
// Draw a solid background with a specified color
Gui.drawRect(
x - border,
y - border,
x + elementWidth + border * 2,
y + elementHeight + border * 2,
SpecialColour.specialToChromaRGB(config.backgroundConfig.color)
)
}
RenderBackground().renderBackground()

position.renderStrings(display, posLabel = "Custom Scoreboard")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package at.hannibal2.skyhanni.features.misc.customscoreboard

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.core.config.Position
import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getAbsX
import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getAbsY
import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getDummySize
import at.hannibal2.skyhanni.utils.SpecialColour
import io.github.moulberry.notenoughupdates.util.Utils
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.Gui
import net.minecraft.client.gui.ScaledResolution
import net.minecraft.util.ResourceLocation
import org.lwjgl.opengl.GL11

private val config get() = SkyHanniMod.feature.gui.customScoreboard

class RenderBackground {
fun renderBackground(){
val position = config.position
val border = 5

val x = position.getAbsX()
val y = position.getAbsY()

val elementWidth = position.getDummySize().x
val elementHeight = position.getDummySize().y

val scaledWidth = ScaledResolution(Minecraft.getMinecraft()).scaledWidth
val scaledHeight = ScaledResolution(Minecraft.getMinecraft()).scaledHeight

position.set(
Position(
when (config.displayConfig.alignRight) {
true -> scaledWidth - elementWidth - (border * 2)
false -> x
},
when (config.displayConfig.alignCenterVertically) {
true -> scaledHeight / 2 - elementHeight / 2
false -> y
},
position.getScale(),
position.isCenter
)
)
/*if (config.backgroundConfig.enabled) {
ShaderManager.enableShader("rounded_rectangle")
} else {
ShaderManager.disableShader()
}*/

val textureLocation = ResourceLocation("skyhanni", "scoreboard.png")
val rareTextureLocation = ResourceLocation("skyhanni", "rareScoreboardBackground.png")

if (config.backgroundConfig.enabled && config.backgroundConfig.useCustomBackgroundImage) {
if (cooldown > 0) {
cooldown--

// Display rare texture during cooldown
Minecraft.getMinecraft().textureManager.bindTexture(rareTextureLocation)
Utils.drawTexturedRect(
(x - border).toFloat(),
(y - border).toFloat(),
(elementWidth + border * 3).toFloat(),
(elementHeight + border * 3).toFloat(),
GL11.GL_NEAREST
)
} else if (Math.random() * 86400.0 * 20 == 1.0) {
// Randomly switch to rare texture with a 1 in 86400 chance (once per day)
Minecraft.getMinecraft().textureManager.bindTexture(rareTextureLocation)
cooldown = 200

Utils.drawTexturedRect(
(x - border).toFloat(),
(y - border).toFloat(),
(elementWidth + border * 2).toFloat(),
(elementHeight + border * 2).toFloat(),
GL11.GL_NEAREST
)
} else {
// Draw the default texture
Minecraft.getMinecraft().textureManager.bindTexture(textureLocation)
Utils.drawTexturedRect(
(x - border).toFloat(),
(y - border).toFloat(),
(elementWidth + border * 3).toFloat(),
(elementHeight + border * 3).toFloat(),
GL11.GL_NEAREST
)
}
} else if (config.backgroundConfig.enabled) {
// Draw a solid background with a specified color
Gui.drawRect(
x - border,
y - border,
x + elementWidth + border * 2,
y + elementHeight + border * 2,
SpecialColour.specialToChromaRGB(config.backgroundConfig.color)
)
}
}
}

0 comments on commit f92c440

Please sign in to comment.