Implemented saving and loading of displays.
This commit is contained in:
parent
4d76f9db12
commit
847df8b091
@ -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
|
||||
|
@ -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<String,String> 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;i<labels.length;i++) {
|
||||
if (sb.length()>0) {
|
||||
sb.append("|");
|
||||
}
|
||||
sb.append(labels[i].replaceAll("\\|","").replaceAll("\\*",""));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String interpretLabel(String string){
|
||||
DrawCanvas data = MyRobot.p;
|
||||
try {
|
||||
|
@ -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;i<displaySplit.length;i++) {
|
||||
MyRobot.p.displays.add(
|
||||
new Display(displaySplit[i])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
@ -304,9 +316,21 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
|
||||
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
saveDisplays();
|
||||
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
|
||||
public void windowClosed(WindowEvent e) {
|
||||
}
|
||||
|
@ -507,6 +507,7 @@ public class MyRobot{
|
||||
|
||||
void go() throws FontFormatException, IOException {
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user