Minor graphical updates and code cleaning.

- Padded game score display, and always display 2 digits in front of the decimal (e.g. 00.00% instead of 0.00%).
- Keep map progress circle at a fixed location instead of basing it off the score length.
- Moved some track resets (pause + restart at preview) to trigger upon loading the song menu.  Fixes weird behaviors when leaving the game state.
- Cleaned up trailing whitespace and added missing overrides.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han
2015-01-16 15:44:13 -05:00
parent be1ec64f28
commit 31a97fbc5d
19 changed files with 95 additions and 60 deletions

View File

@@ -129,7 +129,7 @@ public enum GameMod {
Image img = new Image(filename); Image img = new Image(filename);
float scale = (height * 0.12f) / img.getHeight(); float scale = (height * 0.12f) / img.getHeight();
img = img.getScaledCopy(scale); img = img.getScaledCopy(scale);
// find coordinates // find coordinates
float offsetX = img.getWidth() * 1.5f; float offsetX = img.getWidth() * 1.5f;
float x = (width / 2f) - (offsetX * SIZE / 2.75f); float x = (width / 2f) - (offsetX * SIZE / 2.75f);

View File

@@ -451,20 +451,30 @@ public class GameScore {
* @param firstObject true if the first hit object's start time has not yet passed * @param firstObject true if the first hit object's start time has not yet passed
*/ */
public void drawGameElements(Graphics g, boolean breakPeriod, boolean firstObject) { public void drawGameElements(Graphics g, boolean breakPeriod, boolean firstObject) {
int marginX = (int) (width * 0.008f);
// score // score
drawSymbolString((scoreDisplay < 100000000) ? String.format("%08d", scoreDisplay) : Long.toString(scoreDisplay), drawSymbolString((scoreDisplay < 100000000) ? String.format("%08d", scoreDisplay) : Long.toString(scoreDisplay),
width - 2, 0, 1.0f, true); width - marginX, 0, 1.0f, true);
// score percentage // score percentage
int symbolHeight = getScoreSymbolImage('0').getHeight(); int symbolHeight = getScoreSymbolImage('0').getHeight();
String scorePercentage = String.format("%02.2f%%", getScorePercent()); float scorePercent = getScorePercent();
drawSymbolString(scorePercentage, width - 2, symbolHeight, 0.75f, true); drawSymbolString(
String.format((scorePercent < 10f) ? "0%.2f%%" : "%.2f%%", scorePercent),
width - marginX, symbolHeight, 0.75f, true
);
// map progress circle // map progress circle
g.setAntiAlias(true); g.setAntiAlias(true);
g.setLineWidth(2f); g.setLineWidth(2f);
g.setColor(Color.white); g.setColor(Color.white);
int circleX = width - (getScoreSymbolImage('0').getWidth() * scorePercentage.length()); int circleX = width - marginX - ( // max width: "100.00%"
getScoreSymbolImage('1').getWidth() +
getScoreSymbolImage('0').getWidth() * 4 +
getScoreSymbolImage('.').getWidth() +
getScoreSymbolImage('%').getWidth()
);
float circleDiameter = symbolHeight * 0.75f; float circleDiameter = symbolHeight * 0.75f;
g.drawOval(circleX, symbolHeight, circleDiameter, circleDiameter); g.drawOval(circleX, symbolHeight, circleDiameter, circleDiameter);
@@ -783,7 +793,7 @@ public class GameScore {
combo++; combo++;
if (combo > comboMax) if (combo > comboMax)
comboMax = combo; comboMax = combo;
// combo bursts (at 30, 60, 100+50x) // combo bursts (at 30, 60, 100+50x)
if (Options.isComboBurstEnabled() && if (Options.isComboBurstEnabled() &&
(combo == 30 || combo == 60 || (combo >= 100 && combo % 50 == 0))) { (combo == 30 || combo == 60 || (combo >= 100 && combo % 50 == 0))) {

View File

@@ -18,7 +18,6 @@
package itdelatrisu.opsu; package itdelatrisu.opsu;
import itdelatrisu.opsu.audio.MusicController;
import itdelatrisu.opsu.states.Game; import itdelatrisu.opsu.states.Game;
import itdelatrisu.opsu.states.GamePauseMenu; import itdelatrisu.opsu.states.GamePauseMenu;
import itdelatrisu.opsu.states.GameRanking; import itdelatrisu.opsu.states.GameRanking;
@@ -166,9 +165,9 @@ public class Opsu extends StateBasedGame {
// intercept close requests in game-related states and return to song menu // intercept close requests in game-related states and return to song menu
if (id == STATE_GAME || id == STATE_GAMEPAUSEMENU || id == STATE_GAMERANKING) { if (id == STATE_GAME || id == STATE_GAMEPAUSEMENU || id == STATE_GAMERANKING) {
// start playing track at preview position // start playing track at preview position
MusicController.pause(); SongMenu songMenu = (SongMenu) this.getState(Opsu.STATE_SONGMENU);
MusicController.playAt(MusicController.getOsuFile().previewTime, true); songMenu.resetGameDataOnLoad();
((SongMenu) this.getState(Opsu.STATE_SONGMENU)).resetGameDataOnLoad(); songMenu.resetTrackOnLoad();
this.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); this.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
return false; return false;
} }

View File

@@ -158,7 +158,7 @@ public class OsuFile implements Comparable<OsuFile> {
/** /**
* Compares two OsuFile objects first by overall difficulty, then by total objects. * Compares two OsuFile objects first by overall difficulty, then by total objects.
*/ */
@Override @Override
public int compareTo(OsuFile that) { public int compareTo(OsuFile that) {
int cmp = Float.compare(this.overallDifficulty, that.overallDifficulty); int cmp = Float.compare(this.overallDifficulty, that.overallDifficulty);
if (cmp == 0) if (cmp == 0)

View File

@@ -73,7 +73,7 @@ public class OsuGroupList {
* Returns the single instance of this class. * Returns the single instance of this class.
*/ */
public static OsuGroupList get() { return list; } public static OsuGroupList get() { return list; }
/** /**
* Constructor. * Constructor.
*/ */
@@ -239,7 +239,7 @@ public class OsuGroupList {
} }
/** /**
* Creates a new list of song groups in which each group contains a match to a search query. * Creates a new list of song groups in which each group contains a match to a search query.
* @param query the search query (terms separated by spaces) * @param query the search query (terms separated by spaces)
* @return false if query is the same as the previous one, true otherwise * @return false if query is the same as the previous one, true otherwise
*/ */

View File

@@ -124,7 +124,7 @@ public class OsuGroupNode {
osu.creator); osu.creator);
info[2] = String.format("Length: %d:%02d BPM: %s Objects: %d", info[2] = String.format("Length: %d:%02d BPM: %s Objects: %d",
TimeUnit.MILLISECONDS.toMinutes(osu.endTime), TimeUnit.MILLISECONDS.toMinutes(osu.endTime),
TimeUnit.MILLISECONDS.toSeconds(osu.endTime) - TimeUnit.MILLISECONDS.toSeconds(osu.endTime) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(osu.endTime)), TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(osu.endTime)),
(osu.bpmMax <= 0) ? "--" : (osu.bpmMax <= 0) ? "--" :
((osu.bpmMin == osu.bpmMax) ? osu.bpmMin : String.format("%d-%d", osu.bpmMin, osu.bpmMax)), ((osu.bpmMin == osu.bpmMax) ? osu.bpmMin : String.format("%d-%d", osu.bpmMin, osu.bpmMax)),

View File

@@ -98,7 +98,7 @@ public class Utils {
* Last cursor coordinates. * Last cursor coordinates.
*/ */
private static int lastX = -1, lastY = -1; private static int lastX = -1, lastY = -1;
/** /**
* Stores all previous cursor locations to display a trail. * Stores all previous cursor locations to display a trail.
*/ */
@@ -293,7 +293,7 @@ public class Utils {
/** /**
* Loads the cursor images. * Loads the cursor images.
* @throws SlickException * @throws SlickException
*/ */
public static void loadCursor() throws SlickException { public static void loadCursor() throws SlickException {
// destroy old cursors, if they exist // destroy old cursors, if they exist
@@ -428,7 +428,7 @@ public class Utils {
int dx2 = (dx << 1); // point int dx2 = (dx << 1); // point
int ix = x1 < x2 ? 1 : -1; // increment direction int ix = x1 < x2 ? 1 : -1; // increment direction
int iy = y1 < y2 ? 1 : -1; int iy = y1 < y2 ? 1 : -1;
int k = 5; // sample size int k = 5; // sample size
if (dy <= dx) { if (dy <= dx) {
for (int i = 0; ; i++) { for (int i = 0; ; i++) {

View File

@@ -305,10 +305,10 @@ public class MusicController {
/** /**
* Stops and releases all sources, clears each of the specified Audio * Stops and releases all sources, clears each of the specified Audio
* buffers, destroys the OpenAL context, and resets SoundStore for future use. * buffers, destroys the OpenAL context, and resets SoundStore for future use.
* *
* Calling SoundStore.get().init() will re-initialize the OpenAL context * Calling SoundStore.get().init() will re-initialize the OpenAL context
* after a call to destroyOpenAL (Note: AudioLoader.getXXX calls init for you). * after a call to destroyOpenAL (Note: AudioLoader.getXXX calls init for you).
* *
* @author davedes (http://slick.ninjacave.com/forum/viewtopic.php?t=3920) * @author davedes (http://slick.ninjacave.com/forum/viewtopic.php?t=3920)
*/ */
private static void destroyOpenAL() { private static void destroyOpenAL() {

View File

@@ -124,7 +124,7 @@ public class SoundController {
currentFileName = null; currentFileName = null;
currentFileIndex = -1; currentFileIndex = -1;
} }
/** /**
* Sets the sample volume (modifies the global sample volume). * Sets the sample volume (modifies the global sample volume).
* @param volume the sample volume [0, 1] * @param volume the sample volume [0, 1]

View File

@@ -90,6 +90,7 @@ public class Circle implements HitObject {
this.comboEnd = comboEnd; this.comboEnd = comboEnd;
} }
@Override
public void draw(int trackPosition, boolean currentObject, Graphics g) { public void draw(int trackPosition, boolean currentObject, Graphics g) {
int timeDiff = hitObject.getTime() - trackPosition; int timeDiff = hitObject.getTime() - trackPosition;
@@ -133,6 +134,7 @@ public class Circle implements HitObject {
return result; return result;
} }
@Override
public boolean mousePressed(int x, int y) { public boolean mousePressed(int x, int y) {
double distance = Math.hypot(hitObject.getX() - x, hitObject.getY() - y); double distance = Math.hypot(hitObject.getX() - x, hitObject.getY() - y);
int circleRadius = GameImage.HITCIRCLE.getImage().getWidth() / 2; int circleRadius = GameImage.HITCIRCLE.getImage().getWidth() / 2;
@@ -150,6 +152,7 @@ public class Circle implements HitObject {
return false; return false;
} }
@Override
public boolean update(boolean overlap, int delta, int mouseX, int mouseY) { public boolean update(boolean overlap, int delta, int mouseX, int mouseY) {
int time = hitObject.getTime(); int time = hitObject.getTime();
float x = hitObject.getX(), y = hitObject.getY(); float x = hitObject.getX(), y = hitObject.getY();
@@ -162,7 +165,7 @@ public class Circle implements HitObject {
if (overlap || trackPosition > time + hitResultOffset[GameScore.HIT_50]) { if (overlap || trackPosition > time + hitResultOffset[GameScore.HIT_50]) {
if (isAutoMod) // "auto" mod: catch any missed notes due to lag if (isAutoMod) // "auto" mod: catch any missed notes due to lag
score.hitResult(time, GameScore.HIT_300, x, y, color, comboEnd, hitSound); score.hitResult(time, GameScore.HIT_300, x, y, color, comboEnd, hitSound);
else // no more points can be scored, so send a miss else // no more points can be scored, so send a miss
score.hitResult(time, GameScore.HIT_MISS, x, y, null, comboEnd, hitSound); score.hitResult(time, GameScore.HIT_MISS, x, y, null, comboEnd, hitSound);
return true; return true;

View File

@@ -84,7 +84,7 @@ public class Slider implements HitObject {
* The time duration of the slider, in milliseconds. * The time duration of the slider, in milliseconds.
*/ */
private float sliderTime = 0f; private float sliderTime = 0f;
/** /**
* The time duration of the slider including repeats, in milliseconds. * The time duration of the slider including repeats, in milliseconds.
*/ */
@@ -99,7 +99,7 @@ public class Slider implements HitObject {
* Whether or not to show the follow circle. * Whether or not to show the follow circle.
*/ */
private boolean followCircleActive = false; private boolean followCircleActive = false;
/** /**
* Whether or not the slider result ends the combo streak. * Whether or not the slider result ends the combo streak.
*/ */
@@ -114,12 +114,12 @@ public class Slider implements HitObject {
* The t values of the slider ticks. * The t values of the slider ticks.
*/ */
private float[] ticksT; private float[] ticksT;
/** /**
* The tick index in the ticksT[] array. * The tick index in the ticksT[] array.
*/ */
private int tickIndex = 0; private int tickIndex = 0;
/** /**
* Number of ticks hit and tick intervals so far. * Number of ticks hit and tick intervals so far.
*/ */
@@ -201,7 +201,7 @@ public class Slider implements HitObject {
* Returns the angle of the first control point. * Returns the angle of the first control point.
*/ */
private float getStartAngle() { return startAngle; } private float getStartAngle() { return startAngle; }
/** /**
* Returns the angle of the last control point. * Returns the angle of the last control point.
*/ */
@@ -336,6 +336,7 @@ public class Slider implements HitObject {
this.bezier = new Bezier(); this.bezier = new Bezier();
} }
@Override
public void draw(int trackPosition, boolean currentObject, Graphics g) { public void draw(int trackPosition, boolean currentObject, Graphics g) {
float x = hitObject.getX(), y = hitObject.getY(); float x = hitObject.getX(), y = hitObject.getY();
float[] sliderX = hitObject.getSliderX(), sliderY = hitObject.getSliderY(); float[] sliderX = hitObject.getSliderX(), sliderY = hitObject.getSliderY();
@@ -438,6 +439,7 @@ public class Slider implements HitObject {
return result; return result;
} }
@Override
public boolean mousePressed(int x, int y) { public boolean mousePressed(int x, int y) {
if (sliderClicked) // first circle already processed if (sliderClicked) // first circle already processed
return false; return false;
@@ -448,7 +450,7 @@ public class Slider implements HitObject {
int trackPosition = MusicController.getPosition(); int trackPosition = MusicController.getPosition();
int timeDiff = Math.abs(trackPosition - hitObject.getTime()); int timeDiff = Math.abs(trackPosition - hitObject.getTime());
int[] hitResultOffset = game.getHitResultOffsets(); int[] hitResultOffset = game.getHitResultOffsets();
int result = -1; int result = -1;
if (timeDiff < hitResultOffset[GameScore.HIT_50]) { if (timeDiff < hitResultOffset[GameScore.HIT_50]) {
result = GameScore.HIT_SLIDER30; result = GameScore.HIT_SLIDER30;
@@ -467,6 +469,7 @@ public class Slider implements HitObject {
return false; return false;
} }
@Override
public boolean update(boolean overlap, int delta, int mouseX, int mouseY) { public boolean update(boolean overlap, int delta, int mouseX, int mouseY) {
int repeatCount = hitObject.getRepeatCount(); int repeatCount = hitObject.getRepeatCount();
@@ -490,7 +493,7 @@ public class Slider implements HitObject {
byte hitSound = hitObject.getHitSoundType(); byte hitSound = hitObject.getHitSoundType();
int trackPosition = MusicController.getPosition(); int trackPosition = MusicController.getPosition();
int[] hitResultOffset = game.getHitResultOffsets(); int[] hitResultOffset = game.getHitResultOffsets();
int lastIndex = hitObject.getSliderX().length - 1; int lastIndex = hitObject.getSliderX().length - 1;
boolean isAutoMod = GameMod.AUTO.isActive(); boolean isAutoMod = GameMod.AUTO.isActive();

View File

@@ -71,7 +71,7 @@ public class Spinner implements HitObject {
/** /**
* Initializes the Spinner data type with images and dimensions. * Initializes the Spinner data type with images and dimensions.
* @param container the game container * @param container the game container
* @throws SlickException * @throws SlickException
*/ */
public static void init(GameContainer container) throws SlickException { public static void init(GameContainer container) throws SlickException {
width = container.getWidth(); width = container.getWidth();
@@ -99,6 +99,7 @@ public class Spinner implements HitObject {
rotationsNeeded = spinsPerMinute * (hitObject.getEndTime() - hitObject.getTime()) / 60000f; rotationsNeeded = spinsPerMinute * (hitObject.getEndTime() - hitObject.getTime()) / 60000f;
} }
@Override
public void draw(int trackPosition, boolean currentObject, Graphics g) { public void draw(int trackPosition, boolean currentObject, Graphics g) {
// only draw spinners if current object // only draw spinners if current object
if (!currentObject) if (!currentObject)
@@ -139,7 +140,7 @@ public class Spinner implements HitObject {
score.drawSymbolNumber(extraRotations * 1000, width / 2, height * 2 / 3, 1.0f); score.drawSymbolNumber(extraRotations * 1000, width / 2, height * 2 / 3, 1.0f);
} }
} }
/** /**
* Calculates and sends the spinner hit result. * Calculates and sends the spinner hit result.
* @return the hit result (GameScore.HIT_* constants) * @return the hit result (GameScore.HIT_* constants)
@@ -165,9 +166,10 @@ public class Spinner implements HitObject {
return result; return result;
} }
// not used @Override
public boolean mousePressed(int x, int y) { return false; } public boolean mousePressed(int x, int y) { return false; } // not used
@Override
public boolean update(boolean overlap, int delta, int mouseX, int mouseY) { public boolean update(boolean overlap, int delta, int mouseX, int mouseY) {
int trackPosition = MusicController.getPosition(); int trackPosition = MusicController.getPosition();
if (overlap) if (overlap)

View File

@@ -932,7 +932,7 @@ public class Game extends BasicGameState {
* Returns the object approach time, in milliseconds. * Returns the object approach time, in milliseconds.
*/ */
public int getApproachTime() { return approachTime; } public int getApproachTime() { return approachTime; }
/** /**
* Returns an array of hit result offset times, in milliseconds (indexed by GameScore.HIT_* constants). * Returns an array of hit result offset times, in milliseconds (indexed by GameScore.HIT_* constants).
*/ */

View File

@@ -135,10 +135,10 @@ public class GamePauseMenu extends BasicGameState {
case Input.KEY_ESCAPE: case Input.KEY_ESCAPE:
// 'esc' will normally unpause, but will return to song menu if health is zero // '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); SoundController.playSound(SoundEffect.MENUBACK);
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).resetGameDataOnLoad(); SongMenu songMenu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
songMenu.resetGameDataOnLoad();
songMenu.resetTrackOnLoad();
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
} else { } else {
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
@@ -179,10 +179,10 @@ public class GamePauseMenu extends BasicGameState {
gameState.setRestart(Game.Restart.MANUAL); gameState.setRestart(Game.Restart.MANUAL);
game.enterState(Opsu.STATE_GAME); game.enterState(Opsu.STATE_GAME);
} else if (backButton.contains(x, y)) { } else if (backButton.contains(x, y)) {
MusicController.pause(); // lose state
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).resetGameDataOnLoad(); SongMenu songMenu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
songMenu.resetGameDataOnLoad();
songMenu.resetTrackOnLoad();
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
} }
} }

View File

@@ -118,9 +118,10 @@ public class GameRanking extends BasicGameState {
} }
// header text // header text
Utils.FONT_LARGE.drawString(10, 0, float marginX = width * 0.01f, marginY = height * 0.01f;
Utils.FONT_LARGE.drawString(marginX, marginY,
String.format("%s - %s [%s]", osu.getArtist(), osu.getTitle(), osu.version), Color.white); String.format("%s - %s [%s]", osu.getArtist(), osu.getTitle(), osu.version), Color.white);
Utils.FONT_MEDIUM.drawString(10, Utils.FONT_LARGE.getLineHeight() - 6, Utils.FONT_MEDIUM.drawString(marginX, marginY + Utils.FONT_LARGE.getLineHeight() - 6,
String.format("Beatmap by %s", osu.creator), Color.white); String.format("Beatmap by %s", osu.creator), Color.white);
// buttons // buttons
@@ -147,10 +148,10 @@ public class GameRanking extends BasicGameState {
public void keyPressed(int key, char c) { public void keyPressed(int key, char c) {
switch (key) { switch (key) {
case Input.KEY_ESCAPE: case Input.KEY_ESCAPE:
MusicController.pause();
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).resetGameDataOnLoad(); SongMenu songMenu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
songMenu.resetGameDataOnLoad();
songMenu.resetTrackOnLoad();
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
break; break;
case Input.KEY_F12: case Input.KEY_F12:
@@ -161,7 +162,7 @@ public class GameRanking extends BasicGameState {
@Override @Override
public void mousePressed(int button, int x, int y) { public void mousePressed(int button, int x, int y) {
// check mouse button // check mouse button
if (button != Input.MOUSE_LEFT_BUTTON) if (button != Input.MOUSE_LEFT_BUTTON)
return; return;
@@ -177,10 +178,10 @@ public class GameRanking extends BasicGameState {
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).resetGameDataOnLoad(); ((SongMenu) game.getState(Opsu.STATE_SONGMENU)).resetGameDataOnLoad();
game.enterState(Opsu.STATE_MAINMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); game.enterState(Opsu.STATE_MAINMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
} else if (Utils.getBackButton().contains(x, y)) { } else if (Utils.getBackButton().contains(x, y)) {
MusicController.pause();
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).resetGameDataOnLoad(); SongMenu songMenu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
songMenu.resetGameDataOnLoad();
songMenu.resetTrackOnLoad();
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
} }
} }

View File

@@ -178,7 +178,7 @@ public class MainMenu extends BasicGameState {
throws SlickException { throws SlickException {
int width = container.getWidth(); int width = container.getWidth();
int height = container.getHeight(); int height = container.getHeight();
// draw background // draw background
OsuFile osu = MusicController.getOsuFile(); OsuFile osu = MusicController.getOsuFile();
if (Options.isDynamicBackgroundEnabled() && if (Options.isDynamicBackgroundEnabled() &&
@@ -232,7 +232,7 @@ public class MainMenu extends BasicGameState {
long time = System.currentTimeMillis() - osuStartTime; long time = System.currentTimeMillis() - osuStartTime;
g.drawString(String.format("opsu! has been running for %d minutes, %d seconds.", g.drawString(String.format("opsu! has been running for %d minutes, %d seconds.",
TimeUnit.MILLISECONDS.toMinutes(time), TimeUnit.MILLISECONDS.toMinutes(time),
TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MILLISECONDS.toSeconds(time) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time))), TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time))),
25, height - 25 - (lineHeight * 2)); 25, height - 25 - (lineHeight * 2));
g.drawString(String.format("The current time is %s.", g.drawString(String.format("The current time is %s.",
@@ -342,7 +342,7 @@ public class MainMenu extends BasicGameState {
@Override @Override
public void mousePressed(int button, int x, int y) { public void mousePressed(int button, int x, int y) {
// check mouse button // check mouse button
if (button != Input.MOUSE_LEFT_BUTTON) if (button != Input.MOUSE_LEFT_BUTTON)
return; return;

View File

@@ -130,7 +130,7 @@ public class MainMenuExit extends BasicGameState {
@Override @Override
public void mousePressed(int button, int x, int y) { public void mousePressed(int button, int x, int y) {
// check mouse button // check mouse button
if (button != Input.MOUSE_LEFT_BUTTON) if (button != Input.MOUSE_LEFT_BUTTON)
return; return;

View File

@@ -64,7 +64,7 @@ public class Options extends BasicGameState {
* Temporary folder for file conversions, auto-deleted upon successful exit. * Temporary folder for file conversions, auto-deleted upon successful exit.
*/ */
public static final File TMP_DIR = new File(".opsu_tmp/"); public static final File TMP_DIR = new File(".opsu_tmp/");
/** /**
* File for logging errors. * File for logging errors.
*/ */
@@ -591,7 +591,7 @@ public class Options extends BasicGameState {
* Frame limiters. * Frame limiters.
*/ */
private static final int[] targetFPS = { 60, 120, 240 }; private static final int[] targetFPS = { 60, 120, 240 };
/** /**
* Index in targetFPS[] array. * Index in targetFPS[] array.
*/ */
@@ -761,7 +761,7 @@ public class Options extends BasicGameState {
int subtextWidth = Utils.FONT_DEFAULT.getWidth("Click or drag an option to change it."); int subtextWidth = Utils.FONT_DEFAULT.getWidth("Click or drag an option to change it.");
float tabX = (width / 50) + (tab.getWidth() / 2f); float tabX = (width / 50) + (tab.getWidth() / 2f);
float tabY = 15 + Utils.FONT_XLARGE.getLineHeight() + (tab.getHeight() / 2f); float tabY = 15 + Utils.FONT_XLARGE.getLineHeight() + (tab.getHeight() / 2f);
int tabOffset = Math.min(tab.getWidth(), int tabOffset = Math.min(tab.getWidth(),
((width - subtextWidth - tab.getWidth()) / 2) / TAB_MAX); ((width - subtextWidth - tab.getWidth()) / 2) / TAB_MAX);
for (int i = 0; i < optionTabs.length; i++) for (int i = 0; i < optionTabs.length; i++)
optionTabs[i] = new MenuButton(tab, tabX + (i * tabOffset), tabY); optionTabs[i] = new MenuButton(tab, tabX + (i * tabOffset), tabY);
@@ -872,7 +872,7 @@ public class Options extends BasicGameState {
return; return;
} }
// check mouse button // check mouse button
if (button == Input.MOUSE_MIDDLE_BUTTON) if (button == Input.MOUSE_MIDDLE_BUTTON)
return; return;

View File

@@ -18,8 +18,6 @@
package itdelatrisu.opsu.states; package itdelatrisu.opsu.states;
import java.util.Stack;
import itdelatrisu.opsu.GameImage; import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.GameMod; import itdelatrisu.opsu.GameMod;
import itdelatrisu.opsu.MenuButton; import itdelatrisu.opsu.MenuButton;
@@ -35,6 +33,8 @@ import itdelatrisu.opsu.audio.MusicController;
import itdelatrisu.opsu.audio.SoundController; import itdelatrisu.opsu.audio.SoundController;
import itdelatrisu.opsu.audio.SoundEffect; import itdelatrisu.opsu.audio.SoundEffect;
import java.util.Stack;
import org.lwjgl.opengl.Display; import org.lwjgl.opengl.Display;
import org.newdawn.slick.Animation; import org.newdawn.slick.Animation;
import org.newdawn.slick.Color; import org.newdawn.slick.Color;
@@ -182,6 +182,11 @@ public class SongMenu extends BasicGameState {
*/ */
private boolean resetGame = false; private boolean resetGame = false;
/**
* Whether or not to reset music track upon entering the state.
*/
private boolean resetTrack = false;
// game-related variables // game-related variables
private GameContainer container; private GameContainer container;
private StateBasedGame game; private StateBasedGame game;
@@ -435,7 +440,7 @@ public class SongMenu extends BasicGameState {
@Override @Override
public void mousePressed(int button, int x, int y) { public void mousePressed(int button, int x, int y) {
// check mouse button // check mouse button
if (button != Input.MOUSE_LEFT_BUTTON) if (button != Input.MOUSE_LEFT_BUTTON)
return; return;
@@ -657,6 +662,13 @@ public class SongMenu extends BasicGameState {
GameImage.destroySkinImages(); // destroy skin images, if any GameImage.destroySkinImages(); // destroy skin images, if any
resetGame = false; resetGame = false;
} }
// reset music track
if (resetTrack) {
MusicController.pause();
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
resetTrack = false;
}
} }
@Override @Override
@@ -679,7 +691,7 @@ public class SongMenu extends BasicGameState {
while (n != 0) { while (n != 0) {
if (startNode == null) if (startNode == null)
break; break;
int height = container.getHeight(); int height = container.getHeight();
if (n < 0 && startNode.prev != null) { if (n < 0 && startNode.prev != null) {
startNode = startNode.prev; startNode = startNode.prev;
@@ -777,6 +789,11 @@ public class SongMenu extends BasicGameState {
*/ */
public void resetGameDataOnLoad() { resetGame = true; } public void resetGameDataOnLoad() { resetGame = true; }
/**
* Triggers a reset of the music track upon entering this state.
*/
public void resetTrackOnLoad() { resetTrack = true; }
/** /**
* Starts the game. * Starts the game.
* @param osu the OsuFile to send to the game * @param osu the OsuFile to send to the game