aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWyvest <45589059+Wyvest@users.noreply.github.com>2021-12-25 10:42:42 +0700
committerGitHub <noreply@github.com>2021-12-25 10:42:42 +0700
commitf720ca0a074411be7cbbdc1b9629b14d06e3b26c (patch)
treed3b481e0ba3b42f5f97ec34c59f594d5d53dce13 /src
parent630b6f9757b191591e1a3c623b5c5302dadf3cd8 (diff)
parent275bb75deaa4e53d3c1c506aa4a734c174aeed4d (diff)
downloadChatting-f720ca0a074411be7cbbdc1b9629b14d06e3b26c.tar.gz
Chatting-f720ca0a074411be7cbbdc1b9629b14d06e3b26c.tar.bz2
Chatting-f720ca0a074411be7cbbdc1b9629b14d06e3b26c.zip
new: modify chat message copying to copy entire message and add tooltip (#1)
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/raeids/stratus/hook/GuiNewChatHook.java5
-rw-r--r--src/main/java/com/raeids/stratus/mixin/GuiNewChatMapMixin.java78
-rw-r--r--src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java21
-rw-r--r--src/main/resources/mixins.stratus.json5
4 files changed, 105 insertions, 4 deletions
diff --git a/src/main/java/com/raeids/stratus/hook/GuiNewChatHook.java b/src/main/java/com/raeids/stratus/hook/GuiNewChatHook.java
index 4fb9e0c..93abcdf 100644
--- a/src/main/java/com/raeids/stratus/hook/GuiNewChatHook.java
+++ b/src/main/java/com/raeids/stratus/hook/GuiNewChatHook.java
@@ -1,7 +1,12 @@
package com.raeids.stratus.hook;
+import net.minecraft.client.gui.ChatLine;
+
public interface GuiNewChatHook {
int getRight();
boolean shouldCopy();
String getStratusChatComponent(int mouseY);
+ default ChatLine getFullMessage(ChatLine line) {
+ throw new AssertionError("getFullMessage not overridden on GuiNewChat");
+ }
}
diff --git a/src/main/java/com/raeids/stratus/mixin/GuiNewChatMapMixin.java b/src/main/java/com/raeids/stratus/mixin/GuiNewChatMapMixin.java
new file mode 100644
index 0000000..8f581f9
--- /dev/null
+++ b/src/main/java/com/raeids/stratus/mixin/GuiNewChatMapMixin.java
@@ -0,0 +1,78 @@
+package com.raeids.stratus.mixin;
+
+import com.raeids.stratus.hook.GuiNewChatHook;
+import net.minecraft.client.gui.ChatLine;
+import net.minecraft.client.gui.GuiNewChat;
+import net.minecraft.util.IChatComponent;
+import org.spongepowered.asm.mixin.Final;
+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.callback.CallbackInfo;
+import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Mixin(value = GuiNewChat.class, priority = Integer.MIN_VALUE)
+public abstract class GuiNewChatMapMixin implements GuiNewChatHook {
+
+ @Unique private final Map<ChatLine, ChatLine> drawnToFull = new HashMap<>();
+ @Unique private final List<ChatLine> tempDrawnLines = new ArrayList<>();
+ @Unique private ChatLine lastTempLine = null;
+
+ @Shadow @Final private List<ChatLine> drawnChatLines;
+ @Shadow @Final private List<ChatLine> chatLines;
+
+ @Inject(method = "setChatLine", at = @At("HEAD"))
+ private void handleSetChatLine(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) {
+ tempDrawnLines.clear();
+ }
+
+ @Inject(method = "setChatLine", at = @At(value = "INVOKE", target = "Ljava/util/List;add(ILjava/lang/Object;)V", ordinal = 0, shift = At.Shift.AFTER))
+ private void handleDrawnLineAdded(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) {
+ if (!displayOnly) tempDrawnLines.add(drawnChatLines.get(0));
+ else if (lastTempLine != null) {
+ drawnToFull.put(drawnChatLines.get(0), lastTempLine);
+ }
+ }
+
+ @Inject(method = "setChatLine", at = @At(value = "INVOKE", target = "Ljava/util/List;remove(I)Ljava/lang/Object;", ordinal = 0, shift = At.Shift.BEFORE))
+ private void handleDrawnLineRemoved(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) {
+ drawnToFull.remove(drawnChatLines.get(drawnChatLines.size() - 1));
+ }
+
+ @Inject(method = "setChatLine", at = @At("RETURN"))
+ private void handleLineAdded(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) {
+ if (!displayOnly) {
+ ChatLine masterLine = chatLines.get(0);
+ for (ChatLine tempDrawnLine : tempDrawnLines) drawnToFull.put(tempDrawnLine, masterLine);
+ }else {
+ lastTempLine = null;
+ }
+ }
+
+ @Inject(method = "refreshChat", at = @At("HEAD"))
+ private void handleRefreshedChat(CallbackInfo ci) {
+ drawnToFull.clear();
+ }
+
+ @Inject(method = "refreshChat", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;setChatLine(Lnet/minecraft/util/IChatComponent;IIZ)V", ordinal = 0, shift = At.Shift.BEFORE))
+ private void handleLineRefresh(CallbackInfo ci, int i, ChatLine chatline) {
+ lastTempLine = chatline;
+ }
+
+ @Inject(method = "clearChatMessages", at = @At("HEAD"))
+ private void handleChatCleared(CallbackInfo ci) {
+ drawnToFull.clear();
+ }
+
+ @Override
+ public ChatLine getFullMessage(ChatLine line) {
+ return drawnToFull.getOrDefault(line, null);
+ }
+}
diff --git a/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java b/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java
index 1f1d953..c831528 100644
--- a/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java
+++ b/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java
@@ -1,5 +1,6 @@
package com.raeids.stratus.mixin;
+import com.google.common.collect.Lists;
import com.raeids.stratus.Stratus;
import com.raeids.stratus.config.StratusConfig;
import com.raeids.stratus.hook.ChatSearchingKt;
@@ -10,9 +11,11 @@ import gg.essential.universal.UMouse;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.*;
import net.minecraft.client.renderer.GlStateManager;
+import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
+import net.minecraftforge.fml.client.config.GuiUtils;
import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
@@ -47,6 +50,14 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook {
@Unique private static final ResourceLocation COPY = new ResourceLocation("stratus:copy.png");
+ @Unique private static final List<String> COPY_TOOLTIP = Lists.newArrayList(
+ "\u00A73\u00A7l\u00A7nCopy To Clipboard",
+ "\u00A7lNORMAL CLICK\u00A7r - Full Message",
+ "\u00A7lCTRL CLICK\u00A7r - Single Line",
+ "",
+ "\u00A73\u00A7l\u00A7nModifiers",
+ "\u00A7lALT\u00A7r - Formatting Codes");
+
@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);
@@ -92,7 +103,7 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook {
mouseY = -(MathHelper.floor_float((float)mouseY / f)); //WHY DO I NEED TO DO THIS
if (mouseX >= (left + (Stratus.INSTANCE.isBetterChat() ? ModCompatHooks.getXOffset() : 0)) && mouseY < bottom && mouseX < (right + 9 + (Stratus.INSTANCE.isBetterChat() ? ModCompatHooks.getXOffset() : 0)) && mouseY >= top) {
stratus$shouldCopy = true;
- drawCopyChatBox(right, top);
+ drawCopyChatBox(right, top, mouseX, mouseY);
}
}
}
@@ -138,7 +149,7 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook {
}
}
- private void drawCopyChatBox(int right, int top) {
+ private void drawCopyChatBox(int right, int top, int mouseX, int mouseY) {
stratus$chatCheck = true;
GlStateManager.enableRescaleNormal();
GlStateManager.enableBlend();
@@ -154,6 +165,7 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook {
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
stratus$right = right;
Gui.drawModalRectWithCustomSizedTexture(right, top, 0f, 0f, 9, 9, 9, 9);
+ if (mouseX >= right) GuiUtils.drawHoveringText(COPY_TOOLTIP, mouseX, mouseY, mc.currentScreen.width, mc.currentScreen.height, 300, mc.fontRendererObj);
GlStateManager.disableAlpha();
GlStateManager.disableRescaleNormal();
GlStateManager.disableLighting();
@@ -176,7 +188,10 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook {
int i1 = k / this.mc.fontRendererObj.FONT_HEIGHT + this.scrollPos;
if (i1 >= 0 && i1 < this.drawnChatLines.size()) {
- return this.drawnChatLines.get(i1).getChatComponent().getFormattedText();
+ ChatLine subLine = this.drawnChatLines.get(i1);
+ ChatLine line = GuiScreen.isCtrlKeyDown() ? subLine : this.getFullMessage(subLine);
+ String message = line == null ? "Could not find chat message." : line.getChatComponent().getFormattedText();
+ return GuiScreen.isAltKeyDown() ? message : EnumChatFormatting.getTextWithoutFormattingCodes(message);
}
}
diff --git a/src/main/resources/mixins.stratus.json b/src/main/resources/mixins.stratus.json
index 16489b4..033e372 100644
--- a/src/main/resources/mixins.stratus.json
+++ b/src/main/resources/mixins.stratus.json
@@ -10,5 +10,8 @@
"GuiNewChatAccessor",
"GuiNewChatMixin"
],
- "verbose": true
+ "verbose": true,
+ "client": [
+ "GuiNewChatMapMixin"
+ ]
} \ No newline at end of file