Skip to content

Commit

Permalink
Merge pull request #597 from Irgendwer01/main
Browse files Browse the repository at this point in the history
Improve compact messages behavior
  • Loading branch information
ACGaming authored Dec 9, 2024
2 parents 53a843a + bcd4248 commit c45e5d0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
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

0 comments on commit c45e5d0

Please sign in to comment.