diff options
11 files changed, 271 insertions, 24 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/mining/MiningEventConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/mining/MiningEventConfig.java index 81eeb2b1a..8f5dac292 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/mining/MiningEventConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/mining/MiningEventConfig.java @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.config.features.mining; import at.hannibal2.skyhanni.config.FeatureToggle; import at.hannibal2.skyhanni.config.core.config.Position; +import at.hannibal2.skyhanni.features.mining.eventtracker.MiningEventType.Companion.CompressFormat; import com.google.gson.annotations.Expose; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDropdown; @@ -29,8 +30,13 @@ public class MiningEventConfig { @Expose @ConfigOption(name = "Compressed Format", desc = "Compresses the event names so that they are shorter.") + @ConfigEditorDropdown + public CompressFormat compressedFormat = CompressFormat.DEFAULT; + + @Expose + @ConfigOption(name = "Compressed Island", desc = "Shows the islands only as icon.") @ConfigEditorBoolean - public boolean compressedFormat = false; + public boolean islandAsIcon = false; @Expose @ConfigOption(name = "Show Passed Events", desc = "Shows the most recent passed event at the start greyed out. " + @@ -38,6 +44,7 @@ public class MiningEventConfig { @ConfigEditorBoolean public boolean passedEvents = false; + public enum ShowType { ALL("All Mining Islands"), CRYSTAL("Crystal Hollows Only"), diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/eventtracker/MiningEventDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/eventtracker/MiningEventDisplay.kt index 6a65b6302..18251dfb3 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/eventtracker/MiningEventDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/eventtracker/MiningEventDisplay.kt @@ -1,20 +1,28 @@ package at.hannibal2.skyhanni.features.mining.eventtracker import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.config.features.mining.MiningEventConfig import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.features.fame.ReminderUtils +import at.hannibal2.skyhanni.features.mining.eventtracker.MiningEventType.Companion.CompressFormat +import at.hannibal2.skyhanni.utils.ConfigUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland -import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings +import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName +import at.hannibal2.skyhanni.utils.NEUItems.getItemStack +import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark +import at.hannibal2.skyhanni.utils.renderables.Renderable +import net.minecraft.init.Blocks +import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object MiningEventDisplay { private val config get() = SkyHanniMod.feature.mining.miningEvent - private var display = listOf<String>() + private var display = listOf<Renderable>() private val islandEventData: MutableMap<IslandType, MiningIslandEventInfo> = mutableMapOf() @@ -27,7 +35,7 @@ object MiningEventDisplay { @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { if (!shouldDisplay()) return - config.position.renderStrings(display, posLabel = "Upcoming Events Display") + config.position.renderRenderables(display, posLabel = "Upcoming Events Display") } private fun updateDisplay() { @@ -36,12 +44,12 @@ object MiningEventDisplay { } private fun updateEvents() { - val list = mutableListOf<String>() + val list = mutableListOf<Renderable>() if (MiningEventTracker.apiError) { val count = MiningEventTracker.apiErrorCount - list.add("§cMining Event API Error! ($count)") - list.add("§cSwap servers to try again!") + list.add(Renderable.string("§cMining Event API Error! ($count)")) + list.add(Renderable.string("§cSwap servers to try again!")) } islandEventData.forEach { (islandType, eventDetails) -> @@ -61,19 +69,52 @@ object MiningEventDisplay { if (shouldShow) { val upcomingEvents = formatUpcomingEvents(eventDetails.islandEvents, eventDetails.lastEvent) - list.add("§a${islandType.displayName}§8: $upcomingEvents") + val island = + if (!config.islandAsIcon) Renderable.string("§a${islandType.displayName}§8:") else + Renderable.horizontalContainer( + listOf( + when (islandType) { + IslandType.DWARVEN_MINES -> Renderable.itemStack( + "PERFECT_RUBY_GEM".asInternalName().getItemStack() + ) + + IslandType.CRYSTAL_HOLLOWS -> Renderable.itemStack( + "MITHRIL_ORE".asInternalName().getItemStack() + ) + + IslandType.MINESHAFT -> Renderable.itemStack(ItemStack(Blocks.packed_ice)) + else -> unknownDisplay + }, + Renderable.string("§8:") + ) + ) + list.add( + Renderable.horizontalContainer( + listOf( + island, + *upcomingEvents + ), 3 + ) + ) } } display = list } - private fun formatUpcomingEvents(events: List<RunningEventType>, lastEvent: MiningEventType?): String { - val upcoming = events.filter { !it.endsAt.asTimeMark().isInPast() } - .map { if (it.isDoubleEvent) "${it.event} §8-> ${it.event}" else it.event.toString() }.toMutableList() + private val unknownDisplay = Renderable.string("§7???") + private val transitionDisplay = Renderable.string("§8->") - if (upcoming.isEmpty()) upcoming.add("§7???") - if (config.passedEvents && upcoming.size < 4) lastEvent?.let { upcoming.add(0, it.toPastString()) } - return upcoming.joinToString(" §8-> ") + private fun formatUpcomingEvents(events: List<RunningEventType>, lastEvent: MiningEventType?): Array<Renderable> { + val upcoming = events.filter { !it.endsAt.asTimeMark().isInPast() } + .flatMap { + if (it.isDoubleEvent) listOf(it.event, it.event) else listOf(it.event) + /* if (it.isDoubleEvent) "${it.event} §8-> ${it.event}" else it.event.toString() */ + }.map { it.getRenderable() }.toMutableList() + + if (upcoming.isEmpty()) upcoming.add(unknownDisplay) + if (config.passedEvents && upcoming.size < 4) lastEvent?.let { upcoming.add(0, it.getRenderableAsPast()) } + return upcoming.flatMap { listOf(it, transitionDisplay) }.dropLast(1).toTypedArray() + /* return upcoming.joinToString(" §8-> ") */ } fun updateData(eventData: MiningEventData) { @@ -95,6 +136,13 @@ object MiningEventDisplay { private fun shouldDisplay() = LorenzUtils.inSkyBlock && config.enabled && !ReminderUtils.isBusy() && !(!config.outsideMining && !LorenzUtils.inAdvancedMiningIsland()) + + @SubscribeEvent + fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { + event.transform(46, "mining.miningEvent.compressedFormat") { + ConfigUtils.migrateBooleanToEnum(it, CompressFormat.COMPACT_TEXT, CompressFormat.DEFAULT) + } + } } private class MiningIslandEventInfo(var islandEvents: List<RunningEventType>, var lastEvent: MiningEventType? = null) diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/eventtracker/MiningEventType.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/eventtracker/MiningEventType.kt index b71f8431f..312f291de 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/eventtracker/MiningEventType.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/eventtracker/MiningEventType.kt @@ -1,35 +1,147 @@ package at.hannibal2.skyhanni.features.mining.eventtracker import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.utils.ItemUtils +import at.hannibal2.skyhanni.utils.RenderUtils +import at.hannibal2.skyhanni.utils.StringUtils.allLettersFirstUppercase import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import at.hannibal2.skyhanni.utils.renderables.Renderable +import at.hannibal2.skyhanni.utils.renderables.Renderable.Companion.darken +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.init.Items +import net.minecraft.item.Item +import net.minecraft.item.ItemStack import kotlin.time.Duration import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds +private fun Item.toItemStack(meta: Int = 0): ItemStack = ItemStack(this, 1, meta) + enum class MiningEventType( val eventName: String, private val shortName: String, val defaultLength: Duration, private val colourCode: Char, val dwarvenSpecific: Boolean, + iconInput: Renderable, ) { - GONE_WITH_THE_WIND("GONE WITH THE WIND", "Wind", 18.minutes, '9', false), - DOUBLE_POWDER("2X POWDER", "2x", 15.minutes, 'b', false), - GOBLIN_RAID("GOBLIN RAID", "Raid", 5.minutes, 'c', true), - BETTER_TOGETHER("BETTER TOGETHER", "Better", 18.minutes, 'd', false), - RAFFLE("RAFFLE", "Raffle", 160.seconds, '6', true), - MITHRIL_GOURMAND("MITHRIL GOURMAND", "Gourmand", 10.minutes, 'b', true), + GONE_WITH_THE_WIND("GONE WITH THE WIND", "Wind", 18.minutes, '9', false, object : Renderable { + override val width = 10 + override val height = 10 + override val horizontalAlign = RenderUtils.HorizontalAlignment.LEFT + override val verticalAlign = RenderUtils.VerticalAlignment.CENTER + + val compass = Renderable.itemStack(Items.compass.toItemStack(), 0.45) + val wind = Renderable.string("§9≈", scale = 0.75) + + override fun render(posX: Int, posY: Int) { + GlStateManager.translate(1f, 1f, -2f) + compass.render(posX, posY) + GlStateManager.translate(-1f, -2f, 2f) + wind.render(posX, posY) + GlStateManager.translate(0f, 1f, 0f) + } + }), + DOUBLE_POWDER("2X POWDER", "2x", 15.minutes, 'b', false, object : Renderable { + override val width = 10 + override val height = 10 + override val horizontalAlign = RenderUtils.HorizontalAlignment.LEFT + override val verticalAlign = RenderUtils.VerticalAlignment.CENTER + + val dyeGreen = Renderable.itemStack(Items.dye.toItemStack(10), 0.45) + val dyePink = Renderable.itemStack(Items.dye.toItemStack(9), 0.45) + + override fun render(posX: Int, posY: Int) { + GlStateManager.translate(1f, 0f, 0f) + dyePink.render(posX + 1, posY - 1) + GlStateManager.translate(-2f, 1.5f, 0f) + dyeGreen.render(posX, posY) + GlStateManager.translate(1f, -1.5f, 0f) + } + + }), + GOBLIN_RAID( + "GOBLIN RAID", "Raid", 5.minutes, 'c', true, ItemUtils.createSkull( + "Goblin", + "32518c29-6127-3c71-b2a7-be4c3251e76f", + "ewogICJ0aW1lc3RhbXAiIDogMTYwNzQ2NDg4MTMwOCwKICAicHJvZmlsZUlkIiA6ICJhMmY4MzQ1OTVjODk0YTI3YWRkMzA0OTcxNmNhOTEwYyIsCiAgInByb2ZpbGVOYW1lIiA6ICJiUHVuY2giLAogICJzaWduYXR1cmVSZXF1aXJlZCIgOiB0cnVlLAogICJ0ZXh0dXJlcyIgOiB7CiAgICAiU0tJTiIgOiB7CiAgICAgICJ1cmwiIDogImh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTcyODUwOTA2YjdmMGQ5NTJjMGU1MDgwNzNjYzQzOWZkMzM3NGNjZjViODg5YzA2ZjdlOGQ5MGNjMGNjMjU1YyIKICAgIH0KICB9Cn0=" + ) + ), + BETTER_TOGETHER("BETTER TOGETHER", "Better", 18.minutes, 'd', false, object : Renderable { + override val width = 10 + override val height = 10 + override val horizontalAlign = RenderUtils.HorizontalAlignment.LEFT + override val verticalAlign = RenderUtils.VerticalAlignment.CENTER + + val steveHead = Renderable.itemStack(Items.skull.toItemStack(3), 0.36) + val alexHead = Renderable.itemStack( + ItemUtils.createSkull( + "Alex", + "6ab43178-89fd-4905-97f6-0f67d9d76fd9", + "fRBfVNlIWW6cL478st/8NsNEHVxjvwQDp4+MbKbFj1tPZvxXgpIXRaQsLeDl/0+E4tipPKNANAbmqj9EKAVx3b3gDqLLrTTk/NfuH2RD3I5ppzio8w5oYk1022SopaayGBP4+kuwktDHzlR8IgAUb1RiavldKp+TGRdCbqw8vHHBm9pnuOePzTOOADQgdanRj98bOcfIXe69tSS/VHxDe9tkpYFPkQR8zsJcjUxf+nS83iFU9CW9lKtQlyoU6/BPbHFILvcR1KDR5Imj7GJe2OJefghI6OqtHNZP2tzkia2IDU0Yc4ikwC+7yN3i6I3Do4G3gTtCZVfNXiSdFyU9nCMyBxggTaG9zaljZpN0BynG4FzYMujIVgeNa6FLqwoaFT0iELW2w9JgJFgyVlaDKEqMSGyxgqtcQMPBuvCwMFFjeFd2EhtfTjQ4hcpva+NXXoYPP7yfTk/0DErNZV2dUTasekar8lH6U58B7ECNxDUwcon4z7sSO5mdlPJoiT7zllgpwQn5NUPaxZxaKkGdUIFEGzjmBfnCmk6MOqzi05Rr18wnkdic9hz/fIzzTMhn9mbMG6VF9eBkE4mNu1K5jai6II5Mz9BV49U0ZcA874N1VHpJpQE6762TYv+u7ICTRIOf2LD9wEgu3py/nX+IHma5j22ClUtXH3hYdZmHg+s=\",Value:\"ewogICJ0aW1lc3RhbXAiIDogMTcxMTY1OTI2NDg1NSwKICAicHJvZmlsZUlkIiA6ICI2YWI0MzE3ODg5ZmQ0OTA1OTdmNjBmNjdkOWQ3NmZkOSIsCiAgInByb2ZpbGVOYW1lIiA6ICJNSEZfQWxleCIsCiAgInNpZ25hdHVyZVJlcXVpcmVkIiA6IHRydWUsCiAgInRleHR1cmVzIiA6IHsKICAgICJTS0lOIiA6IHsKICAgICAgInVybCIgOiAiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS84M2NlZTVjYTZhZmNkYjE3MTI4NWFhMDBlODA0OWMyOTdiMmRiZWJhMGVmYjhmZjk3MGE1Njc3YTFiNjQ0MDMyIiwKICAgICAgIm1ldGFkYXRhIiA6IHsKICAgICAgICAibW9kZWwiIDogInNsaW0iCiAgICAgIH0KICAgIH0KICB9Cn0=" + ), 0.36 + ) + + override fun render(posX: Int, posY: Int) { + GlStateManager.translate(-1f, 0f, 0f) + alexHead.render(posX, posY) + GlStateManager.translate(+4f, +3f, 0f) + steveHead.render(posX, posY) + GlStateManager.translate(-3f, -3f, 0f) + } + + }), + RAFFLE( + "RAFFLE", "Raffle", 160.seconds, '6', true, Items.name_tag.toItemStack() + ), + MITHRIL_GOURMAND("MITHRIL GOURMAND", "Gourmand", 10.minutes, 'b', true, Items.dye.toItemStack(6)), ; - override fun toString() = - if (config.compressedFormat) "§$colourCode$shortName" else "§$colourCode$eventName" + constructor( + eventName: String, + shortName: String, + defaultLength: Duration, + colourCode: Char, + dwarvenSpecific: Boolean, + iconInput: ItemStack, + ) : this( + eventName, shortName, defaultLength, colourCode, dwarvenSpecific, Renderable.itemStack( + iconInput, xSpacing = 0 + ) + ) + + val icon = Renderable.hoverTips(iconInput, listOf(eventName)) + val compactText = Renderable.string("§$colourCode$shortName") + val normalText = Renderable.string("§$colourCode$eventName") - fun toPastString() = - if (config.compressedFormat) "§7$shortName" else "§7$eventName" + val compactTextWithIcon = Renderable.horizontalContainer(listOf(icon, compactText), 0) + val normalTextWithIcon = Renderable.horizontalContainer(listOf(icon, normalText), 0) + + fun getRenderable(): Renderable = when (config.compressedFormat) { + CompressFormat.COMPACT_TEXT -> compactTextWithIcon + CompressFormat.ICON_ONLY -> icon + CompressFormat.TEXT_WITHOUT_ICON -> normalText + CompressFormat.COMPACT_TEXT_WITHOUT_ICON -> compactText + CompressFormat.DEFAULT, null -> normalTextWithIcon + } + + fun getRenderableAsPast(): Renderable = getRenderable().darken(0.4f) companion object { private val config get() = SkyHanniMod.feature.mining.miningEvent + enum class CompressFormat { + DEFAULT, + COMPACT_TEXT, + ICON_ONLY, + TEXT_WITHOUT_ICON, + COMPACT_TEXT_WITHOUT_ICON; + + override fun toString(): String { + return name.lowercase().allLettersFirstUppercase() + } + } + fun fromEventName(bossbarName: String): MiningEventType? { return MiningEventType.entries.find { it.eventName == bossbarName.removeColor() } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/DarkenShader.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/DarkenShader.kt new file mode 100644 index 000000000..1a42522de --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/DarkenShader.kt @@ -0,0 +1,17 @@ +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.utils.shader.Shader +import at.hannibal2.skyhanni.utils.shader.Uniform + +object DarkenShader : Shader("darken", "darken") { + + val INSTANCE: DarkenShader + get() = this + + var darknessLevel = 0f + + override fun registerUniforms() { + registerUniform(Uniform.UniformType.FLOAT, "darknessLevel") { darknessLevel } + } +} + diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ConfigUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ConfigUtils.kt index 239f250a0..94d981d8e 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ConfigUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ConfigUtils.kt @@ -65,6 +65,19 @@ object ConfigUtils { return JsonPrimitive(getEnumConstantFromLegacyId(element.asInt, enumClass)?.name) } + /** + * Migrates a Boolean to an Enum Constant. + * + * @param element The JsonElement to migrate + * @param trueValue The enum value it should map to if the value is true + * @param falseValue The enum value it should map to if the value is false + * @return The migrated JsonElement + */ + fun <T : Enum<T>> migrateBooleanToEnum(element: JsonElement, trueValue: T, falseValue: T): JsonElement { + require(element is JsonPrimitive) { "Expected a JsonPrimitive but got ${element.javaClass.simpleName}" } + return JsonPrimitive(if (element.asBoolean) trueValue.name else falseValue.name) + } + fun KMutableProperty0<*>.tryFindEditor(editor: MoulConfigEditor<*>): ProcessedOption? { return editor.processedConfig.getOptionFromField(this.javaField ?: return null) } 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 d893cef52..88b291844 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.data.HighlightOnHoverSlot import at.hannibal2.skyhanni.data.ToolTipData import at.hannibal2.skyhanni.features.chroma.ChromaShaderManager import at.hannibal2.skyhanni.features.chroma.ChromaType +import at.hannibal2.skyhanni.features.misc.DarkenShader import at.hannibal2.skyhanni.utils.CollectionUtils.contains import at.hannibal2.skyhanni.utils.ColorUtils import at.hannibal2.skyhanni.utils.ColorUtils.darker @@ -23,7 +24,9 @@ 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 at.hannibal2.skyhanni.utils.shader.ShaderManager import io.github.notenoughupdates.moulconfig.gui.GuiScreenElementWrapper +import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.client.Minecraft import net.minecraft.client.gui.Gui import net.minecraft.client.gui.GuiIngameMenu @@ -327,6 +330,20 @@ interface Renderable { } } + fun Renderable.darken(amount: Float = 1.0f) = object : Renderable { + override val width = this@darken.width + override val height = this@darken.height + override val horizontalAlign = this@darken.horizontalAlign + override val verticalAlign = this@darken.verticalAlign + + override fun render(posX: Int, posY: Int) { + DarkenShader.darknessLevel = amount + ShaderManager.enableShader("darken") + this@darken.render(posX, posY) + ShaderManager.disableShader() + } + } + fun singeltonString(string: String): List<Renderable> { return Collections.singletonList(string(string)) } 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 fdc34f0ae..89efd7d9f 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderHelper.kt @@ -137,6 +137,10 @@ class ShaderHelper { if (USING_ARB_SHADERS) ARBShaderObjects.glUniform1fARB(location, v0) else GL20.glUniform1f(location, v0) } + fun glUniform1i(location: Int, v0: Int) { + if (USING_ARB_SHADERS) ARBShaderObjects.glUniform1iARB(location, v0) else GL20.glUniform1i(location, v0) + } + fun glUniform2f(location: Int, v0: Float, v1: Float) { if (USING_ARB_SHADERS) ARBShaderObjects.glUniform2fARB(location, v0, v1) else GL20.glUniform2f( location, 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 3efcb0b77..b32e3fa26 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderManager.kt @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.utils.shader import at.hannibal2.skyhanni.features.chroma.StandardChromaShader import at.hannibal2.skyhanni.features.chroma.TexturedChromaShader +import at.hannibal2.skyhanni.features.misc.DarkenShader import at.hannibal2.skyhanni.features.misc.RoundedRectangleOutlineShader import at.hannibal2.skyhanni.features.misc.RoundedRectangleShader import at.hannibal2.skyhanni.test.command.ErrorManager @@ -27,8 +28,11 @@ object ShaderManager { TEXTURED_CHROMA(TexturedChromaShader.INSTANCE), ROUNDED_RECTANGLE(RoundedRectangleShader.INSTANCE), ROUNDED_RECT_OUTLINE(RoundedRectangleOutlineShader.INSTANCE), + DARKEN(DarkenShader.INSTANCE) ; + fun enableShader() = ShaderManager.enableShader(name.lowercase()) + companion object { fun getShaderInstance(shaderName: String): Shader? = when (shaderName) { @@ -36,6 +40,7 @@ object ShaderManager { "textured_chroma" -> TEXTURED_CHROMA.shader "rounded_rect" -> ROUNDED_RECTANGLE.shader "rounded_rect_outline" -> ROUNDED_RECT_OUTLINE.shader + "darken" -> DARKEN.shader else -> { null } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/shader/Uniform.kt b/src/main/java/at/hannibal2/skyhanni/utils/shader/Uniform.kt index 78f9ef569..e3adf2b4d 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/shader/Uniform.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/shader/Uniform.kt @@ -24,6 +24,7 @@ class Uniform<T>( val VEC2: UniformType<FloatArray> = UniformType() val VEC3: UniformType<FloatArray> = UniformType() val BOOL: UniformType<Boolean> = UniformType() + val INT: UniformType<Int> = UniformType() } } @@ -49,6 +50,7 @@ class Uniform<T>( } UniformType.BOOL -> ShaderHelper.glUniform1f(uniformID, if (newUniformValue as Boolean) 1f else 0f) + UniformType.INT -> ShaderHelper.glUniform1i(uniformID, (newUniformValue as Int)) } previousUniformValue = newUniformValue } diff --git a/src/main/resources/assets/skyhanni/shaders/darken.fsh b/src/main/resources/assets/skyhanni/shaders/darken.fsh new file mode 100644 index 000000000..cfc118eef --- /dev/null +++ b/src/main/resources/assets/skyhanni/shaders/darken.fsh @@ -0,0 +1,13 @@ +#version 120 + +// Fragment Shader +uniform sampler2D texture; +uniform float darknessLevel; + +varying vec4 outColor; + +void main() { + vec4 color = texture2D(texture, gl_TexCoord[0].st) * outColor; + vec3 darkenedColor = color.rgb * darknessLevel; + gl_FragColor = vec4(darkenedColor, color.a); +} diff --git a/src/main/resources/assets/skyhanni/shaders/darken.vsh b/src/main/resources/assets/skyhanni/shaders/darken.vsh new file mode 100644 index 000000000..210bee872 --- /dev/null +++ b/src/main/resources/assets/skyhanni/shaders/darken.vsh @@ -0,0 +1,9 @@ +#version 120 + +varying vec4 outColor; + +void main() { + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + gl_TexCoord[0] = gl_MultiTexCoord0; + outColor = gl_Color; +} |