Compare commits
12 Commits
ab30acd69a
...
hitbox-dra
| Author | SHA1 | Date | |
|---|---|---|---|
| 669d26f595 | |||
| fd488d8c9e | |||
| 54dbfbabf4 | |||
| 55aab3cac0 | |||
| f43795e1f4 | |||
| 7e09343035 | |||
| 0545adee2a | |||
| 27bbcee37a | |||
| 58550ae93a | |||
| 6665199d12 | |||
| 2686d036cf | |||
| a0a69c3587 |
BIN
res/NewHueta.png
Normal file
|
After Width: | Height: | Size: 867 B |
BIN
res/circle.png
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 539 B |
BIN
res/destroy.png
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.5 KiB |
BIN
res/destroy1.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
res/iloveimg-resized.zip
Normal file
@ -2,27 +2,27 @@
|
|||||||
<objecttypes>
|
<objecttypes>
|
||||||
<objecttype color="#a0a0a4" name="misato">
|
<objecttype color="#a0a0a4" name="misato">
|
||||||
<property default="Solid" name="class" type="string"/>
|
<property default="Solid" name="class" type="string"/>
|
||||||
<property default="22 10 232 3 264 199 5 198 " name="drawbox" type="string"/>
|
<property default="3 4 197 3 168 191 72 189 " name="drawbox" type="string"/>
|
||||||
<property default="Circle 4 6 24" name="hitbox" type="string"/>
|
<property default="Circle -19 11 40" name="hitbox" type="string"/>
|
||||||
</objecttype>
|
</objecttype>
|
||||||
<objecttype color="#a0a0a4" name="starlight">
|
<objecttype color="#a0a0a4" name="starlight">
|
||||||
<property default="Solid" name="class" type="string"/>
|
<property default="Solid" name="class" type="string"/>
|
||||||
<property default="2 1 253 1 254 468 2 490" name="drawbox" type="string"/>
|
<property default="4 3 162 9 129 121 53 140 " name="drawbox" type="string"/>
|
||||||
<property default="Rectangle 0 0 76 119" name="hitbox" type="string"/>
|
<property default="Circle 14 3 28" name="hitbox" type="string"/>
|
||||||
</objecttype>
|
</objecttype>
|
||||||
<objecttype color="#a0a0a4" name="tavern">
|
<objecttype color="#a0a0a4" name="tavern">
|
||||||
<property default="Solid" name="class" type="string"/>
|
<property default="Solid" name="class" type="string"/>
|
||||||
<property default="3 2 252 1 253 605 6 608" name="drawbox" type="string"/>
|
<property default="93 47 303 55 245 301 90 286 " name="drawbox" type="string"/>
|
||||||
<property default="Rectangle 0 0 96 98" name="hitbox" type="string"/>
|
<property default="Rectangle 4036 2332 271 201" name="hitbox" type="string"/>
|
||||||
</objecttype>
|
</objecttype>
|
||||||
<objecttype color="#a0a0a4" name="TopHome">
|
<objecttype color="#a0a0a4" name="TopHome">
|
||||||
<property default="Solid" name="class" type="string"/>
|
<property default="Solid" name="class" type="string"/>
|
||||||
<property default="3 2 252 1 253 605 6 608" name="drawbox" type="string"/>
|
<property default="3 2 252 1 253 605 6 608" name="drawbox" type="string"/>
|
||||||
<property default="Rectangle 0 0 96 98" name="hitbox" type="string"/>
|
<property default="Rectangle 2212 1964 183 31" name="hitbox" type="string"/>
|
||||||
</objecttype>
|
</objecttype>
|
||||||
<objecttype color="000000" name="newtest">
|
<objecttype color="000000" name="newtest">
|
||||||
<property default="solid" name="class" type="string"/>
|
<property default="solid" name="class" type="string"/>
|
||||||
<property default="0 0 0 0 0 0 0 0" name="drawbox" type="string"/>
|
<property default="252 116 505 120 500 247 235 237 " name="drawbox" type="string"/>
|
||||||
<property default="Rectangle 0 0 0 0" name="hitbox" type="string"/>
|
<property default="Circle 578 671 15" name="hitbox" type="string"/>
|
||||||
</objecttype>
|
</objecttype>
|
||||||
</objecttypes>
|
</objecttypes>
|
||||||
|
|||||||
BIN
res/square.png
|
Before Width: | Height: | Size: 755 B After Width: | Height: | Size: 1.7 KiB |
BIN
res/square1.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
@ -28,47 +28,14 @@ public class DrawboxEditor extends Editable {
|
|||||||
|
|
||||||
DrawboxEditor(ListGUI listGUI) {
|
DrawboxEditor(ListGUI listGUI) {
|
||||||
super(listGUI);
|
super(listGUI);
|
||||||
//Если будет ошибка, попробовать в Editable прокинуть canvas, как сделано с ListGUI
|
|
||||||
canvas = new EditableCanvas(entity, image);
|
canvas = new EditableCanvas();
|
||||||
add(canvas,BorderLayout.CENTER);
|
add(canvas);
|
||||||
canvas.setBackground(Color.GRAY);
|
//canvas.setBackground(Color.GRAY);
|
||||||
canvas.setDrawboxRectengleRenderingFunction();
|
canvas.setDrawboxRectengleRenderingFunction();
|
||||||
canvas.setVisible(true);
|
canvas.setVisible(true);
|
||||||
|
|
||||||
logger.setLevel(Level.CONFIG);
|
logger.setLevel(Level.CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mousePressed(MouseEvent e) {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseMoved(MouseEvent e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void clearPoints(){
|
|
||||||
|
|
||||||
}
|
|
||||||
// эта штука очищает точки при нажатии универскальной кнопки очистки в Main GUI. Это следует рефакторнуть и вместо передачи события сюда,
|
|
||||||
// обрабатывать его прямо в Main GUI(лямбдой) вызывая отсюда только метод в духе clearPoints()
|
|
||||||
/*@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
JTabbedPane parent = (JTabbedPane) getParent();
|
|
||||||
if(parent.getSelectedComponent() == this){
|
|
||||||
if(entity != null) {
|
|
||||||
entity.getDrawbox().getDrawboxlistPoints().clear();
|
|
||||||
entity.getDrawbox().getbaseListPoints().clear();
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
package gui;
|
package gui;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics;
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseListener;
|
import java.awt.event.MouseListener;
|
||||||
@ -11,33 +10,45 @@ import java.awt.image.BufferedImage;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JToolBar;
|
||||||
import javax.swing.event.ListSelectionEvent;
|
import javax.swing.event.ListSelectionEvent;
|
||||||
import javax.swing.event.ListSelectionListener;
|
import javax.swing.event.ListSelectionListener;
|
||||||
|
|
||||||
import model.Entity;
|
import model.Entity;
|
||||||
import repository.Project;
|
import repository.Project;
|
||||||
|
|
||||||
public abstract class Editable extends JPanel implements MouseListener, MouseMotionListener, ListSelectionListener {
|
public abstract class Editable extends JPanel implements ListSelectionListener {
|
||||||
|
|
||||||
protected ListGUI listGUI;
|
protected ListGUI listGUI;
|
||||||
protected Entity entity;
|
protected Entity entity;
|
||||||
protected String selectedEntityName;
|
protected String selectedEntityName;
|
||||||
protected BufferedImage image;
|
protected BufferedImage image;
|
||||||
EditableCanvas canvas;
|
EditableCanvas canvas;
|
||||||
|
JToolBar toolbar = new JToolBar("Toolbar",JToolBar.VERTICAL);
|
||||||
|
JButton clearLinesJButton;
|
||||||
|
|
||||||
private static Logger logger = Logger.getLogger("gui.Editable");
|
private static Logger logger = Logger.getLogger("gui.Editable");
|
||||||
|
|
||||||
|
|
||||||
Editable(ListGUI listGUI){
|
Editable(ListGUI listGUI){
|
||||||
this.listGUI = listGUI;
|
this.listGUI = listGUI;
|
||||||
|
setLayout(new BorderLayout());
|
||||||
|
|
||||||
addMouseListener(this);
|
clearLinesJButton = createButton("Clear lines",null,"res/destroy.png");
|
||||||
addMouseMotionListener(this);
|
clearLinesJButton.addActionListener((e)->{
|
||||||
|
canvas.renderingFunction.functionClearJButton();
|
||||||
|
canvas.repaint();
|
||||||
|
});
|
||||||
|
toolbar.setBorder(BorderFactory.createLoweredBevelBorder());
|
||||||
|
toolbar.addSeparator();
|
||||||
|
toolbar.add(clearLinesJButton);
|
||||||
|
this.add(toolbar,BorderLayout.EAST);
|
||||||
|
toolbar.setPreferredSize(new Dimension(40,40));
|
||||||
// РАСКОММЕНТИТЬ ЕСЛИ НУЖНО ВЫВОДИТЬ ПОДРОБНЫЕ ЛОГИ
|
// РАСКОММЕНТИТЬ ЕСЛИ НУЖНО ВЫВОДИТЬ ПОДРОБНЫЕ ЛОГИ
|
||||||
logger.setLevel(Level.ALL);
|
logger.setLevel(Level.ALL);
|
||||||
}
|
}
|
||||||
@ -58,22 +69,6 @@ public abstract class Editable extends JPanel implements MouseListener, MouseMot
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// из mouse motion listener'a
|
|
||||||
@Override
|
|
||||||
public void mouseDragged(MouseEvent e) {}
|
|
||||||
|
|
||||||
// этих ребят нас обязывает создать MouseListener, так что они здесь
|
|
||||||
@Override
|
|
||||||
public void mouseClicked(MouseEvent e) {}
|
|
||||||
@Override
|
|
||||||
public void mousePressed(MouseEvent e) {}
|
|
||||||
@Override
|
|
||||||
public void mouseEntered(MouseEvent e) {}
|
|
||||||
@Override
|
|
||||||
public void mouseExited(MouseEvent e) {}
|
|
||||||
@Override
|
|
||||||
public void mouseReleased(MouseEvent e) {}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void valueChanged(ListSelectionEvent e) {
|
public void valueChanged(ListSelectionEvent e) {
|
||||||
logger.log(Level.FINEST, "entering method {0} of class {1}", new Object[]{"MouseClicked()" , this.getClass().getName()});
|
logger.log(Level.FINEST, "entering method {0} of class {1}", new Object[]{"MouseClicked()" , this.getClass().getName()});
|
||||||
@ -90,20 +85,22 @@ public abstract class Editable extends JPanel implements MouseListener, MouseMot
|
|||||||
}
|
}
|
||||||
image = Project.getInstance().loadImageByName(selectedEntityName);
|
image = Project.getInstance().loadImageByName(selectedEntityName);
|
||||||
//TODO: if(image == null) вызов FileChooser'a и выбор изображения
|
//TODO: if(image == null) вызов FileChooser'a и выбор изображения
|
||||||
this.repaint();
|
canvas.setEntity(entity);
|
||||||
//canvas.repaint();
|
canvas.setImage(image);
|
||||||
System.out.println(" Edit image = " + image);
|
canvas.repaint();
|
||||||
System.out.println("---");
|
// System.out.println(" Canvas image = " + canvas.image);
|
||||||
System.out.println(" Canvas image = " + image);
|
// System.out.println(" Canvas entity = " + canvas.entity);
|
||||||
|
// System.out.println(" Editable image = " + image);
|
||||||
|
// System.out.println(" Editable entity = " + entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private JButton createButton(String text,ActionListener listener,String pathImage) {
|
JButton createButton(String text,ActionListener listener,String pathImage) {
|
||||||
JButton button = new JButton(new ImageIcon(pathImage));
|
JButton button = new JButton(new ImageIcon(pathImage));
|
||||||
button.addActionListener(listener);
|
button.addActionListener(listener);
|
||||||
button.setContentAreaFilled(false);
|
button.setContentAreaFilled(false);
|
||||||
button.setFocusPainted(false);
|
button.setFocusPainted(false);
|
||||||
button.setPreferredSize(new Dimension(72, 38));
|
button.setPreferredSize(new Dimension(20, 20));
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
package gui;
|
package gui;
|
||||||
|
|
||||||
|
import java.awt.BasicStroke;
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
@ -8,34 +10,41 @@ import java.awt.event.MouseMotionListener;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.event.ListSelectionEvent;
|
|
||||||
import javax.swing.event.ListSelectionListener;
|
|
||||||
|
|
||||||
import gui.render.DrawboxRectengleRenderingFunction;
|
import gui.render.DrawboxRectengleRenderingFunction;
|
||||||
|
import gui.render.HitboxCircleRenderingFunction;
|
||||||
|
import gui.render.HitboxRectengleRenderingFunction;
|
||||||
import gui.render.ShapeRenderingFunction;
|
import gui.render.ShapeRenderingFunction;
|
||||||
import model.Entity;
|
import model.Entity;
|
||||||
import repository.Project;
|
import repository.Project;
|
||||||
|
|
||||||
public class EditableCanvas extends JPanel implements MouseListener, MouseMotionListener, ListSelectionListener {
|
public class EditableCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
||||||
|
|
||||||
DrawboxRectengleRenderingFunction drawboxRectengleRenderFunct;
|
DrawboxRectengleRenderingFunction drawboxRectengleRenderFunct;
|
||||||
|
HitboxRectengleRenderingFunction hitboxRectengleRenderFunct;
|
||||||
|
HitboxCircleRenderingFunction hitboxCircleRenderFunct;
|
||||||
ShapeRenderingFunction renderingFunction;
|
ShapeRenderingFunction renderingFunction;
|
||||||
Entity entity;
|
Entity entity;
|
||||||
BufferedImage image;
|
BufferedImage image;
|
||||||
|
|
||||||
|
|
||||||
public EditableCanvas(Entity entity, BufferedImage image) {
|
public EditableCanvas() {
|
||||||
this.entity = entity;
|
drawboxRectengleRenderFunct = new DrawboxRectengleRenderingFunction();
|
||||||
this.image = image;
|
hitboxRectengleRenderFunct = new HitboxRectengleRenderingFunction();
|
||||||
drawboxRectengleRenderFunct = new DrawboxRectengleRenderingFunction(entity);
|
hitboxCircleRenderFunct = new HitboxCircleRenderingFunction();
|
||||||
drawboxRectengleRenderFunct.subscribe(Project.getInstance()); // подписка: Project получит данные ввиде обьекта Event, содержащий данные drawbox при отрисовке последней точки из 4-х.
|
drawboxRectengleRenderFunct.subscribe(Project.getInstance()); // подписка: Project получит данные ввиде обьекта Event, содержащий данные drawbox при отрисовке последней точки из 4-х.
|
||||||
//hitboxPanel.subscribe(Project.getInstance());
|
hitboxRectengleRenderFunct.subscribe(Project.getInstance());
|
||||||
|
hitboxCircleRenderFunct.subscribe(Project.getInstance());
|
||||||
|
addMouseListener(this);
|
||||||
|
addMouseMotionListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HitboxRectengleRenderingFunction getHitboxRectengleRenderFunct() {
|
||||||
|
return hitboxRectengleRenderFunct;
|
||||||
|
}
|
||||||
|
|
||||||
public void drawing(Graphics2D g) {
|
public void drawing(Graphics2D g) {
|
||||||
if(renderingFunction!=null) {
|
if(renderingFunction!=null&&entity!=null) {
|
||||||
renderingFunction.drawing(g);
|
renderingFunction.drawing(g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -43,25 +52,29 @@ public class EditableCanvas extends JPanel implements MouseListener, MouseMotion
|
|||||||
public void setDrawboxRectengleRenderingFunction() {
|
public void setDrawboxRectengleRenderingFunction() {
|
||||||
renderingFunction = drawboxRectengleRenderFunct;
|
renderingFunction = drawboxRectengleRenderFunct;
|
||||||
}
|
}
|
||||||
|
public void setHitboxRectengleRenderingFunction() {
|
||||||
|
renderingFunction = hitboxRectengleRenderFunct;
|
||||||
|
}
|
||||||
|
public void setHitboxCircleRenderingFunction() {
|
||||||
|
renderingFunction = hitboxCircleRenderFunct;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseMoved(MouseEvent e) {
|
public void mouseMoved(MouseEvent e) {
|
||||||
if(renderingFunction!=null) {
|
//System.out.println("moved");
|
||||||
|
if(renderingFunction!=null&&entity!=null) {
|
||||||
|
//System.out.println("x="+e.getX()+"y="+e.getY());
|
||||||
renderingFunction.mouseMoved(e);
|
renderingFunction.mouseMoved(e);
|
||||||
}
|
repaint();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseClicked(MouseEvent e) {
|
|
||||||
if(renderingFunction!=null) {
|
|
||||||
renderingFunction.mouseClicked(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
if(renderingFunction!=null) {
|
//System.out.println("mousePressed");
|
||||||
|
if(renderingFunction!=null&&entity!=null) {
|
||||||
renderingFunction.mousePressed(e);
|
renderingFunction.mousePressed(e);
|
||||||
|
repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,15 +82,32 @@ public class EditableCanvas extends JPanel implements MouseListener, MouseMotion
|
|||||||
@Override
|
@Override
|
||||||
protected void paintComponent(Graphics g) {
|
protected void paintComponent(Graphics g) {
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
|
if(image!=null) {
|
||||||
g.drawImage(image, 0, 0, this);
|
g.drawImage(image, 0, 0, this);
|
||||||
|
g.setColor(Color.darkGray);
|
||||||
|
g.drawRect(0, 0, image.getWidth(), image.getHeight());
|
||||||
|
g.setColor(Color.RED);
|
||||||
|
g.fillOval(image.getWidth()/2, image.getHeight(), 2, 2);
|
||||||
|
g.setColor(Color.green);
|
||||||
|
}
|
||||||
if(entity != null) {
|
if(entity != null) {
|
||||||
drawing((Graphics2D)g);
|
drawing((Graphics2D)g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEntity(Entity e) {
|
||||||
|
entity = e;
|
||||||
|
drawboxRectengleRenderFunct.setEntityInDrawboxRectengle(e);
|
||||||
|
hitboxRectengleRenderFunct.setEntityInHitboxRectengle(e);
|
||||||
|
hitboxCircleRenderFunct.setEntityInHitboxCircle(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImage(BufferedImage image) {
|
||||||
|
this.image = image;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {}
|
||||||
@Override
|
@Override
|
||||||
public void mouseDragged(MouseEvent e) {}
|
public void mouseDragged(MouseEvent e) {}
|
||||||
@Override
|
@Override
|
||||||
@ -86,11 +116,7 @@ public class EditableCanvas extends JPanel implements MouseListener, MouseMotion
|
|||||||
public void mouseEntered(MouseEvent e) {}
|
public void mouseEntered(MouseEvent e) {}
|
||||||
@Override
|
@Override
|
||||||
public void mouseExited(MouseEvent e) {}
|
public void mouseExited(MouseEvent e) {}
|
||||||
@Override
|
|
||||||
public void valueChanged(ListSelectionEvent e) {
|
|
||||||
//this.repaint();
|
|
||||||
//System.out.println(" Canvas image = " + image);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,117 +6,91 @@ import java.awt.event.MouseEvent;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JList;
|
||||||
import javax.swing.JTabbedPane;
|
import javax.swing.JTabbedPane;
|
||||||
|
import javax.swing.event.ListSelectionEvent;
|
||||||
|
|
||||||
import events.EntityDrawboxChangedEvent;
|
import events.EntityDrawboxChangedEvent;
|
||||||
import events.EntityDrawboxChangedListener;
|
import events.EntityDrawboxChangedListener;
|
||||||
import events.EntityHitboxChangedEvent;
|
import events.EntityHitboxChangedEvent;
|
||||||
import events.EntityHitboxChangedListener;
|
import events.EntityHitboxChangedListener;
|
||||||
import model.Hitbox;
|
import model.Hitbox;
|
||||||
|
import model.HitboxCircle;
|
||||||
|
import model.HitboxRectangle;
|
||||||
import model.Point;
|
import model.Point;
|
||||||
|
import repository.Project;
|
||||||
|
|
||||||
|
|
||||||
public class HitboxEditor extends Editable {
|
public class HitboxEditor extends Editable {
|
||||||
Point firstIsoPoint = null;
|
|
||||||
Point currentIsoPoint = new Point(0,0);
|
JButton changeInRectangleHitboxJButton;
|
||||||
Point firstCartesianPoint = new Point(0,0), currentCartesianPoint = new Point(0,0);
|
JButton changeInCircleHitboxJButton;
|
||||||
private List<EntityHitboxChangedListener> listeners = new ArrayList<>();
|
|
||||||
|
|
||||||
HitboxEditor(ListGUI listGUI) {
|
HitboxEditor(ListGUI listGUI) {
|
||||||
super(listGUI);
|
super(listGUI);
|
||||||
|
|
||||||
|
canvas = new EditableCanvas();
|
||||||
|
add(canvas);
|
||||||
|
canvas.setHitboxRectengleRenderingFunction();
|
||||||
|
canvas.setVisible(true);
|
||||||
|
|
||||||
|
changeInRectangleHitboxJButton = super.createButton("Hitbox Rectangle",null,"res/square.png");
|
||||||
|
changeInCircleHitboxJButton = super.createButton("Hitbox circle",null,"res/circle.png");
|
||||||
|
toolbar.add(changeInRectangleHitboxJButton);
|
||||||
|
toolbar.add(changeInCircleHitboxJButton);
|
||||||
|
|
||||||
|
changeInRectangleHitboxJButton.addActionListener((e)->{
|
||||||
|
functionClearHitboxJButton();
|
||||||
|
entity.setHitbox(new HitboxRectangle("Rectangle",entity));
|
||||||
|
canvas.setHitboxRectengleRenderingFunction();
|
||||||
|
//Сделать создание нового Hitbox формы Rectengle
|
||||||
|
});
|
||||||
|
changeInCircleHitboxJButton.addActionListener((e)->{
|
||||||
|
functionClearHitboxJButton();
|
||||||
|
entity.setHitbox(new HitboxCircle("Circle",entity));
|
||||||
|
canvas.setHitboxCircleRenderingFunction();
|
||||||
|
//Сделать создание нового Hitbox формы Circle
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public void functionClearHitboxJButton() {
|
||||||
//@Override
|
|
||||||
//public void drawing(Graphics2D g) {
|
|
||||||
/*Hitbox nowHitbox = entity.getHitbox();
|
|
||||||
//if(firstIsoPoint != null) {
|
|
||||||
int x1,y1,x2,y2;
|
|
||||||
int size = nowHitbox.getListPointsIso().size();
|
|
||||||
for(int i = 0; i < size;i++) {
|
|
||||||
x1 = (int)nowHitbox.getListPointsIso().get(i % size).x;
|
|
||||||
y1 = (int)nowHitbox.getListPointsIso().get(i % size).y;
|
|
||||||
x2 = (int)nowHitbox.getListPointsIso().get((i+1) % size).x;
|
|
||||||
y2 = (int)nowHitbox.getListPointsIso().get((i+1) % size).y;
|
|
||||||
g.drawLine(x1, y1, x2, y2);
|
|
||||||
}
|
|
||||||
x1 = (int)nowHitbox.getListPointsIso().get(0).x;
|
|
||||||
y1 = (int)nowHitbox.getListPointsIso().get(0).y;
|
|
||||||
x2 = (int)nowHitbox.getListPointsIso().get(3).x;
|
|
||||||
y2 = (int)nowHitbox.getListPointsIso().get(3).y;
|
|
||||||
g.drawLine(x1, y1, x2, y2);
|
|
||||||
//}
|
|
||||||
*/
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseClicked(MouseEvent e) {
|
|
||||||
if(firstIsoPoint == null) {
|
|
||||||
firstIsoPoint = new Point(currentIsoPoint.x,currentIsoPoint.y);
|
|
||||||
//System.out.println("firstPoint("+firstIsoPoint.x+";"+firstIsoPoint.y+");");
|
|
||||||
firstCartesianPoint = Hitbox.isometricToCartesian(firstIsoPoint.x, firstIsoPoint.y,firstCartesianPoint);
|
|
||||||
}else{
|
|
||||||
/*
|
|
||||||
* В данном месте при нажатии закрепляющей точки, необходимо вызывать функцию,
|
|
||||||
* которая будет формировать из текущих декартовых координат:
|
|
||||||
* 1. Точку старта и ширину с высотой.
|
|
||||||
* 2. Так же необходимо реализовать слушатель сохранения новых хитбоксов в дерево.
|
|
||||||
*
|
|
||||||
* */
|
|
||||||
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseMoved(MouseEvent e) {
|
|
||||||
/*currentIsoPoint.x = e.getX();
|
|
||||||
currentIsoPoint.y = e.getY();
|
|
||||||
if(entity != null) {
|
if(entity != null) {
|
||||||
Hitbox nowHitbox = entity.getHitbox();
|
canvas.renderingFunction.functionClearJButton();
|
||||||
if(firstIsoPoint != null) {
|
canvas.repaint();
|
||||||
//System.out.println("firstPoint("+firstIsoPoint.x+";"+firstIsoPoint.y+");");
|
|
||||||
currentCartesianPoint = Hitbox.isometricToCartesian(currentIsoPoint.x, currentIsoPoint.y, currentCartesianPoint);
|
|
||||||
nowHitbox.getListPointsCartesian().get(0).setXY(firstCartesianPoint.x, firstCartesianPoint.y);
|
|
||||||
nowHitbox.getListPointsCartesian().get(1).setXY(currentCartesianPoint.x, firstCartesianPoint.y);
|
|
||||||
nowHitbox.getListPointsCartesian().get(2).setXY(currentCartesianPoint.x, currentCartesianPoint.y);
|
|
||||||
nowHitbox.getListPointsCartesian().get(3).setXY(firstCartesianPoint.x, currentCartesianPoint.y);
|
|
||||||
nowHitbox.convertCartesianPointsToIso();
|
|
||||||
repaint();
|
|
||||||
}
|
}
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
public void subscribe(EntityHitboxChangedListener listener) {
|
|
||||||
listeners.add(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void unsubscribe(EntityHitboxChangedListener listener) {
|
|
||||||
listeners.remove(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
//НАДО ДОБАВИТЬ ЧТО БЫ ПОД КОНЕЦ РИСОВАНИЯ ХИТБОКСА ОНО ВЫЗЫВАЛО ФУНКЦИЮ И ВСЕ СОХРАНЯЛО.
|
//НАДО ДОБАВИТЬ ЧТО БЫ ПОД КОНЕЦ РИСОВАНИЯ ХИТБОКСА ОНО ВЫЗЫВАЛО ФУНКЦИЮ И ВСЕ СОХРАНЯЛО.
|
||||||
//СОХРАНЕНИЕ УЖЕ РЕАЛИЗОВАНО.
|
//СОХРАНЕНИЕ УЖЕ РЕАЛИЗОВАНО.
|
||||||
//НО НЕ ДОБАВЛЕН ВЫЗОВ ФУНКЦИИ И НЕ ОФОРМЛЕНА ПОДПИСКА
|
//НО НЕ ДОБАВЛЕН ВЫЗОВ ФУНКЦИИ И НЕ ОФОРМЛЕНА ПОДПИСКА
|
||||||
//UPD: вроде подписку оформил в MainGUI;
|
//UPD: вроде подписку оформил в MainGUI;
|
||||||
|
@Override
|
||||||
|
public void valueChanged(ListSelectionEvent e) {
|
||||||
|
if(e.getSource() instanceof JList) {
|
||||||
|
//TODO: надо бы элегантнее пробросить сюда ListGUI - просто передача его в аргументах немножко громоздкая
|
||||||
|
// как-то обыграть это через события?
|
||||||
|
// ps. попытки обратиться к eventSource проваливаются - ListGUI это панель, уже внутри которой лежит JList
|
||||||
|
selectedEntityName = listGUI.getSelectedName();
|
||||||
|
try {
|
||||||
|
entity = Project.getInstance().getEntityByName(selectedEntityName);
|
||||||
|
image = Project.getInstance().loadImageByName(selectedEntityName);
|
||||||
|
//TODO: if(image == null) вызов FileChooser'a и выбор изображения
|
||||||
|
canvas.setEntity(entity);
|
||||||
|
canvas.setImage(image);
|
||||||
|
if(entity.getHitbox().getShape().equals("Rectangle")) {
|
||||||
|
canvas.setHitboxRectengleRenderingFunction();
|
||||||
|
}
|
||||||
|
if(entity.getHitbox().getShape().equals("Circle")) {
|
||||||
|
canvas.setHitboxCircleRenderingFunction();
|
||||||
|
}
|
||||||
|
} catch (Exception e1) {
|
||||||
|
//logger.severe("Entity with name '"+selectedEntityName+"' was not found! Cannot display it on panel!");
|
||||||
|
}
|
||||||
|
|
||||||
private void notifySubscribers() {
|
canvas.repaint();
|
||||||
for (EntityHitboxChangedListener listener : listeners) {
|
|
||||||
listener.hitboxChanged(
|
|
||||||
new EntityHitboxChangedEvent(entity.getHitbox(), entity)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//это старая очистка которая пока убрана. В будущем будет убрана вовсе, после рефакторинга.
|
|
||||||
/*@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
JTabbedPane parent = (JTabbedPane) getParent();
|
|
||||||
if(parent.getSelectedComponent() == this){
|
|
||||||
if(entity != null) {
|
|
||||||
firstIsoPoint = null;
|
|
||||||
currentIsoPoint.setXY(0,0);
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,11 +6,14 @@ import java.awt.FlowLayout;
|
|||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JTabbedPane;
|
import javax.swing.JTabbedPane;
|
||||||
|
|
||||||
@ -24,7 +27,7 @@ public class MainGUI extends JFrame{
|
|||||||
ActionListener OpenXMLFileButtonListener;
|
ActionListener OpenXMLFileButtonListener;
|
||||||
JButton openXMLJButton;
|
JButton openXMLJButton;
|
||||||
JButton saveXMLJButton;
|
JButton saveXMLJButton;
|
||||||
JButton clearLinesJButton;
|
|
||||||
public static JTabbedPane editorPane;
|
public static JTabbedPane editorPane;
|
||||||
DrawboxEditor drawBoxPanel;
|
DrawboxEditor drawBoxPanel;
|
||||||
HitboxEditor hitboxPanel;
|
HitboxEditor hitboxPanel;
|
||||||
@ -34,7 +37,25 @@ public class MainGUI extends JFrame{
|
|||||||
|
|
||||||
setTitle("Hitbox/Drawbox Editor");
|
setTitle("Hitbox/Drawbox Editor");
|
||||||
setSize(1000,650);
|
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);
|
setLocationRelativeTo(null);
|
||||||
setMinimumSize(new Dimension(800,600));
|
setMinimumSize(new Dimension(800,600));
|
||||||
list = new ListGUI();
|
list = new ListGUI();
|
||||||
@ -50,7 +71,6 @@ public class MainGUI extends JFrame{
|
|||||||
|
|
||||||
openXMLJButton = createButton("XML", OpenXMLFileButtonListener,"res/xml.png");
|
openXMLJButton = createButton("XML", OpenXMLFileButtonListener,"res/xml.png");
|
||||||
saveXMLJButton = createButton("Save",(e)-> Project.getInstance().writeXML(),"res/download.png");
|
saveXMLJButton = createButton("Save",(e)-> Project.getInstance().writeXML(),"res/download.png");
|
||||||
clearLinesJButton = createButton("Clear lines",null,"res/destroy.png");
|
|
||||||
|
|
||||||
gridButtonBar.add(openXMLJButton);
|
gridButtonBar.add(openXMLJButton);
|
||||||
gridButtonBar.add(saveXMLJButton);
|
gridButtonBar.add(saveXMLJButton);
|
||||||
@ -59,16 +79,12 @@ public class MainGUI extends JFrame{
|
|||||||
TopButtonBar.setBorder(BorderFactory.createLoweredBevelBorder());
|
TopButtonBar.setBorder(BorderFactory.createLoweredBevelBorder());
|
||||||
add(TopButtonBar,BorderLayout.NORTH);
|
add(TopButtonBar,BorderLayout.NORTH);
|
||||||
|
|
||||||
//clearLinesJButton.addActionListener(drawBoxPanel); - ранее регистрировались слушатели для кнопки очистки.
|
|
||||||
//clearLinesJButton.addActionListener(hitboxPanel);
|
|
||||||
|
|
||||||
|
|
||||||
editorPane = new JTabbedPane();
|
editorPane = new JTabbedPane();
|
||||||
editorPane.setVisible(true);
|
editorPane.setVisible(true);
|
||||||
add(editorPane,BorderLayout.CENTER);
|
add(editorPane,BorderLayout.CENTER);
|
||||||
|
|
||||||
editorPane.addTab("Hitbox", hitboxPanel);
|
|
||||||
editorPane.addTab("Drawbox", drawBoxPanel);
|
editorPane.addTab("Drawbox", drawBoxPanel);
|
||||||
|
editorPane.addTab("Hitbox", hitboxPanel);
|
||||||
repaint();
|
repaint();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import events.EntityDrawboxChangedEvent;
|
|||||||
import events.EntityDrawboxChangedListener;
|
import events.EntityDrawboxChangedListener;
|
||||||
import model.Drawbox;
|
import model.Drawbox;
|
||||||
import model.Entity;
|
import model.Entity;
|
||||||
|
import model.HitboxRectangle;
|
||||||
import model.Point;
|
import model.Point;
|
||||||
|
|
||||||
public class DrawboxRectengleRenderingFunction implements ShapeRenderingFunction {
|
public class DrawboxRectengleRenderingFunction implements ShapeRenderingFunction {
|
||||||
@ -21,8 +22,8 @@ public class DrawboxRectengleRenderingFunction implements ShapeRenderingFunction
|
|||||||
private List<EntityDrawboxChangedListener> listeners = new ArrayList<>();
|
private List<EntityDrawboxChangedListener> listeners = new ArrayList<>();
|
||||||
Entity entity;
|
Entity entity;
|
||||||
Logger logger = Logger.getLogger("gui.DrawboxRectangleEditor");
|
Logger logger = Logger.getLogger("gui.DrawboxRectangleEditor");
|
||||||
public DrawboxRectengleRenderingFunction(Entity entity) {
|
public DrawboxRectengleRenderingFunction() {
|
||||||
this.entity = entity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -84,11 +85,6 @@ public class DrawboxRectengleRenderingFunction implements ShapeRenderingFunction
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseClicked(MouseEvent e) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseMoved(MouseEvent e) {
|
public void mouseMoved(MouseEvent e) {
|
||||||
@ -147,4 +143,13 @@ public class DrawboxRectengleRenderingFunction implements ShapeRenderingFunction
|
|||||||
entity.setDrawbox(new Drawbox(drawboxPoints));
|
entity.setDrawbox(new Drawbox(drawboxPoints));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEntityInDrawboxRectengle(Entity e) {
|
||||||
|
entity = e;
|
||||||
|
}
|
||||||
|
public void functionClearJButton() {
|
||||||
|
if(entity != null) {
|
||||||
|
entity.getDrawbox().getDrawboxlistPoints().clear();
|
||||||
|
entity.getDrawbox().getbaseListPoints().clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,31 +2,100 @@ package gui.render;
|
|||||||
|
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import events.EntityHitboxChangedEvent;
|
||||||
|
import events.EntityHitboxChangedListener;
|
||||||
|
import model.Entity;
|
||||||
|
import model.HitboxCircle;
|
||||||
|
import model.Point;
|
||||||
|
|
||||||
public class HitboxCircleRenderingFunction implements ShapeRenderingFunction {
|
public class HitboxCircleRenderingFunction implements ShapeRenderingFunction {
|
||||||
|
Point firstIsoPoint = null;
|
||||||
|
Point currentIsoPoint = new Point(0,0);
|
||||||
|
int currentDiametrX=0;
|
||||||
|
Entity entity;
|
||||||
|
private List<EntityHitboxChangedListener> listeners = new ArrayList<>();
|
||||||
|
|
||||||
|
public void setEntityInHitboxCircle(Entity e) {
|
||||||
|
entity = e;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawing(Graphics2D g) {
|
public void drawing(Graphics2D g) {
|
||||||
// TODO Auto-generated method stub
|
HitboxCircle nowHitbox = (HitboxCircle)entity.getHitbox();
|
||||||
|
if(nowHitbox.getRadius()!=0) {
|
||||||
|
g.drawOval((int)nowHitbox.getCurrentRefPoint().x, (int)(nowHitbox.getCurrentRefPoint().y-(nowHitbox.getDiametrY()/2)), (int)nowHitbox.getDiametrX(), (int)(nowHitbox.getDiametrY()));
|
||||||
|
// System.out.println("READY: diametrX = "+nowHitbox.getDiametrX()+ ". diametrY = "+nowHitbox.getDiametrY());
|
||||||
|
// System.out.println("READY: coordX = "+(int)nowHitbox.getCurrentRefPoint().x+ ". coordY = "+(int)(nowHitbox.getCurrentRefPoint().y-(nowHitbox.getDiametrY()/2)));
|
||||||
|
|
||||||
|
}else if(firstIsoPoint != null) {
|
||||||
|
currentDiametrX = Math.abs((int)firstIsoPoint.x-(int)currentIsoPoint.x);
|
||||||
|
// System.out.println("CURRENT: coordX = "+(int)firstIsoPoint.x+ ". coordX = "+(int)(firstIsoPoint.y-currentDiametrX/4));
|
||||||
|
// System.out.println("CURRENT: diametrX = "+currentDiametrX+ ". diametrY = "+currentDiametrX/2);
|
||||||
|
g.drawOval((int)firstIsoPoint.x, (int)(firstIsoPoint.y-currentDiametrX/4), (int)currentDiametrX, (int)currentDiametrX/2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
// TODO Auto-generated method stub
|
HitboxCircle nowHitbox = (HitboxCircle)entity.getHitbox();
|
||||||
|
if(nowHitbox.getRadius()==0 && firstIsoPoint == null) {
|
||||||
|
firstIsoPoint = new Point(e.getX(), e.getY());
|
||||||
|
}else if(nowHitbox.getRadius()==0 && firstIsoPoint != null) {
|
||||||
|
//Формула высчитывания радиуса из диаметров circle.
|
||||||
|
nowHitbox.getCurrentRefPoint().setXY(firstIsoPoint.x, firstIsoPoint.y);
|
||||||
|
nowHitbox.setDiametrXY(Math.abs(firstIsoPoint.x-e.getX()),Math.abs((firstIsoPoint.x-e.getX())/2));
|
||||||
|
System.out.println("X = "+nowHitbox.getDiametrX()+ ". Y = "+nowHitbox.getDiametrY());
|
||||||
|
float temp = (float)Math.sqrt(2);
|
||||||
|
nowHitbox.setRadius((nowHitbox.getDiametrY()/2)*temp);
|
||||||
|
// высчитываем в параметры хитбокссеркла нужный радиус и текущую реф поинт.
|
||||||
|
// Не забываем высчитать реф поинт хитбокса относительно текущей.
|
||||||
|
// после чего вызываем listPointsToString и нотифай, который отправляет данные на сохранение
|
||||||
|
notifySubscribers();
|
||||||
|
//возвращаем локальные данные текущего рисования хитбокса в нулевые значения.
|
||||||
|
//необходимо, что бы при переходе в новый обьект, при создании хитбокса, очистился кэш канваса.
|
||||||
|
firstIsoPoint = null;
|
||||||
|
currentDiametrX = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseClicked(MouseEvent e) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseMoved(MouseEvent e) {
|
public void mouseMoved(MouseEvent e) {
|
||||||
// TODO Auto-generated method stub
|
currentIsoPoint.x = e.getX();
|
||||||
|
currentIsoPoint.y = e.getY();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void functionClearHitboxJButton() {
|
||||||
|
HitboxCircle nowHitbox = (HitboxCircle)entity.getHitbox();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void functionClearJButton() {
|
||||||
|
firstIsoPoint = null;
|
||||||
|
currentIsoPoint = new Point(0,0);
|
||||||
|
currentDiametrX = 0;
|
||||||
|
HitboxCircle nowhitbox = (HitboxCircle)entity.getHitbox();
|
||||||
|
nowhitbox.setRadius(0);
|
||||||
|
System.err.println("radius: "+nowhitbox.getRadius());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void subscribe(EntityHitboxChangedListener listener) {
|
||||||
|
listeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unsubscribe(EntityHitboxChangedListener listener) {
|
||||||
|
listeners.remove(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void notifySubscribers() {
|
||||||
|
for (EntityHitboxChangedListener listener : listeners) {
|
||||||
|
listener.hitboxChanged(
|
||||||
|
new EntityHitboxChangedEvent(entity.getHitbox(), entity)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,31 +2,161 @@ package gui.render;
|
|||||||
|
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.time.LocalTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import events.EntityHitboxChangedEvent;
|
||||||
|
import events.EntityHitboxChangedListener;
|
||||||
|
import model.Entity;
|
||||||
|
import model.Hitbox;
|
||||||
|
import model.HitboxRectangle;
|
||||||
|
import model.Point;
|
||||||
|
|
||||||
public class HitboxRectengleRenderingFunction implements ShapeRenderingFunction {
|
public class HitboxRectengleRenderingFunction implements ShapeRenderingFunction {
|
||||||
|
|
||||||
|
Point firstIsoPoint = null;
|
||||||
|
Point currentIsoPoint = new Point(0,0);
|
||||||
|
Point firstCartesianPoint = new Point(0,0), currentCartesianPoint = new Point(0,0);
|
||||||
|
private List<EntityHitboxChangedListener> listeners = new ArrayList<>();
|
||||||
|
Entity entity;
|
||||||
|
private List<Point> LocalListPointsIso = new ArrayList<Point>();
|
||||||
|
private List<Point> LocalListPointsCartesian = new ArrayList<Point>();
|
||||||
|
|
||||||
|
public List<Point> getLocalListPointsIso() {
|
||||||
|
return LocalListPointsIso;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Point> getLocalListPointsCartesian() {
|
||||||
|
return LocalListPointsCartesian;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setFirstIsoPointIsNull(){
|
||||||
|
firstIsoPoint = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawing(Graphics2D g) {
|
public void drawing(Graphics2D g) {
|
||||||
// TODO Auto-generated method stub
|
HitboxRectangle nowHitbox = (HitboxRectangle)entity.getHitbox();
|
||||||
|
int x1,y1,x2,y2;
|
||||||
|
if(nowHitbox.getListPointsIso().size() == 4) {
|
||||||
|
drawingLinesFromListPoints(nowHitbox.getListPointsIso(),g);
|
||||||
|
}
|
||||||
|
if(firstIsoPoint!=null&&nowHitbox.getListPointsIso().size() == 0) {
|
||||||
|
drawingLinesFromListPoints(LocalListPointsIso,g);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void drawingLinesFromListPoints(List<Point> listPointsIso, Graphics2D g) {
|
||||||
|
int x1,y1,x2,y2;
|
||||||
|
int size = listPointsIso.size();
|
||||||
|
for(int i = 0; i < size;i++) {
|
||||||
|
x1 = (int)listPointsIso.get(i % size).x;
|
||||||
|
y1 = (int)listPointsIso.get(i % size).y;
|
||||||
|
x2 = (int)listPointsIso.get((i+1) % size).x;
|
||||||
|
y2 = (int)listPointsIso.get((i+1) % size).y;
|
||||||
|
g.drawLine(x1, y1, x2, y2);
|
||||||
|
}
|
||||||
|
x1 = (int)listPointsIso.get(0).x;
|
||||||
|
y1 = (int)listPointsIso.get(0).y;
|
||||||
|
x2 = (int)listPointsIso.get(3).x;
|
||||||
|
y2 = (int)listPointsIso.get(3).y;
|
||||||
|
g.drawLine(x1, y1, x2, y2);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
// TODO Auto-generated method stub
|
//System.out.println("mousePressed");
|
||||||
|
//System.out.println("mouseClicked");
|
||||||
|
HitboxRectangle nowHitbox = (HitboxRectangle)entity.getHitbox();
|
||||||
|
if(nowHitbox.getListPointsIso().size() == 0 && firstIsoPoint == null) {
|
||||||
|
initListsPoints();
|
||||||
|
firstIsoPoint = new Point(currentIsoPoint.x,currentIsoPoint.y);
|
||||||
|
LocalListPointsIso.get(0).setXY(firstIsoPoint.x, firstIsoPoint.y);
|
||||||
|
firstCartesianPoint = Hitbox.isometricToCartesian(firstIsoPoint.x, firstIsoPoint.y,firstCartesianPoint);
|
||||||
|
LocalListPointsCartesian.get(0).setXY(firstCartesianPoint.x, firstCartesianPoint.y);
|
||||||
|
System.out.println("mouseClicked Event 1 TIME: "+LocalTime.now());
|
||||||
|
}else if(nowHitbox.getListPointsIso().size() == 0 && firstIsoPoint != null) {
|
||||||
|
nowHitbox.getListPointsIso().addAll(LocalListPointsIso);
|
||||||
|
nowHitbox.getListPointsCartesian().addAll(LocalListPointsCartesian);
|
||||||
|
System.out.println("mouseClicked Event 2 TIME: "+LocalTime.now());
|
||||||
|
|
||||||
|
notifySubscribers();
|
||||||
|
//очистка кэша
|
||||||
|
firstIsoPoint = null;
|
||||||
|
LocalListPointsIso.clear();
|
||||||
|
LocalListPointsCartesian.clear();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseClicked(MouseEvent e) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseMoved(MouseEvent e) {
|
public void mouseMoved(MouseEvent e) {
|
||||||
// TODO Auto-generated method stub
|
currentIsoPoint.x = e.getX();
|
||||||
|
currentIsoPoint.y = e.getY();
|
||||||
|
HitboxRectangle nowHitbox = (HitboxRectangle)entity.getHitbox();
|
||||||
|
if(entity!=null) {
|
||||||
|
if(firstIsoPoint != null && nowHitbox.getListPointsIso().size() == 0) {
|
||||||
|
//System.out.println("firstPoint("+firstIsoPoint.x+";"+firstIsoPoint.y+");");
|
||||||
|
currentCartesianPoint = Hitbox.isometricToCartesian(currentIsoPoint.x, currentIsoPoint.y, currentCartesianPoint);
|
||||||
|
LocalListPointsCartesian.get(0).setXY(firstCartesianPoint.x, firstCartesianPoint.y);
|
||||||
|
LocalListPointsCartesian.get(1).setXY(currentCartesianPoint.x, firstCartesianPoint.y);
|
||||||
|
LocalListPointsCartesian.get(2).setXY(currentCartesianPoint.x, currentCartesianPoint.y);
|
||||||
|
LocalListPointsCartesian.get(3).setXY(firstCartesianPoint.x, currentCartesianPoint.y);
|
||||||
|
convertCartesianPointsToIso();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEntityInHitboxRectengle(Entity e) {
|
||||||
|
entity = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void subscribe(EntityHitboxChangedListener listener) {
|
||||||
|
listeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unsubscribe(EntityHitboxChangedListener listener) {
|
||||||
|
listeners.remove(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void notifySubscribers() {
|
||||||
|
for (EntityHitboxChangedListener listener : listeners) {
|
||||||
|
listener.hitboxChanged(
|
||||||
|
new EntityHitboxChangedEvent(entity.getHitbox(), entity)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initListsPoints() {
|
||||||
|
if(LocalListPointsIso.size()<1) {
|
||||||
|
for(int i=0;i<4;i++) {
|
||||||
|
LocalListPointsIso.add(new Point(currentIsoPoint.x,currentIsoPoint.y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(LocalListPointsCartesian.size()<1) {
|
||||||
|
for(int i=0;i<4;i++) {
|
||||||
|
LocalListPointsCartesian.add(new Point(0,0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void convertCartesianPointsToIso() {
|
||||||
|
Point cartesianPoint;
|
||||||
|
for (int i = 0 ; i<4;i++) {
|
||||||
|
cartesianPoint = LocalListPointsCartesian.get(i);
|
||||||
|
Hitbox.cartesianToIsometric(cartesianPoint.x,cartesianPoint.y,LocalListPointsIso.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void functionClearJButton() {
|
||||||
|
HitboxRectangle nowHitbox = (HitboxRectangle)entity.getHitbox();
|
||||||
|
nowHitbox.getListPointsIso().clear();
|
||||||
|
nowHitbox.getListPointsCartesian().clear();
|
||||||
|
LocalListPointsCartesian.clear();
|
||||||
|
LocalListPointsIso.clear();
|
||||||
|
setFirstIsoPointIsNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import java.awt.event.MouseEvent;
|
|||||||
public interface ShapeRenderingFunction {
|
public interface ShapeRenderingFunction {
|
||||||
void drawing(Graphics2D g);
|
void drawing(Graphics2D g);
|
||||||
public void mousePressed(MouseEvent e);
|
public void mousePressed(MouseEvent e);
|
||||||
public void mouseClicked(MouseEvent e);
|
|
||||||
public void mouseMoved(MouseEvent e);
|
public void mouseMoved(MouseEvent e);
|
||||||
|
public void functionClearJButton();
|
||||||
//private void notifySubscribers() ?? надо ли? подумать
|
//private void notifySubscribers() ?? надо ли? подумать
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,8 +48,8 @@ public class Entity {
|
|||||||
thisDrawbox = outDrawbox;
|
thisDrawbox = outDrawbox;
|
||||||
};
|
};
|
||||||
|
|
||||||
public void setHitbox(Hitbox outHitbox) {
|
public void setHitbox(Hitbox inputHitbox) {
|
||||||
thisHitbox = outHitbox;
|
thisHitbox = inputHitbox;
|
||||||
};
|
};
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|||||||
@ -61,7 +61,7 @@ public abstract class Hitbox {
|
|||||||
public String getShape() {
|
public String getShape() {
|
||||||
return shape;
|
return shape;
|
||||||
}
|
}
|
||||||
|
public void calculationReferencePoint() {}
|
||||||
|
|
||||||
//not the same as toString()! the latter is for XML while printToConsole() is for console
|
//not the same as toString()! the latter is for XML while printToConsole() is for console
|
||||||
public void printToConsole() {
|
public void printToConsole() {
|
||||||
|
|||||||
@ -2,7 +2,10 @@ package model;
|
|||||||
|
|
||||||
public class HitboxCircle extends Hitbox {
|
public class HitboxCircle extends Hitbox {
|
||||||
private float radiusHitbox;
|
private float radiusHitbox;
|
||||||
|
private float diametrX,diametrY;
|
||||||
|
Point cartesianCenterImagePoint= new Point(0,0);
|
||||||
|
//currentRefPoint - точка хранящая изометрические(экранные) коорды, от которой рисуется овал
|
||||||
|
private Point currentRefPoint= new Point(0,0);
|
||||||
public HitboxCircle(String[] dataHitbox, Entity owner){
|
public HitboxCircle(String[] dataHitbox, Entity owner){
|
||||||
super(dataHitbox[0]);
|
super(dataHitbox[0]);
|
||||||
setOwnerEntity(owner);
|
setOwnerEntity(owner);
|
||||||
@ -14,13 +17,66 @@ public class HitboxCircle extends Hitbox {
|
|||||||
radiusHitbox = 0;
|
radiusHitbox = 0;
|
||||||
}
|
}
|
||||||
private void parseStringToCircleHitbox(String[] informations) {
|
private void parseStringToCircleHitbox(String[] informations) {
|
||||||
|
float temp = (float)Math.sqrt(2);
|
||||||
referencePoint.x = Float.parseFloat(informations[1]);
|
referencePoint.x = Float.parseFloat(informations[1]);
|
||||||
referencePoint.y = Float.parseFloat(informations[2]);
|
referencePoint.y = Float.parseFloat(informations[2]);
|
||||||
radiusHitbox = Float.parseFloat(informations[3]);
|
radiusHitbox = Float.parseFloat(informations[3]);
|
||||||
|
diametrX = radiusHitbox/temp*4;
|
||||||
|
diametrY = radiusHitbox/temp*2;
|
||||||
|
cartesianCenterImagePoint = isometricToCartesian(owner.getImage().getWidth()/2,owner.getImage().getHeight(),cartesianCenterImagePoint);
|
||||||
|
Point cartesianCenterRefPoint = new Point(cartesianCenterImagePoint.x-referencePoint.x, cartesianCenterImagePoint.y-referencePoint.y);
|
||||||
|
Point isoCenterRefPoint = new Point(0,0);
|
||||||
|
isoCenterRefPoint = cartesianToIsometric(cartesianCenterRefPoint.x,cartesianCenterRefPoint.y,isoCenterRefPoint);
|
||||||
|
currentRefPoint.x = isoCenterRefPoint.x-diametrY;
|
||||||
|
currentRefPoint.y = isoCenterRefPoint.y-diametrY/2;
|
||||||
|
System.out.println("----------------------------");
|
||||||
|
System.out.println("Entity = "+owner.getName());
|
||||||
|
System.out.println("refCartEntPoint X ="+cartesianCenterRefPoint.x+"||cartesianCenterRefPoint Y ="+cartesianCenterRefPoint.y);
|
||||||
|
System.out.println("CartCenterImage X ="+cartesianCenterImagePoint.x+"||CartCenterImage Y ="+cartesianCenterImagePoint.y);
|
||||||
|
System.out.println("refIsoEntPoint X ="+currentRefPoint.x+"||refIsoEntPoint Y ="+currentRefPoint.y);
|
||||||
|
System.out.println("diametrY "+ diametrY);
|
||||||
|
System.out.println(" ");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String listPointsToString() {
|
public String listPointsToString() {
|
||||||
return "Circle"+referencePoint.x+referencePoint.x+" "+referencePoint.y+" "+radiusHitbox;
|
Point cartesianCenterRefPoint = new Point(0, 0);
|
||||||
|
cartesianCenterImagePoint = isometricToCartesian(owner.getImage().getWidth()/2,owner.getImage().getHeight(),cartesianCenterImagePoint);
|
||||||
|
cartesianCenterRefPoint = isometricToCartesian(currentRefPoint.x+diametrY,currentRefPoint.y+(diametrY/2),cartesianCenterRefPoint);
|
||||||
|
System.out.println("");
|
||||||
|
referencePoint.x = cartesianCenterImagePoint.x-cartesianCenterRefPoint.x;
|
||||||
|
referencePoint.y = cartesianCenterImagePoint.y-cartesianCenterRefPoint.y;
|
||||||
|
System.out.println("----------------------------");
|
||||||
|
System.out.println("Entity = "+owner.getName());
|
||||||
|
System.out.println("refCartEntPoint X ="+cartesianCenterRefPoint.x+"||cartesianCenterRefPoint Y ="+cartesianCenterRefPoint.y);
|
||||||
|
System.out.println("CartCenterImage X ="+cartesianCenterImagePoint.x+"||CartCenterImage Y ="+cartesianCenterImagePoint.y);
|
||||||
|
System.out.println("refIsoEntPoint X ="+currentRefPoint.x+"||refIsoEntPoint Y ="+currentRefPoint.y);
|
||||||
|
System.out.println("diametrY "+ diametrY);
|
||||||
|
System.out.println(" ");
|
||||||
|
return "Circle "+(int)referencePoint.x+" "+(int)referencePoint.y+" "+(int)radiusHitbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getRadius() {
|
||||||
|
return radiusHitbox;
|
||||||
|
}
|
||||||
|
public void setDiametrXY(float diametrX, float diametrY) {
|
||||||
|
this.diametrX = diametrX;
|
||||||
|
this.diametrY = diametrY;
|
||||||
|
}
|
||||||
|
public float getDiametrX() {
|
||||||
|
return diametrX;
|
||||||
|
}
|
||||||
|
public float getDiametrY() {
|
||||||
|
return diametrY;
|
||||||
|
}
|
||||||
|
public void setRadius(float radius) {
|
||||||
|
radiusHitbox = radius;
|
||||||
|
}
|
||||||
|
public Point getCurrentRefPoint() {
|
||||||
|
return currentRefPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,6 @@ public class HitboxRectangle extends Hitbox {
|
|||||||
public HitboxRectangle(String shape, Entity owner){
|
public HitboxRectangle(String shape, Entity owner){
|
||||||
super(shape);
|
super(shape);
|
||||||
setOwnerEntity(owner);
|
setOwnerEntity(owner);
|
||||||
initListsPoints();
|
|
||||||
}
|
}
|
||||||
public HitboxRectangle(String shape,List<Point> listPointsIso,List<Point> listPointsCartesian){
|
public HitboxRectangle(String shape,List<Point> listPointsIso,List<Point> listPointsCartesian){
|
||||||
super(shape);
|
super(shape);
|
||||||
@ -32,7 +31,7 @@ public class HitboxRectangle extends Hitbox {
|
|||||||
printToConsole();
|
printToConsole();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initListsPoints() {
|
public void initListsPoints() {
|
||||||
if(listPointsIso.size()<1) {
|
if(listPointsIso.size()<1) {
|
||||||
for(int i=0;i<4;i++) {
|
for(int i=0;i<4;i++) {
|
||||||
listPointsIso.add(new Point(0,0));
|
listPointsIso.add(new Point(0,0));
|
||||||
@ -72,13 +71,18 @@ public class HitboxRectangle extends Hitbox {
|
|||||||
}
|
}
|
||||||
//+++++++
|
//+++++++
|
||||||
private void createCartesianPointsFromWidthAndHeigh(){
|
private void createCartesianPointsFromWidthAndHeigh(){
|
||||||
Point refIsoPoint = new Point(owner.getWidth()/2+referencePoint.x,owner.getHeight()+referencePoint.y);
|
Point cartesianCenterImagePoint = new Point(0, 0);
|
||||||
Point refCartesianPoint = isometricToCartesian(refIsoPoint.x,refIsoPoint.y,new Point(0,0));
|
isometricToCartesian(owner.getImage().getWidth()/2,owner.getImage().getHeight(),cartesianCenterImagePoint);
|
||||||
|
Point cartesianCenterRefPoint = new Point(cartesianCenterImagePoint.x-referencePoint.x, cartesianCenterImagePoint.y-referencePoint.y);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
listPointsCartesian.clear();
|
listPointsCartesian.clear();
|
||||||
listPointsCartesian.add(new Point(refCartesianPoint.x-widthHitbox,refCartesianPoint.y));
|
listPointsCartesian.add(new Point(cartesianCenterRefPoint.x-widthHitbox,cartesianCenterRefPoint.y));
|
||||||
listPointsCartesian.add(new Point(refCartesianPoint.x,refCartesianPoint.y));
|
listPointsCartesian.add(new Point(cartesianCenterRefPoint.x,cartesianCenterRefPoint.y));
|
||||||
listPointsCartesian.add(new Point(refCartesianPoint.x,refCartesianPoint.y-heightHitbox));
|
listPointsCartesian.add(new Point(cartesianCenterRefPoint.x,cartesianCenterRefPoint.y-heightHitbox));
|
||||||
listPointsCartesian.add(new Point(refCartesianPoint.x-widthHitbox,refCartesianPoint.y-heightHitbox));
|
listPointsCartesian.add(new Point(cartesianCenterRefPoint.x-widthHitbox,cartesianCenterRefPoint.y-heightHitbox));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Point> getListPointsIso() {
|
public List<Point> getListPointsIso() {
|
||||||
@ -89,6 +93,30 @@ public class HitboxRectangle extends Hitbox {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String listPointsToString() {
|
public String listPointsToString() {
|
||||||
return "Rectangle "+referencePoint.x+" "+referencePoint.y+" "+widthHitbox+" "+heightHitbox;
|
System.out.println("Парсинг данных");
|
||||||
|
parseCartesianListPointsToWidthHeight();
|
||||||
|
calculationReferencePoint();
|
||||||
|
return "Rectangle "+(int)referencePoint.x+" "+(int)referencePoint.y+" "+(int)widthHitbox+" "+(int)heightHitbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void parseCartesianListPointsToWidthHeight() {
|
||||||
|
widthHitbox = Math.abs(listPointsCartesian.get(0).x-listPointsCartesian.get(1).x);
|
||||||
|
heightHitbox = Math.abs(listPointsCartesian.get(1).y-listPointsCartesian.get(2).y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void calculationReferencePoint() {
|
||||||
|
Point bottomPoint = new Point(0,0);
|
||||||
|
for(Point currentPoint: listPointsIso) {
|
||||||
|
if(bottomPoint.y<currentPoint.y) {
|
||||||
|
bottomPoint.x=currentPoint.x;
|
||||||
|
bottomPoint.y=currentPoint.y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bottomPoint = isometricToCartesian(bottomPoint.x,bottomPoint.y,bottomPoint);
|
||||||
|
Point cartesianCenterImagePoint= new Point(0,0);
|
||||||
|
cartesianCenterImagePoint = isometricToCartesian(owner.getImage().getWidth()/2,owner.getImage().getHeight(),cartesianCenterImagePoint);
|
||||||
|
referencePoint.x = cartesianCenterImagePoint.x-bottomPoint.x;
|
||||||
|
referencePoint.y = cartesianCenterImagePoint.y-bottomPoint.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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_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";
|
public static final String DEFAULT_XML_FILENAME = "objecttypes.xml";
|
||||||
|
/**
|
||||||
|
* Переменная которая отслеживает, были ли произведены изменения XML-Dom-дерева.
|
||||||
|
* */
|
||||||
|
public static boolean changeOfXmlDOM = false;
|
||||||
static Project thisProject;
|
static Project thisProject;
|
||||||
private List <Entity> listEntity = new ArrayList<Entity>();
|
private List <Entity> listEntity = new ArrayList<Entity>();
|
||||||
private String path = DEFAULT_XML_PATH;
|
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
|
hitboxProperty.setAttribute("default", "Rectangle 0 0 0 0"); // empty, no hitbox yet
|
||||||
objecttypeElement.appendChild(hitboxProperty);
|
objecttypeElement.appendChild(hitboxProperty);
|
||||||
|
|
||||||
|
changeOfXmlDOM = true;
|
||||||
//printXMlToConsole(); //DEBUG!
|
//printXMlToConsole(); //DEBUG!
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,10 +302,11 @@ public class Project implements Iterable<Entity>, EntityDrawboxChangedListener,
|
|||||||
DOMSource source = new DOMSource(document);
|
DOMSource source = new DOMSource(document);
|
||||||
StreamResult result = new StreamResult(new FileOutputStream(getXMLPath() + getXMLFileName()));
|
StreamResult result = new StreamResult(new FileOutputStream(getXMLPath() + getXMLFileName()));
|
||||||
transformer.transform(source, result);
|
transformer.transform(source, result);
|
||||||
JOptionPane.showMessageDialog(null, "Бугага, сохранилось!", "Success", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Бугагашеньки, сохранилось!", "Success", JOptionPane.INFORMATION_MESSAGE);
|
||||||
} catch (TransformerException | FileNotFoundException e) {
|
} catch (TransformerException | FileNotFoundException e) {
|
||||||
JOptionPane.showMessageDialog(null, "Saving project is unsuccsessfull! Erorr is: "+e, "Project save unsuccsesfull", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Saving project is unsuccsessfull! Erorr is: "+e, "Project save unsuccsesfull", JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
|
changeOfXmlDOM = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PrintEntitys() {
|
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
|
private Node getEntityXMLNodeByName(String name) { //returns entitie's objecttype node
|
||||||
|
|||||||