diff --git a/sigIRCv2.jar b/sigIRCv2.jar index 8fe24ff..952efbd 100644 Binary files a/sigIRCv2.jar and b/sigIRCv2.jar differ diff --git a/src/sig/Module.java b/src/sig/Module.java index 3f0ca7d..6bd9b1a 100644 --- a/src/sig/Module.java +++ b/src/sig/Module.java @@ -7,6 +7,7 @@ import java.awt.Rectangle; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; +import java.awt.event.WindowEvent; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.util.Vector; @@ -27,6 +28,7 @@ public class Module { Point dragOffset; boolean dragging=false; + public static boolean DRAGGING=false; public Module(Rectangle2D bounds, String moduleName) { this.bounds = bounds; @@ -50,10 +52,10 @@ public class Module { } private void enableWindowDrag(int mouseX, int mouseY) { - if (!dragging && inDragBounds(mouseX,mouseY)) { + if (!dragging && inDragBounds(mouseX,mouseY) && !DRAGGING) { //Enable dragging. dragOffset = new Point((int)bounds.getX() - mouseX,(int)bounds.getY()-mouseY); - dragging=true; + dragging=DRAGGING=true; } } @@ -65,10 +67,15 @@ public class Module { public void mousePressed(MouseEvent ev) { } + + public void ApplyConfigWindowProperties() { + } public void mouseReleased(MouseEvent ev) { if (dragging) { - dragging=false; + dragging=DRAGGING=false; + ApplyConfigWindowProperties(); + sigIRC.config.saveProperties(); } } @@ -150,4 +157,8 @@ public class Module { public void keyreleased(KeyEvent ev) { } + + public void windowClosed(WindowEvent ev) { + + } } diff --git a/src/sig/MyPanel.java b/src/sig/MyPanel.java index 7e49495..f29ab3f 100644 --- a/src/sig/MyPanel.java +++ b/src/sig/MyPanel.java @@ -18,13 +18,15 @@ import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; import javax.swing.JColorChooser; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JPopupMenu; -public class MyPanel extends JPanel implements MouseListener, ActionListener, MouseWheelListener, KeyListener, ComponentListener{ +public class MyPanel extends JPanel implements MouseListener, ActionListener, MouseWheelListener, KeyListener, ComponentListener, WindowListener{ //List messages = new ArrayList(); final public static Font programFont = new Font(sigIRC.messageFont,0,24); final public static Font userFont = new Font(sigIRC.usernameFont,0,16); @@ -199,4 +201,36 @@ public class MyPanel extends JPanel implements MouseListener, ActionListener, Mo @Override public void componentHidden(ComponentEvent ev) { } + + @Override + public void windowActivated(WindowEvent ev) { + } + + @Override + public void windowClosed(WindowEvent ev) { + } + + @Override + public void windowClosing(WindowEvent ev) { + for (Module m : sigIRC.modules) { + m.windowClosed(ev); + } + sigIRC.config.saveProperties(); + } + + @Override + public void windowDeactivated(WindowEvent ev) { + } + + @Override + public void windowDeiconified(WindowEvent ev) { + } + + @Override + public void windowIconified(WindowEvent ev) { + } + + @Override + public void windowOpened(WindowEvent ev) { + } } diff --git a/src/sig/modules/TouhouMotherModule.java b/src/sig/modules/TouhouMotherModule.java index 483479c..dcfd167 100644 --- a/src/sig/modules/TouhouMotherModule.java +++ b/src/sig/modules/TouhouMotherModule.java @@ -94,7 +94,7 @@ public class TouhouMotherModule extends Module implements ActionListener{ @Override public void actionPerformed(ActionEvent ev) { memory = FileUtils.readFromFile(sigIRC.BASEDIR+"memory"); - System.out.println(Arrays.toString(memory)); + //System.out.println(Arrays.toString(memory)); if (memory.length>=14) { ProcessMemoryData(); ValidateAndControlMonsterData(); @@ -118,6 +118,13 @@ public class TouhouMotherModule extends Module implements ActionListener{ } } + public void ApplyConfigWindowProperties() { + sigIRC.touhoumothermodule_X=(int)bounds.getX(); + sigIRC.touhoumothermodule_Y=(int)bounds.getY(); + sigIRC.config.setInteger("TOUHOUMOTHER_module_X", sigIRC.touhoumothermodule_X); + sigIRC.config.setInteger("TOUHOUMOTHER_module_Y", sigIRC.touhoumothermodule_Y); + } + public void draw(Graphics g) { if (enabled) { super.draw(g); diff --git a/src/sig/modules/Twitch/Announcement.java b/src/sig/modules/Twitch/Announcement.java new file mode 100644 index 0000000..cd90ebc --- /dev/null +++ b/src/sig/modules/Twitch/Announcement.java @@ -0,0 +1,45 @@ +package sig.modules.Twitch; + +import java.io.File; +import java.text.DateFormat; + +import com.mb3364.twitch.api.models.User; + +import sig.modules.TwitchModule; +import sig.utils.FileUtils; + +public class Announcement { + User userData; + long twitchID; + public Announcement(long twitchID) { + String userFilePath = TwitchModule.USERDIR+twitchID; + File userFile = new File(userFilePath); + if (userFile.exists()) { + String[] contents = FileUtils.readFromFile(userFilePath); + userData = new User(); + int i=1; + userData.setId(twitchID); + userData.setBio(contents[i++]); + userData.setDisplayName(contents[i++]); + userData.setLogo(contents[i++]); + userData.setName(contents[i++]); + userData.setType(contents[i++]); + } else { + System.out.println("WARNING! Could not find user with ID "+twitchID+"!"); + } + this.twitchID=twitchID; + } + + public Announcement(User data) { + this.userData=data; + this.twitchID=data.getId(); + } + + public String toString() { + return userData.toString(); + } + + public User getUser() { + return userData; + } +} diff --git a/src/sig/modules/TwitchModule.java b/src/sig/modules/TwitchModule.java index e6f8b15..3aed37a 100644 --- a/src/sig/modules/TwitchModule.java +++ b/src/sig/modules/TwitchModule.java @@ -2,29 +2,54 @@ package sig.modules; import java.awt.Color; import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.event.WindowEvent; import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; import java.text.DateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.List; + +import javax.imageio.ImageIO; +import javax.swing.SwingUtilities; import com.mb3364.twitch.api.Twitch; import com.mb3364.twitch.api.handlers.ChannelFollowsResponseHandler; import com.mb3364.twitch.api.handlers.StreamResponseHandler; import com.mb3364.twitch.api.models.ChannelFollow; import com.mb3364.twitch.api.models.Stream; +import com.mb3364.twitch.api.models.User; import sig.Module; import sig.sigIRC; +import sig.modules.Twitch.Announcement; import sig.utils.DrawUtils; import sig.utils.FileUtils; +import sig.utils.SoundUtils; import sig.utils.TextUtils; public class TwitchModule extends Module{ public String console="Twitch module goes here."; Twitch manager = new Twitch(); - final static String USERDIR = sigIRC.BASEDIR+"sigIRC/users/"; - final static String FOLLOWERQUEUEFILE = USERDIR+"followers.txt"; + final public static String USERDIR = sigIRC.BASEDIR+"sigIRC/users/"; + final public static String SOUNDSDIR = sigIRC.BASEDIR+"sigIRC/sounds/"; + final public static String FOLLOWERQUEUEFILE = USERDIR+"followers.txt"; public static boolean streamOnline = false; + static BufferedImage follower_img; + BufferedImage followerUserLogo; + List follower_queue = new ArrayList(); + final static int FOLLOWERCHECKTIMER = 900; + int lastFollowerCheck=300; + final static int FOLLOWERANNOUNCEMENTTIME = 300; + int lastFollowerAnnouncement=0; + User announcedFollowerUser; + String[] followersounds = new String[]{"Pokemon Cries - #471 Glaceon.wav"}; public TwitchModule(Rectangle2D bounds, String moduleName) { this(bounds,moduleName,true); @@ -37,6 +62,7 @@ public class TwitchModule extends Module{ private void Initialize() { boolean firstTime = false; + InitializeFollowerImage(); firstTime = CreateUserFolder(); if (firstTime) { CreateFollowerQueueLog(); @@ -83,6 +109,94 @@ public class TwitchModule extends Module{ } } );*/ + /*SwingUtilities.invokeLater(new Runnable() { + public void run() { + System.out.println("Follower Queue Size: "+follower_queue.size()+", Contents: "+follower_queue); + } + });*/ + } + + public void run() { + if (lastFollowerCheck--<=0) { + lastFollowerCheck = FOLLOWERCHECKTIMER; + getFollowers(false); + popFollowerFromQueue(); + } + if (lastFollowerAnnouncement>0) { + lastFollowerAnnouncement--; + } + //System.out.println(lastFollowerCheck); + } + + public void ApplyConfigWindowProperties() { + sigIRC.twitchmodule_X=(int)bounds.getX(); + sigIRC.twitchmodule_Y=(int)bounds.getY(); + sigIRC.config.setInteger("TWITCH_module_X", sigIRC.twitchmodule_X); + sigIRC.config.setInteger("TWITCH_module_Y", sigIRC.twitchmodule_Y); + } + + private void popFollowerFromQueue() { + if (follower_queue.size()>0) { + if (isStreamOnline()) { + //We have a follower to announce! + Announcement a = follower_queue.remove(0); + User user = a.getUser(); + if (user.getDisplayName().length()>0 && + !user.getDisplayName().contains("?")) { + DisplayFollowerAnnouncement(user,true); + } else { + DisplayFollowerAnnouncement(user,false); + } + } else { + //Store away all remaining followers in the queue....We can't announce them right now. + StoreRemainingFollowers(); + } + } + } + + public void windowClosed(WindowEvent ev) { + StoreRemainingFollowers(); + } + + private void StoreRemainingFollowers() { + for (Announcement a : follower_queue) { + FileUtils.logToFile(Long.toString(a.getUser().getId()), FOLLOWERQUEUEFILE); + } + follower_queue.clear(); + } + + private void DisplayFollowerAnnouncement(User user, boolean useNickname) { + lastFollowerAnnouncement = FOLLOWERANNOUNCEMENTTIME; + if (!useNickname) { + user.setDisplayName(user.getName()); + } + announcedFollowerUser = user; + String followerAnnouncement = user.getDisplayName()+" is now following the stream!"; + String userlogo = USERDIR+user.getId()+"_logo"; + if (!user.getLogo().equalsIgnoreCase("null")) { + try { + org.apache.commons.io.FileUtils.copyURLToFile(new URL(user.getLogo()),new File(userlogo)); + followerUserLogo = ImageIO.read(new File(userlogo)); + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } else { + followerUserLogo = null; + } + LogMessageToFile(followerAnnouncement); + System.out.println(followerAnnouncement); + SoundUtils.playSound(SOUNDSDIR+followersounds[(int)(Math.random()*followersounds.length)]); + } + + private void InitializeFollowerImage() { + try { + follower_img = ImageIO.read(new File(sigIRC.BASEDIR+sigIRC.twitchmodule_follower_img)); + System.out.println("Initialized Follower Image successfully."); + } catch (IOException e) { + e.printStackTrace(); + } } private void CreateFollowerQueueLog() { @@ -99,7 +213,6 @@ public class TwitchModule extends Module{ } private void getFollowers(boolean firstTime) { - //isStreamOnline(); manager.channels().getFollows(TextUtils.getActualChannelName(), new ChannelFollowsResponseHandler() { @Override public void onSuccess(int total, java.util.List follows) { @@ -120,12 +233,19 @@ public class TwitchModule extends Module{ } } ); - if (isStreamOnline()) {ClearFollowerAnnouncerQueue();} + if (isStreamOnline()) {/*System.out.println("Stream is Online...Clearing Follower Queue.");*/ClearFollowerAnnouncerQueue();} } private void ClearFollowerAnnouncerQueue() { - // TODO Read the file and announce everybody in that queue. - + String[] contents = FileUtils.readFromFile(FOLLOWERQUEUEFILE); + //System.out.println("Contents: "+Arrays.toString(contents)); + FileUtils.deleteFile(FOLLOWERQUEUEFILE); + for (String s : contents) { + if (s.length()>0) { + int twitchID = Integer.parseInt(s); + AddFollowerToQueue(twitchID); + } + } } private boolean isStreamOnline() { @@ -146,52 +266,61 @@ public class TwitchModule extends Module{ public void onSuccess(Stream arg0) { //System.out.println("Stream data is available! "+arg0); if (arg0==null) { - //System.out.println("Stream is offline."); TwitchModule.streamOnline=false; } else { - TwitchModule.streamOnline=true; + TwitchModule.streamOnline=true; } } }); - //return TwitchModule.streamOnline; - return false; + return TwitchModule.streamOnline; + //return false; } protected void addFollower(ChannelFollow f, boolean streamOnline, boolean silent) { String filename = USERDIR+f.getUser().getId(); File userProfile = new File(filename); - if (!silent) { //If we got in here, this isn't the initial follower setup, so we are good to go with announcing these followers. - if (!streamOnline) { - //Save their ID to a queue. - FileUtils.logToFile(Long.toString(f.getUser().getId()), FOLLOWERQUEUEFILE); - } else { - //Announce it now. - AnnounceFollower(f); + if (!userProfile.exists()) { + if (!silent) { //If we got in here, this isn't the initial follower setup, so we are good to go with announcing these followers. + if (!streamOnline) { + //Save their ID to a queue. + FileUtils.logToFile(Long.toString(f.getUser().getId()), FOLLOWERQUEUEFILE); + } else { + //Announce it now. + //System.out.println("Stream is online..."); + AnnounceFollower(f); + } } + CreateUserProfile(f, filename, userProfile); } - CreateUserProfile(f, filename, userProfile); } private void CreateUserProfile(ChannelFollow f, String filename, File userProfile) { - if (!userProfile.exists()) { - try { - userProfile.createNewFile(); - FileUtils.logToFile(DateFormat.getDateInstance().format(f.getCreatedAt()), filename); - FileUtils.logToFile(f.getUser().getBio(), filename); - FileUtils.logToFile(f.getUser().getDisplayName(), filename); - FileUtils.logToFile(f.getUser().getLogo(), filename); - FileUtils.logToFile(f.getUser().getName(), filename); - FileUtils.logToFile(f.getUser().getType(), filename); - FileUtils.logToFile(DateFormat.getDateInstance().format(f.getUser().getUpdatedAt()), filename); - } catch (IOException e) { - e.printStackTrace(); - } + try { + userProfile.createNewFile(); + FileUtils.logToFile(DateFormat.getDateInstance().format(f.getCreatedAt()), filename); + FileUtils.logToFile(f.getUser().getBio(), filename); + FileUtils.logToFile(f.getUser().getDisplayName(), filename); + FileUtils.logToFile(f.getUser().getLogo(), filename); + FileUtils.logToFile(f.getUser().getName(), filename); + FileUtils.logToFile(f.getUser().getType(), filename); + FileUtils.logToFile(DateFormat.getDateInstance().format(f.getUser().getUpdatedAt()), filename); + } catch (IOException e) { + e.printStackTrace(); } } private void AnnounceFollower(ChannelFollow f) { - System.out.println("Thanks for following "+f.getUser().getDisplayName()+"!"); + //System.out.println("Thanks for following "+f.getUser().getDisplayName()+"!"); + AddFollowerToQueue(f.getUser()); + } + + private void AddFollowerToQueue(int id) { + follower_queue.add(new Announcement(id)); + } + + private void AddFollowerToQueue(User user) { + follower_queue.add(new Announcement(user)); } private boolean CreateUserFolder() { @@ -205,8 +334,58 @@ public class TwitchModule extends Module{ } } + private void LogMessageToFile(String message) { + Calendar cal = Calendar.getInstance(); + FileUtils.logToFile(message, sigIRC.BASEDIR+"sigIRC/logs/log_"+(cal.get(Calendar.MONTH)+1)+"_"+cal.get(Calendar.DAY_OF_MONTH)+"_"+cal.get(Calendar.YEAR)+".txt"); + } + public void draw(Graphics g){ super.draw(g); - DrawUtils.drawText(g, bounds.getX(), bounds.getY()+24, Color.RED, console); + //DrawUtils.drawText(g, bounds.getX(), bounds.getY()+24, Color.RED, console); + DrawFollowerAnnouncement(g); + } + + private void DrawFollowerAnnouncement(Graphics g) { + if (lastFollowerAnnouncement>0) { + final int ticksPassed = FOLLOWERANNOUNCEMENTTIME-lastFollowerAnnouncement; + final int yAlteration = + (sigIRC.twitchmodule_follower_img_animation) + ? Math.max(0,(int)(200-(ticksPassed*(200d/30)))) + : 0; + final int canvasYOffset = + (sigIRC.twitchmodule_follower_img_animation) + ? Math.min(follower_img.getHeight(),yAlteration) + : 0; + final int xAlteration = + (sigIRC.twitchmodule_follower_img_animation) + ? (ticksPassed>=270)?(int)(-((ticksPassed-270)*(500d/30))):0 + : 0; + final int canvasXOffset = + (sigIRC.twitchmodule_follower_img_animation) + ? Math.min(follower_img.getWidth(),xAlteration) + : 0; + //System.out.println(yAlteration); + //g.drawImage(follower_img, (int)bounds.getX()+xAlteration, (int)bounds.getY()+yAlteration, sigIRC.panel); + //g.drawImage(follower_img, (int)bounds.getX(), (int)bounds.getY(), , , sigIRC.panel) + g.drawImage(follower_img, (int)bounds.getX(), (int)bounds.getY()+canvasYOffset, (int)bounds.getX()+follower_img.getWidth()+canvasXOffset, (int)bounds.getY()+follower_img.getHeight(), + -xAlteration, 0, follower_img.getWidth(), follower_img.getHeight()-yAlteration, sigIRC.panel); + Rectangle2D usernameTextsize = TextUtils.calculateStringBoundsFont(announcedFollowerUser.getDisplayName(), sigIRC.panel.programFont); + int textY = (int)bounds.getY()+sigIRC.twitchmodule_followerText_Y+yAlteration; + int textX = (int)bounds.getX()+sigIRC.twitchmodule_followerText_centerX+xAlteration; + if (textYbounds.getX()) { + DrawUtils.drawCenteredText(g, sigIRC.panel.programFont, (int)bounds.getX()+sigIRC.twitchmodule_followerText_centerX+xAlteration, (int)bounds.getY()+sigIRC.twitchmodule_followerText_Y+yAlteration, Color.BLACK, announcedFollowerUser.getDisplayName()); + } + if (!announcedFollowerUser.getBio().equalsIgnoreCase("null")) { + if (followerUserLogo!=null) { + final int image_size = sigIRC.twitchmodule_newfollowerImgLogoSize; + int img_startx = (int)(bounds.getX()+bounds.getWidth()-ticksPassed*3-(image_size+4)); + int img_starty = (int)(bounds.getY()+follower_img.getHeight()+2-image_size/2); + //g.setColor(Color.BLACK); + //g.drawRect(img_startx, img_starty, image_size, image_size); + g.drawImage(followerUserLogo, img_startx, img_starty, img_startx+image_size, img_starty+image_size, 0, 0, followerUserLogo.getWidth(), followerUserLogo.getHeight(), TextUtils.convertStringToColor(sigIRC.twitchmodule_newfollowerImgBackgroundColor), sigIRC.panel); + } + DrawUtils.drawOutlineText(g, sigIRC.panel.userFont, bounds.getX()+bounds.getWidth()-ticksPassed*3, bounds.getY()+follower_img.getHeight()+2+8, 2, TextUtils.convertStringToColor(sigIRC.twitchmodule_newfollowerTextColor), TextUtils.convertStringToColor(sigIRC.twitchmodule_newfollowerShadowTextColor), announcedFollowerUser.getBio()); + } + } } } diff --git a/src/sig/sigIRC.java b/src/sig/sigIRC.java index be91c78..a6e7d29 100644 --- a/src/sig/sigIRC.java +++ b/src/sig/sigIRC.java @@ -17,6 +17,8 @@ import java.awt.Graphics; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Rectangle; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; @@ -48,7 +50,7 @@ public class sigIRC{ final public static int ROWSEPARATION = 64; final public static String BASEDIR = "./"; final public static String WINDOWTITLE = "sigIRCv2"; - static ConfigFile config; + public static ConfigFile config; static String server; static String nickname; public static String channel; @@ -77,6 +79,22 @@ public class sigIRC{ static boolean downloadsComplete=false; static boolean hardwareAcceleration=true; static boolean playedoAuthSoundOnce=false; + public static int twitchmodule_width=500; + public static int twitchmodule_height=120; + public static int twitchmodule_X=320; + public static int twitchmodule_Y=312; + public static String twitchmodule_follower_img="sigIRC/glaceon_follower.png"; + public static boolean twitchmodule_follower_img_animation=true; + public static int twitchmodule_followerText_centerX=292; + public static int twitchmodule_followerText_Y=42; + public static int touhoumothermodule_width=320; + public static int touhoumothermodule_height=312; + public static int touhoumothermodule_X=0; + public static int touhoumothermodule_Y=312; + public static String twitchmodule_newfollowerImgBackgroundColor="90,90,90"; + public static String twitchmodule_newfollowerShadowTextColor="26,90,150"; + public static String twitchmodule_newfollowerTextColor="255,255,255"; + public static int twitchmodule_newfollowerImgLogoSize=32; public static void main(String[] args) { @@ -101,6 +119,22 @@ public class sigIRC{ touhoumotherConsoleFont = config.getProperty("touhoumotherConsoleFont","Agency FB Bold"); touhoumothermodule_enabled = config.getBoolean("Module_touhoumother_Enabled",true); twitchmodule_enabled = config.getBoolean("Module_twitch_Enabled",true); + twitchmodule_width = config.getInteger("TWITCH_module_width",500); + twitchmodule_height = config.getInteger("TWITCH_module_height",120); + twitchmodule_follower_img = config.getProperty("TWITCH_module_follower_img","sigIRC/glaceon_follower.png"); + twitchmodule_follower_img_animation = config.getBoolean("TWITCH_module_follower_img_animation",true); + twitchmodule_followerText_centerX = config.getInteger("TWITCH_module_followerText_centerX",292); + twitchmodule_followerText_Y = config.getInteger("TWITCH_module_followerText_Y",42); + twitchmodule_newfollowerImgLogoSize = config.getInteger("TWITCH_module_newFollowerImgLogoSize",32); + twitchmodule_newfollowerImgBackgroundColor = config.getProperty("TWITCH_module_newFollowerImgBackgroundColor","90,90,90"); + twitchmodule_newfollowerShadowTextColor = config.getProperty("TWITCH_module_newFollowerShadowTextColor","26,90,150"); + twitchmodule_newfollowerTextColor = config.getProperty("TWITCH_module_newFollowerTextColor","255,255,255"); + twitchmodule_X = config.getInteger("TWITCH_module_X",320); + twitchmodule_Y = config.getInteger("TWITCH_module_Y",312); + touhoumothermodule_X = config.getInteger("TOUHOUMOTHER_module_X",0); + touhoumothermodule_Y = config.getInteger("TOUHOUMOTHER_module_Y",312); + touhoumothermodule_width = config.getInteger("TOUHOUMOTHER_module_width",320); + touhoumothermodule_height = config.getInteger("TOUHOUMOTHER_module_height",312); hardwareAcceleration = config.getBoolean("hardware_acceleration",true); DownloadAllRequiredDependencies(); @@ -118,7 +152,6 @@ public class sigIRC{ SwingUtilities.invokeLater(new Runnable() { public void run() { window = createAndShowGUI(); - InitializeModules(); performTwitchEmoteUpdate(); downloadsComplete=true; @@ -163,13 +196,13 @@ public class sigIRC{ } if (touhoumothermodule_enabled) { modules.add(new TouhouMotherModule( - new Rectangle(0,panel.getHeight()/2,320,panel.getHeight()/2), + new Rectangle(touhoumothermodule_X,touhoumothermodule_Y,touhoumothermodule_width,touhoumothermodule_height), "Touhou Mother" )); } if (twitchmodule_enabled) { modules.add(new TwitchModule( - new Rectangle(320,panel.getHeight()/2,panel.getWidth()-320,96), + new Rectangle(twitchmodule_X,twitchmodule_Y,twitchmodule_width,twitchmodule_height), "Twitch" )); } @@ -347,6 +380,7 @@ public class sigIRC{ f.setAlwaysOnTop(true); } //f.setOpacity(0.5f); + f.addWindowListener(sigIRC.panel); return f; } diff --git a/src/sig/utils/DrawUtils.java b/src/sig/utils/DrawUtils.java index a54f700..289872a 100644 --- a/src/sig/utils/DrawUtils.java +++ b/src/sig/utils/DrawUtils.java @@ -60,4 +60,14 @@ public class DrawUtils { g.setColor(healthbarcol); g.fill3DRect((int)bounds.getX()+1, (int)bounds.getY()+1, (int)(bounds.getWidth()*pct)-1, (int)bounds.getHeight()-1, true); } + /** + * Centers the text along the X Axis. + */ + public static void drawCenteredText(Graphics g, Font font, int x, int y, Color color, String text) { + AttributedString as = new AttributedString(text); + as.addAttribute(TextAttribute.FONT, font); + g.setColor(color); + Rectangle2D textBounds = TextUtils.calculateStringBoundsFont(text, font); + g.drawString(as.getIterator(),(int)(x-textBounds.getWidth()/2),(int)(y+textBounds.getHeight())); + } } diff --git a/src/sig/utils/FileUtils.java b/src/sig/utils/FileUtils.java index ae64ef8..049481d 100644 --- a/src/sig/utils/FileUtils.java +++ b/src/sig/utils/FileUtils.java @@ -107,15 +107,22 @@ public class FileUtils { } public static void copyFile(File source, File dest) throws IOException { - FileChannel sourceChannel = null; - FileChannel destChannel = null; - try { - sourceChannel = new FileInputStream(source).getChannel(); - destChannel = new FileOutputStream(dest).getChannel(); - destChannel.transferFrom(sourceChannel, 0, sourceChannel.size()); - }finally{ - sourceChannel.close(); - destChannel.close(); - } - } + FileChannel sourceChannel = null; + FileChannel destChannel = null; + try { + sourceChannel = new FileInputStream(source).getChannel(); + destChannel = new FileOutputStream(dest).getChannel(); + destChannel.transferFrom(sourceChannel, 0, sourceChannel.size()); + }finally{ + sourceChannel.close(); + destChannel.close(); + } + } + + public static void deleteFile(String filename) { + File file = new File(filename); + if (file.exists()) { + file.delete(); + } + } } diff --git a/src/sig/utils/TextUtils.java b/src/sig/utils/TextUtils.java index 5188d50..4725f83 100644 --- a/src/sig/utils/TextUtils.java +++ b/src/sig/utils/TextUtils.java @@ -1,4 +1,5 @@ package sig.utils; +import java.awt.Color; import java.awt.Font; import java.awt.font.FontRenderContext; import java.awt.geom.Rectangle2D; @@ -73,4 +74,12 @@ public class TextUtils { public static String getActualChannelName() { return sigIRC.channel.replaceFirst("#", ""); } + + /** + * Converts a three CSV value to RGB value. + */ + public static Color convertStringToColor(String col) { + String[] split = col.split(","); + return new Color(Integer.parseInt(split[0]),Integer.parseInt(split[1]),Integer.parseInt(split[2])); + } }