2014-06-30 04:17:04 +02:00
|
|
|
/*
|
|
|
|
* opsu! - an open-source osu! client
|
2015-01-16 18:05:44 +01:00
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2015-05-17 03:25:19 +02:00
|
|
|
package itdelatrisu.opsu.beatmap;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-28 09:47:24 +01:00
|
|
|
import itdelatrisu.opsu.GameData.Grade;
|
2015-05-17 03:25:19 +02:00
|
|
|
import itdelatrisu.opsu.GameImage;
|
|
|
|
import itdelatrisu.opsu.GameMod;
|
|
|
|
import itdelatrisu.opsu.Options;
|
|
|
|
import itdelatrisu.opsu.Utils;
|
2015-01-28 09:47:24 +01:00
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
import java.util.ArrayList;
|
2014-07-18 03:16:15 +02:00
|
|
|
import java.util.concurrent.TimeUnit;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
import org.newdawn.slick.Color;
|
|
|
|
import org.newdawn.slick.Image;
|
|
|
|
|
|
|
|
/**
|
2015-05-17 03:25:19 +02:00
|
|
|
* Node in an BeatmapSetList representing a group of beatmaps.
|
2014-06-30 04:17:04 +02:00
|
|
|
*/
|
2015-05-17 03:25:19 +02:00
|
|
|
public class BeatmapSetNode {
|
|
|
|
/** List of associated beatmaps. */
|
|
|
|
public ArrayList<Beatmap> beatmaps;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-05-17 03:25:19 +02:00
|
|
|
/** Index of this node. */
|
2014-06-30 04:17:04 +02:00
|
|
|
public int index = 0;
|
|
|
|
|
2015-05-17 03:25:19 +02:00
|
|
|
/** Index of the selected beatmap (-1 if not focused). */
|
|
|
|
public int beatmapIndex = -1;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-05-17 03:25:19 +02:00
|
|
|
/** Links to other nodes. */
|
|
|
|
public BeatmapSetNode prev, next;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
2015-05-17 03:25:19 +02:00
|
|
|
* @param beatmaps the beatmaps in this group
|
2014-06-30 04:17:04 +02:00
|
|
|
*/
|
2015-05-17 03:25:19 +02:00
|
|
|
public BeatmapSetNode(ArrayList<Beatmap> beatmaps) {
|
|
|
|
this.beatmaps = beatmaps;
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws the button.
|
|
|
|
* @param x the x coordinate
|
|
|
|
* @param y the y coordinate
|
2015-01-28 09:47:24 +01:00
|
|
|
* @param grade the highest grade, if any
|
2014-06-30 04:17:04 +02:00
|
|
|
* @param focus true if this is the focused node
|
|
|
|
*/
|
2015-02-20 05:45:48 +01:00
|
|
|
public void draw(float x, float y, Grade grade, boolean focus) {
|
2015-02-19 08:43:26 +01:00
|
|
|
Image bg = GameImage.MENU_BUTTON_BG.getImage();
|
2015-05-17 03:25:19 +02:00
|
|
|
boolean expanded = (beatmapIndex > -1);
|
|
|
|
Beatmap beatmap;
|
2015-02-16 17:34:35 +01:00
|
|
|
bg.setAlpha(0.9f);
|
2015-02-16 03:38:54 +01:00
|
|
|
Color bgColor;
|
|
|
|
Color textColor = Color.lightGray;
|
2015-02-19 01:35:26 +01:00
|
|
|
|
|
|
|
// get drawing parameters
|
2015-02-20 05:45:48 +01:00
|
|
|
if (expanded) {
|
2015-02-16 03:38:54 +01:00
|
|
|
x -= bg.getWidth() / 10f;
|
2014-06-30 04:17:04 +02:00
|
|
|
if (focus) {
|
2015-02-16 03:38:54 +01:00
|
|
|
bgColor = Color.white;
|
2014-06-30 04:17:04 +02:00
|
|
|
textColor = Color.white;
|
2014-07-11 01:13:53 +02:00
|
|
|
} else
|
2015-02-16 03:38:54 +01:00
|
|
|
bgColor = Utils.COLOR_BLUE_BUTTON;
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap = beatmaps.get(beatmapIndex);
|
2014-06-30 04:17:04 +02:00
|
|
|
} else {
|
2015-02-16 03:38:54 +01:00
|
|
|
bgColor = Utils.COLOR_ORANGE_BUTTON;
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap = beatmaps.get(0);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2015-02-20 05:45:48 +01:00
|
|
|
bg.draw(x, y, bgColor);
|
2014-07-11 01:13:53 +02:00
|
|
|
|
2015-05-15 07:33:53 +02:00
|
|
|
float cx = x + (bg.getWidth() * 0.043f);
|
2014-06-30 04:17:04 +02:00
|
|
|
float cy = y + (bg.getHeight() * 0.2f) - 3;
|
|
|
|
|
2015-02-16 03:38:54 +01:00
|
|
|
// draw grade
|
2015-01-28 09:47:24 +01:00
|
|
|
if (grade != Grade.NULL) {
|
2015-01-29 01:23:02 +01:00
|
|
|
Image gradeImg = grade.getMenuImage();
|
2015-01-28 09:47:24 +01:00
|
|
|
gradeImg.drawCentered(cx - bg.getWidth() * 0.01f + gradeImg.getWidth() / 2f, y + bg.getHeight() / 2.2f);
|
|
|
|
cx += gradeImg.getWidth();
|
|
|
|
}
|
|
|
|
|
2015-02-20 05:45:48 +01:00
|
|
|
// draw text
|
2015-03-19 21:45:26 +01:00
|
|
|
if (Options.useUnicodeMetadata()) { // load glyphs
|
2015-05-17 03:25:19 +02:00
|
|
|
Utils.loadGlyphs(Utils.FONT_MEDIUM, beatmap.titleUnicode, null);
|
|
|
|
Utils.loadGlyphs(Utils.FONT_DEFAULT, null, beatmap.artistUnicode);
|
2015-03-19 21:45:26 +01:00
|
|
|
}
|
2015-05-17 03:25:19 +02:00
|
|
|
Utils.FONT_MEDIUM.drawString(cx, cy, beatmap.getTitle(), textColor);
|
2015-05-15 07:33:53 +02:00
|
|
|
Utils.FONT_DEFAULT.drawString(cx, cy + Utils.FONT_MEDIUM.getLineHeight() - 2,
|
2015-05-17 03:25:19 +02:00
|
|
|
String.format("%s // %s", beatmap.getArtist(), beatmap.creator), textColor);
|
|
|
|
if (expanded || beatmaps.size() == 1)
|
2015-05-15 07:33:53 +02:00
|
|
|
Utils.FONT_BOLD.drawString(cx, cy + Utils.FONT_MEDIUM.getLineHeight() + Utils.FONT_DEFAULT.getLineHeight() - 4,
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.version, textColor);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array of strings containing song information.
|
|
|
|
* <ul>
|
|
|
|
* <li>0: {Artist} - {Title} [{Version}]
|
|
|
|
* <li>1: Mapped by {Creator}
|
|
|
|
* <li>2: Length: {} BPM: {} Objects: {}
|
|
|
|
* <li>3: Circles: {} Sliders: {} Spinners: {}
|
|
|
|
* <li>4: CS:{} HP:{} AR:{} OD:{}
|
|
|
|
* </ul>
|
|
|
|
*/
|
|
|
|
public String[] getInfo() {
|
2015-05-17 03:25:19 +02:00
|
|
|
if (beatmapIndex < 0)
|
2014-06-30 04:17:04 +02:00
|
|
|
return null;
|
|
|
|
|
2015-05-17 03:25:19 +02:00
|
|
|
Beatmap beatmap = beatmaps.get(beatmapIndex);
|
2015-04-04 00:08:35 +02:00
|
|
|
float speedModifier = GameMod.getSpeedMultiplier();
|
2015-05-17 03:25:19 +02:00
|
|
|
long endTime = (long) (beatmap.endTime / speedModifier);
|
|
|
|
int bpmMin = (int) (beatmap.bpmMin * speedModifier);
|
|
|
|
int bpmMax = (int) (beatmap.bpmMax * speedModifier);
|
2015-04-04 18:30:23 +02:00
|
|
|
float multiplier = GameMod.getDifficultyMultiplier();
|
2014-06-30 04:17:04 +02:00
|
|
|
String[] info = new String[5];
|
2015-05-17 03:25:19 +02:00
|
|
|
info[0] = beatmap.toString();
|
|
|
|
info[1] = String.format("Mapped by %s", beatmap.creator);
|
2014-07-18 03:16:15 +02:00
|
|
|
info[2] = String.format("Length: %d:%02d BPM: %s Objects: %d",
|
2015-03-31 17:14:52 +02:00
|
|
|
TimeUnit.MILLISECONDS.toMinutes(endTime),
|
|
|
|
TimeUnit.MILLISECONDS.toSeconds(endTime) -
|
|
|
|
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(endTime)),
|
|
|
|
(bpmMax <= 0) ? "--" : ((bpmMin == bpmMax) ? bpmMin : String.format("%d-%d", bpmMin, bpmMax)),
|
2015-05-17 03:25:19 +02:00
|
|
|
(beatmap.hitObjectCircle + beatmap.hitObjectSlider + beatmap.hitObjectSpinner));
|
2014-06-30 04:17:04 +02:00
|
|
|
info[3] = String.format("Circles: %d Sliders: %d Spinners: %d",
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.hitObjectCircle, beatmap.hitObjectSlider, beatmap.hitObjectSpinner);
|
2014-06-30 10:03:39 +02:00
|
|
|
info[4] = String.format("CS:%.1f HP:%.1f AR:%.1f OD:%.1f",
|
2015-05-17 03:25:19 +02:00
|
|
|
Math.min(beatmap.circleSize * multiplier, 10f),
|
|
|
|
Math.min(beatmap.HPDrainRate * multiplier, 10f),
|
|
|
|
Math.min(beatmap.approachRate * multiplier, 10f),
|
|
|
|
Math.min(beatmap.overallDifficulty * multiplier, 10f));
|
2014-06-30 04:17:04 +02:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-17 03:25:19 +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() {
|
2015-05-17 03:25:19 +02:00
|
|
|
if (beatmapIndex == -1)
|
|
|
|
return String.format("%s - %s", beatmaps.get(0).getArtist(), beatmaps.get(0).getTitle());
|
2014-06-30 04:17:04 +02:00
|
|
|
else
|
2015-05-17 03:25:19 +02:00
|
|
|
return beatmaps.get(beatmapIndex).toString();
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2014-07-17 07:00:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether the node matches a given search query.
|
|
|
|
* @param query the search term
|
|
|
|
* @return true if title, artist, creator, source, version, or tag matches query
|
|
|
|
*/
|
|
|
|
public boolean matches(String query) {
|
2015-05-17 03:25:19 +02:00
|
|
|
Beatmap beatmap = beatmaps.get(0);
|
|
|
|
|
|
|
|
// search: title, artist, creator, source, version, tags (first beatmap)
|
|
|
|
if (beatmap.title.toLowerCase().contains(query) ||
|
|
|
|
beatmap.titleUnicode.toLowerCase().contains(query) ||
|
|
|
|
beatmap.artist.toLowerCase().contains(query) ||
|
|
|
|
beatmap.artistUnicode.toLowerCase().contains(query) ||
|
|
|
|
beatmap.creator.toLowerCase().contains(query) ||
|
|
|
|
beatmap.source.toLowerCase().contains(query) ||
|
|
|
|
beatmap.version.toLowerCase().contains(query) ||
|
|
|
|
beatmap.tags.contains(query))
|
2014-07-17 07:00:28 +02:00
|
|
|
return true;
|
|
|
|
|
2015-05-17 03:25:19 +02:00
|
|
|
// search: version, tags (remaining beatmaps)
|
|
|
|
for (int i = 1; i < beatmaps.size(); i++) {
|
|
|
|
beatmap = beatmaps.get(i);
|
|
|
|
if (beatmap.version.toLowerCase().contains(query) ||
|
|
|
|
beatmap.tags.contains(query))
|
2014-07-17 07:00:28 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-17 18:49:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether the node matches a given condition.
|
|
|
|
* @param type the condition type (ar, cs, od, hp, bpm, length)
|
|
|
|
* @param operator the operator (=/==, >, >=, <, <=)
|
|
|
|
* @param value the value
|
|
|
|
* @return true if the condition is met
|
|
|
|
*/
|
|
|
|
public boolean matches(String type, String operator, float value) {
|
2015-05-17 03:25:19 +02:00
|
|
|
for (Beatmap beatmap : beatmaps) {
|
2014-07-17 18:49:12 +02:00
|
|
|
// get value
|
2015-05-17 03:25:19 +02:00
|
|
|
float v;
|
2014-07-17 18:49:12 +02:00
|
|
|
switch (type) {
|
2015-05-17 03:25:19 +02:00
|
|
|
case "ar": v = beatmap.approachRate; break;
|
|
|
|
case "cs": v = beatmap.circleSize; break;
|
|
|
|
case "od": v = beatmap.overallDifficulty; break;
|
|
|
|
case "hp": v = beatmap.HPDrainRate; break;
|
|
|
|
case "bpm": v = beatmap.bpmMax; break;
|
|
|
|
case "length": v = beatmap.endTime / 1000; break;
|
2014-07-17 18:49:12 +02:00
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get operator
|
|
|
|
boolean met;
|
|
|
|
switch (operator) {
|
|
|
|
case "=":
|
2015-05-17 03:25:19 +02:00
|
|
|
case "==": met = (v == value); break;
|
|
|
|
case ">": met = (v > value); break;
|
|
|
|
case ">=": met = (v >= value); break;
|
|
|
|
case "<": met = (v < value); break;
|
|
|
|
case "<=": met = (v <= value); break;
|
2014-07-17 18:49:12 +02:00
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (met)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|