forked from m0bilebtw/c-engineer-completed
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added chat emotes (#54) * Twitch title now showing (#55) * Bump version to 1.1.1 * Added emote list (#56) Added emotes list ::odaemotes Added better handling of emotes, more options per emote * Send splitted title (#57) * Fix highlighting (#58) * Updated 'linked' chatbox text behavior (#59) Fixes issues with not being able to scroll if you're hovering over the text with link (notifications/livestream notifications). Always have to right click open stream/link. You can now click through the link if you have a transparent chatbox.
- Loading branch information
1 parent
1d14cb0
commit 2a986da
Showing
23 changed files
with
274 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/main/java/com/github/dappermickie/odablock/emotes/Emote.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.github.dappermickie.odablock.emotes; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import java.awt.image.BufferedImage; | ||
import java.util.Map; | ||
import lombok.AllArgsConstructor; | ||
import net.runelite.client.util.ImageUtil; | ||
|
||
@AllArgsConstructor | ||
public enum Emote | ||
{ | ||
AIAIAI("aiaiai", EmoteType.GIF), | ||
AWKWARD("awkward", EmoteType.GIF), | ||
FUFU("fufu", EmoteType.GIF), | ||
GNEAH("gneah", EmoteType.PNG), | ||
HUH("huh", EmoteType.PNG), | ||
HYPERWANKGE("hyperwankge", EmoteType.GIF), | ||
JANITOR("janitor", EmoteType.PNG), | ||
KEK("kek", EmoteType.GIF), | ||
KISS("kiss", EmoteType.PNG), | ||
NOWAY("noway", EmoteType.PNG), | ||
PFACE(":p", EmoteType.GIF, new String[]{"pface"}), | ||
RLY("rly", EmoteType.GIF), | ||
SMILE(":)", EmoteType.GIF, new String[]{"smile"}), | ||
TUNE("tune", EmoteType.GIF), | ||
ODAWHAT("odawhat", EmoteType.PNG), | ||
WHENITREGISTERS("whenitregisters", EmoteType.GIF), | ||
WINK("wink", EmoteType.PNG); | ||
|
||
private enum EmoteType | ||
{ | ||
PNG, | ||
GIF | ||
} | ||
|
||
private static final Map<String, Emote> emojiMap; | ||
|
||
private final String trigger; | ||
private final EmoteType emoteType; | ||
private final String[] altTriggers; | ||
|
||
Emote(final String trigger, EmoteType emoteType) | ||
{ | ||
this(trigger, emoteType, new String[]{}); | ||
} | ||
|
||
static | ||
{ | ||
ImmutableMap.Builder<String, Emote> builder = new ImmutableMap.Builder<>(); | ||
|
||
for (final Emote emoji : values()) | ||
{ | ||
builder.put(emoji.trigger, emoji); | ||
if (!emoji.trigger.startsWith("oda") && !emoji.trigger.startsWith(":")) | ||
{ | ||
builder.put("oda" + emoji.trigger, emoji); | ||
} | ||
for (final String altTrigger : emoji.altTriggers) | ||
{ | ||
builder.put(altTrigger, emoji); | ||
if (!altTrigger.startsWith("oda") && !altTrigger.startsWith(":")) | ||
{ | ||
builder.put("oda" + altTrigger, emoji); | ||
} | ||
} | ||
} | ||
|
||
emojiMap = builder.build(); | ||
} | ||
|
||
BufferedImage loadImage() | ||
{ | ||
return ImageUtil.loadImageResource(getClass(), this.name().toLowerCase() + getEmoteTypeExtension()); | ||
} | ||
|
||
private String getEmoteTypeExtension() | ||
{ | ||
return emoteType == EmoteType.GIF ? ".gif" : ".png"; | ||
} | ||
|
||
static Emote getEmoji(String trigger) | ||
{ | ||
return emojiMap.get(trigger); | ||
} | ||
} |
160 changes: 160 additions & 0 deletions
160
src/main/java/com/github/dappermickie/odablock/emotes/EmoteHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
package com.github.dappermickie.odablock.emotes; | ||
|
||
import static com.github.dappermickie.odablock.OdablockPlugin.ODABLOCK; | ||
import java.awt.image.BufferedImage; | ||
import java.util.regex.Pattern; | ||
import javax.annotation.Nullable; | ||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
import joptsimple.internal.Strings; | ||
import lombok.extern.slf4j.Slf4j; | ||
import net.runelite.api.ChatMessageType; | ||
import net.runelite.api.Client; | ||
import net.runelite.api.MessageNode; | ||
import net.runelite.api.Player; | ||
import net.runelite.api.events.ChatMessage; | ||
import net.runelite.api.events.CommandExecuted; | ||
import net.runelite.api.events.OverheadTextChanged; | ||
import net.runelite.client.callback.ClientThread; | ||
import net.runelite.client.game.ChatIconManager; | ||
import net.runelite.client.util.Text; | ||
|
||
@Slf4j | ||
@Singleton | ||
public class EmoteHandler | ||
{ | ||
private static final Pattern WHITESPACE_REGEXP = Pattern.compile("[\\s\\u00A0]"); | ||
|
||
@Inject | ||
private ChatIconManager chatIconManager; | ||
|
||
@Inject | ||
private ClientThread clientThread; | ||
|
||
@Inject | ||
private Client client; | ||
|
||
private int[] iconIds; | ||
|
||
public void loadEmotes() | ||
{ | ||
if (iconIds != null) | ||
{ | ||
return; | ||
} | ||
|
||
Emote[] emotes = Emote.values(); | ||
iconIds = new int[emotes.length]; | ||
|
||
for (int i = 0; i < emotes.length; i++) | ||
{ | ||
final Emote emoji = emotes[i]; | ||
final BufferedImage image = emoji.loadImage(); | ||
iconIds[i] = chatIconManager.registerChatIcon(image); | ||
} | ||
} | ||
|
||
public void onChatMessage(ChatMessage chatMessage) | ||
{ | ||
if (iconIds == null) | ||
{ | ||
return; | ||
} | ||
|
||
switch (chatMessage.getType()) | ||
{ | ||
case PUBLICCHAT: | ||
case MODCHAT: | ||
case FRIENDSCHAT: | ||
case CLAN_CHAT: | ||
case CLAN_GUEST_CHAT: | ||
case CLAN_GIM_CHAT: | ||
case PRIVATECHAT: | ||
case PRIVATECHATOUT: | ||
case MODPRIVATECHAT: | ||
break; | ||
default: | ||
return; | ||
} | ||
|
||
final MessageNode messageNode = chatMessage.getMessageNode(); | ||
final String message = messageNode.getValue(); | ||
final String updatedMessage = updateMessage(message); | ||
|
||
if (updatedMessage == null) | ||
{ | ||
return; | ||
} | ||
|
||
messageNode.setValue(updatedMessage); | ||
} | ||
|
||
public void onOverheadTextChanged(final OverheadTextChanged event) | ||
{ | ||
if (!(event.getActor() instanceof Player)) | ||
{ | ||
return; | ||
} | ||
|
||
final String message = event.getOverheadText(); | ||
final String updatedMessage = updateMessage(message); | ||
|
||
if (updatedMessage == null) | ||
{ | ||
return; | ||
} | ||
|
||
event.getActor().setOverheadText(updatedMessage); | ||
} | ||
|
||
public void onCommandExecuted(CommandExecuted event) | ||
{ | ||
if (event.getCommand().startsWith("odaemote") || event.getCommand().startsWith("odablockemote")) | ||
{ | ||
clientThread.invoke(this::sendOdaEmotes); | ||
} | ||
} | ||
|
||
private void sendOdaEmotes() | ||
{ | ||
client.addChatMessage(ChatMessageType.GAMEMESSAGE, ODABLOCK, "Odablock emote list:", null); | ||
for (Emote emote : Emote.values()) | ||
{ | ||
final int emoteId = iconIds[emote.ordinal()]; | ||
final String emoteImage = "<img=" + chatIconManager.chatIconIndex(emoteId) + ">"; | ||
client.addChatMessage(ChatMessageType.GAMEMESSAGE, ODABLOCK, emote.name() + " : " + emoteImage, null); | ||
} | ||
} | ||
|
||
@Nullable | ||
String updateMessage(final String message) | ||
{ | ||
final String[] messageWords = WHITESPACE_REGEXP.split(message); | ||
|
||
boolean editedMessage = false; | ||
for (int i = 0; i < messageWords.length; i++) | ||
{ | ||
// Remove tags except for <lt> and <gt> | ||
final String originalTrigger = Text.removeFormattingTags(messageWords[i]); | ||
final String trigger = originalTrigger.toLowerCase(); | ||
final Emote emote = Emote.getEmoji(trigger); | ||
|
||
if (emote == null) | ||
{ | ||
continue; | ||
} | ||
|
||
final int emoteId = iconIds[emote.ordinal()]; | ||
messageWords[i] = messageWords[i].replace(originalTrigger, "<img=" + chatIconManager.chatIconIndex(emoteId) + ">"); | ||
editedMessage = true; | ||
} | ||
|
||
// If we haven't edited the message any, don't update it. | ||
if (!editedMessage) | ||
{ | ||
return null; | ||
} | ||
|
||
return Strings.join(messageWords, " "); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+21.6 KB
src/main/resources/com/github/dappermickie/odablock/emotes/aiaiai.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+28.6 KB
src/main/resources/com/github/dappermickie/odablock/emotes/awkward.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.83 KB
src/main/resources/com/github/dappermickie/odablock/emotes/hyperwankge.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.05 KB
src/main/resources/com/github/dappermickie/odablock/emotes/janitor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.03 KB
src/main/resources/com/github/dappermickie/odablock/emotes/odawhat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+103 KB
src/main/resources/com/github/dappermickie/odablock/emotes/whenitregisters.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.