New architecture of classes for switching the drawing modes of hitboxes/Dravboxes of entities
This commit is contained in:
102
src/gui/HitboxEditor.java
Normal file
102
src/gui/HitboxEditor.java
Normal file
@ -0,0 +1,102 @@
|
||||
package gui;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JTabbedPane;
|
||||
|
||||
import model.Hitbox;
|
||||
import model.Point;
|
||||
|
||||
|
||||
public class HitboxEditor extends Editable {
|
||||
Point firstIsoPoint = null;
|
||||
Point currentIsoPoint = new Point(0,0);
|
||||
Point firstCartesianPoint = new Point(0,0), currentCartesianPoint = new Point(0,0);
|
||||
|
||||
HitboxEditor(ListGUI listGUI) {
|
||||
super(listGUI);
|
||||
}
|
||||
|
||||
@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 saveDataInEntity() {
|
||||
// saveDataInEntity - сохранение данных в сущности.
|
||||
//Она нам тут не нужна.
|
||||
//Все данные и так лежат где необходимо, используя ссылки.
|
||||
}
|
||||
|
||||
@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) {
|
||||
Hitbox nowHitbox = entity.getHitbox();
|
||||
if(firstIsoPoint != null) {
|
||||
//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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JTabbedPane parent = (JTabbedPane) getParent();
|
||||
if(parent.getSelectedComponent() == this){
|
||||
if(entity != null) {
|
||||
firstIsoPoint = null;
|
||||
currentIsoPoint.setXY(0,0);
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user