aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_ChatTabs.java12
-rw-r--r--src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_SmoothMessages.java99
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt1
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt10
-rw-r--r--src/main/resources/mixins.chatting.json1
5 files changed, 111 insertions, 12 deletions
diff --git a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_ChatTabs.java b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_ChatTabs.java
index 1d29941..d21097d 100644
--- a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_ChatTabs.java
+++ b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_ChatTabs.java
@@ -1,13 +1,11 @@
package cc.woverflow.chatting.mixin;
-import cc.woverflow.chatting.chat.ChatSearchingManager;
import cc.woverflow.chatting.chat.ChatTabs;
import cc.woverflow.chatting.config.ChattingConfig;
import cc.woverflow.chatting.utils.ModCompatHooks;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ChatLine;
import net.minecraft.client.gui.GuiNewChat;
-import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
@@ -17,24 +15,18 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.List;
-import java.util.Locale;
-@Mixin(GuiNewChat.class)
+@Mixin(value = GuiNewChat.class, priority = 990)
public abstract class GuiNewChatMixin_ChatTabs {
@Shadow @Final private Minecraft mc;
@Shadow public abstract void deleteChatLine(int id);
@Shadow @Final private List<ChatLine> chatLines;
- @SuppressWarnings({"FieldCanBeLocal", "unused"})
- private float percentComplete; //betterchat support
@Inject(method = "printChatMessageWithOptionalDeletion", at = @At("HEAD"), cancellable = true)
private void handlePrintChatMessage(IChatComponent chatComponent, int chatLineId, CallbackInfo ci) {
handleChatTabMessage(chatComponent, chatLineId, mc.ingameGUI.getUpdateCounter(), false, ci);
- if (!EnumChatFormatting.getTextWithoutFormattingCodes(chatComponent.getUnformattedText()).toLowerCase(Locale.ENGLISH).contains(ChatSearchingManager.INSTANCE.getLastSearch().toLowerCase(Locale.ENGLISH))) {
- percentComplete = 1.0F;
- }
}
@Inject(method = "setChatLine", at = @At("HEAD"), cancellable = true)
@@ -45,7 +37,7 @@ public abstract class GuiNewChatMixin_ChatTabs {
private void handleChatTabMessage(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) {
if (ChattingConfig.INSTANCE.getChatTabs()) {
if (!ChatTabs.INSTANCE.shouldRender(chatComponent)) {
- percentComplete = 1.0F;
+ ChatTabs.INSTANCE.setHasCancelledAnimation(true);
if (chatLineId != 0) {
deleteChatLine(chatLineId);
}
diff --git a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_SmoothMessages.java b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_SmoothMessages.java
new file mode 100644
index 0000000..a09fe0c
--- /dev/null
+++ b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_SmoothMessages.java
@@ -0,0 +1,99 @@
+package cc.woverflow.chatting.mixin;
+
+import cc.woverflow.chatting.chat.ChatSearchingManager;
+import cc.woverflow.chatting.chat.ChatTabs;
+import cc.woverflow.chatting.config.ChattingConfig;
+import net.minecraft.client.gui.GuiNewChat;
+import net.minecraft.client.renderer.GlStateManager;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.util.IChatComponent;
+import net.minecraft.util.MathHelper;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.Unique;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.ModifyArg;
+import org.spongepowered.asm.mixin.injection.ModifyVariable;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import java.util.List;
+import java.util.Locale;
+
+@Mixin(GuiNewChat.class)
+public abstract class GuiNewChatMixin_SmoothMessages {
+ @Shadow
+ private boolean isScrolled;
+
+ @Shadow
+ public abstract float getChatScale();
+
+ private float chatting$percentComplete; //be nice and allow other mods to access this :)
+ @Unique
+ private int chatting$newLines;
+ @Unique
+ private long chatting$prevMillis = System.currentTimeMillis();
+ @Unique
+ private float chatting$animationPercent;
+ @Unique
+ private int chatting$lineBeingDrawn;
+
+ private void updatePercentage(long diff) {
+ if (chatting$percentComplete < 1) chatting$percentComplete += 0.004f * diff;
+ chatting$percentComplete = MathHelper.clamp_float(chatting$percentComplete, 0, 1);
+ }
+
+ @Inject(method = "drawChat", at = @At("HEAD"))
+ private void modifyChatRendering(CallbackInfo ci) {
+ long current = System.currentTimeMillis();
+ long diff = current - chatting$prevMillis;
+ chatting$prevMillis = current;
+ updatePercentage(diff);
+ float t = chatting$percentComplete;
+ chatting$animationPercent = MathHelper.clamp_float(1 - (--t) * t * t * t, 0, 1);
+ }
+
+ @Inject(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;pushMatrix()V", ordinal = 0, shift = At.Shift.AFTER))
+ private void translate(CallbackInfo ci) {
+ float y = 0;
+ if (ChattingConfig.INSTANCE.getSmoothChat() && !this.isScrolled) {
+ y += (9 - 9 * chatting$animationPercent) * this.getChatScale();
+ }
+ GlStateManager.translate(0, y, 0);
+ }
+
+ @ModifyArg(method = "drawChat", at = @At(value = "INVOKE", target = "Ljava/util/List;get(I)Ljava/lang/Object;", ordinal = 0, remap = false), index = 0)
+ private int getLineBeingDrawn(int line) {
+ chatting$lineBeingDrawn = line;
+ return line;
+ }
+
+ @ModifyArg(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;drawStringWithShadow(Ljava/lang/String;FFI)I"), index = 3)
+ private int modifyTextOpacity(int original) {
+ if (ChattingConfig.INSTANCE.getSmoothChat() && chatting$lineBeingDrawn <= chatting$newLines) {
+ int opacity = (original >> 24) & 0xFF;
+ opacity *= chatting$animationPercent;
+ return (original & ~(0xFF << 24)) | (opacity << 24);
+ } else {
+ return original;
+ }
+ }
+
+ @Inject(method = "printChatMessageWithOptionalDeletion", at = @At("HEAD"))
+ private void resetPercentage(IChatComponent chatComponent, int chatLineId, CallbackInfo ci) {
+ if (!EnumChatFormatting.getTextWithoutFormattingCodes(chatComponent.getUnformattedText()).toLowerCase(Locale.ENGLISH).contains(ChatSearchingManager.INSTANCE.getLastSearch().toLowerCase(Locale.ENGLISH))) {
+ return;
+ }
+ if (ChatTabs.INSTANCE.getHasCancelledAnimation()) {
+ ChatTabs.INSTANCE.setHasCancelledAnimation(false);
+ return;
+ }
+ chatting$percentComplete = 0;
+ }
+
+ @ModifyVariable(method = "setChatLine", at = @At("STORE"), ordinal = 0)
+ private List<IChatComponent> setNewLines(List<IChatComponent> original) {
+ chatting$newLines = original.size() - 1;
+ return original;
+ }
+}
diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt
index c2329b4..76659ed 100644
--- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt
@@ -26,6 +26,7 @@ object ChatTabs {
return returnValue
}
}
+ var hasCancelledAnimation = false
private var initialized = false
private val tabFile = ConfigUtils.getProfileFile("chattabs.json")
diff --git a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt
index 86db2cc..d0cfd71 100644
--- a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt
@@ -32,7 +32,7 @@ object ChattingConfig : Config(
@Switch(
name = "Remove Scroll Bar", category = "General"
)
- var removeScrollBar = false
+ var removeScrollBar = true
@Color(
name = "Chat Background Color", category = "General", allowAlpha = false
@@ -60,6 +60,12 @@ object ChattingConfig : Config(
var informForAlternatives = true
@Switch(
+ name = "Smooth Chat Messages",
+ category = "Animations"
+ )
+ var smoothChat = true
+
+ @Switch(
name = "Show Chat Heads", description = "Show the chat heads of players in chat", category = "Chat Heads"
)
var showChatHeads = true
@@ -123,7 +129,7 @@ object ChattingConfig : Config(
@Switch(
name = "Custom Chat Height", category = "Chat Window"
)
- var customChatHeight = true
+ var customChatHeight = false
@Slider(
min = 180F, max = 2160F, name = "Focused Height (px)", category = "Chat Window"
diff --git a/src/main/resources/mixins.chatting.json b/src/main/resources/mixins.chatting.json
index 4c59e73..850bab6 100644
--- a/src/main/resources/mixins.chatting.json
+++ b/src/main/resources/mixins.chatting.json
@@ -16,6 +16,7 @@
"GuiNewChatMixin_ChatSearching",
"GuiNewChatMixin_ChatTabs",
"GuiNewChatMixin_RemoveScrollBar",
+ "GuiNewChatMixin_SmoothMessages",
"GuiNewChatMixin_TextRendering",
"GuiUtilsMixin"
]