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:
@@ -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);
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -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();
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -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)
|
||||||
|
|||||||
@@ -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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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:
|
||||||
@@ -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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user