Skip to content

Commit

Permalink
make bg animation toggleable
Browse files Browse the repository at this point in the history
  • Loading branch information
ImToggle committed Jan 25, 2024
1 parent 4721620 commit 71454f6
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 10 deletions.
44 changes: 41 additions & 3 deletions src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import java.awt.image.BufferedImage;
import java.util.List;

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

@Mixin(value = GuiNewChat.class, priority = 990)
public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook {
@Unique
Expand Down Expand Up @@ -84,12 +86,48 @@ private IChatComponent handleAddDrawnLine(IChatComponent iChatComponent) {
*/

@Unique
private boolean lastOpen, closing;

@Unique
private long time;

@Inject(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;popMatrix()V"))
private void drawClosing(int updateCounter, CallbackInfo ci) {
ChattingConfig config = ChattingConfig.INSTANCE;

if (closing) {
int height = (config.getCustomChatHeight() ? Chatting.INSTANCE.getChatHeight(getChatOpen()) : calculateChatboxHeight(this.mc.gameSettings.chatHeightFocused));
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) (config.getFadeTime() * 20);
if (n >= 200 && !getChatOpen()) {
int q = m * 9;
String string = chatLine.getChatComponent().getFormattedText();
GlStateManager.enableBlend();
ModCompatHooks.redirectDrawString(string, 0, -q - 8, 16777215 + (255 << 24), chatLine, false);
GlStateManager.disableAlpha();
GlStateManager.disableBlend();
}
}
}
}
}

@Inject(method = "drawChat", at = @At("HEAD"))
private void checkScreenshotKeybind(int j2, CallbackInfo ci) {
if (Chatting.INSTANCE.getKeybind().isPressed()) {
Chatting.INSTANCE.setDoTheThing(true);
}
chatting$chatCheck = false;
if (lastOpen != getChatOpen()) {
if (lastOpen) time = Minecraft.getSystemTime();
lastOpen = getChatOpen();
}
ChattingConfig config = ChattingConfig.INSTANCE;
long duration = config.getSmoothBG() ? (long) config.getBgDuration() : 0;
closing = (Minecraft.getSystemTime() - time + 50L <= duration);
}

@Unique
Expand All @@ -103,7 +141,7 @@ private int setUpdateCounterWhenYes(int updateCounter) {
@ModifyVariable(method = "drawChat", at = @At("STORE"), index = 2)
private int setChatLimitWhenYes(int linesToDraw) {
return Chatting.INSTANCE.getDoTheThing()
? GuiNewChat.calculateChatboxHeight(mc.gameSettings.chatHeightFocused) / 9
? calculateChatboxHeight(mc.gameSettings.chatHeightFocused) / 9
: linesToDraw;
}

Expand All @@ -127,7 +165,7 @@ private void startScissor(int updateCounter, CallbackInfo ci) {
ChatWindow hud = config.getChatWindow();
int mcScale = new ScaledResolution(mc).getScaleFactor();
GL11.glEnable(GL11.GL_SCISSOR_TEST);
int height = (int) hud.getHeightAnimation().get();
int height = (int) hud.getAnimationHeight();
GL11.glScissor((int) hud.position.getX() * mcScale, mc.displayHeight - (int) hud.position.getBottomY() * mcScale, (int) (hud.position.getWidth() + (getChatOpen() ? 20 : 0) * hud.getScale()) * mcScale, height * mcScale);
}

Expand Down Expand Up @@ -229,7 +267,7 @@ private double modifyYeah(double value) {
if (chatting$textOpacity == Integer.MIN_VALUE) {
chatting$textOpacity = 0;
}
return value;
return closing ? 255 : value;
}
/*/
@Inject(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;scale(FFF)V"))
Expand Down
27 changes: 20 additions & 7 deletions src/main/kotlin/org/polyfrost/chatting/chat/ChatWindow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import cc.polyfrost.oneconfig.libs.universal.UMatrixStack
import cc.polyfrost.oneconfig.utils.dsl.*
import net.minecraft.client.gui.*
import net.minecraft.util.ChatComponentText
import org.polyfrost.chatting.config.ChattingConfig.messageSpeed
import org.polyfrost.chatting.config.ChattingConfig.showChatHeads
import org.polyfrost.chatting.config.ChattingConfig
import org.polyfrost.chatting.utils.EaseOutQuart
import org.polyfrost.chatting.utils.ModCompatHooks

Expand All @@ -34,6 +33,9 @@ class ChatWindow : BasicHud(true) {
@Exclude
var height = 0

@Exclude
var animationHeight = 0f

override fun draw(matrices: UMatrixStack?, x: Float, y: Float, scale: Float, example: Boolean) {
if (!example) return
nanoVG(true){
Expand All @@ -51,14 +53,25 @@ class ChatWindow : BasicHud(true) {

fun drawBG() {
val currentWidth = widthAnimation.get()
val currentHeight = heightAnimation.get()
animationHeight = heightAnimation.get()
val widthEnd = position.width + (if (mc.ingameGUI.chatGUI.chatOpen) 20 else 0) * scale
val heightEnd = if (height == 0) 0f else (height + paddingY * 2f) * scale
widthAnimation = EaseOutQuart((1.0f - messageSpeed) * 1000f, currentWidth, widthEnd, false)
heightAnimation = EaseOutQuart((1.0f - messageSpeed) * 1000f, currentHeight, heightEnd, false)
if (currentHeight <= 0.3f || !background || HudCore.editing) return
val duration = ChattingConfig.bgDuration
if (widthEnd != widthAnimation.end) {
widthAnimation = if (ChattingConfig.smoothBG)
EaseOutQuart(duration, currentWidth, widthEnd, false)
else
DummyAnimation(widthEnd)
}
if (heightEnd != heightAnimation.end) {
heightAnimation = if (ChattingConfig.smoothBG)
EaseOutQuart(duration, animationHeight, heightEnd, false)
else
DummyAnimation(heightEnd)
}
if (animationHeight <= 0.3f || !background || HudCore.editing) return
nanoVG(true) {
drawBackground(position.x, position.bottomY - currentHeight, currentWidth, currentHeight, scale)
drawBackground(position.x, position.bottomY - animationHeight, currentWidth, animationHeight, scale)
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/main/kotlin/org/polyfrost/chatting/config/ChattingConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ object ChattingConfig : Config(
)
var messageSpeed = 0.5f

@Switch(
name = "Smooth Chat Background",
category = "Animations", subcategory = "Background",
description = "Smoothly animate chat background."
)
var smoothBG = true

@Slider(
name = "Background Animation Duration",
category = "Animations", subcategory = "Background",
min = 50f, max = 1000f,
description = "The speed at which chat background animate."
)
var bgDuration = 400f

@Switch(
name = "Smooth Chat Scrolling",
category = "Animations", subcategory = "Scrolling",
Expand Down Expand Up @@ -319,6 +334,7 @@ object ChattingConfig : Config(
addDependency("unfocusedHeight", "customChatHeight")
addDependency("scrollingSpeed", "smoothScrolling")
addDependency("messageSpeed", "smoothChat")
addDependency("bgDuration", "smoothBG")
addDependency("smoothChat", "BetterChat Smooth Chat") {
!ModCompatHooks.betterChatSmoothMessages
}
Expand Down

0 comments on commit 71454f6

Please sign in to comment.