Minor formatting cleanup for #131.

Also made some members private.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-09-15 23:20:53 -04:00
parent e1becb3962
commit e0da6a2444
5 changed files with 127 additions and 129 deletions

View File

@ -105,9 +105,7 @@ public class ScoreData implements Comparable<ScoreData> {
/**
* Returns the Buttons Offset
*/
public static float getButtonOffset() {
return buttonOffset;
}
public static float getButtonOffset() { return buttonOffset; }
/**
* Returns true if the coordinates are within the bounds of the
@ -136,7 +134,7 @@ public class ScoreData implements Comparable<ScoreData> {
/**
* Draws the scroll bar for the score buttons.
* @param g the graphics context
* @param index the start button index
* @param pos the start button index
* @param total the total number of buttons
*/
public static void drawScrollbar(Graphics g, float pos, float total) {
@ -238,7 +236,7 @@ public class ScoreData implements Comparable<ScoreData> {
/**
* Draws the score data as a rectangular button.
* @param g the graphics context
* @param index the index (to offset the button from the topmost button)
* @param position the index (to offset the button from the topmost button)
* @param rank the score rank
* @param prevScore the previous (lower) score, or -1 if none
* @param focus whether the button is focused

View File

@ -192,20 +192,17 @@ public class DownloadNode {
}
/**
* Returns the button(Results) offset.
* @return the button offset
* Returns the download results button offset.
* @return the offset
*/
public static float getButtonOffset(){
return buttonOffset;
}
public static float getButtonOffset() { return buttonOffset; }
/**
* Returns the info(Download) height.
* @return the infoHeight
* Returns the download info height.
* @return the height
*/
public static float getInfoHeight(){
return infoHeight;
}
public static float getInfoHeight() { return infoHeight; }
/**
* Returns true if the coordinates are within the bounds of the
* download information button area.

View File

@ -95,7 +95,7 @@ public class DownloadsMenu extends BasicGameState {
private int focusTimer = 0;
/** Current start result button (topmost entry). */
KineticScrolling startResultPos = new KineticScrolling();
private KineticScrolling startResultPos = new KineticScrolling();
/** Total number of results for current query. */
private int totalResults = 0;
@ -116,7 +116,7 @@ public class DownloadsMenu extends BasicGameState {
private boolean rankedOnly = true;
/** Current start download index. */
KineticScrolling startDownloadIndexPos = new KineticScrolling();
private KineticScrolling startDownloadIndexPos = new KineticScrolling();
/** Query thread. */
private Thread queryThread;
@ -399,12 +399,12 @@ public class DownloadsMenu extends BasicGameState {
for (int i = 0; i < maxResultsShown + 1; i++) {
int index = startResult + i;
if(index < 0)
if (index < 0)
continue;
if (index >= nodes.length)
break;
nodes[index].drawResult(g, offset + i * DownloadNode.getButtonOffset(),
DownloadNode.resultContains(mouseX, mouseY - offset, i) && !inDropdownMenu,
DownloadNode.resultContains(mouseX, mouseY - offset, i) && !inDropdownMenu,
(index == focusResult), (previewID == nodes[index].getID()));
}
g.clearClip();
@ -443,19 +443,18 @@ public class DownloadsMenu extends BasicGameState {
int offset = (int) (-startDownloadIndexPos.getPosition() + startDownloadIndex * DownloadNode.getInfoHeight());
DownloadNode.clipToDownloadArea(g);
for (int i = 0; i < maxDownloadsShown + 1; i++) {
int index = startDownloadIndex + i;
if (index >= downloadsSize)
break;
DownloadNode node = DownloadList.get().getNode(index);
if (node == null)
break;
node.drawDownload(g, i * DownloadNode.getInfoHeight() + offset, index,
DownloadNode.downloadContains(mouseX, mouseY - offset, i));
}
for (int i = 0; i < maxDownloadsShown + 1; i++) {
int index = startDownloadIndex + i;
if (index >= downloadsSize)
break;
DownloadNode node = DownloadList.get().getNode(index);
if (node == null)
break;
node.drawDownload(g, i * DownloadNode.getInfoHeight() + offset, index,
DownloadNode.downloadContains(mouseX, mouseY - offset, i));
}
g.clearClip();
// scroll bar
if (downloadsSize > maxDownloadsShown)
DownloadNode.drawDownloadScrollbar(g, startDownloadIndexPos.getPosition(), downloadsSize * DownloadNode.getInfoHeight());
@ -946,14 +945,12 @@ public class DownloadsMenu extends BasicGameState {
*/
private void scrollLists(int cx, int cy, int shift) {
// search results
if (DownloadNode.resultAreaContains(cx, cy)) {
if (DownloadNode.resultAreaContains(cx, cy))
startResultPos.scrollOffset(shift * DownloadNode.getButtonOffset());
}
// downloads
else if (DownloadNode.downloadAreaContains(cx, cy)) {
else if (DownloadNode.downloadAreaContains(cx, cy))
startDownloadIndexPos.scrollOffset(shift * DownloadNode.getInfoHeight());
}
}
/**

View File

@ -44,9 +44,9 @@ import itdelatrisu.opsu.beatmap.OszUnpacker;
import itdelatrisu.opsu.db.BeatmapDB;
import itdelatrisu.opsu.db.ScoreDB;
import itdelatrisu.opsu.states.ButtonMenu.MenuState;
import itdelatrisu.opsu.ui.KineticScrolling;
import itdelatrisu.opsu.ui.Colors;
import itdelatrisu.opsu.ui.Fonts;
import itdelatrisu.opsu.ui.KineticScrolling;
import itdelatrisu.opsu.ui.MenuButton;
import itdelatrisu.opsu.ui.StarStream;
import itdelatrisu.opsu.ui.UI;
@ -138,7 +138,7 @@ public class SongMenu extends BasicGameState {
private BeatmapSetNode startNode;
/** The first node is about this high above the header. */
KineticScrolling songScrolling = new KineticScrolling();
private KineticScrolling songScrolling = new KineticScrolling();
/** The number of Nodes to offset from the top to the startNode. */
private int startNodeOffset;
@ -210,8 +210,7 @@ public class SongMenu extends BasicGameState {
private ScoreData[] focusScores;
/** Current start score (topmost score entry). */
KineticScrolling startScorePos = new KineticScrolling();
private KineticScrolling startScorePos = new KineticScrolling();
/** Header and footer end and start y coordinates, respectively. */
private float headerY, footerY;
@ -389,19 +388,18 @@ public class SongMenu extends BasicGameState {
for (int i = startNodeOffset + songButtonIndex; i < MAX_SONG_BUTTONS + 1 && node != null; i++, node = node.next) {
// draw the node
float offset = (node == hoverIndex) ? hoverOffset.getValue() : 0f;
float ypos = buttonY + (i*buttonOffset) ;
float mid = height/2 - ypos - buttonOffset/2;
final float circleRadi = 700 * GameImage.getUIscale();
float ypos = buttonY + (i * buttonOffset);
float mid = (height / 2) - ypos - (buttonOffset / 2);
final float circleRadi = 700 * GameImage.getUIscale();
//finds points along a very large circle (x^2 = h^2 - y^2)
float t = circleRadi * circleRadi - (mid * mid);
float xpos = (float)(t>0?Math.sqrt(t):0) - circleRadi + 50 * GameImage.getUIscale();
float xpos = (float) ((t > 0) ? Math.sqrt(t) : 0) - circleRadi + 50 * GameImage.getUIscale();
ScoreData[] scores = getScoreDataForNode(node, false);
node.draw(buttonX - offset - xpos, ypos,
(scores == null) ? Grade.NULL : scores[0].getGrade(), (node == focusNode));
}
g.clearClip();
// scroll bar
if (focusNode != null && startNode != null) {
int focusNodes = focusNode.getBeatmapSet().size();
@ -434,13 +432,13 @@ public class SongMenu extends BasicGameState {
long prevScore = (rank + 1 < focusScores.length) ? focusScores[rank + 1].score : -1;
float t = Utils.clamp((time - (i * (duration - segmentDuration) / scoreButtons)) / (float) segmentDuration, 0f, 1f);
boolean focus = (t >= 0.9999f && ScoreData.buttonContains(mouseX, mouseY - offset, i));
focusScores[rank].draw(g, offset + i*ScoreData.getButtonOffset(), rank, prevScore, focus, t);
focusScores[rank].draw(g, offset + i * ScoreData.getButtonOffset(), rank, prevScore, focus, t);
}
g.clearClip();
// scroll bar
if (focusScores.length > MAX_SCORE_BUTTONS && ScoreData.areaContains(mouseX, mouseY))
ScoreData.drawScrollbar(g, startScorePos.getPosition() , focusScores.length * ScoreData.getButtonOffset());
ScoreData.drawScrollbar(g, startScorePos.getPosition(), focusScores.length * ScoreData.getButtonOffset());
}
// top/bottom bars
@ -689,7 +687,7 @@ public class SongMenu extends BasicGameState {
// mouse hover
songScrolling.update(delta);
updateDrawnSongPos();
updateDrawnSongPosition();
boolean isHover = false;
if (mouseY > headerY && mouseY < footerY) {
BeatmapSetNode node = startNode;
@ -700,7 +698,7 @@ public class SongMenu extends BasicGameState {
if (node == hoverIndex) {
hoverOffset.update(delta);
} else {
hoverIndex = node ;
hoverIndex = node;
hoverOffset.setTime(0);
}
isHover = true;
@ -1041,14 +1039,12 @@ public class SongMenu extends BasicGameState {
return;
// score buttons
if (focusScores != null && focusScores.length >= MAX_SCORE_BUTTONS && ScoreData.areaContains(oldx, oldy)) {
if (focusScores != null && focusScores.length >= MAX_SCORE_BUTTONS && ScoreData.areaContains(oldx, oldy))
startScorePos.dragged(-diff * multiplier);
}
// song buttons
else
songScrolling.dragged(-diff * multiplier);
}
@Override
@ -1067,9 +1063,8 @@ public class SongMenu extends BasicGameState {
int mouseX = input.getMouseX(), mouseY = input.getMouseY();
// score buttons
if (focusScores != null && focusScores.length >= MAX_SCORE_BUTTONS && ScoreData.areaContains(mouseX, mouseY)) {
if (focusScores != null && focusScores.length >= MAX_SCORE_BUTTONS && ScoreData.areaContains(mouseX, mouseY))
startScorePos.scrollOffset(ScoreData.getButtonOffset() * shift);
}
// song buttons
else
@ -1255,27 +1250,28 @@ public class SongMenu extends BasicGameState {
/**
* Updates the song list data required for drawing.
*/
private void updateDrawnSongPos() {
private void updateDrawnSongPosition() {
float songNodePosDrawn = songScrolling.getPosition();
int startNodeIndex = (int) (songNodePosDrawn / buttonOffset);
buttonY = -songNodePosDrawn + buttonOffset * startNodeIndex + headerY - DIVIDER_LINE_WIDTH;
float max = (BeatmapSetList.get().size() + (focusNode != null ? focusNode.getBeatmapSet().size() : 0));
songScrolling.setMinMax(0 - buttonOffset * 2, (max - MAX_SONG_BUTTONS- 1 + 2) * buttonOffset);
songScrolling.setMinMax(0 - buttonOffset * 2, (max - MAX_SONG_BUTTONS - 1 + 2) * buttonOffset);
//negative startNodeIndex means the first Node is below the header so offset it.
// negative startNodeIndex means the first Node is below the header so offset it.
if (startNodeIndex <= 0) {
startNodeOffset = -startNodeIndex;
startNodeIndex = 0;
} else {
startNodeOffset = 0;
}
// Finds the start node with the expanded focus node in mind.
if (focusNode != null && startNodeIndex >= focusNode.index) {
//below the focus node.
// below the focus node.
if (startNodeIndex <= focusNode.index + focusNode.getBeatmapSet().size()) {
//inside the focus nodes expanded nodes.
// inside the focus nodes expanded nodes.
int nodeIndex = startNodeIndex - focusNode.index;
startNode = BeatmapSetList.get().getBaseNode(focusNode.index);
startNode = startNode.next;
@ -1287,8 +1283,8 @@ public class SongMenu extends BasicGameState {
}
} else
startNode = BeatmapSetList.get().getBaseNode(startNodeIndex);
}
/**
* Sets a new focus node.
* @param node the base node; it will be expanded if it isn't already
@ -1335,9 +1331,9 @@ public class SongMenu extends BasicGameState {
focusScores = getScoreDataForNode(focusNode, true);
startScorePos.setPosition(0);
if (oldFocus != null && oldFocus.getBeatmapSet() != node.getBeatmapSet()){
//Close previous node
if(node.index > oldFocus.index){
if (oldFocus != null && oldFocus.getBeatmapSet() != node.getBeatmapSet()) {
// Close previous node
if (node.index > oldFocus.index) {
float offset = (oldFocus.getBeatmapSet().size() - 1) * buttonOffset;
//updateSongPos(-offset);
songScrolling.addOffset(-offset);
@ -1357,13 +1353,10 @@ public class SongMenu extends BasicGameState {
}
// change the focus node
if (changeStartNode || (startNode.index == 0 && startNode.beatmapIndex == -1 && startNode.prev == null)){
if (changeStartNode || (startNode.index == 0 && startNode.beatmapIndex == -1 && startNode.prev == null))
songScrolling.setPosition((node.index - 1) * buttonOffset);
updateDrawnSongPos();
}
updateDrawnSongPos();
updateDrawnSongPosition();
// make sure focusNode is on the screen
int val = focusNode.index + focusNode.beatmapIndex;
@ -1373,13 +1366,13 @@ public class SongMenu extends BasicGameState {
songScrolling.scrollToPosition((val - MAX_SONG_BUTTONS + 1) * buttonOffset);
/*
//Centers selected node
// Centers selected node
int val = focusNode.index + focusNode.beatmapIndex - MAX_SONG_BUTTONS/2;
songScrolling.scrollToPosition(val * buttonOffset);
//*/
/*
//Attempts to make all nodes in the set at least visible
// Attempts to make all nodes in the set at least visible
if( focusNode.index * buttonOffset < songScrolling.getPosition())
songScrolling.scrollToPosition(focusNode.index * buttonOffset);
if ( ( focusNode.index + focusNode.getBeatmapSet().size() ) * buttonOffset > songScrolling.getPosition() + footerY - headerY)

View File

@ -1,3 +1,21 @@
/*
* opsu! - an open-source osu! client
* Copyright (C) 2014, 2015 Jeffrey Han
*
* 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.ui;
/**
@ -7,49 +25,44 @@ package itdelatrisu.opsu.ui;
* @author fluddokt (https://github.com/fluddokt)
*/
public class KineticScrolling {
/** The moving averaging constant */
final static private float AVG_CONST = 0.2f;
final static private float ONE_MINUS_AVG_CONST = 1 - AVG_CONST;
/** The moving averaging constant. */
private static final float AVG_CONST = 0.2f, ONE_MINUS_AVG_CONST = 1 - AVG_CONST;
/** The constant used to determine how fast the target position will be reach. */
final static private int TIME_CONST = 200;
private static final int TIME_CONST = 200;
/** The constant used to determine how much of the velocity will be used to launch to the target. */
final static private float AMPLITUDE_CONST = 0.25f;
private static final float AMPLITUDE_CONST = 0.25f;
/** The current position. */
float position;
private float position;
/** The offset to scroll to the target position. */
float amplitude;
private float amplitude;
/** The current target to scroll to. */
float target;
private float target;
/** The total amount of time since the mouse button was released. */
float totalDelta;
private float totalDelta;
/** The maximum and minimum value the position can reach. */
float max = Float.MAX_VALUE;
float min = -Float.MAX_VALUE;
private float max = Float.MAX_VALUE, min = -Float.MAX_VALUE;
/** Whether the mouse is currently pressed or not */
boolean pressed = false;
/** Whether the mouse is currently pressed or not. */
private boolean pressed = false;
/** The change in position since the last update */
float deltaPosition;
/** The change in position since the last update. */
private float deltaPosition;
/** The moving average of the velocity. */
float avgVelocity;
private float avgVelocity;
/**
* Returns the current Position.
* @return the position.
* @return the position
*/
public float getPosition() {
return position;
}
public float getPosition() { return position; }
/**
* Updates the scrolling.
@ -63,7 +76,7 @@ public class KineticScrolling {
avgVelocity = (ONE_MINUS_AVG_CONST * avgVelocity + AVG_CONST * (deltaPosition * 1000f / delta));
position += deltaPosition;
target = position ;
target = position;
deltaPosition = 0;
}
if (position > max) {
@ -78,7 +91,7 @@ public class KineticScrolling {
/**
* Scrolls to the position.
* @param newPosition the position to scroll to.
* @param newPosition the position to scroll to
*/
public void scrollToPosition(float newPosition) {
amplitude = newPosition - position;
@ -88,7 +101,7 @@ public class KineticScrolling {
/**
* Scrolls to an offset from target.
* @param offset the offset from the target to scroll to.
* @param offset the offset from the target to scroll to
*/
public void scrollOffset(float offset) {
scrollToPosition(target + offset);
@ -107,7 +120,7 @@ public class KineticScrolling {
/**
* Set the position relative to an offset.
* @param offset the offset from the position.
* @param offset the offset from the position
*/
public void addOffset(float offset) {
setPosition(position + offset);