opsu-dance/src/itdelatrisu/opsu/beatmap/BeatmapSetNode.java

131 lines
3.9 KiB
Java
Raw Normal View History

2014-06-30 04:17:04 +02:00
/*
* opsu! - an open-source osu! client
* Copyright (C) 2014, 2015 Jeffrey Han
2014-06-30 04:17:04 +02:00
*
* opsu! is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* opsu! is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with opsu!. If not, see <http://www.gnu.org/licenses/>.
*/
package itdelatrisu.opsu.beatmap;
2014-06-30 04:17:04 +02:00
import itdelatrisu.opsu.GameData.Grade;
import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.Options;
import itdelatrisu.opsu.Utils;
2014-06-30 04:17:04 +02:00
import org.newdawn.slick.Color;
import org.newdawn.slick.Image;
/**
* Node in an BeatmapSetList representing a beatmap set.
2014-06-30 04:17:04 +02:00
*/
public class BeatmapSetNode {
/** The associated beatmap set. */
private BeatmapSet beatmapSet;
2014-06-30 04:17:04 +02:00
/** Index of the selected beatmap (-1 if not focused). */
public int beatmapIndex = -1;
2014-06-30 04:17:04 +02:00
/** Index of this node. */
public int index = 0;
/** Links to other nodes. */
public BeatmapSetNode prev, next;
2014-06-30 04:17:04 +02:00
/**
* Constructor.
* @param beatmapSet the beatmap set
2014-06-30 04:17:04 +02:00
*/
public BeatmapSetNode(BeatmapSet beatmapSet) {
this.beatmapSet = beatmapSet;
2014-06-30 04:17:04 +02:00
}
/**
* Returns the associated beatmap set.
* @return the beatmap set
*/
public BeatmapSet getBeatmapSet() { return beatmapSet; }
2014-06-30 04:17:04 +02:00
/**
* Draws the button.
* @param x the x coordinate
* @param y the y coordinate
* @param grade the highest grade, if any
2014-06-30 04:17:04 +02:00
* @param focus true if this is the focused node
*/
public void draw(float x, float y, Grade grade, boolean focus) {
Image bg = GameImage.MENU_BUTTON_BG.getImage();
boolean expanded = (beatmapIndex > -1);
Beatmap beatmap;
bg.setAlpha(0.9f);
Color bgColor;
Color textColor = Color.lightGray;
// get drawing parameters
if (expanded) {
x -= bg.getWidth() / 10f;
2014-06-30 04:17:04 +02:00
if (focus) {
bgColor = Color.white;
2014-06-30 04:17:04 +02:00
textColor = Color.white;
} else
bgColor = Utils.COLOR_BLUE_BUTTON;
beatmap = beatmapSet.get(beatmapIndex);
2014-06-30 04:17:04 +02:00
} else {
bgColor = Utils.COLOR_ORANGE_BUTTON;
beatmap = beatmapSet.get(0);
2014-06-30 04:17:04 +02:00
}
bg.draw(x, y, bgColor);
float cx = x + (bg.getWidth() * 0.043f);
2014-06-30 04:17:04 +02:00
float cy = y + (bg.getHeight() * 0.2f) - 3;
// draw grade
if (grade != Grade.NULL) {
Image gradeImg = grade.getMenuImage();
gradeImg.drawCentered(cx - bg.getWidth() * 0.01f + gradeImg.getWidth() / 2f, y + bg.getHeight() / 2.2f);
cx += gradeImg.getWidth();
}
// draw text
if (Options.useUnicodeMetadata()) { // load glyphs
Utils.loadGlyphs(Utils.FONT_MEDIUM, beatmap.titleUnicode, null);
Utils.loadGlyphs(Utils.FONT_DEFAULT, null, beatmap.artistUnicode);
}
Utils.FONT_MEDIUM.drawString(cx, cy, beatmap.getTitle(), textColor);
Utils.FONT_DEFAULT.drawString(cx, cy + Utils.FONT_MEDIUM.getLineHeight() - 2,
String.format("%s // %s", beatmap.getArtist(), beatmap.creator), textColor);
if (expanded || beatmapSet.size() == 1)
Utils.FONT_BOLD.drawString(cx, cy + Utils.FONT_MEDIUM.getLineHeight() + Utils.FONT_DEFAULT.getLineHeight() - 4,
beatmap.version, textColor);
2014-06-30 04:17:04 +02:00
}
/**
* Returns an array of strings containing beatmap information for the
* selected beatmap, or null if none selected.
* @see BeatmapSet#getInfo(int)
2014-06-30 04:17:04 +02:00
*/
public String[] getInfo() { return (beatmapIndex < 0) ? null : beatmapSet.getInfo(beatmapIndex); }
2014-06-30 04:17:04 +02:00
/**
* Returns a formatted string for the beatmap at {@code beatmapIndex}:
* "Artist - Title [Version]" (version omitted if {@code beatmapIndex} is invalid)
2014-06-30 04:17:04 +02:00
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
if (beatmapIndex == -1)
return beatmapSet.toString();
2014-06-30 04:17:04 +02:00
else
return beatmapSet.get(beatmapIndex).toString();
}
2014-06-30 04:17:04 +02:00
}