Allow program to be run in an offline mode. Begin work on new sigIRC

main panel.
dev
sigonasr2 7 years ago
parent f07a89fe22
commit 63dfe0c60e
  1. BIN
      sigIRCv2.jar
  2. 34
      src/sig/MyPanel.java
  3. 24
      src/sig/sigIRC.java
  4. 10
      src/sig/utils/FileUtils.java
  5. 51
      src/sig/windows/LoadingDialog.java
  6. 104
      src/sig/windows/ProgramWindow.java

Binary file not shown.

@ -99,7 +99,7 @@ public class MyPanel extends JPanel implements MouseListener, ActionListener, Mo
break; break;
} }
} }
if (!sigIRC.overlayMode) { if (!sigIRC.overlayMode && sigIRC.button!=null) {
sigIRC.button.draw(g); sigIRC.button.draw(g);
} }
} }
@ -183,19 +183,23 @@ public class MyPanel extends JPanel implements MouseListener, ActionListener, Mo
} }
public static void UpdateComponent(Component com) { public static void UpdateComponent(Component com) {
sigIRC.windowX = (int)sigIRC.window.getLocationOnScreen().getX(); if (sigIRC.window!=null && sigIRC.window.getLocationOnScreen()!=null) {
sigIRC.windowY = (int)sigIRC.window.getLocationOnScreen().getY(); sigIRC.windowX = (int)sigIRC.window.getLocationOnScreen().getX();
sigIRC.windowWidth = sigIRC.window.getWidth(); sigIRC.windowY = (int)sigIRC.window.getLocationOnScreen().getY();
sigIRC.windowHeight = sigIRC.window.getHeight(); sigIRC.windowWidth = sigIRC.window.getWidth();
sigIRC.config.setInteger("windowX", sigIRC.windowX); sigIRC.windowHeight = sigIRC.window.getHeight();
sigIRC.config.setInteger("windowY", sigIRC.windowY); sigIRC.config.setInteger("windowX", sigIRC.windowX);
sigIRC.config.setInteger("windowWidth", sigIRC.windowWidth); sigIRC.config.setInteger("windowY", sigIRC.windowY);
sigIRC.config.setInteger("windowHeight", sigIRC.windowHeight); sigIRC.config.setInteger("windowWidth", sigIRC.windowWidth);
sigIRC.button.x = sigIRC.panel.getX()+sigIRC.panel.getWidth()-96; sigIRC.config.setInteger("windowHeight", sigIRC.windowHeight);
sigIRC.button.y = 64+sigIRC.rowobj.size()*sigIRC.rowSpacing; if (sigIRC.button!=null) {
//com.repaint(); sigIRC.button.x = sigIRC.panel.getX()+sigIRC.panel.getWidth()-96;
//sigIRC.panel.repaint(); sigIRC.button.y = 64+sigIRC.rowobj.size()*sigIRC.rowSpacing;
sigIRC.config.saveProperties(); }
//com.repaint();
//sigIRC.panel.repaint();
sigIRC.config.saveProperties();
}
} }
@Override @Override
@ -220,7 +224,7 @@ public class MyPanel extends JPanel implements MouseListener, ActionListener, Mo
m.windowClosed(ev); m.windowClosed(ev);
} }
sigIRC.config.saveProperties(); sigIRC.config.saveProperties();
if (sigIRC.autoUpdateProgram==0) { if (sigIRC.autoUpdateProgram==0 && !sigIRC.offlineMode && sigIRC.updateAvailable) {
try { try {
FileUtils.copyFile(new File(sigIRC.PROGRAM_UPDATE_FILE), new File(sigIRC.BASEDIR+"sigIRCv2.jar")); FileUtils.copyFile(new File(sigIRC.PROGRAM_UPDATE_FILE), new File(sigIRC.BASEDIR+"sigIRCv2.jar"));
} catch (IOException e) { } catch (IOException e) {

@ -38,6 +38,7 @@ import sig.utils.MemoryUtils;
import sig.utils.TextUtils; import sig.utils.TextUtils;
import sig.windows.IntroDialog; import sig.windows.IntroDialog;
import sig.windows.LoadingDialog; import sig.windows.LoadingDialog;
import sig.windows.ProgramWindow;
import sig.windows.TwitchEmoteDownload; import sig.windows.TwitchEmoteDownload;
import java.awt.Color; import java.awt.Color;
@ -73,6 +74,7 @@ public class sigIRC{
final public static String VERSION = "1.0"; final public static String VERSION = "1.0";
public static MyPanel panel = null; public static MyPanel panel = null;
public static boolean offlineMode = false;
public static ColorPanel colorpanel = null; public static ColorPanel colorpanel = null;
public static List<ScrollingText> textobj = new ArrayList<ScrollingText>(); public static List<ScrollingText> textobj = new ArrayList<ScrollingText>();
public static List<TextRow> rowobj = new ArrayList<TextRow>(); public static List<TextRow> rowobj = new ArrayList<TextRow>();
@ -99,15 +101,16 @@ public class sigIRC{
final public static int DINGTIMER=150; final public static int DINGTIMER=150;
static boolean dingEnabled=true; static boolean dingEnabled=true;
static int dingThreshold; static int dingThreshold;
static Color backgroundcol; public static Color backgroundcol;
public static BackgroundColorButton button; public static BackgroundColorButton button;
public static JFrame window; public static ProgramWindow window;
static boolean overlayMode=false; public static boolean overlayMode=false;
static boolean showWindowControls=false; public static boolean showWindowControls=false;
static int windowX=0; public static boolean updateAvailable=false;
static int windowY=0; public static int windowX=0;
static int windowWidth=0; public static int windowY=0;
static int windowHeight=0; public static int windowWidth=0;
public static int windowHeight=0;
static int chatRows=3; static int chatRows=3;
static int chatScrollSpd=4; static int chatScrollSpd=4;
static int rowSpacing=64; static int rowSpacing=64;
@ -118,7 +121,7 @@ public class sigIRC{
public static boolean twitchmodule_enabled=true; public static boolean twitchmodule_enabled=true;
public static boolean chatlogmodule_enabled=true; public static boolean chatlogmodule_enabled=true;
static boolean downloadsComplete=false; static boolean downloadsComplete=false;
static boolean hardwareAcceleration=true; public static boolean hardwareAcceleration=true;
static boolean playedoAuthSoundOnce=false; static boolean playedoAuthSoundOnce=false;
public static int twitchmodule_width=500; public static int twitchmodule_width=500;
public static int twitchmodule_height=200; public static int twitchmodule_height=200;
@ -252,6 +255,8 @@ public class sigIRC{
//new IntroDialog(); //new IntroDialog();
loadingdialog = new LoadingDialog(); loadingdialog = new LoadingDialog();
/* /*
DownloadAllRequiredDependencies(); DownloadAllRequiredDependencies();
@ -365,6 +370,7 @@ public class sigIRC{
programFile.delete(); programFile.delete();
} }
org.apache.commons.io.FileUtils.copyURLToFile(new URL(sigIRC.PROGRAM_EXECUTABLE_URL),programFile); org.apache.commons.io.FileUtils.copyURLToFile(new URL(sigIRC.PROGRAM_EXECUTABLE_URL),programFile);
sigIRC.updateAvailable=true;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

@ -11,6 +11,7 @@ import java.io.InputStreamReader;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.Reader; import java.io.Reader;
import java.net.URL; import java.net.URL;
import java.net.UnknownHostException;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
@ -207,18 +208,21 @@ public class FileUtils {
} }
public static JSONObject readJsonFromUrl(String url, String file, boolean writeToFile) throws IOException, JSONException { public static JSONObject readJsonFromUrl(String url, String file, boolean writeToFile) throws IOException, JSONException {
InputStream is = new URL(url).openStream(); InputStream is;
try { try {
is = new URL(url).openStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
String jsonText = readAll(rd); String jsonText = readAll(rd);
if (writeToFile) { if (writeToFile) {
writetoFile(new String[]{jsonText},file); writetoFile(new String[]{jsonText},file);
} }
JSONObject json = new JSONObject(jsonText); JSONObject json = new JSONObject(jsonText);
return json;
} finally {
is.close(); 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 { public static JSONArray readJsonArrayFromUrl(String url, String file, boolean writeToFile) throws IOException, JSONException {

@ -4,6 +4,7 @@ import java.awt.Dimension;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -101,21 +102,26 @@ public class LoadingDialog extends JFrame{
managers.add(new FileManager("sigIRC/rabi-ribi/items/attack_up.png")); managers.add(new FileManager("sigIRC/rabi-ribi/items/attack_up.png"));
} }
JSONObject twitchemotes; if (!sigIRC.offlineMode) {
try { JSONObject twitchemotes;
twitchemotes = FileUtils.readJsonFromUrl("https://twitchemotes.com/api_cache/v3/global.json"); try {
System.out.println("Twitch emote Json read."); twitchemotes = FileUtils.readJsonFromUrl("https://twitchemotes.com/api_cache/v3/global.json");
for (String emotes : twitchemotes.keySet()) { System.out.println("Twitch emote Json read.");
JSONObject emote = twitchemotes.getJSONObject(emotes); if (twitchemotes!=null) {
int id = emote.getInt("id"); for (String emotes : twitchemotes.keySet()) {
String name = emote.getString("code"); JSONObject emote = twitchemotes.getJSONObject(emotes);
LoadingDialog.emotes.add(new TwitchEmoteDownload(name,id)); int id = emote.getInt("id");
managers.add(new FakeFileManager("_FAKE_")); String name = emote.getString("code");
//emoticons.add(new Emoticon(name, new URL(TWITCHEMOTEURL+id+"/1.0"))); LoadingDialog.emotes.add(new TwitchEmoteDownload(name,id));
System.out.println("Emote "+id+" with name "+name); 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); bar.setValue(0);
@ -148,7 +154,9 @@ public class LoadingDialog extends JFrame{
for (TwitchEmoteDownload d : emotes) { for (TwitchEmoteDownload d : emotes) {
try { try {
d.download(); if (!sigIRC.offlineMode) {
d.download();
}
bar.setValue(bar.getValue()+1); bar.setValue(bar.getValue()+1);
UpdateBar(); UpdateBar();
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
@ -156,12 +164,15 @@ public class LoadingDialog extends JFrame{
} }
} }
if (!sigIRC.offlineMode) {
sigIRC.prepareTwitchEmoteUpdate(); sigIRC.prepareTwitchEmoteUpdate();
}
twitchEmoteUpdate.setDone(); twitchEmoteUpdate.setDone();
bar.setValue(bar.getValue()+1); bar.setValue(bar.getValue()+1);
UpdateBar(); UpdateBar();
sigIRC.DownloadProgramUpdate(); if (!sigIRC.offlineMode) {
sigIRC.DownloadProgramUpdate();
}
programUpdate.setDone(); programUpdate.setDone();
bar.setValue(bar.getValue()+1); bar.setValue(bar.getValue()+1);
UpdateBar(); UpdateBar();
@ -186,6 +197,10 @@ public class LoadingDialog extends JFrame{
sigIRC.emoticons.add(new Emoticon(":D","11")); sigIRC.emoticons.add(new Emoticon(":D","11"));
sigIRC.emoticons.add(new Emoticon(">(","12")); sigIRC.emoticons.add(new Emoticon(">(","12"));
sigIRC.emoticons.add(new Emoticon("<3","13")); sigIRC.emoticons.add(new Emoticon("<3","13"));
//Load is done. Start up the panel.
sigIRC.window = new ProgramWindow();
this.setVisible(false);
} }
private void UpdateBar() { private void UpdateBar() {

@ -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<ModuleButton> buttons = new ArrayList<ModuleButton>();
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);
}
}
});
}
}
Loading…
Cancel
Save