Refactoring ClearButton. Made by drawing CircleHitbox. Need to finish doing HitboxCircleRenderingFunction and saving hitboxCircle when you put the second point
This commit is contained in:
@ -35,14 +35,6 @@ public class DrawboxEditor extends Editable {
|
||||
canvas.setDrawboxRectengleRenderingFunction();
|
||||
canvas.setVisible(true);
|
||||
|
||||
clearLinesJButton.addActionListener((e)->{
|
||||
if(entity != null) {
|
||||
entity.getDrawbox().getDrawboxlistPoints().clear();
|
||||
entity.getDrawbox().getbaseListPoints().clear();
|
||||
canvas.repaint();
|
||||
}});
|
||||
|
||||
|
||||
logger.setLevel(Level.CONFIG);
|
||||
}
|
||||
|
||||
|
||||
@ -40,12 +40,15 @@ public abstract class Editable extends JPanel implements ListSelectionListener {
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
clearLinesJButton = createButton("Clear lines",null,"res/destroy.png");
|
||||
|
||||
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);
|
||||
}
|
||||
@ -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));
|
||||
button.addActionListener(listener);
|
||||
button.setContentAreaFilled(false);
|
||||
button.setFocusPainted(false);
|
||||
button.setPreferredSize(new Dimension(38, 38));
|
||||
button.setPreferredSize(new Dimension(20, 20));
|
||||
return button;
|
||||
}
|
||||
|
||||
|
||||
@ -88,7 +88,8 @@ public class EditableCanvas extends JPanel implements MouseListener, MouseMotion
|
||||
public void setEntity(Entity e) {
|
||||
entity = e;
|
||||
drawboxRectengleRenderFunct.setEntityInDrawboxRectengle(e);
|
||||
hitboxRectengleRenderFunct.setEntityInHtiboxRectengle(e);
|
||||
hitboxRectengleRenderFunct.setEntityInHitboxRectengle(e);
|
||||
hitboxCircleRenderFunct.setEntityInHitboxCircle(e);
|
||||
}
|
||||
|
||||
public void setImage(BufferedImage image) {
|
||||
|
||||
@ -6,6 +6,8 @@ import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
|
||||
@ -16,10 +18,15 @@ import events.EntityHitboxChangedListener;
|
||||
import model.Hitbox;
|
||||
import model.HitboxRectangle;
|
||||
import model.Point;
|
||||
import repository.Project;
|
||||
|
||||
|
||||
public class HitboxEditor extends Editable {
|
||||
|
||||
JButton changeInRectangleHitboxJButton;
|
||||
JButton changeInCircleHitboxJButton;
|
||||
|
||||
|
||||
HitboxEditor(ListGUI listGUI) {
|
||||
super(listGUI);
|
||||
|
||||
@ -28,29 +35,58 @@ public class HitboxEditor extends Editable {
|
||||
canvas.setHitboxRectengleRenderingFunction();
|
||||
canvas.setVisible(true);
|
||||
|
||||
clearLinesJButton.addActionListener((e)->{
|
||||
if(entity != null) {
|
||||
HitboxRectangle nowHitbox = (HitboxRectangle)entity.getHitbox();
|
||||
System.out.println("1. nowHitbox.getListPointsIso().size() = "+ nowHitbox.getListPointsIso().size());
|
||||
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 = 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();
|
||||
//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;
|
||||
|
||||
|
||||
@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 model.Drawbox;
|
||||
import model.Entity;
|
||||
import model.HitboxRectangle;
|
||||
import model.Point;
|
||||
|
||||
public class DrawboxRectengleRenderingFunction implements ShapeRenderingFunction {
|
||||
@ -145,5 +146,10 @@ public class DrawboxRectengleRenderingFunction implements ShapeRenderingFunction
|
||||
public void setEntityInDrawboxRectengle(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.event.MouseEvent;
|
||||
|
||||
public class HitboxCircleRenderingFunction implements ShapeRenderingFunction {
|
||||
import model.Entity;
|
||||
import model.HitboxCircle;
|
||||
import model.Point;
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
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;
|
||||
}
|
||||
|
||||
public void setFirstIsoPointIsNull(){
|
||||
private void setFirstIsoPointIsNull(){
|
||||
firstIsoPoint = null;
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ public class HitboxRectengleRenderingFunction implements ShapeRenderingFunction
|
||||
}
|
||||
}
|
||||
|
||||
public void setEntityInHtiboxRectengle(Entity e) {
|
||||
public void setEntityInHitboxRectengle(Entity e) {
|
||||
entity = e;
|
||||
}
|
||||
|
||||
@ -151,5 +151,15 @@ public class HitboxRectengleRenderingFunction implements ShapeRenderingFunction
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -7,5 +7,6 @@ public interface ShapeRenderingFunction {
|
||||
void drawing(Graphics2D g);
|
||||
public void mousePressed(MouseEvent e);
|
||||
public void mouseMoved(MouseEvent e);
|
||||
public void functionClearJButton();
|
||||
//private void notifySubscribers() ?? надо ли? подумать
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ package model;
|
||||
|
||||
public class HitboxCircle extends Hitbox {
|
||||
private float radiusHitbox;
|
||||
|
||||
private Point currentRefPoint= new Point(0,0);
|
||||
public HitboxCircle(String[] dataHitbox, Entity owner){
|
||||
super(dataHitbox[0]);
|
||||
setOwnerEntity(owner);
|
||||
@ -16,6 +16,8 @@ public class HitboxCircle extends Hitbox {
|
||||
private void parseStringToCircleHitbox(String[] informations) {
|
||||
referencePoint.x = Float.parseFloat(informations[1]);
|
||||
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]);
|
||||
}
|
||||
@Override
|
||||
@ -23,4 +25,16 @@ public class HitboxCircle extends Hitbox {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user