2016-12-25 12:42:09 +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.GameObject;
|
|
|
|
import itdelatrisu.opsu.ui.Colors;
|
|
|
|
import itdelatrisu.opsu.ui.Fonts;
|
|
|
|
import itdelatrisu.opsu.ui.UI;
|
2016-12-25 15:46:11 +01:00
|
|
|
import itdelatrisu.opsu.ui.animations.AnimationEquation;
|
|
|
|
import org.newdawn.slick.Color;
|
2016-12-25 12:42:09 +01:00
|
|
|
import org.newdawn.slick.GameContainer;
|
|
|
|
import org.newdawn.slick.Graphics;
|
2017-01-19 19:23:31 +01:00
|
|
|
import yugecin.opsudance.core.DisplayContainer;
|
|
|
|
import yugecin.opsudance.core.state.OverlayOpsuState;
|
2016-12-25 14:23:10 +01:00
|
|
|
import yugecin.opsudance.sbv2.movers.CubicStoryboardMover;
|
2016-12-25 12:42:09 +01:00
|
|
|
import yugecin.opsudance.sbv2.movers.LinearStoryboardMover;
|
2016-12-25 13:58:31 +01:00
|
|
|
import yugecin.opsudance.sbv2.movers.QuadraticStoryboardMover;
|
2016-12-25 12:42:09 +01:00
|
|
|
import yugecin.opsudance.ui.SimpleButton;
|
|
|
|
|
|
|
|
import java.lang.reflect.InvocationHandler;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.lang.reflect.Proxy;
|
|
|
|
|
2017-01-19 19:23:31 +01:00
|
|
|
public class MoveStoryboard extends OverlayOpsuState{
|
2016-12-25 12:42:09 +01:00
|
|
|
|
2017-01-19 19:23:31 +01:00
|
|
|
private final DisplayContainer displayContainer;
|
2016-12-25 12:42:09 +01:00
|
|
|
|
2017-01-19 19:23:31 +01:00
|
|
|
private SimpleButton btnAddLinear;
|
|
|
|
private SimpleButton btnAddQuadratic;
|
|
|
|
private SimpleButton btnAddCubic;
|
2016-12-25 15:46:11 +01:00
|
|
|
|
2017-01-19 19:23:31 +01:00
|
|
|
private SimpleButton btnAnimLin;
|
|
|
|
private SimpleButton btnAnimMid;
|
|
|
|
private SimpleButton btnAnimCub;
|
2016-12-25 12:42:09 +01:00
|
|
|
|
2017-01-19 19:23:31 +01:00
|
|
|
private final StoryboardMove dummyMove;
|
2016-12-25 12:42:09 +01:00
|
|
|
|
|
|
|
private StoryboardMove[] moves;
|
|
|
|
|
|
|
|
private GameObject[] gameObjects;
|
|
|
|
private int objectIndex;
|
|
|
|
|
|
|
|
private int trackPosition;
|
|
|
|
|
2017-01-19 19:23:31 +01:00
|
|
|
public MoveStoryboard(DisplayContainer displayContainer) {
|
|
|
|
this.displayContainer = displayContainer;
|
2016-12-25 12:42:09 +01:00
|
|
|
dummyMove = (StoryboardMove) Proxy.newProxyInstance(StoryboardMove.class.getClassLoader(), new Class<?>[]{StoryboardMove.class}, new InvocationHandler() {
|
|
|
|
@Override
|
|
|
|
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-01-19 19:23:31 +01:00
|
|
|
@Override
|
|
|
|
public void revalidate() {
|
2017-01-21 13:29:10 +01:00
|
|
|
super.revalidate();
|
|
|
|
|
2017-01-19 19:23:31 +01:00
|
|
|
btnAddLinear = new SimpleButton(displayContainer.width - 205, 50, 200, 25, Fonts.SMALL, "add linear", Colors.BLUE_BUTTON, Colors.WHITE_FADE, Colors.WHITE_FADE, Colors.ORANGE_BUTTON);
|
|
|
|
btnAddQuadratic = new SimpleButton(displayContainer.width - 205, 80, 200, 25, Fonts.SMALL, "add quadratic", Colors.BLUE_BUTTON, Colors.WHITE_FADE, Colors.WHITE_FADE, Colors.ORANGE_BUTTON);
|
|
|
|
btnAddCubic = new SimpleButton(displayContainer.width - 205, 110, 200, 25, Fonts.SMALL, "add cubic", Colors.BLUE_BUTTON, Colors.WHITE_FADE, Colors.WHITE_FADE, Colors.ORANGE_BUTTON);
|
|
|
|
btnAnimLin = new SimpleButton(displayContainer.width - 250, 50, 40, 25, Fonts.SMALL, "lin", Color.blue, Color.white, Color.white, Color.orange);
|
|
|
|
btnAnimMid = new SimpleButton(displayContainer.width - 250, 80, 40, 25, Fonts.SMALL, "mid", Color.blue, Color.white, Color.white, Color.orange);
|
|
|
|
btnAnimCub = new SimpleButton(displayContainer.width - 250, 110, 40, 25, Fonts.SMALL, "cub", Color.blue, Color.white, Color.white, Color.orange);
|
|
|
|
}
|
|
|
|
|
2016-12-25 12:42:09 +01:00
|
|
|
/**
|
|
|
|
* Get the point at the current time
|
|
|
|
* @param trackPosition current time in ms
|
|
|
|
* @return point calculated by the storyboardmover or null if there is no mover
|
|
|
|
*/
|
|
|
|
public float[] getPoint(int trackPosition) {
|
|
|
|
this.trackPosition = trackPosition;
|
|
|
|
if (moves[objectIndex] == null || objectIndex == 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (trackPosition < gameObjects[objectIndex - 1].getEndTime() || trackPosition > gameObjects[objectIndex].getTime()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
float t = (float) (trackPosition - gameObjects[objectIndex - 1].getEndTime()) / (gameObjects[objectIndex].getTime() - gameObjects[objectIndex - 1].getEndTime());
|
|
|
|
return moves[objectIndex].getPointAt(t);
|
|
|
|
}
|
|
|
|
|
2017-01-19 19:23:31 +01:00
|
|
|
@Override
|
|
|
|
protected void onPreRenderUpdate() {
|
|
|
|
int x = displayContainer.mouseX;
|
|
|
|
int y = displayContainer.mouseY;
|
|
|
|
btnAddLinear.update(x, y);
|
|
|
|
btnAddQuadratic.update(x, y);
|
|
|
|
btnAddCubic.update(x, y);
|
|
|
|
btnAnimLin.update(x, y);
|
|
|
|
btnAnimMid.update(x, y);
|
|
|
|
btnAnimCub.update(x, y);
|
|
|
|
if (moves[objectIndex] != null) {
|
|
|
|
moves[objectIndex].update(displayContainer.renderDelta, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onRender(Graphics g) {
|
2016-12-25 12:42:09 +01:00
|
|
|
btnAddLinear.render(g);
|
|
|
|
btnAddQuadratic.render(g);
|
|
|
|
btnAddCubic.render(g);
|
2016-12-25 15:46:11 +01:00
|
|
|
btnAnimLin.render(g);
|
2016-12-25 16:22:09 +01:00
|
|
|
btnAnimMid.render(g);
|
2016-12-25 15:46:11 +01:00
|
|
|
btnAnimCub.render(g);
|
2016-12-25 12:42:09 +01:00
|
|
|
if (moves[objectIndex] != null && objectIndex > 0 && trackPosition >= gameObjects[objectIndex - 1].getEndTime() && trackPosition < gameObjects[objectIndex].getTime()) {
|
2016-12-25 13:19:54 +01:00
|
|
|
moves[objectIndex].render(g);
|
2016-12-25 12:42:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-19 19:23:31 +01:00
|
|
|
@Override
|
|
|
|
protected boolean onKeyPressed(int key, char c) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean onKeyReleased(int key, char c) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean onMouseWheelMoved(int delta) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean onMousePressed(int button, int x, int y) {
|
2016-12-25 12:42:09 +01:00
|
|
|
if (moves[objectIndex] != null) {
|
|
|
|
moves[objectIndex].mousePressed(x, y);
|
|
|
|
}
|
2017-01-19 19:23:31 +01:00
|
|
|
return true;
|
2016-12-25 12:42:09 +01:00
|
|
|
}
|
|
|
|
|
2017-01-19 19:23:31 +01:00
|
|
|
@Override
|
|
|
|
protected boolean onMouseReleased(int button, int x, int y) {
|
2016-12-25 12:42:09 +01:00
|
|
|
if (moves[objectIndex] != null) {
|
|
|
|
moves[objectIndex].mouseReleased(x, y);
|
2016-12-25 13:19:54 +01:00
|
|
|
if (moves[objectIndex].getAmountOfMovers() == 0) {
|
|
|
|
moves[objectIndex] = null;
|
|
|
|
}
|
2016-12-25 12:42:09 +01:00
|
|
|
}
|
|
|
|
if (objectIndex == 0) {
|
2017-01-19 19:23:31 +01:00
|
|
|
return true;
|
2016-12-25 12:42:09 +01:00
|
|
|
}
|
|
|
|
if (btnAddLinear.isHovered()) {
|
|
|
|
getCurrentMoveOrCreateNew().add(new LinearStoryboardMover());
|
|
|
|
}
|
|
|
|
if (btnAddQuadratic.isHovered()) {
|
2016-12-25 13:58:31 +01:00
|
|
|
getCurrentMoveOrCreateNew().add(new QuadraticStoryboardMover());
|
2016-12-25 12:42:09 +01:00
|
|
|
}
|
|
|
|
if (btnAddCubic.isHovered()) {
|
2016-12-25 14:23:10 +01:00
|
|
|
getCurrentMoveOrCreateNew().add(new CubicStoryboardMover());
|
2016-12-25 12:42:09 +01:00
|
|
|
}
|
2016-12-25 15:46:11 +01:00
|
|
|
if (btnAnimLin.isHovered()) {
|
|
|
|
getCurrentMoveOrDummy().setAnimationEquation(AnimationEquation.LINEAR);
|
|
|
|
}
|
2016-12-25 16:22:09 +01:00
|
|
|
if (btnAnimMid.isHovered()) {
|
2016-12-25 15:46:11 +01:00
|
|
|
getCurrentMoveOrDummy().setAnimationEquation(AnimationEquation.IN_OUT_CIRC);
|
|
|
|
}
|
|
|
|
if (btnAnimCub.isHovered()) {
|
2016-12-25 16:22:09 +01:00
|
|
|
getCurrentMoveOrDummy().setAnimationEquation(AnimationEquation.IN_OUT_EASE_MIDDLE);
|
2016-12-25 15:46:11 +01:00
|
|
|
}
|
2017-01-19 19:23:31 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean onMouseDragged(int oldx, int oldy, int newx, int newy) {
|
|
|
|
return false;
|
2016-12-25 12:42:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private StoryboardMove getCurrentMoveOrCreateNew() {
|
|
|
|
if (gameObjects[objectIndex].isSlider() && trackPosition > gameObjects[objectIndex].getTime() && trackPosition < gameObjects[objectIndex].getEndTime()) {
|
|
|
|
UI.sendBarNotification("wait until the slider ended");
|
|
|
|
return dummyMove;
|
|
|
|
}
|
|
|
|
if (moves[objectIndex] == null) {
|
2017-01-19 19:23:31 +01:00
|
|
|
return moves[objectIndex] = new StoryboardMoveImpl(gameObjects[objectIndex - 1].end, gameObjects[objectIndex].start, displayContainer.width);
|
2016-12-25 12:42:09 +01:00
|
|
|
}
|
|
|
|
return moves[objectIndex];
|
|
|
|
}
|
|
|
|
|
2016-12-25 15:46:11 +01:00
|
|
|
private StoryboardMove getCurrentMoveOrDummy() {
|
|
|
|
if (objectIndex < 0 || gameObjects.length <= objectIndex || moves[objectIndex] == null) {
|
|
|
|
return dummyMove;
|
|
|
|
}
|
|
|
|
return moves[objectIndex];
|
|
|
|
}
|
|
|
|
|
2016-12-25 12:42:09 +01:00
|
|
|
public void setGameObjects(GameObject[] gameObjects) {
|
|
|
|
this.gameObjects = gameObjects;
|
|
|
|
this.moves = new StoryboardMove[gameObjects.length];
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setIndex(int objectIndex) {
|
|
|
|
this.objectIndex = objectIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|