From 847df8b0912b282fa0d79c622b34d6a0c3958ab2 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Fri, 11 Sep 2020 16:45:33 +0900 Subject: [PATCH] Implemented saving and loading of displays. --- DivaBot/config.txt | 13 +++++----- DivaBot/src/sig/Display.java | 43 +++++++++++++++++++++++++++++++++ DivaBot/src/sig/DrawCanvas.java | 26 +++++++++++++++++++- DivaBot/src/sig/MyRobot.java | 4 +-- 4 files changed, 77 insertions(+), 9 deletions(-) diff --git a/DivaBot/config.txt b/DivaBot/config.txt index 87d001f..a08df61 100644 --- a/DivaBot/config.txt +++ b/DivaBot/config.txt @@ -1,10 +1,11 @@ -LAST_HEIGHT 48 +DISPLAYDATA -16776961*-13369549*64*Yu Gothic UI Bold*900*90*300*Song Difficulty*24*152*~-16776961*-13369549*24*Microsoft JhengHei UI Bold*400*28*300*Overall Rating|Song Title (Romanized)|Song Title (English)*176*240* +LAST_HEIGHT 28 WIDTH 1071 HEIGHT 765 BACKGROUND -6697729 -LAST_TEXT -6723841 -LAST_FONT Serif.italic -LAST_FONTSIZE 32 +LAST_TEXT -13369549 +LAST_FONT Microsoft JhengHei UI Bold +LAST_FONTSIZE 24 LAST_BACKGROUND -16776961 -LAST_WIDTH 200 -LAST_DELAY 10000 +LAST_WIDTH 400 +LAST_DELAY 300 diff --git a/DivaBot/src/sig/Display.java b/DivaBot/src/sig/Display.java index 895d5cf..fdaab5f 100644 --- a/DivaBot/src/sig/Display.java +++ b/DivaBot/src/sig/Display.java @@ -19,6 +19,23 @@ public class Display { String currentText; int cycle=0; boolean deleted=false; + /** + * Load a display from a save formatted string. + * */ + Display(String loadString) { + this(); + String[] split = loadString.split("\\*"); + backgroundCol=new Color(Integer.parseInt(split[0])); + textCol=new Color(Integer.parseInt(split[1])); + fontSize=Integer.parseInt(split[2]); + font=new Font(split[3],Font.PLAIN,fontSize); + width=Integer.parseInt(split[4]); + height=Integer.parseInt(split[5]); + delay=Integer.parseInt(split[6]); + labels=split[7].split("\\|"); + x=Integer.parseInt(split[8]); + y=Integer.parseInt(split[9]); + } Display() { HashMap config = MyRobot.p.configData; if (config.containsKey("LAST_BACKGROUND")) { @@ -104,6 +121,32 @@ public class Display { g.drawString(currentText,x,y+fontSize); } + public String getSaveString() { + StringBuilder sb = new StringBuilder(); + return sb.append(backgroundCol.getRGB()).append("*") + .append(textCol.getRGB()).append("*") + .append(fontSize).append("*") + .append(font.getFontName()).append("*") + .append(width).append("*") + .append(height).append("*") + .append(delay).append("*") + .append(combineLabels()).append("*") + .append(x).append("*") + .append(y).append("*") + .toString(); + } + + private String combineLabels() { + StringBuilder sb = new StringBuilder(); + for (int i=0;i0) { + sb.append("|"); + } + sb.append(labels[i].replaceAll("\\|","").replaceAll("\\*","")); + } + return sb.toString(); + } + private String interpretLabel(String string){ DrawCanvas data = MyRobot.p; try { diff --git a/DivaBot/src/sig/DrawCanvas.java b/DivaBot/src/sig/DrawCanvas.java index 691c74a..88bc0c5 100644 --- a/DivaBot/src/sig/DrawCanvas.java +++ b/DivaBot/src/sig/DrawCanvas.java @@ -84,7 +84,7 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener, public static Display selectedDisplay = null; public static Display draggedDisplay = null; DrawCanvas() throws FontFormatException, IOException { - loadConfig(); + //loadConfig(); addConfigButton = ImageIO.read(new File("addDisplay.png")); backgroundColorButton = ImageIO.read(new File("backgroundCol.png")); Thread t = new Thread() { @@ -200,6 +200,18 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener, if (MyRobot.p!=null) { MyRobot.p.repaint(0, 0, MyRobot.p.getWidth(),MyRobot.p.getHeight()); } + loadDisplays(); + } + + private static void loadDisplays() { + if (configData.containsKey("DISPLAYDATA")) { + String[] displaySplit = configData.get("DISPLAYDATA").split("~"); + for (int i=0;i0) { + sb.append("~"); + } + sb.append(displays.get(i).getSaveString()); + } + configData.put("DISPLAYDATA",sb.toString()); + } + @Override public void windowClosed(WindowEvent e) { } diff --git a/DivaBot/src/sig/MyRobot.java b/DivaBot/src/sig/MyRobot.java index 72b291f..450fd01 100644 --- a/DivaBot/src/sig/MyRobot.java +++ b/DivaBot/src/sig/MyRobot.java @@ -506,7 +506,8 @@ public class MyRobot{ } void go() throws FontFormatException, IOException { - initialize(); + initialize(); + p = new DrawCanvas(); DrawCanvas.loadConfig(); //gotoxy(100, 100); SCREEN = new Color[SCREEN_X][SCREEN_Y]; @@ -517,7 +518,6 @@ public class MyRobot{ System.setProperty("awt.useSystemAAFontSettings","on"); FRAME = new JFrame(); FRAME.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - p = new DrawCanvas(); p.difficulty="EXEX"; p.songname = "Dear"; int condition = JComponent.WHEN_IN_FOCUSED_WINDOW;