Skip to content

Commit

Permalink
Rules, Livestreamer variables, refresh streams
Browse files Browse the repository at this point in the history
- Add Rules support:
  - Add Rules Dialog
  - Open Rules automatically once per channel when typing in the input box
  - Add hotkey to toggle rules
  - Add /openrules command
- Livestreamer:
  - Add $stream, $url, $quality replacements for Base command
  - Change Base command setting to EditorStringSetting for easier editing, with quick help
- Editor: Change quick help alignment
- EditorStringSetting: Add change listener, change to BorderLayout to fill available space
- Add Livestreams Dialog context menu entry to manually refresh streams
  • Loading branch information
tduva committed Sep 25, 2016
1 parent 59db5dd commit 5680b76
Show file tree
Hide file tree
Showing 16 changed files with 452 additions and 24 deletions.
3 changes: 3 additions & 0 deletions src/chatty/SettingsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,9 @@ void defineSettings() {
settings.addString("cmTemplate", "{user}: {message}");
settings.addBoolean("cmHighlightedOnly", false);

settings.addBoolean("rulesAutoShow", true);
settings.addList("rulesShown", new HashSet(), Setting.STRING);

//===============
// Other Features
//===============
Expand Down
6 changes: 6 additions & 0 deletions src/chatty/TwitchClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import chatty.util.TwitchEmotes;
import chatty.util.TwitchEmotes.TwitchEmotesListener;
import chatty.util.Webserver;
import chatty.util.api.ChatInfo;
import chatty.util.api.EmoticonSizeCache;
import chatty.util.api.EmoticonUpdate;
import chatty.util.api.Emoticons;
Expand Down Expand Up @@ -1761,6 +1762,11 @@ public void receivedServer(String channel, String server) {
public void followResult(String message) {
g.printSystem(message);
}

@Override
public void receivedChatInfo(ChatInfo chatInfo) {
g.setChatInfo(chatInfo);
}
}

private void checkToken() {
Expand Down
9 changes: 9 additions & 0 deletions src/chatty/gui/Channels.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class Channels {
private final StyleManager styleManager;
private final ContextMenuListener contextMenuListener;
private final MouseClickedListener mouseClickedListener = new MyMouseClickedListener();
private Channel.OnceOffEditListener onceOffEditListener;

/**
* Default width of the userlist, given to Channel objects when created.
Expand Down Expand Up @@ -89,6 +90,13 @@ public Channels(MainGui gui, StyleManager styleManager,
addDefaultChannel();
}

public void setOnceOffEditListener(Channel.OnceOffEditListener listener) {
this.onceOffEditListener = listener;
if (defaultChannel != null) {
defaultChannel.setOnceOffEditListener(listener);
}
}

public void setChangeListener(ChangeListener listener) {
changeListener = listener;
}
Expand Down Expand Up @@ -162,6 +170,7 @@ private Channel createChannel(String name, Channel.Type type) {
channel.setMouseClickedListener(mouseClickedListener);
channel.setScrollbarAlways(chatScrollbarAlaways);
channel.setUserlistEnabled(defaultUserlistVisibleState);
channel.setOnceOffEditListener(onceOffEditListener);
if (type == Channel.Type.SPECIAL || type == Channel.Type.WHISPER) {
channel.setUserlistEnabled(false);
}
Expand Down
60 changes: 60 additions & 0 deletions src/chatty/gui/MainGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import chatty.Usericon;
import chatty.WhisperManager;
import chatty.gui.components.AddressbookDialog;
import chatty.gui.components.ChatRulesDialog;
import chatty.gui.components.EmotesDialog;
import chatty.gui.components.ErrorMessage;
import chatty.gui.components.FollowersDialog;
Expand All @@ -55,6 +56,7 @@
import chatty.util.MiscUtil;
import chatty.util.Sound;
import chatty.util.StringUtil;
import chatty.util.api.ChatInfo;
import chatty.util.api.Emoticon.EmoticonImage;
import chatty.util.api.EmoticonUpdate;
import chatty.util.api.Emoticons.TagEmotes;
Expand Down Expand Up @@ -128,6 +130,7 @@ public class MainGui extends JFrame implements Runnable {
private FollowersDialog subscribersDialog;
private StreamChat streamChat;
private ModerationLog moderationLog;
private ChatRulesDialog chatRulesDialog;

// Helpers
private final Highlighter highlighter = new Highlighter();
Expand Down Expand Up @@ -257,6 +260,9 @@ private void createGui() {

moderationLog = new ModerationLog(this);

chatRulesDialog = new ChatRulesDialog(this);
channels.setOnceOffEditListener(chatRulesDialog);

//this.getContentPane().setBackground(new Color(0,0,0,0));

getSettingsDialog();
Expand Down Expand Up @@ -482,6 +488,15 @@ public void actionPerformed(ActionEvent e) {
}
});

addMenuAction("dialog.chatRules", "Dialog: Toggle Chat Rules",
"Chat Rules", KeyEvent.VK_UNDEFINED, new AbstractAction() {

@Override
public void actionPerformed(ActionEvent e) {
toggleChatRules();
}
});

addMenuAction("dialog.addressbook", "Dialog: Toggle Addressbook",
"Addressbook", KeyEvent.VK_UNDEFINED, new AbstractAction() {

Expand Down Expand Up @@ -1446,6 +1461,9 @@ public void menuItemClicked(ActionEvent e) {
else if (cmd.equals("channelAdmin")) {
openChannelAdminDialog();
}
else if (cmd.equals("chatRules")) {
openChatRules();
}
else if (cmd.equals("closeChannel")) {
client.closeChannel(channels.getActiveChannel().getName());
}
Expand Down Expand Up @@ -1555,6 +1573,10 @@ public void streamInfosMenuItemClicked(ActionEvent e, Collection<StreamInfo> str
}
streamsMenuItemClicked(e, streams);
}
if (cmd.equals("manualRefreshStreams")) {
client.api.manualRefreshStreams();
state.update(true);
}
}

/**
Expand Down Expand Up @@ -1887,6 +1909,12 @@ public boolean commandGui(String command, String parameter) {
openFollowerDialog();
} else if (command.equals("opensubscribers")) {
openSubscriberDialog();
} else if (command.equals("openrules")) {
if (parameter != null) {
openChatRules("#"+parameter);
} else {
openChatRules();
}
} else if (command.equals("openstreamchat")) {
openStreamChat();
} else if (command.equals("clearstreamchat")) {
Expand Down Expand Up @@ -2145,6 +2173,20 @@ private void toggleModerationLog() {
}
}

private void openChatRules() {
openChatRules(channels.getLastActiveChannel().getName());
}

private void openChatRules(String channel) {
chatRulesDialog.showRules(channel);
}

private void toggleChatRules() {
if (!closeDialog(chatRulesDialog)) {
openChatRules();
}
}

private void openUpdateDialog() {
updateMessage.setLocationRelativeTo(this);
updateMessage.showDialog();
Expand Down Expand Up @@ -3623,6 +3665,24 @@ public void performGameSearch(String search) {
client.api.getGameSearch(search);
}

public void getChatInfo(String stream) {
client.api.requestChatInfo(stream);
}

/**
*
* @param info Can be null in an error occured
*/
public void setChatInfo(final ChatInfo info) {
SwingUtilities.invokeLater(new Runnable() {

@Override
public void run() {
chatRulesDialog.setChatInfo(info);
}
});
}

public String getActiveStream() {
return channels.getActiveChannel().getStreamName();
}
Expand Down
1 change: 1 addition & 0 deletions src/chatty/gui/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public MainMenu(ActionListener actionListener, ItemListener itemListener,
addItem(extra,"dialog.subscribers","Subscribers");
extra.addSeparator();
addItem(extra,"dialog.moderationLog", "Moderation Log");
addItem(extra,"dialog.chatRules", "Chat Rules");
extra.addSeparator();
JMenu streamChat = new JMenu("Stream Chat");
addItem(streamChat,"dialog.streamchat", "Open");
Expand Down
27 changes: 26 additions & 1 deletion src/chatty/gui/components/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -65,7 +67,7 @@ public enum Type {

private String name;

public Channel(String name, Type type, MainGui main, StyleManager styleManager,
public Channel(final String name, Type type, MainGui main, StyleManager styleManager,
ContextMenuListener contextMenuListener) {
this.setLayout(new BorderLayout());
this.styleManager = styleManager;
Expand Down Expand Up @@ -118,6 +120,18 @@ public Channel(String name, Type type, MainGui main, StyleManager styleManager,

input.requestFocusInWindow();
setStyles();

input.addKeyListener(new KeyAdapter() {

@Override
public void keyPressed(KeyEvent e) {
String name = Channel.this.name;
if (onceOffEditListener != null && !name.isEmpty()) {
onceOffEditListener.edited(name);
onceOffEditListener = null;
}
}
});
}

public void cleanUp() {
Expand Down Expand Up @@ -159,6 +173,7 @@ public String getStreamName() {
return null;
}

@Override
public void setName(String name) {
this.name = name;
}
Expand Down Expand Up @@ -626,4 +641,14 @@ public String toString() {
return String.format("%s '%s'", type, name);
}

private OnceOffEditListener onceOffEditListener;

public void setOnceOffEditListener(OnceOffEditListener listener) {
onceOffEditListener = listener;
}

public interface OnceOffEditListener {
public void edited(String channel);
}

}
Loading

0 comments on commit 5680b76

Please sign in to comment.