Added functionality to check whether changed data is saved when exiting the program

This commit is contained in:
2026-04-10 12:04:01 +03:00
parent 54dbfbabf4
commit fd488d8c9e
3 changed files with 36 additions and 8 deletions

View File

@ -2,23 +2,23 @@
<objecttypes>
<objecttype color="#a0a0a4" name="misato">
<property default="Solid" name="class" type="string"/>
<property default="1 1 201 0 184 189 72 191 " name="drawbox" type="string"/>
<property default="Rectangle -11 10 49 67" name="hitbox" type="string"/>
<property default="3 4 197 3 168 191 72 189 " name="drawbox" type="string"/>
<property default="Circle -19 11 40" name="hitbox" type="string"/>
</objecttype>
<objecttype color="#a0a0a4" name="starlight">
<property default="Solid" name="class" type="string"/>
<property default="4 3 162 9 129 121 53 140 " name="drawbox" type="string"/>
<property default="Rectangle 18 -2 34 108" name="hitbox" type="string"/>
<property default="Circle 14 3 28" name="hitbox" type="string"/>
</objecttype>
<objecttype color="#a0a0a4" name="tavern">
<property default="Solid" name="class" type="string"/>
<property default="93 47 303 55 245 301 90 286 " name="drawbox" type="string"/>
<property default="Circle 4156 2349 85" name="hitbox" type="string"/>
<property default="Rectangle 4036 2332 271 201" name="hitbox" type="string"/>
</objecttype>
<objecttype color="#a0a0a4" name="TopHome">
<property default="Solid" name="class" type="string"/>
<property default="3 2 252 1 253 605 6 608" name="drawbox" type="string"/>
<property default="Rectangle -431 -2181 323 51" name="hitbox" type="string"/>
<property default="Rectangle 2212 1964 183 31" name="hitbox" type="string"/>
</objecttype>
<objecttype color="000000" name="newtest">
<property default="solid" name="class" type="string"/>

View File

@ -6,11 +6,14 @@ import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
@ -34,7 +37,25 @@ public class MainGUI extends JFrame{
setTitle("Hitbox/Drawbox Editor");
setSize(1000,650);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
if(Project.getInstance().changeOfXmlDOM == true) {
int confirmed = JOptionPane.showConfirmDialog(null,
"Сохранить файл перед выходом?", "Выход",
JOptionPane.YES_NO_OPTION);
if (confirmed == JOptionPane.YES_OPTION) {
Project.getInstance().writeXML();
}
}
System.exit(0);
}
});
setLocationRelativeTo(null);
setMinimumSize(new Dimension(800,600));
list = new ListGUI();

View File

@ -52,7 +52,10 @@ public class Project implements Iterable<Entity>, EntityDrawboxChangedListener,
* */
public static final String DEFAULT_XML_PATH = "res/"; //TODO: make an actual path to example objecttypes in the root of the project
public static final String DEFAULT_XML_FILENAME = "objecttypes.xml";
/**
* Переменная которая отслеживает, были ли произведены изменения XML-Dom-дерева.
* */
public static boolean changeOfXmlDOM = false;
static Project thisProject;
private List <Entity> listEntity = new ArrayList<Entity>();
private String path = DEFAULT_XML_PATH;
@ -249,6 +252,7 @@ public class Project implements Iterable<Entity>, EntityDrawboxChangedListener,
hitboxProperty.setAttribute("default", "Rectangle 0 0 0 0"); // empty, no hitbox yet
objecttypeElement.appendChild(hitboxProperty);
changeOfXmlDOM = true;
//printXMlToConsole(); //DEBUG!
}
@ -298,10 +302,11 @@ public class Project implements Iterable<Entity>, EntityDrawboxChangedListener,
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(new FileOutputStream(getXMLPath() + getXMLFileName()));
transformer.transform(source, result);
JOptionPane.showMessageDialog(null, "Бугага, сохранилось!", "Success", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, "Бугагашеньки, сохранилось!", "Success", JOptionPane.INFORMATION_MESSAGE);
} catch (TransformerException | FileNotFoundException e) {
JOptionPane.showMessageDialog(null, "Saving project is unsuccsessfull! Erorr is: "+e, "Project save unsuccsesfull", JOptionPane.ERROR_MESSAGE);
}
changeOfXmlDOM = false;
}
public void PrintEntitys() {
@ -361,6 +366,7 @@ public class Project implements Iterable<Entity>, EntityDrawboxChangedListener,
}
}
}
changeOfXmlDOM = true;
}
/**
@ -381,6 +387,7 @@ public class Project implements Iterable<Entity>, EntityDrawboxChangedListener,
}
}
}
changeOfXmlDOM = true;
}
private Node getEntityXMLNodeByName(String name) { //returns entitie's objecttype node