Skip to content

Commit

Permalink
fixed text opacity while closing, add dynamic input box
Browse files Browse the repository at this point in the history
  • Loading branch information
ImToggle committed Jan 28, 2024
1 parent 93c05b3 commit 02f1ea3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/polyfrost/chatting/mixin/GuiChatMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ private void onDrawScreen(int mouseX, int mouseY, float partialTicks, CallbackIn

@ModifyArg(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiChat;drawRect(IIIII)V"), index = 2)
private int modifyRight(int right) {
return ChattingConfig.INSTANCE.getCompactInputBox() ? (int) ChattingConfig.INSTANCE.getChatWindow().getAnimationWidth() : right;
ChattingConfig config = ChattingConfig.INSTANCE;
return config.getCompactInputBox() ? (int) Math.max(config.getChatWindow().getAnimationWidth(), (fontRendererObj.getStringWidth(inputField.getText()) + 4 + (inputField.getText().length() < 100 ? 8 : 2)) * config.getChatWindow().getScale()) : right;
}

@ModifyArg(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiChat;drawRect(IIIII)V"), index = 4)
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.List;

import static net.minecraft.client.gui.GuiNewChat.calculateChatboxHeight;
import static net.minecraft.client.gui.GuiNewChat.calculateChatboxWidth;

@Mixin(value = GuiNewChat.class, priority = 990)
public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook {
Expand Down Expand Up @@ -96,14 +97,13 @@ private void drawClosing(int updateCounter, CallbackInfo ci) {
for (int m = 0; m < this.drawnChatLines.size() && m < height / 9; ++m) {
ChatLine chatLine = this.drawnChatLines.get(m);
if (chatLine != null) {
int n = updateCounter - chatLine.getUpdatedCounter() + 200 - (int) (chatting$config().getFadeTime() * 20);
int unFocusHeight = (chatting$config().getCustomChatHeight() ? Chatting.INSTANCE.getChatHeight(false) : calculateChatboxHeight(this.mc.gameSettings.chatHeightUnfocused));
boolean shouldShow = (chatting$config().getFade() && n >= 200) || m >= unFocusHeight / 9;
boolean shouldShow = (chatting$config().getFade() && m >= totalLines) || m >= unFocusHeight / 9;
if (!getChatOpen() && shouldShow) {
int q = m * 9;
String string = chatLine.getChatComponent().getFormattedText();
GlStateManager.enableBlend();
ModCompatHooks.redirectDrawString(string, chatting$config().getFade() ? 0 : 3, -q - 8, 16777215 + (255 << 24), chatLine, false);
ModCompatHooks.redirectDrawString(string, chatting$config().getFade() ? 0 : 3, -q - 8, 16777215 + (chatting$getOpacity(0) << 24), chatLine, false);
GlStateManager.disableAlpha();
GlStateManager.disableBlend();
}
Expand Down Expand Up @@ -208,15 +208,14 @@ private boolean noFade(GuiNewChat instance) {
float f = this.mc.gameSettings.chatOpacity * 0.9F + 0.1F;
int n = updateCounter - chatting$chatLine.getUpdatedCounter();
if (n < 200 || getChatOpen()) {
int backgroundAlpha = chatting$config().getChatWindow().getAlphaBG() * 2;
double d = (double) n / 200.0;
d = 1.0 - d;
d *= 10.0;
d = MathHelper.clamp_double(d, 0.0, 1.0);
d *= d;
int o = (int) (backgroundAlpha * d);
int o = (int) (255 * d);
if (getChatOpen()) {
o = backgroundAlpha;
o = 255;
}
o = (int) ((float) o * f);
if (o <= 3) {
Expand Down Expand Up @@ -244,9 +243,9 @@ private void drawChatBox(Args args) {
chatting$lineInBounds = false;
}

@Redirect(method = "setChatLine", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;getChatScale()F"))
private float wrap(GuiNewChat instance) {
return 1f;
@ModifyVariable(method = "setChatLine", at = @At(value = "STORE"), ordinal = 2)
private int wrap(int value) {
return calculateChatboxWidth(mc.gameSettings.chatWidth);
}

private boolean isHovered(int x, int y, int width, int height) {
Expand All @@ -266,7 +265,7 @@ private double modifyYeah(double value) {
if (chatting$textOpacity == Integer.MIN_VALUE) {
chatting$textOpacity = 0;
}
return closing ? 255 : value;
return closing ? 1 : value;
}
/*/
@Inject(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;scale(FFF)V"))
Expand Down
14 changes: 7 additions & 7 deletions src/main/kotlin/org/polyfrost/chatting/chat/ChatWindow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.polyfrost.chatting.config.ChattingConfig
import org.polyfrost.chatting.utils.EaseOutQuart
import org.polyfrost.chatting.utils.ModCompatHooks

class ChatWindow : BasicHud(true) {
class ChatWindow : BasicHud(true, 0f, 1080 - 27f - 45f) {

@Exclude
private val exampleList: List<ChatLine> = listOf(
Expand Down Expand Up @@ -64,16 +64,16 @@ class ChatWindow : BasicHud(true) {
GlStateManager.enableAlpha()
GlStateManager.enableBlend()
if (widthEnd != widthAnimation.end) {
widthAnimation = if (ChattingConfig.smoothBG)
EaseOutQuart(duration, animationWidth, widthEnd, false)
if (ChattingConfig.smoothBG)
widthAnimation = EaseOutQuart(duration, animationWidth, widthEnd, false)
else
DummyAnimation(widthEnd)
animationWidth = widthEnd
}
if (heightEnd != heightAnimation.end) {
heightAnimation = if (ChattingConfig.smoothBG)
EaseOutQuart(duration, animationHeight, heightEnd, false)
if (ChattingConfig.smoothBG)
heightAnimation = EaseOutQuart(duration, animationHeight, heightEnd, false)
else
DummyAnimation(heightEnd)
animationHeight = heightEnd
}
if (animationHeight <= 0.3f || !background || HudCore.editing) return
nanoVG(true) {
Expand Down

0 comments on commit 02f1ea3

Please sign in to comment.