Skip to content

Commit

Permalink
Localized names support, some small fixes
Browse files Browse the repository at this point in the history
- Add support for localized names
  - Add regular name behind localized name in chat log (for messages, all other actions show the regular display name)
  - Add entries to user context menu to copy either name
  - Add setting to print either both, regular or localized name in chat window
  - Always display regular name behind localized name in User Info Dialog
- Hopefully fix tab completion in $[whisper] tab by allowing User to be updated if tab is already open
- Remove trade mark sign from Emoji
  • Loading branch information
tduva committed Aug 25, 2016
1 parent dca9b9c commit 9bab65c
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 28 deletions.
6 changes: 5 additions & 1 deletion src/chatty/SettingsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public class SettingsManager {

private final List<DefaultHotkey> hotkeys = new ArrayList<>();

public static final long DISPLAY_NAMES_MODE_BOTH = 0;
public static final long DISPLAY_NAMES_MODE_REGULAR = 1;
public static final long DISPLAY_NAMES_MODE_LOCALIZED = 2;

private final String[] debugSettings = {
"server",
"port",
Expand Down Expand Up @@ -177,7 +181,7 @@ void defineSettings() {
settings.addBoolean("correctlyCapitalizedNames", false);
settings.addMap("customNames", new HashMap<>(), Setting.STRING);
settings.addBoolean("actionColored", false);

settings.addLong("displayNamesMode", DISPLAY_NAMES_MODE_BOTH);

// Badges/Emotes
settings.addBoolean("emoticonsEnabled",true);
Expand Down
12 changes: 6 additions & 6 deletions src/chatty/TwitchClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public void versionChecked(String version, String info, boolean isNewVersion) {
* @param channel
*/
private void createTestUser(String name, String channel) {
testUser = new User(name, channel);
testUser = new User(name, "abc" ,channel);
testUser.setColor("blue");
testUser.setGlobalMod(true);
testUser.setBot(true);
Expand Down Expand Up @@ -2114,15 +2114,15 @@ public void onJoin(User user) {
g.printCompact(channel,"JOIN", user);
}
g.playSound("joinPart", channel);
chatLog.compact(channel, "JOIN", user.getDisplayNick());
chatLog.compact(channel, "JOIN", user.getRegularDisplayNick());
}

@Override
public void onPart(User user) {
if (settings.getBoolean("showJoinsParts") && showUserInGui(user)) {
g.printCompact(user.getChannel(), "PART", user);
}
chatLog.compact(user.getChannel(), "PART", user.getDisplayNick());
chatLog.compact(user.getChannel(), "PART", user.getRegularDisplayNick());
g.playSound("joinPart", user.getChannel());
}

Expand Down Expand Up @@ -2224,7 +2224,7 @@ public void onBan(User user, long duration, String reason) {
reason = "";
}
g.userBanned(user, duration, reason, id);
chatLog.userBanned(user.getChannel(), user.getDisplayNick(),
chatLog.userBanned(user.getChannel(), user.getRegularDisplayNick(),
duration, reason);
}

Expand All @@ -2240,7 +2240,7 @@ public void onMod(User user) {
if (modMessagesEnabled && showUserInGui(user)) {
g.printCompact(channel, "MOD", user);
}
chatLog.compact(channel, "MOD", user.getDisplayNick());
chatLog.compact(channel, "MOD", user.getRegularDisplayNick());
}

@Override
Expand All @@ -2250,7 +2250,7 @@ public void onUnmod(User user) {
if (modMessagesEnabled && showUserInGui(user)) {
g.printCompact(channel, "UNMOD", user);
}
chatLog.compact(channel, "UNMOD", user.getDisplayNick());
chatLog.compact(channel, "UNMOD", user.getRegularDisplayNick());
}

@Override
Expand Down
14 changes: 14 additions & 0 deletions src/chatty/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public class User implements Comparable {
*/
private String fullNick;
private boolean hasDisplayNickSet;

/**
* True if the displayNick only differs in case from the username.
*/
private boolean hasRegularDisplayNick;
private final String channel;

Expand Down Expand Up @@ -266,6 +270,10 @@ public synchronized String getRegularDisplayNick() {
return nick;
}

public synchronized boolean hasRegularDisplayNick() {
return hasRegularDisplayNick;
}

public synchronized boolean setDisplayNick(String newDisplayNick) {
if (newDisplayNick == null || newDisplayNick.isEmpty()) {
return false;
Expand All @@ -288,6 +296,12 @@ public synchronized boolean hasDisplayNickSet() {
return hasDisplayNickSet;
}

/**
* Gets the Custom Nick of this user, or the display nick of no custom nick
* is set.
*
* @return
*/
public synchronized String getCustomNick() {
if (customNick != null) {
return customNick;
Expand Down
9 changes: 6 additions & 3 deletions src/chatty/gui/MainGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -1360,8 +1360,10 @@ else if (cmd.equals("setcolor")) {
else if (cmd.startsWith("command")) {
String command = cmd.substring(7);
client.command(user.getChannel(), command, user.getRegularDisplayNick());
} else if (cmd.equals("copy")) {
MiscUtil.copyToClipboard(user.getRegularDisplayNick());
} else if (cmd.equals("copyNick")) {
MiscUtil.copyToClipboard(user.getNick());
} else if (cmd.equals("copyDisplayNick")) {
MiscUtil.copyToClipboard(user.getDisplayNick());
} else if (cmd.equals("ignore")) {
client.commandSetIgnored(user.nick, "chat", true);
} else if (cmd.equals("ignoreWhisper")) {
Expand Down Expand Up @@ -2860,7 +2862,8 @@ public void run() {
}

private boolean shouldUpdateUser(User user) {
return !user.getChannel().equals(WhisperManager.WHISPER_CHANNEL);
return !user.getChannel().equals(WhisperManager.WHISPER_CHANNEL)
|| channels.isChannel(WhisperManager.WHISPER_CHANNEL);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/chatty/gui/StyleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class StyleManager implements StyleServer {
"filterCombiningCharacters", "pauseChatOnMouseMove",
"pauseChatOnMouseMoveCtrlRequired", "showAnimatedEmotes",
"colorCorrection", "banReasonAppended", "banDurationAppended",
"banDurationMessage", "banReasonMessage"
"banDurationMessage", "banReasonMessage", "displayNamesMode"
));

private MutableAttributeSet baseStyle;
Expand Down Expand Up @@ -139,6 +139,7 @@ private void makeStyles() {
deletedMessagesModeNumeric = settings.getLong("deletedMessagesMaxLength");
}
other.addAttribute(Setting.DELETED_MESSAGES_MODE, deletedMessagesModeNumeric);
addLongSetting(Setting.DISPLAY_NAMES_MODE, "displayNamesMode");
}

private void addBooleanSetting(Setting key, String name) {
Expand Down
1 change: 1 addition & 0 deletions src/chatty/gui/components/UserInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ private void setUser(User user, String localUsername) {
String displayNickInfo = user.hasDisplayNickSet() ? "" : "*";
this.setTitle("User: "+user.toString()
+(user.hasCustomNickSet() ? " ("+user.getDisplayNick()+")" : "")
+(!user.hasRegularDisplayNick() ? " ("+user.getNick()+")" : "")
+displayNickInfo
+" / "+user.getChannel()
+" "+categoriesString);
Expand Down
3 changes: 2 additions & 1 deletion src/chatty/gui/components/menus/UserContextMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public UserContextMenu(User user, ContextMenuListener listener) {
addSeparator();

// Misc Submenu
addItem("copy", "Copy Name", MISC_MENU);
addItem("copyNick", "Copy Name", MISC_MENU);
addItem("copyDisplayNick", "Copy Display Name", MISC_MENU);
addSeparator(MISC_MENU);
ContextMenuHelper.addIgnore(this, user.nick, MISC_MENU, false);
ContextMenuHelper.addIgnore(this, user.nick, MISC_MENU, true);
Expand Down
16 changes: 16 additions & 0 deletions src/chatty/gui/components/settings/MessageSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package chatty.gui.components.settings;

import chatty.Helper;
import chatty.SettingsManager;
import chatty.gui.GuiUtil;
import chatty.gui.components.LinkLabel;
import chatty.util.DateTime;
Expand Down Expand Up @@ -147,6 +148,21 @@ public void actionPerformed(ActionEvent e) {
"If enabled, changes some usercolors to make them more readable on the current background"),
gbc);

otherSettingsPanel.add(new JLabel("Localized names:"),
d.makeGbc(0, 4, 1, 1));

Map<Long, String> displayNamesModeSettings = new LinkedHashMap<>();
displayNamesModeSettings.put(SettingsManager.DISPLAY_NAMES_MODE_BOTH, "Localized+Original Name");
displayNamesModeSettings.put(SettingsManager.DISPLAY_NAMES_MODE_REGULAR, "Only Original Name");
displayNamesModeSettings.put(SettingsManager.DISPLAY_NAMES_MODE_LOCALIZED, "Only Localized Name");
ComboLongSetting displayNamesMode = new ComboLongSetting(displayNamesModeSettings);
d.addLongSetting("displayNamesMode", displayNamesMode);

otherSettingsPanel.add(displayNamesMode,
d.makeGbc(1, 4, 2, 1));



/**
* Timeout settings
*/
Expand Down
50 changes: 39 additions & 11 deletions src/chatty/gui/components/textpane/ChannelTextPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import chatty.gui.components.ChannelEditBox;
import chatty.Helper;
import chatty.SettingsManager;
import chatty.gui.MouseClickedListener;
import chatty.gui.UserListener;
import chatty.gui.HtmlColors;
Expand Down Expand Up @@ -132,7 +133,9 @@ public enum Setting {
EMOTICON_MAX_HEIGHT, EMOTICON_SCALE_FACTOR, BOT_BADGE_ENABLED,
FILTER_COMBINING_CHARACTERS, PAUSE_ON_MOUSEMOVE,
PAUSE_ON_MOUSEMOVE_CTRL_REQUIRED, EMOTICONS_SHOW_ANIMATED,
COLOR_CORRECTION
COLOR_CORRECTION,

DISPLAY_NAMES_MODE
}

private static final long DELETED_MESSAGES_KEEP = 0;
Expand Down Expand Up @@ -1269,13 +1272,20 @@ private void clearSearchResult() {
*
* @param user
* @param action
* @param whisper
* @param id
*/
public void printUser(User user, boolean action, boolean ignore,
boolean whisper, String id) {
String userName = user.toString();
if (styles.showUsericons() && !ignore) {
printUserIcons(user);
userName = user.getCustomNick();
if (user.hasRegularDisplayNick() || user.hasCustomNickSet()
|| styles.displayNamesMode() != SettingsManager.DISPLAY_NAMES_MODE_REGULAR) {
userName = user.getCustomNick();
} else {
userName = user.getNick();
}
}
if (user.hasCategory("rainbow")) {
printRainbowUser(user, userName, action, SpecialColor.RAINBOW, id);
Expand All @@ -1293,10 +1303,30 @@ public void printUser(User user, boolean action, boolean ignore,
print("-["+userName + "]- ", style);
}
} else if (action) {
print("* " + userName + " ", style);
print("* " + userName, style);
} else {
print(userName + ": ", style);
print(userName, style);
}
}

if (!user.hasRegularDisplayNick()
&& styles.displayNamesMode() == SettingsManager.DISPLAY_NAMES_MODE_BOTH) {
MutableAttributeSet style = styles.nick(user, null);
StyleConstants.setBold(style, false);
int fontSize = StyleConstants.getFontSize(style) - 2;
if (fontSize <= 0) {
fontSize = StyleConstants.getFontSize(style);
}
StyleConstants.setFontSize(style, fontSize);
print(" ("+user.getNick()+")", style);
}

// Requires user style because it needs the metadata to detect the end
// of the nick when deleting messages (and possibly other stuff)
if (!action) {
print(": ", styles.nick(user, null));
} else {
print(" ", styles.nick(user, null));
}
}

Expand Down Expand Up @@ -1338,13 +1368,6 @@ private void printRainbowUser(User user, String userName, boolean action,
StyleConstants.setForeground(userStyle, c);
print(userName.substring(i, i+1), userStyle);
}
// Requires user style because it needs the metadata to detect the end
// of the nick when deleting messages (and possibly other stuff)
if (!action) {
print(": ", styles.nick(user, null));
} else {
print(" ", styles.nick(user, null));
}
}

private Color makeRainbowColor(int i, int length) {
Expand Down Expand Up @@ -2504,6 +2527,7 @@ private void setSettings() {
addNumericSetting(Setting.AUTO_SCROLL_TIME, 30, 5, 1234);
addNumericSetting(Setting.EMOTICON_MAX_HEIGHT, 200, 0, 300);
addNumericSetting(Setting.EMOTICON_SCALE_FACTOR, 100, 1, 200);
addNumericSetting(Setting.DISPLAY_NAMES_MODE, 0, 0, 2);
timestampFormat = styleServer.getTimestampFormat();
}

Expand Down Expand Up @@ -2858,6 +2882,10 @@ public SimpleDateFormat timestampFormat() {
public int bufferSize() {
return (int)numericSettings.get(Setting.BUFFER_SIZE);
}

public long displayNamesMode() {
return numericSettings.get(Setting.DISPLAY_NAMES_MODE);
}
}

}
Expand Down
4 changes: 1 addition & 3 deletions src/chatty/gui/emoji/EmojiUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static void main(String[] args) {
}
}

private static void twemoji(EmojiSet set, Set<Emoticon> result) {
private static void twemoji(EmojiSet set, Set<Emoticon> result) {
add(set, result, "\uD83C\uDC04","1f004.png","mahjong","symbols");
add(set, result, "\uD83C\uDCCF","1f0cf.png","black joker","symbols");
add(set, result, "\uD83C\uDD70","1f170.png","a","symbols");
Expand Down Expand Up @@ -1737,7 +1737,6 @@ private static void twemoji(EmojiSet set, Set<Emoticon> result) {
add(set, result, "\uD83E\uDDC0","1f9c0.png","cheese wedge","food");
add(set, result, "\u203C","203c.png","bangbang","symbols");
add(set, result, "\u2049","2049.png","interrobang","symbols");
add(set, result, "\u2122","2122.png","trade mark sign","symbols");
add(set, result, "\u2139","2139.png","information source","symbols");
add(set, result, "\u2194","2194.png","left right arrow","symbols");
add(set, result, "\u2195","2195.png","up down arrow","symbols");
Expand Down Expand Up @@ -3571,7 +3570,6 @@ private static void e1(EmojiSet set, Set<Emoticon> result) {
add(set, result, "\uD83E\uDDC0","1f9c0.png","cheese wedge","food");
add(set, result, "\u203C","203c.png","bangbang","symbols");
add(set, result, "\u2049","2049.png","interrobang","symbols");
add(set, result, "\u2122","2122.png","trade mark sign","symbols");
add(set, result, "\u2139","2139.png","information source","symbols");
add(set, result, "\u2194","2194.png","left right arrow","symbols");
add(set, result, "\u2195","2195.png","up down arrow","symbols");
Expand Down
8 changes: 6 additions & 2 deletions src/chatty/util/chatlog/ChatLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,14 @@ public void start() {
public void message(String channel, User user, String message, boolean action) {
if (isEnabled(channel)) {
String line;
String name = user.toString();
if (!user.hasRegularDisplayNick()) {
name += " ("+user.getNick()+")";
}
if (action) {
line = timestamp()+"<"+user+">* "+message;
line = timestamp()+"<"+name+">* "+message;
} else {
line = timestamp()+"<"+user+"> "+message;
line = timestamp()+"<"+name+"> "+message;
}
writeLine(channel, line);
}
Expand Down

0 comments on commit 9bab65c

Please sign in to comment.