2016-12-25 12:16:32 +01:00
|
|
|
/*
|
|
|
|
* opsu!dance - fork of opsu! with cursordance auto
|
|
|
|
* Copyright (C) 2016 yugecin
|
|
|
|
*
|
|
|
|
* opsu!dance is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* opsu!dance is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with opsu!dance. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package yugecin.opsudance.sbv2;
|
|
|
|
|
|
|
|
import itdelatrisu.opsu.objects.curves.Vec2f;
|
2016-12-25 12:35:33 +01:00
|
|
|
import itdelatrisu.opsu.ui.Fonts;
|
2016-12-25 15:46:11 +01:00
|
|
|
import itdelatrisu.opsu.ui.animations.AnimationEquation;
|
2016-12-25 12:16:32 +01:00
|
|
|
import org.newdawn.slick.Color;
|
|
|
|
import org.newdawn.slick.Graphics;
|
2016-12-25 14:19:08 +01:00
|
|
|
import yugecin.opsudance.render.RenderUtils;
|
2016-12-25 12:16:32 +01:00
|
|
|
import yugecin.opsudance.sbv2.movers.StoryboardMover;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class StoryboardMoveImpl implements StoryboardMove {
|
|
|
|
|
2016-12-25 13:19:54 +01:00
|
|
|
private static final int POINTSIZE = 6;
|
|
|
|
|
|
|
|
private int screenWidth;
|
2016-12-25 12:16:32 +01:00
|
|
|
|
|
|
|
private Vec2f start;
|
|
|
|
private Vec2f end;
|
|
|
|
private List<StoryboardMover> movers;
|
|
|
|
private List<Vec2f> midPoints;
|
|
|
|
|
|
|
|
private StoryboardMover nextMover;
|
|
|
|
private Vec2f currentPoint;
|
|
|
|
private StoryboardMover prevMover;
|
|
|
|
|
|
|
|
private float totalLength;
|
|
|
|
|
2016-12-25 12:41:40 +01:00
|
|
|
private int recalculateDelay;
|
|
|
|
|
2016-12-25 15:46:11 +01:00
|
|
|
private AnimationEquation animationEquation;
|
|
|
|
|
2016-12-25 13:19:54 +01:00
|
|
|
public StoryboardMoveImpl(Vec2f start, Vec2f end, int screenWidth) {
|
2016-12-25 15:46:11 +01:00
|
|
|
this.animationEquation = AnimationEquation.LINEAR;
|
2016-12-25 12:16:32 +01:00
|
|
|
this.start = start;
|
|
|
|
this.end = end;
|
2016-12-25 13:19:54 +01:00
|
|
|
this.screenWidth = screenWidth;
|
2016-12-25 12:16:32 +01:00
|
|
|
movers = new ArrayList<>();
|
|
|
|
midPoints = new ArrayList<>();
|
2016-12-25 12:41:40 +01:00
|
|
|
recalculateDelay = 700;
|
2016-12-25 12:16:32 +01:00
|
|
|
}
|
|
|
|
|
2016-12-25 15:46:11 +01:00
|
|
|
@Override
|
|
|
|
public void setAnimationEquation(AnimationEquation animationEquation) {
|
|
|
|
this.animationEquation = animationEquation;
|
|
|
|
}
|
|
|
|
|
2016-12-25 13:19:54 +01:00
|
|
|
@Override
|
|
|
|
public int getAmountOfMovers() {
|
|
|
|
return movers.size();
|
|
|
|
}
|
|
|
|
|
2016-12-25 12:16:32 +01:00
|
|
|
@Override
|
|
|
|
public void add(StoryboardMover mover) {
|
|
|
|
mover.end = end;
|
|
|
|
if (movers.size() == 0) {
|
2016-12-25 13:58:31 +01:00
|
|
|
mover.setInitialStart(start);
|
2016-12-25 12:16:32 +01:00
|
|
|
} else {
|
|
|
|
StoryboardMover lastMover = movers.get(movers.size() - 1);
|
|
|
|
Vec2f mid = new Vec2f(
|
|
|
|
(lastMover.start.x + lastMover.end.x) / 2f,
|
|
|
|
(lastMover.start.y + lastMover.end.y) / 2f
|
|
|
|
);
|
|
|
|
midPoints.add(mid);
|
|
|
|
lastMover.end = mid;
|
|
|
|
totalLength -= lastMover.getLength();
|
|
|
|
lastMover.recalculateLength();
|
|
|
|
totalLength += lastMover.getLength();
|
2016-12-25 13:58:31 +01:00
|
|
|
mover.setInitialStart(mid);
|
2016-12-25 12:16:32 +01:00
|
|
|
}
|
2016-12-25 13:58:31 +01:00
|
|
|
mover.recalculateLength();
|
|
|
|
totalLength += mover.getLength();
|
2016-12-25 12:16:32 +01:00
|
|
|
movers.add(mover);
|
|
|
|
recalculateTimes();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public float[] getPointAt(float t) {
|
|
|
|
if (movers.size() == 0) {
|
|
|
|
return new float[] { end.x, end.y };
|
|
|
|
}
|
2016-12-25 15:46:11 +01:00
|
|
|
t = animationEquation.calc(t);
|
2016-12-25 12:16:32 +01:00
|
|
|
float cumulativeTime = 0f;
|
|
|
|
for (StoryboardMover mover : movers) {
|
|
|
|
cumulativeTime += mover.timeLengthPercentOfTotalTime;
|
|
|
|
if (cumulativeTime > t) {
|
|
|
|
return mover.getPointAt((t - (cumulativeTime - mover.timeLengthPercentOfTotalTime)) / mover.timeLengthPercentOfTotalTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new float[] { end.x, end.y };
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update(int delta, int x, int y) {
|
2016-12-25 13:58:31 +01:00
|
|
|
for (StoryboardMover mover : movers) {
|
|
|
|
mover.update(delta, x, y);
|
|
|
|
}
|
2016-12-25 12:16:32 +01:00
|
|
|
if (currentPoint != null) {
|
|
|
|
moveCurrentPoint(x, y);
|
2016-12-25 12:41:40 +01:00
|
|
|
recalculateDelay -= delta;
|
|
|
|
if (recalculateDelay < 0) {
|
|
|
|
recalculateDelay = 700;
|
|
|
|
recalculateLengths();
|
|
|
|
recalculateTimes();
|
|
|
|
}
|
2016-12-25 12:16:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mousePressed(int x, int y) {
|
|
|
|
int i = 0;
|
2016-12-25 13:58:31 +01:00
|
|
|
for(StoryboardMover mover : movers) {
|
|
|
|
if (mover.mousePressed(x, y)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-12-25 12:16:32 +01:00
|
|
|
for (Vec2f point : midPoints) {
|
|
|
|
if (point.x - POINTSIZE <= x && x <= point.x + POINTSIZE && point.y - POINTSIZE <= y && y <= point.y + POINTSIZE) {
|
|
|
|
currentPoint = point;
|
|
|
|
prevMover = movers.get(i);
|
|
|
|
nextMover = movers.get(i + 1);
|
2016-12-25 13:58:31 +01:00
|
|
|
return;
|
2016-12-25 12:16:32 +01:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mouseReleased(int x, int y) {
|
2016-12-25 13:19:54 +01:00
|
|
|
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();
|
2016-12-25 13:58:31 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(StoryboardMover mover : movers) {
|
|
|
|
float prevLen = mover.getLength();
|
|
|
|
if (mover.mouseReleased(x, y)) {
|
|
|
|
mover.recalculateLength();
|
|
|
|
totalLength += mover.getLength() - prevLen;
|
|
|
|
recalculateTimes();
|
2016-12-25 13:19:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2016-12-25 12:16:32 +01:00
|
|
|
moveCurrentPoint(x, y);
|
2016-12-25 12:41:40 +01:00
|
|
|
recalculateLengths();
|
2016-12-25 13:19:54 +01:00
|
|
|
recalculateTimes();
|
2016-12-25 12:16:32 +01:00
|
|
|
currentPoint = null;
|
|
|
|
}
|
2016-12-25 12:41:40 +01:00
|
|
|
recalculateDelay = 700;
|
2016-12-25 12:16:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void recalculateTimes() {
|
|
|
|
for (StoryboardMover mover : movers) {
|
|
|
|
mover.timeLengthPercentOfTotalTime = mover.getLength() / totalLength;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-25 12:41:40 +01:00
|
|
|
private void recalculateLengths() {
|
|
|
|
totalLength -= prevMover.getLength() + nextMover.getLength();
|
|
|
|
prevMover.recalculateLength();
|
|
|
|
nextMover.recalculateLength();
|
|
|
|
totalLength += prevMover.getLength() + nextMover.getLength();
|
|
|
|
recalculateTimes();
|
|
|
|
}
|
|
|
|
|
2016-12-25 12:16:32 +01:00
|
|
|
private void moveCurrentPoint(int x, int y) {
|
|
|
|
currentPoint.x = x;
|
|
|
|
currentPoint.y = y;
|
|
|
|
prevMover.end = currentPoint;
|
|
|
|
nextMover.start = currentPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void render(Graphics g) {
|
2016-12-25 13:19:54 +01:00
|
|
|
g.setColor(Color.red);
|
|
|
|
int y = 200;
|
2016-12-25 12:16:32 +01:00
|
|
|
for (StoryboardMover mover : movers) {
|
|
|
|
mover.render(g);
|
2016-12-25 13:19:54 +01:00
|
|
|
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;
|
2016-12-25 14:19:08 +01:00
|
|
|
RenderUtils.fillCenteredRect(g, screenWidth - 20, y - dif / 2, 5);
|
2016-12-25 12:16:32 +01:00
|
|
|
}
|
|
|
|
g.setColor(Color.cyan);
|
|
|
|
for (Vec2f point : midPoints) {
|
2016-12-25 14:19:08 +01:00
|
|
|
RenderUtils.fillCenteredRect(g, point.x, point.y, POINTSIZE);
|
2016-12-25 12:16:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|