Merge branch 'logo'

This commit is contained in:
yugecin 2016-11-13 02:45:40 +01:00
commit 5aa3a60f16
10 changed files with 154 additions and 19 deletions

BIN
res/logo2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 143 KiB

BIN
res/logo2piece2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

BIN
res/menu-exit2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

BIN
res/menu-play2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

View File

@ -271,19 +271,25 @@ public enum GameImage {
return img.getScaledCopy(w, h); return img.getScaledCopy(w, h);
} }
}, },
MENU_LOGO ("logo", "png", false, true) { MENU_LOGO ("logo2", "png", false, true) {
@Override @Override
protected Image process_sub(Image img, int w, int h) { protected Image process_sub(Image img, int w, int h) {
return img.getScaledCopy(0.8f); return img.getScaledCopy(0.8f);
} }
}, },
MENU_PLAY ("menu-play", "png", false, false) { MENU_LOGO_PIECE ("logo2piece2", "png", false, true) {
@Override @Override
protected Image process_sub(Image img, int w, int h) { protected Image process_sub(Image img, int w, int h) {
return img.getScaledCopy(0.8f); return img.getScaledCopy(0.8f);
} }
}, },
MENU_EXIT ("menu-exit", "png", false, false) { MENU_PLAY ("menu-play2", "png", false, false) {
@Override
protected Image process_sub(Image img, int w, int h) {
return img.getScaledCopy(0.8f);
}
},
MENU_EXIT ("menu-exit2", "png", false, false) {
@Override @Override
protected Image process_sub(Image img, int w, int h) { protected Image process_sub(Image img, int w, int h) {
return img.getScaledCopy(0.8f); return img.getScaledCopy(0.8f);

View File

@ -348,7 +348,7 @@ public class MusicController {
public static void playThemeSong() { public static void playThemeSong() {
Beatmap beatmap = Options.getThemeBeatmap(); Beatmap beatmap = Options.getThemeBeatmap();
if (beatmap != null) { if (beatmap != null) {
play(beatmap, true, false); play(beatmap, false, false);
themePlaying = true; themePlaying = true;
} }
} }

View File

@ -24,15 +24,7 @@ import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.db.BeatmapDB; import itdelatrisu.opsu.db.BeatmapDB;
import itdelatrisu.opsu.io.MD5InputStreamWrapper; import itdelatrisu.opsu.io.MD5InputStreamWrapper;
import java.io.BufferedInputStream; import java.io.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -212,6 +204,63 @@ public class BeatmapParser {
return lastNode; return lastNode;
} }
public static void parseOnlyTimingPoints(Beatmap map) {
if (map == null || map.getFile() == null || !map.getFile().exists()) {
return;
}
if (map.timingPoints == null) {
map.timingPoints = new ArrayList<TimingPoint>();
}
try (
InputStream bis = new BufferedInputStream(new FileInputStream(map.getFile()));
MD5InputStreamWrapper md5stream = (!hasNoMD5Algorithm) ? new MD5InputStreamWrapper(bis) : null;
BufferedReader in = new BufferedReader(new InputStreamReader((md5stream != null) ? md5stream : bis, "UTF-8"));
) {
String line;
boolean found = false;
while((line = in.readLine()) != null) {
line = line.trim();
if(!isValidLine(line)) {
continue;
}
if ("[TimingPoints]".equals(line)) {
found = true;
continue;
}
if (found) {
if (line.startsWith("[")) {
break;
}
parseSectionTimingPoints(map, line);
}
}
map.timingPoints.trimToSize();
} catch (IOException e) {
ErrorHandler.error(String.format("Failed to read file '%s'.", map.getFile().getAbsolutePath()), e, false);
} catch (NoSuchAlgorithmException e) {
ErrorHandler.error("Failed to get MD5 hash stream.", e, true);
// retry without MD5
hasNoMD5Algorithm = true;
parseOnlyTimingPoints(map);
}
}
private static void parseSectionTimingPoints(Beatmap beatmap, String line) {
TimingPoint timingPoint = new TimingPoint(line);
if(!timingPoint.isInherited()) {
int bpm = Math.round(60000 / timingPoint.getBeatLength());
if( beatmap.bpmMin == 0 ) {
beatmap.bpmMin = beatmap.bpmMax = bpm;
} else if( bpm < beatmap.bpmMin ) {
beatmap.bpmMin = bpm;
} else if( bpm > beatmap.bpmMax ) {
beatmap.bpmMax = bpm;
}
}
beatmap.timingPoints.add(timingPoint);
}
/** /**
* Parses a beatmap. * Parses a beatmap.
* @param file the file to parse * @param file the file to parse

View File

@ -29,6 +29,7 @@ import itdelatrisu.opsu.audio.SoundEffect;
import itdelatrisu.opsu.beatmap.Beatmap; import itdelatrisu.opsu.beatmap.Beatmap;
import itdelatrisu.opsu.beatmap.BeatmapSetList; import itdelatrisu.opsu.beatmap.BeatmapSetList;
import itdelatrisu.opsu.beatmap.BeatmapSetNode; import itdelatrisu.opsu.beatmap.BeatmapSetNode;
import itdelatrisu.opsu.beatmap.TimingPoint;
import itdelatrisu.opsu.downloads.Updater; import itdelatrisu.opsu.downloads.Updater;
import itdelatrisu.opsu.states.ButtonMenu.MenuState; import itdelatrisu.opsu.states.ButtonMenu.MenuState;
import itdelatrisu.opsu.ui.Colors; import itdelatrisu.opsu.ui.Colors;
@ -269,7 +270,23 @@ public class MainMenu extends BasicGameState {
playButton.draw(); playButton.draw();
exitButton.draw(); exitButton.draw();
} }
logo.draw();
Double position = getBPMPiecePosition();
if (position != null) {
double scale = 1 - (0 - position) * 0.05;
logo.draw(Color.white, (float) scale);
Image piece = GameImage.MENU_LOGO_PIECE.getImage();
float xRadius = piece.getWidth() / 2;
float yRadius = piece.getHeight() / 2;
piece = piece.getScaledCopy(logo.getCurrentScale());
float scaleposmodx = piece.getWidth() / 2 - xRadius;
float scaleposmody = piece.getHeight() / 2 - yRadius;
piece.rotate((float)(position * 360));
piece.draw(logo.getX() - xRadius - scaleposmodx, logo.getY() - yRadius - scaleposmody);
} else {
logo.draw();
}
// draw music buttons // draw music buttons
if (MusicController.isPlaying()) if (MusicController.isPlaying())
@ -341,6 +358,34 @@ public class MainMenu extends BasicGameState {
UI.draw(g); UI.draw(g);
} }
private Double getBPMPiecePosition() {
if (!MusicController.isPlaying() || MusicController.getBeatmap() == null) {
return null;
}
Beatmap map = MusicController.getBeatmap();
if (map.timingPoints == null) {
return null;
}
int trackposition = MusicController.getPosition();
TimingPoint p = null;
float beatlen = 0f;
int time = 0;
for (TimingPoint pts : map.timingPoints) {
if (p == null || pts.getTime() < MusicController.getPosition()) {
p = pts;
if (!p.isInherited() && p.getBeatLength() > 0) {
beatlen = p.getBeatLength();
time = p.getTime();
}
}
}
if (p == null) {
return null;
}
double beatLength = beatlen * 100;
return (((trackposition * 100 - time * 100) % beatLength) / beatLength);
}
@Override @Override
public void update(GameContainer container, StateBasedGame game, int delta) public void update(GameContainer container, StateBasedGame game, int delta)
throws SlickException { throws SlickException {
@ -611,6 +656,12 @@ public class MainMenu extends BasicGameState {
switch (key) { switch (key) {
case Input.KEY_ESCAPE: case Input.KEY_ESCAPE:
case Input.KEY_Q: case Input.KEY_Q:
if (logoTimer > 0) {
logoState = LogoState.CLOSING;
logoClose.setTime(0);
logoTimer = 0;
break;
}
((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).setMenuState(MenuState.EXIT); ((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).setMenuState(MenuState.EXIT);
game.enterState(Opsu.STATE_BUTTONMENU); game.enterState(Opsu.STATE_BUTTONMENU);
break; break;

View File

@ -1391,6 +1391,9 @@ public class SongMenu extends BasicGameState {
focusNode = BeatmapSetList.get().getNode(node, beatmapIndex); focusNode = BeatmapSetList.get().getNode(node, beatmapIndex);
Beatmap beatmap = focusNode.getSelectedBeatmap(); Beatmap beatmap = focusNode.getSelectedBeatmap();
if (beatmap.timingPoints == null) {
BeatmapParser.parseOnlyTimingPoints(beatmap);
}
MusicController.play(beatmap, false, preview); MusicController.play(beatmap, false, preview);
// load scores // load scores

View File

@ -98,6 +98,12 @@ public class MenuButton {
/** The default max rotation angle of the button. */ /** The default max rotation angle of the button. */
private static final float DEFAULT_ANGLE_MAX = 30f; private static final float DEFAULT_ANGLE_MAX = 30f;
private float currentScale = 1f;
public float getCurrentScale() {
return currentScale;
}
/** /**
* Creates a new button from an Image. * Creates a new button from an Image.
* @param img the image * @param img the image
@ -191,14 +197,21 @@ public class MenuButton {
/** /**
* Draws the button. * Draws the button.
*/ */
public void draw() { draw(Color.white); } public void draw() { draw(Color.white, 1.0f); }
/** /**
* Draw the button with a color filter. * Draws the button with a color filter.
* @param filter the color to filter with when drawing * @param filter the color to filter with when drawing
*/ */
public void draw(Color filter) { draw(filter, 1.0f); }
/**
* Draw the button with a color filter and scale.
* @param filter the color to filter with when drawing
* @param scaleoverride the scale to use when drawing
*/
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void draw(Color filter) { public void draw(Color filter, float scaleoverride) {
// animations: get current frame // animations: get current frame
Image image = this.img; Image image = this.img;
if (image == null) { if (image == null) {
@ -206,10 +219,20 @@ public class MenuButton {
image = anim.getCurrentFrame(); image = anim.getCurrentFrame();
} }
currentScale = 1f;
// normal images // normal images
if (imgL == null) { if (imgL == null) {
float scaleposmodx = 0;
float scaleposmody = 0;
if (scaleoverride != 1f) {
image = image.getScaledCopy(scaleoverride);
scaleposmodx = image.getWidth() / 2 - xRadius;
scaleposmody = image.getHeight() / 2 - yRadius;
currentScale = scaleoverride;
}
if (hoverEffect == 0) if (hoverEffect == 0)
image.draw(x - xRadius, y - yRadius, filter); image.draw(x - xRadius - scaleposmodx, y - yRadius - scaleposmody, filter);
else { else {
float oldAlpha = image.getAlpha(); float oldAlpha = image.getAlpha();
float oldAngle = image.getRotation(); float oldAngle = image.getRotation();
@ -217,13 +240,16 @@ public class MenuButton {
if (scale.getValue() != 1f) { if (scale.getValue() != 1f) {
image = image.getScaledCopy(scale.getValue()); image = image.getScaledCopy(scale.getValue());
image.setAlpha(oldAlpha); image.setAlpha(oldAlpha);
scaleposmodx = image.getWidth() / 2 - xRadius;
scaleposmody = image.getHeight() / 2 - yRadius;
currentScale *= scale.getValue();
} }
} }
if ((hoverEffect & EFFECT_FADE) > 0) if ((hoverEffect & EFFECT_FADE) > 0)
image.setAlpha(alpha.getValue()); image.setAlpha(alpha.getValue());
if ((hoverEffect & EFFECT_ROTATE) > 0) if ((hoverEffect & EFFECT_ROTATE) > 0)
image.setRotation(angle.getValue()); image.setRotation(angle.getValue());
image.draw(x - xRadius, y - yRadius, filter); image.draw(x - xRadius - scaleposmodx, y - yRadius - scaleposmody, filter);
if (image == this.img) { if (image == this.img) {
image.setAlpha(oldAlpha); image.setAlpha(oldAlpha);
image.setRotation(oldAngle); image.setRotation(oldAngle);