From f95d1c466976ecd4751d9c8e283c8d8d1f074dc5 Mon Sep 17 00:00:00 2001 From: yugecin Date: Sun, 4 Dec 2016 13:23:37 +0100 Subject: [PATCH 1/8] add quadratic bezier mover --- src/yugecin/opsudance/Dancer.java | 3 + .../movers/QuadraticBezierMover.java | 71 +++++++++++++++++++ .../QuadraticBezierMoverFactory.java | 36 ++++++++++ 3 files changed, 110 insertions(+) create mode 100644 src/yugecin/opsudance/movers/QuadraticBezierMover.java create mode 100644 src/yugecin/opsudance/movers/factories/QuadraticBezierMoverFactory.java diff --git a/src/yugecin/opsudance/Dancer.java b/src/yugecin/opsudance/Dancer.java index fe56baac..b8b63d94 100644 --- a/src/yugecin/opsudance/Dancer.java +++ b/src/yugecin/opsudance/Dancer.java @@ -33,6 +33,7 @@ import itdelatrisu.opsu.objects.Slider; import itdelatrisu.opsu.objects.curves.Vec2f; import yugecin.opsudance.movers.LinearMover; import yugecin.opsudance.movers.Mover; +import yugecin.opsudance.movers.QuadraticBezierMover; import yugecin.opsudance.movers.factories.*; import yugecin.opsudance.movers.slidermovers.DefaultSliderMoverController; import yugecin.opsudance.movers.slidermovers.InheritedSliderMoverController; @@ -55,6 +56,7 @@ public class Dancer { new CenterSpiralMoverFactory(), //new LinearFactory(), new ArcFactory(), + new QuadraticBezierMoverFactory(), }; public static Spinner[] spinners = new Spinner[] { @@ -131,6 +133,7 @@ public class Dancer { for (Spinner s : spinners) { s.init(); } + QuadraticBezierMover.reset(); } public int getSpinnerIndex() { diff --git a/src/yugecin/opsudance/movers/QuadraticBezierMover.java b/src/yugecin/opsudance/movers/QuadraticBezierMover.java new file mode 100644 index 00000000..94c75dbc --- /dev/null +++ b/src/yugecin/opsudance/movers/QuadraticBezierMover.java @@ -0,0 +1,71 @@ +/* + * 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 . + */ +package yugecin.opsudance.movers; + +import itdelatrisu.opsu.Utils; +import itdelatrisu.opsu.objects.GameObject; + +import java.awt.*; + +public class QuadraticBezierMover extends Mover { + + private static Point p; + private static double prevspeed; + + public static void reset() { + p = new Point(0, 0); + prevspeed = 0; + } + + private int startTime; + private int totalTime; + + public QuadraticBezierMover(GameObject start, GameObject end, int dir) { + super(start, end, dir); + this.startTime = start.getEndTime(); + this.totalTime = end.getTime() - startTime; + + double startAngle = Math.atan2(startY - p.y, startX - p.x); + double angDiff = Math.atan2(startY - endY, startX - endX) - startAngle; + while (angDiff < 0) angDiff += Math.PI; + while (angDiff > Math.PI) angDiff -= Math.PI; + angDiff -= Math.PI / 2; + if (angDiff < 0) angDiff = -angDiff; + double dist = Utils.distance(startX, startY, endX, endY); + //double speed = dist / 10 + dist * (Math.PI - angDiff) / Math.PI; + p.x = (int) (startX + Math.cos(startAngle) * prevspeed); + p.y = (int) (startY + Math.sin(startAngle) * prevspeed); + prevspeed = (dist / totalTime) * 50; + } + + @Override + public double[] getPointAt(int time) { + double t = (double) (time - startTime) / totalTime; + double ct = (1 - t); + return new double[] { + ct * ct * startX + ct * 2 * t * p.x + t * t * endX, + ct * ct * startY + ct * 2 * t * p.y + t * t * endY, + }; + } + + @Override + public String getName() { + return "Quadratic Bezier"; + } + +} diff --git a/src/yugecin/opsudance/movers/factories/QuadraticBezierMoverFactory.java b/src/yugecin/opsudance/movers/factories/QuadraticBezierMoverFactory.java new file mode 100644 index 00000000..d37c2710 --- /dev/null +++ b/src/yugecin/opsudance/movers/factories/QuadraticBezierMoverFactory.java @@ -0,0 +1,36 @@ +/* + * 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 . + */ +package yugecin.opsudance.movers.factories; + +import itdelatrisu.opsu.objects.GameObject; +import yugecin.opsudance.movers.Mover; +import yugecin.opsudance.movers.QuadraticBezierMover; + +public class QuadraticBezierMoverFactory implements MoverFactory { + + @Override + public Mover create(GameObject start, GameObject end, int dir) { + return new QuadraticBezierMover(start, end, dir); + } + + @Override + public String toString() { + return "Quadratic bezier"; + } + +} From 3c15aeb9bdaaa0ffaaf130d5fd3e380fe3b5b601 Mon Sep 17 00:00:00 2001 From: yugecin Date: Sun, 4 Dec 2016 13:37:00 +0100 Subject: [PATCH 2/8] add aggressiveness in optionmenu --- src/itdelatrisu/opsu/Options.java | 9 +++++++++ src/yugecin/opsudance/movers/QuadraticBezierMover.java | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/itdelatrisu/opsu/Options.java b/src/itdelatrisu/opsu/Options.java index eefa7ada..4004d89f 100644 --- a/src/itdelatrisu/opsu/Options.java +++ b/src/itdelatrisu/opsu/Options.java @@ -56,6 +56,7 @@ import com.sun.jna.platform.win32.Advapi32Util; import com.sun.jna.platform.win32.Win32Exception; import com.sun.jna.platform.win32.WinReg; import yugecin.opsudance.*; +import yugecin.opsudance.movers.QuadraticBezierMover; import yugecin.opsudance.movers.factories.AutoMoverFactory; import yugecin.opsudance.spinners.Spinner; import yugecin.opsudance.ui.SBOverlay; @@ -623,6 +624,14 @@ public class Options { } }, + DANCE_QUAD_BEZ_AGRESSIVE ("Quadratic Bezier aggressiveness", "QuadBezAgr", "AKA initial D factor", 500, 0, 2000) { + @Override + public void read(String s) { + super.read(s); + QuadraticBezierMover.aggressiveness = val / 10; + } + }, + DANCE_MOVER_DIRECTION ("Mover direction", "MoverDirection", "The direction the mover goes" ) { @Override public String getValueString() { diff --git a/src/yugecin/opsudance/movers/QuadraticBezierMover.java b/src/yugecin/opsudance/movers/QuadraticBezierMover.java index 94c75dbc..bedfd953 100644 --- a/src/yugecin/opsudance/movers/QuadraticBezierMover.java +++ b/src/yugecin/opsudance/movers/QuadraticBezierMover.java @@ -24,6 +24,7 @@ import java.awt.*; public class QuadraticBezierMover extends Mover { + public static int aggressiveness = 50; private static Point p; private static double prevspeed; @@ -50,7 +51,7 @@ public class QuadraticBezierMover extends Mover { //double speed = dist / 10 + dist * (Math.PI - angDiff) / Math.PI; p.x = (int) (startX + Math.cos(startAngle) * prevspeed); p.y = (int) (startY + Math.sin(startAngle) * prevspeed); - prevspeed = (dist / totalTime) * 50; + prevspeed = (dist / totalTime) * aggressiveness; } @Override From e2453db9d5faa2c727d3c976351d85b9a95a83b7 Mon Sep 17 00:00:00 2001 From: yugecin Date: Sun, 4 Dec 2016 13:40:41 +0100 Subject: [PATCH 3/8] add showcondition for options --- src/itdelatrisu/opsu/Options.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/itdelatrisu/opsu/Options.java b/src/itdelatrisu/opsu/Options.java index 4004d89f..b7a78f5a 100644 --- a/src/itdelatrisu/opsu/Options.java +++ b/src/itdelatrisu/opsu/Options.java @@ -58,6 +58,7 @@ import com.sun.jna.platform.win32.WinReg; import yugecin.opsudance.*; import yugecin.opsudance.movers.QuadraticBezierMover; import yugecin.opsudance.movers.factories.AutoMoverFactory; +import yugecin.opsudance.movers.factories.QuadraticBezierMoverFactory; import yugecin.opsudance.spinners.Spinner; import yugecin.opsudance.ui.SBOverlay; @@ -625,6 +626,11 @@ public class Options { }, DANCE_QUAD_BEZ_AGRESSIVE ("Quadratic Bezier aggressiveness", "QuadBezAgr", "AKA initial D factor", 500, 0, 2000) { + @Override + public boolean showCondition() { + return Dancer.moverFactories[Dancer.instance.getMoverFactoryIndex()] instanceof QuadraticBezierMoverFactory; + } + @Override public void read(String s) { super.read(s); @@ -1261,6 +1267,13 @@ public class Options { this.type = OptionType.NUMERIC; } + /** + * should the option be shown + * @return true if the option should be shown + */ + public boolean showCondition() { + return true; + } /** * Returns the option name. * @return the name string From 27be84e99a18622474878349d81403f7139e282b Mon Sep 17 00:00:00 2001 From: yugecin Date: Sun, 4 Dec 2016 13:49:35 +0100 Subject: [PATCH 4/8] hide options with failing showcondition --- src/itdelatrisu/opsu/states/OptionsMenu.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/itdelatrisu/opsu/states/OptionsMenu.java b/src/itdelatrisu/opsu/states/OptionsMenu.java index 847c129b..60196f92 100644 --- a/src/itdelatrisu/opsu/states/OptionsMenu.java +++ b/src/itdelatrisu/opsu/states/OptionsMenu.java @@ -113,6 +113,7 @@ public class OptionsMenu extends BasicGameState { }), DANCE ("Dance", new GameOption[] { GameOption.DANCE_MOVER, + GameOption.DANCE_QUAD_BEZ_AGRESSIVE, GameOption.DANCE_MOVER_DIRECTION, GameOption.DANCE_SLIDER_MOVER_TYPE, GameOption.DANCE_SPINNER, @@ -277,9 +278,12 @@ public class OptionsMenu extends BasicGameState { if (selectedOption != null) { hoverOption = selectedOption; } - for (int i = 0; i < currentTab.options.length; i++) { + for (int i = 0, j = 0; i < currentTab.options.length; i++) { GameOption option = currentTab.options[i]; - drawOption(option, i, hoverOption == option); + if (!option.showCondition()) { + continue; + } + drawOption(option, j++, hoverOption == option); } // option tabs @@ -602,6 +606,14 @@ public class OptionsMenu extends BasicGameState { if (index >= currentTab.options.length) return null; + int i = index; + while (i >= 0) { + if (!currentTab.options[i--].showCondition()) { + if (++index >= currentTab.options.length) { + return null; + } + } + } return currentTab.options[index]; } } From e916e73ddbd7269750c742f07854cacebdac22cc Mon Sep 17 00:00:00 2001 From: yugecin Date: Sun, 4 Dec 2016 13:54:26 +0100 Subject: [PATCH 5/8] chagne quadr bez setting sensitivity --- src/itdelatrisu/opsu/Options.java | 9 +++++++-- src/itdelatrisu/opsu/states/OptionsMenu.java | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/itdelatrisu/opsu/Options.java b/src/itdelatrisu/opsu/Options.java index b7a78f5a..f4764165 100644 --- a/src/itdelatrisu/opsu/Options.java +++ b/src/itdelatrisu/opsu/Options.java @@ -625,7 +625,12 @@ public class Options { } }, - DANCE_QUAD_BEZ_AGRESSIVE ("Quadratic Bezier aggressiveness", "QuadBezAgr", "AKA initial D factor", 500, 0, 2000) { + DANCE_QUAD_BEZ_AGGRESSIVENESS ("Quadratic Bezier aggressiveness", "QuadBezAgr", "AKA initial D factor", 50, 0, 200) { + @Override + public String getValueString() { + return val + ""; + } + @Override public boolean showCondition() { return Dancer.moverFactories[Dancer.instance.getMoverFactoryIndex()] instanceof QuadraticBezierMoverFactory; @@ -634,7 +639,7 @@ public class Options { @Override public void read(String s) { super.read(s); - QuadraticBezierMover.aggressiveness = val / 10; + QuadraticBezierMover.aggressiveness = val; } }, diff --git a/src/itdelatrisu/opsu/states/OptionsMenu.java b/src/itdelatrisu/opsu/states/OptionsMenu.java index 60196f92..c26265ec 100644 --- a/src/itdelatrisu/opsu/states/OptionsMenu.java +++ b/src/itdelatrisu/opsu/states/OptionsMenu.java @@ -113,7 +113,7 @@ public class OptionsMenu extends BasicGameState { }), DANCE ("Dance", new GameOption[] { GameOption.DANCE_MOVER, - GameOption.DANCE_QUAD_BEZ_AGRESSIVE, + GameOption.DANCE_QUAD_BEZ_AGGRESSIVENESS, GameOption.DANCE_MOVER_DIRECTION, GameOption.DANCE_SLIDER_MOVER_TYPE, GameOption.DANCE_SPINNER, From 7459dd66d0eb7e059a67a4e8b7d84c850988c37c Mon Sep 17 00:00:00 2001 From: yugecin Date: Sun, 4 Dec 2016 13:57:02 +0100 Subject: [PATCH 6/8] add the showcondition to sboverlay options --- src/yugecin/opsudance/ui/OptionsOverlay.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/yugecin/opsudance/ui/OptionsOverlay.java b/src/yugecin/opsudance/ui/OptionsOverlay.java index 33c500f9..22b10cbc 100644 --- a/src/yugecin/opsudance/ui/OptionsOverlay.java +++ b/src/yugecin/opsudance/ui/OptionsOverlay.java @@ -36,6 +36,7 @@ public class OptionsOverlay { private static Options.GameOption[] options = new Options.GameOption[] { Options.GameOption.DANCE_MOVER, + Options.GameOption.DANCE_QUAD_BEZ_AGGRESSIVENESS, Options.GameOption.DANCE_MOVER_DIRECTION, Options.GameOption.DANCE_SLIDER_MOVER_TYPE, Options.GameOption.DANCE_SPINNER, @@ -99,8 +100,12 @@ public class OptionsOverlay { g.setColor(Color.black); g.fillRect(0, 0, width, height); Color.black.a = a; - for (int i = 0; i < options.length; i++) { - drawOption(g, options[i], i, selectedOption == null ? hoverIdx == i : selectedOption == options[i]); + for (int i = 0, j = 0; i < options.length; i++) { + if (!options[i].showCondition()) { + continue; + } + j++; + drawOption(g, options[j], j, selectedOption == null ? hoverIdx == j : selectedOption == options[j]); } if (list.isVisible()) { list.render(container, game, g); @@ -123,6 +128,14 @@ public class OptionsOverlay { if (index >= options.length) { return -1; } + int i = index; + while (i >= 0) { + if (!options[i--].showCondition()) { + if (++index >= options.length) { + return -1; + } + } + } return index; } From 22146e1ac6ec2be248d5173dd688aa051122aa0d Mon Sep 17 00:00:00 2001 From: yugecin Date: Sun, 4 Dec 2016 14:05:18 +0100 Subject: [PATCH 7/8] fix sboverlay showcondition --- src/yugecin/opsudance/ui/OptionsOverlay.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/yugecin/opsudance/ui/OptionsOverlay.java b/src/yugecin/opsudance/ui/OptionsOverlay.java index 22b10cbc..d9cd3d91 100644 --- a/src/yugecin/opsudance/ui/OptionsOverlay.java +++ b/src/yugecin/opsudance/ui/OptionsOverlay.java @@ -104,8 +104,7 @@ public class OptionsOverlay { if (!options[i].showCondition()) { continue; } - j++; - drawOption(g, options[j], j, selectedOption == null ? hoverIdx == j : selectedOption == options[j]); + drawOption(g, options[i], j++, selectedOption == null ? hoverIdx == i : selectedOption == options[i]); } if (list.isVisible()) { list.render(container, game, g); From f91f2bb88faebf20f9a5e2909afeec1e0bb31a6c Mon Sep 17 00:00:00 2001 From: yugecin Date: Sun, 4 Dec 2016 14:31:35 +0100 Subject: [PATCH 8/8] fix aggressiveness not updating --- src/itdelatrisu/opsu/Options.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/itdelatrisu/opsu/Options.java b/src/itdelatrisu/opsu/Options.java index f4764165..86d9a0c6 100644 --- a/src/itdelatrisu/opsu/Options.java +++ b/src/itdelatrisu/opsu/Options.java @@ -631,6 +631,12 @@ public class Options { return val + ""; } + @Override + public void drag(GameContainer container, int d) { + super.drag(container, d); + QuadraticBezierMover.aggressiveness = val; + } + @Override public boolean showCondition() { return Dancer.moverFactories[Dancer.instance.getMoverFactoryIndex()] instanceof QuadraticBezierMoverFactory;