Skip to content

Commit

Permalink
custom chat width
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed Mar 14, 2024
1 parent d62d36f commit 8e2abe0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private void drawChatBox(Args args) {

@ModifyVariable(method = "setChatLine", at = @At(value = "STORE"), ordinal = 2)
private int wrap(int value) {
return calculateChatboxWidth(mc.gameSettings.chatWidth);
return ChattingConfig.INSTANCE.getChatWindow().getCustomChatWidth() ? Chatting.INSTANCE.getChatWidth() : calculateChatboxWidth(mc.gameSettings.chatWidth);
}

private boolean isHovered(int x, int y, int width, int height) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ private void customHeight_getChatHeight(CallbackInfoReturnable<Integer> cir) {
if (ChattingConfig.INSTANCE.getChatWindow().getCustomChatHeight())
cir.setReturnValue(Chatting.INSTANCE.getChatHeight(getChatOpen()));
}

@Inject(method = "getChatWidth", at = @At("HEAD"), cancellable = true)
private void customWidth_getChatWidth(CallbackInfoReturnable<Integer> cir) {
if (ChattingConfig.INSTANCE.getChatWindow().getCustomChatWidth())
cir.setReturnValue(Chatting.INSTANCE.getChatWidth());
}
}
6 changes: 6 additions & 0 deletions src/main/java/org/polyfrost/chatting/mixin/HUDUtilsMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import cc.polyfrost.oneconfig.config.elements.*;
import cc.polyfrost.oneconfig.hud.*;
import cc.polyfrost.oneconfig.internal.hud.HudCore;
import net.minecraft.client.Minecraft;
import org.polyfrost.chatting.chat.*;
import org.polyfrost.chatting.config.ChattingConfig;
import org.spongepowered.asm.mixin.*;
Expand Down Expand Up @@ -54,6 +55,11 @@ public class HUDUtilsMixin {
case "focusedHeight":
case "unfocusedHeight":
option.addDependency("Custom Chat Height", () -> ChattingConfig.INSTANCE.getChatWindow().getCustomChatHeight());
option.addListener(() -> Minecraft.getMinecraft().ingameGUI.getChatGUI().refreshChat());
break;
case "customWidth":
option.addDependency("Custom Chat Width", () -> ChattingConfig.INSTANCE.getChatWindow().getCustomChatWidth());
option.addListener(() -> Minecraft.getMinecraft().ingameGUI.getChatGUI().refreshChat());
break;
}

Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/org/polyfrost/chatting/Chatting.kt
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,14 @@ object Chatting {
return if (opened) ChattingConfig.chatWindow.focusedHeight else ChattingConfig.chatWindow.unfocusedHeight
}

fun getChatWidth(): Int {
return ChattingConfig.chatWindow.customWidth
}

fun screenshotLine(line: ChatLine): BufferedImage? {
val hud = Minecraft.getMinecraft().ingameGUI
val chat = hud.chatGUI
val i = MathHelper.floor_float(chat.chatWidth / chat.chatScale)
val i = MathHelper.floor_float(getChatWidth() / chat.chatScale)
return screenshot(
hashMapOf<ChatLine, String>().also {
GuiUtilRenderComponents.splitText(
Expand Down
15 changes: 14 additions & 1 deletion src/main/kotlin/org/polyfrost/chatting/chat/ChatWindow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ class ChatWindow : BasicHud(true, 2f, 1080 - 27f - 45f - 12f) {
var unfocusedHeight = 90
get() = field.coerceIn(20, 2160)

@Switch(
name = "Custom Chat Width",
description = "Set a custom width for the chat window. Allows for more customization than the vanilla chat width options."
)
var customChatWidth = false

@Slider(
min = 20F, max = 2160F, name = "Custom Width (px)",
description = "The width of the chat window when focused."
)
var customWidth = 320
get() = field.coerceIn(20, 2160)

init {
showInDebug = true
}
Expand Down Expand Up @@ -138,7 +151,7 @@ class ChatWindow : BasicHud(true, 2f, 1080 - 27f - 45f - 12f) {
}

override fun getWidth(scale: Float, example: Boolean): Float {
return (GuiNewChat.calculateChatboxWidth(mc.gameSettings.chatWidth) + 4 + ModCompatHooks.chatHeadOffset) * scale
return (if (customChatWidth) Chatting.getChatWidth() else GuiNewChat.calculateChatboxWidth(mc.gameSettings.chatWidth) + 4 + ModCompatHooks.chatHeadOffset) * scale
}

override fun getHeight(scale: Float, example: Boolean): Float {
Expand Down

0 comments on commit 8e2abe0

Please sign in to comment.