From f466fafa03a7a03d20c9f34be5c443d6f68980e7 Mon Sep 17 00:00:00 2001 From: yugecin Date: Sat, 12 Nov 2016 23:13:41 +0100 Subject: [PATCH] skip through objects --- src/itdelatrisu/opsu/states/Game.java | 55 +++++++++++++++++++- src/yugecin/opsudance/ui/OptionsOverlay.java | 1 - src/yugecin/opsudance/ui/SBOverlay.java | 34 +++++++++++- 3 files changed, 87 insertions(+), 3 deletions(-) diff --git a/src/itdelatrisu/opsu/states/Game.java b/src/itdelatrisu/opsu/states/Game.java index 76320afe..50c1b138 100644 --- a/src/itdelatrisu/opsu/states/Game.java +++ b/src/itdelatrisu/opsu/states/Game.java @@ -277,7 +277,54 @@ public class Game extends BasicGameState { public Game(int state) { this.state = state; mirrorCursor = new Cursor(true); - sbOverlay = new SBOverlay(); + sbOverlay = new SBOverlay(this); + } + + public void setObjectIndex(int newObjIndex) { + try { + /* + + restart = Restart.MANUAL; + enter(container, game); + checkpointLoaded = true; + if (isLeadIn()) { + leadInTime = 0; + MusicController.resume(); + } + SoundController.playSound(SoundEffect.MENUHIT); + UI.sendBarNotification("Checkpoint loaded."); + + // skip to checkpoint + MusicController.setPosition(checkpoint); + MusicController.setPitch(GameMod.getSpeedMultiplier() * playbackSpeed.getModifier()); + while (objectIndex < gameObjects.length && + beatmap.objects[objectIndex++].getTime() <= checkpoint) + ; + objectIndex--; + lastReplayTime = beatmap.objects[objectIndex].getTime(); + } catch (SlickException e) { + ErrorHandler.error("Failed to load checkpoint.", e, false); + } + */ + restart = Restart.MANUAL; + enter(container, game); + checkpointLoaded = true; + if (isLeadIn()) { + leadInTime = 0; + MusicController.resume(); + } + int checkpoint = gameObjects[newObjIndex].getTime(); + // skip to checkpoint + MusicController.setPosition(checkpoint); + while (objectIndex < gameObjects.length && beatmap.objects[objectIndex].getTime() <= checkpoint) { + objectIndex++; + } + objectIndex--; + sbOverlay.updateIndex(objectIndex); + lastReplayTime = beatmap.objects[objectIndex].getTime(); + } catch (SlickException e) { + e.printStackTrace(); + } } @Override @@ -918,6 +965,7 @@ public class Game extends BasicGameState { // update hit object and check completion status if (gameObjects[objectIndex].update(overlap, delta, mouseX, mouseY, keyPressed, trackPosition)) { objectIndex++; // done, so increment object index + sbOverlay.updateIndex(objectIndex); if (objectIndex >= mirrorTo) { Dancer.mirror = false; } @@ -1249,6 +1297,11 @@ public class Game extends BasicGameState { // grab the mouse (not working for touchscreen) // container.setMouseGrabbed(true); + + if (!checkpointLoaded) { + sbOverlay.updateIndex(0); + } + // restart the game if (restart != Restart.FALSE) { // load mods diff --git a/src/yugecin/opsudance/ui/OptionsOverlay.java b/src/yugecin/opsudance/ui/OptionsOverlay.java index a4a23bdd..c2c1a1e1 100644 --- a/src/yugecin/opsudance/ui/OptionsOverlay.java +++ b/src/yugecin/opsudance/ui/OptionsOverlay.java @@ -53,7 +53,6 @@ public class OptionsOverlay { Options.GameOption.DANCE_REMOVE_BG, Options.GameOption.DANCE_HIDE_OBJECTS, Options.GameOption.DANCE_HIDE_UI, - Options.GameOption.DANCE_HIDE_WATERMARK, Options.GameOption.PIPPI_ENABLE, Options.GameOption.PIPPI_ANGLE_INC_MUL, Options.GameOption.PIPPI_ANGLE_INC_MUL_SLIDER, diff --git a/src/yugecin/opsudance/ui/SBOverlay.java b/src/yugecin/opsudance/ui/SBOverlay.java index d914c277..32bb4d79 100644 --- a/src/yugecin/opsudance/ui/SBOverlay.java +++ b/src/yugecin/opsudance/ui/SBOverlay.java @@ -19,6 +19,7 @@ package yugecin.opsudance.ui; import itdelatrisu.opsu.audio.MusicController; import itdelatrisu.opsu.objects.GameObject; +import itdelatrisu.opsu.states.Game; import itdelatrisu.opsu.ui.Fonts; import org.newdawn.slick.Color; import org.newdawn.slick.Graphics; @@ -40,9 +41,13 @@ public class SBOverlay { private GameObject[] gameObjects; private HashMap[] optionsMap; + private int index; + + private final Game game; private final OptionsOverlay options; - public SBOverlay() { + public SBOverlay(Game game) { + this.game = game; options = new OptionsOverlay(); } @@ -62,6 +67,7 @@ public class SBOverlay { Fonts.SMALL.drawString(10, height - 50, "speed: C " + (speed / 10f) + " V", Color.cyan); Fonts.SMALL.drawString(10, height - 50 - lh, "Menu: N", Color.cyan); Fonts.SMALL.drawString(10, height - 50 - lh * 2, "HIDE: H", Color.cyan); + Fonts.SMALL.drawString(10, height - 50 - lh * 3, "obj: J " + index + " K", Color.cyan); if (menu) { options.render(g); } @@ -97,10 +103,31 @@ public class SBOverlay { hide = !hide; } else if (key == Input.KEY_N) { menu = !menu; + if (menu && speed != 0) { + MusicController.pause(); + } else if (!menu && speed != 0) { + MusicController.resume(); + } + } else if (key == Input.KEY_J && index > 0) { + index--; + setMusicPosition(); + } else if (key == Input.KEY_K && index < gameObjects.length - 1) { + index++; + setMusicPosition(); } return false; } + private void setMusicPosition() { + game.setObjectIndex(index); + if (speed != 0) { + MusicController.setPitch(speed / 10f); + MusicController.resume(); + } else { + MusicController.pause(); + } + } + public void setGameObjects(GameObject[] gameObjects) { if (this.gameObjects.length != gameObjects.length) { optionsMap = new HashMap[gameObjects.length]; @@ -115,4 +142,9 @@ public class SBOverlay { public void mouseDragged(int oldx, int oldy, int newx, int newy) { if (menu) options.mouseDragged(oldx, oldy, newx, newy); } + + public void updateIndex(int index) { + this.index = index; + } + }