Implemented a status bar to show Twitch stream info. Config file now
re-orders all elements in alphabetical order for easier finding of settings.
This commit is contained in:
parent
7494b60b10
commit
d3f9fa204f
1
sigIRCv2.bat
Normal file
1
sigIRCv2.bat
Normal file
@ -0,0 +1 @@
|
||||
java -jar ./sigIRCv2.jar
|
BIN
sigIRCv2.jar
BIN
sigIRCv2.jar
Binary file not shown.
@ -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()) {
|
||||
|
@ -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++;
|
||||
} else
|
||||
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_autosave<AUTOSAVETIMER) {
|
||||
|
89
src/sig/modules/Twitch/FancyNumber.java
Normal file
89
src/sig/modules/Twitch/FancyNumber.java
Normal file
@ -0,0 +1,89 @@
|
||||
package sig.modules.Twitch;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import sig.sigIRC;
|
||||
import sig.modules.TwitchModule;
|
||||
import sig.utils.DrawUtils;
|
||||
import sig.utils.TextUtils;
|
||||
|
||||
public class FancyNumber {
|
||||
BufferedImage icon;
|
||||
int displayedValue=0;
|
||||
int lastValue=0;
|
||||
int lastValueChange=0;
|
||||
boolean upArrow=false;
|
||||
final static int DELAYEDFREQUENCY = 100; //How many ticks to wait before performing a calculation update.
|
||||
int delayCount=0;
|
||||
final static String ICONDIR = sigIRC.BASEDIR+"sigIRC/";
|
||||
|
||||
public FancyNumber(String icon_name, int startingValue) {
|
||||
try {
|
||||
icon = ImageIO.read(new File(ICONDIR+icon_name));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
lastValue = startingValue;
|
||||
}
|
||||
|
||||
public void updateValue(int newValue) {
|
||||
if (newValue>0) { //Don't accept 0 or negative numbers as acceptable values.
|
||||
if (lastValue>newValue) {
|
||||
upArrow=false;
|
||||
} else
|
||||
if (lastValue<newValue) {
|
||||
upArrow=true;
|
||||
}
|
||||
|
||||
if (lastValue!=newValue) {
|
||||
lastValueChange = TwitchModule.ARROWTIMER;
|
||||
}
|
||||
lastValue = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
public Rectangle draw(Graphics g, int x, int y) {
|
||||
int xoffset = 0;
|
||||
int yoffset = 0;
|
||||
g.drawImage(icon, x, y, sigIRC.panel);
|
||||
xoffset+=icon.getWidth()+4;
|
||||
if (displayedValue!=lastValue) {
|
||||
if (delayCount==0) {
|
||||
int diff = Math.abs(displayedValue-lastValue);
|
||||
double chance = diff*0.1;
|
||||
int incr_rate = 0;
|
||||
if (chance+Math.random()>=1) {
|
||||
incr_rate = 1;
|
||||
int val = diff;
|
||||
while (val>10) {
|
||||
val/=10;
|
||||
incr_rate*=10;
|
||||
}
|
||||
}
|
||||
if (displayedValue<lastValue) {
|
||||
displayedValue+=incr_rate;
|
||||
} else {
|
||||
displayedValue-=incr_rate;
|
||||
}
|
||||
delayCount=DELAYEDFREQUENCY;
|
||||
} else {
|
||||
delayCount--;
|
||||
}
|
||||
}
|
||||
DrawUtils.drawTextFont(g, sigIRC.panel.userFont, x+xoffset, y+yoffset+TextUtils.calculateStringBoundsFont(Integer.toString(displayedValue), sigIRC.panel.userFont).getHeight()/2+3, new Color(184,181,192), Integer.toString(displayedValue));
|
||||
xoffset+=TextUtils.calculateStringBoundsFont(Integer.toString(displayedValue), sigIRC.panel.userFont).getWidth()+4;
|
||||
if (lastValueChange>0) {
|
||||
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);
|
||||
}
|
||||
}
|
@ -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,10 +299,19 @@ 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;
|
||||
//return false;
|
||||
@ -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) {
|
||||
|
@ -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();
|
||||
|
32
src/sig/utils/TimeUtils.java
Normal file
32
src/sig/utils/TimeUtils.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user