diff --git a/sigIRCv2.jar b/sigIRCv2.jar index 8c9efbc..34e7e8c 100644 Binary files a/sigIRCv2.jar and b/sigIRCv2.jar differ diff --git a/src/sig/MyPanel.java b/src/sig/MyPanel.java index 076e392..9aa8e8e 100644 --- a/src/sig/MyPanel.java +++ b/src/sig/MyPanel.java @@ -99,7 +99,7 @@ public class MyPanel extends JPanel implements MouseListener, ActionListener, Mo break; } } - if (!sigIRC.overlayMode) { + if (!sigIRC.overlayMode && sigIRC.button!=null) { sigIRC.button.draw(g); } } @@ -183,19 +183,23 @@ public class MyPanel extends JPanel implements MouseListener, ActionListener, Mo } public static void UpdateComponent(Component com) { - 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.button.x = sigIRC.panel.getX()+sigIRC.panel.getWidth()-96; - sigIRC.button.y = 64+sigIRC.rowobj.size()*sigIRC.rowSpacing; - //com.repaint(); - //sigIRC.panel.repaint(); - sigIRC.config.saveProperties(); + if (sigIRC.window!=null && sigIRC.window.getLocationOnScreen()!=null) { + 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); + if (sigIRC.button!=null) { + sigIRC.button.x = sigIRC.panel.getX()+sigIRC.panel.getWidth()-96; + sigIRC.button.y = 64+sigIRC.rowobj.size()*sigIRC.rowSpacing; + } + //com.repaint(); + //sigIRC.panel.repaint(); + sigIRC.config.saveProperties(); + } } @Override @@ -220,7 +224,7 @@ public class MyPanel extends JPanel implements MouseListener, ActionListener, Mo m.windowClosed(ev); } sigIRC.config.saveProperties(); - if (sigIRC.autoUpdateProgram==0) { + if (sigIRC.autoUpdateProgram==0 && !sigIRC.offlineMode && sigIRC.updateAvailable) { try { FileUtils.copyFile(new File(sigIRC.PROGRAM_UPDATE_FILE), new File(sigIRC.BASEDIR+"sigIRCv2.jar")); } catch (IOException e) { diff --git a/src/sig/sigIRC.java b/src/sig/sigIRC.java index 74ec184..d598de1 100644 --- a/src/sig/sigIRC.java +++ b/src/sig/sigIRC.java @@ -38,6 +38,7 @@ import sig.utils.MemoryUtils; import sig.utils.TextUtils; import sig.windows.IntroDialog; import sig.windows.LoadingDialog; +import sig.windows.ProgramWindow; import sig.windows.TwitchEmoteDownload; import java.awt.Color; @@ -73,6 +74,7 @@ public class sigIRC{ final public static String VERSION = "1.0"; public static MyPanel panel = null; + public static boolean offlineMode = false; public static ColorPanel colorpanel = null; public static List textobj = new ArrayList(); public static List rowobj = new ArrayList(); @@ -99,15 +101,16 @@ public class sigIRC{ final public static int DINGTIMER=150; static boolean dingEnabled=true; static int dingThreshold; - static Color backgroundcol; + public static Color backgroundcol; public static BackgroundColorButton button; - public static JFrame window; - static boolean overlayMode=false; - static boolean showWindowControls=false; - static int windowX=0; - static int windowY=0; - static int windowWidth=0; - static int windowHeight=0; + public static ProgramWindow window; + public static boolean overlayMode=false; + public static boolean showWindowControls=false; + public static boolean updateAvailable=false; + public static int windowX=0; + public static int windowY=0; + public static int windowWidth=0; + public static int windowHeight=0; static int chatRows=3; static int chatScrollSpd=4; static int rowSpacing=64; @@ -118,7 +121,7 @@ public class sigIRC{ public static boolean twitchmodule_enabled=true; public static boolean chatlogmodule_enabled=true; static boolean downloadsComplete=false; - static boolean hardwareAcceleration=true; + public static boolean hardwareAcceleration=true; static boolean playedoAuthSoundOnce=false; public static int twitchmodule_width=500; public static int twitchmodule_height=200; @@ -251,7 +254,9 @@ public class sigIRC{ //new IntroDialog(); loadingdialog = new LoadingDialog(); - + + + /* DownloadAllRequiredDependencies(); @@ -365,6 +370,7 @@ public class sigIRC{ programFile.delete(); } org.apache.commons.io.FileUtils.copyURLToFile(new URL(sigIRC.PROGRAM_EXECUTABLE_URL),programFile); + sigIRC.updateAvailable=true; } catch (IOException e) { e.printStackTrace(); } diff --git a/src/sig/utils/FileUtils.java b/src/sig/utils/FileUtils.java index ade655d..f03f814 100644 --- a/src/sig/utils/FileUtils.java +++ b/src/sig/utils/FileUtils.java @@ -11,6 +11,7 @@ import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.Reader; import java.net.URL; +import java.net.UnknownHostException; import java.nio.channels.FileChannel; import java.nio.charset.Charset; import java.util.ArrayList; @@ -207,18 +208,21 @@ public class FileUtils { } public static JSONObject readJsonFromUrl(String url, String file, boolean writeToFile) throws IOException, JSONException { - InputStream is = new URL(url).openStream(); + InputStream is; try { + is = new URL(url).openStream(); BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); String jsonText = readAll(rd); if (writeToFile) { writetoFile(new String[]{jsonText},file); } JSONObject json = new JSONObject(jsonText); - return json; - } finally { is.close(); + return json; + } catch (UnknownHostException e) { + sigIRC.offlineMode = true; } + return null; } public static JSONArray readJsonArrayFromUrl(String url, String file, boolean writeToFile) throws IOException, JSONException { diff --git a/src/sig/windows/LoadingDialog.java b/src/sig/windows/LoadingDialog.java index 7a3fde1..c58a97c 100644 --- a/src/sig/windows/LoadingDialog.java +++ b/src/sig/windows/LoadingDialog.java @@ -4,6 +4,7 @@ import java.awt.Dimension; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; +import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; @@ -101,21 +102,26 @@ public class LoadingDialog extends JFrame{ managers.add(new FileManager("sigIRC/rabi-ribi/items/attack_up.png")); } - JSONObject twitchemotes; - try { - twitchemotes = FileUtils.readJsonFromUrl("https://twitchemotes.com/api_cache/v3/global.json"); - System.out.println("Twitch emote Json read."); - for (String emotes : twitchemotes.keySet()) { - JSONObject emote = twitchemotes.getJSONObject(emotes); - int id = emote.getInt("id"); - String name = emote.getString("code"); - LoadingDialog.emotes.add(new TwitchEmoteDownload(name,id)); - managers.add(new FakeFileManager("_FAKE_")); - //emoticons.add(new Emoticon(name, new URL(TWITCHEMOTEURL+id+"/1.0"))); - System.out.println("Emote "+id+" with name "+name); + if (!sigIRC.offlineMode) { + JSONObject twitchemotes; + try { + twitchemotes = FileUtils.readJsonFromUrl("https://twitchemotes.com/api_cache/v3/global.json"); + System.out.println("Twitch emote Json read."); + if (twitchemotes!=null) { + for (String emotes : twitchemotes.keySet()) { + JSONObject emote = twitchemotes.getJSONObject(emotes); + int id = emote.getInt("id"); + String name = emote.getString("code"); + LoadingDialog.emotes.add(new TwitchEmoteDownload(name,id)); + managers.add(new FakeFileManager("_FAKE_")); + //emoticons.add(new Emoticon(name, new URL(TWITCHEMOTEURL+id+"/1.0"))); + System.out.println("Emote "+id+" with name "+name); + } + } + } catch (NullPointerException | JSONException | IOException e) { + sigIRC.offlineMode=true; + e.printStackTrace(); } - } catch (JSONException | IOException e) { - e.printStackTrace(); } bar.setValue(0); @@ -148,20 +154,25 @@ public class LoadingDialog extends JFrame{ for (TwitchEmoteDownload d : emotes) { try { - d.download(); + if (!sigIRC.offlineMode) { + d.download(); + } bar.setValue(bar.getValue()+1); UpdateBar(); } catch (MalformedURLException e) { e.printStackTrace(); } } - - sigIRC.prepareTwitchEmoteUpdate(); + if (!sigIRC.offlineMode) { + sigIRC.prepareTwitchEmoteUpdate(); + } twitchEmoteUpdate.setDone(); bar.setValue(bar.getValue()+1); UpdateBar(); - sigIRC.DownloadProgramUpdate(); + if (!sigIRC.offlineMode) { + sigIRC.DownloadProgramUpdate(); + } programUpdate.setDone(); bar.setValue(bar.getValue()+1); UpdateBar(); @@ -186,6 +197,10 @@ public class LoadingDialog extends JFrame{ sigIRC.emoticons.add(new Emoticon(":D","11")); sigIRC.emoticons.add(new Emoticon(">(","12")); sigIRC.emoticons.add(new Emoticon("<3","13")); + + //Load is done. Start up the panel. + sigIRC.window = new ProgramWindow(); + this.setVisible(false); } private void UpdateBar() { diff --git a/src/sig/windows/ProgramWindow.java b/src/sig/windows/ProgramWindow.java new file mode 100644 index 0000000..87dab75 --- /dev/null +++ b/src/sig/windows/ProgramWindow.java @@ -0,0 +1,104 @@ +package sig.windows; + +import java.awt.Color; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import javax.imageio.ImageIO; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JToggleButton; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import sig.BackgroundColorButton; +import sig.ColorPanel; +import sig.MyPanel; +import sig.sigIRC; + +public class ProgramWindow extends JFrame{ + + static Icon deselected_icon,selected_icon; + + List buttons = new ArrayList(); + + public ProgramWindow() { + try { + deselected_icon = new ImageIcon(ImageIO.read(sigIRC.class.getResource("/resource/deselected_button.png"))); + selected_icon = new ImageIcon(ImageIO.read(sigIRC.class.getResource("/resource/selected_button.png"))); + } catch (IOException e) { + e.printStackTrace(); + } + + if (sigIRC.overlayMode && sigIRC.showWindowControls) { + JFrame.setDefaultLookAndFeelDecorated(true); + } + System.setProperty("sun.java2d.opengl", Boolean.toString(sigIRC.hardwareAcceleration)); + JFrame f = new JFrame("sigIRCv2"); + this.setAutoRequestFocus(true); + this.toFront(); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + if (sigIRC.overlayMode && !sigIRC.showWindowControls) { + this.setUndecorated(true); + } + sigIRC.panel = new MyPanel(); + if (sigIRC.overlayMode) { + sigIRC.panel.setOpaque(false); + } + sigIRC.panel.setBackground(sigIRC.backgroundcol); + + if (!sigIRC.disableChatMessages) { + + } + + //colorpanel = new ColorPanel(); + //this.add(colorpanel); + this.add(sigIRC.panel); + this.pack(); + this.setVisible(true); + this.setLocation(sigIRC.windowX, sigIRC.windowY); + this.setSize(sigIRC.windowWidth, sigIRC.windowHeight); + + this.setIconImage(sigIRC.programIcon); + + // button = new BackgroundColorButton(new File(sigIRC.BASEDIR+"backcolor.png"),panel.getX()+panel.getWidth()-96,64+rowobj.size()*rowSpacing); + if (sigIRC.overlayMode) { + this.setBackground(new Color(0,0,0,0)); + this.setAlwaysOnTop(true); + } + //this.setOpacity(0.5f); + this.addWindowListener(sigIRC.panel); + } +} + +class ModuleButton extends JToggleButton { + String label = ""; + ModuleButton button; + public ModuleButton(String label) { + this.label=label; + this.button=this; + this.setBackground(Color.DARK_GRAY); + button.setForeground(Color.GRAY); + button.setIconTextGap(4); + button.setIcon(IntroDialog.deselected_icon); + button.setSelectedIcon(IntroDialog.selected_icon); + this.addChangeListener(new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + if (button.isSelected()) { + button.setForeground(Color.BLUE); + } + else { + button.setBackground(Color.DARK_GRAY); + button.setForeground(Color.GRAY); + } + } + + }); + } + +} \ No newline at end of file