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,10 +105,8 @@ 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
* button at the given index.
@ -136,14 +134,14 @@ 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) {
UI.drawScrollbar(g, pos, total, SongMenu.MAX_SCORE_BUTTONS * buttonOffset, 0, baseY,
0, buttonAreaHeight, null, Color.white, false);
}
/**
* Sets a clip to the area.
* @param g the graphics context
@ -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

@ -153,7 +153,7 @@ public class DownloadNode {
public static void clipToResultArea(Graphics g) {
g.setClip((int) buttonBaseX, (int) buttonBaseY, (int) buttonWidth, (int) (buttonOffset * maxResultsShown));
}
/**
* Sets a clip to the download area.
* @param g the graphics context
@ -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.
@ -224,8 +221,8 @@ public class DownloadNode {
* @param total the total number of buttons
*/
public static void drawResultScrollbar(Graphics g, float position, float total) {
UI.drawScrollbar(g, position, total, maxResultsShown * buttonOffset, buttonBaseX, buttonBaseY,
buttonWidth * 1.01f, (maxResultsShown-1) * buttonOffset + buttonHeight,
UI.drawScrollbar(g, position, total, maxResultsShown * buttonOffset, buttonBaseX, buttonBaseY,
buttonWidth * 1.01f, (maxResultsShown-1) * buttonOffset + buttonHeight,
Colors.BLACK_BG_NORMAL, Color.white, true);
}

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;
@ -396,15 +396,15 @@ public class DownloadsMenu extends BasicGameState {
int maxResultsShown = DownloadNode.maxResultsShown();
int startResult = (int) (startResultPos.getPosition() / DownloadNode.getButtonOffset());
int offset = (int) (-startResultPos.getPosition() + startResult * DownloadNode.getButtonOffset());
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();
@ -441,20 +441,19 @@ public class DownloadsMenu extends BasicGameState {
int maxDownloadsShown = DownloadNode.maxDownloadsShown();
int startDownloadIndex = (int) (startDownloadIndexPos.getPosition() / DownloadNode.getInfoHeight());
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));
}
g.clearClip();
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));
}
g.clearClip();
// scroll bar
if (downloadsSize > maxDownloadsShown)
@ -508,7 +507,7 @@ public class DownloadsMenu extends BasicGameState {
if (resultList != null)
startResultPos.setMinMax(0, DownloadNode.getButtonOffset() * (resultList.length - DownloadNode.maxResultsShown()));
startResultPos.update(delta);
// focus timer
if (focusResult != -1 && focusTimer < FOCUS_DELAY)
focusTimer += delta;
@ -579,7 +578,7 @@ public class DownloadsMenu extends BasicGameState {
for (int i = 0; i < maxResultsShown + 1; i++) {
int startResult = (int) (startResultPos.getPosition() / DownloadNode.getButtonOffset());
int offset = (int) (-startResultPos.getPosition() + startResult * DownloadNode.getButtonOffset());
int index = startResult + i;
if (index >= nodes.length)
break;
@ -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,9 +210,8 @@ 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,29 +388,28 @@ 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();
int totalNodes = BeatmapSetList.get().size() + focusNodes - 1;
if (totalNodes > MAX_SONG_BUTTONS) {
UI.drawScrollbar(g,
UI.drawScrollbar(g,
songScrolling.getPosition(),
totalNodes * buttonOffset,
totalNodes * buttonOffset,
MAX_SONG_BUTTONS * buttonOffset,
width, headerY + DIVIDER_LINE_WIDTH / 2,
width, headerY + DIVIDER_LINE_WIDTH / 2,
0, MAX_SONG_BUTTONS * buttonOffset,
Colors.BLACK_ALPHA, Color.white, true);
}
@ -422,7 +420,7 @@ public class SongMenu extends BasicGameState {
ScoreData.clipToDownloadArea(g);
int startScore = (int) (startScorePos.getPosition() / ScoreData.getButtonOffset());
int offset = (int) (-startScorePos.getPosition() + startScore * ScoreData.getButtonOffset());
int scoreButtons = Math.min(focusScores.length - startScore, MAX_SCORE_BUTTONS + 1);
float timerScale = 1f - (1 / 3f) * ((MAX_SCORE_BUTTONS - scoreButtons) / (float) (MAX_SCORE_BUTTONS - 1));
int duration = (int) (songChangeTimer.getDuration() * timerScale);
@ -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
@ -681,7 +679,7 @@ public class SongMenu extends BasicGameState {
searchTransitionTimer = SEARCH_TRANSITION_TIME;
}
// Scores
// Scores
if (focusScores != null) {
startScorePos.setMinMax(0, (focusScores.length - MAX_SCORE_BUTTONS) * ScoreData.getButtonOffset());
startScorePos.update(delta);
@ -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;
@ -738,7 +736,7 @@ public class SongMenu extends BasicGameState {
songScrolling.pressed();
startScorePos.pressed();
}
@Override
public void mouseReleased(int button, int x, int y) {
songScrolling.release();
@ -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
@ -1334,10 +1330,10 @@ public class SongMenu extends BasicGameState {
scoreMap = ScoreDB.getMapSetScores(beatmap);
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);
@ -1355,37 +1351,34 @@ public class SongMenu extends BasicGameState {
// open from the top
}
}
// change the focus node
if (changeStartNode || (startNode.index == 0 && startNode.beatmapIndex == -1 && startNode.prev == null)){
songScrolling.setPosition((node.index - 1) * buttonOffset);
updateDrawnSongPos();
}
updateDrawnSongPos();
// change the focus node
if (changeStartNode || (startNode.index == 0 && startNode.beatmapIndex == -1 && startNode.prev == null))
songScrolling.setPosition((node.index - 1) * buttonOffset);
updateDrawnSongPosition();
// make sure focusNode is on the screen
int val = focusNode.index + focusNode.beatmapIndex;
if (val <= startNode.index)
songScrolling.scrollToPosition(val * buttonOffset);
else if (val > startNode.index + MAX_SONG_BUTTONS - 1)
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)
songScrolling.scrollToPosition((focusNode.index + focusNode.getBeatmapSet().size() ) * buttonOffset - (footerY - headerY));
//*/
// load background image
beatmap.loadBackground();
boolean isBgNull = lastBackgroundImage == null || beatmap.bg == null;

View File

@ -1,56 +1,69 @@
/*
* 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;
/**
* Drag to scroll based on:
* http://ariya.ofilabs.com/2013/11/javascript-kinetic-scrolling-part-2.html
*
*
* @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. */
private float deltaPosition;
/** The change in position since the last update */
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.
* @param delta the elapsed time since the last update
@ -61,9 +74,9 @@ public class KineticScrolling {
position = target + (float) (-amplitude * Math.exp(-totalDelta / TIME_CONST));
} else {
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);