diff --git a/sigIRCv2.bat b/sigIRCv2.bat new file mode 100644 index 0000000..e763464 --- /dev/null +++ b/sigIRCv2.bat @@ -0,0 +1 @@ +java -jar ./sigIRCv2.jar \ No newline at end of file diff --git a/sigIRCv2.jar b/sigIRCv2.jar index a9a626d..03452c9 100644 Binary files a/sigIRCv2.jar and b/sigIRCv2.jar differ diff --git a/src/sig/ConfigFile.java b/src/sig/ConfigFile.java index 5ed04a8..9e735a2 100644 --- a/src/sig/ConfigFile.java +++ b/src/sig/ConfigFile.java @@ -6,9 +6,12 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.util.Arrays; import java.util.HashMap; import java.util.Properties; +import sig.utils.FileUtils; + public class ConfigFile { String basepath; Properties properties; @@ -90,12 +93,20 @@ public class ConfigFile { public void saveProperties() { try { properties.store(GetFileWriter(basepath), "Properties file for sigIRCv2\n"); + SortConfigProperties(); System.out.println("Properties successfully saved."); } catch (IOException e) { e.printStackTrace(); } } + private void SortConfigProperties() { + String[] contents = FileUtils.readFromFile(sigIRC.BASEDIR+basepath); + Arrays.sort(contents); + //System.out.println(Arrays.toString(contents)); + FileUtils.writetoFile(contents, sigIRC.BASEDIR+basepath); + } + private FileReader GetFileReader(String basepath) { File file = new File(sigIRC.BASEDIR+basepath); if (file.exists()) { diff --git a/src/sig/UpdateEvent.java b/src/sig/UpdateEvent.java index a589a02..fbfa556 100644 --- a/src/sig/UpdateEvent.java +++ b/src/sig/UpdateEvent.java @@ -19,14 +19,18 @@ public class UpdateEvent implements ActionListener{ private void UpdateAuthenticationCountdownMessage() { if (sigIRC.downloadsComplete) { - if (!sigIRC.authenticated && last_authentication_msg=MSGTIMER) { + if ((!sigIRC.authenticated || sigIRC.testMode) && 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.playedoAuthSoundOnce); - if (!sigIRC.playedoAuthSoundOnce) { - sigIRC.playedoAuthSoundOnce=true; + 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. Kappa",!sigIRC.playedoAuthSoundOnce); } } if (last_autosave0) { //Don't accept 0 or negative numbers as acceptable values. + if (lastValue>newValue) { + upArrow=false; + } else + if (lastValue=1) { + incr_rate = 1; + int val = diff; + while (val>10) { + val/=10; + incr_rate*=10; + } + } + if (displayedValue0) { + lastValueChange--; + g.drawImage((upArrow)?TwitchModule.UPARROWIMAGE:TwitchModule.DOWNARROWIMAGE, x+xoffset, y+yoffset, sigIRC.panel); + } + xoffset+=((upArrow)?TwitchModule.UPARROWIMAGE.getWidth():TwitchModule.DOWNARROWIMAGE.getWidth())+4; + return new Rectangle(x,y,xoffset,yoffset+16); + } +} diff --git a/src/sig/modules/TwitchModule.java b/src/sig/modules/TwitchModule.java index b90191d..804f847 100644 --- a/src/sig/modules/TwitchModule.java +++ b/src/sig/modules/TwitchModule.java @@ -3,6 +3,7 @@ package sig.modules; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; +import java.awt.Rectangle; import java.awt.event.WindowEvent; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; @@ -14,6 +15,7 @@ import java.text.DateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; +import java.util.Date; import java.util.List; import javax.imageio.ImageIO; @@ -29,10 +31,12 @@ import com.mb3364.twitch.api.models.User; import sig.Module; import sig.sigIRC; import sig.modules.Twitch.Announcement; +import sig.modules.Twitch.FancyNumber; import sig.utils.DrawUtils; import sig.utils.FileUtils; import sig.utils.SoundUtils; import sig.utils.TextUtils; +import sig.utils.TimeUtils; public class TwitchModule extends Module{ public String console="Twitch module goes here."; @@ -50,6 +54,15 @@ public class TwitchModule extends Module{ int lastFollowerAnnouncement=0; User announcedFollowerUser; String[] followersounds = new String[]{"Glaceon_cry.wav"}; + FancyNumber viewers_numb; + FancyNumber followers_numb; + FancyNumber views_numb; + Date uptime; + String currentlyPlaying=""; + final public static int ARROWTIMER = 3000; + public static BufferedImage UPARROWIMAGE; + public static BufferedImage DOWNARROWIMAGE; + public static BufferedImage UPTIMEIMAGE; public TwitchModule(Rectangle2D bounds, String moduleName) { this(bounds,moduleName,true); @@ -62,7 +75,8 @@ public class TwitchModule extends Module{ private void Initialize() { boolean firstTime = false; - InitializeFollowerImage(); + InitializeImages(); + InitializeStatistics(); firstTime = CreateUserFolder(); if (firstTime) { CreateFollowerQueueLog(); @@ -116,6 +130,12 @@ public class TwitchModule extends Module{ });*/ } + private void InitializeStatistics() { + viewers_numb = new FancyNumber("icon_viewers_count.png",0); + views_numb = new FancyNumber("icon_views_count.png",0); + followers_numb = new FancyNumber("icon_follower_count.png",0); + } + public void run() { if (lastFollowerCheck--<=0) { lastFollowerCheck = FOLLOWERCHECKTIMER; @@ -136,6 +156,14 @@ public class TwitchModule extends Module{ } private void popFollowerFromQueue() { + if (sigIRC.testMode) { + User user = new User(); + user.setDisplayName("Test User"+((int)Math.random()*100000)); + user.setBio("I am an awesome test subject."); + user.setName(user.getDisplayName()); + user.setLogo("http://45.33.13.215/sigIRCv2/sigIRC/sigIRCicon.png"); + DisplayFollowerAnnouncement(user,true); + } else if (follower_queue.size()>0) { if (isStreamOnline()) { //We have a follower to announce! @@ -190,10 +218,13 @@ public class TwitchModule extends Module{ SoundUtils.playSound(SOUNDSDIR+followersounds[(int)(Math.random()*followersounds.length)]); } - private void InitializeFollowerImage() { + private void InitializeImages() { try { follower_img = ImageIO.read(new File(sigIRC.BASEDIR+sigIRC.twitchmodule_follower_img)); - System.out.println("Initialized Follower Image successfully."); + UPARROWIMAGE = ImageIO.read(new File(sigIRC.BASEDIR+"sigIRC/icon_up_arrow.png")); + DOWNARROWIMAGE = ImageIO.read(new File(sigIRC.BASEDIR+"sigIRC/icon_down_arrow.png")); + UPTIMEIMAGE = ImageIO.read(new File(sigIRC.BASEDIR+"sigIRC/icon_uptime.png")); + //System.out.println("Initialized Follower Image successfully."); } catch (IOException e) { e.printStackTrace(); } @@ -268,9 +299,18 @@ public class TwitchModule extends Module{ if (arg0==null) { TwitchModule.streamOnline=false; } else { - TwitchModule.streamOnline=true; + TwitchModule.streamOnline=true; + UpdateAllStreamStatistics(arg0); } } + + private void UpdateAllStreamStatistics(Stream data) { + currentlyPlaying = data.getGame(); + uptime = data.getCreatedAt(); + viewers_numb.updateValue(data.getViewers()); + views_numb.updateValue((int)data.getChannel().getViews()); + followers_numb.updateValue(data.getChannel().getFollowers()); + } }); return TwitchModule.streamOnline; @@ -343,6 +383,35 @@ public class TwitchModule extends Module{ super.draw(g); //DrawUtils.drawText(g, bounds.getX(), bounds.getY()+24, Color.RED, console); DrawFollowerAnnouncement(g); + if (streamOnline) { + DrawStatisticsBar(g); + } + } + + private void DrawStatisticsBar(Graphics g) { + g.setColor(new Color(25,25,25)); + int xoffset = (int)bounds.getX()+4; + int yoffset = (int)(bounds.getY()+follower_img.getHeight()+sigIRC.twitchmodule_newfollowerImgLogoSize); + g.fillPolygon(new int[]{(int)bounds.getX(),(int)(bounds.getX()+bounds.getWidth()),(int)(bounds.getX()+bounds.getWidth()),(int)bounds.getX()}, + new int[]{yoffset-4,yoffset-4,yoffset+16,yoffset+16}, + 4); + DrawUtils.drawOutlineText(g, sigIRC.panel.userFont, xoffset, yoffset+TextUtils.calculateStringBoundsFont(currentlyPlaying, sigIRC.panel.userFont).getHeight()/2+3, 2, g.getColor(), new Color(195,195,195), currentlyPlaying);xoffset+=TextUtils.calculateStringBoundsFont(currentlyPlaying, sigIRC.panel.userFont).getWidth()+16; + Rectangle offsets = DrawUptime(g, xoffset, yoffset);xoffset+=offsets.getWidth(); + offsets = views_numb.draw(g, xoffset, yoffset);xoffset+=offsets.getWidth(); + offsets = followers_numb.draw(g, xoffset, yoffset);xoffset+=offsets.getWidth(); + offsets = viewers_numb.draw(g, xoffset, yoffset);xoffset+=offsets.getWidth(); + } + + private Rectangle DrawUptime(Graphics g, int x, int y) { + int xoffset = 0; + int yoffset = 0; + g.drawImage(UPTIMEIMAGE, x+xoffset, y+yoffset-2, sigIRC.panel);xoffset+=UPTIMEIMAGE.getWidth()+4; + String timediff = TimeUtils.GetTimeDifferenceFromCurrentDate(uptime); + if (timediff.length()>0) { + DrawUtils.drawTextFont(g, sigIRC.panel.userFont, x+xoffset, y+yoffset+TextUtils.calculateStringBoundsFont(timediff, sigIRC.panel.userFont).getHeight()/2+3,new Color(184,181,192),timediff);xoffset+=TextUtils.calculateStringBoundsFont(timediff, sigIRC.panel.userFont).getWidth()+12; + } + yoffset+=16; + return new Rectangle(x,y,xoffset,yoffset); } private void DrawFollowerAnnouncement(Graphics g) { diff --git a/src/sig/sigIRC.java b/src/sig/sigIRC.java index 95d100d..a7c8ad5 100644 --- a/src/sig/sigIRC.java +++ b/src/sig/sigIRC.java @@ -95,6 +95,7 @@ public class sigIRC{ public static String twitchmodule_newfollowerShadowTextColor="26,90,150"; public static String twitchmodule_newfollowerTextColor="255,255,255"; public static int twitchmodule_newfollowerImgLogoSize=32; + public static boolean testMode=false; public static void main(String[] args) { @@ -131,6 +132,7 @@ public class sigIRC{ 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); + testMode = config.getBoolean("Testing_Mode",false); touhoumothermodule_X = config.getInteger("TOUHOUMOTHER_module_X",0); touhoumothermodule_Y = config.getInteger("TOUHOUMOTHER_module_Y",312); touhoumothermodule_width = config.getInteger("TOUHOUMOTHER_module_width",320); @@ -181,6 +183,12 @@ public class sigIRC{ manager = new FileManager("sigIRC/record"); manager.verifyAndFetchFileFromServer(); manager = new FileManager("sigIRC/glaceon_follower.png"); manager.verifyAndFetchFileFromServer(); manager = new FileManager("sigIRC/sigIRCicon.png"); manager.verifyAndFetchFileFromServer(); + manager = new FileManager("sigIRC/icon_down_arrow.png"); manager.verifyAndFetchFileFromServer(); + manager = new FileManager("sigIRC/icon_follower_count.png"); manager.verifyAndFetchFileFromServer(); + manager = new FileManager("sigIRC/icon_up_arrow.png"); manager.verifyAndFetchFileFromServer(); + manager = new FileManager("sigIRC/icon_uptime.png"); manager.verifyAndFetchFileFromServer(); + manager = new FileManager("sigIRC/icon_viewers_count.png"); manager.verifyAndFetchFileFromServer(); + manager = new FileManager("sigIRC/icon_views_count.png"); manager.verifyAndFetchFileFromServer(); manager = new FileManager("kill.png"); manager.verifyAndFetchFileFromServer(); manager = new FileManager("memory"); manager.verifyAndFetchFileFromServer(); manager = new FileManager("swap.png"); manager.verifyAndFetchFileFromServer(); diff --git a/src/sig/utils/TimeUtils.java b/src/sig/utils/TimeUtils.java new file mode 100644 index 0000000..5f98488 --- /dev/null +++ b/src/sig/utils/TimeUtils.java @@ -0,0 +1,32 @@ +package sig.utils; + +import java.text.DecimalFormat; +import java.util.Calendar; +import java.util.Date; + + +public class TimeUtils { + public static String GetTimeDifferenceFromCurrentDate(Date pastDate) { + long totalseconds = (Calendar.getInstance().getTimeInMillis()-pastDate.getTime())/1000; + //System.out.println("Total Seconds: "+totalseconds); + long seconds = (long)(totalseconds); + long minutes = (long)(seconds/60); + long hours = (long)(minutes/60); + long days = (long)(hours/24); + StringBuilder string = new StringBuilder(); + DecimalFormat df = new DecimalFormat("00"); + if (days>0) { + string.append(days); + } + if (hours>0) { + string.append(((string.length()>0)?":":"")+(hours%24)); + } + if (minutes>0) { + string.append(((string.length()>0)?":":"")+df.format((minutes%60))); + } + if (seconds>0) { + string.append(((string.length()>0)?":":"")+df.format((seconds%60))); + } + return string.toString(); + } +}