diff --git a/.classpath b/.classpath index fd654da..fcd4204 100644 --- a/.classpath +++ b/.classpath @@ -2,7 +2,7 @@ - + diff --git a/.gitignore b/.gitignore index 983c3ec..997ceee 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ /sigIRCv2.conf /swap.png /update.png -/WSplits \ No newline at end of file +/WSplits +/drag_bar.png diff --git a/projectBuilder.xml b/projectBuilder.xml index 48c0b4c..362bfe3 100644 --- a/projectBuilder.xml +++ b/projectBuilder.xml @@ -13,7 +13,7 @@ - + diff --git a/sigIRCv2.jar b/sigIRCv2.jar index f8efd31..54544cf 100644 Binary files a/sigIRCv2.jar and b/sigIRCv2.jar differ diff --git a/src/sig/BackgroundColorButton.java b/src/sig/BackgroundColorButton.java index 3dbee0b..48dd8ed 100644 --- a/src/sig/BackgroundColorButton.java +++ b/src/sig/BackgroundColorButton.java @@ -11,11 +11,11 @@ import java.util.Arrays; import javax.imageio.ImageIO; -import sig.DrawUtils; -import sig.FileUtils; -import sig.TextUtils; import sig.sigIRC; import sig.modules.TouhouMotherModule; +import sig.utils.DrawUtils; +import sig.utils.FileUtils; +import sig.utils.TextUtils; public class BackgroundColorButton { BufferedImage buttonimg; diff --git a/src/sig/CustomSound.java b/src/sig/CustomSound.java index 888c6c7..fba5be1 100644 --- a/src/sig/CustomSound.java +++ b/src/sig/CustomSound.java @@ -1,5 +1,6 @@ package sig; +import sig.utils.SoundUtils; public class CustomSound { final static int SOUNDCOOLDOWN = 108000; diff --git a/src/sig/Emoticon.java b/src/sig/Emoticon.java index 72fae90..3cb0172 100644 --- a/src/sig/Emoticon.java +++ b/src/sig/Emoticon.java @@ -6,6 +6,8 @@ import java.net.URL; import javax.imageio.ImageIO; +import sig.utils.TextUtils; + public class Emoticon { private BufferedImage image=null; private String emotename=null; diff --git a/src/sig/Module.java b/src/sig/Module.java index 359daef..23fcf39 100644 --- a/src/sig/Module.java +++ b/src/sig/Module.java @@ -1,43 +1,131 @@ package sig; +import java.awt.Color; +import java.awt.Cursor; import java.awt.Graphics; +import java.awt.Point; +import java.awt.Rectangle; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; +import java.util.Vector; import javax.swing.SwingUtilities; +import sig.utils.DrawUtils; +import sig.utils.TextUtils; + public class Module { protected Rectangle2D bounds; protected boolean enabled; protected String name; + public static BufferedImage IMG_DRAGBAR; + + final protected int titleHeight; + + Point dragOffset; + boolean dragging=false; public Module(Rectangle2D bounds, String moduleName) { this.bounds = bounds; this.name = moduleName; this.enabled=true; + + this.titleHeight = (int)TextUtils.calculateStringBoundsFont(this.name, sigIRC.panel.userFont).getHeight(); } public Module(Rectangle2D bounds, String moduleName, boolean enabled) { - this.bounds = bounds; - this.name = moduleName; + this(bounds, moduleName); this.enabled=enabled; } + protected void mouseModuleMousePress(MouseEvent ev) { + int mouseX = ev.getX(); + int mouseY = ev.getY(); + //System.out.println(mouseX + "," + mouseY); + enableWindowDrag(mouseX,mouseY); + mousePressed(ev); + } + + private void enableWindowDrag(int mouseX, int mouseY) { + if (!dragging && inDragBounds(mouseX,mouseY)) { + //Enable dragging. + dragOffset = new Point((int)bounds.getX() - mouseX,(int)bounds.getY()-mouseY); + dragging=true; + } + } + + public boolean inDragBounds(int x, int y) { + return x>=bounds.getX() && x<=bounds.getX()+bounds.getWidth() && + y>=(int)bounds.getY()-Module.IMG_DRAGBAR.getHeight() && + y<=(int)bounds.getY(); + } + public void mousePressed(MouseEvent ev) { } + + public void mouseReleased(MouseEvent ev) { + if (dragging) { + dragging=false; + } + } + + protected void moduleRun() { + dragWindow(); + run(); + } + + private void dragWindow() { + if (dragging) { + sigIRC.panel.repaint(getDrawBounds().getBounds()); + int mouseX = sigIRC.panel.lastMouseX+(int)dragOffset.getX(); + int mouseY = sigIRC.panel.lastMouseY+(int)dragOffset.getY(); + int oldX = (int)bounds.getX(); + int oldY = (int)bounds.getY(); + bounds = new Rectangle(mouseX, mouseY,(int)bounds.getWidth(),(int)bounds.getHeight()); + //System.out.println(sigIRC.panel.lastMouseX+","+sigIRC.panel.lastMouseY); + ModuleDragEvent(oldX,oldY,mouseX,mouseY); + } + if (inDragBounds(sigIRC.panel.lastMouseX,sigIRC.panel.lastMouseY)) { + sigIRC.panel.setCursor(new Cursor(Cursor.MOVE_CURSOR)); + } else + if (sigIRC.panel.getCursor().getType()==Cursor.MOVE_CURSOR) { + sigIRC.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + } + } public void run() { } public void draw(Graphics g) { + drawModuleHeader(g); SwingUtilities.invokeLater(new Runnable() { public void run() { - sigIRC.panel.repaint(bounds.getBounds()); + sigIRC.panel.repaint(getDrawBounds().getBounds()); } }); } + private void drawModuleHeader(Graphics g) { + g.drawImage(Module.IMG_DRAGBAR, + (int)bounds.getX()+2, + (int)bounds.getY()-Module.IMG_DRAGBAR.getHeight(), + (int)bounds.getWidth()-4, + Module.IMG_DRAGBAR.getHeight(), + sigIRC.panel); + DrawUtils.drawTextFont(g, sigIRC.panel.smallFont, (int)bounds.getX(), (int)bounds.getY()-titleHeight/2+4, Color.BLACK, this.name); + } + + private Rectangle2D getDrawBounds() { + Rectangle2D drawBounds = new Rectangle((int)bounds.getX(),(int)bounds.getY()-titleHeight+3,(int)bounds.getWidth(),(int)bounds.getHeight()+titleHeight); + return drawBounds; + } + + public void ModuleDragEvent(int oldX, int oldY, int newX, int newY) { + + } + public void mouseWheel(MouseWheelEvent ev) { } diff --git a/src/sig/MyPanel.java b/src/sig/MyPanel.java index ecf345a..7e49495 100644 --- a/src/sig/MyPanel.java +++ b/src/sig/MyPanel.java @@ -95,7 +95,11 @@ public class MyPanel extends JPanel implements MouseListener, ActionListener, Mo } public void addMessage(String message) { - ScrollingText text = new ScrollingText(message,this.getWidth(),(int)(Math.random()*128)); + addMessage(message,true); + } + + public void addMessage(String message, boolean playSound) { + ScrollingText text = new ScrollingText(message,this.getWidth(),(int)(Math.random()*128),playSound); TextRow row = TextRow.PickRandomTextRow(text.getUsername()); sigIRC.textobj.add(text); row.updateRow(text); @@ -108,13 +112,16 @@ public class MyPanel extends JPanel implements MouseListener, ActionListener, Mo @Override public void mousePressed(MouseEvent ev) { for (Module m : sigIRC.modules) { - m.mousePressed(ev); + m.mouseModuleMousePress(ev); } sigIRC.button.onClickEvent(ev); } @Override public void mouseReleased(MouseEvent ev) { + for (Module m : sigIRC.modules) { + m.mouseReleased(ev); + } } @Override diff --git a/src/sig/ScrollingText.java b/src/sig/ScrollingText.java index ee9a0bd..2925ec6 100644 --- a/src/sig/ScrollingText.java +++ b/src/sig/ScrollingText.java @@ -20,6 +20,11 @@ import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.UnsupportedAudioFileException; import javax.swing.SwingUtilities; +import sig.utils.DrawUtils; +import sig.utils.FileUtils; +import sig.utils.SoundUtils; +import sig.utils.TextUtils; + public class ScrollingText { private String username; private String message; @@ -86,8 +91,14 @@ public class ScrollingText { this.stringWidth = (int)TextUtils.calculateStringBoundsFont(this.message,MyPanel.programFont).getWidth(); this.stringHeight = (int)TextUtils.calculateStringBoundsFont(this.message,MyPanel.programFont).getHeight(); this.userstringWidth = (int)TextUtils.calculateStringBoundsFont(this.username,MyPanel.userFont).getWidth(); + } + + public ScrollingText(String msg, double x, double y, boolean playSound) { + this(msg,x,y); - playMessageSound(username); + if (playSound) { + playMessageSound(username); + } } private void playMessageSound(String user) { diff --git a/src/sig/UpdateEvent.java b/src/sig/UpdateEvent.java index 201227e..3eec234 100644 --- a/src/sig/UpdateEvent.java +++ b/src/sig/UpdateEvent.java @@ -24,7 +24,10 @@ public class UpdateEvent implements ActionListener{ } else if (!sigIRC.authenticated && last_authentication_msg>=MSGTIMER) { last_authentication_msg=0; - 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.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; + } } if (last_autosave0) { DrawUtils.drawOutlineText(g, MyPanel.smallFont, x+buttonimg.getWidth()+4, y+buttonimg.getHeight(), 2, Color.WHITE, new Color(60,0,150), message); } diff --git a/src/sig/modules/TouhouMother/TimeRecord.java b/src/sig/modules/TouhouMother/TimeRecord.java index 15a90dd..529f08a 100644 --- a/src/sig/modules/TouhouMother/TimeRecord.java +++ b/src/sig/modules/TouhouMother/TimeRecord.java @@ -1,8 +1,8 @@ package sig.modules.TouhouMother; -import sig.FileUtils; import sig.sigIRC; import sig.modules.TouhouMotherModule; +import sig.utils.FileUtils; public class TimeRecord { final public static int ERROR_VALUE = Integer.MAX_VALUE; diff --git a/src/sig/modules/TouhouMother/TouhouMotherButton.java b/src/sig/modules/TouhouMother/TouhouMotherButton.java new file mode 100644 index 0000000..914b0ec --- /dev/null +++ b/src/sig/modules/TouhouMother/TouhouMotherButton.java @@ -0,0 +1,66 @@ +package sig.modules.TouhouMother; + +import java.awt.Graphics; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; +import java.awt.event.MouseWheelEvent; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; + +import sig.sigIRC; +import sig.modules.TouhouMotherModule; + +public class TouhouMotherButton { + protected BufferedImage buttonimg; + protected int x=0; + protected int y=0; + protected TouhouMotherModule module; + + public TouhouMotherButton(TouhouMotherModule parentmodule, File filename, int x, int y) { + this.x=x; + this.y=y; + this.module=parentmodule; + try { + buttonimg = ImageIO.read(filename); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void run() { + + } + + public void draw(Graphics g) { + g.drawImage(buttonimg, x, y, sigIRC.panel); + } + + public void onClickEvent(MouseEvent ev) { + + } + + public void keyPressEvent(KeyEvent ev) { + + } + + public void keyReleaseEvent(KeyEvent ev) { + + } + + public void onMouseWheelEvent(MouseWheelEvent ev) { + + } + + public void updatePosition(int oldX, int oldY, int newX, int newY) { + int diffx = x - oldX; + int diffy = y - oldY; + x = newX + diffx; + y = newY + diffy; + /*System.out.println("Old: "+oldX+","+oldY); + System.out.println("New: "+newX+","+newY); + System.out.println("Diffs: "+diffx+","+diffy);*/ + } +} diff --git a/src/sig/modules/TouhouMother/Button.java b/src/sig/modules/TouhouMother/UpdateButton.java similarity index 84% rename from src/sig/modules/TouhouMother/Button.java rename to src/sig/modules/TouhouMother/UpdateButton.java index 160ef69..509b3e2 100644 --- a/src/sig/modules/TouhouMother/Button.java +++ b/src/sig/modules/TouhouMother/UpdateButton.java @@ -11,41 +11,30 @@ import java.util.Arrays; import javax.imageio.ImageIO; -import sig.DrawUtils; -import sig.FileUtils; -import sig.TextUtils; import sig.sigIRC; import sig.modules.TouhouMotherModule; +import sig.utils.DrawUtils; +import sig.utils.FileUtils; +import sig.utils.TextUtils; -public class Button { - BufferedImage buttonimg; - int x=0; - int y=0; +public class UpdateButton extends TouhouMotherButton{ String[] data; int currentselection=4; - TouhouMotherModule module; boolean buttonEnabled = false; - public Button(TouhouMotherModule parentmodule, File filename, int x, int y) { - this.x=x; - this.y=y; + public UpdateButton(TouhouMotherModule parentmodule, File filename, int x, int y) { + super(parentmodule,filename,x,y); data = FileUtils.readFromFile(sigIRC.BASEDIR+"WSplits"); if (data.length>4) { buttonEnabled=true; } - this.module=parentmodule; - try { - buttonimg = ImageIO.read(filename); - } catch (IOException e) { - e.printStackTrace(); - } } public void draw(Graphics g) { if (buttonEnabled) { DrawUtils.drawOutlineText(g, sigIRC.panel.smallFont, x-TextUtils.calculateStringBoundsFont(data[currentselection].split(",")[0], sigIRC.panel.smallFont).getWidth(), (int)module.getBounds().getY()+(int)module.getBounds().getHeight()-8, 1, Color.WHITE, new Color(30,0,86,255), data[currentselection].split(",")[0]); - g.drawImage(buttonimg, x, y, sigIRC.panel); + super.draw(g); } } diff --git a/src/sig/modules/TouhouMotherModule.java b/src/sig/modules/TouhouMotherModule.java index 47f04e1..483479c 100644 --- a/src/sig/modules/TouhouMotherModule.java +++ b/src/sig/modules/TouhouMotherModule.java @@ -19,22 +19,23 @@ import java.util.List; import javax.imageio.ImageIO; import javax.swing.Timer; -import sig.DrawUtils; -import sig.FileUtils; import sig.Module; -import sig.TextUtils; import sig.sigIRC; -import sig.modules.TouhouMother.Button; -import sig.modules.TouhouMother.Button2; -import sig.modules.TouhouMother.Button3; import sig.modules.TouhouMother.DataProperty; import sig.modules.TouhouMother.IncreaseTouhouMotherClockCount; +import sig.modules.TouhouMother.KillButton; +import sig.modules.TouhouMother.SwapButton; import sig.modules.TouhouMother.TimeRecord; import sig.modules.TouhouMother.TouhouMotherBossData; +import sig.modules.TouhouMother.TouhouMotherButton; import sig.modules.TouhouMother.TouhouMotherCharacterData; import sig.modules.TouhouMother.TouhouPlayerCharacter; +import sig.modules.TouhouMother.UpdateButton; import sig.modules.utils.SemiValidInteger; import sig.modules.utils.SemiValidString; +import sig.utils.DrawUtils; +import sig.utils.FileUtils; +import sig.utils.TextUtils; public class TouhouMotherModule extends Module implements ActionListener{ Timer filereadClock = new Timer(200,this); @@ -66,9 +67,11 @@ public class TouhouMotherModule extends Module implements ActionListener{ boolean diamondSparkyMsg = false; - Button updateButton; - Button2 killButton; - Button3 swapButton; + List moduleButtons = new ArrayList(); + + UpdateButton updateButton; + KillButton killButton; + SwapButton swapButton; public TouhouMotherModule(Rectangle2D bounds, String moduleName) { super(bounds, moduleName); @@ -109,6 +112,12 @@ public class TouhouMotherModule extends Module implements ActionListener{ EnableAndDisableTimer(); } + public void ModuleDragEvent(int oldX, int oldY, int newX, int newY) { + for (TouhouMotherButton tmb : moduleButtons) { + tmb.updatePosition(oldX,oldY,newX,newY); + } + } + public void draw(Graphics g) { if (enabled) { super.draw(g); @@ -487,15 +496,18 @@ public class TouhouMotherModule extends Module implements ActionListener{ } private void DefineButton() { - updateButton = new Button(this, //56x20 pixels + updateButton = new UpdateButton(this, //56x20 pixels new File(sigIRC.BASEDIR+"update.png"), (int)bounds.getX()+320-56,(int)bounds.getY()+sigIRC.panel.getHeight()/2-20); - killButton = new Button2(this, + killButton = new KillButton(this, new File(sigIRC.BASEDIR+"kill.png"), (int)bounds.getX(),(int)bounds.getY()+sigIRC.panel.getHeight()/2-20); - swapButton = new Button3(this, + swapButton = new SwapButton(this, new File(sigIRC.BASEDIR+"swap.png"), (int)bounds.getX(),(int)bounds.getY()+sigIRC.panel.getHeight()/2-40); + moduleButtons.add(updateButton); + moduleButtons.add(killButton); + moduleButtons.add(swapButton); } public Rectangle2D getBounds() { diff --git a/src/sig/modules/utils/SemiValidInteger.java b/src/sig/modules/utils/SemiValidInteger.java index fe82b91..6445c40 100644 --- a/src/sig/modules/utils/SemiValidInteger.java +++ b/src/sig/modules/utils/SemiValidInteger.java @@ -2,7 +2,7 @@ package sig.modules.utils; import java.util.Arrays; -import sig.TextUtils; +import sig.utils.TextUtils; public class SemiValidInteger { final public static int ERROR_VALUE = Integer.MIN_VALUE; diff --git a/src/sig/modules/utils/SemiValidString.java b/src/sig/modules/utils/SemiValidString.java index ba2977d..09ac4f8 100644 --- a/src/sig/modules/utils/SemiValidString.java +++ b/src/sig/modules/utils/SemiValidString.java @@ -2,7 +2,7 @@ package sig.modules.utils; import java.util.Arrays; -import sig.TextUtils; +import sig.utils.TextUtils; public class SemiValidString { final public static String ERROR_VALUE = "nil"; diff --git a/src/sig/sigIRC.java b/src/sig/sigIRC.java index 23055c6..f74c95e 100644 --- a/src/sig/sigIRC.java +++ b/src/sig/sigIRC.java @@ -7,6 +7,7 @@ import org.json.JSONException; import org.json.JSONObject; import sig.modules.TouhouMotherModule; +import sig.utils.FileUtils; import java.awt.Color; import java.awt.Dimension; @@ -70,11 +71,12 @@ public class sigIRC{ static int chatScrollSpd=4; static int rowSpacing=64; static String messageFont="Gill Sans Ultra Bold Condensed"; - static String usernameFont="Gill Sans"; + static String usernameFont="GillSansMTStd-Book"; static String touhoumotherConsoleFont="Agency FB Bold"; static boolean touhoumothermodule_enabled=true; static boolean downloadsComplete=false; static boolean hardwareAcceleration=true; + static boolean playedoAuthSoundOnce=false; public static void main(String[] args) { @@ -148,10 +150,16 @@ public class sigIRC{ manager = new FileManager("swap.png"); manager.verifyAndFetchFileFromServer(); manager = new FileManager("update.png"); manager.verifyAndFetchFileFromServer(); manager = new FileManager("backcolor.png"); manager.verifyAndFetchFileFromServer(); + manager = new FileManager("drag_bar.png"); manager.verifyAndFetchFileFromServer(); manager = new FileManager("WSplits"); manager.verifyAndFetchFileFromServer(); } private static void InitializeModules() { + try { + Module.IMG_DRAGBAR = ImageIO.read(new File(sigIRC.BASEDIR+"drag_bar.png")); + } catch (IOException e) { + e.printStackTrace(); + } if (touhoumothermodule_enabled) { modules.add(new TouhouMotherModule( new Rectangle(0,panel.getHeight()/2,320,panel.getHeight()/2), diff --git a/src/sig/DrawUtils.java b/src/sig/utils/DrawUtils.java similarity index 95% rename from src/sig/DrawUtils.java rename to src/sig/utils/DrawUtils.java index 2720a35..a54f700 100644 --- a/src/sig/DrawUtils.java +++ b/src/sig/utils/DrawUtils.java @@ -1,4 +1,4 @@ -package sig; +package sig.utils; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; @@ -13,6 +13,8 @@ import java.awt.font.TextAttribute; import java.awt.geom.Rectangle2D; import java.text.AttributedString; +import sig.MyPanel; + public class DrawUtils { public static void drawOutlineText(Graphics g, Font font, double x, double y, int outline_size, Color text_color, Color shadow_color, String message) { AttributedString as = new AttributedString(message); diff --git a/src/sig/FileUtils.java b/src/sig/utils/FileUtils.java similarity index 95% rename from src/sig/FileUtils.java rename to src/sig/utils/FileUtils.java index 230c6c2..ae64ef8 100644 --- a/src/sig/FileUtils.java +++ b/src/sig/utils/FileUtils.java @@ -1,4 +1,4 @@ -package sig; +package sig.utils; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; diff --git a/src/sig/SoundUtils.java b/src/sig/utils/SoundUtils.java similarity index 94% rename from src/sig/SoundUtils.java rename to src/sig/utils/SoundUtils.java index feaa154..b1ec024 100644 --- a/src/sig/SoundUtils.java +++ b/src/sig/utils/SoundUtils.java @@ -1,4 +1,4 @@ -package sig; +package sig.utils; import java.io.File; import java.io.IOException; diff --git a/src/sig/TextUtils.java b/src/sig/utils/TextUtils.java similarity index 94% rename from src/sig/TextUtils.java rename to src/sig/utils/TextUtils.java index cedc461..12b4bff 100644 --- a/src/sig/TextUtils.java +++ b/src/sig/utils/TextUtils.java @@ -1,8 +1,10 @@ -package sig; +package sig.utils; import java.awt.Font; import java.awt.font.FontRenderContext; import java.awt.geom.Rectangle2D; +import sig.sigIRC; + public class TextUtils { public static Rectangle2D calculateStringBoundsFont(String msg, Font font) {