Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add shadow options to chat input box #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/main/java/org/polyfrost/chatting/hook/GuiTextFieldHook.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.polyfrost.chatting.hook

import cc.polyfrost.oneconfig.platform.Platform
import cc.polyfrost.oneconfig.renderer.TextRenderer
import cc.polyfrost.oneconfig.utils.dsl.getAlpha
import org.polyfrost.chatting.config.ChattingConfig.chatInput
import org.polyfrost.chatting.utils.ModCompatHooks

object GuiTextFieldHook {
@JvmStatic
fun redirectDrawString(text: String, x: Float, y: Float, color: Int): Int {
return when (chatInput.inputTextRenderType) {
0 -> Platform.getGLPlatform().drawText(text, x, y, color, false).toInt()
1 -> Platform.getGLPlatform().drawText(text, x, y, color, true).toInt()
2 -> TextRenderer.drawBorderedText(text, x, y, color, color.getAlpha())
else -> ModCompatHooks.fontRenderer.drawString(text, x, y, color, true)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

@Mixin(ChatLine.class)
public class ChatLineMixin implements ChatLineHook {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

@Mixin(GuiIngameForge.class)
public class GuiIngameForgeMixin {

@ModifyArgs(method = "renderChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;translate(FFF)V"))
private void cancelTranslate(Args args) {
args.set(1, 0f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

@Mixin(GuiNewChat.class)
public abstract class GuiNewChatMixin_Movable {

@Shadow public abstract int getChatWidth();

@Unique private static ChatLine chatting$currentLine;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package org.polyfrost.chatting.mixin;

import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiTextField;
import org.polyfrost.chatting.chat.ChatHooks;
import org.polyfrost.chatting.config.ChattingConfig;
import org.polyfrost.chatting.hook.GuiTextFieldHook;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(GuiTextField.class)
public abstract class GuiTextFieldMixin {

@ModifyVariable(method = "drawTextBox", at = @At(value = "STORE"), ordinal = 5)
private int getRight(int right) {
if (ChatHooks.INSTANCE.checkField(this)) ChatHooks.INSTANCE.setInputRight(right);
return right;
}

// TODO: this method is called 3 times, here I'm targetting them all but I'm not really sure if that's required
@Redirect(method = "drawTextBox", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;drawStringWithShadow(Ljava/lang/String;FFI)I"))
private int drawStringWithShadow(FontRenderer fontRenderer, String text, float x, float y, int color) {
return GuiTextFieldHook.redirectDrawString(text, x, y, color);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

@Mixin(value = HUDUtils.class, remap = false)
public class HUDUtilsMixin {

@Inject(method = "addHudOptions", at = @At("TAIL"))
private static void hudUtils$modifyOptions(OptionPage page, Field field, Object instance, Config config, CallbackInfo ci) {
Hud hud = (Hud) ConfigUtils.getField(field, instance);
Expand All @@ -27,6 +26,7 @@ public class HUDUtilsMixin {
ConfigUtils.getSubCategory(page, hudAnnotation.category(), hudAnnotation.subcategory()).options.removeIf(HUDUtilsMixin::hudUtils$shouldRemove);
}

@Unique
private static boolean hudUtils$shouldRemove(BasicOption option) {
String fieldName = option.getField().getName();
Object hud = option.getParent();
Expand Down
8 changes: 7 additions & 1 deletion src/main/kotlin/org/polyfrost/chatting/chat/ChatInputBox.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.polyfrost.chatting.chat

import cc.polyfrost.oneconfig.config.annotations.Dropdown
import cc.polyfrost.oneconfig.config.annotations.Switch
import cc.polyfrost.oneconfig.hud.BasicHud
import cc.polyfrost.oneconfig.libs.universal.UMatrixStack
Expand All @@ -8,7 +9,6 @@ import net.minecraft.client.renderer.GlStateManager
import org.polyfrost.chatting.utils.ModCompatHooks

class ChatInputBox: BasicHud(true, -100f, -100f) {

init {
scale = 1f
paddingX = 0f
Expand All @@ -27,6 +27,12 @@ class ChatInputBox: BasicHud(true, -100f, -100f) {
)
var inputFieldDraft = false

@Dropdown(
name = "Input Text Render Type", options = ["No Shadow", "Shadow", "Full Shadow"],
description = "The type of shadow to render in the input field."
)
var inputTextRenderType = 1

fun drawBG(x: Float, y: Float, width: Float, height: Float) {
if (!ModCompatHooks.shouldDrawInputBox) return
GlStateManager.enableAlpha()
Expand Down
Loading