ability to remove movers

This commit is contained in:
yugecin 2016-12-25 13:19:54 +01:00
parent ddaa8f5bcc
commit 81431067d8
3 changed files with 50 additions and 5 deletions

View File

@ -82,7 +82,7 @@ public class MoveStoryboard {
btnAddQuadratic.render(g); btnAddQuadratic.render(g);
btnAddCubic.render(g); btnAddCubic.render(g);
if (moves[objectIndex] != null && objectIndex > 0 && trackPosition >= gameObjects[objectIndex - 1].getEndTime() && trackPosition < gameObjects[objectIndex].getTime()) { if (moves[objectIndex] != null && objectIndex > 0 && trackPosition >= gameObjects[objectIndex - 1].getEndTime() && trackPosition < gameObjects[objectIndex].getTime()) {
moves[objectIndex].render(g, width); moves[objectIndex].render(g);
} }
} }
@ -95,6 +95,9 @@ public class MoveStoryboard {
public void mouseReleased(int x, int y) { public void mouseReleased(int x, int y) {
if (moves[objectIndex] != null) { if (moves[objectIndex] != null) {
moves[objectIndex].mouseReleased(x, y); moves[objectIndex].mouseReleased(x, y);
if (moves[objectIndex].getAmountOfMovers() == 0) {
moves[objectIndex] = null;
}
} }
if (objectIndex == 0) { if (objectIndex == 0) {
return; return;
@ -114,7 +117,7 @@ public class MoveStoryboard {
return dummyMove; return dummyMove;
} }
if (moves[objectIndex] == null) { if (moves[objectIndex] == null) {
return moves[objectIndex] = new StoryboardMoveImpl(gameObjects[objectIndex - 1].end, gameObjects[objectIndex].start); return moves[objectIndex] = new StoryboardMoveImpl(gameObjects[objectIndex - 1].end, gameObjects[objectIndex].start, width);
} }
return moves[objectIndex]; return moves[objectIndex];
} }

View File

@ -22,6 +22,7 @@ import yugecin.opsudance.sbv2.movers.StoryboardMover;
public interface StoryboardMove { public interface StoryboardMove {
int getAmountOfMovers();
void add(StoryboardMover mover); void add(StoryboardMover mover);
float[] getPointAt(float t); float[] getPointAt(float t);
void update(int delta, int x, int y); void update(int delta, int x, int y);

View File

@ -28,7 +28,9 @@ import java.util.List;
public class StoryboardMoveImpl implements StoryboardMove { public class StoryboardMoveImpl implements StoryboardMove {
private static final int POINTSIZE = 3; private static final int POINTSIZE = 6;
private int screenWidth;
private Vec2f start; private Vec2f start;
private Vec2f end; private Vec2f end;
@ -43,14 +45,20 @@ public class StoryboardMoveImpl implements StoryboardMove {
private int recalculateDelay; private int recalculateDelay;
public StoryboardMoveImpl(Vec2f start, Vec2f end) { public StoryboardMoveImpl(Vec2f start, Vec2f end, int screenWidth) {
this.start = start; this.start = start;
this.end = end; this.end = end;
this.screenWidth = screenWidth;
movers = new ArrayList<>(); movers = new ArrayList<>();
midPoints = new ArrayList<>(); midPoints = new ArrayList<>();
recalculateDelay = 700; recalculateDelay = 700;
} }
@Override
public int getAmountOfMovers() {
return movers.size();
}
@Override @Override
public void add(StoryboardMover mover) { public void add(StoryboardMover mover) {
mover.end = end; mover.end = end;
@ -119,9 +127,34 @@ public class StoryboardMoveImpl implements StoryboardMove {
@Override @Override
public void mouseReleased(int x, int y) { public void mouseReleased(int x, int y) {
if (currentPoint != null) { int posY = 200;
if (currentPoint == null) {
for (int i = 0; i < movers.size(); i++) {
int dif = posY;
posY += Fonts.SMALL.getLineHeight() * 1.1f;
dif = posY - dif;
if (screenWidth - 20 <= x && x <= screenWidth - 10 && posY - dif / 2 - 5 <= y && y <= posY - dif / 2 + 5) {
if (movers.size() == 1) {
movers.clear();
return;
}
StoryboardMover mover = movers.get(i);
if (i == movers.size() - 1) {
midPoints.remove(i - 1);
movers.get(i - 1).end = mover.end;
} else {
midPoints.remove(i);
movers.get(i + 1).start = mover.start;
}
movers.remove(i);
totalLength -= mover.getLength();
recalculateTimes();
}
}
} else {
moveCurrentPoint(x, y); moveCurrentPoint(x, y);
recalculateLengths(); recalculateLengths();
recalculateTimes();
currentPoint = null; currentPoint = null;
} }
recalculateDelay = 700; recalculateDelay = 700;
@ -151,8 +184,16 @@ public class StoryboardMoveImpl implements StoryboardMove {
@Override @Override
public void render(Graphics g) { public void render(Graphics g) {
g.setColor(Color.red);
int y = 200;
for (StoryboardMover mover : movers) { for (StoryboardMover mover : movers) {
mover.render(g); mover.render(g);
String text = mover.toString();
Fonts.SMALL.drawString(screenWidth - Fonts.SMALL.getWidth(text) - 30, y, text);
int dif = y;
y += Fonts.SMALL.getLineHeight() * 1.1f;
dif = y - dif;
g.fillRect(screenWidth - 20, y - dif / 2 - 5, 10, 10);
} }
g.setColor(Color.cyan); g.setColor(Color.cyan);
for (Vec2f point : midPoints) { for (Vec2f point : midPoints) {