diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
5 files changed, 142 insertions, 160 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt index df8adab37..7c61eade8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt @@ -1,20 +1,11 @@ // // TODO LIST // V2 RELEASE -// - Soulflow API // - Bank API (actually maybe not, I like the current design) -// - beacon power -// - skyblock level -// - more bg options (round, blurr, outline) // - countdown events like fishing festival + fiesta when its not on tablist -// - CookieAPI https://discord.com/channels/997079228510117908/1162844830360146080/1195695210433351821 -// - Rng meter display -// - option to hide coins earned +// - improve hide coin difference to also work with bits, motes, etc // - color options in the purse etc lines // - choose the amount of decimal places in shorten nums -// - more anchor points (alignment enums in renderutils) -// - 24h instead of 12h for skyblock time -// - only alert for lines that exist longer than 1s // package at.hannibal2.skyhanni.features.gui.customscoreboard @@ -34,9 +25,10 @@ import at.hannibal2.skyhanni.utils.DelayedRun.runDelayed import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.HorizontalAlignment import at.hannibal2.skyhanni.utils.RenderUtils.VerticalAlignment -import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAlignedWidth +import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderable import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase import at.hannibal2.skyhanni.utils.TabListData +import at.hannibal2.skyhanni.utils.renderables.Renderable import com.google.gson.JsonArray import com.google.gson.JsonPrimitive import net.minecraftforge.client.GuiIngameForge @@ -58,19 +50,25 @@ object CustomScoreboard { if (!isEnabled()) return if (display.isEmpty()) return - RenderBackground().renderBackground() - val render = if (!TabListData.fullyLoaded && displayConfig.cacheScoreboardOnIslandSwitch && cache.isNotEmpty()) { cache } else { display } - config.position.renderStringsAlignedWidth( - render, - posLabel = guiName, - extraSpace = displayConfig.lineSpacing - 10, + + val textRenderable = Renderable.verticalContainer( + render.map { Renderable.string(it.first, horizontalAlign = it.second) }, + 0, + horizontalAlign = HorizontalAlignment.CENTER, + verticalAlign = VerticalAlignment.CENTER, ) + + val finalRenderable = RenderBackground.addBackground(textRenderable) + + RenderBackground.updatePosition(finalRenderable) + + config.position.renderRenderable(finalRenderable, posLabel = guiName) } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboardUtils.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboardUtils.kt index d1eaf2abd..99fdc4f3f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboardUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboardUtils.kt @@ -23,7 +23,7 @@ object CustomScoreboardUtils { pattern.matchMatcher(line) { group(group) } - } ?: "0" + } fun getProfileTypeSymbol() = when { HypixelData.ironman -> "§7♲ " diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/RenderBackground.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/RenderBackground.kt index ebbb7fa30..44e5c927c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/RenderBackground.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/RenderBackground.kt @@ -1,139 +1,97 @@ package at.hannibal2.skyhanni.features.gui.customscoreboard -import at.hannibal2.skyhanni.config.core.config.Position import at.hannibal2.skyhanni.data.GuiEditManager import at.hannibal2.skyhanni.data.GuiEditManager.getAbsX import at.hannibal2.skyhanni.data.GuiEditManager.getAbsY -import at.hannibal2.skyhanni.data.GuiEditManager.getDummySize import at.hannibal2.skyhanni.utils.ColorUtils.toChromaColor import at.hannibal2.skyhanni.utils.RenderUtils +import at.hannibal2.skyhanni.utils.renderables.Renderable import net.minecraft.client.Minecraft import net.minecraft.client.gui.ScaledResolution -import net.minecraft.client.renderer.GlStateManager import net.minecraft.util.ResourceLocation -import org.lwjgl.opengl.GL11 -class RenderBackground { +object RenderBackground { - fun renderBackground() { - val alignmentConfig = CustomScoreboard.alignmentConfig + private val textureLocation by lazy { ResourceLocation("skyhanni", "scoreboard.png") } + + internal fun addBackground(renderable: Renderable): Renderable { val backgroundConfig = CustomScoreboard.backgroundConfig val outlineConfig = backgroundConfig.outline - val position = CustomScoreboard.config.position - val border = backgroundConfig.borderSize - - val x = position.getAbsX() - val y = position.getAbsY() - - val elementWidth = position.getDummySize().x - val elementHeight = position.getDummySize().y - - // Update the position to the alignment options - if ( - alignmentConfig.horizontalAlignment != RenderUtils.HorizontalAlignment.DONT_ALIGN - || alignmentConfig.verticalAlignment != RenderUtils.VerticalAlignment.DONT_ALIGN - ) { - position.set(updatePosition(position)) + val padding = backgroundConfig.borderSize + + if (!backgroundConfig.enabled) return renderable + + val backgroundRenderable = if (backgroundConfig.useCustomBackgroundImage) { + Renderable.drawInsideImage( + renderable, + textureLocation, + (backgroundConfig.customBackgroundImageOpacity * 255) / 100, + padding, + horizontalAlign = RenderUtils.HorizontalAlignment.CENTER, + verticalAlign = RenderUtils.VerticalAlignment.CENTER, + radius = backgroundConfig.roundedCornerSmoothness, + ) + } else { + Renderable.drawInsideRoundedRect( + renderable, + backgroundConfig.color.toChromaColor(), + padding, + backgroundConfig.roundedCornerSmoothness, + 1, + horizontalAlign = RenderUtils.HorizontalAlignment.CENTER, + verticalAlign = RenderUtils.VerticalAlignment.CENTER, + ) } - if (GuiEditManager.isInGui()) return - - GlStateManager.pushMatrix() - - GlStateManager.color(1f, 1f, 1f, 1f) - GL11.glDepthMask(false) - - if (backgroundConfig.enabled) { - if (backgroundConfig.useCustomBackgroundImage) { - val textureLocation = ResourceLocation("skyhanni", "scoreboard.png") - Minecraft.getMinecraft().textureManager.bindTexture(textureLocation) - - RenderUtils.drawRoundTexturedRect( - x - border, - y - border, - elementWidth + border * 3, - elementHeight + border * 2, - GL11.GL_NEAREST, - backgroundConfig.roundedCornerSmoothness, - ) - } else { - RenderUtils.drawRoundRect( - x - border, - y - border, - elementWidth + border * 3, - elementHeight + border * 2, - backgroundConfig.color.toChromaColor().rgb, - backgroundConfig.roundedCornerSmoothness, - ) - } - if (outlineConfig.enabled) { - RenderUtils.drawRoundRectOutline( - x - border, - y - border, - elementWidth + border * 3, - elementHeight + border * 2, - outlineConfig.colorTop.toChromaColor().rgb, - outlineConfig.colorBottom.toChromaColor().rgb, - outlineConfig.thickness, - backgroundConfig.roundedCornerSmoothness, - outlineConfig.blur, - ) - } - } - GL11.glDepthMask(true) - GlStateManager.popMatrix() + return if (outlineConfig.enabled) { + Renderable.drawInsideRoundedRectOutline( + backgroundRenderable, + 0, + backgroundConfig.roundedCornerSmoothness, + 1, + outlineConfig.colorTop.toChromaColor().rgb, + outlineConfig.colorBottom.toChromaColor().rgb, + outlineConfig.thickness, + outlineConfig.blur, + horizontalAlign = RenderUtils.HorizontalAlignment.CENTER, + verticalAlign = RenderUtils.VerticalAlignment.CENTER, + ) + } else backgroundRenderable } - private fun updatePosition(position: Position): Position { + internal fun updatePosition(renderable: Renderable) { + if (GuiEditManager.isInGui()) return val alignmentConfig = CustomScoreboard.alignmentConfig - val backgroundConfig = CustomScoreboard.backgroundConfig - val outlineConfig = backgroundConfig.outline - val border = backgroundConfig.borderSize - val x = position.getAbsX() - val y = position.getAbsY() + with(alignmentConfig) { + if (horizontalAlignment == RenderUtils.HorizontalAlignment.DONT_ALIGN && + verticalAlignment == RenderUtils.VerticalAlignment.DONT_ALIGN + ) return + } - val elementWidth = position.getDummySize().x - val elementHeight = position.getDummySize().y + val position = CustomScoreboard.config.position val scaledWidth = ScaledResolution(Minecraft.getMinecraft()).scaledWidth val scaledHeight = ScaledResolution(Minecraft.getMinecraft()).scaledHeight - - - var newX = when (alignmentConfig.horizontalAlignment) { - RenderUtils.HorizontalAlignment.LEFT -> border - RenderUtils.HorizontalAlignment.CENTER -> scaledWidth / 2 - (elementWidth + border * 3) / 2 - RenderUtils.HorizontalAlignment.RIGHT -> scaledWidth - (elementWidth + border * 2) - else -> x - } - - var newY = when (alignmentConfig.verticalAlignment) { - RenderUtils.VerticalAlignment.TOP -> border - RenderUtils.VerticalAlignment.CENTER -> scaledHeight / 2 - (elementHeight + border * 2) / 2 - RenderUtils.VerticalAlignment.BOTTOM -> scaledHeight - elementHeight - border - else -> y - } - - if (outlineConfig.enabled) { - val thickness = outlineConfig.thickness - if (alignmentConfig.horizontalAlignment == RenderUtils.HorizontalAlignment.RIGHT) { - newX -= thickness / 2 - } else if (alignmentConfig.horizontalAlignment == RenderUtils.HorizontalAlignment.LEFT) { - newX += thickness / 2 + val elementWidth = renderable.width + val elementHeight = renderable.height + + with(alignmentConfig) { + val x = when (horizontalAlignment) { + RenderUtils.HorizontalAlignment.DONT_ALIGN -> position.getAbsX() + RenderUtils.HorizontalAlignment.LEFT -> 0 + margin + RenderUtils.HorizontalAlignment.CENTER -> scaledWidth / 2 - elementWidth / 2 + RenderUtils.HorizontalAlignment.RIGHT -> scaledWidth - elementWidth - margin + else -> 0 } - - if (alignmentConfig.verticalAlignment == RenderUtils.VerticalAlignment.TOP) { - newY += thickness / 2 - } else if (alignmentConfig.verticalAlignment == RenderUtils.VerticalAlignment.BOTTOM) { - newY -= thickness / 2 + val y = when (verticalAlignment) { + RenderUtils.VerticalAlignment.DONT_ALIGN -> position.getAbsY() + RenderUtils.VerticalAlignment.TOP -> 0 + margin + RenderUtils.VerticalAlignment.CENTER -> scaledHeight / 2 - elementHeight / 2 + RenderUtils.VerticalAlignment.BOTTOM -> scaledHeight - elementHeight - margin + else -> 0 } + CustomScoreboard.config.position.moveTo(x, y) } - - return Position( - newX, - newY, - position.getScale(), - position.isCenter, - ) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt index 7c9757da2..57376dbbb 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt @@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.data.MaxwellAPI import at.hannibal2.skyhanni.data.MayorAPI import at.hannibal2.skyhanni.data.MiningAPI +import at.hannibal2.skyhanni.data.MiningAPI.inGlaciteArea import at.hannibal2.skyhanni.data.PartyAPI import at.hannibal2.skyhanni.data.PurseAPI import at.hannibal2.skyhanni.data.QuiverAPI @@ -52,6 +53,7 @@ import at.hannibal2.skyhanni.utils.RenderUtils.HorizontalAlignment import at.hannibal2.skyhanni.utils.SkyBlockTime import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase import at.hannibal2.skyhanni.utils.StringUtils.pluralize +import at.hannibal2.skyhanni.utils.TabListData import at.hannibal2.skyhanni.utils.TimeLimitedSet import at.hannibal2.skyhanni.utils.TimeUtils.format import at.hannibal2.skyhanni.utils.TimeUtils.formatted @@ -147,9 +149,15 @@ enum class ScoreboardElement( ::shouldShowChunkedStats, "§652,763,737 §7| §d64,647 §7| §6249M\n§b59,264 §7| §c23,495 §7| §a57,873\n§c♨ 0 §7| §b0❄ §7| §d756", ), + SOULFLOW( + ::getSoulflowDisplayPair, + ::getSoulflowDisplayWhen, + "Soulflow: §3761", + ), EMPTY_LINE( ::getEmptyLineDisplayPair, - { true }, "", + { true }, + "", ), ISLAND( ::getIslandDisplayPair, @@ -203,7 +211,8 @@ enum class ScoreboardElement( ), EMPTY_LINE2( ::getEmptyLineDisplayPair, - { true }, "", + { true }, + "", ), OBJECTIVE( ::getObjectiveDisplayPair, @@ -363,16 +372,17 @@ private fun getTitleDisplayPair(): List<ScoreboardElementType> = ).flatten() } -private fun getProfileDisplayPair() = - listOf(CustomScoreboardUtils.getProfileTypeSymbol() + HypixelData.profileName.firstLetterUppercase() to HorizontalAlignment.LEFT) +private fun getProfileDisplayPair() = listOf( + CustomScoreboardUtils.getProfileTypeSymbol() + HypixelData.profileName.firstLetterUppercase() + to HorizontalAlignment.LEFT, +) private fun getPurseDisplayPair(): List<ScoreboardElementType> { var purse = PurseAPI.currentPurse.formatNum() - val earned = getGroupFromPattern(ScoreboardData.sidebarLinesFormatted, PurseAPI.coinsPattern, "earned") - - if (earned != "0") { - purse += " §7(§e+$earned§7)§6" + if (!displayConfig.hideCoinsDifference) { + val earned = getGroupFromPattern(ScoreboardData.sidebarLinesFormatted, PurseAPI.coinsPattern, "earned") + if (earned != null) purse += " §7(§e+$earned§7)§6" } return listOf( @@ -387,7 +397,7 @@ private fun getPurseDisplayPair(): List<ScoreboardElementType> { private fun getPurseShowWhen() = !inAnyIsland(IslandType.THE_RIFT) private fun getMotesDisplayPair(): List<ScoreboardElementType> { - val motes = getMotes().formatNum() + val motes = getMotes()?.formatNum() ?: "0" return listOf( when { @@ -434,7 +444,7 @@ private fun getBitsDisplayPair(): List<ScoreboardElementType> { private fun getBitsShowWhen() = !HypixelData.bingo && !inAnyIsland(IslandType.CATACOMBS, IslandType.KUUDRA_ARENA) private fun getCopperDisplayPair(): List<ScoreboardElementType> { - val copper = getCopper().formatNum() + val copper = getCopper()?.formatNum() ?: "0" return listOf( when { @@ -467,8 +477,8 @@ private fun getHeatDisplayPair(): List<ScoreboardElementType> { return listOf( when { informationFilteringConfig.hideEmptyLines && heat == "§c♨ 0" -> "<hidden>" - displayConfig.displayNumbersFirst/* && heat != "§6IMMUNE" */ -> if (heat == "0") "§c♨ 0 Heat" else "$heat Heat" - else -> if (heat == "0") "Heat: §c♨ 0" else "Heat: $heat" + displayConfig.displayNumbersFirst -> heat?.let { "$heat Heat" } ?: "§c♨ 0 Heat" + else -> heat?.let { "Heat: $heat" } ?: "§c♨ 0 Heat" } to HorizontalAlignment.LEFT, ) } @@ -488,11 +498,11 @@ private fun getColdDisplayPair(): List<ScoreboardElementType> { ) } -private fun getColdShowWhen() = inAnyIsland(IslandType.DWARVEN_MINES, IslandType.MINESHAFT) - && ScoreboardData.sidebarLinesFormatted.any { ScoreboardPattern.coldPattern.matches(it) } +private fun getColdShowWhen() = inAnyIsland(IslandType.DWARVEN_MINES, IslandType.MINESHAFT) && + ScoreboardData.sidebarLinesFormatted.any { ScoreboardPattern.coldPattern.matches(it) } private fun getNorthStarsDisplayPair(): List<ScoreboardElementType> { - val northStars = getNorthStars().formatNum() + val northStars = getNorthStars()?.formatNum() ?: "0" return listOf( when { @@ -510,6 +520,20 @@ private fun getChunkedStatsDisplayPair(): List<ScoreboardElementType> = .chunked(chunkedConfig.maxStatsPerLine) .map { it.joinToString(" §f| ") to HorizontalAlignment.LEFT } +private fun getSoulflowDisplayPair(): List<ScoreboardElementType> { + val soulflow = getGroupFromPattern(TabListData.getTabList(), ScoreboardPattern.soulflowPattern, "soulflow") + ?.formatNum() ?: "0" + return listOf( + when { + informationFilteringConfig.hideEmptyLines && soulflow == "0" -> "<hidden>" + displayConfig.displayNumbersFirst -> "§3$soulflow Soulflow" + else -> "Soulflow: §3$soulflow" + } to HorizontalAlignment.LEFT, + ) +} + +private fun getSoulflowDisplayWhen() = !inAnyIsland(IslandType.THE_RIFT) + private fun getEmptyLineDisplayPair() = listOf("<empty>" to HorizontalAlignment.LEFT) private fun getIslandDisplayPair() = @@ -536,7 +560,8 @@ fun getPlayerAmountDisplayPair() = buildList { private fun getVisitDisplayPair() = listOf( - ScoreboardData.sidebarLinesFormatted.first { ScoreboardPattern.visitingPattern.matches(it) } to HorizontalAlignment.LEFT, + ScoreboardData.sidebarLinesFormatted.first { ScoreboardPattern.visitingPattern.matches(it) } to + HorizontalAlignment.LEFT, ) private fun getVisitShowWhen() = @@ -548,11 +573,12 @@ private fun getDateDisplayPair() = ) private fun getTimeDisplayPair(): List<ScoreboardElementType> { - var symbol = getGroupFromPattern(ScoreboardData.sidebarLinesFormatted, ScoreboardPattern.timePattern, "symbol") - if (symbol == "0") symbol = "" + val symbol = + getGroupFromPattern(ScoreboardData.sidebarLinesFormatted, ScoreboardPattern.timePattern, "symbol") ?: "" return listOf( "§7" + SkyBlockTime.now() - .formatted(dayAndMonthElement = false, yearElement = false) + " $symbol" to HorizontalAlignment.LEFT, + .formatted(dayAndMonthElement = false, yearElement = false, timeFormat24h = config.display.skyblockTime24hFormat) + + " $symbol" to HorizontalAlignment.LEFT, ) } @@ -668,14 +694,14 @@ private fun getQuiverDisplayPair(): List<ScoreboardElementType> { if (QuiverAPI.currentArrow == NONE_ARROW_TYPE) return listOf("No Arrows selected" to HorizontalAlignment.LEFT) - val amountString = (if (arrowConfig.colorArrowAmount) { - percentageColor( - QuiverAPI.currentAmount.toLong(), - QuiverAPI.MAX_ARROW_AMOUNT.toLong(), - ).getChatColor() - } else { - "" - }) + if (QuiverAPI.wearingSkeletonMasterChestplate) { + val amountString = ( + if (arrowConfig.colorArrowAmount) { + percentageColor( + QuiverAPI.currentAmount.toLong(), + QuiverAPI.MAX_ARROW_AMOUNT.toLong(), + ).getChatColor() + } else "" + ) + if (QuiverAPI.wearingSkeletonMasterChestplate) { "∞" } else { when (arrowConfig.arrowAmountDisplay) { @@ -809,11 +835,7 @@ private fun getPartyShowWhen() = if (DungeonAPI.inDungeon()) { if (partyConfig.showPartyEverywhere) { true } else { - inAnyIsland( - IslandType.DUNGEON_HUB, - IslandType.KUUDRA_ARENA, - IslandType.CRIMSON_ISLE, - ) + inAnyIsland(IslandType.DUNGEON_HUB, IslandType.KUUDRA_ARENA, IslandType.CRIMSON_ISLE) || inGlaciteArea() } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardPattern.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardPattern.kt index 2101409d1..126331ff2 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardPattern.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardPattern.kt @@ -570,6 +570,10 @@ object ScoreboardPattern { "bank", "^\\s*Bank: §6(?<bank>[\\w.,]+(?:§7 \\/ §6(?<coop>[\\w.,]+))?)$", ) + val soulflowPattern by tablistGroup.pattern( + "soulflow", + "^\\s*Soulflow: (?:§.)+(?<soulflow>[\\d,.]+)$", + ) val eventNamePattern by tablistGroup.pattern( "event", "^\\s*§e§lEvent: §r(?<name>§.*)$", |