Skip to content

Commit

Permalink
fixed chat head not being drawn when closing
Browse files Browse the repository at this point in the history
  • Loading branch information
ImToggle committed Jul 21, 2024
1 parent 72e3a58 commit ab88520
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void drawClosing(int updateCounter, CallbackInfo ci) {
int q = m * 9;
String string = chatLine.getChatComponent().getFormattedText();
GlStateManager.enableBlend();
ModCompatHooks.redirectDrawString(string, chatting$config().getFade() ? 0 : 3, -q - 8, 16777215 + (chatting$getOpacity(chatting$updateCounter, chatLine) << 24), chatLine, false);
ModCompatHooks.redirectDrawString(string, chatting$config().getFade() ? 0 : 3, -q - 8, 0xFFFFFFFF, chatLine, false);
GlStateManager.disableAlpha();
GlStateManager.disableBlend();
}
Expand Down Expand Up @@ -317,6 +317,11 @@ private void checkStuff(int j2, CallbackInfo ci) {
}
}

@Inject(method = "getChatScale", at = @At("HEAD"), cancellable = true)
private void chatScale(CallbackInfoReturnable<Float> cir) {
cir.setReturnValue(ChattingConfig.INSTANCE.getChatWindow().getScale());
}

@Override
public int chatting$getRight() {
return chatting$right;
Expand Down
37 changes: 7 additions & 30 deletions src/main/kotlin/org/polyfrost/chatting/chat/ChatWindow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -173,42 +173,19 @@ class ChatWindow : BasicHud(true, 2f, 1080 - 27f - 45f - 12f,

override fun drawBackground(x: Float, y: Float, width: Float, height: Float, scale: Float) {
if (Chatting.isPatcher && PatcherConfig.transparentChat) return
val nanoVGHelper = NanoVGHelper.INSTANCE
val animatingOpacity = wasInChatGui && (ChattingConfig.smoothBG && (previousAnimationWidth != width || previousAnimationHeight != height))
wasInChatGui = mc.currentScreen is GuiChat || animatingOpacity
previousAnimationWidth = width
previousAnimationHeight = height
val bgOpacity = openOpacity
val borderOpacity = openBorderOpacity
val bgColor = bgColor.getRGB().setAlpha(if (differentOpacity && wasInChatGui) bgOpacity else bgColor.alpha)
val borderColor = borderColor.getRGB().setAlpha(if (differentOpacity && wasInChatGui) borderOpacity else borderColor.alpha)
nanoVGHelper.setupAndDraw(true) { vg: Long ->
if (rounded) {
nanoVGHelper.drawRoundedRect(vg, x, y, width, height, bgColor, cornerRadius * scale)
if (border) nanoVGHelper.drawHollowRoundRect(
vg,
x - borderSize * scale,
y - borderSize * scale,
width + borderSize * scale,
height + borderSize * scale,
borderColor,
cornerRadius * scale,
borderSize * scale
)
} else {
nanoVGHelper.drawRect(vg, x, y, width, height, bgColor)
if (border) nanoVGHelper.drawHollowRoundRect(
vg,
x - borderSize * scale,
y - borderSize * scale,
width + borderSize * scale,
height + borderSize * scale,
borderColor,
0f,
borderSize * scale
)
}
}
val tempBgAlpha = bgColor.alpha
val tempBorderAlpha = borderColor.alpha
bgColor.alpha = if (differentOpacity && wasInChatGui) bgOpacity else bgColor.alpha
borderColor.alpha = if (differentOpacity && wasInChatGui) borderOpacity else borderColor.alpha
super.drawBackground(x, y, width, height, scale)
bgColor.alpha = tempBgAlpha
borderColor.alpha = tempBorderAlpha
}

fun drawBG() {
Expand Down

0 comments on commit ab88520

Please sign in to comment.