Implemented saving and loading of displays.

This commit is contained in:
sigonasr2 2020-09-11 16:45:33 +09:00
parent 4d76f9db12
commit 847df8b091
4 changed files with 77 additions and 9 deletions

View File

@ -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 WIDTH 1071
HEIGHT 765 HEIGHT 765
BACKGROUND -6697729 BACKGROUND -6697729
LAST_TEXT -6723841 LAST_TEXT -13369549
LAST_FONT Serif.italic LAST_FONT Microsoft JhengHei UI Bold
LAST_FONTSIZE 32 LAST_FONTSIZE 24
LAST_BACKGROUND -16776961 LAST_BACKGROUND -16776961
LAST_WIDTH 200 LAST_WIDTH 400
LAST_DELAY 10000 LAST_DELAY 300

View File

@ -19,6 +19,23 @@ public class Display {
String currentText; String currentText;
int cycle=0; int cycle=0;
boolean deleted=false; 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() { Display() {
HashMap<String,String> config = MyRobot.p.configData; HashMap<String,String> config = MyRobot.p.configData;
if (config.containsKey("LAST_BACKGROUND")) { if (config.containsKey("LAST_BACKGROUND")) {
@ -104,6 +121,32 @@ public class Display {
g.drawString(currentText,x,y+fontSize); 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;i<labels.length;i++) {
if (sb.length()>0) {
sb.append("|");
}
sb.append(labels[i].replaceAll("\\|","").replaceAll("\\*",""));
}
return sb.toString();
}
private String interpretLabel(String string){ private String interpretLabel(String string){
DrawCanvas data = MyRobot.p; DrawCanvas data = MyRobot.p;
try { try {

View File

@ -84,7 +84,7 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
public static Display selectedDisplay = null; public static Display selectedDisplay = null;
public static Display draggedDisplay = null; public static Display draggedDisplay = null;
DrawCanvas() throws FontFormatException, IOException { DrawCanvas() throws FontFormatException, IOException {
loadConfig(); //loadConfig();
addConfigButton = ImageIO.read(new File("addDisplay.png")); addConfigButton = ImageIO.read(new File("addDisplay.png"));
backgroundColorButton = ImageIO.read(new File("backgroundCol.png")); backgroundColorButton = ImageIO.read(new File("backgroundCol.png"));
Thread t = new Thread() { Thread t = new Thread() {
@ -200,6 +200,18 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
if (MyRobot.p!=null) { if (MyRobot.p!=null) {
MyRobot.p.repaint(0, 0, MyRobot.p.getWidth(),MyRobot.p.getHeight()); 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;i<displaySplit.length;i++) {
MyRobot.p.displays.add(
new Display(displaySplit[i])
);
}
}
} }
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
@ -304,9 +316,21 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
@Override @Override
public void windowClosing(WindowEvent e) { public void windowClosing(WindowEvent e) {
saveDisplays();
saveConfig(); saveConfig();
} }
private void saveDisplays() {
StringBuilder sb = new StringBuilder();
for (int i=0;i<displays.size();i++) {
if (sb.length()>0) {
sb.append("~");
}
sb.append(displays.get(i).getSaveString());
}
configData.put("DISPLAYDATA",sb.toString());
}
@Override @Override
public void windowClosed(WindowEvent e) { public void windowClosed(WindowEvent e) {
} }

View File

@ -506,7 +506,8 @@ public class MyRobot{
} }
void go() throws FontFormatException, IOException { void go() throws FontFormatException, IOException {
initialize(); initialize();
p = new DrawCanvas();
DrawCanvas.loadConfig(); DrawCanvas.loadConfig();
//gotoxy(100, 100); //gotoxy(100, 100);
SCREEN = new Color[SCREEN_X][SCREEN_Y]; SCREEN = new Color[SCREEN_X][SCREEN_Y];
@ -517,7 +518,6 @@ public class MyRobot{
System.setProperty("awt.useSystemAAFontSettings","on"); System.setProperty("awt.useSystemAAFontSettings","on");
FRAME = new JFrame(); FRAME = new JFrame();
FRAME.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); FRAME.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
p = new DrawCanvas();
p.difficulty="EXEX"; p.difficulty="EXEX";
p.songname = "Dear"; p.songname = "Dear";
int condition = JComponent.WHEN_IN_FOCUSED_WINDOW; int condition = JComponent.WHEN_IN_FOCUSED_WINDOW;