Refactoring ClearButton. Made by drawing CircleHitbox. Need to finish doing HitboxCircleRenderingFunction and saving hitboxCircle when you put the second point
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
@ -23,6 +23,6 @@
|
|||||||
<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="252 116 505 120 500 247 235 237 " name="drawbox" type="string"/>
|
<property default="252 116 505 120 500 247 235 237 " name="drawbox" type="string"/>
|
||||||
<property default="Rectangle -185 -822 189 99" name="hitbox" type="string"/>
|
<property default="Rectangle -18 -678 217 161" 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 |
@ -35,14 +35,6 @@ public class DrawboxEditor extends Editable {
|
|||||||
canvas.setDrawboxRectengleRenderingFunction();
|
canvas.setDrawboxRectengleRenderingFunction();
|
||||||
canvas.setVisible(true);
|
canvas.setVisible(true);
|
||||||
|
|
||||||
clearLinesJButton.addActionListener((e)->{
|
|
||||||
if(entity != null) {
|
|
||||||
entity.getDrawbox().getDrawboxlistPoints().clear();
|
|
||||||
entity.getDrawbox().getbaseListPoints().clear();
|
|
||||||
canvas.repaint();
|
|
||||||
}});
|
|
||||||
|
|
||||||
|
|
||||||
logger.setLevel(Level.CONFIG);
|
logger.setLevel(Level.CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -40,12 +40,15 @@ public abstract class Editable extends JPanel implements ListSelectionListener {
|
|||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
|
|
||||||
clearLinesJButton = createButton("Clear lines",null,"res/destroy.png");
|
clearLinesJButton = createButton("Clear lines",null,"res/destroy.png");
|
||||||
|
clearLinesJButton.addActionListener((e)->{
|
||||||
|
canvas.renderingFunction.functionClearJButton();
|
||||||
|
canvas.repaint();
|
||||||
|
});
|
||||||
toolbar.setBorder(BorderFactory.createLoweredBevelBorder());
|
toolbar.setBorder(BorderFactory.createLoweredBevelBorder());
|
||||||
toolbar.addSeparator();
|
toolbar.addSeparator();
|
||||||
toolbar.add(clearLinesJButton);
|
toolbar.add(clearLinesJButton);
|
||||||
this.add(toolbar,BorderLayout.EAST);
|
this.add(toolbar,BorderLayout.EAST);
|
||||||
|
toolbar.setPreferredSize(new Dimension(40,40));
|
||||||
// РАСКОММЕНТИТЬ ЕСЛИ НУЖНО ВЫВОДИТЬ ПОДРОБНЫЕ ЛОГИ
|
// РАСКОММЕНТИТЬ ЕСЛИ НУЖНО ВЫВОДИТЬ ПОДРОБНЫЕ ЛОГИ
|
||||||
logger.setLevel(Level.ALL);
|
logger.setLevel(Level.ALL);
|
||||||
}
|
}
|
||||||
@ -92,12 +95,12 @@ public abstract class Editable extends JPanel implements ListSelectionListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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(38, 38));
|
button.setPreferredSize(new Dimension(20, 20));
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -88,7 +88,8 @@ public class EditableCanvas extends JPanel implements MouseListener, MouseMotion
|
|||||||
public void setEntity(Entity e) {
|
public void setEntity(Entity e) {
|
||||||
entity = e;
|
entity = e;
|
||||||
drawboxRectengleRenderFunct.setEntityInDrawboxRectengle(e);
|
drawboxRectengleRenderFunct.setEntityInDrawboxRectengle(e);
|
||||||
hitboxRectengleRenderFunct.setEntityInHtiboxRectengle(e);
|
hitboxRectengleRenderFunct.setEntityInHitboxRectengle(e);
|
||||||
|
hitboxCircleRenderFunct.setEntityInHitboxCircle(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setImage(BufferedImage image) {
|
public void setImage(BufferedImage image) {
|
||||||
|
|||||||
@ -6,6 +6,8 @@ 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 javax.swing.event.ListSelectionEvent;
|
||||||
|
|
||||||
@ -16,10 +18,15 @@ import events.EntityHitboxChangedListener;
|
|||||||
import model.Hitbox;
|
import model.Hitbox;
|
||||||
import model.HitboxRectangle;
|
import model.HitboxRectangle;
|
||||||
import model.Point;
|
import model.Point;
|
||||||
|
import repository.Project;
|
||||||
|
|
||||||
|
|
||||||
public class HitboxEditor extends Editable {
|
public class HitboxEditor extends Editable {
|
||||||
|
|
||||||
|
JButton changeInRectangleHitboxJButton;
|
||||||
|
JButton changeInCircleHitboxJButton;
|
||||||
|
|
||||||
|
|
||||||
HitboxEditor(ListGUI listGUI) {
|
HitboxEditor(ListGUI listGUI) {
|
||||||
super(listGUI);
|
super(listGUI);
|
||||||
|
|
||||||
@ -28,29 +35,58 @@ public class HitboxEditor extends Editable {
|
|||||||
canvas.setHitboxRectengleRenderingFunction();
|
canvas.setHitboxRectengleRenderingFunction();
|
||||||
canvas.setVisible(true);
|
canvas.setVisible(true);
|
||||||
|
|
||||||
clearLinesJButton.addActionListener((e)->{
|
changeInRectangleHitboxJButton = super.createButton("Hitbox Rectangle",null,"res/square.png");
|
||||||
if(entity != null) {
|
changeInCircleHitboxJButton = super.createButton("Hitbox circle",null,"res/circle.png");
|
||||||
HitboxRectangle nowHitbox = (HitboxRectangle)entity.getHitbox();
|
toolbar.add(changeInRectangleHitboxJButton);
|
||||||
System.out.println("1. nowHitbox.getListPointsIso().size() = "+ nowHitbox.getListPointsIso().size());
|
toolbar.add(changeInCircleHitboxJButton);
|
||||||
nowHitbox.getListPointsIso().clear();
|
|
||||||
System.out.println("2. nowHitbox.getListPointsIso().size() = "+ nowHitbox.getListPointsIso().size());
|
|
||||||
System.out.println("1. nowHitbox.getListPointsCartesian().size() = "+ nowHitbox.getListPointsCartesian().size() );
|
|
||||||
nowHitbox.getListPointsCartesian().clear();
|
|
||||||
System.out.println("2. nowHitbox.getListPointsCartesian().size() = "+ nowHitbox.getListPointsCartesian().size());
|
|
||||||
canvas.getHitboxRectengleRenderFunct().getLocalListPointsCartesian().clear();
|
|
||||||
canvas.getHitboxRectengleRenderFunct().getLocalListPointsIso().clear();
|
|
||||||
canvas.getHitboxRectengleRenderFunct().setFirstIsoPointIsNull();
|
|
||||||
canvas.repaint();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
changeInRectangleHitboxJButton.addActionListener((e)->{
|
||||||
|
functionClearHitboxJButton();
|
||||||
|
//canvas.setHitboxRectengleRenderingFunction();
|
||||||
|
//Сделать создание нового Hitbox формы Rectengle
|
||||||
|
});
|
||||||
|
changeInCircleHitboxJButton.addActionListener((e)->{
|
||||||
|
functionClearHitboxJButton();
|
||||||
|
//canvas.setHitboxCircleRenderingFunction();
|
||||||
|
//Сделать создание нового Hitbox формы Circle
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
public void functionClearHitboxJButton() {
|
||||||
|
if(entity != null) {
|
||||||
|
canvas.renderingFunction.functionClearJButton();
|
||||||
|
canvas.repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
//НАДО ДОБАВИТЬ ЧТО БЫ ПОД КОНЕЦ РИСОВАНИЯ ХИТБОКСА ОНО ВЫЗЫВАЛО ФУНКЦИЮ И ВСЕ СОХРАНЯЛО.
|
//НАДО ДОБАВИТЬ ЧТО БЫ ПОД КОНЕЦ РИСОВАНИЯ ХИТБОКСА ОНО ВЫЗЫВАЛО ФУНКЦИЮ И ВСЕ СОХРАНЯЛО.
|
||||||
//СОХРАНЕНИЕ УЖЕ РЕАЛИЗОВАНО.
|
//СОХРАНЕНИЕ УЖЕ РЕАЛИЗОВАНО.
|
||||||
//НО НЕ ДОБАВЛЕН ВЫЗОВ ФУНКЦИИ И НЕ ОФОРМЛЕНА ПОДПИСКА
|
//НО НЕ ДОБАВЛЕН ВЫЗОВ ФУНКЦИИ И НЕ ОФОРМЛЕНА ПОДПИСКА
|
||||||
//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);
|
||||||
|
} catch (Exception e1) {
|
||||||
|
//logger.severe("Entity with name '"+selectedEntityName+"' was not found! Cannot display it on panel!");
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
canvas.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 {
|
||||||
@ -145,5 +146,10 @@ public class DrawboxRectengleRenderingFunction implements ShapeRenderingFunction
|
|||||||
public void setEntityInDrawboxRectengle(Entity e) {
|
public void setEntityInDrawboxRectengle(Entity e) {
|
||||||
entity = e;
|
entity = e;
|
||||||
}
|
}
|
||||||
|
public void functionClearJButton() {
|
||||||
|
if(entity != null) {
|
||||||
|
entity.getDrawbox().getDrawboxlistPoints().clear();
|
||||||
|
entity.getDrawbox().getbaseListPoints().clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,24 +3,62 @@ package gui.render;
|
|||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
|
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 currentRadius=0;
|
||||||
|
Entity entity;
|
||||||
|
|
||||||
|
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, (int)nowHitbox.getRadius()*2, (int)nowHitbox.getRadius());
|
||||||
|
}else if(firstIsoPoint != null) {
|
||||||
|
currentRadius = Math.abs((int)firstIsoPoint.x-(int)currentIsoPoint.x);
|
||||||
|
g.drawOval((int)firstIsoPoint.x, (int)firstIsoPoint.y, currentRadius, currentRadius/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) {
|
||||||
|
// высчитываем в параметры хитбокссеркла нужный радиус и текущую реф поинт.
|
||||||
|
// Не забываем высчитать реф поинт хитбокса относительно текущей.
|
||||||
|
// после чего вызываем listPointsToString и нотифай, который отправляет данные на сохранение
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@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);
|
||||||
|
currentRadius = 0;
|
||||||
|
HitboxCircle nowhitbox = (HitboxCircle)entity.getHitbox();
|
||||||
|
nowhitbox.setRadius(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,7 +32,7 @@ public class HitboxRectengleRenderingFunction implements ShapeRenderingFunction
|
|||||||
return LocalListPointsCartesian;
|
return LocalListPointsCartesian;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFirstIsoPointIsNull(){
|
private void setFirstIsoPointIsNull(){
|
||||||
firstIsoPoint = null;
|
firstIsoPoint = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ public class HitboxRectengleRenderingFunction implements ShapeRenderingFunction
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEntityInHtiboxRectengle(Entity e) {
|
public void setEntityInHitboxRectengle(Entity e) {
|
||||||
entity = e;
|
entity = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,4 +152,14 @@ public class HitboxRectengleRenderingFunction implements ShapeRenderingFunction
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void functionClearJButton() {
|
||||||
|
HitboxRectangle nowHitbox = (HitboxRectangle)entity.getHitbox();
|
||||||
|
nowHitbox.getListPointsIso().clear();
|
||||||
|
nowHitbox.getListPointsCartesian().clear();
|
||||||
|
LocalListPointsCartesian.clear();
|
||||||
|
LocalListPointsIso.clear();
|
||||||
|
setFirstIsoPointIsNull();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,5 +7,6 @@ public interface ShapeRenderingFunction {
|
|||||||
void drawing(Graphics2D g);
|
void drawing(Graphics2D g);
|
||||||
public void mousePressed(MouseEvent e);
|
public void mousePressed(MouseEvent e);
|
||||||
public void mouseMoved(MouseEvent e);
|
public void mouseMoved(MouseEvent e);
|
||||||
|
public void functionClearJButton();
|
||||||
//private void notifySubscribers() ?? надо ли? подумать
|
//private void notifySubscribers() ?? надо ли? подумать
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ package model;
|
|||||||
|
|
||||||
public class HitboxCircle extends Hitbox {
|
public class HitboxCircle extends Hitbox {
|
||||||
private float radiusHitbox;
|
private float radiusHitbox;
|
||||||
|
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);
|
||||||
@ -16,6 +16,8 @@ public class HitboxCircle extends Hitbox {
|
|||||||
private void parseStringToCircleHitbox(String[] informations) {
|
private void parseStringToCircleHitbox(String[] informations) {
|
||||||
referencePoint.x = Float.parseFloat(informations[1]);
|
referencePoint.x = Float.parseFloat(informations[1]);
|
||||||
referencePoint.y = Float.parseFloat(informations[2]);
|
referencePoint.y = Float.parseFloat(informations[2]);
|
||||||
|
currentRefPoint.x = owner.getImage().getWidth()/2+referencePoint.x;
|
||||||
|
currentRefPoint.y = owner.getImage().getHeight()+referencePoint.y;
|
||||||
radiusHitbox = Float.parseFloat(informations[3]);
|
radiusHitbox = Float.parseFloat(informations[3]);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
@ -23,4 +25,16 @@ public class HitboxCircle extends Hitbox {
|
|||||||
return "Circle"+referencePoint.x+referencePoint.x+" "+referencePoint.y+" "+radiusHitbox;
|
return "Circle"+referencePoint.x+referencePoint.x+" "+referencePoint.y+" "+radiusHitbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getRadius() {
|
||||||
|
return radiusHitbox;
|
||||||
|
}
|
||||||
|
public void setRadius(int radius) {
|
||||||
|
radiusHitbox = radius;
|
||||||
|
}
|
||||||
|
public Point getCurrentRefPoint() {
|
||||||
|
return currentRefPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||