diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2021-12-31 15:22:31 +0700 |
---|---|---|
committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2021-12-31 15:22:31 +0700 |
commit | 503bbd969e929c42221d835c7f124940648100f2 (patch) | |
tree | d2dd2f827ddb4a6556e237d3fe4a102d12412e05 /src | |
parent | fa0f88fff7e617d522d69ae3989477c43a5f35e7 (diff) | |
download | Chatting-503bbd969e929c42221d835c7f124940648100f2.tar.gz Chatting-503bbd969e929c42221d835c7f124940648100f2.tar.bz2 Chatting-503bbd969e929c42221d835c7f124940648100f2.zip |
Text Render Type
update to mixin 0.8 (may break dev env)
Diffstat (limited to 'src')
11 files changed, 106 insertions, 11 deletions
diff --git a/src/main/java/com/raeids/stratus/hook/GuiNewChatHook.java b/src/main/java/com/raeids/stratus/hook/GuiNewChatHook.java index 4db0b51..67552c4 100644 --- a/src/main/java/com/raeids/stratus/hook/GuiNewChatHook.java +++ b/src/main/java/com/raeids/stratus/hook/GuiNewChatHook.java @@ -18,4 +18,6 @@ public interface GuiNewChatHook { String getPrevText(); void setPrevText(String prevText); + + int getTextOpacity(); } diff --git a/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java b/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java index 4e79cac..e701758 100644 --- a/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java +++ b/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java @@ -3,9 +3,9 @@ package com.raeids.stratus.mixin; import com.raeids.stratus.Stratus; import com.raeids.stratus.chat.ChatSearchingManager; import com.raeids.stratus.chat.ChatTabs; -import com.raeids.stratus.utils.ModCompatHooks; import com.raeids.stratus.config.StratusConfig; import com.raeids.stratus.hook.GuiNewChatHook; +import com.raeids.stratus.utils.ModCompatHooks; import com.raeids.stratus.utils.RenderHelper; import gg.essential.universal.UMouse; import net.minecraft.client.Minecraft; @@ -15,7 +15,7 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IChatComponent; import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; -import org.spongepowered.asm.lib.Opcodes; +import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -36,6 +36,7 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { @Unique private int stratus$right = 0; @Unique private boolean stratus$shouldCopy; @Unique private boolean stratus$chatCheck; + @Unique private int stratus$textOpacity; @Shadow @Final private Minecraft mc; @Shadow @Final private List<ChatLine> drawnChatLines; @SuppressWarnings({"FieldCanBeLocal", "unused"}) @@ -113,6 +114,16 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { return ChatSearchingManager.filterMessages(stratus$previousText, drawnChatLines); } + @ModifyVariable(method = "drawChat", at = @At("STORE"), slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/util/MathHelper;clamp_double(DDD)D"), to = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/ChatLine;getChatComponent()Lnet/minecraft/util/IChatComponent;")), name = "l1") + private int modifyYeah(int value) { + return stratus$textOpacity = value; + } + + @Redirect(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;drawStringWithShadow(Ljava/lang/String;FFI)I")) + private int redirectDrawString(FontRenderer instance, String text, float x, float y, int color) { + return ModCompatHooks.redirectDrawString(text, x, y, color); + } + @Inject(method = "drawChat", at = @At("RETURN")) private void checkStuff(int j2, CallbackInfo ci) { if (!stratus$chatCheck && stratus$shouldCopy) { @@ -221,4 +232,9 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { public void setPrevText(String prevText) { stratus$previousText = prevText; } + + @Override + public int getTextOpacity() { + return stratus$textOpacity; + } } diff --git a/src/main/kotlin/com/raeids/stratus/config/StratusConfig.kt b/src/main/kotlin/com/raeids/stratus/config/StratusConfig.kt index de26dcb..4e00bf8 100644 --- a/src/main/kotlin/com/raeids/stratus/config/StratusConfig.kt +++ b/src/main/kotlin/com/raeids/stratus/config/StratusConfig.kt @@ -9,11 +9,22 @@ import com.raeids.stratus.updater.DownloadGui import com.raeids.stratus.updater.Updater import gg.essential.api.EssentialAPI import gg.essential.vigilance.Vigilant +import gg.essential.vigilance.data.Category import gg.essential.vigilance.data.Property import gg.essential.vigilance.data.PropertyType +import gg.essential.vigilance.data.SortingBehavior import java.io.File -object StratusConfig : Vigilant(File(Stratus.modDir, "${Stratus.ID}.toml"), Stratus.NAME) { +object StratusConfig : Vigilant(File(Stratus.modDir, "${Stratus.ID}.toml"), Stratus.NAME, sortingBehavior = ConfigSorting) { + + @Property( + type = PropertyType.SELECTOR, + name = "Text Render Type", + description = "Choose the type of rendering for the text.", + category = "General", + options = ["No Shadow", "Shadow", "Full Shadow"] + ) + var textRenderType = 1 @Property( type = PropertyType.SWITCH, @@ -163,4 +174,14 @@ object StratusConfig : Vigilant(File(Stratus.modDir, "${Stratus.ID}.toml"), Stra ChatShortcuts.initialize() } } + + private object ConfigSorting : SortingBehavior() { + override fun getCategoryComparator(): Comparator<in Category> = Comparator { o1, o2 -> + if (o1.name == "General") return@Comparator -1 + if (o2.name == "General") return@Comparator 1 + else compareValuesBy(o1, o2) { + it.name + } + } + } }
\ No newline at end of file diff --git a/src/main/kotlin/com/raeids/stratus/gui/ChatShortcutEditGui.kt b/src/main/kotlin/com/raeids/stratus/gui/ChatShortcutEditGui.kt index 5a52ea3..6552c36 100644 --- a/src/main/kotlin/com/raeids/stratus/gui/ChatShortcutEditGui.kt +++ b/src/main/kotlin/com/raeids/stratus/gui/ChatShortcutEditGui.kt @@ -3,6 +3,7 @@ package com.raeids.stratus.gui import com.raeids.stratus.chat.ChatShortcuts import gg.essential.api.EssentialAPI import gg.essential.api.gui.buildConfirmationModal +import gg.essential.elementa.ElementaVersion import gg.essential.elementa.WindowScreen import gg.essential.elementa.components.UIBlock import gg.essential.elementa.constraints.CenterConstraint @@ -16,7 +17,7 @@ import gg.essential.vigilance.gui.settings.ButtonComponent import gg.essential.vigilance.gui.settings.TextComponent class ChatShortcutEditGui(private var alias: String, private var command: String, private val editing: Boolean) : - WindowScreen(restoreCurrentGuiOnClose = true) { + WindowScreen(restoreCurrentGuiOnClose = true, version = ElementaVersion.V1) { private val initialAlias = alias private val initialCommand = command @@ -71,7 +72,7 @@ class ChatShortcutEditGui(private var alias: String, private var command: String } inner class ChatShortcutConfirmGui(private var alias: String, private var command: String) : - WindowScreen(restoreCurrentGuiOnClose = true) { + WindowScreen(restoreCurrentGuiOnClose = true, version = ElementaVersion.V1) { override fun initScreen(width: Int, height: Int) { super.initScreen(width, height) EssentialAPI.getEssentialComponentFactory().buildConfirmationModal { diff --git a/src/main/kotlin/com/raeids/stratus/gui/ChatShortcutViewGui.kt b/src/main/kotlin/com/raeids/stratus/gui/ChatShortcutViewGui.kt index 06dfcbd..6efd29c 100644 --- a/src/main/kotlin/com/raeids/stratus/gui/ChatShortcutViewGui.kt +++ b/src/main/kotlin/com/raeids/stratus/gui/ChatShortcutViewGui.kt @@ -3,6 +3,7 @@ package com.raeids.stratus.gui import com.raeids.stratus.chat.ChatShortcuts import com.raeids.stratus.gui.components.TextBlock import gg.essential.api.EssentialAPI +import gg.essential.elementa.ElementaVersion import gg.essential.elementa.WindowScreen import gg.essential.elementa.components.UIBlock import gg.essential.elementa.constraints.CenterConstraint @@ -12,7 +13,7 @@ import gg.essential.elementa.dsl.* import gg.essential.vigilance.gui.VigilancePalette import gg.essential.vigilance.gui.settings.ButtonComponent -class ChatShortcutViewGui : WindowScreen() { +class ChatShortcutViewGui : WindowScreen(version = ElementaVersion.V1) { override fun initScreen(width: Int, height: Int) { super.initScreen(width, height) for ((yes, shortcut) in ChatShortcuts.shortcuts.withIndex()) { diff --git a/src/main/kotlin/com/raeids/stratus/gui/components/TextBlock.kt b/src/main/kotlin/com/raeids/stratus/gui/components/TextBlock.kt index 9b36fa4..63b3d01 100644 --- a/src/main/kotlin/com/raeids/stratus/gui/components/TextBlock.kt +++ b/src/main/kotlin/com/raeids/stratus/gui/components/TextBlock.kt @@ -9,6 +9,10 @@ import gg.essential.elementa.state.BasicState import gg.essential.vigilance.gui.VigilancePalette import gg.essential.vigilance.gui.settings.SettingComponent +/** + * Heavily modified from Vigilance under LGPLv3 (modified to be just a text block) + * https://github.com/Sk1erLLC/Vigilance/blob/master/LICENSE + */ class TextBlock( text: String ) : SettingComponent() { @@ -21,13 +25,13 @@ class TextBlock( 1f ).bindColor(BasicState(VigilancePalette.getDivider())) - private val textInput: UIText = UIText(text) constrain { + private val text: UIText = UIText(text) constrain { x = 3.pixels() y = 3.pixels() } init { - textInput childOf textHolder + this.text childOf textHolder constrain { width = ChildBasedSizeConstraint() diff --git a/src/main/kotlin/com/raeids/stratus/updater/DownloadGui.kt b/src/main/kotlin/com/raeids/stratus/updater/DownloadGui.kt index d3fa69e..4fc465f 100644 --- a/src/main/kotlin/com/raeids/stratus/updater/DownloadGui.kt +++ b/src/main/kotlin/com/raeids/stratus/updater/DownloadGui.kt @@ -4,11 +4,12 @@ import com.raeids.stratus.Stratus import gg.essential.api.EssentialAPI import gg.essential.api.gui.buildConfirmationModal import gg.essential.api.utils.Multithreading +import gg.essential.elementa.ElementaVersion import gg.essential.elementa.WindowScreen import gg.essential.elementa.dsl.childOf import java.io.File -class DownloadGui : WindowScreen(true, true, true, -1) { +class DownloadGui : WindowScreen(ElementaVersion.V1, true, true, true, -1) { override fun initScreen(width: Int, height: Int) { super.initScreen(width, height) EssentialAPI.getEssentialComponentFactory().buildConfirmationModal { diff --git a/src/main/kotlin/com/raeids/stratus/updater/Updater.kt b/src/main/kotlin/com/raeids/stratus/updater/Updater.kt index 11368fd..22ac905 100644 --- a/src/main/kotlin/com/raeids/stratus/updater/Updater.kt +++ b/src/main/kotlin/com/raeids/stratus/updater/Updater.kt @@ -27,7 +27,7 @@ object Updater { DefaultArtifactVersion(Stratus.VER.substringBefore("-")) val latestVersion = DefaultArtifactVersion(latestTag!!.substringAfter("v").substringBefore("-")) if (currentVersion >= latestVersion) { - if (!Stratus.VER.contains("-")) { + if (currentVersion != latestVersion || !Stratus.VER.contains("-")) { return@runAsync } } diff --git a/src/main/kotlin/com/raeids/stratus/utils/ModCompatHooks.kt b/src/main/kotlin/com/raeids/stratus/utils/ModCompatHooks.kt index b28e9ea..dde7165 100644 --- a/src/main/kotlin/com/raeids/stratus/utils/ModCompatHooks.kt +++ b/src/main/kotlin/com/raeids/stratus/utils/ModCompatHooks.kt @@ -4,6 +4,8 @@ import club.sk1er.patcher.config.PatcherConfig import com.llamalad7.betterchat.BetterChat import com.raeids.stratus.Stratus.isBetterChat import com.raeids.stratus.Stratus.isPatcher +import com.raeids.stratus.config.StratusConfig.textRenderType +import com.raeids.stratus.utils.RenderHelper.drawBorderedString import net.minecraft.client.Minecraft import net.minecraft.client.gui.FontRenderer @@ -28,4 +30,17 @@ object ModCompatHooks { @JvmStatic val fontRenderer: FontRenderer get() = Minecraft.getMinecraft().fontRendererObj + + @JvmStatic + fun redirectDrawString(text: String, x: Float, y: Float, color: Int): Int { + return when (textRenderType) { + 0 -> { + fontRenderer.drawString(text, x, y, color, false) + } + 2 -> { + drawBorderedString(fontRenderer, text, x.toInt(), y.toInt(), color) + } + else -> fontRenderer.drawString(text, x, y, color, true) + } + } } diff --git a/src/main/kotlin/com/raeids/stratus/utils/RenderHelper.kt b/src/main/kotlin/com/raeids/stratus/utils/RenderHelper.kt index 95de4d8..8fd417b 100644 --- a/src/main/kotlin/com/raeids/stratus/utils/RenderHelper.kt +++ b/src/main/kotlin/com/raeids/stratus/utils/RenderHelper.kt @@ -1,6 +1,9 @@ package com.raeids.stratus.utils import com.raeids.stratus.config.StratusConfig +import com.raeids.stratus.hook.GuiNewChatHook +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.FontRenderer import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.renderer.texture.TextureUtil import net.minecraft.client.shader.Framebuffer @@ -18,9 +21,12 @@ import java.lang.reflect.Method import java.nio.ByteBuffer import java.nio.ByteOrder import javax.imageio.ImageIO +import kotlin.math.roundToInt object RenderHelper { + private val regex = Regex("(?i)\\u00A7[0-9a-f]") + /** * Taken from https://github.com/Moulberry/HyChat * Modified so if not on Windows just in case it will switch it to RGB and remove the transparent background. @@ -208,4 +214,32 @@ object RenderHelper { framebuffer.bindFramebuffer(true) return framebuffer } + + /** + * Taken from https://github.com/Moulberry/HyChat + */ + fun drawBorderedString( + fontRendererIn: FontRenderer, + text: String, + x: Int, + y: Int, + color: Int + ): Int { + val noColors = text.replace(regex, "\u00A7r") + var yes = 0 + if (((Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).textOpacity / 4) > 3) { + for (xOff in -2..2) { + for (yOff in -2..2) { + if (xOff * xOff != yOff * yOff) { + yes += fontRendererIn.drawString( + noColors, + (xOff / 2f) + x, (yOff / 2f) + y, ((Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).textOpacity / 4) shl 24, false + ) + } + } + } + } + yes += fontRendererIn.drawString(text, x, y, color) + return yes + } }
\ No newline at end of file diff --git a/src/main/resources/mixins.stratus.json b/src/main/resources/mixins.stratus.json index fc3d100..71ce68e 100644 --- a/src/main/resources/mixins.stratus.json +++ b/src/main/resources/mixins.stratus.json @@ -1,6 +1,6 @@ { "compatibilityLevel": "JAVA_8", - "minVersion": "0.7", + "minVersion": "0.8", "package": "com.raeids.stratus.mixin", "refmap": "mixins.${id}.refmap.json", "mixins": [ |