Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve compact messages behavior #597

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
import net.minecraft.client.gui.ChatLine;
import net.minecraft.client.gui.GuiNewChat;
import net.minecraft.client.gui.GuiUtilRenderComponents;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.*;

import mod.acgaming.universaltweaks.config.UTConfigTweaks;
import net.minecraft.util.text.event.HoverEvent;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down Expand Up @@ -55,14 +54,14 @@ public void utCompactMessage(ITextComponent chatComponent, int chatLineId, int u
int chatSize = MathHelper.floor(this.getChatWidth() / this.getChatScale());
List<ITextComponent> splittedText = GuiUtilRenderComponents.splitText(chatComponent, chatSize, this.mc.fontRenderer, false, false);
ITextComponent textComponent = splittedText.get(splittedText.size() - 1);
for (int i = 0; i < drawnChatLines.size(); i++)
{
ChatLine chatLine = drawnChatLines.get(i);
if (universalTweaks$isMessageEqual(chatLine.getChatComponent().createCopy(), textComponent.createCopy()))
if (!this.drawnChatLines.isEmpty() && !this.chatLines.isEmpty()) {
ChatLine oldDrawnChatLine = this.drawnChatLines.get(0);
ChatLine oldChatLine = this.chatLines.get(0);
if (universalTweaks$isMessageEqual(oldDrawnChatLine.getChatComponent().createCopy(), textComponent.createCopy()))
{
if (!chatLine.getChatComponent().getSiblings().isEmpty())
if (!oldDrawnChatLine.getChatComponent().getSiblings().isEmpty())
{
for (ITextComponent sibling : chatLine.getChatComponent().getSiblings())
for (ITextComponent sibling : oldDrawnChatLine.getChatComponent().getSiblings())
{
if (universalTweaks$matchPattern.matcher(sibling.getUnformattedComponentText()).matches())
{
Expand All @@ -71,10 +70,16 @@ public void utCompactMessage(ITextComponent chatComponent, int chatLineId, int u
}
}
}
this.drawnChatLines.removeIf(chatLine1 -> splittedText.contains(chatLine1.getChatComponent()) || chatLine1.equals(chatLine));
this.chatLines.removeIf(chatLine1 -> chatLine1.getChatComponent().getUnformattedComponentText().equals(chatComponent.getUnformattedComponentText()));
chatComponent.appendSibling(new TextComponentString(" (" + count + ")").setStyle(new Style().setColor(TextFormatting.GRAY)));
break;
if ((oldDrawnChatLine.equals(oldDrawnChatLine) || splittedText.contains(oldDrawnChatLine.getChatComponent())) && oldChatLine.getChatComponent().getUnformattedComponentText().equals(chatComponent.getUnformattedComponentText())) {
this.drawnChatLines.remove(oldDrawnChatLine);
this.chatLines.remove(oldChatLine);
}
// this.drawnChatLines.removeIf(chatLine1 -> splittedText.contains(chatLine1.getChatComponent()) || chatLine1.equals(chatLine));
// this.chatLines.removeIf(chatLine1 -> chatLine1.getChatComponent().getUnformattedComponentText().equals(chatComponent.getUnformattedComponentText()));
ITextComponent textComponentCount = new TextComponentString(" (" + count + ")").setStyle(new Style().setColor(TextFormatting.GRAY));
textComponentCount.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString(I18n.format("msg.universaltweaks.compactmessages.count", count))));
chatComponent.appendSibling(textComponentCount);

}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/assets/universaltweaks/lang/de_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ btn.universaltweaks.lanserverproperties.online_mode=Online-Modus
btn.universaltweaks.lanserverproperties.online_mode_desc=Deaktivierung ermöglicht nicht authentifizierte Verbindungen
btn.universaltweaks.lanserverproperties.port=Abhörender Port
btn.universaltweaks.lanserverproperties.spawn_animals=Erschaffe Tiere
btn.universaltweaks.lanserverproperties.spawn_npcs=Erschaffe NPCs
btn.universaltweaks.lanserverproperties.spawn_npcs=Erschaffe NPCs

# COMPACT MESSAGES
msg.universaltweaks.compactmessages.count=Diese Nachricht wurde %s mal/e wiederholt
3 changes: 3 additions & 0 deletions src/main/resources/assets/universaltweaks/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ btn.universaltweaks.lanserverproperties.port=Listening Port
btn.universaltweaks.lanserverproperties.spawn_animals=Spawn Animals
btn.universaltweaks.lanserverproperties.spawn_npcs=Spawn NPCs

# COMPACT MESSAGES
msg.universaltweaks.compactmessages.count=This message has been repeated %s times

# CONFIG
# Doesn't need to be translated because config is English in general
cfg.universaltweaks.config.blocks=Blocks
Expand Down
Loading