Skip to content

Commit

Permalink
feat: Add individual GuiElement text shadow configuration (#432)
Browse files Browse the repository at this point in the history
* Replace spam text shadow with global feature

* separate configuration for each gui element

Signed-off-by: RectangularObject <26125768+RectangularObject@users.noreply.github.com>

* Add middle click to change text shadow

Signed-off-by: RectangularObject <26125768+RectangularObject@users.noreply.github.com>

---------

Signed-off-by: RectangularObject <26125768+RectangularObject@users.noreply.github.com>
Co-authored-by: My-Name-Is-Jeff <37018278+My-Name-Is-Jeff@users.noreply.github.com>
  • Loading branch information
RectangularObject and My-Name-Is-Jeff authored Jan 12, 2024
1 parent e9b2c85 commit 5569957
Show file tree
Hide file tree
Showing 24 changed files with 96 additions and 84 deletions.
12 changes: 9 additions & 3 deletions src/main/kotlin/gg/skytils/skytilsmod/core/GuiManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import gg.skytils.skytilsmod.events.impl.RenderHUDEvent
import gg.skytils.skytilsmod.gui.LocationEditGui
import gg.skytils.skytilsmod.utils.GlState
import gg.skytils.skytilsmod.utils.Utils
import gg.skytils.skytilsmod.utils.graphics.SmartFontRenderer
import gg.skytils.skytilsmod.utils.toast.Toast
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
Expand All @@ -52,6 +53,7 @@ import java.util.Queue
object GuiManager : PersistentSave(File(Skytils.modDir, "guipositions.json")) {
val GUIPOSITIONS = hashMapOf<String, Pair<Float, Float>>()
val GUISCALES = hashMapOf<String, Float>()
val GUITEXTSHADOWS = hashMapOf<String, SmartFontRenderer.TextShadow>()
val elements = hashMapOf<Int, GuiElement>()
private val names = hashMapOf<String, GuiElement>()

Expand Down Expand Up @@ -236,13 +238,15 @@ object GuiManager : PersistentSave(File(Skytils.modDir, "guipositions.json")) {
}

override fun read(reader: Reader) {
json.decodeFromString<Map<String, GuiElementLocation>>(reader.readText()).forEach { name, (x, y, scale) ->
json.decodeFromString<Map<String, GuiElementLocation>>(reader.readText()).forEach { name, (x, y, scale, textShadow) ->
val pos = x to y
GUIPOSITIONS[name] = pos
GUISCALES[name] = scale
GUITEXTSHADOWS[name] = textShadow
getByName(name)?.let { element ->
element.setPos(x, y)
element.scale = scale
element.textShadow = textShadow
}
}
}
Expand All @@ -251,12 +255,14 @@ object GuiManager : PersistentSave(File(Skytils.modDir, "guipositions.json")) {
names.entries.forEach { (n, e) ->
GUIPOSITIONS[n] = e.x to e.y
GUISCALES[n] = e.scale
GUITEXTSHADOWS[n] = e.textShadow
}
writer.write(json.encodeToString(GUIPOSITIONS.entries.associate {
it.key to GuiElementLocation(
it.value.first,
it.value.second,
GUISCALES[it.key] ?: 1f
GUISCALES[it.key] ?: 1f,
GUITEXTSHADOWS[it.key] ?: SmartFontRenderer.TextShadow.NORMAL
)
}))
}
Expand All @@ -268,5 +274,5 @@ object GuiManager : PersistentSave(File(Skytils.modDir, "guipositions.json")) {
// this class sucks lol (why is there a thing called floatpair)
// was going to make guielement serializable but it's too much effort
@Serializable
private data class GuiElementLocation(val x: Float, val y: Float, val scale: Float)
private data class GuiElementLocation(val x: Float, val y: Float, val scale: Float = 1f, val textShadow: SmartFontRenderer.TextShadow = SmartFontRenderer.TextShadow.NORMAL)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ package gg.skytils.skytilsmod.core.structure
import gg.essential.universal.UResolution
import gg.skytils.skytilsmod.core.GuiManager
import gg.skytils.skytilsmod.utils.graphics.ScreenRenderer
import gg.skytils.skytilsmod.utils.graphics.SmartFontRenderer

abstract class GuiElement(var name: String, var scale: Float = 1f, var x: Float, var y: Float) {
constructor(name: String, scale: Float = 1f, x: Int, y: Int) : this(
abstract class GuiElement(var name: String, var scale: Float = 1f, var x: Float, var y: Float, var textShadow: SmartFontRenderer.TextShadow = SmartFontRenderer.TextShadow.NORMAL) {
constructor(name: String, scale: Float = 1f, x: Int, y: Int, textShadow: SmartFontRenderer.TextShadow = SmartFontRenderer.TextShadow.NORMAL) : this(
name,
scale,
(x / UResolution.scaledWidth).toFloat(),
(y / UResolution.scaledHeight).toFloat()
(y / UResolution.scaledHeight).toFloat(),
textShadow
)

abstract fun render()
Expand Down Expand Up @@ -73,5 +75,6 @@ abstract class GuiElement(var name: String, var scale: Float = 1f, var x: Float,
x = pos.first
y = pos.second
scale = GuiManager.GUISCALES.getOrDefault(name, scale)
textShadow = GuiManager.GUITEXTSHADOWS.getOrDefault(name, textShadow)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ object BossHPDisplays {
0f,
CommonColors.WHITE,
alignment,
SmartFontRenderer.TextShadow.NORMAL
textShadow
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ object ChestProfit {
element.scaleY,
chest.displayColor,
alignment,
SmartFontRenderer.TextShadow.NORMAL
textShadow_
)

for (item in chest.items) {
Expand All @@ -187,7 +187,7 @@ object ChestProfit {
element.scaleY + drawnLines * ScreenRenderer.fontRenderer.FONT_HEIGHT,
CommonColors.WHITE,
alignment,
SmartFontRenderer.TextShadow.NORMAL
textShadow_
)
drawnLines++
}
Expand Down Expand Up @@ -254,11 +254,13 @@ object ChestProfit {
}
}

private var textShadow_ = SmartFontRenderer.TextShadow.NORMAL
private class DungeonChestLootItem(var item: ItemStack, var value: Double)
class DungeonChestProfitElement : GuiElement("Dungeon Chest Profit", x = 200, y = 120) {
override fun render() {
if (toggled && (Utils.inDungeons || SBInfo.mode == SkyblockIsland.DungeonHub.mode)) {
val leftAlign = scaleX < sr.scaledWidth / 2f
textShadow_ = textShadow
GlStateManager.color(1f, 1f, 1f, 1f)
GlStateManager.disableLighting()
DungeonChest.entries.filter { it.items.isNotEmpty() }.forEachIndexed { i, chest ->
Expand All @@ -269,7 +271,7 @@ object ChestProfit {
(i * ScreenRenderer.fontRenderer.FONT_HEIGHT).toFloat(),
chest.displayColor,
if (leftAlign) TextAlignment.LEFT_RIGHT else TextAlignment.RIGHT_LEFT,
SmartFontRenderer.TextShadow.NORMAL
textShadow
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import net.minecraft.block.BlockStainedGlass
import net.minecraft.block.material.Material
import net.minecraft.client.entity.EntityOtherPlayerMP
import net.minecraft.client.gui.GuiScreen
import net.minecraft.client.renderer.GlStateManager
Expand Down Expand Up @@ -756,7 +755,7 @@ object DungeonFeatures {
0f,
CommonColors.PURPLE,
alignment,
SmartFontRenderer.TextShadow.NORMAL
textShadow
)
}
}
Expand All @@ -771,7 +770,7 @@ object DungeonFeatures {
0f,
CommonColors.PURPLE,
alignment,
SmartFontRenderer.TextShadow.NORMAL
textShadow
)
}

Expand Down Expand Up @@ -803,7 +802,7 @@ object DungeonFeatures {
0f,
CommonColors.WHITE,
alignment,
SmartFontRenderer.TextShadow.NORMAL
textShadow
)
}
}
Expand All @@ -819,7 +818,7 @@ object DungeonFeatures {
0f,
CommonColors.WHITE,
alignment,
SmartFontRenderer.TextShadow.NORMAL
textShadow
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import gg.skytils.skytilsmod.utils.NumberUtil.roundToPrecision
import gg.skytils.skytilsmod.utils.RenderUtil
import gg.skytils.skytilsmod.utils.Utils
import gg.skytils.skytilsmod.utils.graphics.ScreenRenderer
import gg.skytils.skytilsmod.utils.graphics.SmartFontRenderer
import gg.skytils.skytilsmod.utils.stripControlCodes
import net.minecraftforge.client.event.ClientChatReceivedEvent
import net.minecraftforge.event.world.WorldEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import gg.skytils.skytilsmod.listeners.DungeonListener
import gg.skytils.skytilsmod.mixins.transformers.accessors.AccessorChatComponentText
import gg.skytils.skytilsmod.utils.*
import gg.skytils.skytilsmod.utils.graphics.ScreenRenderer
import gg.skytils.skytilsmod.utils.graphics.SmartFontRenderer
import gg.skytils.skytilsmod.utils.graphics.SmartFontRenderer.TextAlignment
import gg.skytils.skytilsmod.utils.graphics.colors.CommonColors
import net.minecraft.entity.monster.EntityZombie
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ object MayorJerry {
0f,
CommonColors.ORANGE,
SmartFontRenderer.TextAlignment.LEFT_RIGHT,
SmartFontRenderer.TextShadow.NORMAL
textShadow
)
}
}
Expand All @@ -106,7 +106,7 @@ object MayorJerry {
0f,
CommonColors.ORANGE,
SmartFontRenderer.TextAlignment.LEFT_RIGHT,
SmartFontRenderer.TextShadow.NORMAL
textShadow
)
}

Expand Down Expand Up @@ -142,7 +142,7 @@ object MayorJerry {
5f,
CommonColors.ORANGE,
SmartFontRenderer.TextAlignment.LEFT_RIGHT,
SmartFontRenderer.TextShadow.NORMAL
textShadow
)
}
}
Expand All @@ -155,7 +155,7 @@ object MayorJerry {
5f,
CommonColors.ORANGE,
SmartFontRenderer.TextAlignment.LEFT_RIGHT,
SmartFontRenderer.TextShadow.NORMAL
textShadow
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ object VisitorHelper {

override fun render() {
// Rendering is handled in the BackgroundDrawnEvent to give the text proper lighting
textShadow_ = textShadow
}

override fun demoRender() {
Expand All @@ -157,7 +158,7 @@ object VisitorHelper {
).forEachIndexed { i, str ->
fr.drawString(
str, textPosX, (i * fr.FONT_HEIGHT).toFloat(),
CommonColors.WHITE, alignment, SmartFontRenderer.TextShadow.NORMAL
CommonColors.WHITE, alignment, textShadow
)
}
}
Expand All @@ -174,14 +175,15 @@ object VisitorHelper {
}
}

private var textShadow_ = SmartFontRenderer.TextShadow.NORMAL
private fun drawLine(index: Int, str: String) {
ScreenRenderer.fontRenderer.drawString(
str,
VisitorHelperDisplay.textPosX,
(index * ScreenRenderer.fontRenderer.FONT_HEIGHT).toFloat(),
CommonColors.WHITE,
VisitorHelperDisplay.alignment,
SmartFontRenderer.TextShadow.NORMAL
textShadow_
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ object CooldownTracker : PersistentSave(File(Skytils.modDir, "cooldowntracker.js
(ScreenRenderer.fontRenderer.FONT_HEIGHT * i).toFloat(),
CommonColors.ORANGE,
SmartFontRenderer.TextAlignment.LEFT_RIGHT,
SmartFontRenderer.TextShadow.NORMAL
textShadow
)
}
}
Expand All @@ -104,7 +104,7 @@ object CooldownTracker : PersistentSave(File(Skytils.modDir, "cooldowntracker.js
0f,
CommonColors.ORANGE,
SmartFontRenderer.TextAlignment.LEFT_RIGHT,
SmartFontRenderer.TextShadow.NORMAL
textShadow
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import gg.skytils.skytilsmod.mixins.transformers.accessors.AccessorGuiNewChat
import gg.skytils.skytilsmod.utils.RegexAsString
import gg.skytils.skytilsmod.utils.Utils
import gg.skytils.skytilsmod.utils.graphics.ScreenRenderer
import gg.skytils.skytilsmod.utils.graphics.SmartFontRenderer
import gg.skytils.skytilsmod.utils.graphics.SmartFontRenderer.TextAlignment
import gg.skytils.skytilsmod.utils.graphics.SmartFontRenderer.TextShadow
import gg.skytils.skytilsmod.utils.graphics.colors.CommonColors
Expand Down Expand Up @@ -766,11 +767,6 @@ object SpamHider : PersistentSave(File(Skytils.modDir, "spamhider.json")) {
animOnOff += 1.0
val x = animOnOff * (messageWidth + 30) * if (leftAlign) -1 else 1
val y = -1 * message.height
val shadow: TextShadow = when (Skytils.config.spamShadow) {
1 -> TextShadow.NONE
2 -> TextShadow.OUTLINE
else -> TextShadow.NORMAL
}
val alignment =
if (leftAlign) TextAlignment.LEFT_RIGHT else TextAlignment.RIGHT_LEFT
ScreenRenderer.fontRenderer.drawString(
Expand All @@ -779,7 +775,7 @@ object SpamHider : PersistentSave(File(Skytils.modDir, "spamhider.json")) {
y.toFloat(),
CommonColors.WHITE,
alignment,
shadow
textShadow
)
if (message.time > 4000) {
spamMessages.remove(message)
Expand All @@ -793,11 +789,6 @@ object SpamHider : PersistentSave(File(Skytils.modDir, "spamhider.json")) {
override fun demoRender() {
val messageWidth =
ScreenRenderer.fontRenderer.getStringWidth("§r§7Your Implosion hit §r§c3 §r§7enemies for §r§c1,000,000.0 §r§7damage.§r".stripControlCodes())
val shadow: TextShadow = when (Skytils.config.spamShadow) {
1 -> TextShadow.NONE
2 -> TextShadow.OUTLINE
else -> TextShadow.NORMAL
}
val x = (sin(90 * Math.PI / 180) * -1 + 1) * (messageWidth + 30)
val y = 0.0
ScreenRenderer.fontRenderer.drawString(
Expand All @@ -806,7 +797,7 @@ object SpamHider : PersistentSave(File(Skytils.modDir, "spamhider.json")) {
y.toFloat(),
CommonColors.WHITE,
TextAlignment.LEFT_RIGHT,
shadow
textShadow
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import gg.skytils.skytilsmod.events.impl.PacketEvent
import gg.skytils.skytilsmod.features.impl.handlers.MayorInfo
import gg.skytils.skytilsmod.utils.*
import gg.skytils.skytilsmod.utils.RenderUtil.highlight
import gg.skytils.skytilsmod.utils.graphics.SmartFontRenderer
import gg.skytils.skytilsmod.utils.graphics.colors.ColorFactory
import net.minecraft.client.entity.EntityOtherPlayerMP
import net.minecraft.client.renderer.GlStateManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ object ContainerSellValue {
).forEachIndexed { i, str ->
fr.drawString(
str, textPosX, (i * fr.FONT_HEIGHT).toFloat(),
CommonColors.WHITE, alignment, SmartFontRenderer.TextShadow.NORMAL
CommonColors.WHITE, alignment, textShadow
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import gg.skytils.skytilsmod.gui.elements.GIFResource
import gg.skytils.skytilsmod.utils.SuperSecretSettings
import gg.skytils.skytilsmod.utils.Utils
import gg.skytils.skytilsmod.utils.getSkytilsResource
import gg.skytils.skytilsmod.utils.graphics.SmartFontRenderer
import net.minecraft.client.entity.EntityPlayerSP
import net.minecraft.util.MathHelper
import net.minecraftforge.client.event.RenderWorldLastEvent
Expand Down Expand Up @@ -96,7 +97,7 @@ object Funny {
GuiManager.registerElement(JamCatElement)
}

object JamCatElement : GuiElement("Jamcat", x = 0, y = 0) {
object JamCatElement : GuiElement("Jamcat", x = 0, y = 0) { // textShadow is a bit useless here... Too bad!
val gif by lazy {
GIFResource(getSkytilsResource("splashes/jamcat.gif"), frameDelay = 5)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import gg.skytils.skytilsmod.utils.RenderUtil.highlight
import gg.skytils.skytilsmod.utils.RenderUtil.renderRarity
import gg.skytils.skytilsmod.utils.Utils.equalsOneOf
import gg.skytils.skytilsmod.utils.graphics.ScreenRenderer
import gg.skytils.skytilsmod.utils.graphics.SmartFontRenderer
import gg.skytils.skytilsmod.utils.graphics.SmartFontRenderer.TextAlignment
import gg.skytils.skytilsmod.utils.graphics.SmartFontRenderer.TextShadow
import gg.skytils.skytilsmod.utils.graphics.colors.CommonColors
Expand Down
Loading

0 comments on commit 5569957

Please sign in to comment.