diff --git a/.classpath b/.classpath index 7f63612..e58c6d0 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,7 @@ + diff --git a/sigIRCv2.jar b/sigIRCv2.jar index c4a47c1..1925884 100644 Binary files a/sigIRCv2.jar and b/sigIRCv2.jar differ diff --git a/src/sig/ListenerPanel.java b/src/sig/ListenerPanel.java new file mode 100644 index 0000000..5ea12ce --- /dev/null +++ b/src/sig/ListenerPanel.java @@ -0,0 +1,53 @@ +package sig; + +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseWheelEvent; +import java.awt.event.MouseWheelListener; + +import javax.swing.JPanel; + +public class ListenerPanel extends JPanel implements MouseListener, MouseWheelListener{ + + Module mod; + + public ListenerPanel(Module mod) { + this.addMouseListener(this); + this.addMouseWheelListener(this); + this.mod=mod; + } + + @Override + public void mouseWheelMoved(MouseWheelEvent e) { + this.mod.mouseWheelMoved(e); + } + + @Override + public void mouseClicked(MouseEvent e) { + this.mod.mouseClicked(e); + } + + @Override + public void mouseEntered(MouseEvent e) { + this.mod.mouseEntered(e); + } + + @Override + public void mouseExited(MouseEvent e) { + this.mod.mouseExited(e); + } + + @Override + public void mousePressed(MouseEvent e) { + this.mod.mousePressed(e); + } + + @Override + public void mouseReleased(MouseEvent e) { + this.mod.mouseReleased(e); + } + + +} \ No newline at end of file diff --git a/src/sig/Module.java b/src/sig/Module.java index a78a12d..2f8fa71 100644 --- a/src/sig/Module.java +++ b/src/sig/Module.java @@ -11,9 +11,7 @@ import java.awt.event.ComponentListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; import java.awt.event.MouseWheelEvent; -import java.awt.event.MouseWheelListener; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.awt.geom.Rectangle2D; @@ -27,21 +25,21 @@ import java.util.concurrent.TimeUnit; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JFrame; -import javax.swing.JPanel; import javax.swing.SwingUtilities; import sig.utils.DrawUtils; import sig.utils.TextUtils; import sig.windows.ProgramWindow; -public class Module extends JFrame implements MouseListener, MouseWheelListener, KeyListener, ComponentListener, WindowListener{ - public JPanel panel; +public class Module extends JFrame implements ComponentListener, WindowListener, KeyListener{ + public ListenerPanel panel; public Rectangle position; protected boolean enabled; protected String name; public static BufferedImage IMG_DRAGBAR; public static BufferedImage MSG_SEPARATOR; public static boolean inDragZone=false; + final public static int WINDOW_EXTRA_BORDER = 32; //Number of pixels that the border takes up (Reduces the size of the window) final protected int titleHeight; @@ -58,18 +56,16 @@ public class Module extends JFrame implements MouseListener, MouseWheelListener, public Module(Rectangle bounds, String moduleName) { - this.addMouseListener(this); - this.addMouseWheelListener(this); - this.addKeyListener(this); this.addComponentListener(this); this.addWindowListener(this); + this.addKeyListener(this); this.position = bounds; this.name = moduleName; this.enabled=true; this.setVisible(true); this.setTitle(moduleName); - panel = new JPanel(){ + panel = new ListenerPanel(this){ public void paintComponent(Graphics g) { super.paintComponent(g); draw(g); @@ -79,10 +75,12 @@ public class Module extends JFrame implements MouseListener, MouseWheelListener, this.titleHeight = (int)TextUtils.calculateStringBoundsFont(this.name, sigIRC.userFont).getHeight(); + this.setSize((int)position.getWidth(), (int)position.getHeight()); panel.setSize(this.getSize()); this.add(panel); + //this.pack(); ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); scheduler.scheduleWithFixedDelay(()->{ @@ -114,9 +112,6 @@ public class Module extends JFrame implements MouseListener, MouseWheelListener, } return val; } - - public void mousePressed(MouseEvent ev) { - } public void ApplyConfigWindowProperties() { } @@ -124,9 +119,6 @@ public class Module extends JFrame implements MouseListener, MouseWheelListener, public void SaveConfig() { } - - public void mouseReleased(MouseEvent ev) { - } protected void moduleRun() { run(); @@ -147,16 +139,6 @@ public class Module extends JFrame implements MouseListener, MouseWheelListener, public void ModuleDragEvent(int oldX, int oldY, int newX, int newY) { } - - public void mouseWheel(MouseWheelEvent ev) { - } - - public void keypressed(KeyEvent ev) { - - } - - public void keyreleased(KeyEvent ev) { - } public void windowClosed(WindowEvent ev) { @@ -210,7 +192,7 @@ public class Module extends JFrame implements MouseListener, MouseWheelListener, } private void UpdatePosition(ComponentEvent e) { - position = new Rectangle((int)e.getComponent().getLocationOnScreen().getX(),(int)e.getComponent().getLocationOnScreen().getY(),e.getComponent().getWidth(),e.getComponent().getHeight()-16); + position = new Rectangle((int)e.getComponent().getLocationOnScreen().getX(),(int)e.getComponent().getLocationOnScreen().getY(),e.getComponent().getWidth(),e.getComponent().getHeight()); //System.out.println(position); ApplyConfigWindowProperties(); sigIRC.configNeedsUpdating = System.currentTimeMillis(); @@ -226,46 +208,47 @@ public class Module extends JFrame implements MouseListener, MouseWheelListener, // TODO Auto-generated method stub } - - @Override + public void keyPressed(KeyEvent e) { // TODO Auto-generated method stub } - @Override public void keyReleased(KeyEvent e) { // TODO Auto-generated method stub } - @Override public void keyTyped(KeyEvent e) { // TODO Auto-generated method stub } - @Override - public void mouseWheelMoved(MouseWheelEvent e) { + public void mouseWheelMoved(MouseWheelEvent arg0) { // TODO Auto-generated method stub } - @Override public void mouseClicked(MouseEvent e) { // TODO Auto-generated method stub } - @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub } - @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub } + + public void mousePressed(MouseEvent e) { + // TODO Auto-generated method stub + + } + + public void mouseReleased(MouseEvent e) { + } } \ No newline at end of file diff --git a/src/sig/MyPanel.java b/src/sig/MyPanel.java index f2c12ae..10abc60 100644 --- a/src/sig/MyPanel.java +++ b/src/sig/MyPanel.java @@ -30,6 +30,7 @@ import javax.swing.JPanel; import javax.swing.JPopupMenu; import sig.modules.ChatLogModule; +import sig.modules.ScrollingChatModule; import sig.modules.ChatLog.ChatLogMessage; import sig.utils.FileUtils; @@ -51,8 +52,8 @@ public class MyPanel extends JPanel{ // Draw Text //int counter=18; if (sigIRC.panel!=null) { - lastMouseX = (int)(MouseInfo.getPointerInfo().getLocation().getX()-sigIRC.panel.getLocationOnScreen().getX()); - lastMouseY = (int)(MouseInfo.getPointerInfo().getLocation().getY()-sigIRC.panel.getLocationOnScreen().getY()); + lastMouseX = (int)(MouseInfo.getPointerInfo().getLocation().getX()); + lastMouseY = (int)(MouseInfo.getPointerInfo().getLocation().getY()); //System.out.println("("+lastMouseX+","+lastMouseY+")"); } /*if (sigIRC.window!=null && sigIRC.window.getMousePosition(true)!=null && sigIRC.overlayMode) { @@ -103,7 +104,7 @@ public class MyPanel extends JPanel{ } public void addMessage(String message, boolean playSound) { - ScrollingText text = new ScrollingText(message,this.getWidth(),(int)(Math.random()*128),playSound); + ScrollingText text = new ScrollingText(message,ScrollingChatModule.module.getWidth(),(int)(Math.random()*128),playSound); TextRow row = TextRow.PickRandomTextRow(text.getUsername()); sigIRC.textobj.add(text); row.updateRow(text); diff --git a/src/sig/ScrollingText.java b/src/sig/ScrollingText.java index 0428491..e40495f 100644 --- a/src/sig/ScrollingText.java +++ b/src/sig/ScrollingText.java @@ -20,6 +20,7 @@ import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.UnsupportedAudioFileException; import javax.swing.SwingUtilities; +import sig.modules.ScrollingChatModule; import sig.utils.DrawUtils; import sig.utils.FileUtils; import sig.utils.SoundUtils; @@ -180,7 +181,7 @@ public class ScrollingText { } private boolean WithinBounds(double x, double y, double w, double h) { - if (x0 && y0) { + if (x0 && y0) { return true; } return false; @@ -188,28 +189,28 @@ public class ScrollingText { public int FindLeftMostCornerInDisplay() { if (x-shadowSize>0) { - return Math.min((int)x-shadowSize, sigIRC.panel.getWidth()); + return Math.min((int)x-shadowSize, ScrollingChatModule.module.getWidth()); } else { return 0; } } public int FindTopMostCornerInDisplay() { if (y-shadowSize>0) { - return Math.min((int)y-shadowSize, sigIRC.panel.getHeight()); + return Math.min((int)y-shadowSize, ScrollingChatModule.module.getHeight()); } else { return 0; } } public int FindRightMostCornerInDisplay() { if (x+stringWidth+(int)sigIRC.BASESCROLLSPD+1+shadowSize+1>0) { - return Math.min(Math.max(stringWidth,userstringWidth+8)+(int)sigIRC.BASESCROLLSPD+1+shadowSize+1, sigIRC.panel.getWidth()-(int)x); + return Math.min(Math.max(stringWidth,userstringWidth+8)+(int)sigIRC.BASESCROLLSPD+1+shadowSize+1, ScrollingChatModule.module.getWidth()-(int)x); } else { return 0; } } public int FindBottomMostCornerInDisplay() { if (y+stringHeight+shadowSize>0) { - return Math.min(stringHeight+shadowSize+4, sigIRC.panel.getHeight()-(int)y); + return Math.min(stringHeight+shadowSize+4, ScrollingChatModule.module.getHeight()-(int)y); } else { return 0; } diff --git a/src/sig/TwitchEmote.java b/src/sig/TwitchEmote.java index 23303f4..6eaf49c 100644 --- a/src/sig/TwitchEmote.java +++ b/src/sig/TwitchEmote.java @@ -3,6 +3,8 @@ import java.awt.Graphics; import javax.swing.SwingUtilities; +import sig.modules.ScrollingChatModule; + public class TwitchEmote { Emoticon emote; int x=0; //X Offset @@ -38,7 +40,7 @@ public class TwitchEmote { public void draw(Graphics g) { if (WithinBounds((int)(text.getX()+x), (int)(text.getY()+y), emote.getImage().getWidth(), emote.getImage().getHeight())) { - g.drawImage(emote.getImage(), (int)(text.getX()+x), (int)(text.getY()+y), sigIRC.panel); + g.drawImage(emote.getImage(), (int)(text.getX()+x), (int)(text.getY()+y), ScrollingChatModule.module.panel); } } @@ -47,7 +49,7 @@ public class TwitchEmote { } private boolean WithinBounds(double x, double y, double w, double h) { - if (x0 && y0) { + if (x0 && y0) { return true; } return false; diff --git a/src/sig/modules/ChatLog/ChatLogMessage.java b/src/sig/modules/ChatLog/ChatLogMessage.java index 5ac062d..e90b7d4 100644 --- a/src/sig/modules/ChatLog/ChatLogMessage.java +++ b/src/sig/modules/ChatLog/ChatLogMessage.java @@ -25,7 +25,7 @@ public class ChatLogMessage { String username; List displayMessage = new ArrayList(); final static public int MESSAGE_SPACING = 24; - final static public int BORDER_SPACING = 8; + final static public int BORDER_SPACING = 16; final static public Color SHADOW_COL = new Color(35,35,35,255); int usernameWidth = 0; boolean active=true; @@ -170,7 +170,7 @@ public class ChatLogMessage { } private String BreakTextAtNextSection(String msg, int maxWidth) { - int marker = 1; + int marker = msg.indexOf(' '); int textWidth = (int)TextUtils.calculateStringBoundsFont(msg.substring(0, marker), sigIRC.userFont).getWidth(); while (textWidth0 && + return (position.getY()+MESSAGE_SPACING-Module.WINDOW_EXTRA_BORDER)>0 && (position.getY()+messageDisplaySize.getY())0 && y0) { + if (x0 && y0) { return true; } return false; diff --git a/src/sig/modules/ChatLogModule.java b/src/sig/modules/ChatLogModule.java index 729f3cc..37510e5 100644 --- a/src/sig/modules/ChatLogModule.java +++ b/src/sig/modules/ChatLogModule.java @@ -32,7 +32,8 @@ public class ChatLogModule extends Module{ public int scrolllog_yoffset = 0; public Color backgroundColor; long positionsNeedUpdating = 0; //Set it to System.currentTimeMillis() to request a configuration save. - Rectangle prevpos; + Rectangle prevpos = (Rectangle)position.clone(); + int justOpened=2; public ChatLogModule(Rectangle bounds, String moduleName) { @@ -40,7 +41,6 @@ public class ChatLogModule extends Module{ //Initialize(); chatlogmodule = this; backgroundColor = DrawUtils.convertStringToColor(sigIRC.chatlogmodule_backgroundColor); - prevpos = (Rectangle)position.clone(); } private void Initialize() { @@ -77,13 +77,22 @@ public class ChatLogModule extends Module{ } } } + if (positionsNeedUpdating==0 && (prevpos.getWidth()!=position.getWidth() || prevpos.getHeight()!=position.getHeight())) { + positionsNeedUpdating=System.currentTimeMillis(); + } if (positionsNeedUpdating!=0 && System.currentTimeMillis()-positionsNeedUpdating>1000) { positionsNeedUpdating=0; int diff = (int)(position.getHeight()-prevpos.getHeight()); prevpos = (Rectangle)position.clone(); - for (ChatLogMessage clm : messageHistory) { + /*for (ChatLogMessage clm : messageHistory) { clm.position.y+=diff; - } + }*/ + messageHistory.clear(); + sigIRC.chatlogtwitchemoticons.clear(); + Initialize(); + moveAllMessages(-scrolllog_yoffset); + scrolllog_yoffset=0; + repaint(); } } @@ -92,13 +101,15 @@ public class ChatLogModule extends Module{ g.setColor(backgroundColor); g.fill3DRect(0, 0, (int)position.getWidth(), (int)position.getHeight(), true); g.setColor(Color.BLACK); - for (int i=0; i0) { if (HighestMessageIsVisible()) { @@ -145,11 +157,6 @@ public class ChatLogModule extends Module{ return true; } - @Override - public void componentResized(ComponentEvent e) { - this.positionsNeedUpdating=System.currentTimeMillis(); - } - public void moveAllMessages(int yAmt) { for (int i=0;i=position.getX() && - mouseX<=position.getX()+position.getWidth() && - mouseY>=position.getX() && - mouseY<=position.getX()+position.getHeight(); + return mouseX>=0 && + mouseX<=0+position.getWidth() && + mouseY>=0 && + mouseY<=0+position.getHeight(); } - public void keypressed(KeyEvent ev) { + public void keyPressed(KeyEvent ev) { int key = ev.getKeyCode(); int scroll = 0; if (key==KeyEvent.VK_PAGE_UP) { @@ -181,7 +188,7 @@ public class ChatLogModule extends Module{ scroll=-8; } if (key==KeyEvent.VK_HOME) { - scroll=Math.abs(GetHighestMessagePosition()); + scroll=Math.abs(GetHighestMessagePosition()-Module.WINDOW_EXTRA_BORDER); } if (key==KeyEvent.VK_END) { moveAllMessages(-scrolllog_yoffset); diff --git a/src/sig/modules/ScrollingChatModule.java b/src/sig/modules/ScrollingChatModule.java new file mode 100644 index 0000000..76d7501 --- /dev/null +++ b/src/sig/modules/ScrollingChatModule.java @@ -0,0 +1,191 @@ +package sig.modules; + +import java.awt.Graphics; +import java.awt.Rectangle; +import java.io.File; +import java.io.IOException; +import java.util.Calendar; + +import org.json.JSONException; +import org.json.JSONObject; + +import sig.CustomSound; +import sig.Module; +import sig.TextRow; +import sig.sigIRC; +import sig.utils.FileUtils; + +public class ScrollingChatModule extends Module{ + + final static int MSGTIMER = 300; + final static int AUTOSAVETIMER = 600; + int last_authentication_msg = MSGTIMER; + int last_autosave = AUTOSAVETIMER; + public static ScrollingChatModule module; + + public ScrollingChatModule(Rectangle bounds, String moduleName) { + super(bounds, moduleName); + + ScrollingChatModule.module = this; + String[] filedata = FileUtils.readFromFile(sigIRC.BASEDIR+"sigIRC/oauthToken.txt"); + + final String oauth = filedata[0].trim().substring(0, Math.min(36,filedata[0].trim().length())); + Thread t = new Thread(()->{ + sigIRC.InitializeIRCConnection(sigIRC.server, sigIRC.nickname, sigIRC.channel, oauth); + }); + + t.start(); + + UpdateSubEmoticons(); + } + + public void run() { + UpdateScrollingText(); + UpdateAuthenticationCountdownMessage(); + } + + + private void UpdateSubEmoticons() { + if (!sigIRC.downloadedSubEmotes && + sigIRC.disableChatMessages && + sigIRC.subchannelCount==sigIRC.subchannelIds.size()) { + Thread downloadThread = new Thread(){ + public void run() { + JSONObject data = GetSubEmoteJson(); + sigIRC.downloadSubEmotes(data); + sigIRC.subEmotesCompleted=true; + } + }; + downloadThread.start(); + sigIRC.downloadedSubEmotes=true; + } + } + + public void draw(Graphics g) { + for (int i=0;i=MSGTIMER) { + last_authentication_msg=0; + if (!sigIRC.authenticated && !sigIRC.testMode) { + sigIRC.panel.addMessage("SYSTEM: Your oauthToken was not successful. Please go to the sigIRC folder and make sure your oauthToken.txt file is correct!!! SwiftRage",!sigIRC.playedoAuthSoundOnce); + if (!sigIRC.playedoAuthSoundOnce) { + sigIRC.playedoAuthSoundOnce=true; + } + } else { + sigIRC.panel.addMessage("SYSTEM: This is a test message for your testing convenience. mikansBox",!sigIRC.playedoAuthSoundOnce); + } + } + if (last_autosave=AUTOSAVETIMER) { + last_autosave=0; + sigIRC.windowX = (int)sigIRC.window.getLocationOnScreen().getX(); + sigIRC.windowY = (int)sigIRC.window.getLocationOnScreen().getY(); + sigIRC.windowWidth = sigIRC.window.getWidth(); + sigIRC.windowHeight = sigIRC.window.getHeight(); + sigIRC.config.setInteger("windowX", sigIRC.windowX); + sigIRC.config.setInteger("windowY", sigIRC.windowY); + sigIRC.config.setInteger("windowWidth", sigIRC.windowWidth); + sigIRC.config.setInteger("windowHeight", sigIRC.windowHeight); + sigIRC.config.saveProperties(); + } + if (sigIRC.lastPlayedDing>0) { + sigIRC.lastPlayedDing--; + } + } + } + + public void UpdateScrollingText() { + for (int i=0;i