diff --git a/src/itdelatrisu/opsu/GameImage.java b/src/itdelatrisu/opsu/GameImage.java index 299f0f21..3eeb9e47 100644 --- a/src/itdelatrisu/opsu/GameImage.java +++ b/src/itdelatrisu/opsu/GameImage.java @@ -257,9 +257,18 @@ public enum GameImage { return img.getScaledCopy((h / 1.2f) / img.getHeight()); } }, - // TODO: scale MENU_PLAY and MENU_EXIT - MENU_PlAY ("menu-play.png", false), - MENU_EXIT ("menu-exit.png", false), + MENU_PlAY ("menu-play.png", false) { + @Override + protected Image process_sub(Image img, int w, int h) { + return img.getScaledCopy(MENU_LOGO.getImage().getWidth() * 0.83f / img.getWidth()); + } + }, + MENU_EXIT ("menu-exit.png", false) { + @Override + protected Image process_sub(Image img, int w, int h) { + return img.getScaledCopy(MENU_LOGO.getImage().getWidth() * 0.66f / img.getWidth()); + } + }, MENU_BUTTON_MID ("button-middle.png", false) { @Override protected Image process_sub(Image img, int w, int h) { diff --git a/src/itdelatrisu/opsu/audio/MusicController.java b/src/itdelatrisu/opsu/audio/MusicController.java index 2bd2dcce..cf4d0515 100644 --- a/src/itdelatrisu/opsu/audio/MusicController.java +++ b/src/itdelatrisu/opsu/audio/MusicController.java @@ -66,6 +66,11 @@ public class MusicController { */ private static boolean themePlaying = false; + /** + * Track pause time. + */ + private static float pauseTime = 0f; + // This class should not be instantiated. private MusicController() {} @@ -141,6 +146,7 @@ public class MusicController { player.loop(); else player.play(); + pauseTime = 0f; } } @@ -205,12 +211,21 @@ public class MusicController { return (trackExists() && player.playing()); } + /** + * Returns true if the current track is paused. + */ + public static boolean isPaused() { + return (trackExists() && pauseTime > 0f); + } + /** * Pauses the current track. */ public static void pause() { - if (isPlaying()) + if (isPlaying()) { + pauseTime = player.getPosition(); player.pause(); + } } /** @@ -218,6 +233,7 @@ public class MusicController { */ public static void resume() { if (trackExists()) { + pauseTime = 0f; player.resume(); player.setVolume(1.0f); } @@ -241,11 +257,13 @@ public class MusicController { /** * Returns the position in the current track, in ms. - * If no track is playing, 0 will be returned. + * If no track is loaded, 0 will be returned. */ public static int getPosition() { if (isPlaying()) return Math.max((int) (player.getPosition() * 1000 + Options.getMusicOffset()), 0); + else if (isPaused()) + return Math.max((int) (pauseTime * 1000 + Options.getMusicOffset()), 0); else return 0; } diff --git a/src/itdelatrisu/opsu/states/Game.java b/src/itdelatrisu/opsu/states/Game.java index d8f3132c..dd28e173 100644 --- a/src/itdelatrisu/opsu/states/Game.java +++ b/src/itdelatrisu/opsu/states/Game.java @@ -61,11 +61,12 @@ public class Game extends BasicGameState { /** * Game restart states. */ - public static final byte - RESTART_FALSE = 0, - RESTART_NEW = 1, // first time loading song - RESTART_MANUAL = 2, // retry - RESTART_LOSE = 3; // health is zero: no-continue/force restart + public enum Restart { + FALSE, // no restart + NEW, // first time loading song + MANUAL, // retry + LOSE; // health is zero: no-continue/force restart + } /** * Minimum time before start of song, in milliseconds, to process skip-related actions. @@ -120,7 +121,7 @@ public class Game extends BasicGameState { /** * Current restart state. */ - private byte restart; + private Restart restart; /** * Current break index in breaks ArrayList. @@ -570,7 +571,7 @@ public class Game extends BasicGameState { } // game over, force a restart - restart = RESTART_LOSE; + restart = Restart.LOSE; game.enterState(Opsu.STATE_GAMEPAUSEMENU); } @@ -638,7 +639,7 @@ public class Game extends BasicGameState { try { if (trackPosition < osu.objects[0].getTime()) retries--; // don't count this retry (cancel out later increment) - restart = RESTART_MANUAL; + restart = Restart.MANUAL; enter(container, game); skipIntro(); } catch (SlickException e) { @@ -664,7 +665,7 @@ public class Game extends BasicGameState { if (checkpoint == 0 || checkpoint > osu.endTime) break; // invalid checkpoint try { - restart = RESTART_MANUAL; + restart = Restart.MANUAL; enter(container, game); checkpointLoaded = true; if (isLeadIn()) { @@ -740,7 +741,7 @@ public class Game extends BasicGameState { @Override public void enter(GameContainer container, StateBasedGame game) throws SlickException { - if (restart == RESTART_NEW) + if (restart == Restart.NEW) osu = MusicController.getOsuFile(); if (osu == null || osu.objects == null) @@ -750,9 +751,9 @@ public class Game extends BasicGameState { // container.setMouseGrabbed(true); // restart the game - if (restart != RESTART_FALSE) { + if (restart != Restart.FALSE) { // new game - if (restart == RESTART_NEW) { + if (restart == Restart.NEW) { loadImages(); setMapModifiers(); retries = 0; @@ -816,7 +817,7 @@ public class Game extends BasicGameState { } leadInTime = osu.audioLeadIn + approachTime; - restart = RESTART_FALSE; + restart = Restart.FALSE; } skipButton.setScale(1f); @@ -944,8 +945,8 @@ public class Game extends BasicGameState { /** * Sets/returns whether entering the state will restart it. */ - public void setRestart(byte restart) { this.restart = restart; } - public byte getRestart() { return restart; } + public void setRestart(Restart restart) { this.restart = restart; } + public Restart getRestart() { return restart; } /** * Returns whether or not the track is in the lead-in time state. diff --git a/src/itdelatrisu/opsu/states/GamePauseMenu.java b/src/itdelatrisu/opsu/states/GamePauseMenu.java index 912e9d93..6c1ea264 100644 --- a/src/itdelatrisu/opsu/states/GamePauseMenu.java +++ b/src/itdelatrisu/opsu/states/GamePauseMenu.java @@ -85,13 +85,13 @@ public class GamePauseMenu extends BasicGameState { public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException { // background - if (gameState.getRestart() != Game.RESTART_LOSE) + if (gameState.getRestart() != Game.Restart.LOSE) GameImage.PAUSE_OVERLAY.getImage().draw(); else GameImage.FAIL_BACKGROUND.getImage().draw(); // draw buttons - if (gameState.getRestart() != Game.RESTART_LOSE) + if (gameState.getRestart() != Game.Restart.LOSE) continueButton.draw(); retryButton.draw(); backButton.draw(); @@ -126,21 +126,21 @@ public class GamePauseMenu extends BasicGameState { switch (key) { case Input.KEY_ESCAPE: // 'esc' will normally unpause, but will return to song menu if health is zero - if (gameState.getRestart() == Game.RESTART_LOSE) { + if (gameState.getRestart() == Game.Restart.LOSE) { MusicController.stop(); MusicController.playAt(MusicController.getOsuFile().previewTime, true); SoundController.playSound(SoundEffect.MENUBACK); game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); } else { SoundController.playSound(SoundEffect.MENUBACK); - gameState.setRestart(Game.RESTART_FALSE); + gameState.setRestart(Game.Restart.FALSE); game.enterState(Opsu.STATE_GAME); } break; case Input.KEY_R: // restart if (input.isKeyDown(Input.KEY_RCONTROL) || input.isKeyDown(Input.KEY_LCONTROL)) { - gameState.setRestart(Game.RESTART_MANUAL); + gameState.setRestart(Game.Restart.MANUAL); game.enterState(Opsu.STATE_GAME); } break; @@ -155,7 +155,7 @@ public class GamePauseMenu extends BasicGameState { if (button == Input.MOUSE_MIDDLE_BUTTON) return; - boolean loseState = (gameState.getRestart() == Game.RESTART_LOSE); + boolean loseState = (gameState.getRestart() == Game.Restart.LOSE); // if music faded out (i.e. health is zero), don't process any actions before FADEOUT_TIME if (loseState && System.currentTimeMillis() - pauseStartTime < FADEOUT_TIME) @@ -163,11 +163,11 @@ public class GamePauseMenu extends BasicGameState { if (continueButton.contains(x, y) && !loseState) { SoundController.playSound(SoundEffect.MENUBACK); - gameState.setRestart(Game.RESTART_FALSE); + gameState.setRestart(Game.Restart.FALSE); game.enterState(Opsu.STATE_GAME); } else if (retryButton.contains(x, y)) { SoundController.playSound(SoundEffect.MENUHIT); - gameState.setRestart(Game.RESTART_MANUAL); + gameState.setRestart(Game.Restart.MANUAL); game.enterState(Opsu.STATE_GAME); } else if (backButton.contains(x, y)) { MusicController.pause(); // lose state @@ -181,7 +181,7 @@ public class GamePauseMenu extends BasicGameState { public void enter(GameContainer container, StateBasedGame game) throws SlickException { pauseStartTime = System.currentTimeMillis(); - if (gameState.getRestart() == Game.RESTART_LOSE) { + if (gameState.getRestart() == Game.Restart.LOSE) { MusicController.fadeOut(FADEOUT_TIME); SoundController.playSound(SoundEffect.FAIL); } else diff --git a/src/itdelatrisu/opsu/states/GameRanking.java b/src/itdelatrisu/opsu/states/GameRanking.java index df393caa..34cc89a8 100644 --- a/src/itdelatrisu/opsu/states/GameRanking.java +++ b/src/itdelatrisu/opsu/states/GameRanking.java @@ -168,7 +168,7 @@ public class GameRanking extends BasicGameState { if (retryButton.contains(x, y)) { OsuFile osu = MusicController.getOsuFile(); Display.setTitle(String.format("%s - %s", game.getTitle(), osu.toString())); - ((Game) game.getState(Opsu.STATE_GAME)).setRestart(Game.RESTART_MANUAL); + ((Game) game.getState(Opsu.STATE_GAME)).setRestart(Game.Restart.MANUAL); SoundController.playSound(SoundEffect.MENUHIT); game.enterState(Opsu.STATE_GAME, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); } else if (exitButton.contains(x, y)) { diff --git a/src/itdelatrisu/opsu/states/MainMenu.java b/src/itdelatrisu/opsu/states/MainMenu.java index 6d3d160f..02003cc6 100644 --- a/src/itdelatrisu/opsu/states/MainMenu.java +++ b/src/itdelatrisu/opsu/states/MainMenu.java @@ -91,7 +91,7 @@ public class MainMenu extends BasicGameState { /** * Indexes of previous songs. */ - private static Stack previous; + private Stack previous; /** * Main menu background image (optional). @@ -132,24 +132,18 @@ public class MainMenu extends BasicGameState { int height = container.getHeight(); // initialize buttons - // TODO: clean this up, scale in GameImage.process_sub() - Image logoImg = new Image("logo.png"); - float buttonScale = (height / 1.2f) / logoImg.getHeight(); - Image logoImgScaled = GameImage.MENU_LOGO.getImage(); - logo = new MenuButton(logoImgScaled, width / 2f, height / 2f); - logo.setHoverScale(1.05f); - + Image logoImg = GameImage.MENU_LOGO.getImage(); Image playImg = GameImage.MENU_PlAY.getImage(); Image exitImg = GameImage.MENU_EXIT.getImage(); - playImg = playImg.getScaledCopy((logoImg.getWidth() * 0.83f) / playImg.getWidth()); - exitImg = exitImg.getScaledCopy((logoImg.getWidth() * 0.66f) / exitImg.getWidth()); float exitOffset = (playImg.getWidth() - exitImg.getWidth()) / 3f; - playButton = new MenuButton(playImg.getScaledCopy(buttonScale), - width * 0.75f, (height / 2) - (logoImgScaled.getHeight() / 5f) + logo = new MenuButton(logoImg, width / 2f, height / 2f); + playButton = new MenuButton(playImg, + width * 0.75f, (height / 2) - (logoImg.getHeight() / 5f) ); - exitButton = new MenuButton(exitImg.getScaledCopy(buttonScale), + exitButton = new MenuButton(exitImg, width * 0.75f - exitOffset, (height / 2) + (exitImg.getHeight() / 2f) ); + logo.setHoverScale(1.05f); playButton.setHoverScale(1.05f); exitButton.setHoverScale(1.05f); diff --git a/src/itdelatrisu/opsu/states/SongMenu.java b/src/itdelatrisu/opsu/states/SongMenu.java index e621f88f..cb2e914f 100644 --- a/src/itdelatrisu/opsu/states/SongMenu.java +++ b/src/itdelatrisu/opsu/states/SongMenu.java @@ -582,6 +582,10 @@ public class SongMenu extends BasicGameState { if (MusicController.isThemePlaying() && focusNode != null) MusicController.play(focusNode.osuFiles.get(focusNode.osuFileIndex), true); + // unpause track + else if (MusicController.isPaused()) + MusicController.resume(); + // destroy skin images, if any GameImage.destroySkinImages(); } @@ -712,7 +716,7 @@ public class SongMenu extends BasicGameState { Display.setTitle(String.format("%s - %s", game.getTitle(), osu.toString())); OsuParser.parseHitObjects(osu); HitSound.setSampleSet(osu.sampleSet); - ((Game) game.getState(Opsu.STATE_GAME)).setRestart(Game.RESTART_NEW); + ((Game) game.getState(Opsu.STATE_GAME)).setRestart(Game.Restart.NEW); game.enterState(Opsu.STATE_GAME, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); } }